Skip to contentSkip to conversation

Consilidate test libs to libcflat for single lib for all arch

PATCH Applied Jerone Young 2 participants 2 messages Jul 5, 2008 – Jul 6, 2008 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Consilidate test libs to libcflat for single lib for all arch

23 files changed, 478 insertions(+), 427 deletions(-)
user/Makefile              |   11 ++
user/config-x86-common.mak |   16 ++-
user/main.c                |    2 
user/test/lib/libcflat.h   |   37 ++++++++
user/test/lib/panic.c      |   13 ++
user/test/lib/printf.c     |  179 ++++++++++++++++++++++++++++++++++++++++
user/test/lib/string.c     |   21 ++++
user/test/lib/x86/apic.h   |   14 +++
user/test/lib/x86/io.c     |   23 +++++
user/test/lib/x86/smp.c    |  150 +++++++++++++++++++++++++++++++++
user/test/lib/x86/smp.h    |   16 +++
user/test/x86/access.c     |    3 
user/test/x86/lib/apic.h   |   14 ---
user/test/x86/lib/exit.c   |    5 -
user/test/x86/lib/printf.c |  195 --------------------------------------------
user/test/x86/lib/printf.h |    2 
user/test/x86/lib/smp.c    |  151 ----------------------------------
user/test/x86/lib/smp.h    |   16 ---
user/test/x86/lib/string.c |   21 ----
user/test/x86/lib/string.h |    7 -
user/test/x86/port80.c     |    3 
user/test/x86/smptest.c    |    3 
user/test/x86/tsc.c        |    3 

* This patch is consolidation of the libcflat patch series sent earlier due to popular demand. So it's big.

* Could not figure out a cleaner way to generate file deletion diffs, with my current setup.

This patch lays the ground work for a sinlge libcflat library that can be used for x86. But this allows for other archs to share common code, and build a single archive for tests to use libcflat functions.

Add Makefile and test changes required for x86 & x86-64 to use libcflat.

Remove old x86 test libs, that are now appart of libcflat.

user/Makefile +10 -1
@@ -9,6 +9,12 @@
 CFLAGS =
 
 libgcc := $(shell $(CC) --print-libgcc-file-name)
+
+libcflat := test/lib/libcflat.a
+cflatobjs := \
+	test/lib/panic.o \
+	test/lib/printf.o \
+	test/lib/string.o
 
 #include architecure specific make rules
 include config-$(ARCH).mak
@@ -41,10 +47,13 @@
 kvmtrace: $(kvmtrace_objs)
 	$(CC) $(LDFLAGS) $^ -o $@
 
+$(libcflat): $(cflatobjs)
+	ar rcs $@ $^
+
 %.o: %.S
 	$(CC) $(CFLAGS) -c -nostdlib -o $@ $^
 
 -include .*.d
 
 clean: arch_clean
-	$(RM) kvmctl kvmtrace *.o *.a .*.d
+	$(RM) kvmctl kvmtrace *.o *.a .*.d $(libcflat) $(cflatobjs)
user/config-x86-common.mak +10 -6
@@ -5,7 +5,15 @@
 kvmctl_objs= main.o iotable.o ../libkvm/libkvm.a
 balloon_ctl: balloon_ctl.o
 
-FLATLIBS = $(TEST_DIR)/libcflat.a $(libgcc)
+cflatobjs += \
+	test/lib/x86/io.o \
+	test/lib/x86/smp.o
+
+$(libcflat): LDFLAGS += -nostdlib
+$(libcflat): CFLAGS += -ffreestanding -I test/lib
+
+
+FLATLIBS = test/lib/libcflat.a $(libgcc)
 %.flat: %.o $(FLATLIBS)
 	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,flat.lds $^ $(FLATLIBS)
 
@@ -15,7 +23,7 @@
 
 test_cases: $(tests-common) $(tests)
 
-$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I$(TEST_DIR)/lib
+$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I test/lib -I test/lib/x86
  
 $(TEST_DIR)/bootstrap: $(TEST_DIR)/bootstrap.o
 	$(CC) -nostdlib -o $@ -Wl,-T,bootstrap.lds $^
