Skip to contentSkip to conversation

x86 user directory refactoring

PATCH New Jerone Young 2 participants 5 messages Oct 23, 2007 – Oct 24, 2007 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86 user directory refactoring

The following patches are the 2nd attempt to refactor code for x86 in the user directory to better accomidate the addition of other architectures.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#1 lore raw

PATCH 1/1 : x86_user_make_changes

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193171111 18000
# Node ID 4ab89cf7599614117dcd2d3d7d96d29871b71328
# Parent 707451c0b5ab24ac40bf29885c1b660201eae203
[mq]: x86_user_make_changes

user/Makefile +1 -17
@@ -15,8 +15,7 @@ cc-option = $(shell if $(CC) $(1) -S -o 
 cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
               > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
-CFLAGS += -I $(KERNELDIR)/include $(autodepend-flags) -g -fomit-frame-pointer \
-	-Wall
+CFLAGS += $(autodepend-flags) -g -fomit-frame-pointer -Wall 
 CFLAGS += $(call cc-option, -fno-stack-protector, "")
 CFLAGS += $(call cc-option, -fno-stack-protector-all, "")
 
@@ -25,21 +24,6 @@ CXXFLAGS = $(autodepend-flags)
 CXXFLAGS = $(autodepend-flags) 
 
 autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
-
-all: kvmctl libkvm.a flatfiles
-
-kvmctl: LDFLAGS += -pthread -lrt
-
-kvmctl: kvmctl.o main.o
-
-balloon_ctl: balloon_ctl.o
-
-libkvm.a: kvmctl.o
-	$(AR) rcs $@ $^
-
-flatfiles-common = test/bootstrap test/vmexit.flat test/smp.flat
-
-flatfiles: $(flatfiles-common) $(flatfiles)
 
 install:
 	install -D kvmctl.h $(DESTDIR)/$(PREFIX)/include/kvmctl.h
user/config-i386.mak +5 -1
@@ -3,5 +3,9 @@ bits = 32
 bits = 32
 ldarch = elf32-i386
 CFLAGS += -m32
+CFLAGS += -D__i386__
+CFLAGS += -I $(KERNELDIR)/include
 
-flatfiles=
+flatfile_tests=
+
+include config-x86-common.mak
user/config-x86-common.mak new file +16 -0
new file mode 100644
@@ -0,0 +1,16 @@
+#This is a make file with common rules for both x86 & x86-64
+
+all: kvmctl libkvm.a flatfiles
+
+kvmctl: LDFLAGS += -pthread -lrt
+
+kvmctl: kvmctl.o main.o
+
+libkvm.a: kvmctl.o
+	$(AR) rcs $@ $^
+
+balloon_ctl: balloon_ctl.o
+
+flatfiles_tests-common = test/bootstrap test/vmexit.flat test/smp.flat
+
+flatfiles: $(flatfiles_tests-common) $(flatfile_tests))
user/config-x86_64.mak +5 -1
@@ -3,5 +3,9 @@ bits = 64
 bits = 64
 ldarch = elf64-x86-64
 CFLAGS += -m64
+CFLAGS += -D__x86_64__
+CFLAGS += -I $(KERNELDIR)/include
 
-flatfiles = test/access.flat test/irq.flat test/sieve.flat test/simple.flat test/stringio.flat test/memtest1.flat
+flatfile_tests = test/access.flat test/irq.flat test/sieve.flat test/simple.flat test/stringio.flat test/memtest1.flat
+
+include config-x86-common.mak

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#2 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 2] [mq]: x86_user_make_changes

Quoted 2 lines · Jerone Young

+flatfiles_tests-common = test/bootstrap test/vmexit.flat test/smp.flat

Instead of "flatfiles_tests-common" (getting a little long, no?), I would just call them "tests" and "tests-common" or "tests-x86". We're going to have non-flat test binaries in the near future anyways...

Signature · 9 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
#3 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 2] [mq]: x86_user_make_changes

ok I can resend this anyway . I forgot to consolidate the kvmctl stuff.

Quoted 8 lines · Hollis Blanchard
Quoted 2 lines · Jerone Young

+flatfiles_tests-common = test/bootstrap test/vmexit.flat test/smp.flat

Instead of "flatfiles_tests-common" (getting a little long, no?), I would just call them "tests" and "tests-common" or "tests-x86". We're going to have non-flat test binaries in the near future anyways...

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#4 lore raw

PATCH 1/1 This patch moves x86 specific tests to there own directory

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193171508 18000
# Node ID 5cd9f474ff2b1e7175278d4bcd3e885f1b294d98
# Parent 4f7e88d410070f9b49236fad68533ca4352981f6
This patch moves x86 specific tests to there own directory.

