From: John Hodge Date: Sun, 20 Jun 2010 06:04:29 +0000 (+0800) Subject: Fixing behavior of Threads_CloneTCB X-Git-Tag: rel0.06~139 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=8a7da9218db0705e08ddbcb18127dc2a650452eb;p=tpg%2Facess2.git Fixing behavior of Threads_CloneTCB - Also removed the SMP CPU number hack in x86, now uses the TSS trick --- diff --git a/Kernel/arch/x86/desctab.asm b/Kernel/arch/x86/desctab.asm index 27b7bb1a..9d19300d 100644 --- a/Kernel/arch/x86/desctab.asm +++ b/Kernel/arch/x86/desctab.asm @@ -21,8 +21,8 @@ gGDT: dd 0x0000FFFF, 0x00CF9200 ; 10 PL0 Data dd 0x0000FFFF, 0x00CFFA00 ; 18 PL3 Code dd 0x0000FFFF, 0x00CFF200 ; 20 PL3 Data - dd 26*4-1, 0x00408900 ; Double Fault TSS - times MAX_CPUS dd 26*4-1, 0x00408900 + dd 26*4-1, 0x00408900 ; 28 Double Fault TSS + times MAX_CPUS dd 26*4-1, 0x00408900 ; 30+ TSSes [global gGDTPtr] gGDTPtr: dw GDT_SIZE-1 diff --git a/Kernel/arch/x86/proc.asm b/Kernel/arch/x86/proc.asm index d905c249..1cf1f962 100644 --- a/Kernel/arch/x86/proc.asm +++ b/Kernel/arch/x86/proc.asm @@ -114,6 +114,13 @@ Proc_ReturnToUser: iret +[global GetCPUNum] +GetCPUNum: + xor eax, eax + ltr ax + sub ax, 0x30 + shr ax, 3 ; ax /= 8 + ret [section .usertext] User_Syscall_RetAndExit: diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index b6dbfdd5..2f59472a 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -24,6 +24,7 @@ extern tGDT gGDT[]; extern tIDT gIDT[]; extern void APStartup(void); // 16-bit AP startup code extern Uint GetEIP(void); // start.asm +extern int GetCPUNum(void); // start.asm extern Uint32 gaInitPageDir[1024]; // start.asm extern void Kernel_Stack_Top; extern tSpinlock glThreadListLock; @@ -389,7 +390,8 @@ void Proc_Start(void) tThread *Proc_GetCurThread(void) { #if USE_MP - return gaCPUs[ gaAPIC_to_CPU[gpMP_LocalAPIC->ID.Val&0xFF] ].Current; + //return gaCPUs[ gaAPIC_to_CPU[gpMP_LocalAPIC->ID.Val&0xFF] ].Current; + return gaCPUs[ GetCPUNum() ].Current; #else return gCurrentThread; #endif diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index 934bee90..6c75aaaf 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -39,7 +39,7 @@ extern tThread *Threads_GetNextToRun(int CPU); extern void Threads_Dump(void); extern tThread *Threads_CloneTCB(Uint *Err, Uint Flags); extern void Proc_ReturnToUser(void); -extern void GetCPUNum(void); +extern int GetCPUNum(void); // === PROTOTYPES === void ArchThreads_Init(void); diff --git a/Kernel/threads.c b/Kernel/threads.c index a947169d..ba0f430d 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -173,6 +173,7 @@ tThread *Threads_CloneTCB(Uint *Err, Uint Flags) *Err = -ENOMEM; return NULL; } + memcpy(new, cur, sizeof(tThread)); new->Next = NULL; new->IsLocked = 0; @@ -184,8 +185,7 @@ tThread *Threads_CloneTCB(Uint *Err, Uint Flags) new->PTID = cur->TID; // Clone Name - new->ThreadName = malloc(strlen(cur->ThreadName)+1); - strcpy(new->ThreadName, cur->ThreadName); + new->ThreadName = strdup(cur->ThreadName); // Set Thread Group ID (PID) if(Flags & CLONE_VM)