From 1e0e16d290fa8c73f468462274fa2ea2d2127a28 Mon Sep 17 00:00:00 2001 From: Malo Lecomte Date: Wed, 14 Jul 2021 20:39:59 +0200 Subject: [PATCH 01/11] feat(idt): add idt_entry, idt and idt_r structs --- k/idt.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 k/idt.h diff --git a/k/idt.h b/k/idt.h new file mode 100644 index 0000000..4bc9362 --- /dev/null +++ b/k/idt.h @@ -0,0 +1,35 @@ +#ifndef IDT_H +#define IDT_H + +#include + +#define IDT_NB_ENTRIES 32 +#define IDT_SIZE (IDT_NB_ENTRIES * sizeof(struct idt_entry)) + +struct idt_entry +{ + uint16_t offset_1 : 16; + uint16_t selector : 16; + + uint8_t zero : 8; // unused, set to 0 + uint8_t type : 3; // gate type + uint8_t size : 1; + uint8_t zero_2 : 1; // set to 0 for interrupt and trap gates + uint8_t desc_priv : 2; // Descriptor privilege + uint8_t present : 1; + + uint16_t offset_2 : 16; +} __attribute__ ((packed)); + +struct idt +{ + struct idt_entry entries[IDT_NB_ENTRIES]; +}; + +struct idt_r +{ + uint16_t limit; + uint32_t addr; +} __attribute__ ((packed)); + +#endif /* !IDT_H */ From 8162cb501182a898a11e07d0f142807ae7d6d093 Mon Sep 17 00:00:00 2001 From: Malo Lecomte Date: Wed, 14 Jul 2021 21:31:58 +0200 Subject: [PATCH 02/11] feat(idt): change selector to use segment_selector struct --- k/idt.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/k/idt.h b/k/idt.h index 4bc9362..c5613f0 100644 --- a/k/idt.h +++ b/k/idt.h @@ -2,6 +2,7 @@ #define IDT_H #include +#include "gdt.h" #define IDT_NB_ENTRIES 32 #define IDT_SIZE (IDT_NB_ENTRIES * sizeof(struct idt_entry)) @@ -9,9 +10,9 @@ struct idt_entry { uint16_t offset_1 : 16; - uint16_t selector : 16; + struct segment_selector selector; - uint8_t zero : 8; // unused, set to 0 + uint8_t zero_1 : 8; // unused, set to 0 uint8_t type : 3; // gate type uint8_t size : 1; uint8_t zero_2 : 1; // set to 0 for interrupt and trap gates From 48cc6590a9eb94f4b00286d32daf8a7ff7d93ea3 Mon Sep 17 00:00:00 2001 From: Malo Lecomte Date: Wed, 14 Jul 2021 21:32:15 +0200 Subject: [PATCH 03/11] feat(idt): add load_idt instructions --- k/idt.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 k/idt.c diff --git a/k/idt.c b/k/idt.c new file mode 100644 index 0000000..510a626 --- /dev/null +++ b/k/idt.c @@ -0,0 +1,20 @@ +#include "idt.h" + +static struct idt idt = { 0 }; + +static void load_idt() +{ + struct idt_r idtr; + idtr.addr = (uint32_t)&idt; + idtr.limit = IDT_SIZE - 1; + + asm volatile("lidt %0\n" + : + : "m" (idtr) + : "memory"); +} + +void init_idt() +{ + load_idt(); +} From 96610353c8b589af059f0c379858211c0237a94f Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Wed, 14 Jul 2021 22:57:38 +0200 Subject: [PATCH 04/11] feat(idt): add idt creation Signed-off-by: Julien CLEMENT --- k/Makefile | 3 ++- k/gdt.c | 16 ++++++++-------- k/gdt.h | 2 +- k/idt.c | 42 ++++++++++++++++++++++++++++++++++++++++-- k/idt.h | 4 ++++ k/k.c | 8 +++++--- 6 files changed, 60 insertions(+), 15 deletions(-) diff --git a/k/Makefile b/k/Makefile index 02ba1c9..4ed6e32 100644 --- a/k/Makefile +++ b/k/Makefile @@ -31,7 +31,8 @@ OBJS = \ list.o \ memory.o \ serial.o \ - gdt.o + gdt.o \ + idt.o DEPS = $(OBJS:.o=.d) diff --git a/k/gdt.c b/k/gdt.c index c8e0182..42b53eb 100644 --- a/k/gdt.c +++ b/k/gdt.c @@ -2,7 +2,7 @@ static struct gdt gdt = { 0 }; -static void create_kernel_ds() +static void create_kernel_ds(void) { struct gdt_entry *entry = gdt.entries + KERNEL_DS_INDEX; @@ -30,7 +30,7 @@ static void create_kernel_ds() entry->base_3 = (base >> 24) & 0xff; } -static void create_kernel_cs() +static void create_kernel_cs(void) { struct gdt_entry *entry = gdt.entries + KERNEL_CS_INDEX; @@ -58,13 +58,13 @@ static void create_kernel_cs() entry->base_3 = (base >> 24) & 0xff; } -static void create_gdt() +static void create_gdt(void) { create_kernel_ds(); create_kernel_cs(); } -static void load_gdt() +static void load_gdt(void) { struct gdt_r gdtr; gdtr.addr = (uint32_t)&gdt; @@ -76,7 +76,7 @@ static void load_gdt() : "memory"); } -static void load_ds() +static void load_ds(void) { struct segment_selector selector; selector.index = KERNEL_DS_INDEX; @@ -93,7 +93,7 @@ static void load_ds() : "ax"); } -static void load_cs() +static void load_cs(void) { struct segment_selector selector; selector.index = KERNEL_CS_INDEX; @@ -108,13 +108,13 @@ static void load_cs() : "m" (selector)); } -static void reload_segment_selectors() +static void reload_segment_selectors(void) { load_ds(); load_cs(); } -void init_gdt() +void init_gdt(void) { create_gdt(); load_gdt(); diff --git a/k/gdt.h b/k/gdt.h index c2833cd..7704d0b 100644 --- a/k/gdt.h +++ b/k/gdt.h @@ -60,6 +60,6 @@ struct segment_selector uint16_t index : 13; // index of the entry in the table } __attribute__ ((packed)); -void init_gdt(); +void init_gdt(void); #endif /* !GDT_H */ diff --git a/k/idt.c b/k/idt.c index 510a626..0a2d74c 100644 --- a/k/idt.c +++ b/k/idt.c @@ -2,7 +2,44 @@ static struct idt idt = { 0 }; -static void load_idt() +void handle_interrupt() +{ + return; +} + +struct idt_entry create_idt_entry(uint32_t offset, + struct segment_selector selector) +{ + struct idt_entry res = { 0 }; + + res.selector = selector; + res.offset_1 = offset & 0xffff; + res.offset_2 = (offset >> 16) & 0xffff; + + res.type = INTERRUPT_TYPE; + res.size = 1; + res.desc_priv = 0; + res.present = 1; + + return res; +} + +static void create_idt(void) +{ + struct segment_selector selector; + selector.rpl = 0; + selector.table_indicator = 0; + selector.index = KERNEL_CS_INDEX; + for (int i = 0; i < IDT_NB_ENTRIES; ++i) + { + struct idt_entry entry = create_idt_entry((uint32_t)&handle_interrupt, + selector); + idt.entries[i] = entry; + } +} + + +static void load_idt(void) { struct idt_r idtr; idtr.addr = (uint32_t)&idt; @@ -14,7 +51,8 @@ static void load_idt() : "memory"); } -void init_idt() +void init_idt(void) { + create_idt(); load_idt(); } diff --git a/k/idt.h b/k/idt.h index c5613f0..39a1857 100644 --- a/k/idt.h +++ b/k/idt.h @@ -7,6 +7,8 @@ #define IDT_NB_ENTRIES 32 #define IDT_SIZE (IDT_NB_ENTRIES * sizeof(struct idt_entry)) +#define INTERRUPT_TYPE 0x6 + struct idt_entry { uint16_t offset_1 : 16; @@ -33,4 +35,6 @@ struct idt_r uint32_t addr; } __attribute__ ((packed)); +void init_idt(void); + #endif /* !IDT_H */ diff --git a/k/k.c b/k/k.c index 40a4ae5..ff57813 100644 --- a/k/k.c +++ b/k/k.c @@ -23,15 +23,17 @@ */ #include -#include "multiboot.h" -#include "stdio.h" -#include "serial.h" #include "gdt.h" +#include "idt.h" +#include "multiboot.h" +#include "serial.h" +#include "stdio.h" static void k_init(void) { init_serial(); init_gdt(); + init_idt(); } void k_main(unsigned long magic, multiboot_info_t *info) From 10896fe2e9efab2b7df5f7889ae05e9286e6cce5 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Fri, 16 Jul 2021 02:46:07 +0200 Subject: [PATCH 05/11] feat(isr): add basic isr wrappers Signed-off-by: Julien CLEMENT --- k/isr.h | 32 +++++++++++++++++ k/isr.s | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 k/isr.h create mode 100644 k/isr.s diff --git a/k/isr.h b/k/isr.h new file mode 100644 index 0000000..1d5c8a6 --- /dev/null +++ b/k/isr.h @@ -0,0 +1,32 @@ +#ifndef ISR_H +#define ISR_H + +struct isr_param +{ + uint32_t int_vector; + uint32_t error_code; +} __attribute__ ((packed)); + +void isr_divide(void); +void isr_debug(void); +void isr_nmi(void); +void isr_breakpoint(void); +void isr_overflow(void); +void isr_bound_range_exceeded(void); +void isr_invalid_opcode(void); +void isr_device_not_available(void); +void isr_double_fault(void); +void isr_coprocessor_segment_overrun(void); +void isr_invalid_tss(void); +void isr_segment_not_present(void); +void isr_stack_segment_fault(void); +void isr_general_protection(void); +void isr_page_fault(void); +void isr_fpu_floating_point_error(void); +void isr_alignment_check(void); +void isr_machine_check(void); +void isr_simd_floating_point_exception(void); +void isr_virtualization_exception(void); +void isr_control_protection_exception(void); + +#endif /* !ISR_H */ diff --git a/k/isr.s b/k/isr.s new file mode 100644 index 0000000..3b1eeb1 --- /dev/null +++ b/k/isr.s @@ -0,0 +1,107 @@ +.section .text + +isr: + pushal + pushl %esp + add $32, (%esp) + call interrupt_handler + add $4, %esp + popal + iret + +.global isr_divide: + pushl $0 ; error code padding + pushl $0 ; int vector + jmp isr + +.global isr_debug: + pushl $0 ; error code padding + pushl $1 ; int vector + jmp isr + +.global isr_nmi: + pushl $0 ; error code padding + pushl $2 ; int vector + jmp isr + +.global isr_breakpoint: + pushl $0 ; error code padding + pushl $3 ; int vector + jmp isr + +.global isr_overflow: + pushl $0 ; error code padding + pushl $4 ; int vector + jmp isr + +.global isr_bound_range_exceeded: + pushl $0 ; error code padding + pushl $5 ; int vector + jmp isr + +.global isr_invalid_opcode: + pushl $0 ; error code padding + pushl $6 ; int vector + jmp isr + +.global isr_device_not_available: + pushl $0 ; error code padding + pushl $7 ; int vector + jmp isr + +.global isr_double_fault: + pushl $8 ; int vector + jmp isr + +.global isr_coprocessor_segment_overrun: + pushl $0 ; error code padding + pushl $9 ; int vector + jmp isr + +.global isr_invalid_tss: + pushl $10 ; int vector + jmp isr + +.global isr_segment_not_present: + pushl $11 ; int vector + jmp isr + +.global isr_stack_segment_fault: + pushl $12 ; int vector + jmp isr + +.global isr_general_protection: + pushl $13 ; int vector + jmp isr + +.global isr_page_fault: + pushl $14 ; int vector + jmp isr + +.global isr_fpu_floating_point_error: + pushl $0 ; error code padding + pushl $16 ; int vector + jmp isr + +.global isr_alignment_check: + pushl $17 ; int vector + jmp isr + +.global isr_machine_check: + pushl $0 ; error code padding + pushl $18 ; int vector + jmp isr + +.global isr_simd_floating_point_exception: + pushl $0 ; error code padding + pushl $19 ; int vector + jmp isr + +.global isr_virtualization_exception: + pushl $0 ; error code padding + pushl $20 ; int vector + jmp isr + +.global isr_control_protection_exception: + pushl $21 ; int vector + jmp isr From ed803673c4d549d6a072d85055be9d58670ed9ec Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Fri, 16 Jul 2021 02:46:28 +0200 Subject: [PATCH 06/11] feat(isr): add isr wrappers in makefile Signed-off-by: Julien CLEMENT --- k/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/k/Makefile b/k/Makefile index 4ed6e32..388d54c 100644 --- a/k/Makefile +++ b/k/Makefile @@ -32,7 +32,8 @@ OBJS = \ memory.o \ serial.o \ gdt.o \ - idt.o + idt.o \ + isr.o DEPS = $(OBJS:.o=.d) From 02811acc2cad5bda6c4c29d8905e436ba4320e20 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Fri, 16 Jul 2021 02:47:12 +0200 Subject: [PATCH 07/11] feat(gdt): add macros for generic kernel segment descriptors Signed-off-by: Julien CLEMENT --- k/gdt.c | 10 ++-------- k/gdt.h | 3 +++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/k/gdt.c b/k/gdt.c index 42b53eb..507795f 100644 --- a/k/gdt.c +++ b/k/gdt.c @@ -78,10 +78,7 @@ static void load_gdt(void) static void load_ds(void) { - struct segment_selector selector; - selector.index = KERNEL_DS_INDEX; - selector.table_indicator = 0; - selector.rpl = 0; + struct segment_selector selector = KERNEL_DS_SEGMENT_SELECTOR; asm volatile("movw %0, %%ax\n" "movw %%ax, %%ds\n" @@ -95,10 +92,7 @@ static void load_ds(void) static void load_cs(void) { - struct segment_selector selector; - selector.index = KERNEL_CS_INDEX; - selector.table_indicator = 0; - selector.rpl = 0; + struct segment_selector selector = KERNEL_CS_SEGMENT_SELECTOR; asm volatile("pushl %0\n" "pushl $1f\n" diff --git a/k/gdt.h b/k/gdt.h index 7704d0b..3a0f9fc 100644 --- a/k/gdt.h +++ b/k/gdt.h @@ -9,6 +9,9 @@ #define KERNEL_CS_INDEX 1 #define KERNEL_DS_INDEX 2 +#define KERNEL_CS_SEGMENT_SELECTOR {0, 0, KERNEL_CS_INDEX} +#define KERNEL_DS_SEGMENT_SELECTOR {0, 0, KERNEL_DS_INDEX} + struct gdt_entry { uint16_t limit_1 : 16; // 16 lsbs of the segment limit From af24d0f18a8fe5d9b33b490f4679c12314a27f63 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Fri, 16 Jul 2021 02:57:13 +0200 Subject: [PATCH 08/11] feat(idt): add idt creation through idt entries descriptors Signed-off-by: Julien CLEMENT --- k/idt.c | 58 +++++++++++++++++++++++++++++++++++++++++++-------------- k/idt.h | 11 +++++++++++ 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/k/idt.c b/k/idt.c index 0a2d74c..5975f40 100644 --- a/k/idt.c +++ b/k/idt.c @@ -1,22 +1,57 @@ #include "idt.h" +#include "stdio.h" static struct idt idt = { 0 }; -void handle_interrupt() +static struct idt_entry_descriptor idt_entries_descriptors[] = { + {(uint32_t)&isr_divide, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 0 + {(uint32_t)&isr_debug, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 1 + {(uint32_t)&isr_nmi, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 2 + {(uint32_t)&isr_breakpoint, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 3 + {(uint32_t)&isr_overflow, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 4 + {(uint32_t)&isr_bound_range_exceeded, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 5 + {(uint32_t)&isr_invalid_opcode, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 6 + {(uint32_t)&isr_device_not_available, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 7 + {(uint32_t)&isr_double_fault, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 8 + {(uint32_t)&isr_coprocessor_segment_overrun, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 9 + {(uint32_t)&isr_invalid_tss, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 10 + {(uint32_t)&isr_segment_not_present, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 11 + {(uint32_t)&isr_stack_segment_fault, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 12 + {(uint32_t)&isr_general_protection, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 13 + {(uint32_t)&isr_page_fault, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 14 + {0, {0, 0, 0}, 0}, // 15 + {(uint32_t)&isr_fpu_floating_point_error, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 16 + {(uint32_t)&isr_alignment_check, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 17 + {(uint32_t)&isr_machine_check, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 18 + {(uint32_t)&isr_simd_floating_point_exception, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 19 + {(uint32_t)&isr_virtualization_exception, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 20 + {(uint32_t)&isr_control_protection_exception, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 21 + {0, {0, 0, 0}, 0}, // 22 + {0, {0, 0, 0}, 0}, // 23 + {0, {0, 0, 0}, 0}, // 24 + {0, {0, 0, 0}, 0}, // 25 + {0, {0, 0, 0}, 0}, // 26 + {0, {0, 0, 0}, 0}, // 27 + {0, {0, 0, 0}, 0}, // 28 + {0, {0, 0, 0}, 0}, // 29 + {0, {0, 0, 0}, 0}, // 30 + {0, {0, 0, 0}, 0} // 31 +}; + +void interrupt_handler(struct isr_param *isr_param) { - return; + printf("Oh no %d!\r\n", isr_param->int_vector); } -struct idt_entry create_idt_entry(uint32_t offset, - struct segment_selector selector) +struct idt_entry create_idt_entry(struct idt_entry_descriptor descriptor) { struct idt_entry res = { 0 }; - res.selector = selector; - res.offset_1 = offset & 0xffff; - res.offset_2 = (offset >> 16) & 0xffff; + res.selector = descriptor.selector; + res.offset_1 = descriptor.offset & 0xffff; + res.offset_2 = (descriptor.offset >> 16) & 0xffff; - res.type = INTERRUPT_TYPE; + res.type = descriptor.type; res.size = 1; res.desc_priv = 0; res.present = 1; @@ -26,14 +61,9 @@ struct idt_entry create_idt_entry(uint32_t offset, static void create_idt(void) { - struct segment_selector selector; - selector.rpl = 0; - selector.table_indicator = 0; - selector.index = KERNEL_CS_INDEX; for (int i = 0; i < IDT_NB_ENTRIES; ++i) { - struct idt_entry entry = create_idt_entry((uint32_t)&handle_interrupt, - selector); + struct idt_entry entry = create_idt_entry(idt_entries_descriptors[i]); idt.entries[i] = entry; } } diff --git a/k/idt.h b/k/idt.h index 39a1857..2d6c276 100644 --- a/k/idt.h +++ b/k/idt.h @@ -3,11 +3,13 @@ #include #include "gdt.h" +#include "isr.h" #define IDT_NB_ENTRIES 32 #define IDT_SIZE (IDT_NB_ENTRIES * sizeof(struct idt_entry)) #define INTERRUPT_TYPE 0x6 +#define TRAP_TYPE 0x7 struct idt_entry { @@ -35,6 +37,15 @@ struct idt_r uint32_t addr; } __attribute__ ((packed)); +struct idt_entry_descriptor +{ + uint32_t offset; + struct segment_selector selector; + char type; +}; + void init_idt(void); +void interrupt_handler(struct isr_param *isr_param); + #endif /* !IDT_H */ From 4492b7e9d674b20cb3296ce6ac5069944b74b0e6 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Fri, 16 Jul 2021 03:03:20 +0200 Subject: [PATCH 09/11] feat(isr): learnt to do assembly Signed-off-by: Julien CLEMENT --- k/isr.S | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ k/isr.s | 107 ---------------------------------------------- 2 files changed, 128 insertions(+), 107 deletions(-) create mode 100644 k/isr.S delete mode 100644 k/isr.s diff --git a/k/isr.S b/k/isr.S new file mode 100644 index 0000000..184cdd5 --- /dev/null +++ b/k/isr.S @@ -0,0 +1,128 @@ +.section .text + +isr: + pushal + pushl %esp + add $32, (%esp) + call interrupt_handler + add $4, %esp + popal + iret + +.global isr_divide +isr_divide: + pushl $0 // error code padding + pushl $0 // int vector + jmp isr + +.global isr_debug +isr_debug: + pushl $0 // error code padding + pushl $1 // int vector + jmp isr + +.global isr_nmi +isr_nmi: + pushl $0 // error code padding + pushl $2 // int vector + jmp isr + +.global isr_breakpoint +isr_breakpoint: + pushl $0 // error code padding + pushl $3 // int vector + jmp isr + +.global isr_overflow +isr_overflow: + pushl $0 // error code padding + pushl $4 // int vector + jmp isr + +.global isr_bound_range_exceeded +isr_bound_range_exceeded: + pushl $0 // error code padding + pushl $5 // int vector + jmp isr + +.global isr_invalid_opcode +isr_invalid_opcode: + pushl $0 // error code padding + pushl $6 // int vector + jmp isr + +.global isr_device_not_available +isr_device_not_available: + pushl $0 // error code padding + pushl $7 // int vector + jmp isr + +.global isr_double_fault +isr_double_fault: + pushl $8 // int vector + jmp isr + +.global isr_coprocessor_segment_overrun +isr_coprocessor_segment_overrun: + pushl $0 // error code padding + pushl $9 // int vector + jmp isr + +.global isr_invalid_tss +isr_invalid_tss: + pushl $10 // int vector + jmp isr + +.global isr_segment_not_present +isr_segment_not_present: + pushl $11 // int vector + jmp isr + +.global isr_stack_segment_fault +isr_stack_segment_fault: + pushl $12 // int vector + jmp isr + +.global isr_general_protection +isr_general_protection: + pushl $13 // int vector + jmp isr + +.global isr_page_fault +isr_page_fault: + pushl $14 // int vector + jmp isr + +.global isr_fpu_floating_point_error +isr_fpu_floating_point_error: + pushl $0 // error code padding + pushl $16 // int vector + jmp isr + +.global isr_alignment_check +isr_alignment_check: + pushl $17 // int vector + jmp isr + +.global isr_machine_check +isr_machine_check: + pushl $0 // error code padding + pushl $18 // int vector + jmp isr + +.global isr_simd_floating_point_exception +isr_simd_floating_point_exception: + pushl $0 // error code padding + pushl $19 // int vector + jmp isr + +.global isr_virtualization_exception +isr_virtualization_exception: + pushl $0 // error code padding + pushl $20 // int vector + jmp isr + +.global isr_control_protection_exception +isr_control_protection_exception: + pushl $21 // int vector + jmp isr diff --git a/k/isr.s b/k/isr.s deleted file mode 100644 index 3b1eeb1..0000000 --- a/k/isr.s +++ /dev/null @@ -1,107 +0,0 @@ -.section .text - -isr: - pushal - pushl %esp - add $32, (%esp) - call interrupt_handler - add $4, %esp - popal - iret - -.global isr_divide: - pushl $0 ; error code padding - pushl $0 ; int vector - jmp isr - -.global isr_debug: - pushl $0 ; error code padding - pushl $1 ; int vector - jmp isr - -.global isr_nmi: - pushl $0 ; error code padding - pushl $2 ; int vector - jmp isr - -.global isr_breakpoint: - pushl $0 ; error code padding - pushl $3 ; int vector - jmp isr - -.global isr_overflow: - pushl $0 ; error code padding - pushl $4 ; int vector - jmp isr - -.global isr_bound_range_exceeded: - pushl $0 ; error code padding - pushl $5 ; int vector - jmp isr - -.global isr_invalid_opcode: - pushl $0 ; error code padding - pushl $6 ; int vector - jmp isr - -.global isr_device_not_available: - pushl $0 ; error code padding - pushl $7 ; int vector - jmp isr - -.global isr_double_fault: - pushl $8 ; int vector - jmp isr - -.global isr_coprocessor_segment_overrun: - pushl $0 ; error code padding - pushl $9 ; int vector - jmp isr - -.global isr_invalid_tss: - pushl $10 ; int vector - jmp isr - -.global isr_segment_not_present: - pushl $11 ; int vector - jmp isr - -.global isr_stack_segment_fault: - pushl $12 ; int vector - jmp isr - -.global isr_general_protection: - pushl $13 ; int vector - jmp isr - -.global isr_page_fault: - pushl $14 ; int vector - jmp isr - -.global isr_fpu_floating_point_error: - pushl $0 ; error code padding - pushl $16 ; int vector - jmp isr - -.global isr_alignment_check: - pushl $17 ; int vector - jmp isr - -.global isr_machine_check: - pushl $0 ; error code padding - pushl $18 ; int vector - jmp isr - -.global isr_simd_floating_point_exception: - pushl $0 ; error code padding - pushl $19 ; int vector - jmp isr - -.global isr_virtualization_exception: - pushl $0 ; error code padding - pushl $20 ; int vector - jmp isr - -.global isr_control_protection_exception: - pushl $21 ; int vector - jmp isr From 457dfdd7a4693444170d350ce7df01a1fd4ccdb8 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Fri, 16 Jul 2021 03:07:46 +0200 Subject: [PATCH 10/11] feat(idt): specify idt_entries_descriptors length for compile safety Signed-off-by: Julien CLEMENT --- k/idt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k/idt.c b/k/idt.c index 5975f40..7392c42 100644 --- a/k/idt.c +++ b/k/idt.c @@ -3,7 +3,7 @@ static struct idt idt = { 0 }; -static struct idt_entry_descriptor idt_entries_descriptors[] = { +static struct idt_entry_descriptor idt_entries_descriptors[IDT_NB_ENTRIES] = { {(uint32_t)&isr_divide, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 0 {(uint32_t)&isr_debug, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 1 {(uint32_t)&isr_nmi, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 2 From e425051af74fb79ab49edff93fb813dc176b8305 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Fri, 16 Jul 2021 15:11:48 +0200 Subject: [PATCH 11/11] fix(isr): reallign stack after isr wrapper Signed-off-by: Julien CLEMENT --- k/Makefile | 2 +- k/isr.S | 1 + k/k.c | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/k/Makefile b/k/Makefile index 388d54c..99c5520 100644 --- a/k/Makefile +++ b/k/Makefile @@ -41,7 +41,7 @@ DEPS = $(OBJS:.o=.d) all: $(TARGET) $(TARGET): CPPFLAGS += -MMD -Iinclude -I ../libs/libc/include/ -$(TARGET): CFLAGS += $(K_EXTRA_CFLAGS) +$(TARGET): CFLAGS += $(K_EXTRA_CFLAGS) -g $(TARGET): LDFLAGS += -Wl,-Tk.lds $(TARGET): LDLIBS = -L../libs/libc -lc $(TARGET): $(OBJS) diff --git a/k/isr.S b/k/isr.S index 184cdd5..09ff49c 100644 --- a/k/isr.S +++ b/k/isr.S @@ -7,6 +7,7 @@ isr: call interrupt_handler add $4, %esp popal + add $8, %esp iret .global isr_divide diff --git a/k/k.c b/k/k.c index ff57813..5e7c1f4 100644 --- a/k/k.c +++ b/k/k.c @@ -45,8 +45,14 @@ void k_main(unsigned long magic, multiboot_info_t *info) char *fb = (void *)0xb8000; k_init(); - + asm volatile("int $3\n" + : + : + :); printf("bonjour\r\n"); + + + for (unsigned i = 0; ; ) { *fb = star[i++ % 4]; }