task_stack_arm64.S raw

   1  #ifdef __MACH__
   2  .global  _moxie_startTask
   3  _moxie_startTask:
   4  #else
   5  .global  moxie_startTask
   6  moxie_startTask:
   7  #endif
   8      .cfi_startproc
   9      // Small assembly stub for starting a goroutine. This is already run on the
  10      // new stack, with the callee-saved registers already loaded.
  11      // Most importantly, x19 contains the pc of the to-be-started function and
  12      // x20 contains the only argument it is given. Multiple arguments are packed
  13      // into one by storing them in a new allocation.
  14  
  15      // Indicate to the unwinder that there is nothing to unwind, this is the
  16      // root frame. It avoids the following (bogus) error message in GDB:
  17      //     Backtrace stopped: previous frame identical to this frame (corrupt stack?)
  18      .cfi_undefined lr
  19  
  20      // Set the first argument of the goroutine start wrapper, which contains all
  21      // the arguments.
  22      mov   x0, x20
  23  
  24      // Branch to the "goroutine start" function. By using blx instead of bx,
  25      // we'll return here instead of tail calling.
  26      blr   x19
  27  
  28      // After return, exit this goroutine. This is a tail call.
  29  #ifdef __MACH__
  30      b     _moxie_task_exit
  31  #else
  32      b     moxie_task_exit
  33  #endif
  34      .cfi_endproc
  35  #ifndef __MACH__
  36  #endif
  37  
  38  
  39  #ifdef __MACH__
  40  .global _moxie_swapTask
  41  _moxie_swapTask:
  42  #else
  43  .global moxie_swapTask
  44  moxie_swapTask:
  45  #endif
  46      // This function gets the following parameters:
  47      // x0 = newStack uintptr
  48      // x1 = oldStack *uintptr
  49  
  50      // Save all callee-saved registers:
  51      stp     x19, x20, [sp, #-160]!
  52      stp     x21, x22, [sp, #16]
  53      stp     x23, x24, [sp, #32]
  54      stp     x25, x26, [sp, #48]
  55      stp     x27, x28, [sp, #64]
  56      stp     x29, x30, [sp, #80]
  57      stp     d8,  d9,  [sp, #96]
  58      stp     d10, d11, [sp, #112]
  59      stp     d12, d13, [sp, #128]
  60      stp     d14, d15, [sp, #144]
  61  
  62      // Save the current stack pointer in oldStack.
  63      mov x8, sp
  64      str x8, [x1]
  65  
  66      // Switch to the new stack pointer.
  67      mov sp, x0
  68  
  69      // Restore stack state and return.
  70      ldp     d14, d15, [sp, #144]
  71      ldp     d12, d13, [sp, #128]
  72      ldp     d10, d11, [sp, #112]
  73      ldp     d8, d9, [sp, #96]
  74      ldp     x29, x30, [sp, #80]
  75      ldp     x27, x28, [sp, #64]
  76      ldp     x25, x26, [sp, #48]
  77      ldp     x23, x24, [sp, #32]
  78      ldp     x21, x22, [sp, #16]
  79      ldp     x19, x20, [sp], #160
  80      ret
  81