Document initialization on AMD64

This commit is contained in:
Ali Mashtizadeh 2023-08-20 19:06:38 -04:00
parent c8f6294511
commit 45928b97a8

View File

@ -40,7 +40,16 @@ static PseudoDescriptor GDTDescriptor[MAX_CPUS];
TaskStateSegment64 TSS[MAX_CPUS]; TaskStateSegment64 TSS[MAX_CPUS];
static char df_stack[4096]; static char df_stack[4096];
/*
* Machine_GDTInit --
*
* Configures the Global Descriptor Table (GDT) that lists all segments
* and privilege levels in x86. 64-bit mode uses flat 64-bit segments and
* doesn't support offsets and limits except for the special FS/GS segment
* registers. We create four segments for the kernel code/data and user
* code/data.
*/
static void static void
Machine_GDTInit() Machine_GDTInit()
{ {
@ -76,6 +85,12 @@ Machine_GDTInit()
kprintf("Done!\n"); kprintf("Done!\n");
} }
/*
* Machine_TSSInit --
*
* Configures the Task State Segment (TSS) that specifies the kernel stack
* pointer during an interrupt.
*/
static void static void
Machine_TSSInit() Machine_TSSInit()
{ {
@ -104,6 +119,13 @@ Machine_TSSInit()
kprintf("Done!\n"); kprintf("Done!\n");
} }
/*
* Machine_SyscallInit --
*
* Configure the model specific registers (MSRs) that specify how to
* transfer control to the operating system when the system call
* instruction is invoked.
*/
static void static void
Machine_SyscallInit() Machine_SyscallInit()
{ {
@ -117,6 +139,11 @@ Machine_SyscallInit()
kprintf("Done!\n"); kprintf("Done!\n");
} }
/*
* Machine_EarlyInit --
*
* Initializes early kernel state.
*/
void void
Machine_EarlyInit() Machine_EarlyInit()
{ {
@ -133,23 +160,42 @@ Machine_IdleThread(void *test)
while (1) { enable_interrupts(); hlt(); } while (1) { enable_interrupts(); hlt(); }
} }
/*
* Machine_Init --
*
* At this point the assembly startup code has setup temporary processor
* data structures sufficient to execute C code and make it through this
* initialization routine.
*/
void Machine_Init() void Machine_Init()
{ {
/*
* Initialize Processor State
*/
Machine_GDTInit(); Machine_GDTInit();
Machine_TSSInit(); Machine_TSSInit();
Trap_Init(); Trap_Init();
Machine_SyscallInit(); Machine_SyscallInit();
clts(); // Enable FPU/XMM clts(); // Enable FPU/XMM
/*
* Initialize Memory Allocation and Virtual Memory
*/
PAlloc_AddRegion(DMPA2VA(16*1024*1024), 16*1024*1024); PAlloc_AddRegion(DMPA2VA(16*1024*1024), 16*1024*1024);
PMap_Init(); PMap_Init();
XMem_Init(); XMem_Init();
PAlloc_LateInit(); PAlloc_LateInit();
MachineBoot_AddMem(); MachineBoot_AddMem();
/*
* Initialize Time Keeping
*/
KTime_Init(); KTime_Init();
RTC_Init(); // Finishes initializing KTime RTC_Init(); // Finishes initializing KTime
/*
* Initialize Interrupts
*/
IRQ_Init(); IRQ_Init();
LAPIC_Init(); LAPIC_Init();
IOAPIC_Init(); IOAPIC_Init();
@ -158,13 +204,22 @@ void Machine_Init()
KTimer_Init(); // Depends on RTC and KTime KTimer_Init(); // Depends on RTC and KTime
/*
* Initialize Additional Processors
*/
MP_Init(); MP_Init();
PS2_Init(); /*
PCI_Init(); * Initialize Basic Devices
IDE_Init(); */
PS2_Init(); // PS2 Keyboard
PCI_Init(); // PCI BUS
IDE_Init(); // IDE Disk Controller
BufCache_Init(); BufCache_Init();
/*
* Open the primary disk and mount the root file system
*/
Disk *root = Disk_GetByID(0, 0); Disk *root = Disk_GetByID(0, 0);
if (!root) if (!root)
Panic("No boot disk!"); Panic("No boot disk!");
@ -172,17 +227,28 @@ void Machine_Init()
Critical_Exit(); Critical_Exit();
/*
* Create the idle thread
*/
Thread *thr = Thread_KThreadCreate(&Machine_IdleThread, NULL); Thread *thr = Thread_KThreadCreate(&Machine_IdleThread, NULL);
if (thr == NULL) { if (thr == NULL) {
kprintf("Couldn't create idle thread!\n"); kprintf("Couldn't create idle thread!\n");
} }
Sched_SetRunnable(thr); Sched_SetRunnable(thr);
/*
* Load the init processor
*/
Loader_LoadInit(); Loader_LoadInit();
breakpoint(); breakpoint();
} }
/*
* Machine_InitAP --
*
* Shorter initialization routine for co-processors.
*/
void Machine_InitAP() void Machine_InitAP()
{ {
Critical_Enter(); Critical_Enter();