git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Kernel/arm7 - Fiddling, still having issues with VMM
[tpg/acess2.git]
/
Kernel
/
arch
/
x86_64
/
proc.c
diff --git
a/Kernel/arch/x86_64/proc.c
b/Kernel/arch/x86_64/proc.c
index
8691100
..
31dd80e
100644
(file)
--- a/
Kernel/arch/x86_64/proc.c
+++ b/
Kernel/arch/x86_64/proc.c
@@
-13,9
+13,11
@@
# include <mp.h>
#endif
#include <arch_config.h>
# include <mp.h>
#endif
#include <arch_config.h>
+#include <hal_proc.h>
// === FLAGS ===
#define DEBUG_TRACE_SWITCH 0
// === FLAGS ===
#define DEBUG_TRACE_SWITCH 0
+//#define BREAK_ON_SWITCH 1 // Break into bochs debugger on a task switch
// === CONSTANTS ===
#define SWITCH_MAGIC 0x55ECAFFF##FFFACE55 // There is no code in this area
// === CONSTANTS ===
#define SWITCH_MAGIC 0x55ECAFFF##FFFACE55 // There is no code in this area
@@
-44,11
+46,10
@@
extern int giNumActiveThreads;
extern tThread gThreadZero;
extern void Threads_Dump(void);
extern void Proc_ReturnToUser(void);
extern tThread gThreadZero;
extern void Threads_Dump(void);
extern void Proc_ReturnToUser(void);
-extern int GetCPUNum(void);
extern void Time_UpdateTimestamp(void);
// === PROTOTYPES ===
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);
#if USE_MP
void MP_StartAP(int CPU);
void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode);
@@
-59,11
+60,11
@@
void Proc_ChangeStack(void);
// int Proc_Clone(Uint *Err, Uint Flags);
// int Proc_SpawnWorker(void);
Uint Proc_MakeUserStack(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_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 ===
void Proc_Scheduler(int CPU);
// === GLOBALS ===
@@
-287,10
+288,10
@@
void ArchThreads_Init(void)
#if USE_MP
}
for(pos=0;pos<giNumCPUs;pos++) {
#if USE_MP
}
for(pos=0;pos<giNumCPUs;pos++) {
- #endif
__asm__ __volatile__ ("ltr %%ax"::"a"(0x38+pos*16));
__asm__ __volatile__ ("ltr %%ax"::"a"(0x38+pos*16));
- #if USE_MP
}
}
+ #else
+ __asm__ __volatile__ ("ltr %%ax"::"a"(0x38));
#endif
// Set Debug registers
#endif
// Set Debug registers
@@
-390,7
+391,7
@@
void Proc_Start(void)
while( giNumInitingCPUs ) __asm__ __volatile__ ("hlt");
#else
// Create Idle Task
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";
{
gaCPUs[0].IdleThread = Proc_GetCurThread();
gaCPUs[0].IdleThread->ThreadName = (char*)"Idle Thread";
@@
-476,10
+477,10
@@
void Proc_ChangeStack(void)
}
/**
}
/**
- * \fn int Proc_Clone(Uint
*Err, Uint
Flags)
+ * \fn int Proc_Clone(Uint Flags)
* \brief Clone the current process
*/
* \brief Clone the current process
*/
-int Proc_Clone(Uint
*Err, Uint
Flags)
+int Proc_Clone(Uint Flags)
{
tThread *newThread;
tThread *cur = Proc_GetCurThread();
{
tThread *newThread;
tThread *cur = Proc_GetCurThread();
@@
-488,7
+489,7
@@
int Proc_Clone(Uint *Err, Uint Flags)
__asm__ __volatile__ ("mov %%rsp, %0": "=r"(rsp));
__asm__ __volatile__ ("mov %%rbp, %0": "=r"(rbp));
__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);
if(!newThread) return -1;
Log("Proc_Clone: newThread = %p", newThread);
@@
-498,6
+499,7
@@
int Proc_Clone(Uint *Err, Uint Flags)
Log("Proc_Clone: Cloning VM");
newThread->MemState.CR3 = MM_Clone();
newThread->KernelStack = cur->KernelStack;
Log("Proc_Clone: Cloning VM");
newThread->MemState.CR3 = MM_Clone();
newThread->KernelStack = cur->KernelStack;
+// MAGIC_BREAK();
} else {
Uint tmp_rbp, old_rsp = rsp;
} else {
Uint tmp_rbp, old_rsp = rsp;
@@
-542,6
+544,7
@@
int Proc_Clone(Uint *Err, Uint Flags)
if(rip == SWITCH_MAGIC) {
outb(0x20, 0x20); // ACK Timer and return as child
__asm__ __volatile__ ("sti");
if(rip == SWITCH_MAGIC) {
outb(0x20, 0x20); // ACK Timer and return as child
__asm__ __volatile__ ("sti");
+// MAGIC_BREAK();
return 0;
}
return 0;
}
@@
-597,7
+600,7
@@
int Proc_SpawnWorker(void)
// Set EIP as parent
new->SavedState.RIP = rip;
// Mark as active
// Set EIP as parent
new->SavedState.RIP = rip;
// Mark as active
- new->Status = THREAD_STAT_
ACTIVE
;
+ new->Status = THREAD_STAT_
PREINIT
;
Threads_AddActive( new );
return new->TID;
Threads_AddActive( new );
return new->TID;
@@
-789,7
+792,12
@@
void Proc_Scheduler(int CPU)
thread->SavedState.UserCS = regs->CS;
thread->SavedState.UserRIP = regs->RIP;
}
thread->SavedState.UserCS = regs->CS;
thread->SavedState.UserRIP = regs->RIP;
}
-
+
+ #if BREAK_ON_SWITCH
+ {
+ tThread *oldthread = thread;
+ #endif
+
// Get next thread
thread = Threads_GetNextToRun(CPU, thread);
// Get next thread
thread = Threads_GetNextToRun(CPU, thread);
@@
-797,9
+805,18
@@
void Proc_Scheduler(int CPU)
if(thread == NULL) {
thread = gaCPUs[CPU].IdleThread;
//Warning("Hmm... Threads_GetNextToRun returned NULL, I don't think this should happen.\n");
if(thread == NULL) {
thread = gaCPUs[CPU].IdleThread;
//Warning("Hmm... Threads_GetNextToRun returned NULL, I don't think this should happen.\n");
- //LogF("Zzzzz.\n");
- return;
+// LogF("Zzzzz.\n");
+ //return;
+ }
+ if(thread == NULL ) {
+ return ;
+ }
+ #if BREAK_ON_SWITCH
+ if( thread != oldthread ) {
+ MAGIC_BREAK();
}
}
+ }
+ #endif
#if DEBUG_TRACE_SWITCH
LogF("Switching to task %i, CR3 = 0x%x, RIP = %p",
#if DEBUG_TRACE_SWITCH
LogF("Switching to task %i, CR3 = 0x%x, RIP = %p",
@@
-818,16
+835,15
@@
void Proc_Scheduler(int CPU)
// Update Kernel Stack pointer
gTSSs[CPU].RSP0 = thread->KernelStack-4;
// Update Kernel Stack pointer
gTSSs[CPU].RSP0 = thread->KernelStack-4;
- // Set address space
- __asm__ __volatile__ ("mov %0, %%cr3"::"a"(thread->MemState.CR3));
-
// Switch threads
__asm__ __volatile__ (
// Switch threads
__asm__ __volatile__ (
+ "mov %4, %%cr3\n\t"
"mov %1, %%rsp\n\t" // Restore RSP
"mov %2, %%rbp\n\t" // and RBP
"jmp *%3" : : // And return to where we saved state (Proc_Clone or Proc_Scheduler)
"mov %1, %%rsp\n\t" // Restore RSP
"mov %2, %%rbp\n\t" // and RBP
"jmp *%3" : : // And return to where we saved state (Proc_Clone or Proc_Scheduler)
- "a"(SWITCH_MAGIC), "b"(thread->SavedState.RSP),
- "d"(thread->SavedState.RBP), "c"(thread->SavedState.RIP)
+ "a"(SWITCH_MAGIC), "r"(thread->SavedState.RSP),
+ "r"(thread->SavedState.RBP), "r"(thread->SavedState.RIP),
+ "r"(thread->MemState.CR3)
);
for(;;); // Shouldn't reach here
}
);
for(;;); // Shouldn't reach here
}
UCC
git Repository :: git.ucc.asn.au