Skip to content

Commit

Permalink
asm startup incomplete, but can boot a tiny example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor committed May 13, 2024
1 parent c7dceea commit 502f681
Show file tree
Hide file tree
Showing 14 changed files with 673 additions and 62 deletions.
2 changes: 0 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ target = "thumbv4t-none-eabi"

[unstable]
build-std = ["core"]
build-std-features = ["compiler-builtins-weak-intrinsics"]

[target.thumbv4t-none-eabi]
runner = "mgba-qt"
rustflags = [
"-Clinker=arm-none-eabi-ld",
"-Clink-arg=-Tlinker_scripts/mono_boot.ld",
"--emit=mir",
]
3 changes: 3 additions & 0 deletions .github/workflows/ci-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ jobs:

- name: Build The Examples (Link With LLD, strong compiler intrinsics)
run: cargo build --examples --target=thumbv4t-none-eabi -Zbuild-std=core -Clink-arg=-Tlinker_scripts/mono_boot.ld

- name: Build The Crate With No Default Features (build script usage simulation)
run: cargo build --no-default-features
21 changes: 19 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@ edition = "2021"
license = "Zlib OR Apache-2.0 OR MIT"

[features]
default = ["on_gba", "critical-section", "doc_cfg"]
default = ["on_gba"]
# SEE THE CRATE DOCS FOR SAFETY RELATED INFO REGARDING THIS FEATURE.
on_gba = []
# utilize `doc_cfg` where appropriate. requires nightly.
# utilize `doc_cfg` where appropriate. requires nightly. intended mostly for use
# during docs.rs documentation generation.
doc_cfg = []
# Activates the `track_caller` attribute on various functions. Use of the
# `track_caller` attribute on a function adds a "secret" extra argument for the
# `Location` of the caller, which can reduce performance if the function is not
# inlined (meaning `Location` is passed via the stack). This is only needed for
# debugging, and so it's off by default.
track_caller = []
# The assembly runtime's irq handler will take extra steps to allow nested
# interrupts during calls to the Rust interrupt handler, and also the Rust
# interrupt handler will be called with the CPU in System mode, allowing for
# full stack usage. If you do not use this feature then the Rust IRQ handler
# will be called with the CPU in IRQ mode with nested interrupts disabled at the
# CPU level. IRQ mode still has enough stack space to do any *reasonable* IRQ
# handling, so you do NOT normally need to use this unless you need nested
# interrupt support or extremely large stack usage during the handler.
robust_irq_handler = []

[dependencies]
voladdress = "1.3.0"
bitfrob = "1"
critical-section = { version = "1.1.2", features = [
"restore-state-bool",
], optional = true }
bytemuck = { version = "1.16.0", optional = true }

[profile.dev]
opt-level = 3
Expand All @@ -38,3 +54,4 @@ incremental = false
# on the GBA. This is the closest target that docs.rs supports by default and
# which *also* supports the `instruction_set` attribute to avoid build errors.
targets = ["armv5te-unknown-linux-gnueabi"]
features = ["doc_cfg"]
2 changes: 2 additions & 0 deletions dump.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cargo build --examples
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std target/thumbv4t-none-eabi/debug/examples/do_nothing >target/ex-do_nothing.txt
9 changes: 9 additions & 0 deletions examples/do_nothing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![no_std]
#![no_main]

gba::panic_handler!(empty_loop);

#[no_mangle]
pub extern "C" fn main() -> ! {
loop {}
}
28 changes: 14 additions & 14 deletions linker_scripts/mono_boot.ld
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* THIS LINKER SCRIPT FILE IS RELEASED TO THE PUBLIC DOMAIN (SPDX: CC0-1.0) */

ENTRY(__start)
ENTRY(_start)

MEMORY {
ewram (w!x) : ORIGIN = 0x2000000, LENGTH = 256K
Expand All @@ -11,7 +11,7 @@ MEMORY {
SECTIONS {
.text : {
/* be sure that the ROM header is the very first */
*(.text.gba_rom_header);
*(.text._start);
*(.text .text.*);
. = ALIGN(4);
} >rom = 0x00
Expand All @@ -22,42 +22,42 @@ SECTIONS {
} >rom = 0x00

. = ALIGN(4);
__iwram_position_in_rom = .;
_iwram_position_in_rom = .;
.data : {
__iwram_start = ABSOLUTE(.);
_iwram_start = ABSOLUTE(.);

*(.data .data.*);
*(.iwram .iwram.*);
. = ALIGN(4);

__iwram_end = ABSOLUTE(.);
_iwram_end = ABSOLUTE(.);
} >iwram AT>rom = 0x00

. = ALIGN(4);
__ewram_position_in_rom = __iwram_position_in_rom + (__iwram_end - __iwram_start);
_ewram_position_in_rom = _iwram_position_in_rom + (_iwram_end - _iwram_start);
.ewram : {
__ewram_start = ABSOLUTE(.);
_ewram_start = ABSOLUTE(.);

*(.ewram .ewram.*);
. = ALIGN(4);

__ewram_end = ABSOLUTE(.);
_ewram_end = ABSOLUTE(.);
} >ewram AT>rom = 0x00

. = ALIGN(4);
__bss_position_in_rom = __ewram_position_in_rom + (__ewram_end - __ewram_start);
_bss_position_in_rom = _ewram_position_in_rom + (_ewram_end - _ewram_start);
.bss : {
__bss_start = ABSOLUTE(.);
_bss_start = ABSOLUTE(.);

*(.bss .bss.*);
. = ALIGN(4);

__bss_end = ABSOLUTE(.);
_bss_end = ABSOLUTE(.);
} >iwram

__iwram_word_copy_count = (__iwram_end - __iwram_start) / 4;
__ewram_word_copy_count = (__ewram_end - __ewram_start) / 4;
__bss_word_clear_count = (__bss_end - __bss_start) / 4;
_iwram_word_copy_count = (_iwram_end - _iwram_start) / 4;
_ewram_word_copy_count = (_ewram_end - _ewram_start) / 4;
_bss_word_clear_count = (_bss_end - _bss_start) / 4;

/* rust-lld demands we keep the `section header string table` */
.shstrtab 0 : { *(.shstrtab) }
Expand Down
Loading

0 comments on commit 502f681

Please sign in to comment.