From: John Hodge Date: Sun, 25 Sep 2011 03:13:24 +0000 (+0800) Subject: Kernel/x86_64 - Oops, forgot some files X-Git-Tag: rel0.11~73 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3d0a53a04f9f156147db11a09c70046484926570;p=tpg%2Facess2.git Kernel/x86_64 - Oops, forgot some files --- diff --git a/Kernel/arch/x86_64/include/common.inc.asm b/Kernel/arch/x86_64/include/common.inc.asm new file mode 100644 index 00000000..c3a362a4 --- /dev/null +++ b/Kernel/arch/x86_64/include/common.inc.asm @@ -0,0 +1,48 @@ + +%macro SAVE_GPR 1 + mov [%1-0x08], r15 + mov [%1-0x10], r14 + mov [%1-0x18], r13 + mov [%1-0x20], r12 + mov [%1-0x28], r11 + mov [%1-0x30], r10 + mov [%1-0x38], r9 + mov [%1-0x40], r8 + mov [%1-0x48], rdi + mov [%1-0x50], rsi + mov [%1-0x58], rbp + mov [%1-0x60], rsp + mov [%1-0x68], rbx + mov [%1-0x70], rdx + mov [%1-0x78], rcx + mov [%1-0x80], rax +%endmacro + +%macro PUSH_GPR 0 + SAVE_GPR rsp + sub rsp, 0x80 +%endmacro + +%macro RESTORE_GPR 1 + mov r15, [%1-0x08] + mov r14, [%1-0x10] + mov r13, [%1-0x18] + mov r12, [%1-0x20] + mov r11, [%1-0x28] + mov r10, [%1-0x30] + mov r9, [%1-0x38] + mov r8, [%1-0x40] + mov rdi, [%1-0x48] + mov rsi, [%1-0x50] + mov rbp, [%1-0x58] + ;mov rsp, [%1-0x60] + mov rbx, [%1-0x68] + mov rdx, [%1-0x70] + mov rcx, [%1-0x78] + mov rax, [%1-0x80] +%endmacro + +%macro POP_GPR 0 + add rsp, 0x80 + RESTORE_GPR rsp +%endmacro diff --git a/Kernel/arch/x86_64/proc.asm b/Kernel/arch/x86_64/proc.asm new file mode 100644 index 00000000..541abd6c --- /dev/null +++ b/Kernel/arch/x86_64/proc.asm @@ -0,0 +1,72 @@ +; +; +; +%include "arch/x86_64/include/common.inc.asm" +[BITS 64] +[section .text] + +[extern Threads_Exit] + +[global GetRIP] +GetRIP: + mov rax, [rsp] + ret + +[global NewTaskHeader] +NewTaskHeader: + mov rax, [rsp] + mov dr0, rax + + sti + mov al, 0x20 + mov dx, 0x20 + out dx, al + + mov rdi, [rsp+0x18] + dec QWORD [rsp+0x10] + jz .call + mov rsi, [rsp+0x20] + dec QWORD [rsp+0x10] + jz .call + mov rdx, [rsp+0x28] + dec QWORD [rsp+0x10] + jz .call + mov rcx, [rsp+0x30] + dec QWORD [rsp+0x10] + jz .call +.call: + mov rax, [rsp+0x8] +; xchg bx, bx + call rax + + ; Quit thread with RAX as the return code + xor rdi, rdi + mov rsi, rax + call Threads_Exit + +.hlt: + jmp .hlt + +[global SaveState] +SaveState: + ; Save regs to RSI + xchg bx, bx + add rsi, 0x80 + SAVE_GPR rsi + sub rsi, 0x80 + ; Return RSI as the RSP value + mov [rdi], rsi + call GetRIP + cmp eax, 0x80000000 + ja .fastret +.restore: + ; RSP = RSI from call + xchg bx, bx + POP_GPR + mov rsp, [rsp-0x60] ; Restore RSP from the saved value + xor eax, eax + ret +.fastret: + ; RAX is still the return addr + ret +