Changeset 538 for Whitix/branches/hybrid/kernel
- Timestamp:
- 05/24/08 09:54:46 (6 months ago)
- Location:
- Whitix/branches/hybrid/kernel
- Files:
-
- 1 added
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/hybrid/kernel/main.c
r489 r538 17 17 */ 18 18 19 /* TODO: Fix cli(); hlt();*/19 /* FIXME: Trim includes. */ 20 20 21 21 #include <console.h> … … 35 35 #include <time.h> 36 36 37 /* Implement proper ramdisk support and remove. */38 #include "../devices/storage/ata/ata.h"39 40 extern WORD rootDevMajor,rootDevMinor;41 extern BYTE biosDriveNo;42 43 static void CallInitCalls()44 {45 InitCall* currCall;46 47 for (currCall=(InitCall*)initcall_start; currCall<(InitCall*)initcall_end; currCall++)48 (*currCall)();49 }50 51 struct StorageDevice* StartMountCd()52 {53 int i;54 struct StorageDevice* rootDev=NULL;55 56 /* Temporary hack for live cd */57 for (i=0; i<256; i+=64)58 {59 struct AtaDrive* drive;60 rootDev=DevFindRootDev(4,i);61 if (!rootDev)62 continue;63 64 drive=(struct AtaDrive*)(rootDev->priv);65 66 if (drive->type & ATA_REMOVABLE)67 break;68 }69 70 /* Didn't find it */71 if (i == 256)72 rootDev=NULL;73 74 return rootDev;75 }76 77 /*78 * Start79 * -----80 *81 * This is where system things will be inited82 * This still runs at kernel level and does all the things that main83 * just couldn't do, like fs code84 */85 86 #define RANGE_KBS(start,end) ((DWORD)end-(DWORD)start)/102487 88 static void Start()89 {90 struct StorageDevice* rootDev=NULL;91 int fds[]={92 0,0,0,93 };94 95 CallInitCalls();96 97 /* For ISO filesystems, have a ramdisk - makes life a lot easier */98 if (biosDriveNo > 0x80 && rootDevMajor == 4)99 rootDev=StartMountCd();100 else101 /* Decode root filesystem here */102 rootDev=DevFindRootDev(rootDevMajor,rootDevMinor);103 104 if (!rootDev)105 {106 printf("Device major:%d, minor: %d not valid root device.\n",(int)rootDevMajor,(int)rootDevMinor);107 cli();108 hlt();109 }110 111 VfsMountRoot(rootDev);112 113 /* Print a few stats about the size of the kernel */114 printf("Kernel code size: %uk, kernel data size: %uk, kernel BSS size: %uk\n",RANGE_KBS(code,endCode),RANGE_KBS(data,endData),RANGE_KBS(bss,endbss));115 116 /* This mounting will be moved to an init-like program. */117 118 printf("DEVFS: Mounting device filesystem at %s\n", DEVICES_PATH);119 120 if (VfsMount(NULL,DEVICES_PATH,"DevFs",NULL))121 {122 KernelPanic("Failed to mount the device filesystem");123 }124 125 printf("Mounted the filesystems. Starting the shell\n");126 127 if (DoOpenFile(¤t->files[0], DEVICES_PATH "/Consoles/Console0",FILE_READ | FILE_FORCE_OPEN,0))128 KernelPanic("Failed to open the first console. Halting");129 130 extern int Exec(char* pathName,int* fds,char** argv);131 if (Exec("/System/Startup/startup", fds, NULL) < 0)132 KernelPanic("Could not launch the startup program. Halting");133 134 ThrProcessExit(0);135 ThrSchedule();136 137 while (1) hlt();138 }139 140 37 extern int ArchInit(); 141 38 142 39 void KernelMain() 143 40 { 144 struct Process* start; 145 struct Thread* firstThread; 146 41 EarlyConsoleInit(); 147 42 ArchInit(); 148 ThrInit(); 149 VfsInit(); 43 ThrEarlyInit(); 150 44 TimeInit(); 151 45 152 start=ThrCreateProcess("KernelLoading"); 153 firstThread=ThrCreateThread(start,(DWORD)Start,false,0, NULL); 46 ModulesBootLoad(); 154 47 155 ThrStartThread(firstThread); 156 157 /* This is where the idle thread idles */ 48 /* This is where the idle thread idles, after returning from StartInit in startup.c */ 158 49 ThrIdleFunc(); 159 50 } -
Whitix/branches/hybrid/kernel/module.c
r490 r538 29 29 #include <sys.h> 30 30 #include <task.h> 31 #include <imports.h> 31 32 32 33 LIST_HEAD(moduleList); 34 35 static struct Module bootModules[20]; 36 int bootIndex=0; 33 37 34 38 #define MODULE_START 0xD8000000 … … 83 87 84 88 if (name) 85 printf("%s+%#X/%#X\n", name, offset, size);89 KePrint("%s+%#X/%#X\n", name, offset, size); 86 90 else 87 printf("%#X\n", address);91 KePrint("%#X\n", address); 88 92 }else 89 printf("%#X\n", address);93 KePrint("%#X\n", address); 90 94 } 91 95 … … 106 110 void ModuleSymbolPrint(DWORD address) 107 111 { 108 printf("%#X\n", address);112 KePrint("%#X\n", address); 109 113 } 110 114 … … 148 152 } 149 153 150 printf("Could not resolve %s\n", name);154 KePrint("Could not resolve %s\n", name); 151 155 152 156 return 0; … … 191 195 break; 192 196 193 printf("Could not resolve %s\n", symName);197 KePrint("Could not resolve %s\n", symName); 194 198 return -ENOENT; 195 199 … … 200 204 /* Common symbols aren't supported by the module loading code. */ 201 205 case STN_COMMON: 202 printf("Please recompile the module with -fno-common.\n");206 KePrint("Please recompile the module with -fno-common.\n"); 203 207 return -ENOENT; 204 208 … … 240 244 241 245 default: 242 printf("ModuleSymbolResolve: type = %u, %u\n", ELF_R_TYPE(reloc->info), symbol->symIndex);246 KePrint("ModuleSymbolResolve: type = %u, %u\n", ELF_R_TYPE(reloc->info), symbol->symIndex); 243 247 } 244 248 } … … 286 290 287 291 /* Get basic information about the module. */ 288 module=(struct Module*)malloc(sizeof(struct Module)); 292 if (MemAlloc) 293 module=(struct Module*)MemAlloc(sizeof(struct Module)); 294 else 295 module=&bootModules[bootIndex++]; 296 289 297 module->loadAddr=loadAddr; 290 298 module->sectionHeaders=sectionHeaders; … … 362 370 } 363 371 372 #define SYS_MODULE_BASE 51 373 374 int SysModuleAdd(void* data, unsigned long length); 375 int SysModuleRemove(const char* name); 376 377 struct SysCall moduleSysCalls[]={ 378 { SysModuleAdd, 8 }, 379 { SysModuleRemove, 4}, 380 { 0, 0 } 381 }; 382 383 void ModulesBootLoad() 384 { 385 /* The modules are located above the kernel in memory. */ 386 BYTE* numModules=(BYTE*)0x2FFFF; 387 int i=0; 388 DWORD* length=(DWORD*)0x40000; 389 char* names=(char*)0x30000; 390 391 for (i=0; i<*numModules; i++) 392 { 393 /* Load each module, one at a time. */ 394 BYTE* data=(BYTE*)(length+1); 395 void* kData=(void*)VirtMapPhysRange(MODULE_START, MODULE_END, PAGE_ALIGN_UP(*length) >> PAGE_SHIFT, 3); 396 char buf[32]; 397 398 int j=0; 399 400 while (names[j] != '\n') 401 j++; 402 403 names[j]='\0'; 404 405 strcpy(buf, names); 406 strcat(buf, ".sys"); 407 408 if (ModuleAdd(data, kData, *length, 0)) 409 KernelPanic("Could not initialize the kernel"); 410 411 KePrint("MODULES: Loaded %s, %dkb\n", buf, (*length)/1024); 412 413 names+=strlen(names)+1; 414 415 length+=(*length/4)+1; 416 } 417 418 /* Free the low pages. */ 419 420 /* Add the calls to the system table. */ 421 SysRegisterRange(SYS_MODULE_BASE, moduleSysCalls); 422 } 423 364 424 int SysModuleAdd(void* data, unsigned long length) 365 425 { … … 374 434 int SysModuleRemove(const char* name) 375 435 { 376 printf("SysModuleRemove\n");436 KePrint("SysModuleRemove\n"); 377 437 return 0; 378 438 } -
Whitix/branches/hybrid/kernel/sched.c
r491 r538 17 17 */ 18 18 19 /* TODO: Clean up these includes. */ 19 20 #include <sched.h> 20 21 #include <error.h> … … 25 26 #include <malloc.h> 26 27 #include <fs/vfs.h> 28 #include <init.h> 27 29 #include <task.h> 28 30 #include <panic.h> … … 31 33 #include <net/socket.h> 32 34 #include <module.h> 35 #include <imports.h> 36 #include <sys.h> 33 37 34 38 /* List heads */ … … 55 59 56 60 /* Used when a thread is exiting */ 57 DWORD exitStack[PAGE_SIZE];61 BYTE exitStack[PAGE_SIZE/4]; 58 62 59 63 /*********************************************************************** … … 141 145 SpinLockIrq(&procListLock); 142 146 143 process=(struct Process*) MemCacheAlloc(processCache);147 process=(struct Process*)memCacheAlloc(processCache); 144 148 if (!process) 145 149 return NULL; … … 147 151 if (VirtMemManagerSetup(process)) 148 152 { 149 MemCacheFree(processCache,process);153 memCacheFree(processCache,process); 150 154 SpinUnlockIrq(&procListLock); 151 155 return NULL; … … 153 157 154 158 /* Allocate the process's name - used when listing processes or when faulting. */ 155 process->name=(char*) malloc(strlen(name)+1);156 strcpy(process->name, name);159 process->name=(char*)MemAlloc(strlen(name)+1); 160 strcpy(process->name, name); 157 161 158 162 /* Add to parent's children list */ … … 168 172 process->state=THR_RUNNING; 169 173 170 process->files=NULL; 174 process->files=NULL; /* FIXME */ 171 175 172 176 ListAddTail(&process->next,&processList); … … 176 180 return process; 177 181 } 182 183 SYMBOL_EXPORT(ThrCreateProcess); 178 184 179 185 /*********************************************************************** … … 200 206 ListRemove(&process->next); 201 207 202 free(process->name);203 MemCacheFree(processCache,process);208 MemFree(process->name); 209 memCacheFree(processCache,process); 204 210 205 211 IrqRestoreFlags(flags); 206 212 } 213 214 SYMBOL_EXPORT(ThrFreeProcess); 207 215 208 216 /*********************************************************************** … … 251 259 SpinLockIrq(&thrListLock); 252 260 253 ret=(struct Thread*) MemCacheAlloc(threadCache);261 ret=(struct Thread*)memCacheAlloc(threadCache); 254 262 if (!ret) 255 263 return NULL; … … 272 280 } 273 281 282 SYMBOL_EXPORT(ThrCreateThread); 283 274 284 /*********************************************************************** 275 285 * … … 295 305 } 296 306 307 SYMBOL_EXPORT(ThrSetPriority); 308 297 309 /*********************************************************************** 298 310 * … … 310 322 void _ThrFreeThread(struct Thread* thread) 311 323 { 312 free((void*)thread->currStack);324 MemFree((void*)thread->currStack); 313 325 currThread=NULL; 314 MemCacheFree(threadCache, thread);326 memCacheFree(threadCache, thread); 315 327 ThrSchedule(); 316 328 } … … 350 362 351 363 if (thread == currThread) 352 ArchSwitchStackCall(exitStack+PAGE_SIZE ,_ThrFreeThread,thread);364 ArchSwitchStackCall(exitStack+PAGE_SIZE/4,_ThrFreeThread,thread); 353 365 else{ 354 free((void*)(thread->currStack));355 MemCacheFree(threadCache,thread);366 MemFree((void*)(thread->currStack)); 367 memCacheFree(threadCache,thread); 356 368 } 357 369 … … 401 413 } 402 414 } 415 416 SYMBOL_EXPORT(ThrStartThread); 403 417 404 418 /*********************************************************************** … … 467 481 ***********************************************************************/ 468 482 483 /* TODO: Move to filesystem code. */ 484 469 485 static void ThrReleaseFsContext() 470 486 { … … 473 489 /* Now release the filesystem context */ 474 490 475 if (current->files)491 // if (current->files) 476 492 /* Close all files associated with the process */ 477 for (i=0; i<current->numFds; i++)478 DoCloseFile(¤t->files[i]);493 // for (i=0; i<current->numFds; i++) 494 // DoCloseFile(¤t->files[i]); 479 495 480 496 /* Does not apply to the KernelLoading process */ 481 if (current->exec)482 VNodeRelease(current->exec);483 484 VNodeRelease(current->cwd);485 VNodeRelease(current->root);486 487 free(current->files);488 free(current->sCwd);497 // if (current->exec) 498 // VNodeRelease(current->exec); 499 500 // VNodeRelease(current->cwd); 501 // VNodeRelease(current->root); 502 503 // free(current->files); 504 // free(current->sCwd); 489 505 } 490 506 … … 511 527 512 528 /* Release all vmm areas */ 513 MmapProcessRemove(current);529 // MmapProcessRemove(current); 514 530 ThrReleaseFsContext(); 515 531 … … 548 564 } 549 565 566 SYMBOL_EXPORT(ThrProcessExit); 567 550 568 /*********************************************************************** 551 569 * … … 599 617 } 600 618 } 619 620 SYMBOL_EXPORT(ThrResumeThread); 601 621 602 622 /*********************************************************************** … … 751 771 int SysExitThread(int threadId) 752 772 { 753 // printf("SysExitThread(%d)\n", threadId);754 773 if (threadId == -1) /* Exit current thread. */ 755 774 ThrDoExitThread(); … … 803 822 waitEntry.thread=currThread; 804 823 805 if (finishStatus)806 if (VirtCheckArea(finishStatus,sizeof(int),VER_WRITE))807 return -EFAULT;824 // if (finishStatus) 825 // if (VirtCheckArea(finishStatus,sizeof(int),VER_WRITE)) 826 // return -EFAULT; 808 827 809 828 if (pid >= 0) … … 903 922 ***********************************************************************/ 904 923 905 int Thr Init()924 int ThrEarlyInit() 906 925 { 907 926 ThrArchInit(); /* Set up arch-specific data structures for multitasking here */ 908 909 /* Allocate the general scheduling caches */910 processCache=MemCacheCreate("Process Cache", sizeof(struct Process), ThrProcessConstructor, NULL, 0);911 threadCache=MemCacheCreate("Thread Cache", sizeof(struct Thread), NULL, NULL, 0);912 927 913 928 currThread=idleTask; … … 919 934 return 0; 920 935 } 936 937 #define SYS_SCHED_BASE 34 938 939 struct SysCall schedSysCallTable[]= 940 { 941 { SysCreateThread, 12 }, 942 { SysGetCurrentThreadId, 0 }, 943 { SysGetCurrentProcessId, 0 }, 944 { SysExitThread, 4 }, 945 { SysExit, 4 }, 946 { SysWaitForProcessFinish, 8 }, 947 { SysYield, 0 }, 948 { 0, 0 }, 949 }; 950 951 int ThrInit() 952 { 953 /* Allocate the general scheduling caches */ 954 processCache=memCacheCreate("Process Cache", sizeof(struct Process), ThrProcessConstructor, NULL, 0); 955 threadCache=memCacheCreate("Thread Cache", sizeof(struct Thread), NULL, NULL, 0); 956 957 /* Register the threading system calls. */ 958 SysRegisterRange(SYS_SCHED_BASE, schedSysCallTable); 959 960 return 0; 961 } 962 963 CoreInit(ThrInit); -
Whitix/branches/hybrid/kernel/symbols.c
r483 r538 65 65 if (*offset > *size) 66 66 { 67 printf("%#X-%#X = %#X %#X\n", address, symbol->symValue, *offset, *size);67 KePrint("%#X-%#X = %#X %#X\n", address, symbol->symValue, *offset, *size); 68 68 while (1); 69 69 } … … 79 79 80 80 if (name) 81 printf("%s+%#X/%#X\n", name, offset, size);81 KePrint("%s+%#X/%#X\n", name, offset, size); 82 82 else 83 printf("%#X\n", address); 84 } 85 86 int SymbolInit() 87 { 88 return 0; 83 KePrint("%#X\n", address); 89 84 } 90 85 … … 124 119 } 125 120 126 CoreInit(SymbolInit);127 128 121 #else 129 122 /* Stub functions. */ … … 131 124 void SymbolPrint(DWORD address) 132 125 { 133 printf("%10X\n", address); 126 KePrint("%10X\n", address); 127 } 128 129 void SymbolsCopy() 130 { 134 131 } 135 132