[global IrqCommon]
IrqCommon:
PUSH_GPR
+ push gs
+ push fs
- mov rbx, [rsp+16*8] ; Calculate address
+ mov rbx, [rsp+(16+2)*8] ; Calculate address
shr rbx, 3+2 ; *8*4
mov rax, gaIRQ_Handlers
add rbx, rax
mov dx, 0x0020
out dx, al
+ pop fs
+ pop gs
POP_GPR
add rsp, 8*2
;xchg bx, bx
[extern Proc_Scheduler]
[global SchedulerIRQ]
+;
+; NOTE: Proc_Scheduler makes assumptions about the stack state when called
+;
SchedulerIRQ:
+ push 0 ; Error code
+ push 0 ; IRQNum
PUSH_GPR
+ push gs
+ push fs
;PUSH_FPU
;PUSH_XMM
;POP_XMM
;POP_FPU
+ pop fs
+ pop gs
POP_GPR
+ add rsp, 2*8 ; Dummy error code and IRQ num
iretq
[section .data]
#define MM_HWMAP_TOP (MM_KERNEL_RANGE|(0xD000##00000000))
#define MM_PPD_BASE (MM_KERNEL_RANGE|(0xD000##00000000))
#define MM_PPD_CFG MM_PPD_BASE
-#define MM_PPD_VFS (MM_KERNEL_RANGE|(0xD008##00000000))
+#define MM_PPD_HANDLES (MM_KERNEL_RANGE|(0xD008##00000000))
#define MM_USER_CODE (MM_KERNEL_RANGE|(0xD080##00000000))
#define MM_PAGE_COUNTS (MM_KERNEL_RANGE|(0xE000##00000000))
Uint FS, GS;
Uint RAX, RCX, RDX, RBX;
- Uint KernelRSP, RBP, RSI, RDI;
+ Uint KernelRSP, RBP, RSI, RDI;
Uint R8, R9, R10, R11;
Uint R12, R13, R14, R15;
- Uint IntNum, ErrorCode;
- Uint RIP, CS;
+ Uint IntNum, ErrorCode;
+ Uint RIP, CS;
Uint RFlags, RSP, SS;
} tRegs;
typedef struct sTaskState
{
Uint RIP, RSP, RBP;
+ Uint64 UserRIP, UserCS;
} tTaskState;
// === CONSTANTS ===
void Proc_DumpThreadCPUState(tThread *Thread)
{
+ Log(" At %04x:%016llx", Thread->SavedState.UserCS, Thread->SavedState.UserRIP);
}
/**
// Get current thread
thread = gaCPUs[CPU].Current;
-
- // Reduce remaining quantum and continue timeslice if non-zero
- if(thread->Remaining--) return;
- // Reset quantum for next call
- thread->Remaining = thread->Quantum;
-
- // Get machine state
- __asm__ __volatile__ ("mov %%rsp, %0":"=r"(rsp));
- __asm__ __volatile__ ("mov %%rbp, %0":"=r"(rbp));
- rip = GetRIP();
- if(rip == SWITCH_MAGIC) return; // Check if a switch happened
-
- // Save machine state
- thread->SavedState.RSP = rsp;
- thread->SavedState.RBP = rbp;
- thread->SavedState.RIP = rip;
+
+ if( thread )
+ {
+ tRegs *regs;
+ // Reduce remaining quantum and continue timeslice if non-zero
+ if(thread->Remaining--) return;
+ // Reset quantum for next call
+ thread->Remaining = thread->Quantum;
+
+ // Get machine state
+ __asm__ __volatile__ ("mov %%rsp, %0":"=r"(rsp));
+ __asm__ __volatile__ ("mov %%rbp, %0":"=r"(rbp));
+ rip = GetRIP();
+ if(rip == SWITCH_MAGIC) return; // Check if a switch happened
+
+ // Save machine state
+ thread->SavedState.RSP = rsp;
+ thread->SavedState.RBP = rbp;
+ thread->SavedState.RIP = rip;
+
+ // TODO: Make this more stable somehow
+ regs = (tRegs*)(rbp+(2+1)*8); // RBP,Ret + CurThread
+ thread->SavedState.UserCS = regs->CS;
+ thread->SavedState.UserRIP = regs->RIP;
+ }
// Get next thread
thread = Threads_GetNextToRun(CPU, thread);