diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-12 10:28:04 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-12 10:28:04 +0200 |
| commit | 457a2117706cdaee34f894e67c89da7bf29f6143 (patch) | |
| tree | e3a1a519c5360abcca95732500594c92af9af51c /src/core | |
| parent | 39713a3736145483dd3310c3605f940ca34f05c3 (diff) | |
Refactoring
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/framebuffer.c | 58 | ||||
| -rw-r--r-- | src/core/framebuffer.h | 35 | ||||
| -rw-r--r-- | src/core/gdt.h | 3 | ||||
| -rw-r--r-- | src/core/idt.c | 39 | ||||
| -rw-r--r-- | src/core/idt.h | 32 | ||||
| -rw-r--r-- | src/core/int.S | 72 |
6 files changed, 146 insertions, 93 deletions
diff --git a/src/core/framebuffer.c b/src/core/framebuffer.c deleted file mode 100644 index 110dc73..0000000 --- a/src/core/framebuffer.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "framebuffer.h" - -#define MAX_COL 80 -#define MAX_LINE 25 - -VIDEO_STATE VS={ - (u8 *)0xB8000, - 0, - 0, - BLACK, - GRAY, -}; - -void putchar(char c){ - // Handle newline here - if(c=='\n'){ - VS.col=0; - VS.line+=1; - if(VS.line>=MAX_LINE){ - VS.line=MAX_LINE-1; - scrollup(); - } - return; - } - - // Print char - VS.mem[VS.col*2+MAX_COL*VS.line*2]=c; - VS.mem[VS.col*2+MAX_COL*VS.line*2+1]=VS.fg|VS.bg<<4; - - // Refresh location - VS.col+=1; - if(VS.col>= MAX_COL){ - VS.col=0; - VS.line+=1; - if(VS.line>=MAX_LINE){ - VS.line=MAX_LINE-1; - scrollup(); - } - } -} - -void clear(){ - for(char i=0;i<MAX_LINE;i++){ - scrollup(); - } -} - -void scrollup(){ - // Move VS.line up - for(char i=1;i<=MAX_LINE;i++){ - for(char j=0;j<=MAX_COL;j++) - VS.mem[j*2+MAX_COL*(i-1)*2]=VS.mem[j*2+MAX_COL*i*2]; - } - // Clear last VS.line - for(char i=0;i<=MAX_COL;i++){ - VS.mem[i*2+MAX_COL*(MAX_LINE-1)*2]='\0'; - } -} diff --git a/src/core/framebuffer.h b/src/core/framebuffer.h deleted file mode 100644 index 3d862d6..0000000 --- a/src/core/framebuffer.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef FRAMEBUFFER_H -#define FRAMEBUFFER_H - -#include "types.h" - -typedef enum VIDEO_COLORS { - BLACK=0, BLUE=1, GREEN=2,CYAN=3, RED=4,PURPLE=5,BROWN=6,GRAY=7, - DARK_GRAY=8,LIGHT_BLUE=9,LIGHT_GREEN=10,LIGHT_CYAN=11,LIGHT_RED=12,LIGHT_PURPLE=13,YELLOW=14,WHITE=15 - -} VIDEO_COLORS; - -typedef struct VIDEO_STATE { - u8 *mem; - u8 col; - u8 line; - u8 bg; - u8 fg; -} 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/core/gdt.h b/src/core/gdt.h index f010891..246ddbe 100644 --- a/src/core/gdt.h +++ b/src/core/gdt.h @@ -72,6 +72,9 @@ void gdt_memcpy(); */ void gdt_write_entry(GDT_ENTRY entry, u32 id); +/** + * Extract the base from the user data segment + */ int gdt_user_ds_base(); #endif diff --git a/src/core/idt.c b/src/core/idt.c new file mode 100644 index 0000000..4e08d62 --- /dev/null +++ b/src/core/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); + } + // Load IDT + 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/core/idt.h b/src/core/idt.h new file mode 100644 index 0000000..17c5cfa --- /dev/null +++ b/src/core/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/core/int.S b/src/core/int.S new file mode 100644 index 0000000..8ca8b7a --- /dev/null +++ b/src/core/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 + |
