// === PROTOTYPES ===
void MM_InitPhys_Multiboot(tMBoot_Info *MBoot);
-tPAddr MM_AllocPhysRange(int Num, int Bits);
-tPAddr MM_AllocPhys(void);
-void MM_RefPhys(tPAddr PAddr);
-void MM_DerefPhys(tPAddr PAddr);
+//tPAddr MM_AllocPhysRange(int Num, int Bits);
+//tPAddr MM_AllocPhys(void);
+//void MM_RefPhys(tPAddr PAddr);
+//void MM_DerefPhys(tPAddr PAddr);
int MM_int_GetRangeID( tPAddr Addr );
// === GLOBALS ===
// === PROTOTYPES ===
void MM_InitVirt(void);
-void MM_FinishVirtualInit(void);
+//void MM_FinishVirtualInit(void);
void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs);
void MM_DumpTables(tVAddr Start, tVAddr End);
- int MM_Map(tVAddr VAddr, tPAddr PAddr);
+// int MM_Map(tVAddr VAddr, tPAddr PAddr);
+void MM_Unmap(tVAddr VAddr);
+void MM_ClearUser(void);
int MM_GetPageEntry(tVAddr Addr, tPAddr *Phys, Uint *Flags);
// === GLOBALS ===
//Log("MM_NewKStack: Found one at %p", base + KERNEL_STACK_SIZE);
for( i = 0; i < KERNEL_STACK_SIZE; i += 0x1000)
- MM_Allocate(base+i);
+ {
+ if( !MM_Allocate(base+i) )
+ {
+ Log_Warning("MM", "MM_NewKStack - Allocation failed");
+ for( i -= 0x1000; i; i -= 0x1000)
+ MM_Deallocate(base+i);
+ return 0;
+ }
+ }
return base + KERNEL_STACK_SIZE;
}
extern int giTotalTickets;
extern int giNumActiveThreads;
extern tThread gThreadZero;
-//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 int GetCPUNum(void);
void MP_StartAP(int CPU);
void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode);
#endif
-void Proc_Start(void);
-tThread *Proc_GetCurThread(void);
+//void Proc_Start(void);
+//tThread *Proc_GetCurThread(void);
void Proc_ChangeStack(void);
- int Proc_Clone(Uint *Err, Uint Flags);
+// 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_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_Scheduler(int CPU);
outb(0x40, (TIMER_DIVISOR>>8)&0xFF); // High Byte
// Create Per-Process Data Block
- MM_Allocate(MM_PPD_CFG);
+ if( !MM_Allocate(MM_PPD_CFG) )
+ {
+ Warning("Oh, hell, Unable to allocate PPD for Thread#0");
+ }
// Change Stacks
Proc_ChangeStack();
if(Proc_Clone(0, 0) == 0)
{
gaCPUs[0].IdleThread = Proc_GetCurThread();
- gaCPUs[0].IdleThread->ThreadName = "Idle Thread";
+ gaCPUs[0].IdleThread->ThreadName = (char*)"Idle Thread";
Threads_SetPriority( gaCPUs[0].IdleThread, -1 ); // Never called randomly
gaCPUs[0].IdleThread->Quantum = 1; // 1 slice quantum
for(;;) HALT(); // Just yeilds
if(i != -1) return 0;
// Allocate Stack - Allocate incrementally to clean up MM_Dump output
- for( i = 0; i < USER_STACK_SZ/4069; i++ )
- MM_Allocate( base + (i<<12) );
+ for( i = 0; i < USER_STACK_SZ/0x1000; i++ )
+ {
+ if( !MM_Allocate( base + (i<<12) ) )
+ {
+ // Error
+ Log_Error("Proc", "Unable to allocate user stack (%i pages requested)", USER_STACK_SZ/0x1000);
+ while( i -- )
+ MM_Deallocate( base + (i<<12) );
+ return 0;
+ }
+ }
return base + USER_STACK_SZ;
}