diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-12 10:13:21 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-12 10:13:21 +0200 |
| commit | 39713a3736145483dd3310c3605f940ca34f05c3 (patch) | |
| tree | d4dcdf0f3b667a5d706aa4b04501a71facf186bd | |
| parent | 6edeba8fe208fb019aec00fdc72b97407a8078d3 (diff) | |
Refactoring
| -rw-r--r-- | src/Makefile | 4 | ||||
| -rw-r--r-- | src/boot/multiboot.c | 1 | ||||
| -rw-r--r-- | src/boot/multiboot.h | 5 | ||||
| -rw-r--r-- | src/bringelle.c | 14 | ||||
| -rw-r--r-- | src/core/asm.h (renamed from src/utils/asm.h) | 0 | ||||
| -rw-r--r-- | src/core/framebuffer.c (renamed from src/utils/framebuffer.c) | 0 | ||||
| -rw-r--r-- | src/core/framebuffer.h (renamed from src/utils/framebuffer.h) | 8 | ||||
| -rw-r--r-- | src/core/gdt.c (renamed from src/utils/gdt.c) | 0 | ||||
| -rw-r--r-- | src/core/gdt.h (renamed from src/utils/gdt.h) | 0 | ||||
| -rw-r--r-- | src/core/mem.c (renamed from src/utils/mem.c) | 0 | ||||
| -rw-r--r-- | src/core/mem.h (renamed from src/utils/mem.h) | 3 | ||||
| -rw-r--r-- | src/core/paging.c (renamed from src/utils/paging.c) | 0 | ||||
| -rw-r--r-- | src/core/paging.h (renamed from src/utils/paging.h) | 3 | ||||
| -rw-r--r-- | src/core/syscall.c (renamed from src/utils/syscall.c) | 0 | ||||
| -rw-r--r-- | src/core/syscall.h (renamed from src/utils/syscall.h) | 3 | ||||
| -rw-r--r-- | src/core/types.h (renamed from src/utils/types.h) | 2 | ||||
| -rw-r--r-- | src/int/8042.c | 4 | ||||
| -rw-r--r-- | src/int/8042.h | 2 | ||||
| -rw-r--r-- | src/int/idt.c | 39 | ||||
| -rw-r--r-- | src/int/idt.h | 32 | ||||
| -rw-r--r-- | src/int/int.S | 72 | ||||
| -rw-r--r-- | src/int/pic.c | 99 | ||||
| -rw-r--r-- | src/int/pic.h | 22 | ||||
| -rw-r--r-- | src/libc/stdio.h | 2 |
24 files changed, 187 insertions, 128 deletions
diff --git a/src/Makefile b/src/Makefile index 2151883..3643f77 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,14 +6,14 @@ LD_SCRIPT := linker.ld # Indeed boot.o generated by boot.S should appear # first in the kernel binary (thus it must be linked first, cf the $(EXEC) rule) BOOT_OBJ := $(addsuffix .o,$(basename $(shell find ./boot -name "*.[c|S]" ! -name "boot.S"))) -UTILS_OBJ := $(addsuffix .o,$(basename $(shell find ./utils -name "*.[c|S]"))) +CORE_OBJ := $(addsuffix .o,$(basename $(shell find ./core -name "*.[c|S]"))) LIBC_OBJ := $(addsuffix .o,$(basename $(shell find ./libc -name "*.[c|S]"))) INT_OBJ := $(addsuffix .o,$(basename $(shell find ./int -name "*.[c|S]"))) all: $(EXEC) -$(EXEC): boot/boot.o $(BOOT_OBJ) $(UTILS_OBJ) $(LIBC_OBJ) $(INT_OBJ) bringelle.o +$(EXEC): boot/boot.o $(BOOT_OBJ) $(CORE_OBJ) $(LIBC_OBJ) $(INT_OBJ) bringelle.o ld -n -T $(LD_SCRIPT) -nostdlib -o bringelle $^ %.o: %.S diff --git a/src/boot/multiboot.c b/src/boot/multiboot.c index c41aeb7..71382d5 100644 --- a/src/boot/multiboot.c +++ b/src/boot/multiboot.c @@ -1,5 +1,4 @@ #include "multiboot.h" -#include "utils/mem.h" /// See boot.S extern u8* MB_INFO; diff --git a/src/boot/multiboot.h b/src/boot/multiboot.h index 010f60b..9eae31f 100644 --- a/src/boot/multiboot.h +++ b/src/boot/multiboot.h @@ -1,7 +1,8 @@ #ifndef MULTIBOOT_H #define MULTIBOOT_H -#include "utils/types.h" +#include "core/types.h" +#include "core/mem.h" typedef struct MBI_TAG_HEADER { u32 type; @@ -29,10 +30,12 @@ typedef struct MBI_TAG_FB { * Parse Bootloader boot information structure */ char mb_load_tag(char **data, char type); + /** * Search for Bootloader name */ char mb_load_bl_name(MBI_TAG_BL_NAME *data); + /** * Search for FrameBuffer structure (TODO: Finish) */ diff --git a/src/bringelle.c b/src/bringelle.c index 340e884..49670e8 100644 --- a/src/bringelle.c +++ b/src/bringelle.c @@ -1,14 +1,14 @@ #include "libc/stdio.h" #include "int/pic.h" #include "boot/multiboot.h" -#include "utils/mem.h" -#include "utils/gdt.h" -#include "utils/paging.h" - +#include "core/mem.h" +#include "core/gdt.h" +#include "core/paging.h" char show_tics=0; extern GDT_TSS TSS; +extern void interrupt_enable(); void utask(){ char msg[]="Message from the task :D"; @@ -20,8 +20,8 @@ void bringelle(){ clear(); printc("Booting Bringelle...\n",GREEN); - // Kernel boot sequence - pic_enable_interrupt(); + // ----- Kernel boot sequence + interrupt_enable(); print("Interrupts enabled\n"); paging_enable(); @@ -52,8 +52,6 @@ void bringelle(){ : "=m" (TSS.ss0), "=m" (TSS.esp0) ); - - while(1); } diff --git a/src/utils/asm.h b/src/core/asm.h index be265d8..be265d8 100644 --- a/src/utils/asm.h +++ b/src/core/asm.h diff --git a/src/utils/framebuffer.c b/src/core/framebuffer.c index 110dc73..110dc73 100644 --- a/src/utils/framebuffer.c +++ b/src/core/framebuffer.c diff --git a/src/utils/framebuffer.h b/src/core/framebuffer.h index f4e52a0..3d862d6 100644 --- a/src/utils/framebuffer.h +++ b/src/core/framebuffer.h @@ -21,7 +21,15 @@ typedef struct VIDEO_STATE { * Print char */ void putchar(char); + +/** + * Scroll the framebuffer from one line + */ void scrollup(); + +/** + * Clear all char from the framebuffer + */ void clear(); #endif diff --git a/src/utils/gdt.c b/src/core/gdt.c index 8c1c70d..8c1c70d 100644 --- a/src/utils/gdt.c +++ b/src/core/gdt.c diff --git a/src/utils/gdt.h b/src/core/gdt.h index f010891..f010891 100644 --- a/src/utils/gdt.h +++ b/src/core/gdt.h diff --git a/src/utils/mem.c b/src/core/mem.c index 4cefd6d..4cefd6d 100644 --- a/src/utils/mem.c +++ b/src/core/mem.c diff --git a/src/utils/mem.h b/src/core/mem.h index f051219..5bef441 100644 --- a/src/utils/mem.h +++ b/src/core/mem.h @@ -3,6 +3,9 @@ #include "types.h" +/** + * Copy size byte from *src to *dst + */ void memcpy(void *src, void *dst, int size); #endif diff --git a/src/utils/paging.c b/src/core/paging.c index b1f462f..b1f462f 100644 --- a/src/utils/paging.c +++ b/src/core/paging.c diff --git a/src/utils/paging.h b/src/core/paging.h index 3e6b3f8..1e8f4e3 100644 --- a/src/utils/paging.h +++ b/src/core/paging.h @@ -5,6 +5,9 @@ #define PAGING_DIR_LOCATION 0x1000 #define PAGING_TABLE_LOCATION 0x5000 +/* + * Configure and enable paging + */ void paging_enable(); #endif
\ No newline at end of file diff --git a/src/utils/syscall.c b/src/core/syscall.c index 300b7aa..300b7aa 100644 --- a/src/utils/syscall.c +++ b/src/core/syscall.c diff --git a/src/utils/syscall.h b/src/core/syscall.h index 26f3682..1f0c584 100644 --- a/src/utils/syscall.h +++ b/src/core/syscall.h @@ -1,6 +1,9 @@ #ifndef SYSCALL_H #define SYSCALL_H +/* + * Perform a syscall + */ void syscall(); #endif
\ No newline at end of file diff --git a/src/utils/types.h b/src/core/types.h index ce49701..071d8d6 100644 --- a/src/utils/types.h +++ b/src/core/types.h @@ -1,5 +1,5 @@ #ifndef TYPES_H -#define TYPES_h +#define TYPES_H typedef unsigned char u8; typedef unsigned short u16; diff --git a/src/int/8042.c b/src/int/8042.c index f0a987f..5446f11 100644 --- a/src/int/8042.c +++ b/src/int/8042.c @@ -1,6 +1,6 @@ #include "8042.h" -#include "utils/framebuffer.h" -#include "utils/asm.h" +#include "core/framebuffer.h" +#include "core/asm.h" DEFINE_AZERTY; diff --git a/src/int/8042.h b/src/int/8042.h index e35e5a0..5e61ffd 100644 --- a/src/int/8042.h +++ b/src/int/8042.h @@ -1,7 +1,7 @@ #ifndef _8042_H #define _8042_H -#include "utils/types.h" +#include "core/types.h" void _8042_keypress(); diff --git a/src/int/idt.c b/src/int/idt.c new file mode 100644 index 0000000..e3e71e8 --- /dev/null +++ b/src/int/idt.c @@ -0,0 +1,39 @@ +#include "idt.h" + +struct IDT_REGISTER IDTR={ + 8*IDT_MAX_ENTRY, + 0x0 +}; + +// Interrupt functions (cf int.S) +extern u32 +INT_DEFAULT, +INT_PAGE_FAULT, +INT_CLOCK, +INT_KEYPRESS, +INT_SYSCALL; + + +void idt_init(){ + // Map first default 32 entries + for(int i=0;i<IDT_MAX_ENTRY;i++){ + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_DEFAULT,IDT_INT_GATE},i); + if(i==14) + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_PAGE_FAULT,IDT_INT_GATE},i); + if(i==32) + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_CLOCK,IDT_INT_GATE},i); + if(i==33) + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_KEYPRESS,IDT_INT_GATE},i); + if(i==48) + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_SYSCALL,IDT_TRAP_GATE},i); + } + + asm("lidtl (IDTR)"); +} + +void idt_write_entry(IDT_ENTRY entry, int id){ + int descriptor[2]; + descriptor[0]=entry.offset & 0xFFFF | entry.segment << 16; + descriptor[1]=entry.type & 0xFFFF | entry.offset & 0xFFFF0000; + memcpy((void*)descriptor, (void *)(IDTR.base+(id*8)),8); +}
\ No newline at end of file diff --git a/src/int/idt.h b/src/int/idt.h new file mode 100644 index 0000000..17c5cfa --- /dev/null +++ b/src/int/idt.h @@ -0,0 +1,32 @@ +#ifndef IDT_H +#define IDT_H + +#include "core/types.h" +#include "core/mem.h" + +#define IDT_MAX_ENTRY 200 +#define IDT_INT_GATE 0x8E00 +#define IDT_TRAP_GATE 0xEF00 + +typedef struct IDT_ENTRY { + u16 segment; + u32 offset; + u16 type; +} IDT_ENTRY; + +struct IDT_REGISTER { + u16 limit; + u32 base; +} __attribute__((packed)); + +/** + * Copy IDT into memory and load it + */ +void idt_init(); + +/** + * Write an IDT entry into memory + */ +void idt_write_entry(IDT_ENTRY entry,int id); + +#endif
\ No newline at end of file diff --git a/src/int/int.S b/src/int/int.S index e69de29..8ca8b7a 100644 --- a/src/int/int.S +++ b/src/int/int.S @@ -0,0 +1,72 @@ +.macro SAVE_REGS +pushal +push %ds +push %es +push %fs +push %gs +push %ebx +mov $0x10,%bx +mov %bx,%ds +pop %ebx +.endm + +.macro RESTORE_REGS + pop %gs + pop %fs + pop %es + pop %ds + popal +.endm + +.globl interrupt_enable +interrupt_enable: + call idt_init + call pic_init + sti + ret + +.globl INT_DEFAULT +INT_DEFAULT: + SAVE_REGS + movb $0x20, %al + outb %al, $0x20 + RESTORE_REGS + iret + +.globl INT_KEYPRESS +INT_KEYPRESS: + SAVE_REGS + call _8042_keypress + movb $0x20, %al + outb %al, $0x20 + RESTORE_REGS + iret + +.globl INT_CLOCK +INT_CLOCK: + SAVE_REGS + call clock + movb $0x20, %al + outb %al, $0x20 + RESTORE_REGS + iret + +.globl INT_SYSCALL +INT_SYSCALL: + SAVE_REGS + call syscall + movb $0x20, %al + outb %al, $0x20 + RESTORE_REGS + iret + +.globl INT_PAGE_FAULT +INT_PAGE_FAULT: + SAVE_REGS + call page_fault + hlt + movb $0x20, %al + outb %al, $0x20 + RESTORE_REGS + iret + diff --git a/src/int/pic.c b/src/int/pic.c index 472e50c..d509e1d 100644 --- a/src/int/pic.c +++ b/src/int/pic.c @@ -1,88 +1,10 @@ #include "pic.h" -#include "utils/asm.h" -#include "utils/mem.h" -#include "utils/syscall.h" - -struct IDT_REGISTER IDTR={ - 200*8, - 0x0 -}; - -/// Bridge between IDT and functions call -asm ( -".macro SAVE_REGS \n\t" - "pushal \n\t" - "push %ds \n\t" - "push %es \n\t" - "push %fs \n\t" - "push %gs \n\t" - "push %ebx \n\t" - "mov $0x10,%bx \n\t" - "mov %bx,%ds \n\t" - "pop %ebx \n\t" -".endm \n\t" -".macro RESTORE_REGS \n\t" - "pop %gs \n\t" - "pop %fs \n\t" - "pop %es \n\t" - "pop %ds \n\t" - "popal \n\t" -".endm \n\t" -"PIC_IRQ_DEFAULT: \n\t" - "SAVE_REGS \n\t" - "movb $0x20, %al \n\t" - "outb %al, $0x20 \n\t" - "RESTORE_REGS \n\t" - "iret \n\t" -"PIC_IRQ_PRINT: \n\t" - "SAVE_REGS \n\t" - "call _8042_keypress \n\t" - "movb $0x20, %al \n\t" - "outb %al, $0x20 \n\t" - "RESTORE_REGS \n\t" - "iret \n\t" -"PIC_IRQ_CLOCK: \n\t" - "SAVE_REGS \n\t" - "call clock \n\t" - "movb $0x20, %al \n\t" - "outb %al, $0x20 \n\t" - "RESTORE_REGS \n\t" - "iret \n\t" -"PIC_IRQ_SYSCALL: \n\t" - "SAVE_REGS \n\t" - "call syscall \n\t" - "movb $0x20, %al \n\t" - "outb %al, $0x20 \n\t" - "RESTORE_REGS \n\t" - "iret \n\t" -"INT_PAGE_FAULT: \n\t" - "SAVE_REGS \n\t" - "call page_fault \n\t" - "hlt \n\t" - "movb $0x20, %al \n\t" - "outb %al, $0x20 \n\t" - "RESTORE_REGS \n\t" - "iret \n\t" -); - -extern u32 PIC_IRQ_DEFAULT,PIC_IRQ_PRINT,PIC_IRQ_CLOCK, PIC_IRQ_SYSCALL,INT_PAGE_FAULT; - -void pic_enable_interrupt(){ - // Map first default 32 entries - for(int i=0;i<200;i++){ - pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_DEFAULT,IDT_INT_GATE},i); - if(i==14) - pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&INT_PAGE_FAULT,IDT_INT_GATE},i); - if(i==32) - pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_CLOCK,IDT_INT_GATE},i); - if(i==33) - pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_PRINT,IDT_INT_GATE},i); - if(i==48) - pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_SYSCALL,IDT_TRAP_GATE},i); - } - - // Now configure 8952A +#include "core/asm.h" +#include "core/mem.h" +#include "core/syscall.h" +void pic_init(){ + // ICW1: Initialisation outbj(0x20,0x11); // Master outbj(0xA0,0x11); // Slave @@ -101,15 +23,6 @@ void pic_enable_interrupt(){ // OCW: Masking outbj(0x21,0b11111100); - - - asm("lidtl (IDTR)"); - asm("sti"); } -void pic_add_idt_entry(IDT_ENTRY entry, int id){ - int descriptor[2]; - descriptor[0]=entry.offset & 0xFFFF | entry.segment << 16; - descriptor[1]=entry.type & 0xFFFF | entry.offset & 0xFFFF0000; - memcpy((void*)descriptor, (void *)(IDTR.base+(id*8)),8); -} + diff --git a/src/int/pic.h b/src/int/pic.h index db1ccec..19e0f5c 100644 --- a/src/int/pic.h +++ b/src/int/pic.h @@ -1,23 +1,9 @@ #ifndef PIC_H #define PIC_H -#include "utils/types.h" - -#define IDT_INT_GATE 0x8E00 -#define IDT_TRAP_GATE 0xEF00 - -typedef struct IDT_ENTRY { - u16 segment; - u32 offset; - u16 type; -} IDT_ENTRY; - -struct IDT_REGISTER { - u16 limit; - u32 base; -} __attribute__((packed)); - -void pic_enable_interrupt(); -void pic_add_idt_entry(IDT_ENTRY entry,int id); +/** + * Configure + */ +void pic_init(); #endif
\ No newline at end of file diff --git a/src/libc/stdio.h b/src/libc/stdio.h index ece8df5..5805f5a 100644 --- a/src/libc/stdio.h +++ b/src/libc/stdio.h @@ -1,7 +1,7 @@ #ifndef STDIO_H #define STDIO_H -#include "utils/framebuffer.h" +#include "core/framebuffer.h" void print(char*); void printc(char*,VIDEO_COLORS c); |