@@ -41,10 +49,6 @@
 
 $(TEST_DIR)/tsc.flat: $(cstart.o) $(TEST_DIR)/tsc.o
 
-$(TEST_DIR)/libcflat.a: $(TEST_DIR)/lib/exit.o $(TEST_DIR)/lib/printf.o \
-	$(TEST_DIR)/lib/smp.o $(TEST_DIR)/lib/string.o
-	ar rcs $@ $^
-
 arch_clean:
 	$(RM) $(TEST_DIR)/bootstrap $(TEST_DIR)/*.o $(TEST_DIR)/*.flat \
 	$(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
user/main.c +1 -1
@@ -17,7 +17,7 @@
 #define _GNU_SOURCE
 
 #include <libkvm.h>
-#include "test/x86/lib/apic.h"
+#include "test/lib/x86/apic.h"
 #include "test/x86/ioram.h"
 
 #include <stdio.h>
user/test/lib/libcflat.h new file +37 -0
new file mode 100644
@@ -0,0 +1,37 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ */
+
+#ifndef __LIBCFLAT_H
+#define __LIBCFLAT_H
+
+#include <stdarg.h>
+
+extern int main(void);
+extern void exit(int code);
+extern void panic(char *fmt, ...);
+
+extern unsigned long strlen(const char *buf);
+extern char *strcat(char *dest, const char *src);
+
+extern int printf(const char *fmt, ...);
+extern int vsnprintf(char *buf, int size, const char *fmt, va_list va);
+
+extern void puts(const char *s);
+
+#endif
user/test/lib/panic.c new file +13 -0
new file mode 100644
@@ -0,0 +1,13 @@
+#include "libcflat.h"
+
+void panic(char *fmt, ...)
+{
+	va_list va;
+	char buf[2000];
+
+	va_start(va, fmt);
+	vsnprintf(buf, sizeof(buf), fmt, va);
+	va_end(va);
+	puts(buf);
+	exit(-1);
+}
user/test/lib/printf.c new file +179 -0

179 lines not on this page · raw message

user/test/lib/string.c new file +21 -0
new file mode 100644
@@ -0,0 +1,21 @@
+#include "libcflat.h"
+
+unsigned long strlen(const char *buf)
+{
+    unsigned long len = 0;
+
+    while (*buf++)
+	++len;
+    return len;
+}
+
+char *strcat(char *dest, const char *src)
+{
+    char *p = dest;
+
+    while (*p)
+	++p;
+    while ((*p++ = *src++) != 0)
+	;
+    return dest;
+}
user/test/lib/x86/apic.h new file +14 -0
new file mode 100644
@@ -0,0 +1,14 @@
+#ifndef SILLY_APIC_H
+#define SILLY_APIC_H
+
+#define APIC_BASE 0x1000
+#define APIC_SIZE 0x100
+
+#define APIC_REG_NCPU        0x00
+#define APIC_REG_ID          0x04
+#define APIC_REG_SIPI_ADDR   0x08
+#define APIC_REG_SEND_SIPI   0x0c
+#define APIC_REG_IPI_VECTOR  0x10
+#define APIC_REG_SEND_IPI    0x14
+
+#endif
user/test/lib/x86/io.c new file +23 -0
new file mode 100644
@@ -0,0 +1,23 @@
+#include "libcflat.h"
+#include "smp.h"
+
+static struct spinlock lock;
+
+static void print_serial(const char *buf)
+{
+	unsigned long len = strlen(buf);
+
+	asm volatile ("rep/outsb" : "+S"(buf), "+c"(len) : "d"(0xf1));
+}
+
+void puts(const char *s)
+{
+	spin_lock(&lock);
+	print_serial(s);
+	spin_unlock(&lock);
+}
+
+void exit(int code)
+{
+        asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4));
+}
user/test/lib/x86/smp.c new file +150 -0

150 lines not on this page · raw message

