|
| 1 | +// This is a very minimal bootloader for the ESP32-C6. It only initializes the |
| 2 | +// flash and then continues with the generic RISC-V initialization code, which |
| 3 | +// in turn will call runtime.main. |
| 4 | +// It is written in assembly (and not in a higher level language) to make sure |
| 5 | +// it is entirely loaded into IRAM and doesn't accidentally call functions |
| 6 | +// stored in IROM. |
| 7 | +// |
| 8 | +// The ESP32-C6 has a unified IRAM/DRAM address space at 0x40800000, and |
| 9 | +// separate DROM (0x42800000) / IROM (0x42000000) flash-mapped regions. |
| 10 | + |
| 11 | +.section .init |
| 12 | +.global call_start_cpu0 |
| 13 | +.type call_start_cpu0,@function |
| 14 | +call_start_cpu0: |
| 15 | + // At this point: |
| 16 | + // - The ROM bootloader is finished and has jumped to here. |
| 17 | + // - We're running from IRAM: both IRAM and DRAM segments have been loaded |
| 18 | + // by the ROM bootloader. |
| 19 | + // - We have a usable stack (but not the one we would like to use). |
| 20 | + // - No flash mappings (MMU) are set up yet. |
| 21 | + |
| 22 | + // Reset MMU, see bootloader_reset_mmu in the ESP-IDF. |
| 23 | + call Cache_Suspend_ICache |
| 24 | + mv s0, a0 // autoload value |
| 25 | + call Cache_Invalidate_ICache_All |
| 26 | + call Cache_MMU_Init |
| 27 | + |
| 28 | + // Set up flash mapping (both IROM and DROM). |
| 29 | + // On ESP32-C6, Cache_Dbus_MMU_Set is replaced by Cache_MSPI_MMU_Set |
| 30 | + // which has an extra "sensitive" parameter. |
| 31 | + // C equivalent: |
| 32 | + // Cache_MSPI_MMU_Set(0, 0, 0x42000000, 0, 64, 256, 0) |
| 33 | + // Maps 16MB starting at 0x42000000, covering both IROM and DROM. |
| 34 | + li a0, 0 // sensitive: no flash encryption |
| 35 | + li a1, 0 // ext_ram: MMU_ACCESS_FLASH |
| 36 | + li a2, 0x42000000 // vaddr: start of flash-mapped region |
| 37 | + li a3, 0 // paddr: physical address in the flash chip |
| 38 | + li a4, 64 // psize: always 64 (kilobytes) |
| 39 | + li a5, 256 // num: pages (16MB / 64K = 256, covers IROM+DROM) |
| 40 | + li a6, 0 // fixed |
| 41 | + call Cache_MSPI_MMU_Set |
| 42 | + |
| 43 | + // Enable the flash cache. |
| 44 | + mv a0, s0 // restore autoload value from Cache_Suspend_ICache call |
| 45 | + call Cache_Resume_ICache |
| 46 | + |
| 47 | + // Jump to generic RISC-V initialization, which initializes the stack |
| 48 | + // pointer and globals register. It should not return. |
| 49 | + j _start |
| 50 | + |
| 51 | +.section .text.exception_vectors |
| 52 | +.global _vector_table |
| 53 | +.type _vector_table,@function |
| 54 | + |
| 55 | +_vector_table: |
| 56 | + |
| 57 | + .option push |
| 58 | + .option norvc |
| 59 | + |
| 60 | + .rept 32 |
| 61 | + j handleInterruptASM /* interrupt handler */ |
| 62 | + .endr |
| 63 | + |
| 64 | + .option pop |
| 65 | + |
| 66 | +.size _vector_table, .-_vector_table |
0 commit comments