Kernel/x86_64 - Implemented SYSCALL in x86_64 port
[tpg/acess2.git] / Kernel / arch / x86_64 / proc.c
index ed2b684..f7d6f92 100644 (file)
@@ -13,6 +13,7 @@
 # include <mp.h>
 #endif
 #include <arch_config.h>
+#include <hal_proc.h>
 
 // === FLAGS ===
 #define DEBUG_TRACE_SWITCH     0
@@ -45,11 +46,10 @@ extern int  giNumActiveThreads;
 extern tThread gThreadZero;
 extern void    Threads_Dump(void);
 extern void    Proc_ReturnToUser(void);
-extern int     GetCPUNum(void);
 extern void    Time_UpdateTimestamp(void);
 
 // === PROTOTYPES ===
-void   ArchThreads_Init(void);
+//void ArchThreads_Init(void);
 #if USE_MP
 void   MP_StartAP(int CPU);
 void   MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode);
@@ -60,14 +60,16 @@ void        Proc_ChangeStack(void);
 // int Proc_Clone(Uint *Err, Uint Flags);
 // int Proc_SpawnWorker(void);
 Uint   Proc_MakeUserStack(void);
-void   Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize);
+//void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize);
 void   Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP);
  int   Proc_Demote(Uint *Err, int Dest, tRegs *Regs);
-void   Proc_CallFaultHandler(tThread *Thread);
-void   Proc_DumpThreadCPUState(tThread *Thread);
+//void Proc_CallFaultHandler(tThread *Thread);
+//void Proc_DumpThreadCPUState(tThread *Thread);
 void   Proc_Scheduler(int CPU);
 
 // === GLOBALS ===
+//!\brief Used by desctab.asm in SyscallStub
+const int ci_offsetof_tThread_KernelStack = offsetof(tThread, KernelStack);
 // --- Multiprocessing ---
 #if USE_MP
 volatile int   giNumInitingCPUs = 0;
@@ -391,7 +393,7 @@ void Proc_Start(void)
        while( giNumInitingCPUs )       __asm__ __volatile__ ("hlt");
        #else
        // Create Idle Task
-       if(Proc_Clone(0, 0) == 0)
+       if(Proc_Clone(0) == 0)
        {
                gaCPUs[0].IdleThread = Proc_GetCurThread();
                gaCPUs[0].IdleThread->ThreadName = (char*)"Idle Thread";
@@ -477,10 +479,10 @@ void Proc_ChangeStack(void)
 }
 
 /**
- * \fn int Proc_Clone(Uint *Err, Uint Flags)
+ * \fn int Proc_Clone(Uint Flags)
  * \brief Clone the current process
  */
-int Proc_Clone(Uint *Err, Uint Flags)
+int Proc_Clone(Uint Flags)
 {
        tThread *newThread;
        tThread *cur = Proc_GetCurThread();
@@ -489,7 +491,7 @@ int Proc_Clone(Uint *Err, Uint Flags)
        __asm__ __volatile__ ("mov %%rsp, %0": "=r"(rsp));
        __asm__ __volatile__ ("mov %%rbp, %0": "=r"(rbp));
        
-       newThread = Threads_CloneTCB(Err, Flags);
+       newThread = Threads_CloneTCB(NULL, Flags);
        if(!newThread)  return -1;
        
        Log("Proc_Clone: newThread = %p", newThread);
@@ -687,20 +689,22 @@ void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP)
        *--stack = CS;          //Code Segment
        *--stack = IP;  //EIP
        //PUSHAD
-       *--stack = 0xAAAAAAAA;  // eax
-       *--stack = 0xCCCCCCCC;  // ecx
-       *--stack = 0xDDDDDDDD;  // edx
-       *--stack = 0xBBBBBBBB;  // ebx
-       *--stack = 0xD1D1D1D1;  // edi
-       *--stack = 0x54545454;  // rsp - NOT POPED
-       *--stack = 0x51515151;  // esi
-       *--stack = 0xB4B4B4B4;  // rbp
+//     *--stack = 0xAAAAAAAA;  // rax
+//     *--stack = 0xCCCCCCCC;  // rcx
+//     *--stack = 0xDDDDDDDD;  // rdx
+//     *--stack = 0xBBBBBBBB;  // rbx
+//     *--stack = 0xD1D1D1D1;  // rdi
+//     *--stack = 0x54545454;  // rsp - NOT POPED
+//     *--stack = 0x51515151;  // rsi
+//     *--stack = 0xB4B4B4B4;  // rbp
        //Individual PUSHs
-       *--stack = SS;  // ds
-       
+//     *--stack = SS;  // ds
+
+       MAGIC_BREAK();  
        __asm__ __volatile__ (
-       "mov %%rax,%%rsp;\n\t"  // Set stack pointer
-       "iret;\n\t" : : "a" (stack));
+               "mov %%rax,%%rsp;\n\t"  // Set stack pointer
+               "iretq;\n\t" : : "a" (stack)
+               );
        for(;;);
 }
 

UCC git Repository :: git.ucc.asn.au