SummerCart64/fw/cpu/bootloader/main.c

41 lines
852 B
C
Raw Normal View History

2021-08-23 22:30:47 +02:00
#include "sys.h"
2021-08-05 19:50:29 +02:00
2021-08-12 21:07:47 +02:00
int reset_handler (void) {
2021-08-23 21:40:37 +02:00
#ifdef BOOT_UART
2021-08-12 21:07:47 +02:00
io8_t pointer = &RAM;
2021-08-23 21:40:37 +02:00
#else
#ifdef BOOT_N64
io32_t pointer = &RAM;
#endif
#endif
2021-08-18 13:54:07 +02:00
uint32_t length = 0;
2021-08-12 21:07:47 +02:00
2021-08-23 21:40:37 +02:00
#ifdef BOOT_UART
2021-08-18 13:54:07 +02:00
for (int i = 0; i < 4; i++) {
2021-08-23 21:40:37 +02:00
while (!(UART_SR & UART_SR_RXNE));
length |= (UART_DR << (i * 8));
2021-08-18 13:54:07 +02:00
}
2021-08-23 21:40:37 +02:00
#else
#ifdef BOOT_N64
while (!(CFG_SCR & CFG_SCR_BOOTSTRAP_PENDING));
length = CFG_BOOTSTRAP;
#endif
#endif
2021-08-18 13:54:07 +02:00
2021-08-05 19:50:29 +02:00
while (1) {
2021-08-23 21:40:37 +02:00
#ifdef BOOT_UART
while (!(UART_SR & UART_SR_RXNE));
*pointer++ = UART_DR;
#else
#ifdef BOOT_N64
while (!(CFG_SCR & CFG_SCR_BOOTSTRAP_PENDING));
*pointer++ = CFG_BOOTSTRAP;
#endif
#endif
if (((uint32_t) pointer) == length) {
CFG_SCR |= CFG_SCR_CPU_BOOTSTRAPPED;
2021-08-12 21:07:47 +02:00
__asm__("call 0");
2021-08-05 19:50:29 +02:00
}
}
}