Przeglądaj źródła

evx: lots of bugs, tab and values on i386 and returning on x86_64. holiday ends

rain 4 lat temu
rodzic
commit
a88a30d879

+ 1 - 1
arch/x86/.archcflags

@@ -1 +1 @@
--m64 -I/root/evx/arch/x86/include -I/root/evx/arch/x86/include64 
+-m32 -I/root/evx/arch/x86/include -I/root/evx/arch/x86/include32 

+ 4 - 62
arch/x86/include/arch/int.h

@@ -45,72 +45,14 @@ struct idt_entry {
 #endif
 } __attribute__ ((packed));
 
-#if CONFIG_64BIT
-
-#define IRQ_SAVE_REGS 		\
-	"pushfq\n\t"		\
-	"pushq %rax\n\t"	\
-	"pushq %rcx\n\t"	\
-	"pushq %rbx\n\t"	\
-	"pushq %rdx\n\t"	\
-	"pushq %rbp\n\t"	\
-	"pushq %rsi\n\t"	\
-	"pushq %rdi\n\t"	\
-	"pushq %r8\n\t"		\
-	"pushq %r9\n\t"		\
-	"pushq %r10\n\t"	\
-	"pushq %r11\n\t"	\
-	"pushq %r12\n\t"	\
-	"pushq %r13\n\t"	\
-	"pushq %r14\n\t"	\
-	"pushq %r15\n\t"	\
-	"movq %ds, %rax\n\t"	\
-	"pushq %rax\n\t"	\
-	"movq %es, %rax\n\t"	\
-	"pushq %rax\n\t"	\
-	"movq %fs, %rax\n\t" 	\
-	"pushq %rax\n\t"	\
-	"movq %gs, %rax\n\t"	\
-	"pushq %rax\n\t"	\
-	"movq $0x10, %rax\n\t"	\
-	"movq %rax, %ds\n\t"	\
-	"movq %rax, %es\n\t"	\
-	"movq %rax, %gs\n\t"	\
-	"movq %rax, %fs\n\t"
-
-#else
-
-#define IRQ_SAVE_REGS		\
-	"pushfl\n\t"		\
-	"pushl %eax\n\t"	\
-	"pushl %ecx\n\t"	\
-	"pushl %ebx\n\t"	\
-	"pushl %edx\n\t"	\
-	"pushl %ebp\n\t"	\
-	"pushl %esi\n\t"	\
-	"pushl %edi\n\t"	\
-	"movl %ds, %eax\n\t"	\
-	"pushl %eax\n\t"	\
-	"movl %es, %eax\n\t"	\
-	"pushl %eax\n\t"	\
-	"movl %fs, %eax\n\t"	\
-	"pushl %eax\n\t"	\
-	"movl %gs, %eax\n\t"	\
-	"pushl %eax\n\t"	\
-	"movl $0x10, %eax\n\t"	\
-	"movl %eax, %ds\n\t"	\
-	"movl %eax, %es\n\t"	\
-	"movl %eax, %fs\n\t"	\
-	"movl %eax, %gs\n\t"
-
-#endif
 
 struct registers {
-	__archptr_t 	flags, ax, cx, bx, dx, bp, si, di, 
+	__archptr_t 	gs, fs, es, ds;
 #if CONFIG_64BIT
-			r8, r9, r10, r11, r12, r13, r14, r15, 
+	__archptr_t 	r15, r14, r13, r12, r11, r10, r9, r8;
 #endif
-			ds, es, fs, gs;
+	__archptr_t 	di, si, bp, dx, bx, cx, ax;
+	__archptr_t 	errcode, ip, cs, flags, sp, ss;
 };
 
 #endif

+ 1 - 1
arch/x86/init/head32.S

@@ -106,7 +106,7 @@ ret_intr:
 	popl %ecx
 	popl %eax
 
-	popfl
+	addl $4, %esp
 
 	iretl
 	

+ 2 - 1
arch/x86/init/head64.S

@@ -171,7 +171,8 @@ ret_intr:
 	popq %rcx
 	popq %rax
 
-	popfq
+/* errrcode */
+	addq $8, %rsp
 
 	iretq
 

+ 170 - 15
arch/x86/kernel/arch_int.c

@@ -27,6 +27,7 @@
 
 #include <arch/archinfo.h>
 #include <arch/mm.h>
+#include <arch/asm.h>
 #include <arch/int.h>
 #include <arch/string.h>
 
@@ -44,7 +45,7 @@
 extern struct idt_entry idt[256];
 
 extern void ret_intr(void);
-int do_trap(int nr);
+int do_trap(int nr, __archptr_t sp);
 static int set_gate(struct idt_entry *, void (*) (void), int attr);
 
 #define set_int_gate(nr, handler) 	set_gate(idt + nr, handler, 0x8e)
