diff options
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/gdt.c | 15 | ||||
| -rw-r--r-- | src/utils/gdt.h | 4 | ||||
| -rw-r--r-- | src/utils/pic.c | 44 | ||||
| -rw-r--r-- | src/utils/pic.h | 3 |
4 files changed, 56 insertions, 10 deletions
diff --git a/src/utils/gdt.c b/src/utils/gdt.c index fd86f5f..c380283 100644 --- a/src/utils/gdt.c +++ b/src/utils/gdt.c @@ -5,7 +5,7 @@ struct GDT_REGISTER GDTR = { 0, 0 }; GDT_TSS TSS; void gdt_memcpy(){ - GDTR.limit=8*8; // Each entry is 8 bytes and 8 entries + GDTR.limit=8*GDT_MAX_ENTRIES; // Each entry is 8 bytes and 8 entries GDTR.base=0x800; gdt_write_entry((GDT_ENTRY){0,0,0,0},0); // First one must be null @@ -60,12 +60,10 @@ void gdt_memcpy(){ // Init TSS segment TSS.t_reserved=0; TSS.io_map=0; - TSS.ss0=0x18; - TSS.esp0=0x50000; GDT_ENTRY tss_desc; tss_desc.base=(u32)&TSS; // Not used in stack descriptor - tss_desc.limit=0x68; // Define how much entry it can contains + tss_desc.limit=0x68; // Define how much bytes it occupies tss_desc.flags=0; tss_desc.access=0x89 | GDT_PRVL_3; // Note that 0x89 is specific to TSS! gdt_write_entry(tss_desc, 7); @@ -89,3 +87,12 @@ void gdt_write_entry(GDT_ENTRY entry, u32 id){ // Copy descriptor into memory memcpy(descriptor,(void*)GDTR.base+8*id,8); // Each entry is 64 bits (8 bytes) } + +int gdt_user_ds_base(){ + char *addr=(char*)GDTR.base+48; + int *base0_15=(int*)addr+2; + int *base16_31=(int*)addr+7; + int base0_15_content=*base0_15 & 0xFFFF; + int base16_21_content=*base16_31 & 0xFFFF; + return(base16_21_content<<16 & base0_15_content); +}
\ No newline at end of file diff --git a/src/utils/gdt.h b/src/utils/gdt.h index 01a01bf..f010891 100644 --- a/src/utils/gdt.h +++ b/src/utils/gdt.h @@ -3,6 +3,8 @@ #include "types.h" +#define GDT_MAX_ENTRIES 8 + // Access byte #define GDT_AC 1 // Access bit #define GDT_RW 1 << 1 // Read/Write bit @@ -70,4 +72,6 @@ void gdt_memcpy(); */ void gdt_write_entry(GDT_ENTRY entry, u32 id); +int gdt_user_ds_base(); + #endif diff --git a/src/utils/pic.c b/src/utils/pic.c index f811d04..7681a13 100644 --- a/src/utils/pic.c +++ b/src/utils/pic.c @@ -1,6 +1,7 @@ #include "pic.h" #include "asm.h" #include "mem.h" +#include "syscall.h" struct IDT_REGISTER IDTR={ 200*8, @@ -9,32 +10,65 @@ struct IDT_REGISTER IDTR={ /// Bridge between IDT and functions call asm ( -"PIC_IRQ_DEFAULT:" +".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" ); -extern u32 PIC_IRQ_DEFAULT,PIC_IRQ_PRINT,PIC_IRQ_CLOCK; +extern u32 PIC_IRQ_DEFAULT,PIC_IRQ_PRINT,PIC_IRQ_CLOCK, PIC_IRQ_SYSCALL; 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_TYPE_1},i); + pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_DEFAULT,IDT_INT_GATE},i); if(i==32) - pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_CLOCK,IDT_TYPE_1},i); + 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_TYPE_1},i); + 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 diff --git a/src/utils/pic.h b/src/utils/pic.h index 2734437..5ee1ab2 100644 --- a/src/utils/pic.h +++ b/src/utils/pic.h @@ -3,7 +3,8 @@ #include "types.h" -#define IDT_TYPE_1 0x8E00 +#define IDT_INT_GATE 0x8E00 +#define IDT_TRAP_GATE 0xEF00 typedef struct IDT_ENTRY { u16 segment; |