user/test/lib/x86/smp.h new file +16 -0
new file mode 100644
@@ -0,0 +1,16 @@
+#ifndef __SMP_H
+#define __SMP_H
+
+struct spinlock {
+    int v;
+};
+
+void smp_init(void (*smp_main)(void));
+
+int cpu_count(void);
+int smp_id(void);
+void on_cpu(int cpu, void (*function)(void *data), void *data);
+void spin_lock(struct spinlock *lock);
+void spin_unlock(struct spinlock *lock);
+
+#endif
user/test/x86/access.c +1 -2
@@ -1,7 +1,6 @@
 
+#include "libcflat.h"
 #include "smp.h"
-#include "printf.h"
-#include "string.h"
 
 #define true 1
 #define false 0
user/test/x86/lib/apic.h deleted +0 -14
deleted file mode 100644
@@ -1,14 +0,0 @@
-#ifndef SILLY_APIC_H
-#define SILLY_APIC_H
-
-#define APIC_BASE 0x1000
-#define APIC_SIZE 0x100
-
-#define APIC_REG_NCPU        0x00
-#define APIC_REG_ID          0x04
-#define APIC_REG_SIPI_ADDR   0x08
-#define APIC_REG_SEND_SIPI   0x0c
-#define APIC_REG_IPI_VECTOR  0x10
-#define APIC_REG_SEND_IPI    0x14
-
-#endif
user/test/x86/lib/exit.c deleted +0 -5
deleted file mode 100644
@@ -1,5 +0,0 @@
-
-void exit(int code)
-{
-	asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4));
-}
user/test/x86/lib/printf.c deleted +0 -195

195 lines not on this page · raw message

user/test/x86/lib/printf.h deleted +0 -2
deleted file mode 100644
@@ -1,2 +0,0 @@
-
-int printf(const char *fmt, ...);
user/test/x86/lib/smp.c deleted +0 -151

151 lines not on this page · raw message

user/test/x86/lib/smp.h deleted +0 -16
deleted file mode 100644
@@ -1,16 +0,0 @@
-#ifndef __SMP_H
-#define __SMP_H
-
-struct spinlock {
-    int v;
-};
-
-void smp_init(void (*smp_main)(void));
-
-int cpu_count(void);
-int smp_id(void);
-void on_cpu(int cpu, void (*function)(void *data), void *data);
-void spin_lock(struct spinlock *lock);
-void spin_unlock(struct spinlock *lock);
-
-#endif
user/test/x86/lib/string.c deleted +0 -21
deleted file mode 100644
@@ -1,21 +0,0 @@
-#include "string.h"
-
-unsigned long strlen(const char *buf)
-{
-    unsigned long len = 0;
-
-    while (*buf++)
-	++len;
-    return len;
-}
-
-char *strcat(char *dest, const char *src)
-{
-    char *p = dest;
-
-    while (*p)
-	++p;
-    while ((*p++ = *src++) != 0)
-	;
-    return dest;
-}
user/test/x86/lib/string.h deleted +0 -7
deleted file mode 100644
@@ -1,7 +0,0 @@
-#ifndef FLAT_LIB_STRING_H
-#define FLAT_LIB_STRING_H
-
-unsigned long strlen(const char *buf);
-char *strcat(char *dest, const char *src);
-
-#endif
user/test/x86/port80.c +1 -2
@@ -1,5 +1,4 @@
-
-#include "printf.h"
+#include "libcflat.h"
 
 int main()
 {
user/test/x86/smptest.c +1 -2
@@ -1,6 +1,5 @@
-
+#include "libcflat.h"
 #include "smp.h"
-#include "printf.h"
 
 static void ipi_test(void *data)
 {
user/test/x86/tsc.c +1 -2
@@ -1,5 +1,4 @@
-
-#include "printf.h"
+#include "libcflat.h"
 
 typedef unsigned long long u64;
 
Applied
#1 lore raw
Quoted 7 lines · Jerone Young

This patch lays the ground work for a sinlge libcflat library that can be used for x86. But this allows for other archs to share common code, and build a single archive for tests to use libcflat functions.

Add Makefile and test changes required for x86 & x86-64 to use libcflat.

Remove old x86 test libs, that are now appart of libcflat.

Applied, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function