From: John Hodge Date: Sun, 1 Aug 2010 01:39:09 +0000 (+0800) Subject: Bugfixing the x86_64 port X-Git-Tag: rel0.06~72 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a1b7b0fcbf99e2c53dd6d7ee5961772bf29bdb2b;p=tpg%2Facess2.git Bugfixing the x86_64 port --- diff --git a/Kernel/arch/x86_64/Makefile b/Kernel/arch/x86_64/Makefile index f539e250..647a49af 100644 --- a/Kernel/arch/x86_64/Makefile +++ b/Kernel/arch/x86_64/Makefile @@ -5,9 +5,9 @@ MAX_CPUS := 4 -CPPFLAGS := -DMAX_CPUS=$(MAX_CPUS) +CPPFLAGS := -DMAX_CPUS=$(MAX_CPUS) -D USE_MP=0 CFLAGS := $(KERNEL_CFLAGS) -mno-sse -mno-mmx -ASFLAGS := -f elf64 -D MAX_CPUS=$(MAX_CPUS) +ASFLAGS := -f elf64 -D MAX_CPUS=$(MAX_CPUS) -D USE_MP=0 LDFLAGS := -nostdlib -nodefaultlibs ifeq ($(ARCH),amd64) diff --git a/Kernel/arch/x86_64/desctab.asm b/Kernel/arch/x86_64/desctab.asm index cf1b0f61..816d14e5 100644 --- a/Kernel/arch/x86_64/desctab.asm +++ b/Kernel/arch/x86_64/desctab.asm @@ -80,7 +80,7 @@ Desctab_Init: %endrep ; Install IRQs - SETIDT 0xF0, Irq0 + SETIDT 0xF0, SchedulerIRQ SETIDT 0xF1, Irq1 SETIDT 0xF2, Irq2 SETIDT 0xF3, Irq3 @@ -321,20 +321,43 @@ IrqCommon: [extern Proc_Scheduler] [global SchedulerIRQ] SchedulerIRQ: - ; TODO: Find Current CPU PUSH_GPR ;PUSH_FPU ;PUSH_XMM - xor rsi, rsi - mov rdi, MM_LOCALAPIC+0x20 - mov esi, [rdi] + ; Save Thread Pointer + mov rax, dr0 + push rax + + ; Get the CPU Number + mov rdi, dr1 + ; Call the Scheduler call Proc_Scheduler + ; Restore Thread Pointer + pop rax + mov dr0, rax + + ; Send EOI (To either the APIC or the PIC) + %if USE_MP + test ebx, ebx + jnz .sendEOI + %endif + ; PIC + mov al, 0x20 + out 0x20, al ; ACK IRQ + %if USE_MP + jmp .ret + ; APIC +.sendEOI: + mov eax, DWORD [gpMP_LocalAPIC] + mov DWORD [eax+0x0B0], 0 + %endif +.ret: + ;POP_XMM ;POP_FPU POP_GPR - add rsp, 8*2 iretq [section .data] diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index 8e7d24c2..81b8eeb8 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -289,9 +289,14 @@ void ArchThreads_Init(void) } #endif + // Set Debug registers + __asm__ __volatile__ ("mov %0, %%db0" : : "r"(&gThreadZero)); + __asm__ __volatile__ ("mov %%rax, %%db1" : : "a"(0)); + gaCPUs[0].Current = &gThreadZero; gThreadZero.MemState.CR3 = (Uint)gInitialPML4 - KERNEL_BASE; + gThreadZero.CurCPU = 0; // Set timer frequency outb(0x43, 0x34); // Set Channel 0, Low/High, Rate Generator @@ -303,6 +308,8 @@ void ArchThreads_Init(void) // Change Stacks Proc_ChangeStack(); + + Log("Multithreading initialised"); } #if USE_MP @@ -387,11 +394,13 @@ void Proc_Start(void) // Set current task gaCPUs[0].Current = &gThreadZero; + gaCPUs[0].Current->CurCPU = 0; // Start Interrupts (and hence scheduler) __asm__ __volatile__("sti"); #endif MM_FinishVirtualInit(); + Log("Multithreading started"); } /** @@ -726,7 +735,7 @@ void Proc_Scheduler(int CPU) // If the spinlock is set, let it complete if(IS_LOCKED(&glThreadListLock)) return; - + // Get current thread thread = gaCPUs[CPU].Current; diff --git a/Kernel/arch/x86_64/start64.asm b/Kernel/arch/x86_64/start64.asm index 7617d6ae..d0cc503f 100644 --- a/Kernel/arch/x86_64/start64.asm +++ b/Kernel/arch/x86_64/start64.asm @@ -25,6 +25,9 @@ start64: jmp rax .himem: + xor rax, rax + mov dr0, rax ; Set CPU0 + ; Clear the screen mov rax, 0x1F201F201F201F20 ; Set the screen to White on blue, space (4 characters) mov edi, 0xB8000 diff --git a/Kernel/include/threads.h b/Kernel/include/threads.h index b7d9bad5..4a62166f 100644 --- a/Kernel/include/threads.h +++ b/Kernel/include/threads.h @@ -18,13 +18,11 @@ typedef struct sMessage typedef struct sThread { // --- threads.c's - // 0 struct sThread *Next; //!< Next thread in list tSpinlock IsLocked; //!< Thread's spinlock volatile int Status; //!< Thread Status int RetStatus; //!< Return Status - // 16 Uint TID; //!< Thread ID Uint TGID; //!< Thread Group (Process) Uint PTID; //!< Parent Thread ID @@ -32,20 +30,16 @@ typedef struct sThread char *ThreadName; //!< Name of thread // --- arch/proc.c's responsibility - // 40 //! Kernel Stack Base tVAddr KernelStack; - // 44 (x86) //! Memory Manager State tMemoryState MemState; - // 48 (x86) //! State on task switch tTaskState SavedState; // --- threads.c's - // 60 int CurFaultNum; //!< Current fault number, 0: none tVAddr FaultHandler; //!< Fault Handler @@ -57,7 +51,6 @@ typedef struct sThread Uint Config[NUM_CFG_ENTRIES]; //!< Per-process configuration - // --- proc.c's volatile int CurCPU; } tThread; diff --git a/Kernel/lib.c b/Kernel/lib.c index 9923d7c8..586a2e8f 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -270,14 +270,14 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) { case 'd': case 'i': - #if BITS == 32 - if( (isLongLong && val >> 63) || (!isLongLong && val >> 31) ) { - #else - if( (Sint)val < 0 ) { - #endif + if( isLongLong && val >> 63 ) { PUTCH('-'); val = -val; } + else if( !isLongLong && val >> 31 ) { + PUTCH('-'); + val = -(Sint32)val; + } itoa(p, val, 10, minSize, pad); goto printString; case 'u': diff --git a/Kernel/vfs/fs/root.c b/Kernel/vfs/fs/root.c index c52313de..c613cfd5 100644 --- a/Kernel/vfs/fs/root.c +++ b/Kernel/vfs/fs/root.c @@ -20,11 +20,8 @@ tRamFS_File *Root_int_AllocFile(void); // === GLOBALS === tVFS_Driver gRootFS_Info = { - "rootfs", 0, - Root_InitDevice, - NULL, // Unmount - NULL -}; + "rootfs", 0, Root_InitDevice, NULL, NULL + }; tRamFS_File RootFS_Files[MAX_FILES]; tVFS_ACL RootFS_DirACLs[3] = { {{0,0}, {0,VFS_PERM_ALL}}, // Owner (Root) diff --git a/Kernel/vfs/main.c b/Kernel/vfs/main.c index eee0e10f..b447f04d 100644 --- a/Kernel/vfs/main.c +++ b/Kernel/vfs/main.c @@ -104,6 +104,7 @@ tVFS_Driver *VFS_GetFSByName(char *Name) for(;drv;drv=drv->Next) { + Log("strcmp('%s' (%p), '%s') == 0?", drv->Name, drv->Name, Name); if(strcmp(drv->Name, Name) == 0) return drv; }