From: John Hodge Date: Fri, 16 Jul 2010 09:41:21 +0000 (+0800) Subject: Working on multiprocessing support X-Git-Tag: rel0.06~101 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=ccd6cf2af99fdc050888c70eb4d59f078a15a2da;p=tpg%2Facess2.git Working on multiprocessing support - Also some cleanup in other parts --- diff --git a/Kernel/arch/x86/include/proc.h b/Kernel/arch/x86/include/proc.h index 5e3fadd9..2b04b757 100644 --- a/Kernel/arch/x86/include/proc.h +++ b/Kernel/arch/x86/include/proc.h @@ -7,17 +7,7 @@ #include -// === TYPES === -#if USE_MP -typedef struct sCPU -{ - Uint8 APICID; - Uint8 State; // 0: Unavaliable, 1: Idle, 2: Active - Uint16 Resvd; - tThread *Current; -} tCPU; -#endif - +// === TYPES == typedef struct sTSS { Uint32 Link; Uint32 ESP0, SS0; diff --git a/Kernel/arch/x86/main.c b/Kernel/arch/x86/main.c index 3a45637c..f9e70e5c 100644 --- a/Kernel/arch/x86/main.c +++ b/Kernel/arch/x86/main.c @@ -33,6 +33,7 @@ void Arch_LoadBootModules(void); // === GLOBALS === char *gsBootCmdLine = NULL; struct { + Uint32 PBase; void *Base; Uint Size; char *ArgString; @@ -66,7 +67,7 @@ int kmain(Uint MbMagic, void *MbInfoPtr) // Multiboot 2 case MULTIBOOT2_MAGIC: - Warning("Multiboot 2 Not yet supported"); + Panic("Multiboot 2 not yet supported"); //MM_InstallMBoot2( MbInfo ); // Set up physical memory manager return 0; break; @@ -102,9 +103,10 @@ int kmain(Uint MbMagic, void *MbInfoPtr) Log_Log("Arch", "Multiboot Module at 0x%08x, 0x%08x bytes (String at 0x%08x)", mods[i].Start, mods[i].End-mods[i].Start, mods[i].String); - // Always HW map the module data + gaArch_BootModules[i].PBase = mods[i].Start; gaArch_BootModules[i].Size = mods[i].End - mods[i].Start; - + + // Always HW map the module data ofs = mods[i].Start&0xFFF; gaArch_BootModules[i].Base = (void*)( MM_MapHWPages(mods[i].Start, (gaArch_BootModules[i].Size+ofs+0xFFF) / 0x1000 @@ -134,13 +136,9 @@ int kmain(Uint MbMagic, void *MbInfoPtr) void Arch_LoadBootModules(void) { - int i; + int i, j, numPages; for( i = 0; i < giArch_NumBootModules; i ++ ) { - Log_Debug("Arch", "Module %i: %p - %p 0x%x", - i, gaArch_BootModules[i].ArgString, - gaArch_BootModules[i].Base, gaArch_BootModules[i].Size - ); Log_Log("Arch", "Loading '%s'", gaArch_BootModules[i].ArgString); if( !Module_LoadMem( gaArch_BootModules[i].Base, gaArch_BootModules[i].Size, gaArch_BootModules[i].ArgString ) ) @@ -148,10 +146,12 @@ void Arch_LoadBootModules(void) Log_Warning("Arch", "Unable to load module"); } - MM_UnmapHWPages( - (tVAddr)gaArch_BootModules[i].Base, - (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12 - ); + // Unmap and free + numPages = (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12; + MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].Base, numPages ); + + for( j = 0; j < numPages; j++ ) + MM_DerefPhys( gaArch_BootModules[i].PBase + (j << 12) ); if( (tVAddr) gaArch_BootModules[i].ArgString > MAX_ARGSTR_POS ) MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].ArgString, 2 ); diff --git a/Kernel/arch/x86/mm_phys.c b/Kernel/arch/x86/mm_phys.c index b3325c90..3c7dcddc 100644 --- a/Kernel/arch/x86/mm_phys.c +++ b/Kernel/arch/x86/mm_phys.c @@ -39,12 +39,10 @@ void MM_Install(tMBoot_Info *MBoot) tMBoot_MMapEnt *ent; // --- Find largest address - Log("MBoot->MMapAddr = %08x", MBoot->MMapAddr); MBoot->MMapAddr |= KERNEL_BASE; ent = (void *)( MBoot->MMapAddr ); while( (Uint)ent < MBoot->MMapAddr + MBoot->MMapLength ) { - Log(" ent->Size = %08x", ent->Size); // Adjust for size ent->Size += 4; @@ -91,12 +89,10 @@ void MM_Install(tMBoot_Info *MBoot) // Mark Multiboot's pages as taken // - Structure MM_RefPhys( (Uint)MBoot - KERNEL_BASE ); - Log("MBoot->ModuleCount = %i", MBoot->ModuleCount); // - Module List for(i = (MBoot->ModuleCount*sizeof(tMBoot_Module)+0xFFF)>12; i--; ) MM_RefPhys( MBoot->Modules + (i << 12) ); // - Modules - Log("MBoot->Modules = %p", MBoot->Modules); mods = (void*)(MBoot->Modules + KERNEL_BASE); for(i = 0; i < MBoot->ModuleCount; i++) { diff --git a/Kernel/arch/x86/mm_virt.c b/Kernel/arch/x86/mm_virt.c index fc689f78..4c2455e1 100644 --- a/Kernel/arch/x86/mm_virt.c +++ b/Kernel/arch/x86/mm_virt.c @@ -158,7 +158,6 @@ void MM_InstallVirtual(void) // Unset kernel on the User Text pages for( i = ((tVAddr)&_UsertextEnd-(tVAddr)&_UsertextBase+0xFFF)/4096; i--; ) { - Log("MM_SetFlags( 0x%08x, 0, MM_PFLAG_KERNEL)", (tVAddr)&_UsertextBase + i*4096); MM_SetFlags( (tVAddr)&_UsertextBase + i*4096, 0, MM_PFLAG_KERNEL ); } } diff --git a/Kernel/arch/x86/proc.asm b/Kernel/arch/x86/proc.asm index ebc1664e..348c31ba 100644 --- a/Kernel/arch/x86/proc.asm +++ b/Kernel/arch/x86/proc.asm @@ -156,7 +156,7 @@ Proc_ReturnToUser: [global GetCPUNum] GetCPUNum: xor eax, eax - ltr ax + str ax sub ax, 0x30 shr ax, 3 ; ax /= 8 ret diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 5406d2e4..c9035e1b 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -19,9 +19,21 @@ // Base is 1193182 #define TIMER_DIVISOR 11931 //~100Hz +// === TYPES === +#if USE_MP +typedef struct sCPU +{ + Uint8 APICID; + Uint8 State; // 0: Unavaliable, 1: Idle, 2: Active + Uint16 Resvd; + tThread *Current; +} tCPU; +#endif + // === IMPORTS === extern tGDT gGDT[]; extern tIDT gIDT[]; +extern void APWait(void); // 16-bit AP pause code extern void APStartup(void); // 16-bit AP startup code extern Uint GetEIP(void); // start.asm extern int GetCPUNum(void); // start.asm @@ -64,6 +76,7 @@ tMPInfo *gMPFloatPtr = NULL; tAPIC *gpMP_LocalAPIC = NULL; Uint8 gaAPIC_to_CPU[256] = {0}; tCPU gaCPUs[MAX_CPUS]; + int giProc_BootProcessorID = 0; #else tThread *gCurrentThread = NULL; #endif @@ -170,7 +183,7 @@ void ArchThreads_Init(void) Log("\t.ExtendedTableChecksum = 0x%02x", mptable->ExtendedTableChecksum); Log("}"); - gpMP_LocalAPIC = (void*)MM_MapHWPage(mptable->LocalAPICMemMap, 1); + gpMP_LocalAPIC = (void*)MM_MapHWPages(mptable->LocalAPICMemMap, 1); ents = mptable->Entries; giNumCPUs = 0; @@ -207,10 +220,9 @@ void ArchThreads_Init(void) gaCPUs[giNumCPUs].State = 0; giNumCPUs ++; - // Send IPI - if( !(ents->Proc.CPUFlags & 2) ) - { - MP_StartAP( giNumCPUs-1 ); + // Set BSP Variable + if( ents->Proc.CPUFlags & 2 ) { + giProc_BootProcessorID = giNumCPUs-1; } break; @@ -218,7 +230,7 @@ void ArchThreads_Init(void) entSize = 8; Log("%i: Bus", i); Log("\t.ID = %i", ents->Bus.ID); - Log("\t.TypeString = '%6c'", ents->Bus.TypeString); + Log("\t.TypeString = '%6C'", ents->Bus.TypeString); break; case 2: // I/O APIC entSize = 8; @@ -259,11 +271,6 @@ void ArchThreads_Init(void) Warning("Too many CPUs detected (%i), only using %i of them", giNumCPUs, MAX_CPUS); giNumCPUs = MAX_CPUS; } - - while( giNumInitingCPUs ) - MM_FinishVirtualInit(); - - Panic("Uh oh... MP Table Parsing is unimplemented\n"); } else { Log("No MP Table was found, assuming uniprocessor\n"); @@ -277,26 +284,15 @@ void ArchThreads_Init(void) #endif // Initialise Double Fault TSS - /* - gGDT[5].LimitLow = sizeof(tTSS); - gGDT[5].LimitHi = 0; - gGDT[5].Access = 0x89; // Type - gGDT[5].Flags = 0x4; - */ gGDT[5].BaseLow = (Uint)&gDoubleFault_TSS & 0xFFFF; gGDT[5].BaseMid = (Uint)&gDoubleFault_TSS >> 16; gGDT[5].BaseHi = (Uint)&gDoubleFault_TSS >> 24; - Log_Debug("Proc", "gIDT[8] = {OffsetLo:%04x, CS:%04x, Flags:%04x, OffsetHi:%04x}", - gIDT[8].OffsetLo, gIDT[8].CS, gIDT[8].Flags, gIDT[8].OffsetHi); + // Set double fault IDT to use the new TSS gIDT[8].OffsetLo = 0; gIDT[8].CS = 5<<3; gIDT[8].Flags = 0x8500; gIDT[8].OffsetHi = 0; - Log_Debug("Proc", "gIDT[8] = {OffsetLo:%04x, CS:%04x, Flags:%04x, OffsetHi:%04x}", - gIDT[8].OffsetLo, gIDT[8].CS, gIDT[8].Flags, gIDT[8].OffsetHi); - - //__asm__ __volatile__ ("xchg %bx, %bx"); #if USE_MP // Initialise Normal TSS(s) @@ -312,13 +308,26 @@ void ArchThreads_Init(void) gGDT[6+pos].BaseHi = ((Uint)(&gTSSs[pos])) >> 24; #if USE_MP } - for(pos=0;posoc = PCI_CfgReadWord(bus, slot, fcn, 0x8|2); // Load Config Bytes - addr = 0x80000000 | ((Uint)bus<<16) | ((Uint)slot<<11) | ((Uint)fcn<<8); for(i=0;i<256/4;i++) { - #if 0 - outd(0xCF8, addr); - info->ConfigCache[i] = ind(0xCFC); - addr += 4; - #else info->ConfigCache[i] = PCI_CfgReadDWord(bus, slot, fcn, i*4); - #endif } //#if LIST_DEVICES diff --git a/Kernel/logging.c b/Kernel/logging.c index 507ff07c..6ba68bff 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -123,6 +123,7 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) */ void Log_Int_PrintMessage(tLogEntry *Entry) { + //LOCK( &glLogOutput ); LogF("%s%014lli%s [%+8s] %s\x1B[0m\n", csaLevelColours[Entry->Level], Entry->Time, @@ -130,6 +131,7 @@ void Log_Int_PrintMessage(tLogEntry *Entry) Entry->Ident, Entry->Data ); + //RELEASE( &glLogOutput ); } /** diff --git a/Makefile.i486.cfg b/Makefile.i486.cfg new file mode 120000 index 00000000..5b8aab70 --- /dev/null +++ b/Makefile.i486.cfg @@ -0,0 +1 @@ +Makefile.i386.cfg \ No newline at end of file diff --git a/Makefile.i586.cfg b/Makefile.i586.cfg new file mode 120000 index 00000000..5b8aab70 --- /dev/null +++ b/Makefile.i586.cfg @@ -0,0 +1 @@ +Makefile.i386.cfg \ No newline at end of file diff --git a/Modules/Filesystems/InitRD/GenerateInitRD.php b/Modules/Filesystems/InitRD/GenerateInitRD.php index 031ad590..ab6eb600 100644 --- a/Modules/Filesystems/InitRD/GenerateInitRD.php +++ b/Modules/Filesystems/InitRD/GenerateInitRD.php @@ -10,6 +10,12 @@ $gOutput = << 3 ? $argv[3] : false); + +$gDependencies = array(); + $lines = file($argv[1]); $lDepth = 0; @@ -34,6 +40,7 @@ foreach($lines as $line) if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches)) { $lStack[$lDepth][1][] = array($matches[1], $matches[2]); + $gDependencies[] = $matches[2]; continue; } echo "ERROR: $line\n"; @@ -41,6 +48,14 @@ foreach($lines as $line) } function hd($fp) +{ + //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT ); + $val = unpack("I", fread($fp, 4)); + //print_r($val); exit -1; + return "0x".dechex($val[1]); +} + +function hd8($fp) { return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT ); } @@ -83,25 +98,50 @@ EOF; } $size = filesize($item[1]); - $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n"; $fp = fopen($item[1], "rb"); - for( $j = 0; $j + 16 < $size; $j += 16 ) + if(0) { + $gOutput .= "Uint32 {$prefix}_{$i}_data[] = {\n"; + for( $j = 0; $j + 16 < $size; $j += 16 ) + { + $gOutput .= "\t"; + $gOutput .= hd($fp).",".hd($fp).","; + $gOutput .= hd($fp).",".hd($fp).",\n"; + } $gOutput .= "\t"; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).",\n"; + for( ; $j+3 < $size; $j += 4 ) + { + if( $j & 15 ) $gOutput .= ","; + $gOutput .= hd($fp); + } + if($j < $size) { + $tmp = ""; + while($j ++ < $size) + $tmp .= fgetc($fp); + $tmp .= "\0\0\0"; + $tmp = unpack("I", $tmp); + $gOutput .= "0x".dechex($tmp[1]); + } } - $gOutput .= "\t"; - for( ; $j < $size; $j ++ ) + else { - if( $j & 15 ) $gOutput .= ","; - $gOutput .= hd($fp); + $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n"; + for( $j = 0; $j + 16 < $size; $j += 16 ) { + $gOutput .= "\t"; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).",\n"; + } + $gOutput .= "\t"; + for( ; $j < $size; $j ++ ) { + if( $j & 15 ) $gOutput .= ","; + $gOutput .= hd8($fp); + } } fclose($fp); $gOutput .= "\n};\n"; @@ -145,7 +185,17 @@ tVFS_Node gInitRD_RootNode = { }; EOF; -$fp = fopen($argv[2], "w"); +$fp = fopen($gOutputFile, "w"); fputs($fp, $gOutput); fclose($fp); + + +if($gDepFile !== false) +{ + $fp = fopen($gDepFile, "w"); + $line = $gOutputFile.":\t".implode(" ", $gDependencies); + fputs($fp, $line); + fclose($fp); +} + ?> diff --git a/Modules/Filesystems/InitRD/Makefile b/Modules/Filesystems/InitRD/Makefile index 00542d72..7506f7e3 100644 --- a/Modules/Filesystems/InitRD/Makefile +++ b/Modules/Filesystems/InitRD/Makefile @@ -8,4 +8,6 @@ NAME = InitRD -include ../Makefile.tpl files.c: GenerateInitRD.php files.lst - php GenerateInitRD.php files.lst files.c + php GenerateInitRD.php files.lst files.c files.c.d + +-include files.c.d diff --git a/Modules/Makefile.tpl b/Modules/Makefile.tpl index 0c66fddc..6fce4152 100644 --- a/Modules/Makefile.tpl +++ b/Modules/Makefile.tpl @@ -40,7 +40,7 @@ DEPFILES := $(DEPFILES:%.o.$(_SUFFIX)=%.d.$(ARCH)) all: $(BIN) clean: - $(RM) $(BIN) $(BIN).dsm $(KOBJ) $(OBJ) $(DEPFILES) + $(RM) $(BIN) $(BIN).dsm $(KOBJ) $(OBJ) $(DEPFILES) $(EXTRA) install: $(BIN) ifneq ($(BUILDTYPE),static) diff --git a/Modules/USB/Core/main.c b/Modules/USB/Core/main.c index 51cd38ea..36e898cc 100644 --- a/Modules/USB/Core/main.c +++ b/Modules/USB/Core/main.c @@ -21,7 +21,7 @@ tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name); int USB_IOCtl(tVFS_Node *Node, int Id, void *Data); // === GLOBALS === -MODULE_DEFINE(0, VERSION, USB, USB_Install, NULL, NULL); +MODULE_DEFINE(0, VERSION, USB_Core, USB_Install, NULL, NULL); tDevFS_Driver gUSB_DrvInfo = { NULL, "usb", { .NumACLs = 1,