core: added the shell structure

This commit is contained in:
0x35c 2024-09-10 12:03:08 +02:00
parent 5fc5a3be0e
commit 232b19666a
6 changed files with 51 additions and 64 deletions

View File

@ -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");
}
}

0
src/shell/color.c Normal file
View File

0
src/shell/echo.c Normal file
View File

0
src/shell/exec.c Normal file
View File

0
src/shell/poweroff.c Normal file
View File

0
src/shell/reboot.c Normal file
View File