# HG changeset patch
# User Hollis Blanchard <[EMAIL PROTECTED]>
# Date 1200436754 21600
# Node ID d4c0de7599e4a4ae107044aa4f4c95dc50f9ce6a
# Parent  59aa1c2e71c23b6fe1fb072c81163807da817d5b
This duplicates some test/x86/lib/ files into test/lib/ until someone ports x86
to use the common source. Architectures must provide their own exit() and
puts() implementations under test/lib/<arch>/.

Signed-off-by: Hollis Blanchard <[EMAIL PROTECTED]>

---
9 files changed, 182 insertions(+), 45 deletions(-)
user/Makefile                     |    4 ++
user/config-powerpc.mak           |   14 +++++++++-
user/test/lib/libcflat.h          |   37 ++++++++++++++++++++++++++
user/test/lib/panic.c             |   13 +++++++++
user/test/lib/powerpc/44x/map.c   |   51 +++++++++++++++++++++++++++++++++++++
user/test/lib/powerpc/44x/tlbwe.S |   50 ++++++++++++++++++------------------
user/test/lib/powerpc/io.c        |   35 +++++++++++++++++++++++++
user/test/lib/printf.c            |   21 +--------------
user/test/lib/string.c            |    2 -


diff --git a/user/Makefile b/user/Makefile
--- a/user/Makefile
+++ b/user/Makefile
@@ -9,6 +9,10 @@ CFLAGS =
 CFLAGS =
 
 libgcc := $(shell $(CC) --print-libgcc-file-name)
+cflatobjs := \
+       test/lib/panic.o \
+       test/lib/printf.o \
+       test/lib/string.o
 
 #include architecure specific make rules
 include config-$(ARCH).mak
diff --git a/user/config-powerpc.mak b/user/config-powerpc.mak
--- a/user/config-powerpc.mak
+++ b/user/config-powerpc.mak
@@ -1,3 +1,10 @@ CFLAGS += -m32
+libcflat := test/lib/libcflat.a
+
+cflatobjs += \
+       test/lib/powerpc/io.o \
+       test/lib/powerpc/44x/map.o \
+       test/lib/powerpc/44x/tlbwe.o
+
 CFLAGS += -m32
 CFLAGS += -D__powerpc__
 CFLAGS += -I $(KERNELDIR)/include
@@ -20,7 +27,12 @@ tests := $(addprefix test/powerpc/, $(te
 
 all: kvmctl $(tests)
 
+$(libcflat): LDFLAGS += -nostdlib
+$(libcflat): CFLAGS += -ffreestanding -I test/lib -I test/lib/powerpc/44x
+$(libcflat): $(cflatobjs)
+       ar rcs $@ $^
+
 kvmctl_objs = main-ppc.o iotable.o ../libkvm/libkvm.a
 
 arch_clean:
-       rm -f $(tests)
+       rm -f $(tests) $(cflatobjs)
diff --git a/user/test/lib/libcflat.h b/user/test/lib/libcflat.h
new file mode 100644
--- /dev/null
+++ b/user/test/lib/libcflat.h
@@ -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
diff --git a/user/test/lib/panic.c b/user/test/lib/panic.c
new file mode 100644
--- /dev/null
+++ b/user/test/lib/panic.c
@@ -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);
+}
diff --git a/user/test/lib/powerpc/44x/map.c b/user/test/lib/powerpc/44x/map.c
new file mode 100644
--- /dev/null
+++ b/user/test/lib/powerpc/44x/map.c
@@ -0,0 +1,51 @@
+/*
+ * 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]>
+ */
+
+#include "libcflat.h"
+
+#define TLB_SIZE 64
+
+extern void tlbwe(unsigned int index,
+                  unsigned char tid,
+                  unsigned int word0,
+                  unsigned int word1,
+                  unsigned int word2);
+
+unsigned int next_free_index;
+
+#define PAGE_SHIFT 12
+#define PAGE_MASK (~((1<<PAGE_SHIFT)-1))
+
+#define V (1<<9)
+
+void map(unsigned long vaddr, unsigned long paddr)
+{
+       unsigned int w0, w1, w2;
+
+       /* We don't install exception handlers, so we can't handle TLB misses,
+        * so we can't loop around and overwrite entry 0. */
+       if (next_free_index++ >= TLB_SIZE)
+               panic("TLB overflow");
+
+       w0 = (vaddr & PAGE_MASK) | V;
+       w1 = paddr & PAGE_MASK;
+       w2 = 0x3;
+
+       tlbwe(next_free_index, 0, w0, w1, w2);
+}
diff --git a/user/test/powerpc/44x/tlbwe.S b/user/test/lib/powerpc/44x/tlbwe.S
copy from user/test/powerpc/44x/tlbwe.S
copy to user/test/lib/powerpc/44x/tlbwe.S
--- a/user/test/lib/powerpc/44x/tlbwe.S
+++ b/user/test/lib/powerpc/44x/tlbwe.S
@@ -1,27 +1,29 @@
+/*
+ * 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]>
+ */
+
 #define SPRN_MMUCR 0x3b2
 
