diff --git a/src/gdt/gdt.c b/src/gdt/gdt.c index 21c7b5e..4e43bbf 100644 --- a/src/gdt/gdt.c +++ b/src/gdt/gdt.c @@ -6,27 +6,28 @@ extern void setGdt(void *); void encodeGdtEntry(uint8_t *target, struct gdt_entry source) { - // Check the limit to make sure that it can be encoded - if (source.limit > 0xFFFFF) { - kprintf(KERN_ERR, "GDT cannot encode limits larger than 0xFFFFF"); - } - - // Encode the limit - target[0] = source.limit & 0xFF; - target[1] = (source.limit >> 8) & 0xFF; - target[6] = (source.limit >> 16) & 0x0F; - - // Encode the base - target[2] = source.base & 0xFF; - target[3] = (source.base >> 8) & 0xFF; - target[4] = (source.base >> 16) & 0xFF; - target[7] = (source.base >> 24) & 0xFF; - - // Encode the access byte - target[5] = source.access_byte; - - // Encode the flags - target[6] |= (source.flags << 4); + // Check the limit to make sure that it can be encoded + if (source.limit > 0xFFFFF) { + kprintf(KERN_ERR, + "GDT cannot encode limits larger than 0xFFFFF"); + } + + // Encode the limit + target[0] = source.limit & 0xFF; + target[1] = (source.limit >> 8) & 0xFF; + target[6] = (source.limit >> 16) & 0x0F; + + // Encode the base + target[2] = source.base & 0xFF; + target[3] = (source.base >> 8) & 0xFF; + target[4] = (source.base >> 16) & 0xFF; + target[7] = (source.base >> 24) & 0xFF; + + // Encode the access byte + target[5] = source.access_byte; + + // Encode the flags + target[6] |= (source.flags << 4); } uint8_t gdt_entries[8][7]; @@ -34,62 +35,48 @@ struct gdt_descriptor gdtr; void initGdt() { - gdtr.size = GDT_SIZE - 1; - gdtr.base = GDT_BASE; + gdtr.size = GDT_SIZE - 1; + gdtr.base = GDT_BASE; - struct gdt_entry gdt_entry_null_descriptor = { .base = 0, - .limit = 0x00000000, - .access_byte = 0x00, - .flags = 0x0}; - encodeGdtEntry(gdt_entries[0], gdt_entry_null_descriptor); + struct gdt_entry gdt_entry_null_descriptor = { + .base = 0, .limit = 0x00000000, .access_byte = 0x00, .flags = 0x0}; + encodeGdtEntry(gdt_entries[0], gdt_entry_null_descriptor); - struct gdt_entry gdt_entry_kernel_mode_code_segment = { .base = 0, - .limit = 0xFFFFF, - .access_byte = 0x9A, - .flags = 0xC }; - encodeGdtEntry(gdt_entries[1], gdt_entry_kernel_mode_code_segment); + struct gdt_entry gdt_entry_kernel_mode_code_segment = { + .base = 0, .limit = 0xFFFFF, .access_byte = 0x9A, .flags = 0xC}; + encodeGdtEntry(gdt_entries[1], gdt_entry_kernel_mode_code_segment); - struct gdt_entry gdt_entry_kernel_mode_data_segment = { .base = 0, - .limit = 0xFFFFF, - .access_byte = 0x92, - .flags = 0xC }; - encodeGdtEntry(gdt_entries[2], gdt_entry_kernel_mode_data_segment); + struct gdt_entry gdt_entry_kernel_mode_data_segment = { + .base = 0, .limit = 0xFFFFF, .access_byte = 0x92, .flags = 0xC}; + encodeGdtEntry(gdt_entries[2], gdt_entry_kernel_mode_data_segment); - struct gdt_entry gdt_entry_kernel_mode_stack_segment = { .base = 0x0, - .limit = 0x0, - .access_byte = 0x97, - .flags = 0x0D }; - encodeGdtEntry(gdt_entries[3], gdt_entry_kernel_mode_data_segment); + struct gdt_entry gdt_entry_kernel_mode_stack_segment = { + .base = 0x0, .limit = 0x0, .access_byte = 0x97, .flags = 0x0D}; + encodeGdtEntry(gdt_entries[3], gdt_entry_kernel_mode_data_segment); - struct gdt_entry gdt_entry_user_mode_code_segment = { .base = 0, - .limit = 0xFFFFF, - .access_byte = 0xFA, - .flags = 0xC }; - encodeGdtEntry(gdt_entries[4], gdt_entry_user_mode_code_segment); + struct gdt_entry gdt_entry_user_mode_code_segment = { + .base = 0, .limit = 0xFFFFF, .access_byte = 0xFA, .flags = 0xC}; + encodeGdtEntry(gdt_entries[4], gdt_entry_user_mode_code_segment); - struct gdt_entry gdt_entry_user_mode_data_segment = { .base = 0, - .limit = 0xFFFFF, - .access_byte = 0xF2, - .flags = 0xC }; - encodeGdtEntry(gdt_entries[5], gdt_entry_user_mode_data_segment); + struct gdt_entry gdt_entry_user_mode_data_segment = { + .base = 0, .limit = 0xFFFFF, .access_byte = 0xF2, .flags = 0xC}; + encodeGdtEntry(gdt_entries[5], gdt_entry_user_mode_data_segment); - struct gdt_entry gdt_entry_user_mode_stack_segment = { .base = 0x0, - .limit = 0x0, - .access_byte = 0xF7, - .flags = 0x0D }; - encodeGdtEntry(gdt_entries[6], gdt_entry_user_mode_data_segment); + struct gdt_entry gdt_entry_user_mode_stack_segment = { + .base = 0x0, .limit = 0x0, .access_byte = 0xF7, .flags = 0x0D}; + encodeGdtEntry(gdt_entries[6], gdt_entry_user_mode_data_segment); - memcpy((void *) gdtr.base, (void *) gdt_entries, (size_t) GDT_SIZE); + memcpy((void *)gdtr.base, (void *)gdt_entries, (size_t)GDT_SIZE); - /* load the gdtr registry */ - asm("lgdtl (gdtr)"); + /* load the gdtr registry */ + asm("lgdtl (gdtr)"); - /* initiliaz the segments */ - asm(" movw $0x10, %ax \n \ + /* initiliaz the segments */ + asm(" movw $0x10, %ax \n \ movw %ax, %ds \n \ movw %ax, %es \n \ movw %ax, %fs \n \ movw %ax, %gs \n \ ljmp $0x08, $next \n \ next: \n"); -} \ No newline at end of file +} diff --git a/src/shell/color.c b/src/shell/color.c new file mode 100644 index 0000000..e69de29 diff --git a/src/shell/echo.c b/src/shell/echo.c new file mode 100644 index 0000000..e69de29 diff --git a/src/shell/exec.c b/src/shell/exec.c new file mode 100644 index 0000000..e69de29 diff --git a/src/shell/poweroff.c b/src/shell/poweroff.c new file mode 100644 index 0000000..e69de29 diff --git a/src/shell/reboot.c b/src/shell/reboot.c new file mode 100644 index 0000000..e69de29