PERFORCE change 28483 for review
Peter Wemm
peter at FreeBSD.org
Mon Apr 7 20:47:24 PDT 2003
http://perforce.freebsd.org/chv.cgi?CH=28483
Change 28483 by peter at peter_daintree on 2003/04/07 20:46:57
give cpu_switch a chance to work. Update for register conventions etc.
note that unlike i386 where %esi and %edi are saved, x86-64 saves
%r12-%r15 instead. %rsi/%rdi are not preserved across function calls,
so they do not need to be saved in the pcb.
Affected files ...
.. //depot/projects/hammer/sys/x86_64/include/pcb.h#9 edit
.. //depot/projects/hammer/sys/x86_64/x86_64/exception.s#15 edit
.. //depot/projects/hammer/sys/x86_64/x86_64/genassym.c#15 edit
.. //depot/projects/hammer/sys/x86_64/x86_64/swtch.s#15 edit
.. //depot/projects/hammer/sys/x86_64/x86_64/vm_machdep.c#17 edit
Differences ...
==== //depot/projects/hammer/sys/x86_64/include/pcb.h#9 (text+ko) ====
@@ -47,8 +47,10 @@
struct pcb {
long pcb_cr3;
- long pcb_rdi;
- long pcb_rsi;
+ long pcb_r15;
+ long pcb_r14;
+ long pcb_r13;
+ long pcb_r12;
long pcb_rbp;
long pcb_rsp;
long pcb_rbx;
==== //depot/projects/hammer/sys/x86_64/x86_64/exception.s#15 (text+ko) ====
@@ -212,14 +212,13 @@
jmp doreti
ENTRY(fork_trampoline)
- pushq %rsp /* trapframe pointer */
- pushq %rbx /* arg1 */
- pushq %rsi /* function */
+ movq %r12, %rdi /* function */
+ movq %rbx, %rsi /* arg1 */
+ movq %rsp, %rdx /* trapframe pointer */
movq PCPU(CURTHREAD),%rbx /* setup critnest */
movl $1,TD_CRITNEST(%rbx)
sti /* enable interrupts */
call fork_exit
- addq $24,%rsp
/* cut from syscall */
/*
==== //depot/projects/hammer/sys/x86_64/x86_64/genassym.c#15 (text+ko) ====
@@ -114,8 +114,10 @@
ASSYM(KERNBASE, KERNBASE);
ASSYM(MCLBYTES, MCLBYTES);
ASSYM(PCB_CR3, offsetof(struct pcb, pcb_cr3));
-ASSYM(PCB_RDI, offsetof(struct pcb, pcb_rdi));
-ASSYM(PCB_RSI, offsetof(struct pcb, pcb_rsi));
+ASSYM(PCB_R15, offsetof(struct pcb, pcb_r15));
+ASSYM(PCB_R14, offsetof(struct pcb, pcb_r14));
+ASSYM(PCB_R13, offsetof(struct pcb, pcb_r13));
+ASSYM(PCB_R12, offsetof(struct pcb, pcb_r12));
ASSYM(PCB_RBP, offsetof(struct pcb, pcb_rbp));
ASSYM(PCB_RSP, offsetof(struct pcb, pcb_rsp));
ASSYM(PCB_RBX, offsetof(struct pcb, pcb_rbx));
==== //depot/projects/hammer/sys/x86_64/x86_64/swtch.s#15 (text+ko) ====
@@ -54,33 +54,26 @@
* about its state. This is only a slight optimization and is probably
* not worth it anymore. Note that we need to clear the pm_active bits so
* we do need the old proc if it still exists.
- * 0(%rsp) = ret
- * 8(%rsp) = oldtd
- * 16(%rsp) = newtd
+ * %rdi = oldtd
+ * %rsi = newtd
*/
ENTRY(cpu_throw)
- movq $nothrow, %rdi
- call serial_puts
- movq $nothrow, %rdi
- call panic
- xorq %rsi, %rsi
- movl PCPU(CPUID), %esi
- movq 8(%rsp),%rcx /* Old thread */
- testq %rcx,%rcx /* no thread? */
+ xorq %rax, %rax
+ movl PCPU(CPUID), %eax
+ testq %rdi,%rdi /* no thread? */
jz 1f
/* release bit from old pm_active */
- movq TD_PROC(%rcx), %rax /* thread->td_proc */
- movq P_VMSPACE(%rax), %rbx /* proc->p_vmspace */
- btrq %rsi, VM_PMAP+PM_ACTIVE(%rbx) /* clear old */
+ movq TD_PROC(%rdi), %rdx /* oldtd->td_proc */
+ movq P_VMSPACE(%rdx), %rdx /* proc->p_vmspace */
+ btrq %rax, VM_PMAP+PM_ACTIVE(%rdx) /* clear old */
1:
- movq 16(%rsp),%rcx /* New thread */
- movq TD_PCB(%rcx),%rdx
- movq PCB_CR3(%rdx),%rax
- movq %rax,%cr3 /* new address space */
+ movq TD_PCB(%rsi),%rdx /* newtd->td_proc */
+ movq PCB_CR3(%rdx),%rdx
+ movq %rdx,%cr3 /* new address space */
/* set bit in new pm_active */
- movq TD_PROC(%rcx),%rax
- movq P_VMSPACE(%rax), %rbx
- btsq %rsi, VM_PMAP+PM_ACTIVE(%rbx) /* set new */
+ movq TD_PROC(%rsi),%rdx
+ movq P_VMSPACE(%rdx), %rdx
+ btsq %rax, VM_PMAP+PM_ACTIVE(%rdx) /* set new */
jmp sw1
/*
@@ -88,40 +81,33 @@
*
* Save the current thread state, then select the next thread to run
* and load its state.
- * 0(%rsp) = ret
- * 8(%rsp) = oldtd
- * 16(%rsp) = newtd
+ * %rdi = oldtd
+ * %rsi = newtd
*/
ENTRY(cpu_switch)
- movq $noswitch, %rdi
- call serial_puts
- movq $noswitch, %rdi
- call panic
-
/* Switch to new thread. First, save context. */
- movq 8(%rsp),%rcx
-
#ifdef INVARIANTS
- testq %rcx,%rcx /* no thread? */
+ testq %rdi,%rdi /* no thread? */
jz badsw2 /* no, panic */
#endif
- movq TD_PCB(%rcx),%rdx
+ movq TD_PCB(%rdi),%rdx
movq (%rsp),%rax /* Hardware registers */
movq %rax,PCB_RIP(%rdx)
movq %rbx,PCB_RBX(%rdx)
movq %rsp,PCB_RSP(%rdx)
movq %rbp,PCB_RBP(%rdx)
- movq %rsi,PCB_RSI(%rdx)
- movq %rdi,PCB_RDI(%rdx)
-#XXX movq %gs,PCB_GS(%rdx)
+ movq %r12,PCB_R12(%rdx)
+ movq %r13,PCB_R13(%rdx)
+ movq %r14,PCB_R14(%rdx)
+ movq %r15,PCB_R15(%rdx)
pushfq /* PSL */
popq PCB_PSL(%rdx)
/* have we used fp, and need a save? */
- cmpq %rcx,PCPU(FPCURTHREAD)
+ cmpq %rdi,PCPU(FPCURTHREAD)
jne 1f
addq $PCB_SAVEFPU,%rdx /* h/w bugs make saving complicated */
pushq %rdx
@@ -130,52 +116,52 @@
1:
/* Save is done. Now fire up new thread. Leave old vmspace. */
- movq %rcx,%rdi
- movq 16(%rsp),%rcx /* New thread */
#ifdef INVARIANTS
- testq %rcx,%rcx /* no thread? */
+ testq %rsi,%rsi /* no thread? */
jz badsw3 /* no, panic */
#endif
- movq TD_PCB(%rcx),%rdx
- xorq %rsi, %rsi
- movl PCPU(CPUID), %esi
+ movq TD_PCB(%rsi),%rdx
+ xorq %rax, %rax
+ movl PCPU(CPUID), %eax
/* switch address space */
- movq PCB_CR3(%rdx),%rax
- movq %rax,%cr3 /* new address space */
+ movq PCB_CR3(%rdx),%rdx
+ movq %rdx,%cr3 /* new address space */
/* Release bit from old pmap->pm_active */
- movq TD_PROC(%rdi), %rax /* oldproc */
- movq P_VMSPACE(%rax), %rbx
- btrq %rsi, VM_PMAP+PM_ACTIVE(%rbx) /* clear old */
+ movq TD_PROC(%rdi), %rdx /* oldproc */
+ movq P_VMSPACE(%rdx), %rdx
+ btrq %rax, VM_PMAP+PM_ACTIVE(%rdx) /* clear old */
/* Set bit in new pmap->pm_active */
- movq TD_PROC(%rcx),%rax /* newproc */
- movq P_VMSPACE(%rax), %rbx
- btsq %rsi, VM_PMAP+PM_ACTIVE(%rbx) /* set new */
+ movq TD_PROC(%rsi),%rdx /* newproc */
+ movq P_VMSPACE(%rdx), %rdx
+ btsq %rax, VM_PMAP+PM_ACTIVE(%rdx) /* set new */
sw1:
/*
* At this point, we've switched address spaces and are ready
* to load up the rest of the next context.
*/
+ movq TD_PCB(%rsi),%rdx
/* Restore context. */
movq PCB_RBX(%rdx),%rbx
movq PCB_RSP(%rdx),%rsp
movq PCB_RBP(%rdx),%rbp
- movq PCB_RSI(%rdx),%rsi
- movq PCB_RDI(%rdx),%rdi
+ movq PCB_R12(%rdx),%r12
+ movq PCB_R13(%rdx),%r13
+ movq PCB_R14(%rdx),%r14
+ movq PCB_R15(%rdx),%r15
movq PCB_RIP(%rdx),%rax
movq %rax,(%rsp)
pushq PCB_PSL(%rdx)
popfq
movq %rdx, PCPU(CURPCB)
- movq %rcx, PCPU(CURTHREAD) /* into next thread */
+ movq %rsi, PCPU(CURTHREAD) /* into next thread */
.globl cpu_switch_load_gs
cpu_switch_load_gs:
-#XXX movq PCB_GS(%rdx),%gs
ret
@@ -261,9 +247,10 @@
movq %rbx,PCB_RBX(%rcx)
movq %rsp,PCB_RSP(%rcx)
movq %rbp,PCB_RBP(%rcx)
- movq %rsi,PCB_RSI(%rcx)
- movq %rdi,PCB_RDI(%rcx)
-#XXX movq %gs,PCB_GS(%rcx)
+ movq %r12,PCB_R12(%rcx)
+ movq %r13,PCB_R13(%rcx)
+ movq %r14,PCB_R14(%rcx)
+ movq %r15,PCB_R15(%rcx)
pushfq
popq PCB_PSL(%rcx)
==== //depot/projects/hammer/sys/x86_64/x86_64/vm_machdep.c#17 (text+ko) ====
@@ -139,8 +139,7 @@
#else
pcb2->pcb_cr3 = vtophys(vmspace_pmap(p2->p_vmspace)->pm_pdir);
#endif
- pcb2->pcb_rdi = 0;
- pcb2->pcb_rsi = (int)fork_return; /* fork_trampoline argument */
+ pcb2->pcb_r12 = (int)fork_return; /* fork_trampoline argument */
pcb2->pcb_rbp = 0;
pcb2->pcb_rsp = (long)td2->td_frame - sizeof(void *);
pcb2->pcb_rbx = (long)td2; /* fork_trampoline argument */
@@ -180,7 +179,7 @@
* Note that the trap frame follows the args, so the function
* is really called like this: func(arg, frame);
*/
- td->td_pcb->pcb_rsi = (long) func; /* function */
+ td->td_pcb->pcb_r12 = (long) func; /* function */
td->td_pcb->pcb_rbx = (long) arg; /* first arg */
}
More information about the p4-projects
mailing list