core: added the shell structure
This commit is contained in:
parent
5fc5a3be0e
commit
232b19666a
115
src/gdt/gdt.c
115
src/gdt/gdt.c
@ -6,27 +6,28 @@ extern void setGdt(void *);
|
|||||||
|
|
||||||
void encodeGdtEntry(uint8_t *target, struct gdt_entry source)
|
void encodeGdtEntry(uint8_t *target, struct gdt_entry source)
|
||||||
{
|
{
|
||||||
// Check the limit to make sure that it can be encoded
|
// Check the limit to make sure that it can be encoded
|
||||||
if (source.limit > 0xFFFFF) {
|
if (source.limit > 0xFFFFF) {
|
||||||
kprintf(KERN_ERR, "GDT cannot encode limits larger than 0xFFFFF");
|
kprintf(KERN_ERR,
|
||||||
}
|
"GDT cannot encode limits larger than 0xFFFFF");
|
||||||
|
}
|
||||||
// Encode the limit
|
|
||||||
target[0] = source.limit & 0xFF;
|
// Encode the limit
|
||||||
target[1] = (source.limit >> 8) & 0xFF;
|
target[0] = source.limit & 0xFF;
|
||||||
target[6] = (source.limit >> 16) & 0x0F;
|
target[1] = (source.limit >> 8) & 0xFF;
|
||||||
|
target[6] = (source.limit >> 16) & 0x0F;
|
||||||
// Encode the base
|
|
||||||
target[2] = source.base & 0xFF;
|
// Encode the base
|
||||||
target[3] = (source.base >> 8) & 0xFF;
|
target[2] = source.base & 0xFF;
|
||||||
target[4] = (source.base >> 16) & 0xFF;
|
target[3] = (source.base >> 8) & 0xFF;
|
||||||
target[7] = (source.base >> 24) & 0xFF;
|
target[4] = (source.base >> 16) & 0xFF;
|
||||||
|
target[7] = (source.base >> 24) & 0xFF;
|
||||||
// Encode the access byte
|
|
||||||
target[5] = source.access_byte;
|
// Encode the access byte
|
||||||
|
target[5] = source.access_byte;
|
||||||
// Encode the flags
|
|
||||||
target[6] |= (source.flags << 4);
|
// Encode the flags
|
||||||
|
target[6] |= (source.flags << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t gdt_entries[8][7];
|
uint8_t gdt_entries[8][7];
|
||||||
@ -34,62 +35,48 @@ struct gdt_descriptor gdtr;
|
|||||||
|
|
||||||
void initGdt()
|
void initGdt()
|
||||||
{
|
{
|
||||||
gdtr.size = GDT_SIZE - 1;
|
gdtr.size = GDT_SIZE - 1;
|
||||||
gdtr.base = GDT_BASE;
|
gdtr.base = GDT_BASE;
|
||||||
|
|
||||||
struct gdt_entry gdt_entry_null_descriptor = { .base = 0,
|
struct gdt_entry gdt_entry_null_descriptor = {
|
||||||
.limit = 0x00000000,
|
.base = 0, .limit = 0x00000000, .access_byte = 0x00, .flags = 0x0};
|
||||||
.access_byte = 0x00,
|
encodeGdtEntry(gdt_entries[0], gdt_entry_null_descriptor);
|
||||||
.flags = 0x0};
|
|
||||||
encodeGdtEntry(gdt_entries[0], gdt_entry_null_descriptor);
|
|
||||||
|
|
||||||
struct gdt_entry gdt_entry_kernel_mode_code_segment = { .base = 0,
|
struct gdt_entry gdt_entry_kernel_mode_code_segment = {
|
||||||
.limit = 0xFFFFF,
|
.base = 0, .limit = 0xFFFFF, .access_byte = 0x9A, .flags = 0xC};
|
||||||
.access_byte = 0x9A,
|
encodeGdtEntry(gdt_entries[1], gdt_entry_kernel_mode_code_segment);
|
||||||
.flags = 0xC };
|
|
||||||
encodeGdtEntry(gdt_entries[1], gdt_entry_kernel_mode_code_segment);
|
|
||||||
|
|
||||||
struct gdt_entry gdt_entry_kernel_mode_data_segment = { .base = 0,
|
struct gdt_entry gdt_entry_kernel_mode_data_segment = {
|
||||||
.limit = 0xFFFFF,
|
.base = 0, .limit = 0xFFFFF, .access_byte = 0x92, .flags = 0xC};
|
||||||
.access_byte = 0x92,
|
encodeGdtEntry(gdt_entries[2], gdt_entry_kernel_mode_data_segment);
|
||||||
.flags = 0xC };
|
|
||||||
encodeGdtEntry(gdt_entries[2], gdt_entry_kernel_mode_data_segment);
|
|
||||||
|
|
||||||
struct gdt_entry gdt_entry_kernel_mode_stack_segment = { .base = 0x0,
|
struct gdt_entry gdt_entry_kernel_mode_stack_segment = {
|
||||||
.limit = 0x0,
|
.base = 0x0, .limit = 0x0, .access_byte = 0x97, .flags = 0x0D};
|
||||||
.access_byte = 0x97,
|
encodeGdtEntry(gdt_entries[3], gdt_entry_kernel_mode_data_segment);
|
||||||
.flags = 0x0D };
|
|
||||||
encodeGdtEntry(gdt_entries[3], gdt_entry_kernel_mode_data_segment);
|
|
||||||
|
|
||||||
struct gdt_entry gdt_entry_user_mode_code_segment = { .base = 0,
|
struct gdt_entry gdt_entry_user_mode_code_segment = {
|
||||||
.limit = 0xFFFFF,
|
.base = 0, .limit = 0xFFFFF, .access_byte = 0xFA, .flags = 0xC};
|
||||||
.access_byte = 0xFA,
|
encodeGdtEntry(gdt_entries[4], gdt_entry_user_mode_code_segment);
|
||||||
.flags = 0xC };
|
|
||||||
encodeGdtEntry(gdt_entries[4], gdt_entry_user_mode_code_segment);
|
|
||||||
|
|
||||||
struct gdt_entry gdt_entry_user_mode_data_segment = { .base = 0,
|
struct gdt_entry gdt_entry_user_mode_data_segment = {
|
||||||
.limit = 0xFFFFF,
|
.base = 0, .limit = 0xFFFFF, .access_byte = 0xF2, .flags = 0xC};
|
||||||
.access_byte = 0xF2,
|
encodeGdtEntry(gdt_entries[5], gdt_entry_user_mode_data_segment);
|
||||||
.flags = 0xC };
|
|
||||||
encodeGdtEntry(gdt_entries[5], gdt_entry_user_mode_data_segment);
|
|
||||||
|
|
||||||
struct gdt_entry gdt_entry_user_mode_stack_segment = { .base = 0x0,
|
struct gdt_entry gdt_entry_user_mode_stack_segment = {
|
||||||
.limit = 0x0,
|
.base = 0x0, .limit = 0x0, .access_byte = 0xF7, .flags = 0x0D};
|
||||||
.access_byte = 0xF7,
|
encodeGdtEntry(gdt_entries[6], gdt_entry_user_mode_data_segment);
|
||||||
.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 */
|
/* load the gdtr registry */
|
||||||
asm("lgdtl (gdtr)");
|
asm("lgdtl (gdtr)");
|
||||||
|
|
||||||
/* initiliaz the segments */
|
/* initiliaz the segments */
|
||||||
asm(" movw $0x10, %ax \n \
|
asm(" movw $0x10, %ax \n \
|
||||||
movw %ax, %ds \n \
|
movw %ax, %ds \n \
|
||||||
movw %ax, %es \n \
|
movw %ax, %es \n \
|
||||||
movw %ax, %fs \n \
|
movw %ax, %fs \n \
|
||||||
movw %ax, %gs \n \
|
movw %ax, %gs \n \
|
||||||
ljmp $0x08, $next \n \
|
ljmp $0x08, $next \n \
|
||||||
next: \n");
|
next: \n");
|
||||||
}
|
}
|
||||||
|
0
src/shell/color.c
Normal file
0
src/shell/color.c
Normal file
0
src/shell/echo.c
Normal file
0
src/shell/echo.c
Normal file
0
src/shell/exec.c
Normal file
0
src/shell/exec.c
Normal file
0
src/shell/poweroff.c
Normal file
0
src/shell/poweroff.c
Normal file
0
src/shell/reboot.c
Normal file
0
src/shell/reboot.c
Normal file
Loading…
Reference in New Issue
Block a user