void Init_Scheduler(void) { struct Kernel_Thread* mainThread = (struct Kernel_Thread *) KERNEL_THREAD_OBJECT; PrintBoth("Initializing Scheduler\n"); /* * Create initial kernel thread context object and stack, * and make them current. */ Init_Thread(mainThread, (void *) KERNEL_STACK, PRIORITY_NORMAL, true); g_currentThread = mainThread; Add_To_Back_Of_All_Thread_List(&s_allThreadList, mainThread); /* * Create the idle thread. */ /*Print("starting idle thread\n");*/ Start_Kernel_Thread(Idle, 0, PRIORITY_IDLE, true); /* * Create the reaper thread. */ /*Print("starting reaper thread\n");*/ Start_Kernel_Thread(Reaper, 0, PRIORITY_NORMAL, true); }
/* * Kernel C code entry point. * Initializes kernel subsystems, mounts filesystems, * and spawns init process. */ void Main(struct Boot_Info* bootInfo) { Init_BSS(); Init_Screen(); Init_Mem(bootInfo); Init_CRC32(); Init_TSS(); Init_Interrupts(); Init_Scheduler(); Init_Traps(); Init_Timer(); Init_Keyboard(); Set_Current_Attr(ATTRIB(BLACK, GREEN|BRIGHT)); Print("Welcome to GeekOS!\n"); Set_Current_Attr(ATTRIB(BLACK, GRAY)); /* TODO("Start a kernel thread to echo pressed keys and print counts");*/ Start_Kernel_Thread(&funct_eigen, 0, PRIORITY_NORMAL, false); /* Now this thread is done. */ Exit(0); }
/* * Initialize the floppy controller. */ void Init_Floppy(void) { uchar_t floppyByte; bool ready = false; bool good; Print("Initializing floppy controller...\n"); /* Allocate memory for DMA transfers */ s_transferBuf = (uchar_t*) Alloc_Page(); /* Use CMOS to get floppy configuration */ Out_Byte(CMOS_OUT, CMOS_FLOPPY_INDEX); floppyByte = In_Byte(CMOS_IN); Setup_Drive_Parameters(0, (floppyByte >> 4) & 0xF); Setup_Drive_Parameters(1, floppyByte & 0xF); /* Install floppy interrupt handler */ Install_IRQ(FDC_IRQ, &Floppy_Interrupt_Handler); Enable_IRQ(FDC_IRQ); /* Reset and calibrate the controller. */ Disable_Interrupts(); good = Reset_Controller(); Enable_Interrupts(); if (!good) { Print(" Failed to reset controller!\n"); goto done; } /* Reserve DMA channel 2. */ if (!Reserve_DMA(FDC_DMA)) { Print(" Failed to reserve DMA channel\n"); goto done; } /* * Driver is now ready for requests. * Start the request processing thread. */ ready = true; Start_Kernel_Thread(Floppy_Request_Thread, 0, PRIORITY_NORMAL, true); done: if (!ready) Print(" Floppy controller initialization FAILED\n"); }
void Init_IDE(void) { int errorCode; Print("Initializing IDE controller...\n"); /* Reset the controller and drives */ Out_Byte(IDE_DEVICE_CONTROL_REGISTER, IDE_DCR_NOINTERRUPT | IDE_DCR_RESET); Micro_Delay(100); Out_Byte(IDE_DEVICE_CONTROL_REGISTER, IDE_DCR_NOINTERRUPT); /* * FIXME: This code doesn't work on Bochs 2.0. * while ((In_Byte(IDE_STATUS_REGISTER) & IDE_STATUS_DRIVE_READY) == 0) * ; */ /* This code does work on Bochs 2.0. */ while (In_Byte(IDE_STATUS_REGISTER) & IDE_STATUS_DRIVE_BUSY) ; if(ideDebug) Print("About to run drive Diagnosis\n"); Out_Byte(IDE_COMMAND_REGISTER, IDE_COMMAND_DIAGNOSTIC); while (In_Byte(IDE_STATUS_REGISTER) & IDE_STATUS_DRIVE_BUSY) ; errorCode = In_Byte(IDE_ERROR_REGISTER); if(ideDebug > 1) Print("ide: ide error register = %x\n", errorCode); /* Probe and register drives */ int i; for(i = 0; i < IDE_MAX_DRIVES; i++) { if(readDriveConfig(i) == 0) ++numDrives; } if(ideDebug) Print("Found %d IDE drives\n", numDrives); /* Start request thread */ if(numDrives > 0) Start_Kernel_Thread(IDE_Request_Thread, 0, PRIORITY_NORMAL, true, "{IDE}"); }
/* * Kernel C code entry point. * Initializes kernel subsystems, mounts filesystems, * and spawns init process. */ void Main(struct Boot_Info* bootInfo) { Init_BSS(); Init_Screen(); Init_Mem(bootInfo); Init_CRC32(); Init_TSS(); Init_Interrupts(); Init_Scheduler(); Init_Traps(); Init_Timer(); Init_Keyboard(); Set_Current_Attr(ATTRIB(BLACK, GREEN|BRIGHT)); Print("Welcome to GeekOS!\n"); Set_Current_Attr(ATTRIB(BLACK, GRAY)); Start_Kernel_Thread(Print_Key_Pressed, 0, PRIORITY_NORMAL, false); /* Now this thread is done. */ Exit(0); }
static void Spawn_Init_Process(void) { /* this thread will load&run ELF files, see the rest in lprog.c */ Print("Starting the Spawner thread...\n"); Start_Kernel_Thread( Spawner, 0, PRIORITY_NORMAL, true ); }