From 3050dfa116f245d2b254199c086c8a47d67d51e7 Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Fri, 8 Dec 2023 21:22:19 +0100 Subject: [PATCH] minor bootloader tweaks --- sw/bootloader/Makefile | 7 ++-- sw/bootloader/N64.ld | 7 +++- sw/bootloader/src/exception.S | 63 +++++++++++------------------------ sw/bootloader/src/exception.h | 1 - sw/bootloader/src/init.c | 2 -- 5 files changed, 29 insertions(+), 51 deletions(-) diff --git a/sw/bootloader/Makefile b/sw/bootloader/Makefile index 74087ff..6f9db41 100644 --- a/sw/bootloader/Makefile +++ b/sw/bootloader/Makefile @@ -81,9 +81,10 @@ $(BUILD_DIR)/bootloader.elf: $(OBJS) N64.ld @$(OBJDUMP) -S $@ > $(BUILD_DIR)/bootloader.lst $(BUILD_DIR)/bootloader.bin: $(BUILD_DIR)/bootloader.elf - @$(STRIP) -s $< - @$(N64_ELFCOMPRESS) -c 2 -o $(dir $<) $< - @$(N64_TOOL) --title "SC64 bootloader" --output $@ --align 256 $< + @cp $< $<.stripped + @$(STRIP) -s $<.stripped + @$(N64_ELFCOMPRESS) -c 2 -o $(dir $<) $<.stripped + @$(N64_TOOL) --title "SC64 bootloader" --output $@ --align 256 $<.stripped all: $(BUILD_DIR)/bootloader.bin diff --git a/sw/bootloader/N64.ld b/sw/bootloader/N64.ld index 802a781..f96acc1 100644 --- a/sw/bootloader/N64.ld +++ b/sw/bootloader/N64.ld @@ -1,6 +1,7 @@ MEMORY { + exception (rx) : org = 0x80000000, len = 0x400 ram (rwx) : org = 0x80000400, len = 1M - framebuffer (rw) : org = 0x8026A000, len = 600k + framebuffer (rw) : org = 0x8016A000, len = 600k } ENTRY(entry_handler) @@ -9,6 +10,10 @@ __exception_stack_size = 8k; __stack_size = 16k; SECTIONS { + .exception : { + KEEP(*(.text.exception_vector)); + } > exception + .text : SUBALIGN(8) { *(.text.entry_handler) *(.text .text.* .gnu.linkonce.t.*) diff --git a/sw/bootloader/src/exception.S b/sw/bootloader/src/exception.S index 7eb580c..048ae30 100644 --- a/sw/bootloader/src/exception.S +++ b/sw/bootloader/src/exception.S @@ -3,10 +3,6 @@ #define WATCHDOG_TIMEOUT (5 * (93750000UL / 2)) -#define VECTOR_LOCATION (0xA0000000UL) -#define VECTOR_SIZE (0x80) -#define VECTOR_NUM (4) - #define ZR_OFFSET (0) #define AT_OFFSET (8) #define V0_OFFSET (16) @@ -46,8 +42,23 @@ #define SAVE_REGISTERS_SIZE (280) +.section .text.exception_vector +exception_tlb_miss: + .org 0x0000 + j exception_handler + +exception_xtlb_miss: + .org 0x0080 + j exception_handler + +exception_other: + .org 0x0180 + j exception_handler + + .section .text.exception_handler exception_handler: + .type exception_handler, %function .set noat la $k0, (_esp - SAVE_REGISTERS_SIZE) sd $zero, ZR_OFFSET($k0) @@ -153,48 +164,9 @@ exception_restore: eret -.section .text.exception_vector -exception_vector: - .set noreorder - la $k0, exception_handler - jalr $k1, $k0 - nop - .equ exception_vector_size, (. - exception_vector) - .set reorder - - -.section .text.exception_install -exception_install: - .global exception_install - la $t0, exception_vector - li $t1, VECTOR_LOCATION - li $t2, (VECTOR_SIZE * VECTOR_NUM) - add $t2, $t2, $t1 -1: - move $t3, $t0 - move $t4, $t1 - li $t5, exception_vector_size - add $t5, $t5, $t4 -2: - lw $t6, 0($t3) - addiu $t3, 4 - sw $t6, 0($t4) - addiu $t4, 4 - bne $t4, $t5, 2b - addiu $t1, VECTOR_SIZE - bne $t1, $t2, 1b - li $t0, VECTOR_LOCATION - li $t1, (VECTOR_SIZE * VECTOR_NUM) - add $t1, $t0, $t1 -3: - cache HIT_INVALIDATE_I, 0($t0) - addiu $t0, CACHE_LINE_SIZE_I - bne $t0, $t1, 3b - jr $ra - - .section .text.exception_enable_interrupts exception_enable_interrupts: + .type exception_enable_interrupts, %function .global exception_enable_interrupts mfc0 $t0, C0_STATUS li $t1, C0_SR_IE @@ -205,6 +177,7 @@ exception_enable_interrupts: .section .text.exception_disable_interrupts exception_disable_interrupts: + .type exception_disable_interrupts, %function .global exception_disable_interrupts mfc0 $t0, C0_STATUS li $t1, ~(C0_SR_IE) @@ -215,6 +188,7 @@ exception_disable_interrupts: .section .text.exception_enable_watchdog exception_enable_watchdog: + .type exception_enable_watchdog, %function .global exception_enable_watchdog mtc0 $zero, C0_COUNT li $t1, WATCHDOG_TIMEOUT @@ -228,6 +202,7 @@ exception_enable_watchdog: .section .text.exception_disable_watchdog exception_disable_watchdog: + .type exception_disable_watchdog, %function .global exception_disable_watchdog mfc0 $t0, C0_STATUS li $t1, ~(C0_SR_IM7) diff --git a/sw/bootloader/src/exception.h b/sw/bootloader/src/exception.h index 7b3873e..0d647d9 100644 --- a/sw/bootloader/src/exception.h +++ b/sw/bootloader/src/exception.h @@ -7,7 +7,6 @@ #define EXCEPTION_TRIGGER(code) { asm volatile ("syscall %[c]\n" :: [c] "i" (code)); } -void exception_install (void); void exception_enable_interrupts (void); void exception_disable_interrupts (void); void exception_enable_watchdog (void); diff --git a/sw/bootloader/src/init.c b/sw/bootloader/src/init.c index 15d1430..b475d3a 100644 --- a/sw/bootloader/src/init.c +++ b/sw/bootloader/src/init.c @@ -16,8 +16,6 @@ void init (init_tv_type_t tv_type, init_reset_type_t reset_type) { __tv_type = tv_type; __reset_type = reset_type; - exception_install(); - sc64_unlock(); if (!sc64_check_presence()) {