@@ -55,31 +56,156 @@ static int set_gate(struct idt_entry *, void (*) (void), int attr);
 
 /* errcodes later */
 
-#define build_trap_entry(nr) 			\
+__asm__ (
+		".globl common_trap\n\t"
+	"common_trap:\n\t"
+	/* rax already saved */
+		"pushq %rcx\n\t"
+		"pushq %rbx\n\t"
+		"pushq %rdx\n\t"
+		"pushq %rbp\n\t"
+		"pushq %rsi\n\t"
+		"pushq %rdi\n\t"
+		"pushq %r8\n\t"
+		"pushq %r9\n\t"
+		"pushq %r10\n\t"
+		"pushq %r11\n\t"
+		"pushq %r12\n\t"
+		"pushq %r13\n\t"
+		"pushq %r14\n\t"
+		"pushq %r15\n\t"
+		"movq %rax, %rdi\n\t"
+
+		"movq %ds, %rax\n\t"
+		"pushq %rax\n\t"
+		"movq %es, %rax\n\t"
+		"pushq %rax\n\t"
+		"movq %fs, %rax\n\t"
+		"pushq %rax\n\t"
+		"movq %gs, %rax\n\t"
+		"pushq %rax\n\t"
+
+		"movq $0x10, %rax\n\t"
+		"movq %rax, %ds\n\t"
+		"movq %rax, %es\n\t"
+		"movq %rax, %fs\n\t"
+		"movq %rax, %gs\n\t"
+		"movq %rax, %ss\n\t"
+
+		"movq %rsp, %rsi\n\t"
+		"pushq ret_intr(%rip)\n\t"
+		"jmp do_trap\n\t"
+);
+
+#define build_trap_entry_errcode(nr) 		\
 	void trap_##nr##_entry(void); 		\
 	__asm__ (				\
 		".globl trap_"#nr"_entry\n\t" 	\
 		"trap_"#nr"_entry:\n\t"		\
-		IRQ_SAVE_REGS			\
-		"movq $"#nr", %rdi\n\t"		\
-		"pushq ret_intr(%rip)\n\t"	\
-		"jmp do_trap\n\t"		\
+		"cli\n\t"			\
+		"pushq %rax\n\t"		\
+		"movq $"#nr", %rax\n\t"		\
+		"jmp common_trap\n\t"		\
 	);
+
+#define build_trap_entry_nerrcode(nr) 		\
+	void trap_##nr##_entry(void);		\
+	__asm__ (				\
+		".globl trap_"#nr"_entry\n\t"	\
+		"trap_"#nr"_entry:\n\t"		\
+		"cli\n\t"			\
+		"pushq $0\n\t"			\
+		"pushq %rax\n\t"		\
+		"movq $"#nr", %rax\n\t"		\
+		"jmp common_trap\n\t"		\
+	)
 #else
 
-#define build_trap_entry(nr) 			\
+__asm__ (
+		".globl common_trap\n\t"
+	"common_trap:\n\t"
+		"pushl %ecx\n\t"
+		"pushl %ebx\n\t"
+		"pushl %edx\n\t"
+		"pushl %ebp\n\t"
+		"pushl %esi\n\t"
+		"pushl %edi\n\t"
+
+		"movl %eax, %edi\n\t"
+		"movl %ds, %eax\n\t"
+		"pushl %eax\n\t"
+		"movl %es, %eax\n\t"
+		"pushl %eax\n\t"
+		"movl %fs, %eax\n\t"
+		"pushl %eax\n\t"
+		"movl %gs, %eax\n\t"
+		"pushl %eax\n\t"
+
+		"movl $0x10, %eax\n\t"
+		"movl %eax, %ds\n\t"
+		"movl %eax, %es\n\t"
+		"movl %eax, %fs\n\t"
+		"movl %eax, %gs\n\t"
+		"movl %eax, %ss\n\t"
+
+		"movl %esp, %esi\n\t"
+		"pushl %esi\n\t"
+		"pushl %edi\n\t"
+		"call do_trap\n\t"
+		"addl $8, %esp\n\t"
+		"jmp ret_intr\n\t"
+);
+
+
+#define build_trap_entry_errcode(nr) 		\
 	void trap_##nr##_entry(void); 		\
 	__asm__ (				\
 		".globl trap_"#nr"_entry\n\t"	\
 		"trap_"#nr"_entry:\n\t"		\
-		"pushl $"#nr"\n\t"		\
-		"call do_trap\n\t"		\
-		"addl $4, %esp\n\t"		\
-		"jmp ret_intr\n\t"		\
+		"cli\n\t"			\
+		"pushl %eax\n\t"		\
+		"movl $"#nr", %eax\n\t"		\
+		"jmp common_trap\n\t"		\
 	);
