kernel: save and restore all registers on syscall

This commit is contained in:
Giacomo Tesio 2017-05-21 00:15:51 +02:00
parent 4b7957a28f
commit cc595c7c99
2 changed files with 15 additions and 1 deletions

View File

@ -198,6 +198,8 @@ struct Mach
uint64_t machno; /* physical id of processor */
uint64_t splpc; /* pc of last caller to splhi */
Proc* proc; /* current process on this processor */
uint64_t tmp0; /* for syscallentry */
uint64_t tmp1; /* for syscallentry */
int apicno;
int online;

View File

@ -28,10 +28,14 @@ touser:
syscallentry:
swapgs
movq %gs:0, %r15 /* m-> (movq GS:0x0, R15) */
xchgq %gs:0, %r15
movq %r14, 24(%r15) /* save %r14 to m->tmp0 */
movq 16(%r15), %r14 /* m->proc (set up->) */
movq %r13, 32(%r15) /* save %r13 to m->tmp1 */
movq 16*8(%r14), %r13 /* m->proc->kstack (after the Label) */
xchgq %r13, %rsp
movq 24(%r15), %r14 /* restore %r14 */
addq $KSTACK, %rsp
/* build Ureg */
@ -41,6 +45,10 @@ syscallentry:
pushq $SSEL(SiUCS, SsRPL3) /* old code segment */
pushq %rcx /* old ip */
movq %r14, 24(%r15) /* restore %r14 from m->tmp0 */
movq %r13, 32(%r15) /* restore %r13 from m->tmp1 */
xchgq %gs:0, %r15 /* restore %r15 */
subq $(17*8), %rsp
movq %rax, (0*8)(%rsp) // ureg.ax
@ -61,6 +69,10 @@ syscallentry:
// (15*8)(%rsp) // ureg.type
// (16*8)(%rsp) // ureg.error
/* prepare m-> and up-> for the kernel */
movq %gs:0, %r15
movq 16(%r15), %r14
movq %rsp, %rsi /* Ureg* */
// system call number is in %rax, as per linux.
movq %rax, %rdi