user/Makefile +5 -22
@@ -2,6 +2,8 @@ include config.mak
 include config.mak
 
 DESTDIR :=
+
+.PHONY: arch_clean clean
 
 #make sure env CFLAGS variable is not used
 CFLAGS =
@@ -15,13 +17,13 @@ cc-option = $(shell if $(CC) $(1) -S -o 
 cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
               > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
-CFLAGS += $(autodepend-flags) -g -fomit-frame-pointer -Wall 
+CFLAGS += $(autodepend-flags) -g -fomit-frame-pointer -Wall
 CFLAGS += $(call cc-option, -fno-stack-protector, "")
 CFLAGS += $(call cc-option, -fno-stack-protector-all, "")
 
 LDFLAGS += $(CFLAGS)
 
-CXXFLAGS = $(autodepend-flags) 
+CXXFLAGS = $(autodepend-flags)
 
 autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
 
@@ -36,29 +38,10 @@ install:
 %.flat: %.o
 	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,flat.lds $^
 
-test/bootstrap: test/bootstrap.o
-	$(CC) -nostdlib -o $@ -Wl,-T,bootstrap.lds $^
-
 %.o: %.S
 	$(CC) $(CFLAGS) -c -nostdlib -o $@ $^
 
-test/irq.flat: test/print.o
-
-test/access.flat: $(cstart.o) test/access.o test/printf.o test/print.o \
-	test/smp.o
-
-test/sieve.flat: $(cstart.o) test/sieve.o test/print.o test/vm.o
-
-test/vmexit.flat: $(cstart.o) test/vmexit.o test/printf.o test/smp.o
-
-test/test32.flat: test/test32.o
-
-test/smp.flat: $(cstart.o) test/smp.o test/printf.o test/smptest.o
-
-test/%.o: CFLAGS += -std=gnu99 -ffreestanding
-
 -include .*.d
 
-clean:
+clean: arch_clean
 	$(RM) kvmctl *.o *.a .*.d
-	$(RM) test/bootstrap test/*.o test/*.flat test/.*.d
user/config-i386.mak +2 -1
@@ -1,5 +1,6 @@ LIBDIR = /lib
 LIBDIR = /lib
-cstart.o = test/cstart.o
+TEST_DIR=test/x86
+cstart.o = $(TEST_DIR)/cstart.o
 bits = 32
 ldarch = elf32-i386
 CFLAGS += -m32
user/config-x86-common.mak +29 -2
@@ -11,6 +11,33 @@ libkvm.a: kvmctl.o
 
 balloon_ctl: balloon_ctl.o
 
-flatfiles_tests-common = test/bootstrap test/vmexit.flat test/smp.flat
+flatfiles_tests-common = $(TEST_DIR)/bootstrap \
+			$(TEST_DIR)/vmexit.flat \
+			$(TEST_DIR)/smp.flat
 
-flatfiles: $(flatfiles_tests-common) $(flatfile_tests))
+flatfiles: $(flatfiles_tests-common) $(flatfile_tests)
+
+$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding
+ 
+$(TEST_DIR)/bootstrap: $(TEST_DIR)/bootstrap.o
+	$(CC) -nostdlib -o $@ -Wl,-T,bootstrap.lds $^
+ 
+$(TEST_DIR)/irq.flat: $(TEST_DIR)/test/print.o
+ 
+$(TEST_DIR)/access.flat: $(cstart.o) $(TEST_DIR)/access.o \
+	$(TEST_DIR)/printf.o $(TEST_DIR)/print.o $(TEST_DIR)/smp.o
+ 
+$(TEST_DIR)/sieve.flat: $(cstart.o) $(TEST_DIR)/sieve.o \
+		$(TEST_DIR)/print.o $(TEST_DIR)/vm.o
+ 
+$(TEST_DIR)/vmexit.flat: $(cstart.o) $(TEST_DIR)/vmexit.o \
+	$(TEST_DIR)/printf.o $(TEST_DIR)/smp.o
+ 
+$(TEST_DIR)/test32.flat: $(TEST_DIR)/test32.o
+
+$(TEST_DIR)/smp.flat: $(cstart.o) $(TEST_DIR)/smp.o $(TEST_DIR)/printf.o \
+			$(TEST_DIR)/smptest.o
+ 
+arch_clean:
+	$(RM) $(TEST_DIR)/bootstrap $(TEST_DIR)/*.o $(TEST_DIR)/*.flat \
+	$(TEST_DIR)/.*.d
user/config-x86_64.mak +2 -1
@@ -1,5 +1,6 @@ LIBDIR = /lib64
 LIBDIR = /lib64
-cstart.o = test/cstart64.o
+TEST_DIR=test/x86
+cstart.o = $(TEST_DIR)/cstart64.o
 bits = 64
 ldarch = elf64-x86-64
 CFLAGS += -m64
user/main.c +1 -1
@@ -17,7 +17,7 @@
 #define _GNU_SOURCE
 
 #include "kvmctl.h"
-#include "test/apic.h"
+#include "test/x86/apic.h"
 
 #include <stdio.h>
 #include <unistd.h>
user/test/access.c deleted +0 -367

367 lines not on this page · raw message

user/test/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/bootstrap.S deleted +0 -137

137 lines not on this page · raw message

user/test/cstart.S deleted +0 -10
deleted file mode 100644
@@ -1,10 +0,0 @@
-
-
-.bss
-
-.section .init
-	call main
-1:	hlt
-	jmp 1b
-
-
user/test/cstart64.S deleted +0 -169

169 lines not on this page · raw message

user/test/irq.S deleted +0 -118

118 lines not on this page · raw message

user/test/memtest1.S deleted +0 -44

44 lines not on this page · raw message

user/test/print.S deleted +0 -31
deleted file mode 100644
@@ -1,31 +0,0 @@
-
-#include "print.h"
-
-#define PSEUDO_SERIAL_PORT 0xf1
-
-	
-.text
-	PRINT "boo"
-	hlt
-1:	jmp 1b
-	
-.globl print
-print:
-	push %rax
-	push %rsi
-	push %rdx
-
-	mov %rdi, %rsi
-	mov $(PSEUDO_SERIAL_PORT), %edx
-
-putchar:
-	cmpb $0, (%rsi)
-	jz done
-	outsb
-	jmp putchar
-done:
-	
-	pop %rdx
-	pop %rsi
-	pop %rax
-	ret
user/test/print.h deleted +0 -19
deleted file mode 100644
@@ -1,19 +0,0 @@
-#ifndef PRINT_H
-#define PRINT_H
-
-.macro PRINT text
-
-.data
-
-333: .asciz "\text\n"
-
-.previous
-
-	push %rdi
-	lea 333b, %rdi
-	call print
-	pop %rdi
-
-.endm
-
-#endif
user/test/printf.c deleted +0 -169

169 lines not on this page · raw message

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

89 lines not on this page · raw message

user/test/simple.S deleted +0 -13
deleted file mode 100644
@@ -1,13 +0,0 @@
-
-	.text
-
-	mov $0, %al
-	mov $10000, %ebx
-1:
-	mov %rbx, %rcx
-2:	
-	loop 2b
-	out %al, $0x80
-	inc %al
-	add $10000, %rbx
-	jmp 1b
user/test/smp.c deleted +0 -151

151 lines not on this page · raw message

user/test/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/smptest.c deleted +0 -32
deleted file mode 100644
@@ -1,32 +0,0 @@
-
-#include "smp.h"
-#include "printf.h"
-
-static void ipi_test(void *data)
-{
-    int n = (long)data;
-
-    printf("ipi called, cpu %d\n", n);
-    if (n != smp_id())
-	printf("but wrong cpu %d\n", smp_id());
-}
-
-static void smp_main(void)
-{
-    printf("smp main %d\n", smp_id());
-    while (1)
-	asm volatile ("hlt" : : : "memory");
-}
-
-int main()
-{
-    int ncpus;
-    int i;
-
-    smp_init(smp_main);
-    ncpus = cpu_count();
-    printf("found %d cpus\n", ncpus);
-    for (i = 0; i < ncpus; ++i)
-	on_cpu(i, ipi_test, (void *)(long)i);
-    return 0;
-}
user/test/stringio.S deleted +0 -31
deleted file mode 100644
@@ -1,31 +0,0 @@
-
-.data
-
-.macro str name, value
-
-\name :	.long 1f-2f
-2:	.ascii "\value"
-1:	
-.endm	
-
-	str "forward", "forward"
-	str "backward", "backward"
-		
-.text
-
-
-	cld
-	movl forward, %ecx
-	lea  4+forward, %rsi
-	movw $1, %dx
-	rep outsb
-
-	std
-	movl backward, %ecx
-	lea 4+backward-1(%rcx), %rsi
-	movw $2, %dx
-	rep outsb
-	
-	hlt
-
-
user/test/test32.S deleted +0 -8
deleted file mode 100644
@@ -1,8 +0,0 @@
-.code32
-
-.text
-
-1:
-	mov $0x12, %al
-	out %al, $0x80
-	jmp 1b
user/test/vm.c deleted +0 -249

249 lines not on this page · raw message

user/test/vm.h deleted +0 -9
deleted file mode 100644
@@ -1,9 +0,0 @@
-#ifndef VM_H
-#define VM_H
-
-void setup_vm();
-
-void *vmalloc(unsigned long size);
-void vfree(void *mem);
-
-#endif
user/test/vmexit.c deleted +0 -32
deleted file mode 100644
@@ -1,32 +0,0 @@
-
-#include "printf.h"
-
-static inline unsigned long long rdtsc()
-{
-	long long r;
-
-#ifdef __x86_64__
-	unsigned a, d;
-
-	asm volatile ("rdtsc" : "=a"(a), "=d"(d));
-	r = a | ((long long)d << 32);
-#else
-	asm volatile ("rdtsc" : "=A"(r));
-#endif
-	return r;
-}
-
-#define N (1 << 22)
-
-int main()
-{
-	int i;
-	unsigned long long t1, t2;
-
-	t1 = rdtsc();
-	for (i = 0; i < N; ++i)
-		asm volatile ("cpuid" : : : "eax", "ebx", "ecx", "edx");
-	t2 = rdtsc();
-	printf("vmexit latency: %d\n", (int)((t2 - t1) / N));
-	return 0;
-}
user/test/x86/access.c new file +367 -0

367 lines not on this page · raw message

user/test/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/x86/bootstrap.S new file +137 -0

137 lines not on this page · raw message

user/test/x86/cstart.S new file +10 -0
new file mode 100644
@@ -0,0 +1,10 @@
+
+
+.bss
+
+.section .init
+	call main
+1:	hlt
+	jmp 1b
+
+
user/test/x86/cstart64.S new file +169 -0

169 lines not on this page · raw message

user/test/x86/irq.S new file +118 -0

118 lines not on this page · raw message

user/test/x86/memtest1.S new file +44 -0

44 lines not on this page · raw message

user/test/x86/print.S new file +31 -0
new file mode 100644
@@ -0,0 +1,31 @@
+
+#include "print.h"
+
+#define PSEUDO_SERIAL_PORT 0xf1
+
+	
+.text
+	PRINT "boo"
+	hlt
+1:	jmp 1b
+	
+.globl print
+print:
+	push %rax
+	push %rsi
+	push %rdx
+
+	mov %rdi, %rsi
+	mov $(PSEUDO_SERIAL_PORT), %edx
+
+putchar:
+	cmpb $0, (%rsi)
+	jz done
+	outsb
+	jmp putchar
+done:
+	
+	pop %rdx
+	pop %rsi
+	pop %rax
+	ret
user/test/x86/print.h new file +19 -0
new file mode 100644
@@ -0,0 +1,19 @@
+#ifndef PRINT_H
+#define PRINT_H
+
+.macro PRINT text
+
+.data
+
+333: .asciz "\text\n"
+
+.previous
+
+	push %rdi
+	lea 333b, %rdi
+	call print
+	pop %rdi
+
+.endm
+
+#endif
user/test/x86/printf.c new file +169 -0

169 lines not on this page · raw message

user/test/x86/printf.h new file +2 -0
new file mode 100644
@@ -0,0 +1,2 @@
+
+int printf(const char *fmt, ...);
user/test/x86/sieve.c new file +89 -0

89 lines not on this page · raw message

user/test/x86/simple.S new file +13 -0
new file mode 100644
@@ -0,0 +1,13 @@
+
+	.text
+
+	mov $0, %al
+	mov $10000, %ebx
+1:
+	mov %rbx, %rcx
+2:	
+	loop 2b
+	out %al, $0x80
+	inc %al
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

user/test/x86/smp.c new file +151 -0

151 lines not on this page · raw message

user/test/x86/smp.h new file +16 -0
new file mode 100644

Lines of this file are not shown. View the raw message.

user/test/x86/smptest.c new file +32 -0
new file mode 100644

Lines of this file are not shown. View the raw message.

user/test/x86/stringio.S new file +31 -0
new file mode 100644

Lines of this file are not shown. View the raw message.

user/test/x86/test32.S new file +8 -0
new file mode 100644

Lines of this file are not shown. View the raw message.

user/test/x86/vm.c new file +249 -0

249 lines not on this page · raw message

user/test/x86/vm.h new file +9 -0
new file mode 100644

Lines of this file are not shown. View the raw message.

user/test/x86/vmexit.c new file +32 -0
new file mode 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

Part of the diff is not shown here. View the raw message.