hocclk: add bpmpfw loading
This commit is contained in:
1 parent
7fea98a72d
commit
bd468f087d
14 files changed
+522
-3
No files matched your search
@@ -0,0 +1,44 @@
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
include $(DEVKITARM)/base_rules
|
||||
|
||||
TARGET := bpmpfw
|
||||
BUILDDIR := build
|
||||
OUTPUTDIR := out
|
||||
SOURCEDIR := source
|
||||
|
||||
OBJS := $(BUILDDIR)/start.o $(BUILDDIR)/main.o
|
||||
|
||||
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb-interwork
|
||||
CXXFLAGS := $(ARCH) -O2 -g -ffreestanding -nostdlib -fno-exceptions -fno-rtti \
|
||||
-fno-unwind-tables -fno-threadsafe-statics -ffunction-sections -fdata-sections \
|
||||
-fomit-frame-pointer -std=gnu++20 -Wall -Wextra $(CUSTOMDEFINES)
|
||||
ASFLAGS := $(ARCH) -g
|
||||
LDFLAGS := $(ARCH) -nostartfiles -nodefaultlibs -Wl,--nmagic,--gc-sections \
|
||||
-T $(SOURCEDIR)/../bpmpfw.ld -lgcc
|
||||
|
||||
BIN_TARGET := $(OUTPUTDIR)/$(TARGET).bin
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(BIN_TARGET)
|
||||
|
||||
$(BIN_TARGET): $(BUILDDIR)/$(TARGET).elf
|
||||
@mkdir -p $(OUTPUTDIR)
|
||||
$(OBJCOPY) -S -O binary $< $@
|
||||
|
||||
$(BUILDDIR)/$(TARGET).elf: $(OBJS)
|
||||
@$(CXX) $(LDFLAGS) $(OBJS) -o $@
|
||||
|
||||
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.cpp | $(BUILDDIR)
|
||||
@$(CXX) $(CXXFLAGS) -I$(SOURCEDIR) -c $< -o $@
|
||||
|
||||
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.s | $(BUILDDIR)
|
||||
@$(CXX) $(ASFLAGS) -I$(SOURCEDIR) -c $< -o $@
|
||||
|
||||
$(BUILDDIR):
|
||||
@mkdir -p $(BUILDDIR)
|
||||
|
||||
clean:
|
||||
@rm -rf $(BUILDDIR) $(OUTPUTDIR)
|
||||
@@ -0,0 +1,151 @@
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(reset)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
bpmpfw : ORIGIN = 0x40004000, LENGTH = 32K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
PROVIDE(__start__ = ORIGIN(bpmpfw));
|
||||
. = __start__;
|
||||
__code_start = . ;
|
||||
|
||||
.vectors :
|
||||
{
|
||||
KEEP (*(.vectors .vectors.*))
|
||||
. = ALIGN(8);
|
||||
} >bpmpfw
|
||||
|
||||
.text :
|
||||
{
|
||||
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
|
||||
*(.text.exit .text.exit.*)
|
||||
*(.text.startup .text.startup.*)
|
||||
*(.text.hot .text.hot.*)
|
||||
*(.text .stub .text.* .gnu.linkonce.t.*)
|
||||
. = ALIGN(8);
|
||||
} >bpmpfw
|
||||
|
||||
.init :
|
||||
{
|
||||
KEEP( *(.init) )
|
||||
. = ALIGN(8);
|
||||
} >bpmpfw
|
||||
|
||||
.plt :
|
||||
{
|
||||
*(.plt)
|
||||
*(.iplt)
|
||||
. = ALIGN(8);
|
||||
} >bpmpfw
|
||||
|
||||
.fini :
|
||||
{
|
||||
KEEP( *(.fini) )
|
||||
. = ALIGN(8);
|
||||
} >bpmpfw
|
||||
|
||||
. = ALIGN(8);
|
||||
__rodata_start = . ;
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
||||
. = ALIGN(8);
|
||||
} >bpmpfw
|
||||
|
||||
.eh_frame_hdr : { __eh_frame_hdr_start = .; *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) __eh_frame_hdr_end = .; } >bpmpfw
|
||||
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) } >bpmpfw
|
||||
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } >bpmpfw
|
||||
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } >bpmpfw
|
||||
|
||||
.hash : { *(.hash) } >bpmpfw
|
||||
|
||||
. = ALIGN(8);
|
||||
__data_start = . ;
|
||||
|
||||
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } >bpmpfw
|
||||
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } >bpmpfw
|
||||
.gnu_extab : ONLY_IF_RW { *(.gnu_extab*) } >bpmpfw
|
||||
.exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } >bpmpfw
|
||||
|
||||
.preinit_array ALIGN(8) :
|
||||
{
|
||||
PROVIDE (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE (__preinit_array_end = .);
|
||||
} >bpmpfw
|
||||
|
||||
.init_array ALIGN(8) :
|
||||
{
|
||||
PROVIDE (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
PROVIDE (__init_array_end = .);
|
||||
} >bpmpfw
|
||||
|
||||
.fini_array ALIGN(8) :
|
||||
{
|
||||
PROVIDE (__fini_array_start = .);
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE (__fini_array_end = .);
|
||||
} >bpmpfw
|
||||
|
||||
.ctors ALIGN(8) :
|
||||
{
|
||||
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
} >bpmpfw
|
||||
|
||||
.dtors ALIGN(8) :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
} >bpmpfw
|
||||
|
||||
__got_start__ = .;
|
||||
|
||||
.got : { *(.got) *(.igot) } >bpmpfw
|
||||
.got.plt : { *(.got.plt) *(.igot.plt) } >bpmpfw
|
||||
|
||||
__got_end__ = .;
|
||||
|
||||
.data ALIGN(8) :
|
||||
{
|
||||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
SORT(CONSTRUCTORS)
|
||||
} >bpmpfw
|
||||
|
||||
__bss_start__ = .;
|
||||
.bss ALIGN(8) :
|
||||
{
|
||||
*(.dynbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(16);
|
||||
} >bpmpfw
|
||||
__bss_end__ = .;
|
||||
|
||||
__end__ = ABSOLUTE(.) ;
|
||||
|
||||
__stack_top = ORIGIN(bpmpfw) + LENGTH(bpmpfw) - 0x10;
|
||||
|
||||
/DISCARD/ : { *(.group .comment .note .interp .ARM.attributes) }
|
||||
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.debug_info 0 : { *(.debug_info) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
#include "regs.hpp"
|
||||
|
||||
extern "C" void main() {
|
||||
UartPuts("[bpmpfw]: Hello from BPMP-FW\n");
|
||||
|
||||
for (;;) {
|
||||
FlowCtlrHaltUsec(200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
using u8 = std::uint8_t;
|
||||
using u16 = std::uint16_t;
|
||||
using u32 = std::uint32_t;
|
||||
|
||||
#define MMIO32(addr) (*reinterpret_cast<volatile u32 *>(addr))
|
||||
|
||||
constexpr u32 FlowCtlrBase = 0x60007000;
|
||||
constexpr u32 FlowCtlrHaltCopEvents = 0x004;
|
||||
|
||||
constexpr u32 HaltModeWaitEvent = (2u << 29);
|
||||
constexpr u32 HaltUsec = (0u << 24);
|
||||
|
||||
inline void FlowCtlrHaltUsec(u32 usec) {
|
||||
MMIO32(FlowCtlrBase + FlowCtlrHaltCopEvents) = HaltModeWaitEvent | HaltUsec | (usec & 0xFFFFFFu);
|
||||
}
|
||||
|
||||
constexpr u32 UartBBase = 0x70006040;
|
||||
constexpr u32 UartThr = 0x00;
|
||||
constexpr u32 UartLsr = 0x14;
|
||||
constexpr u32 UartLsrThre = (1u << 5);
|
||||
|
||||
inline void UartPutc(char c) {
|
||||
while (!(MMIO32(UartBBase + UartLsr) & UartLsrThre))
|
||||
;
|
||||
MMIO32(UartBBase + UartThr) = static_cast<u32>(static_cast<u8>(c));
|
||||
}
|
||||
|
||||
inline void UartPuts(const char *s) {
|
||||
while (*s) {
|
||||
UartPutc(*s++);
|
||||
}
|
||||
}
|
||||
|
||||
inline void UartPutHex32(u32 v) {
|
||||
static const char digits[] = "0123456789ABCDEF";
|
||||
for (int i = 28; i >= 0; i -= 4) {
|
||||
UartPutc(digits[(v >> i) & 0xF]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
.section .vectors, "ax", %progbits
|
||||
.align 3
|
||||
.global reset
|
||||
reset:
|
||||
b _start
|
||||
b _panic
|
||||
|
||||
.section .text.start, "ax", %progbits
|
||||
.align 3
|
||||
.global _start
|
||||
.extern main
|
||||
_start:
|
||||
/* Mask IRQ + FIQ, enter SVC mode. */
|
||||
msr cpsr_f, #0xC0
|
||||
msr cpsr_cf, #0xD3
|
||||
|
||||
/* Set the stack pointer. */
|
||||
ldr sp, =__stack_top
|
||||
|
||||
/* Zero .bss. */
|
||||
ldr r0, =__bss_start__
|
||||
ldr r1, =__bss_end__
|
||||
mov r2, #0
|
||||
1:
|
||||
cmp r0, r1
|
||||
bge 2f
|
||||
str r2, [r0], #4
|
||||
b 1b
|
||||
2:
|
||||
|
||||
/* Run global constructors. */
|
||||
ldr r4, =__init_array_start
|
||||
ldr r5, =__init_array_end
|
||||
3:
|
||||
cmp r4, r5
|
||||
bge 4f
|
||||
ldr r0, [r4], #4
|
||||
mov lr, pc
|
||||
bx r0
|
||||
b 3b
|
||||
4:
|
||||
|
||||
bl main
|
||||
|
||||
.global _panic
|
||||
_panic:
|
||||
ldr r0, =0x70006040 /* UART_B_BASE */
|
||||
adr r3, _panic_msg
|
||||
7:
|
||||
ldrb r1, [r3], #1
|
||||
cmp r1, #0
|
||||
beq _panic_hang
|
||||
8:
|
||||
ldr r2, [r0, #0x14] /* UART_LSR */
|
||||
tst r2, #0x20 /* UART_LSR_THRE */
|
||||
beq 8b
|
||||
str r1, [r0]
|
||||
b 7b
|
||||
|
||||
_panic_msg:
|
||||
.asciz "[bpmpfw] PANIC\n"
|
||||
.align 2
|
||||
|
||||
_panic_hang:
|
||||
b _panic_hang
|
||||
Reference in new issue
Block a user