2020-10-08 02:04:42 +02:00
|
|
|
#include "boot.h"
|
2023-12-14 19:26:54 +01:00
|
|
|
#include "cic.h"
|
|
|
|
#include "init.h"
|
[SC64][FW][HW][SW] New version based on LCMXO2 FPGA (#19)
* isv support + usb/dd improvements
* make room for saves
* update offset
* fixed debug address
* idk
* exception
* ironed out all broken stuff
* cleanup
* return epc fix
* better
* more cleanup
* even more cleanup
* mooore cleanup
* fixed printf
* no assert
* improved docker build, pyft232 instead of pyserial
* fixed displaying long message strings
description test
* just straight cleanup
* smallest cleanup
* PAL
* cpu buffer
* n64 bootloader done
* super slow usb storage reading implemented
* reduced buffer size
* usb gets fast
* little cleanup
* double buffered reads
* removed separate event id
* ISV in hardware finally
* small exception changes
* mac testing
* py spacing
* fsd write, rtc, isv and reset fixes
* fixxx
* good stopping point
* usb fixed?
* pretend we have 128 MB sdram
* backup
* chmod
* test
* test done
* more tests
* user rm
* help
* final fix
* updated component values
* nice asset names
* cic 64dd support
* ddipl enable separation
* pre DMA rewrite, created dedicated buffer memory space, simplified code
* dma rewrite, needs testing
* moved xml
* dd basics
* timing
* 64dd working yet again, isv brought back, dma fixes, usb path rewrite, pc code rewrite
* added usb read functionality, general cleanup
* changed mem addressing
* added fpga flash update access
* added mcu update
* chmod
* little cleanup
* update format and stuff
* fixes
* uninitialized fix
* small fixes
* update fixes
* update stuff done
* fpga update tested
* build time fix
* boot fix
* test timing
* readme test
* test 2
* reports
* testseet
* final
* build test
* forgot
* button and naming
* General cleanup
And multiline commit message test
* Exception screen UI touch ups
* display separation and tests beginning
* pc software update
* pc software done
* timing test
* delete launch.json
* sw fixes
* fixed button hole diameter in shell
* small cleanup, rpi testing
* shell fillet fix, pc rtc printing
* added cfg lock mechanism
* moved lock to cfg address space
* extended ROM and ISV fixes
* preliminary sd card support
* little sd card cleanup
* sd menu fixes
* 5 second limit
* reduced shell thickness
* basic led act blinking
* faster sd menu loading
* inst cache invalidate
* sd card writing is working
* SD card CSD and CID registers
* wait for previous command
* led error codes
* fixed cfg_translate_address use
* 64dd from sd card working
* 64dd speedup and button handling
* delayed address latching cycle - might break other builds, needs testing
* bootloader improvements
* small fixes
* return previous cfg when setting new
* cache stuff
* unfloader debug protocol support
* UNFLoader style debug command line support
* requirements.txt
* shell groove fillet
* reset state inside controller
* fixed fast PI read, added PI R/W fifo debug info
* PI access prioritize
* SD clock stop when RX FIFO is more than half full
* flash erase method change
* CFG error handling, TLOZ MM debug ISV support
* CIC5167 support
* general fixes
* USB unplugged cable handling
* turn off led when changing between error/act modes
* rtc 2 bit clock stop support
* line endings
* Revert "line endings"
This reverts commit d0ddfe5ec716d2db7c72561703f51a94bf34e6bb.
* PI address debug
* readme test
* diagram update
* diagram background
* diagram background
* diagram background
* updated readme
2022-11-10 11:46:54 +01:00
|
|
|
#include "io.h"
|
2023-02-19 15:50:57 +01:00
|
|
|
#include "vr4300.h"
|
2021-12-10 17:36:30 +01:00
|
|
|
|
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
extern uint32_t reboot_start __attribute__((section(".text")));
|
|
|
|
extern size_t reboot_size __attribute__((section(".text")));
|
2021-12-10 17:36:30 +01:00
|
|
|
|
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
static io32_t *boot_get_device_base (boot_params_t *params) {
|
2021-12-10 17:36:30 +01:00
|
|
|
io32_t *device_base_address = ROM_CART;
|
2023-09-15 20:51:57 +02:00
|
|
|
if (params->device_type == BOOT_DEVICE_TYPE_64DD) {
|
2021-12-10 17:36:30 +01:00
|
|
|
device_base_address = ROM_DDIPL;
|
|
|
|
}
|
|
|
|
return device_base_address;
|
2020-10-08 02:04:42 +02:00
|
|
|
}
|
|
|
|
|
2023-12-14 19:26:54 +01:00
|
|
|
static void boot_detect_cic_seed (boot_params_t *params) {
|
2023-09-15 20:51:57 +02:00
|
|
|
io32_t *base = boot_get_device_base(params);
|
2020-10-08 02:04:42 +02:00
|
|
|
|
2023-12-14 19:26:54 +01:00
|
|
|
uint8_t ipl3[IPL3_LENGTH] __attribute__((aligned(8)));
|
2020-10-08 02:04:42 +02:00
|
|
|
|
[SC64][FW][HW][SW] New version based on LCMXO2 FPGA (#19)
* isv support + usb/dd improvements
* make room for saves
* update offset
* fixed debug address
* idk
* exception
* ironed out all broken stuff
* cleanup
* return epc fix
* better
* more cleanup
* even more cleanup
* mooore cleanup
* fixed printf
* no assert
* improved docker build, pyft232 instead of pyserial
* fixed displaying long message strings
description test
* just straight cleanup
* smallest cleanup
* PAL
* cpu buffer
* n64 bootloader done
* super slow usb storage reading implemented
* reduced buffer size
* usb gets fast
* little cleanup
* double buffered reads
* removed separate event id
* ISV in hardware finally
* small exception changes
* mac testing
* py spacing
* fsd write, rtc, isv and reset fixes
* fixxx
* good stopping point
* usb fixed?
* pretend we have 128 MB sdram
* backup
* chmod
* test
* test done
* more tests
* user rm
* help
* final fix
* updated component values
* nice asset names
* cic 64dd support
* ddipl enable separation
* pre DMA rewrite, created dedicated buffer memory space, simplified code
* dma rewrite, needs testing
* moved xml
* dd basics
* timing
* 64dd working yet again, isv brought back, dma fixes, usb path rewrite, pc code rewrite
* added usb read functionality, general cleanup
* changed mem addressing
* added fpga flash update access
* added mcu update
* chmod
* little cleanup
* update format and stuff
* fixes
* uninitialized fix
* small fixes
* update fixes
* update stuff done
* fpga update tested
* build time fix
* boot fix
* test timing
* readme test
* test 2
* reports
* testseet
* final
* build test
* forgot
* button and naming
* General cleanup
And multiline commit message test
* Exception screen UI touch ups
* display separation and tests beginning
* pc software update
* pc software done
* timing test
* delete launch.json
* sw fixes
* fixed button hole diameter in shell
* small cleanup, rpi testing
* shell fillet fix, pc rtc printing
* added cfg lock mechanism
* moved lock to cfg address space
* extended ROM and ISV fixes
* preliminary sd card support
* little sd card cleanup
* sd menu fixes
* 5 second limit
* reduced shell thickness
* basic led act blinking
* faster sd menu loading
* inst cache invalidate
* sd card writing is working
* SD card CSD and CID registers
* wait for previous command
* led error codes
* fixed cfg_translate_address use
* 64dd from sd card working
* 64dd speedup and button handling
* delayed address latching cycle - might break other builds, needs testing
* bootloader improvements
* small fixes
* return previous cfg when setting new
* cache stuff
* unfloader debug protocol support
* UNFLoader style debug command line support
* requirements.txt
* shell groove fillet
* reset state inside controller
* fixed fast PI read, added PI R/W fifo debug info
* PI access prioritize
* SD clock stop when RX FIFO is more than half full
* flash erase method change
* CFG error handling, TLOZ MM debug ISV support
* CIC5167 support
* general fixes
* USB unplugged cable handling
* turn off led when changing between error/act modes
* rtc 2 bit clock stop support
* line endings
* Revert "line endings"
This reverts commit d0ddfe5ec716d2db7c72561703f51a94bf34e6bb.
* PI address debug
* readme test
* diagram update
* diagram background
* diagram background
* diagram background
* updated readme
2022-11-10 11:46:54 +01:00
|
|
|
pi_dma_read(&base[16], ipl3, sizeof(ipl3));
|
2020-10-08 02:04:42 +02:00
|
|
|
|
2023-12-14 19:26:54 +01:00
|
|
|
params->cic_seed = cic_get_seed(cic_detect(ipl3));
|
2021-12-10 17:36:30 +01:00
|
|
|
}
|
2020-10-08 02:04:42 +02:00
|
|
|
|
2023-12-14 19:26:54 +01:00
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
void boot (boot_params_t *params) {
|
|
|
|
if (params->tv_type == BOOT_TV_TYPE_PASSTHROUGH) {
|
2023-12-14 19:26:54 +01:00
|
|
|
switch (__tv_type) {
|
|
|
|
case INIT_TV_TYPE_PAL:
|
|
|
|
params->tv_type = BOOT_TV_TYPE_PAL;
|
|
|
|
break;
|
|
|
|
case INIT_TV_TYPE_NTSC:
|
|
|
|
params->tv_type = BOOT_TV_TYPE_NTSC;
|
|
|
|
break;
|
|
|
|
case INIT_TV_TYPE_MPAL:
|
|
|
|
params->tv_type = BOOT_TV_TYPE_MPAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
params->tv_type = BOOT_TV_TYPE_NTSC;
|
|
|
|
break;
|
|
|
|
}
|
2023-02-02 19:03:01 +01:00
|
|
|
}
|
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
if (params->detect_cic_seed) {
|
2023-12-14 19:26:54 +01:00
|
|
|
boot_detect_cic_seed(params);
|
2023-02-02 19:03:01 +01:00
|
|
|
}
|
|
|
|
|
2023-02-19 15:50:57 +01:00
|
|
|
asm volatile (
|
|
|
|
"li $t1, %[status] \n"
|
|
|
|
"mtc0 $t1, $12 \n" ::
|
|
|
|
[status] "i" (C0_SR_CU1 | C0_SR_CU0 | C0_SR_FR)
|
|
|
|
);
|
|
|
|
|
2023-02-02 19:03:01 +01:00
|
|
|
while (!(cpu_io_read(&SP->SR) & SP_SR_HALT));
|
2021-12-10 17:36:30 +01:00
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
cpu_io_write(&SP->SR,
|
|
|
|
SP_SR_CLR_SIG7 |
|
|
|
|
SP_SR_CLR_SIG6 |
|
|
|
|
SP_SR_CLR_SIG5 |
|
|
|
|
SP_SR_CLR_SIG4 |
|
|
|
|
SP_SR_CLR_SIG3 |
|
|
|
|
SP_SR_CLR_SIG2 |
|
|
|
|
SP_SR_CLR_SIG1 |
|
|
|
|
SP_SR_CLR_SIG0 |
|
|
|
|
SP_SR_CLR_INTR_BREAK |
|
|
|
|
SP_SR_CLR_SSTEP |
|
|
|
|
SP_SR_CLR_INTR |
|
|
|
|
SP_SR_CLR_BROKE |
|
|
|
|
SP_SR_SET_HALT
|
|
|
|
);
|
|
|
|
cpu_io_write(&SP->SEMAPHORE, 0);
|
|
|
|
cpu_io_write(&SP->PC, 0);
|
2020-10-08 02:04:42 +02:00
|
|
|
|
2023-02-02 19:03:01 +01:00
|
|
|
while (cpu_io_read(&SP->DMA_BUSY));
|
2020-10-08 02:04:42 +02:00
|
|
|
|
2023-02-02 19:03:01 +01:00
|
|
|
cpu_io_write(&PI->SR, PI_SR_CLR_INTR | PI_SR_RESET);
|
2023-09-15 20:51:57 +02:00
|
|
|
while ((cpu_io_read(&VI->CURR_LINE) & ~(VI_CURR_LINE_FIELD)) != 0);
|
2023-02-02 19:03:01 +01:00
|
|
|
cpu_io_write(&VI->V_INTR, 0x3FF);
|
|
|
|
cpu_io_write(&VI->H_LIMITS, 0);
|
|
|
|
cpu_io_write(&VI->CURR_LINE, 0);
|
|
|
|
cpu_io_write(&AI->MADDR, 0);
|
|
|
|
cpu_io_write(&AI->LEN, 0);
|
2020-10-08 02:04:42 +02:00
|
|
|
|
2023-02-19 15:50:57 +01:00
|
|
|
while (cpu_io_read(&SP->SR) & SP_SR_DMA_BUSY);
|
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
uint32_t *reboot_src = &reboot_start;
|
|
|
|
io32_t *reboot_dst = SP_MEM->IMEM;
|
|
|
|
size_t reboot_instructions = (size_t) (&reboot_size) / sizeof(uint32_t);
|
2023-02-19 15:50:57 +01:00
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
for (int i = 0; i < reboot_instructions; i++) {
|
|
|
|
cpu_io_write(&reboot_dst[i], reboot_src[i]);
|
2023-02-19 15:50:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cpu_io_write(&PI->DOM[0].LAT, 0xFF);
|
|
|
|
cpu_io_write(&PI->DOM[0].PWD, 0xFF);
|
|
|
|
cpu_io_write(&PI->DOM[0].PGS, 0x0F);
|
|
|
|
cpu_io_write(&PI->DOM[0].RLS, 0x03);
|
2021-12-10 17:36:30 +01:00
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
io32_t *base = boot_get_device_base(params);
|
2021-12-10 17:36:30 +01:00
|
|
|
uint32_t pi_config = pi_io_read(base);
|
|
|
|
|
2023-02-02 19:03:01 +01:00
|
|
|
cpu_io_write(&PI->DOM[0].LAT, pi_config & 0xFF);
|
|
|
|
cpu_io_write(&PI->DOM[0].PWD, pi_config >> 8);
|
|
|
|
cpu_io_write(&PI->DOM[0].PGS, pi_config >> 16);
|
|
|
|
cpu_io_write(&PI->DOM[0].RLS, pi_config >> 20);
|
2021-12-10 17:36:30 +01:00
|
|
|
|
2023-02-02 19:03:01 +01:00
|
|
|
if (cpu_io_read(&DPC->SR) & DPC_SR_XBUS_DMEM_DMA) {
|
|
|
|
while (cpu_io_read(&DPC->SR) & DPC_SR_PIPE_BUSY);
|
2020-10-08 21:50:46 +02:00
|
|
|
}
|
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
io32_t *ipl3_src = base;
|
|
|
|
io32_t *ipl3_dst = SP_MEM->DMEM;
|
|
|
|
|
|
|
|
for (int i = 16; i < 1024; i++) {
|
2023-02-02 19:03:01 +01:00
|
|
|
cpu_io_write(&ipl3_dst[i], pi_io_read(&ipl3_src[i]));
|
2020-10-08 02:04:42 +02:00
|
|
|
}
|
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
register uint32_t boot_device asm ("s3");
|
|
|
|
register uint32_t tv_type asm ("s4");
|
|
|
|
register uint32_t reset_type asm ("s5");
|
|
|
|
register uint32_t cic_seed asm ("s6");
|
|
|
|
register uint32_t version asm ("s7");
|
|
|
|
|
2023-09-15 20:51:57 +02:00
|
|
|
boot_device = (params->device_type & 0x01);
|
|
|
|
tv_type = (params->tv_type & 0x03);
|
|
|
|
reset_type = (params->reset_type & 0x01);
|
|
|
|
cic_seed = (params->cic_seed & 0xFF);
|
|
|
|
version = (params->tv_type == BOOT_TV_TYPE_PAL) ? 6
|
|
|
|
: (params->tv_type == BOOT_TV_TYPE_NTSC) ? 1
|
|
|
|
: (params->tv_type == BOOT_TV_TYPE_MPAL) ? 4
|
|
|
|
: 0;
|
2021-12-10 17:36:30 +01:00
|
|
|
|
|
|
|
asm volatile (
|
2023-09-15 20:51:57 +02:00
|
|
|
"la $t3, reboot \n"
|
|
|
|
"jr $t3 \n" ::
|
2021-12-10 17:36:30 +01:00
|
|
|
[boot_device] "r" (boot_device),
|
|
|
|
[tv_type] "r" (tv_type),
|
|
|
|
[reset_type] "r" (reset_type),
|
|
|
|
[cic_seed] "r" (cic_seed),
|
2023-09-15 20:51:57 +02:00
|
|
|
[version] "r" (version) :
|
|
|
|
"t3"
|
2020-10-08 02:04:42 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
while (1);
|
|
|
|
}
|