Bootloader changes for ca1

trunk
alexis 2022-05-28 17:33:03 -06:00
parent c39f6599e2
commit e442d0e267
7 changed files with 60 additions and 35 deletions

View File

@ -1,23 +1,23 @@
#include "board.h"
.global boot68010
.type boot68010, function
boot68010: // boot68010(vbr, ssp, pc)
.section .start,"ax",@progbits
.global boot_trap1
.type boot_trap1, function
boot_trap1: // a0=vbr, a1=ssp, a2=pc
move.w #0x2700, %sr
move.l 4(%sp), %a0 // vbr
movec.l %a0, %vbr
// fall through
.global boot
.type boot, function
boot: // boot(vbr, ssp, pc)
.global boot_trap0
.type boot_trap0, function
boot_trap0: // a1=ssp, a2=pc
move.w #0x2700, %sr
move.l 12(%sp), %a0 // pc
move.l 8(%sp), %a1 // sp
#if !NO_RESET_ON_BOOT
reset
#endif
#if HAS_BOOT_INC
# include "boot.inc"
#endif
move.l %a1, %sp
move.l %a1, %usp
jmp (%a0)
jmp (%a2)

View File

@ -7,19 +7,31 @@
#include <stddef.h>
#include <inttypes.h>
// Boot into a new location. Reinitializes everything just like the CPU does
__attribute__((noreturn)) void boot(
uintptr_t vbr,
uintptr_t ssp,
uintptr_t pc
);
// Because a6boot can optionally run in user mode, we have to get supervisor
// mode back before booting the user application. Do this by using traps to
// perform the boot.
// Boot into a new location, also moving the vector base register. Required
// for 68010, will crash a 68000! Make sure to check the CPU identity.
__attribute__((noreturn)) void boot68010(
uintptr_t vbr,
uintptr_t ssp,
uintptr_t pc
);
static inline __attribute__((noreturn)) void
boot(uintptr_t vbr, uintptr_t ssp, uintptr_t pc)
{
(void) vbr;
register uintptr_t a1_ssp asm("a1") = ssp;
register uintptr_t a2_pc asm("a2") = pc;
asm volatile("trap #0" :: "r"(a1_ssp), "r"(a2_pc));
__builtin_unreachable();
}
static inline __attribute__((noreturn)) void
boot68010(uintptr_t vbr, uintptr_t ssp, uintptr_t pc)
{
register uintptr_t a0_vbr asm("a0") = vbr;
register uintptr_t a1_ssp asm("a1") = ssp;
register uintptr_t a2_pc asm("a2") = pc;
asm volatile("trap #1" :: "r"(a0_vbr), "r"(a1_ssp), "r"(a2_pc));
__builtin_unreachable();
}
void boot_trap0(void);
void boot_trap1(void);
#endif // !defined(BOOT_H)

View File

@ -24,7 +24,23 @@ enum m68k_vec {
ZDIV_ERROR,
CHK_ERROR,
TRAPV_ERROR,
PRIV_ERROR
PRIV_ERROR,
TRAP0 = 32,
TRAP1,
TRAP2,
TRAP3,
TRAP4,
TRAP5,
TRAP6,
TRAP7,
TRAP8,
TRAP9,
TRAP10,
TRAP11,
TRAP12,
TRAP13,
TRAP14,
TRAP15,
};
// Last exception that occurred. User must clear.

View File

@ -169,6 +169,9 @@ int main(void)
for (uint8_t i = 4; i != 0; i++)
vectab[i] = &unexp_vec;
vectab[TRAP0] = boot_trap0;
vectab[TRAP1] = boot_trap1;
if (!_entry_prompt())
_boot(BOOT_APPLICATION, 0, 0);

View File

@ -42,11 +42,14 @@
// the vector table writable.
#define RUN_AS_USER 1
// Whether the bootloader should not perform a peripheral reset when it boots
// the application.
#define NO_RESET_ON_BOOT 1
// Whether certain commands should be included
#define HAS_DEVICES 0
#define HAS_PEEK 1
#define HAS_POKE 1
#define HAS_REBOOT 1 // Board package must define a reboot() function!
#ifndef __ASSEMBLER__

View File

@ -1,4 +1,4 @@
board_sources = files('board.c', 'reboot.S')
board_sources = files('board.c')
board_depends = files('startup_pre.inc', 'boot.inc')
a6boot_always_cpu = '68000'

View File

@ -1,9 +0,0 @@
#include "board.h"
.global reboot
.type reboot,function
reboot:
move.l #__stack_top, %a0
move.l %a0, %usp
move.l %a0, %ssp
jmp start