From: Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [PATCH 5 of 6] Create libcflat for PowerPC
Date: Tue, 15 Jan 2008 16:43:43 -0600 [thread overview]
Message-ID: <d4c0de7599e4a4ae1070.1200437023@basalt> (raw)
In-Reply-To: <patchbomb.1200437018@basalt>
# HG changeset patch
# User Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# 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 <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
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 <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
+ */
+
+#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 <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
+ */
+
+#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 <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
+ */
+
#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, TLBWORD0@h
- ori r4, r4, TLBWORD0@l
- tlbwe r4, r3, 0
-
- lis r4, TLBWORD1@h
- ori r4, r4, TLBWORD1@l
- tlbwe r4, r3, 1
-
- lis r4, TLBWORD2@h
- ori r4, r4, TLBWORD2@l
- 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 <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
+ */
+
+#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/
next prev parent reply other threads:[~2008-01-15 22:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-15 22:43 [PATCH 0 of 6] Enhance PowerPC unit tests Hollis Blanchard
2008-01-15 22:43 ` [PATCH 1 of 6] Move IO handling code to a separate file Hollis Blanchard
2008-01-16 8:16 ` Avi Kivity
2008-01-15 22:43 ` [PATCH 2 of 6] Register a debug MMIO handler, and implement putc() and exit() with it Hollis Blanchard
2008-01-15 22:43 ` [PATCH 3 of 6] Move FLATLIBS to config-x86-common.mak Hollis Blanchard
2008-01-15 22:43 ` [PATCH 4 of 6] Use "$(CC)" instead of "gcc" to find libgcc Hollis Blanchard
2008-01-15 22:43 ` Hollis Blanchard [this message]
2008-01-15 22:43 ` [PATCH 6 of 6] Reorganize PowerPC makefiles and add an "exit" test that uses libcflat Hollis Blanchard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d4c0de7599e4a4ae1070.1200437023@basalt \
--to=hollisb-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
--cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox