github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/device/esp/esp32.S (about)

     1  
     2  // The following definitions were copied from:
     3  // esp-idf/components/xtensa/include/xtensa/corebits.h
     4  #define PS_WOE_MASK                0x00040000
     5  #define PS_OWB_MASK                0x00000F00
     6  #define PS_CALLINC_MASK            0x00030000
     7  #define PS_WOE                     PS_WOE_MASK
     8  
     9  // Only calling it call_start_cpu0 for consistency with ESP-IDF.
    10  .section .text.call_start_cpu0
    11  1:
    12      .long _stack_top
    13  .global call_start_cpu0
    14  call_start_cpu0:
    15      // We need to set the stack pointer to a different value. This is somewhat
    16      // complicated in the Xtensa architecture. The code below is a modified
    17      // version of the following code:
    18      // https://github.com/espressif/esp-idf/blob/c77c4ccf/components/xtensa/include/xt_instr_macros.h#L47
    19  
    20      // Disable WOE.
    21      rsr.ps a2
    22      movi a3, ~(PS_WOE_MASK)
    23      and a2, a2, a3
    24      wsr.ps a2
    25      rsync
    26  
    27      // Set WINDOWSTART to 1 << WINDOWBASE.
    28      rsr.windowbase  a2
    29      ssl  a2
    30      movi a2, 1
    31      sll  a2, a2
    32      wsr.windowstart a2
    33      rsync
    34  
    35      // Load new stack pointer.
    36      l32r sp, 1b
    37  
    38      // Re-enable WOE.
    39      rsr.ps a2
    40      movi a3, PS_WOE
    41      or a2, a2, a3
    42      wsr.ps a2
    43      rsync
    44  
    45      // Enable the FPU (coprocessor 0 so the lowest bit).
    46      movi a2, 1
    47      wsr.cpenable a2
    48      rsync
    49  
    50      // Jump to the runtime start function written in Go.
    51      call4 main
    52  
    53  .section .text.tinygo_scanCurrentStack
    54  .global tinygo_scanCurrentStack
    55  tinygo_scanCurrentStack:
    56      // TODO: save callee saved registers on the stack
    57      j tinygo_scanstack