Disable interrupts before jumping to scratch ROM

This commit is contained in:
Jeremy Soller
2020-02-04 09:44:50 -07:00
parent c50632c1bf
commit 81084066df
3 changed files with 86 additions and 103 deletions

View File

@ -27,32 +27,29 @@ static void scratch_start(void) __naked {
// Enter or exit scratch ROM
void scratch_trampoline(void) {
// Uses SCAR0 which is mapped at 0x0000 in data space and are
// Uses SCAR0 which is mapped at 0x0000 in data space and are
// 4096 bytes in size.
//TODO: ensure pdata is not used!
// Disable interrupts
EA = 0;
if (SCAR0H == 0x00) {
// Disable scratch RAM mapping
SCAR0H = 0b11;
} else {
int __data i;
// Copy scratch ROM
for (i = 0; i < ARRAY_SIZE(scratch_rom) && i < ARRAY_SIZE(scratch_ram); i++) {
scratch_ram[i] = scratch_rom[i];
}
// Fill the rest with nop
for (; i < ARRAY_SIZE(scratch_ram); i++) {
scratch_ram[i] = 0x00;
}
// Set scratch RAM 0 mapping at 0x0000 and enable
SCAR0L = 0x00;
SCAR0M = 0x00;
SCAR0H = 0x00;
// Ensure pdata is not used!
int __data i;
// Copy scratch ROM
for (i = 0; i < ARRAY_SIZE(scratch_rom) && i < ARRAY_SIZE(scratch_ram); i++) {
scratch_ram[i] = scratch_rom[i];
}
// Fill the rest with nop
for (; i < ARRAY_SIZE(scratch_ram); i++) {
scratch_ram[i] = 0x00;
}
// Set scratch RAM 0 mapping at 0x0000 and enable
SCAR0L = 0x00;
SCAR0M = 0x00;
SCAR0H = 0x00;
// Jump to reset function
__asm__("ljmp 0");
}