diff options
author | Ayke van Laethem <[email protected]> | 2020-08-06 23:28:45 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-08-31 09:02:23 +0200 |
commit | 3ee47a9c1b0787e567d7af0f661cf02b8b5d5aed (patch) | |
tree | a8447560da0c9059b5e163d1668b52996e9c4da6 /src/device | |
parent | da7db81087d8326c887391b58794d3bea1cae6bc (diff) | |
download | tinygo-3ee47a9c1b0787e567d7af0f661cf02b8b5d5aed.tar.gz tinygo-3ee47a9c1b0787e567d7af0f661cf02b8b5d5aed.zip |
esp: add support for the Espressif ESP32 chip
This is only very minimal support. More support (such as tinygo flash,
or peripheral access) should be added in later commits, to keep this one
focused.
Importantly, this commit changes the LLVM repo from llvm/llvm-project to
tinygo-org/llvm-project. This provides a little bit of versioning in
case something changes in the Espressif fork. If we want to upgrade to
LLVM 11 it's easy to switch back to llvm/llvm-project until Espressif
has updated their fork.
Diffstat (limited to 'src/device')
-rw-r--r-- | src/device/esp/esp32.S | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/device/esp/esp32.S b/src/device/esp/esp32.S new file mode 100644 index 000000000..af8e9d664 --- /dev/null +++ b/src/device/esp/esp32.S @@ -0,0 +1,52 @@ + +// The following definitions were copied from: +// esp-idf/components/xtensa/include/xtensa/corebits.h +#define PS_WOE_MASK 0x00040000 +#define PS_OWB_MASK 0x00000F00 +#define PS_CALLINC_MASK 0x00030000 +#define PS_WOE PS_WOE_MASK + +// Only calling it call_start_cpu0 for consistency with ESP-IDF. +.section .text.call_start_cpu0 +1: + .long _stack_top +.global call_start_cpu0 +call_start_cpu0: + // We need to set the stack pointer to a different value. This is somewhat + // complicated in the Xtensa architecture. The code below is a modified + // version of the following code: + // https://github.com/espressif/esp-idf/blob/c77c4ccf/components/xtensa/include/xt_instr_macros.h#L47 + + // Disable WOE. + rsr.ps a2 + movi a3, ~(PS_WOE_MASK) + and a2, a2, a3 + wsr.ps a2 + rsync + + // Set WINDOWBASE to 1 << WINDOWSTART. + rsr.windowbase a2 + ssl a2 + movi a2, 1 + sll a2, a2 + wsr.windowstart a2 + rsync + + // Load new stack pointer. + l32r sp, 1b + + // Re-enable WOE. + rsr.ps a2 + movi a3, PS_WOE + or a2, a2, a3 + wsr.ps a2 + rsync + + // Jump to the runtime start function written in Go. + j main + +.section .text.tinygo_scanCurrentStack +.global tinygo_scanCurrentStack +tinygo_scanCurrentStack: + // TODO: save callee saved registers on the stack + j tinygo_scanstack |