Procházet zdrojové kódy

evx: not working traps

rain před 4 roky
rodič
revize
1ba30c770e

+ 1 - 1
arch/x86/.archcflags

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

+ 1 - 1
arch/x86/Makefile

@@ -25,7 +25,7 @@ endif
 
 vmevx.o: $(PWD)/.objlist 
 	@$(MAKE) -C init/ BITS=$(BITS)
-	@cat $(PWD)/.objlist | xargs $(LD) -o vmevx.o -T vmevx$(BITS).lds 
+	@cat $(PWD)/.objlist | xargs $(LD) -o vmevx.o -T vmevx$(BITS).lds --no-relax 
 	@echo "LD                vmevx.o"
 
 vmevx.bin: vmevx.o

+ 67 - 0
arch/x86/include/arch/int.h

@@ -45,6 +45,73 @@ 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, 
+#if CONFIG_64BIT
+			r8, r9, r10, r11, r12, r13, r14, r15, 
+#endif
+			ds, es, fs, gs;
+};
 
 #endif
 #endif

+ 27 - 0
arch/x86/init/head32.S

@@ -82,6 +82,33 @@ rsidt: 	movl %eax, (%edi)
 default_int_handler:
 	incl 0xb8000
 	iretl
+
+.globl ret_intr
+
+ret_intr:
+	popl %eax
+	movl %eax, %gs
+
+	popl %eax
+	movl %eax, %fs
+
+	popl %eax
+	movl %eax, %es
+
+	popl %eax
+	movl %eax, %ds
+
+	popl %edi
+	popl %esi
+	popl %ebp
+	popl %edx
+	popl %ebx
+	popl %ecx
+	popl %eax
+
+	popfl
+
+	iretl
 	
 
 

+ 36 - 0
arch/x86/init/head64.S

@@ -139,6 +139,42 @@ default_int_handler:
 	incq 0xb8000
 	iretq
 
+.globl ret_intr
+
+ret_intr:
+	popq %rax
+	movq %rax, %gs
+
+	popq %rax
+	movq %rax, %fs
+
+	popq %rax
+	movq %rax, %es
+	
+	popq %rax
+	movq %rax, %ds
+
+	popq %r15
+	popq %r14
+	popq %r13
+	popq %r12
+	popq %r11
+	popq %r10
+	popq %r9
+	popq %r8
+
+	popq %rdi
+	popq %rsi
+	popq %rbp
+	popq %rdx
+	popq %rbx
+	popq %rcx
+	popq %rax
+
+	popfq
+
+	iretq
+
 
 .globl __stack_chk_fail
 

+ 2 - 0
arch/x86/kernel/Makefile

@@ -16,5 +16,7 @@ ifeq ($(D), )
 endif
 
 # $(PWD) is the / directory of kernel, e.g. /root/evx/
+	@python generate.py 
+	@echo "GEN               arch_int"
 	@$(MAKE) -C $(PWD) D=$(shell pwd) obj-i="$(obj-i)"
 

+ 77 - 1
arch/x86/kernel/arch_int.c

@@ -43,12 +43,88 @@
 
 extern struct idt_entry idt[256];
 
+extern void ret_intr(void);
+int do_trap(int nr);
 static int set_gate(struct idt_entry *, void (*) (void), int attr);
 
+#define set_int_gate(nr, handler) 	set_gate(idt + nr, handler, 0x8e)
+#define set_trap_gate(nr, handler) 	set_gate(idt + nr, handler, 0x8f)
+#define set_sys_gate(nr, handler) 	set_gate(idt + nr, handler, 0xef)
+
+#if CONFIG_64BIT
+
+/* errcodes later */
+
+#define build_trap_entry(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"		\
+	);
+#else
+
+#define build_trap_entry(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"		\
+	);
+#endif
+
+#include "__build_traps_generated.c"
+
+
 /* set the handlers for traps, 0 - 31 */
 
 int __init arch_traps_init(void) {
-	set_gate(idt + 0x80, NULL, 0x8e);
+#include "__arch_traps_generated.c"
+
+	return 0;
+}
+
+const static char *trap_msg[32] = {
+	"division by zero", 
+	"debug trap", 
+	"NMI", 
+	"breakpoint", 
+	"overflow", 
+	"bound", 
+	"invalid op-code", 
+	"device not avaliable", 
+	"double fault", 
+	"coprocessor segment overrun", 
+	"invalid tss", 
+	"segment not present", 
+	"stack-segment fault", 
+	"general protection", 
+	"page fault", 
+	"reserved", 
+	"x87 floating-point exception", 
+	"alignment check", 
+	"machine check", 
+	"simd floating-point exception", 
+	"virtualization exception", 
+	"control protection exception", 
+	"reserved", 
+	"hypervisor injection exception", 
+	"vmm communication exception", 
+	"security exception", 
+	"reserved"
+};
+
+int do_trap(int nr) {
+	kmlog("Oops! trap %d: %s\n", nr, trap_msg[nr]);
+
+	for (;;) 
+		;
 
 	return 0;
 }

+ 34 - 0
arch/x86/kernel/generate.py

@@ -0,0 +1,34 @@
+# arch/x86/kernel/generate.py
+# 
+# This file is part of evx. 
+# 
+# evx is free software: you can redistribute if and/or modify 
+# it under the terms of the GNU General Public License as published by 
+# the Free Software Foundation, either version 3 of the License, or 
+# (at your option) any later version. 
+# 
+# evx 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 evx. If not, see <https://www.gnu.org/licenses/>
+
+
+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):
+    print("\tset_trap_gate(%d, trap_%d_entry);" % (i, i))
+
+sys.stdout.close()
+

+ 0 - 32
docs/x86/memmap.md.back

@@ -1,32 +0,0 @@
-### memory used in boot-loader for evx
-
-#### 64-bits
--------------------------------------------------
-
-+ End of zones     Kernel mrmory page descriptors
-+ `&_end`          Kernel memory zone descriptors
-+ 0x00100000                               System
-+ 0x00090000                      E820 Memory Map
-+ 0x00090000                     Stack for kernel
-+ 0x00011000
-+ 0x00010000
-+ 0x0000f000
-+ 0x0000e000
-+ 0x0000d000
-+ 0x0000c000
-+ 0x0000b000
-+ 0x0000a000
-+ 0x00009000
-+ 0x00008000                    Loader and System
-+  0x00007e00           (By boot.lds) Boot Loader
-+  0x00007c00                          (Was) Boot
-+  0x00007c00                               Stack
-+ 0x00007000
-+ 0x00006000
-+ 0x00005000
-+ 0x00004000
-+ 0x00003000           End of 2M Page table lvl 3
-+ 0x00002000                  2M Page table lvl 3
-+ 0x00001000                     Page table lvl 2
-+ 0x00000000                     Page table lvl 1
-

+ 0 - 11
init/main.c

@@ -38,8 +38,6 @@ static int do_init_calls(void);
 
 
 int __init init(void) {
-	struct page *p;
-
 	init_state = STATE_INIT_CALLS;
 
 	do_init_calls();
@@ -47,15 +45,6 @@ int __init init(void) {
 
 	init_state = STATE_READY;
 	
-	p = getfreepages(10, 0);
-	kmlog(KERN_INFO "%p\n", p);
-
-	p = getfreepages(16, 0);
-	kmlog(KERN_INFO "%p\n", p);
-
-	p = getfreepages(50, 0);
-	kmlog(KERN_INFO "%p\n", p);
-
 	return 0;
 }