"Fossies" - the Fresh Open Source Software Archive

Member "txr-217/jmp.S" (10 Jun 2019, 7164 Bytes) of package /linux/misc/txr-217.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PowerPC Assembler source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright 2009-2019
    2  * Kaz Kylheku <kaz@kylheku.com>
    3  * Vancouver, Canada
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions are met:
    8  *
    9  * 1. Redistributions of source code must retain the above copyright notice, this
   10  *    list of conditions and the following disclaimer.
   11  *
   12  * 2. Redistributions in binary form must reproduce the above copyright notice,
   13  *    this list of conditions and the following disclaimer in the documentation
   14  *    and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   19  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   23  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   26  */
   27 
   28 #if __MINGW32__ || (__CYGWIN__ && __i386__)
   29 #define DEFUN(NAME) \
   30 .global _ ## NAME ; \
   31 _ ## NAME: ;
   32 #elif __APPLE__
   33 #define DEFUN(NAME) \
   34 .globl _ ## NAME ; \
   35 _ ## NAME: ;
   36 #elif (__arm__ && !__thumb__) || __aarch64__
   37 #define DEFUN(NAME) \
   38 .text ; \
   39 .align 4 ; \
   40 .global NAME ; \
   41 .type NAME, %function ; \
   42 NAME: ;
   43 #elif __arm__ && __thumb__
   44 #define DEFUN(NAME) \
   45 .text ; \
   46 .align 4 ; \
   47 .global NAME ; \
   48 .thumb ; \
   49 .thumb_func ; \
   50 .type NAME, %function ; \
   51 NAME: ;
   52 #elif __CYGWIN__ && __x86_64__
   53 #define DEFUN(NAME) \
   54 .globl NAME ; \
   55 .def NAME; .scl 2; .type 32; .endef; \
   56 NAME: ;
   57 #else
   58 #define DEFUN(NAME) \
   59 .global NAME ; \
   60 .type NAME, @function ; \
   61 NAME: ;
   62 #endif
   63 
   64 #if __arm__
   65 #define SIGIL() %
   66 #else
   67 #define SIGIL() @
   68 #endif
   69 
   70 #if __i386__
   71 
   72 #define JEIP  0
   73 #define JESP  4
   74 #define JEBP  8
   75 #define JEBX 12
   76 #define JESI 16
   77 #define JEDI 20
   78 
   79 #define RETA  0
   80 #define ARG1  4
   81 #define ARG2  8
   82 
   83 DEFUN(jmp_save)
   84   movl RETA(%esp), %ecx
   85   movl ARG1(%esp), %eax
   86   movl %ecx, JEIP(%eax)
   87   leal ARG1(%esp), %ecx
   88   movl %ecx, JESP(%eax)
   89   movl %ebp, JEBP(%eax)
   90   movl %ebx, JEBX(%eax)
   91   movl %esi, JESI(%eax)
   92   movl %edi, JEDI(%eax)
   93   xorl %eax, %eax
   94   ret
   95 
   96 DEFUN(jmp_restore)
   97   movl ARG1(%esp), %edx
   98   movl ARG2(%esp), %eax
   99   mov JEDI(%edx),%edi
  100   mov JESI(%edx),%esi
  101   mov JEBX(%edx),%ebx
  102   mov JEBP(%edx),%ebp
  103   mov JESP(%edx),%ecx
  104   mov %ecx,%esp
  105   mov JEIP(%edx),%ecx
  106   jmp *%ecx
  107 
  108 #elif __x86_64__ && !__CYGWIN__
  109 
  110 #define JRIP  0
  111 #define JRSP  8
  112 #define JRBP 16
  113 #define JRBX 24
  114 #define JR12 32
  115 #define JR13 40
  116 #define JR14 48
  117 #define JR15 56
  118 
  119 #define RETA  0
  120 #define ARG2  8
  121 
  122 DEFUN(jmp_save)
  123   mov RETA(%rsp), %rdx
  124   mov %rdx, JRIP(%rdi)
  125   lea ARG2(%rsp), %rdx
  126   mov %rdx, JRSP(%rdi)
  127   mov %rbp, JRBP(%rdi)
  128   mov %rbx, JRBX(%rdi)
  129   mov %r12, JR12(%rdi)
  130   mov %r13, JR13(%rdi)
  131   mov %r14, JR14(%rdi)
  132   mov %r15, JR15(%rdi)
  133   xor %rax, %rax
  134   ret
  135 
  136 DEFUN(jmp_restore)
  137   mov JR15(%rdi), %r15
  138   mov JR14(%rdi), %r14
  139   mov JR13(%rdi), %r13
  140   mov JR12(%rdi), %r12
  141   mov JRBX(%rdi), %rbx
  142   mov JRBP(%rdi), %rbp
  143   mov JRSP(%rdi), %rdx
  144   mov %rdx, %rsp
  145   mov JRIP(%rdi), %rdx
  146   mov %rsi, %rax
  147   jmp *%rdx
  148 
  149 #elif __x86_64__ && __CYGWIN__
  150 
  151 #define JRIP  0
  152 #define JRSP  8
  153 #define JRBP 16
  154 #define JRBX 24
  155 #define JR12 32
  156 #define JR13 40
  157 #define JR14 48
  158 #define JR15 56
  159 #define JRSI 64
  160 #define JRDI 72
  161 
  162 #define RETA  0
  163 #define ARG2  8
  164 
  165 DEFUN(jmp_save)
  166   mov RETA(%rsp), %rax
  167   mov %rax, JRIP(%rcx)
  168   lea ARG2(%rsp), %rax
  169   mov %rax, JRSP(%rcx)
  170   mov %rbp, JRBP(%rcx)
  171   mov %rbx, JRBX(%rcx)
  172   mov %r12, JR12(%rcx)
  173   mov %r13, JR13(%rcx)
  174   mov %r14, JR14(%rcx)
  175   mov %r15, JR15(%rcx)
  176   mov %rsi, JRSI(%rcx)
  177   mov %rdi, JRDI(%rcx)
  178   xor %rax, %rax
  179   ret
  180 
  181 DEFUN(jmp_restore)
  182   mov JRDI(%rcx), %rdi
  183   mov JRSI(%rcx), %rsi
  184   mov JR15(%rcx), %r15
  185   mov JR14(%rcx), %r14
  186   mov JR13(%rcx), %r13
  187   mov JR12(%rcx), %r12
  188   mov JRBX(%rcx), %rbx
  189   mov JRBP(%rcx), %rbp
  190   mov JRSP(%rcx), %rax
  191   mov %rax, %rsp
  192   mov JRIP(%rcx), %rcx
  193   mov %rdx, %rax
  194   jmp *%rcx
  195 
  196 
  197 #elif __arm__ && !__thumb__
  198 
  199 DEFUN(jmp_save)
  200   stmia r0, {r4, r5, r6, r7, r8, r9, r10, fp, sp, lr}
  201   mov   r0, #0
  202   bx    lr
  203 
  204 DEFUN(jmp_restore)
  205   ldmia r0, {r4, r5, r6, r7, r8, r9, r10, fp, sp, lr}
  206   mov   r0, r1
  207   bx    lr
  208 
  209 #elif __arm__ && __thumb__
  210 
  211 DEFUN(jmp_save)
  212   mov   r2, r0
  213   mov   r3, lr
  214   stmia r0!, {r3, r4, r5, r6, r7}
  215   mov   r3, r8
  216   mov   r4, r9
  217   mov   r5, r10
  218   mov   r6, fp
  219   mov   r7, sp
  220   stmia r0!, {r3, r4, r5, r6, r7}
  221   ldmia r2!, {r3, r4, r5, r6, r7}
  222   mov   r0, #0
  223   bx    lr
  224 
  225 DEFUN(jmp_restore)
  226   mov   r2, r0
  227   add   r0, #5*4
  228   ldmia r0!, {r3, r4, r5, r6, r7}
  229   mov   r8, r3
  230   mov   r9, r4
  231   mov   r10, r5
  232   mov   fp, r6
  233   mov   sp, r7
  234   ldmia r2!, {r3, r4, r5, r6, r7}
  235   mov   r0, r1
  236   bx    r3
  237 
  238 #elif __PPC64__
  239 
  240 DEFUN(jmp_save)
  241   mflr  %r11
  242   mfcr  %r12
  243   std   %r1, 0(%r3)
  244   std   %r2, 8(%r3)
  245   std   %r11, 16(%r3)
  246   std   %r12, 24(%r3)
  247   std   %r13, 32(%r3)
  248   std   %r14, 40(%r3)
  249   std   %r15, 48(%r3)
  250   std   %r16, 56(%r3)
  251   std   %r17, 64(%r3)
  252   std   %r18, 72(%r3)
  253   std   %r19, 80(%r3)
  254   std   %r20, 88(%r3)
  255   std   %r21, 96(%r3)
  256   std   %r22, 104(%r3)
  257   std   %r23, 112(%r3)
  258   std   %r24, 120(%r3)
  259   std   %r25, 128(%r3)
  260   std   %r26, 136(%r3)
  261   std   %r27, 144(%r3)
  262   std   %r28, 152(%r3)
  263   std   %r29, 160(%r3)
  264   std   %r30, 168(%r3)
  265   std   %r31, 176(%r3)
  266   li    %r3, 0
  267   blr
  268 
  269 DEFUN(jmp_restore)
  270   ld    %r31, 176(%r3)
  271   ld    %r30, 168(%r3)
  272   ld    %r29, 160(%r3)
  273   ld    %r28, 152(%r3)
  274   ld    %r27, 144(%r3)
  275   ld    %r26, 136(%r3)
  276   ld    %r25, 128(%r3)
  277   ld    %r24, 120(%r3)
  278   ld    %r23, 112(%r3)
  279   ld    %r22, 104(%r3)
  280   ld    %r21, 96(%r3)
  281   ld    %r20, 88(%r3)
  282   ld    %r17, 64(%r3)
  283   ld    %r19, 80(%r3)
  284   ld    %r18, 72(%r3)
  285   ld    %r16, 56(%r3)
  286   ld    %r15, 48(%r3)
  287   ld    %r14, 40(%r3)
  288   ld    %r13, 32(%r3)
  289   ld    %r12, 24(%r3)
  290   ld    %r11, 16(%r3)
  291   ld    %r2, 8(%r3)
  292   ld    %r1, 0(%r3)
  293   mtcr  %r12
  294   mtlr  %r11
  295   mr    %r3, %r4
  296   blr
  297 
  298 #elif __aarch64__
  299 
  300 DEFUN(jmp_save)
  301   stp x19, x20, [x0, 0]
  302   stp x21, x22, [x0, 16]
  303   stp x23, x24, [x0, 32]
  304   stp x25, x26, [x0, 48]
  305   stp x27, x28, [x0, 64]
  306   stp x29, x30, [x0, 80]
  307   stp d8, d9, [x0, 96]
  308   stp d10, d11, [x0, 112]
  309   stp d12, d13, [x0, 128]
  310   stp d14, d15, [x0, 144]
  311   mov x16, sp
  312   str x16, [x0, 160]
  313   mov w0, #0
  314   ret
  315 
  316 DEFUN(jmp_restore)
  317   ldp x19, x20, [x0, 0]
  318   ldp x21, x22, [x0, 16]
  319   ldp x23, x24, [x0, 32]
  320   ldp x25, x26, [x0, 48]
  321   ldp x27, x28, [x0, 64]
  322   ldp x29, x30, [x0, 80]
  323   ldp d8, d9, [x0, 96]
  324   ldp d10, d11, [x0, 112]
  325   ldp d12, d13, [x0, 128]
  326   ldp d14, d15, [x0, 144]
  327   ldr x16, [x0, 160]
  328   mov sp, x16
  329   mov w0, w1
  330   br x30
  331 
  332 #else
  333 #error port me!
  334 #endif
  335 
  336 #if !defined(__APPLE__) && !defined(__MINGW32__) && !defined(__CYGWIN__)
  337 /* This is needed so our assembly code doesn't cause
  338    the program to require an executable stack! */
  339 .section .note.GNU-stack,"",SIGIL()progbits
  340 #endif