# include <mp.h>
#endif
+// === FLAGS ===
+#define DEBUG_TRACE_SWITCH 0
+
// === CONSTANTS ===
#define SWITCH_MAGIC 0xFFFACE55 // There is no code in this area
-#define DEFAULT_QUANTUM 10
-#define DEFAULT_TICKETS 5
-#define MAX_TICKETS 10
#define TIMER_DIVISOR 11931 //~100Hz
// === IMPORTS ===
extern Uint GetEIP(); // start.asm
extern Uint32 gaInitPageDir[1024]; // start.asm
extern void Kernel_Stack_Top;
+extern volatile int giThreadListLock;
+extern int giNumCPUs;
+extern int giNextTID;
+extern int giTotalTickets;
+extern int giNumActiveThreads;
+extern tThread gThreadZero;
+extern tThread *gActiveThreads;
+extern tThread *gSleepingThreads;
+extern tThread *gDeleteThreads;
+extern tThread *Threads_GetNextToRun(int CPU);
+extern void Threads_Dump();
+extern tThread *Threads_CloneTCB(Uint *Err, Uint Flags);
+extern void Isr7();
// === PROTOTYPES ===
-void Proc_Start();
+void ArchThreads_Init();
+tThread *Proc_GetCurThread();
void Proc_ChangeStack();
int Proc_Clone(Uint *Err, Uint Flags);
-void Proc_Exit();
-void Proc_Yield();
-void Proc_Sleep();
-static tThread *Proc_int_GetPrevThread(tThread **List, tThread *Thread);
void Proc_Scheduler();
-Sint64 now();
-Uint rand();
// === GLOBALS ===
-// -- Core Thread --
-tThread gThreadZero = {
- NULL, 0, // Next, Lock
- THREAD_STAT_ACTIVE, // Status
- 0, 0, // TID, TGID
- 0, 0, // UID, GID
- "ThreadZero", // Name
- 0, 0, 0, // ESP, EBP, EIP (Set on switch)
- #if USE_PAE
- {0,0,0}, // PML4 Entries
- #else
- (Uint)&gaInitPageDir-KERNEL_BASE, // CR3
- #endif
- (Uint)&Kernel_Stack_Top, // Kernel Stack (Unused as it is PL0)
- NULL, NULL, // Messages, Last Message
- DEFAULT_QUANTUM, DEFAULT_QUANTUM, // Quantum, Remaining
- DEFAULT_TICKETS,
- {0} // Default config to zero
- };
-// -- Processes --
-// --- Locks ---
-volatile int giThreadListLock = 0; ///\note NEVER use a heap function while locked
// --- Current State ---
#if USE_MP
-tThread **gCurrentThread = NULL;
-# define CUR_THREAD gCurrentThread[0]
+tThread *gCurrentThread[MAX_CPUS] = {NULL};
#else
tThread *gCurrentThread = NULL;
-# define CUR_THREAD gCurrentThread
#endif
-volatile int giNumActiveThreads = 0;
-volatile int giTotalTickets = 0;
-volatile Uint giNextTID = 1;
-// --- Thread Lists ---
-tThread *gActiveThreads = NULL; // Currently Running Threads
-tThread *gSleepingThreads = NULL; // Sleeping Threads
-tThread *gDeleteThreads = NULL; // Threads to delete
// --- Multiprocessing ---
- int giNumCPUs = 1;
#if USE_MP
tMPInfo *gMPTable = NULL;
#endif
#if !USE_MP
tTSS gTSS0 = {0};
#endif
+// --- Error Recovery ---
+char gaDoubleFaultStack[1024];
+tTSS gDoubleFault_TSS = {
+ .ESP0 = (Uint)&gaDoubleFaultStack[1023],
+ .SS0 = 0x10,
+ .EIP = (Uint)Isr7
+};
// === CODE ===
/**
- * \fn void Proc_Start()
+ * \fn void ArchThreads_Init()
* \brief Starts the process scheduler
*/
-void Proc_Start()
+void ArchThreads_Init()
{
Uint pos = 0;
-
#if USE_MP
// -- Initialise Multiprocessing
// Find MP Floating Table
#if USE_MP
}
+ // 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;
+
// Initialise TSS
for(pos=0;pos<giNumCPUs;pos++)
{
#endif
gTSSs[pos].SS0 = 0x10;
gTSSs[pos].ESP0 = 0; // Set properly by scheduler
- gGDT[5+pos].LimitLow = sizeof(tTSS);
- gGDT[5+pos].LimitHi = 0;
- gGDT[5+pos].Access = 0x89; // Type
- gGDT[5+pos].Flags = 0x4;
- gGDT[5+pos].BaseLow = (Uint)&gTSSs[pos] & 0xFFFF;
- gGDT[5+pos].BaseMid = (Uint)&gTSSs[pos] >> 16;
- gGDT[5+pos].BaseHi = (Uint)&gTSSs[pos] >> 24;
+ gGDT[6+pos].LimitLow = sizeof(tTSS);
+ gGDT[6+pos].LimitHi = 0;
+ gGDT[6+pos].Access = 0x89; // Type
+ gGDT[6+pos].Flags = 0x4;
+ gGDT[6+pos].BaseLow = (Uint)&gTSSs[pos] & 0xFFFF;
+ gGDT[6+pos].BaseMid = (Uint)&gTSSs[pos] >> 16;
+ gGDT[6+pos].BaseHi = (Uint)&gTSSs[pos] >> 24;
#if USE_MP
}
for(pos=0;pos<giNumCPUs;pos++) {
#endif
- __asm__ __volatile__ ("ltr %%ax"::"a"(0x28+pos*8));
+ __asm__ __volatile__ ("ltr %%ax"::"a"(0x30+pos*8));
#if USE_MP
}
#endif
+ #if USE_MP
+ gCurrentThread[0] = &gThreadZero;
+ #else
+ gCurrentThread = &gThreadZero;
+ #endif
+
+ #if USE_PAE
+ gThreadZero.MemState.PDP[0] = 0;
+ gThreadZero.MemState.PDP[1] = 0;
+ gThreadZero.MemState.PDP[2] = 0;
+ #else
+ gThreadZero.MemState.CR3 = (Uint)gaInitPageDir - KERNEL_BASE;
+ #endif
+
// Set timer frequency
outb(0x43, 0x34); // Set Channel 0, Low/High, Rate Generator
outb(0x40, TIMER_DIVISOR&0xFF); // Low Byte of Divisor
outb(0x40, (TIMER_DIVISOR>>8)&0xFF); // High Byte
- // Create Initial Task
- gActiveThreads = &gThreadZero;
- gCurrentThread = &gThreadZero;
- giTotalTickets = gThreadZero.NumTickets;
- giNumActiveThreads = 1;
-
// Create Per-Process Data Block
MM_Allocate(MM_PPD_CFG);
// Change Stacks
Proc_ChangeStack();
-
- #if 1
- // Create Idle Task
- if(Proc_Clone(0, 0) == 0)
- {
- gCurrentThread->ThreadName = "Idle Thread";
- Proc_SetTickets(0); // Never called randomly
- gCurrentThread->Quantum = 1; // 1 slice quantum
- for(;;) __asm__ __volatile__ ("hlt"); // Just yeilds
- }
- #endif
-
+}
+
+/**
+ * \fn void Proc_Start()
+ * \brief Start process scheduler
+ */
+void Proc_Start()
+{
// Start Interrupts (and hence scheduler)
__asm__ __volatile__("sti");
}
+/**
+ * \fn tThread *Proc_GetCurThread()
+ * \brief Gets the current thread
+ */
+tThread *Proc_GetCurThread()
+{
+ #if USE_MP
+ return NULL;
+ #else
+ return gCurrentThread;
+ #endif
+}
+
/**
* \fn void Proc_ChangeStack()
* \brief Swaps the current stack for a new one (in the proper stack reigon)
return;
}
- curBase = gCurrentThread->KernelStack;
+ curBase = (Uint)&Kernel_Stack_Top;
LOG("curBase = 0x%x, newBase = 0x%x", curBase, newBase);
int Proc_Clone(Uint *Err, Uint Flags)
{
tThread *newThread;
+ tThread *cur = Proc_GetCurThread();
Uint eip, esp, ebp;
__asm__ __volatile__ ("mov %%esp, %0": "=r"(esp));
__asm__ __volatile__ ("mov %%ebp, %0": "=r"(ebp));
- // Create new thread structure
- newThread = malloc( sizeof(tThread) );
- if(!newThread) {
- Warning("Proc_Clone - Out of memory when creating thread\n");
- *Err = -ENOMEM;
- return -1;
- }
- // Base new thread on old
- memcpy(newThread, gCurrentThread, sizeof(tThread));
+ newThread = Threads_CloneTCB(Err, Flags);
+ if(!newThread) return -1;
+
// Initialise Memory Space (New Addr space or kernel stack)
if(Flags & CLONE_VM) {
- newThread->TGID = newThread->TID;
- newThread->CR3 = MM_Clone();
+ newThread->MemState.CR3 = MM_Clone();
+ newThread->KernelStack = cur->KernelStack;
} else {
Uint tmpEbp, oldEsp = esp;
+ // Set CR3
+ newThread->MemState.CR3 = cur->MemState.CR3;
+
// Create new KStack
newThread->KernelStack = MM_NewKStack();
// Check for errors
}
// Get ESP as a used size
- esp = gCurrentThread->KernelStack - esp;
+ esp = cur->KernelStack - esp;
// Copy used stack
- memcpy( (void*)(newThread->KernelStack - esp), (void*)(gCurrentThread->KernelStack - esp), esp );
+ memcpy( (void*)(newThread->KernelStack - esp), (void*)(cur->KernelStack - esp), esp );
// Get ESP as an offset in the new stack
esp = newThread->KernelStack - esp;
// Adjust EBP
- ebp = newThread->KernelStack - (gCurrentThread->KernelStack - ebp);
+ ebp = newThread->KernelStack - (cur->KernelStack - ebp);
// Repair EBPs & Stack Addresses
// Catches arguments also, but may trash stack-address-like values
for(tmpEbp = esp; tmpEbp < newThread->KernelStack; tmpEbp += 4)
{
- if(oldEsp < *(Uint*)tmpEbp && *(Uint*)tmpEbp < gCurrentThread->KernelStack)
- *(Uint*)tmpEbp += newThread->KernelStack - gCurrentThread->KernelStack;
+ if(oldEsp < *(Uint*)tmpEbp && *(Uint*)tmpEbp < cur->KernelStack)
+ *(Uint*)tmpEbp += newThread->KernelStack - cur->KernelStack;
}
}
-
- // Set Pointer, Spinlock and TID
- newThread->Next = NULL;
- newThread->IsLocked = 0;
- newThread->TID = giNextTID++;
-
- // Clear message list (messages are not inherited)
- newThread->Messages = NULL;
- newThread->LastMessage = NULL;
-
- // Set remaining (sheduler expects remaining to be correct)
- newThread->Remaining = newThread->Quantum;
// Save core machine state
- newThread->ESP = esp;
- newThread->EBP = ebp;
+ newThread->SavedState.ESP = esp;
+ newThread->SavedState.EBP = ebp;
eip = GetEIP();
if(eip == SWITCH_MAGIC) {
outb(0x20, 0x20); // ACK Timer and return as child
}
// Set EIP as parent
- newThread->EIP = eip;
-
- //Log(" Proc_Clone: giTimestamp = %i.%07i", (Uint)giTimestamp, (Uint)giPartMiliseconds/214);
+ newThread->SavedState.EIP = eip;
// Lock list and add to active
- LOCK( &giThreadListLock );
- newThread->Next = gActiveThreads;
- gActiveThreads = newThread;
- giNumActiveThreads ++;
- giTotalTickets += newThread->NumTickets;
- RELEASE( &giThreadListLock );
+ Threads_AddActive(newThread);
return newThread->TID;
}
/**
- * \fn void Proc_SetThreadName()
- * \brief Sets the thread's name
+ * \fn int Proc_SpawnWorker()
+ * \brief Spawns a new worker thread
*/
-void Proc_SetThreadName(char *NewName)
+int Proc_SpawnWorker()
{
- if( (Uint)CUR_THREAD->ThreadName > 0xC0400000 )
- free( CUR_THREAD->ThreadName );
- CUR_THREAD->ThreadName = malloc(strlen(NewName)+1);
- strcpy(CUR_THREAD->ThreadName, NewName);
+ tThread *new, *cur;
+ Uint eip, esp, ebp;
+
+ cur = Proc_GetCurThread();
+
+ // Create new thread
+ new = malloc( sizeof(tThread) );
+ if(!new) {
+ Warning("Proc_SpawnWorker - Out of heap space!\n");
+ return -1;
+ }
+ memcpy(new, &gThreadZero, sizeof(tThread));
+ // Set Thread ID
+ new->TID = giNextTID++;
+ // Set kernel stack
+ new->KernelStack = MM_NewWorkerStack();
+
+ // Get ESP and EBP based in the new stack
+ __asm__ __volatile__ ("mov %%esp, %0": "=r"(esp));
+ __asm__ __volatile__ ("mov %%ebp, %0": "=r"(ebp));
+ esp = cur->KernelStack - (new->KernelStack - esp);
+ ebp = new->KernelStack - (cur->KernelStack - ebp);
+
+ // Save core machine state
+ new->SavedState.ESP = esp;
+ new->SavedState.EBP = ebp;
+ eip = GetEIP();
+ if(eip == SWITCH_MAGIC) {
+ outb(0x20, 0x20); // ACK Timer and return as child
+ return 0;
+ }
+
+ // Set EIP as parent
+ new->SavedState.EIP = eip;
+
+ return new->TID;
}
/**
/**
- * \fn void Proc_StartUser(Uint Entrypoint, Uint Base, int ArgC, char **ArgV, char **EnvP, int DataSize)
+ * \fn void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize)
* \brief Starts a user task
*/
void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize)
for(;;);
}
-/**
- * \fn void Proc_Exit()
- * \brief Kill the current process
- */
-void Proc_Exit()
-{
- tThread *thread;
- tMsg *msg;
-
- ///\note Double lock is needed due to overlap of locks
-
- // Lock thread (stop us recieving messages)
- LOCK( &gCurrentThread->IsLocked );
-
- // Lock thread list
- LOCK( &giThreadListLock );
-
- // Get previous thread on list
- thread = Proc_int_GetPrevThread( &gActiveThreads, gCurrentThread );
- if(!thread) {
- Warning("Proc_Exit - Current thread is not on the active queue");
- return;
- }
-
- // Clear Message Queue
- while( gCurrentThread->Messages )
- {
- msg = gCurrentThread->Messages->Next;
- free( gCurrentThread->Messages );
- gCurrentThread->Messages = msg;
- }
-
- gCurrentThread->Remaining = 0; // Clear Remaining Quantum
- gCurrentThread->Quantum = 0; // Clear Quantum to indicate dead thread
- thread->Next = gCurrentThread->Next; // Remove from active
-
- // Add to delete queue
- if(gDeleteThreads) {
- gCurrentThread->Next = gDeleteThreads;
- gDeleteThreads = gCurrentThread;
- } else {
- gCurrentThread->Next = NULL;
- gDeleteThreads = gCurrentThread;
- }
-
- giNumActiveThreads --;
- giTotalTickets -= gCurrentThread->NumTickets;
-
- // Mark thread as sleeping
- gCurrentThread->Status = THREAD_STAT_DEAD;
-
- // Release spinlocks
- RELEASE( &gCurrentThread->IsLocked ); // Released first so that it IS released
- RELEASE( &giThreadListLock );
- __asm__ __volatile__ ("hlt");
-}
-
-/**
- * \fn void Proc_Yield()
- * \brief Yield remainder of timeslice
- */
-void Proc_Yield()
-{
- gCurrentThread->Quantum = 0;
- __asm__ __volatile__ ("hlt");
-}
-
-/**
- * \fn void Proc_Sleep()
- * \brief Take the current process off the run queue
- */
-void Proc_Sleep()
-{
- tThread *thread;
-
- //Log("Proc_Sleep: %i going to sleep", gCurrentThread->TID);
-
- // Acquire Spinlock
- LOCK( &giThreadListLock );
-
- // Get thread before current thread
- thread = Proc_int_GetPrevThread( &gActiveThreads, gCurrentThread );
- if(!thread) {
- Warning("Proc_Sleep - Current thread is not on the active queue");
- return;
- }
-
- // Don't sleep if there is a message waiting
- if( gCurrentThread->Messages ) {
- RELEASE( &giThreadListLock );
- return;
- }
-
- // Unset remaining timeslices (force a task switch on timer fire)
- gCurrentThread->Remaining = 0;
-
- // Remove from active list
- thread->Next = gCurrentThread->Next;
-
- // Add to Sleeping List (at the top)
- gCurrentThread->Next = gSleepingThreads;
- gSleepingThreads = gCurrentThread;
-
- // Reduce the active count & ticket count
- giNumActiveThreads --;
- giTotalTickets -= gCurrentThread->NumTickets;
-
- // Mark thread as sleeping
- gCurrentThread->Status = THREAD_STAT_SLEEPING;
-
- // Release Spinlock
- RELEASE( &giThreadListLock );
-
- __asm__ __volatile__ ("hlt");
-}
-
-/**
- * \fn void Thread_Wake( tThread *Thread )
- * \brief Wakes a sleeping/waiting thread up
- */
-void Thread_Wake(tThread *Thread)
-{
- tThread *prev;
- switch(Thread->Status)
- {
- case THREAD_STAT_ACTIVE: break;
- case THREAD_STAT_SLEEPING:
- LOCK( &giThreadListLock );
- prev = Proc_int_GetPrevThread(&gSleepingThreads, Thread);
- prev->Next = Thread->Next; // Remove from sleeping queue
- Thread->Next = gActiveThreads; // Add to active queue
- gActiveThreads = Thread;
- Thread->Status = THREAD_STAT_ACTIVE;
- RELEASE( &giThreadListLock );
- break;
- case THREAD_STAT_WAITING:
- Warning("Thread_Wake - Waiting threads are not currently supported");
- break;
- case THREAD_STAT_DEAD:
- Warning("Thread_Wake - Attempt to wake dead thread (%i)", Thread->TID);
- break;
- default:
- Warning("Thread_Wake - Unknown process status (%i)\n", Thread->Status);
- break;
- }
-}
-
/**
* \fn int Proc_Demote(Uint *Err, int Dest, tRegs *Regs)
* \brief Demotes a process to a lower permission level
* \param Err Pointer to user's errno
+ * \param Dest New Permission Level
+ * \param Regs Pointer to user's register structure
*/
int Proc_Demote(Uint *Err, int Dest, tRegs *Regs)
{
return 0;
}
-/**
- * \fn void Proc_SetTickets(int Num)
- * \brief Sets the 'priority' of a task
- */
-void Proc_SetTickets(int Num)
-{
- if(Num < 0) return;
- if(Num > MAX_TICKETS) Num = MAX_TICKETS;
-
- LOCK( &giThreadListLock );
- giTotalTickets -= gCurrentThread->NumTickets;
- gCurrentThread->NumTickets = Num;
- giTotalTickets += Num;
- //LOG("giTotalTickets = %i", giTotalTickets);
- RELEASE( &giThreadListLock );
-}
-
-/**
- * \fn tThread *Proc_GetThread(Uint TID)
- * \brief Gets a thread given its TID
- */
-tThread *Proc_GetThread(Uint TID)
-{
- tThread *thread;
-
- // Search Active List
- for(thread = gActiveThreads;
- thread;
- thread = thread->Next)
- {
- if(thread->TID == TID)
- return thread;
- }
-
- // Search Sleeping List
- for(thread = gSleepingThreads;
- thread;
- thread = thread->Next)
- {
- if(thread->TID == TID)
- return thread;
- }
-
- return NULL;
-}
-
-/**
- * \fn static tThread *Proc_int_GetPrevThread(tThread *List, tThread *Thread)
- * \brief Gets the previous entry in a thead linked list
- */
-static tThread *Proc_int_GetPrevThread(tThread **List, tThread *Thread)
-{
- tThread *ret;
- // First Entry
- if(*List == Thread) {
- return (tThread*)List;
- } else {
- for(ret = *List;
- ret->Next && ret->Next != Thread;
- ret = ret->Next
- );
- // Error if the thread is not on the list
- if(!ret->Next || ret->Next != Thread) {
- return NULL;
- }
- }
- return ret;
-}
-
-/**
- * \fn void Proc_DumpThreads()
- * \brief Dums a list of currently running threads
- */
-void Proc_DumpThreads()
-{
- tThread *thread;
-
- Log("Active Threads:");
- for(thread=gActiveThreads;thread;thread=thread->Next)
- {
- Log(" %i (%i) - %s", thread->TID, thread->TGID, thread->ThreadName);
- Log(" %i Tickets, Quantum %i", thread->NumTickets, thread->Quantum);
- Log(" CR3 0x%x, KStack 0x%x", thread->CR3, thread->KernelStack);
- }
- Log("Sleeping Threads:");
- for(thread=gSleepingThreads;thread;thread=thread->Next)
- {
- Log(" %i (%i) - %s", thread->TID, thread->TGID, thread->ThreadName);
- Log(" %i Tickets, Quantum %i", thread->NumTickets, thread->Quantum);
- Log(" CR3 0x%x, KStack 0x%x", thread->CR3, thread->KernelStack);
- }
-}
-
/**
* \fn void Proc_Scheduler(int CPU)
* \brief Swap current thread and clears dead threads
void Proc_Scheduler(int CPU)
{
Uint esp, ebp, eip;
- Uint number, ticket;
tThread *thread;
// If the spinlock is set, let it complete
// Check if there is any tasks running
if(giNumActiveThreads == 0) {
- Log("No Active threads, sleeping\n");
+ Log("No Active threads, sleeping");
__asm__ __volatile__ ("hlt");
return;
}
- // Reduce remaining quantum
+ // Reduce remaining quantum and continue timeslice if non-zero
if(gCurrentThread->Remaining--) return;
// Reset quantum for next call
gCurrentThread->Remaining = gCurrentThread->Quantum;
if(eip == SWITCH_MAGIC) return; // Check if a switch happened
// Save machine state
- gCurrentThread->ESP = esp;
- gCurrentThread->EBP = ebp;
- gCurrentThread->EIP = eip;
-
- // Special case: 1 thread
- if(giNumActiveThreads == 1)
- {
- // Check if a switch is needed (NumActive can be 1 after a sleep)
- if(gActiveThreads == gCurrentThread) return;
- // Switch processes
- gCurrentThread = gActiveThreads;
- goto performSwitch;
- }
+ gCurrentThread->SavedState.ESP = esp;
+ gCurrentThread->SavedState.EBP = ebp;
+ gCurrentThread->SavedState.EIP = eip;
- // Get the ticket number
- ticket = number = rand() % giTotalTickets;
-
- // Find the next thread
- for(thread=gActiveThreads;thread;thread=thread->Next)
- {
- if(thread->NumTickets > number) break;
- number -= thread->NumTickets;
- }
+ // Get next thread
+ thread = Threads_GetNextToRun(CPU);
// Error Check
- if(thread == NULL)
- {
- number = 0;
- for(thread=gActiveThreads;thread;thread=thread->Next)
- number += thread->NumTickets;
- Panic("Bookeeping Failed - giTotalTicketCount (%i) != true count (%i)",
- giTotalTickets, number);
+ if(thread == NULL) {
+ Warning("Hmm... Threads_GetNextToRun returned NULL, I don't think this should happen.\n");
+ return;
}
+ #if DEBUG_TRACE_SWITCH
+ Log("Switching to task %i, CR3 = 0x%x, EIP = %p",
+ thread->TID,
+ thread->MemState.CR3,
+ thread->SavedState.EIP
+ );
+ #endif
+
// Set current thread
gCurrentThread = thread;
// Update Kernel Stack pointer
gTSSs[CPU].ESP0 = thread->KernelStack;
-performSwitch:
// Set address space
- //MM_SetCR3( gCurrentThread->CR3 );
- __asm__ __volatile__ ("mov %0, %%cr3"::"a"(gCurrentThread->CR3));
+ __asm__ __volatile__ ("mov %0, %%cr3"::"a"(gCurrentThread->MemState.CR3));
// Switch threads
__asm__ __volatile__ (
"mov %1, %%esp\n\t"
"mov %2, %%ebp\n\t"
"jmp *%3" : :
- "a"(SWITCH_MAGIC), "b"(gCurrentThread->ESP),
- "d"(gCurrentThread->EBP), "c"(gCurrentThread->EIP));
+ "a"(SWITCH_MAGIC), "b"(gCurrentThread->SavedState.ESP),
+ "d"(gCurrentThread->SavedState.EBP), "c"(gCurrentThread->SavedState.EIP));
for(;;); // Shouldn't reach here
}
-
-// --- Process Structure Access Functions ---
-int Proc_GetPID()
-{
- return gCurrentThread->TGID;
-}
-int Proc_GetTID()
-{
- return gCurrentThread->TID;
-}
-int Proc_GetUID()
-{
- return gCurrentThread->UID;
-}
-int Proc_GetGID()
-{
- return gCurrentThread->GID;
-}