Merge into main the new state of the operating system/kernel #1

Open
Nigel wants to merge 120 commits from dev into main
5 changed files with 38 additions and 31 deletions
Showing only changes of commit c9a036bfbb - Show all commits

View File

@ -5,6 +5,7 @@
.section .bootstrap_stack, "aw", @nobits .section .bootstrap_stack, "aw", @nobits
stack_bottom: stack_bottom:
.skip 16384 # 16 KiB .skip 16384 # 16 KiB
.globl stack_top
stack_top: stack_top:
/* /*
@ -75,16 +76,7 @@ _start:
4: 4:
# At this point, paging is fully set up and enabled # At this point, paging is fully set up and enabled
isPaging: isPaging:
/* push the pointer to the Multiboot information structure*/
pushl %ebx
/* push the magic value */
pushl %eax
call prekernelSetup
# Unmap the identity mapping as it is now unnecessary
# movl $0, boot_page_directory + 0
# Reload cr3 to force tlb flush # Reload cr3 to force tlb flush
movl %cr3, %ecx movl %cr3, %ecx
movl %ecx, %cr3 movl %ecx, %cr3
@ -97,6 +89,19 @@ isPaging:
pushl $0 pushl $0
popf popf
/* push the pointer to the Multiboot information structure*/
pushl %ebx
/* push the magic value */
pushl %eax
call prekernelSetup
# Unmap the identity mapping as it is now unnecessary
# movl $0, boot_page_directory + 0
call early_main call early_main

View File

@ -36,6 +36,8 @@ extern "C"
#include "serial.h" #include "serial.h"
#include "time.h" #include "time.h"
#include "definitions.h" #include "definitions.h"
extern "C" void LoadGlobalDescriptorTable();
/* /*
Copyright © Nigel Barink 2023 Copyright © Nigel Barink 2023
@ -50,18 +52,19 @@ extern "C" void kernel_main ()
startSuperVisorTerminal(); startSuperVisorTerminal();
} }
extern "C" void early_main() extern "C" void early_main()
{ {
init_serial(); init_serial();
kterm_init(); kterm_init();
setup_tss();
initGDT(); initGDT();
//setup_tss();
initidt(); initidt();
LoadGlobalDescriptorTable();
flush_tss();
printf("Memory setup complete!\n");
// Enable interrupts // Enable interrupts
asm volatile("STI"); asm volatile("STI");
@ -73,7 +76,7 @@ extern "C" void early_main()
initHeap(); initHeap();
printf("Enable Protected mode and jump to kernel main\n"); printf("Enable Protected mode and jump to kernel main\n");
// Set the protected bit of control register 0 // Set the protected bit of control register 0
// this will put the CPU into protected mode // this will put the CPU into protected mode

View File

@ -34,26 +34,27 @@ struct TaskStateSegment {
}__attribute__((packed)); }__attribute__((packed));
TaskStateSegment tss0 = {}; TaskStateSegment tss0 ={};
inline void flush_tss(){ inline void flush_tss()
asm volatile("mov (5 * 8) |0 , %eax; ltr %ax"); {
asm volatile("mov $0x2B, %ax ; ltr %ax");
} }
void setup_tss(){ void setup_tss(){
// ensure the tss is zero'd // ensure the tss is zero'd
//memset((void*)&tss0, 0, sizeof(tss0)); memset((void*)&tss0, 0, sizeof(tss0));
tss0.ss0 = (uint32_t) &(GlobalDescriptorTable[KERNEL_DATA_SEGMENT]); tss0.ss0 = (uint32_t) &GlobalDescriptorTable[KERNEL_DATA_SEGMENT];
uint32_t esp_addr =0 ;
asm volatile ("movl %%esp, %0" : "=a"(esp_addr)); extern uint32_t stack_top;
tss0.esp0 = esp_addr; tss0.esp0 = (unsigned long)&stack_top;
// Task Segment Descriptor // Task Segment Descriptor
add_descriptor(TASK_STATE_SEGMENT, (unsigned long)&tss0, sizeof(tss0), 0x89, 0x0);
flush_tss(); uint32_t address = (unsigned long) &tss0;
uint32_t size = sizeof(tss0);
uint32_t limit = (address + size );
add_descriptor(TASK_STATE_SEGMENT, address, limit- 1, 0xE9, 0x0);
} }

View File

@ -40,8 +40,7 @@ void initGDT(){
add_descriptor(USER_DATA_SEGMENT, 0, 0xFFFFFFFF, 0xF2, 0xCF); add_descriptor(USER_DATA_SEGMENT, 0, 0xFFFFFFFF, 0xF2, 0xCF);
// init Gdt Descriptor // init Gdt Descriptor
gdtDescriptor.limit = ((sizeof(SegmentDescriptor ) * 5 ) - 1); gdtDescriptor.limit = ((sizeof(SegmentDescriptor ) * 6 ) - 1);
gdtDescriptor.base = (unsigned int) (&GlobalDescriptorTable); gdtDescriptor.base = (unsigned int) (&GlobalDescriptorTable);
LoadGlobalDescriptorTable();
} }

View File

@ -32,5 +32,4 @@ struct GlobalDescriptorTableDescriptor{
void add_descriptor(int which , unsigned long base, unsigned long limit, unsigned char access, unsigned char granularity ); void add_descriptor(int which , unsigned long base, unsigned long limit, unsigned char access, unsigned char granularity );
extern "C" void LoadGlobalDescriptorTable();
void initGDT(); void initGDT();