vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

linux-asm.S (2122B)


      1 // Context routines for Linux
      2 
      3 // vx32_getcontext(struct mcontext_t *ss);  
      4 // see /usr/include/sys/ucontext.h for layout.
      5 // notice that we don't set the floating-point state.
      6 // notice also that unlike the linux getcontext,
      7 // we *do* copy the segment registers
      8 
      9 #ifdef i386
     10 
     11 .globl vx32_getcontext
     12 vx32_getcontext:
     13 	movl 4(%esp), %eax
     14 	
     15 	movl %ecx, 40(%eax)
     16 	movl $0, %ecx
     17 	movw %gs, %cx
     18 	movl %ecx, 0(%eax)
     19 	movw %fs, %cx
     20 	movl %ecx, 4(%eax)
     21 	movw %es, %cx
     22 	movl %ecx, 8(%eax)
     23 	movw %ds, %cx
     24 	movl %ecx, 12(%eax)
     25 	movl %edi, 16(%eax)
     26 	movl %esi, 20(%eax)
     27 	movl %ebp, 24(%eax)
     28 	/* 28(%eax) is esp */
     29 	movl %ebx, 32(%eax)
     30 	movl %edx, 36(%eax)
     31 	/* 40(%eax) is ecx, saved above */
     32 	movl $1, 44(%eax)	/* eax */
     33 	movl $0, 48(%eax)	/* trapno */
     34 	movl $0, 52(%eax)	/* err */
     35 	/* 56(%eax) is eip */
     36 	movw %cs, %cx
     37 	movl %ecx, 60(%eax)
     38 	pushf
     39 	movl 0(%esp), %ecx
     40 	popf
     41 	movl %ecx, 64(%eax)
     42 	/* 68(%eax) is another esp */
     43 	movw %ss, %cx
     44 	movl %ecx, 72(%eax)
     45 	
     46 	movl 0(%esp), %ecx		/* %eip */
     47 	movl %ecx, 56(%eax)
     48 	leal 4(%esp), %ecx		/* %esp */
     49 	movl %ecx, 28(%eax)
     50 	movl %ecx, 68(%eax)
     51 	
     52 	movl 40(%eax), %ecx		/* restore %ecx */
     53 	movl $0, %eax
     54 	ret
     55 
     56 #else	/* x86-64 */
     57 
     58 .globl vx32_getcontext
     59 vx32_getcontext:
     60 	// mcontext_t pointer is in %rdi
     61 	movq %r8, 0(%rdi)
     62 	movq %r9, 8(%rdi)
     63 	movq %r10, 16(%rdi)
     64 	movq %r11, 24(%rdi)
     65 	movq %r12, 32(%rdi)
     66 	movq %r13, 40(%rdi)
     67 	movq %r14, 48(%rdi)
     68 	movq %r15, 56(%rdi)
     69 	movq %rdi, 64(%rdi)
     70 	movq %rsi, 72(%rdi)
     71 	movq %rbp, 80(%rdi)
     72 	movq %rbx, 88(%rdi)
     73 	movq %rdx, 96(%rdi)
     74 	movq $1, 104(%rdi)	/* %rax */
     75 	movq %rcx, 112(%rdi)
     76 	/* 120(%rdi) is rsp */
     77 	leaq 8(%rsp), %rax
     78 	movq %rax, 120(%rdi)
     79 	/* 128(%rdi) is rip */
     80 	movq 0(%rsp), %rax
     81 	movq %rax, 128(%rdi)
     82 	/* 136(%rdi) is eflags */
     83 	pushf
     84 	popq %rax
     85 	movq %rax, 136(%rdi)
     86 	/* 144(%rdi) is cs, gs, fs, pad */
     87 	xorq %rax, %rax
     88 	movw %fs, %ax
     89 	shlq $16, %rax
     90 	movw %gs, %ax
     91 	shlq $16, %rax
     92 	movw %cs, %ax
     93 	movq %rax, 144(%rdi)
     94 	/* 152(%rdi) is err */
     95 	movq $0, 152(%rdi)
     96 	/* 160(%rdi) is trapno */
     97 	movq $0, 160(%rdi)
     98 	/* 168(%rdi) is oldmask */
     99 	movq $0, 168(%rdi)
    100 	/* 176(%rdi) is cr2 */
    101 	movq $0, 176(%rdi)
    102 	movq $0, %rax
    103 	ret
    104 
    105 #endif