-/* Create a mapping at 4MB */
-#define TLBWORD0 0x00400210
-#define TLBWORD1 0x00400000
-#define TLBWORD2 0x00000003
-
-.global _start
-_start:
-       li      r4, 0
+/* tlbwe(uint index, uint8_t tid, uint word0, uint word1, uint word2) */
+.global tlbwe
+tlbwe:
        mtspr   SPRN_MMUCR, r4
-
-       li      r3, 23
-
-       lis     r4, [EMAIL PROTECTED]
-       ori     r4, r4, [EMAIL PROTECTED]
-       tlbwe   r4, r3, 0
-
-       lis     r4, [EMAIL PROTECTED]
-       ori     r4, r4, [EMAIL PROTECTED]
-       tlbwe   r4, r3, 1
-
-       lis     r4, [EMAIL PROTECTED]
-       ori     r4, r4, [EMAIL PROTECTED]
-       tlbwe   r4, r3, 2
-
-       b       .
+       tlbwe   r5, r3, 0
+       tlbwe   r6, r3, 1
+       tlbwe   r7, r3, 2
+       blr
diff --git a/user/test/lib/powerpc/io.c b/user/test/lib/powerpc/io.c
new file mode 100644
--- /dev/null
+++ b/user/test/lib/powerpc/io.c
@@ -0,0 +1,35 @@
+/*
+ * 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]>
+ */
+
+#include "libcflat.h"
+
+#define BASE 0xf0000000
+#define _putc ((volatile char *)(BASE))
+#define _exit ((volatile char *)(BASE+1))
+
+void puts(const char *s)
+{
+       while (*s != '\0')
+               *_putc = *s++;
+}
+
+void exit(int code)
+{
+       *_exit = code;
+}
diff --git a/user/test/x86/lib/printf.c b/user/test/lib/printf.c
copy from user/test/x86/lib/printf.c
copy to user/test/lib/printf.c
--- a/user/test/lib/printf.c
+++ b/user/test/lib/printf.c
@@ -1,11 +1,4 @@
-#include "printf.h"
-#include "smp.h"
-#include <stdarg.h>
-#include "string.h"
-
-static struct spinlock lock;
-
-void print(const char *s);
+#include "libcflat.h"
 
 typedef struct pstream {
     char *buffer;
@@ -92,7 +85,6 @@ void print_unsigned(pstream_t *ps, unsig
 
 int vsnprintf(char *buf, int size, const char *fmt, va_list va)
 {
-    int n;
     pstream_t s;
 
     s.buffer = buf;
@@ -173,13 +165,6 @@ int snprintf(char *buf, int size, const 
     return r;
 }
 
-void print_serial(const char *buf)
-{
-    unsigned long len = strlen(buf);
-
-    asm volatile ("rep/outsb" : "+S"(buf), "+c"(len) : "d"(0xf1));
-}
-
 int printf(const char *fmt, ...)
 {
     va_list va;
@@ -189,8 +174,6 @@ int printf(const char *fmt, ...)
     va_start(va, fmt);
     r = vsnprintf(buf, sizeof buf, fmt, va);
     va_end(va);
-    spin_lock(&lock);
-    print_serial(buf);
-    spin_unlock(&lock);
+    puts(buf);
     return r;
 }
diff --git a/user/test/x86/lib/string.c b/user/test/lib/string.c
copy from user/test/x86/lib/string.c
copy to user/test/lib/string.c
--- a/user/test/lib/string.c
+++ b/user/test/lib/string.c
@@ -1,4 +1,4 @@
-#include "string.h"
+#include "libcflat.h"
 
 unsigned long strlen(const char *buf)
 {

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to