+
+#define build_trap_entry_nerrcode(nr) 		\
+	void trap_##nr##_entry(void);		\
+	__asm__ (				\
+		".globl trap_"#nr"_entry\n\t"	\
+		"trap_"#nr"_entry:\n\t"		\
+		"cli\n\t"			\
+		"pushl $0\n\t"			\
+		"pushl %eax\n\t"		\
+		"movl $"#nr", %eax\n\t"		\
+		"jmp common_trap\n\t"		\
+	)
+
 #endif
 
-#include "__build_traps_generated.c"
+
+build_trap_entry_nerrcode(0);
+build_trap_entry_nerrcode(1);
+build_trap_entry_nerrcode(2);
+build_trap_entry_nerrcode(3);
+build_trap_entry_nerrcode(4);
+build_trap_entry_nerrcode(5);
+build_trap_entry_nerrcode(6);
+build_trap_entry_nerrcode(7);
+build_trap_entry_errcode(8);
+build_trap_entry_nerrcode(9);
+build_trap_entry_errcode(10);
+build_trap_entry_errcode(11);
+build_trap_entry_errcode(12);
+build_trap_entry_errcode(13);
+build_trap_entry_errcode(14);
+build_trap_entry_nerrcode(15);
+build_trap_entry_nerrcode(16);
+build_trap_entry_errcode(17);
+build_trap_entry_nerrcode(18);
+build_trap_entry_nerrcode(19);
+build_trap_entry_nerrcode(20);
+
+
 
 
 /* set the handlers for traps, 0 - 31 */
@@ -120,11 +246,40 @@ const static char *trap_msg[32] = {
 	"reserved"
 };
 
-int do_trap(int nr) {
-	kmlog("Oops! trap %d: %s\n", nr, trap_msg[nr]);
+
+int do_trap(int nr, __archptr_t sp) {
+	struct registers *regs = (struct registers *) sp;
+
+	kmlog(KERN_ABANDON "Oops! trap %d: %s\n", nr, trap_msg[nr]);
+	kmlog(KERN_ABANDON "sp at %p\n", sp);
+
+	/* okay, we use wrong tabs in protected-mode but i think that's ok :-) */
+	kmlog(KERN_ABANDON "ax\t\t\tcx\t\t\tbx\n");
+	kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->ax, regs->cx, regs->bx);
+	kmlog(KERN_ABANDON "dx\t\t\tbp\t\t\tsp\n");
+	kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->dx, regs->bp, regs->sp);
+
+#if CONFIG_64BIT
+	kmlog(KERN_ABANDON "si\t\t\tdi\t\t\tr8\n");
+	kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->si, regs->di, regs->r8);
+
+	kmlog(KERN_ABANDON "r9\t\t\tr10\t\t\tr11\n");
+	kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->r9, regs->r10, regs->r11);
+	kmlog(KERN_ABANDON "r12\t\t\tr13\t\t\tr14\n");
+	kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->r12, regs->r13, regs->r14);
+	kmlog(KERN_ABANDON "r15\n%d\n", regs->r15);
+
+#else
+	kmlog(KERN_ABANDON "si\t\t\tdi\n");
+	kmlog(KERN_ABANDON "%p\t%p\n", regs->si, regs->di);
+#endif
+	kmlog(KERN_ABANDON "ds: \t\t%p\n", regs->ds);
+	kmlog(KERN_ABANDON "ss: \t\t%p\n", regs->ss);
+	kmlog(KERN_ABANDON "flags: \t\t%p\n", regs->flags);
+	kmlog(KERN_ABANDON "cs:ip: \t\t%d:%p\n", regs->cs, regs->ip);
 
 	for (;;) 
-		;
+		cpu_relax();
 
 	return 0;
 }

+ 1 - 7
arch/x86/kernel/generate.py

@@ -18,16 +18,10 @@
 
 import sys
 
-sys.stdout = open("__build_traps_generated.c", "w")
-
-for i in range(0, 32):
-    print("build_trap_entry(%d);" % i)
-
-sys.stdout.close()
 
 sys.stdout = open("__arch_traps_generated.c", "w")
 
-for i in range(0, 32):
+for i in range(0, 21):
     print("\tset_trap_gate(%d, trap_%d_entry);" % (i, i))
 
 sys.stdout.close()

+ 6 - 1
init/main.c

@@ -38,12 +38,17 @@ static int do_init_calls(void);
 
 
 int __init init(void) {
+	struct page *p = NULL;
+	int i;
+
 	init_state = STATE_INIT_CALLS;
 
 	do_init_calls();
-	cpu_irq_enable();
 
 	init_state = STATE_READY;
+
+	i = 1 / (long) p;
+	kmlog("%d\n", i);
 	
 	return 0;
 }