From: John Hodge Date: Fri, 1 Jan 2010 13:47:57 +0000 (+0800) Subject: SMP Work (APs now start, just seem to lock up on lgdt, or whatever is at that address) X-Git-Tag: rel0.06~340 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=8d062ceb17eb6cfb2e3db8af6794d38391c245d3;p=tpg%2Facess2.git SMP Work (APs now start, just seem to lock up on lgdt, or whatever is at that address) - Also added support for setting the build architecture in the environment - Included the Doxygen layout file --- diff --git a/Kernel/DoxygenLayout.xml b/Kernel/DoxygenLayout.xml new file mode 100644 index 00000000..3796b580 --- /dev/null +++ b/Kernel/DoxygenLayout.xml @@ -0,0 +1,186 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 96e78f41..40dbf54a 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 39 +BUILD_NUM = 57 diff --git a/Kernel/arch/x86/desctab.asm b/Kernel/arch/x86/desctab.asm index bc37711b..b5d060dd 100644 --- a/Kernel/arch/x86/desctab.asm +++ b/Kernel/arch/x86/desctab.asm @@ -13,7 +13,6 @@ GDT_SIZE equ (1+2*2+1+MAX_CPUS)*8 [section .data] ; GDT [global gGDT] -[global gGDTptr] gGDT: ; PL0 - Kernel ; PL3 - User @@ -24,22 +23,25 @@ gGDT: dd 0x0000FFFF, 0x00CFF200 ; 20 PL3 Data dd 26*4-1, 0x00408900 ; Double Fault TSS times MAX_CPUS dd 26*4-1, 0x00408900 -gGDTptr: +[global gGDTPtr] +gGDTPtr: dw GDT_SIZE-1 dd gGDT ; IDT ALIGN 8 gIDT: times 256 dd 0x00080000,0x00000F00 +[global gIDTPtr] gIDTPtr: dw 256 * 16 - 1 ; Limit dd gIDT ; Base [section .text] + [global Desctab_Install] Desctab_Install: ; Set GDT - lgdt [gGDTptr] + lgdt [gGDTPtr] mov ax, 0x10 ; PL0 Data mov ss, ax mov ds, ax diff --git a/Kernel/arch/x86/include/mp.h b/Kernel/arch/x86/include/mp.h index 45d24727..30b2780f 100644 --- a/Kernel/arch/x86/include/mp.h +++ b/Kernel/arch/x86/include/mp.h @@ -80,13 +80,26 @@ typedef struct sMPTable { } tMPTable; typedef volatile struct { - Uint8 Addr; - Uint8 Resvd[3]; - Uint32 Resvd2[3]; + Uint32 Addr; + Uint32 Resvd1[3]; union { Uint8 Byte; + Uint16 Word; Uint32 DWord; } Value; + Uint32 Resvd2[3]; } tIOAPIC; +typedef struct { + Uint32 Val; + Uint32 Padding[3]; +} tReg; + +typedef volatile struct { + tReg _unused; + tReg _unused2; + tReg ID; + tReg Version; +} tAPIC; + #endif diff --git a/Kernel/arch/x86/mm_virt.c b/Kernel/arch/x86/mm_virt.c index 5afc86f9..0ef67710 100644 --- a/Kernel/arch/x86/mm_virt.c +++ b/Kernel/arch/x86/mm_virt.c @@ -105,10 +105,10 @@ Uint32 gWorkerStacks[(NUM_WORKER_STACKS+31)/32]; void MM_PreinitVirtual() { #if USE_PAE - gaInitPDPT[ 0 ] = 0; + //gaInitPDPT[ 0 ] = 0; gaInitPageDir[ ((PAGE_TABLE_ADDR >> TAB)-3*512+3)*2 ] = ((tTabEnt)&gaInitPageDir - KERNEL_BASE) | 3; #else - gaInitPageDir[ 0 ] = 0; + //gaInitPageDir[ 0 ] = 0; // Needed for SMP startup code gaInitPageDir[ PAGE_TABLE_ADDR >> 22 ] = ((tTabEnt)&gaInitPageDir - KERNEL_BASE) | 3; #endif INVLPG( PAGE_TABLE_ADDR ); diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 98ba7e0c..9ad06a53 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -53,7 +53,7 @@ void Proc_Scheduler(); // --- Multiprocessing --- #if USE_MP tMPInfo *gMPFloatPtr = NULL; -tIOAPIC *gpMP_LocalAPIC = NULL; +tAPIC *gpMP_LocalAPIC = NULL; Uint8 gaAPIC_to_CPU[256] = {0}; tCPU gaCPUs[MAX_CPUS]; #else @@ -176,6 +176,12 @@ void ArchThreads_Init() Log("\t.CPUSignature = 0x%08x", ents->Proc.CPUSignature); Log("\t.FeatureFlags = 0x%08x", ents->Proc.FeatureFlags); + + if( !(ents->Proc.CPUFlags & 1) ) { + Log("DISABLED"); + break; + } + // Check if there is too many processors if(giNumCPUs >= MAX_CPUS) { giNumCPUs ++; // If `giNumCPUs` > MAX_CPUS later, it will be clipped @@ -189,7 +195,10 @@ void ArchThreads_Init() giNumCPUs ++; // Send IPI - MP_StartAP( giNumCPUs-1 ); + if( !(ents->Proc.CPUFlags & 2) ) + { + MP_StartAP( giNumCPUs-1 ); + } break; case 1: // Bus @@ -320,9 +329,17 @@ void MP_StartAP(int CPU) void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode) { - Uint32 addr = (Uint)gpMP_LocalAPIC + 0x20 + (APICID<<3); - - *(Uint32*)addr = ((DeliveryMode & 7) << 8) | (Vector & 0xFF); + Uint32 addr = (Uint)gpMP_LocalAPIC + 0x300; + Uint32 val; + + // Hi + val = (Uint)APICID << 24; + Log("*%p = 0x%08x", addr+0x10, val); + *(Uint32*)(addr+0x10) = val; + // Low (and send) + val = ((DeliveryMode & 7) << 8) | (Vector & 0xFF); + Log("*%p = 0x%08x", addr, val); + *(Uint32*)addr = val; } #endif @@ -343,8 +360,7 @@ void Proc_Start() tThread *Proc_GetCurThread() { #if USE_MP - gpMP_LocalAPIC->Addr = 0; - return gaCPUs[ gaAPIC_to_CPU[gpMP_LocalAPIC->Value.Byte] ].Current; + return gaCPUs[ gaAPIC_to_CPU[gpMP_LocalAPIC->ID.Val&0xFF] ].Current; #else return gCurrentThread; #endif @@ -679,7 +695,7 @@ void Proc_Scheduler(int CPU) #if USE_MP thread = gaCPUs[CPU].Current; #else - curThread = gCurrentThread; + thread = gCurrentThread; #endif // Reduce remaining quantum and continue timeslice if non-zero diff --git a/Kernel/arch/x86/start.asm b/Kernel/arch/x86/start.asm index 4dd76036..ebf69f42 100644 --- a/Kernel/arch/x86/start.asm +++ b/Kernel/arch/x86/start.asm @@ -39,8 +39,6 @@ start: jmp ecx .higherHalf: - mov DWORD [gaInitPageDir], 0 - ; Call the kernel push ebx ; Multiboot Info push eax ; Multiboot Magic Value @@ -56,22 +54,27 @@ start: ; Multiprocessing AP Startup Code (Must be within 0x10FFF0) ; %if USE_MP -[extern gGDTptr] +[extern gGDT] +[extern gGDTPtr] +[extern gIDTPtr] [extern gpMP_LocalAPIC] [extern gaAPIC_to_CPU] [extern gaCPUs] -[global APStartup] +lGDTPtr: ; Local GDT Pointer + dw 2*8-1 + dd gGDT-KERNEL_BASE [bits 16] +[global APStartup] APStartup: xchg bx, bx ; MAGIC BREAK! mov ax, 0xFFFF mov ds, ax - lgdt [DWORD ds:gGDTptr-0xFFFF0] + lgdt [DWORD ds:lGDTPtr-KERNEL_BASE-0xFFFF0] mov eax, cr0 or al, 1 mov cr0, eax - jmp 08h:DWORD .ProtectedMode + jmp 08h:DWORD .ProtectedMode-KERNEL_BASE [bits 32] .ProtectedMode: ; Start Paging @@ -84,6 +87,10 @@ APStartup: lea eax, [.higherHalf] jmp eax .higherHalf: + ; Load True GDT & IDT + lgdt [gGDTPtr] + lidt [gIDTPtr] + mov eax, [gpMP_LocalAPIC] mov DWORD [eax], 0 xor ecx, ecx @@ -93,6 +100,7 @@ APStartup: ; CL is now the CPU ID mov BYTE [gaCPUs+ecx*8+1], 1 ; CPU is now marked as initialised + sti .hlt: hlt jmp .hlt diff --git a/Makefile.cfg b/Makefile.cfg index 14ce84ba..604f8614 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -16,8 +16,12 @@ xMKDIR = mmd xRMDIR = mdeltree xRM = mdel -ARCH = i486 -ARCHDIR = x86 +ifeq ($(ARCH),) + ARCH = i386 +endif +ifeq ($(ARCHDIR),) + ARCHDIR = x86 +endif FILESYSTEMS = fat DRIVERS = ata_x86