Merge pull request #271 from lifning/master

Support armv4t-none-eabi target as well.
This commit is contained in:
Corwin 2022-08-01 20:38:39 +01:00 committed by GitHub
commit 940a92b021
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 83 additions and 13 deletions

View file

@ -8,3 +8,7 @@ target = "thumbv4t-none-eabi"
[target.thumbv4t-none-eabi] [target.thumbv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"] rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-test-runner" runner = "mgba-test-runner"
[target.armv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-test-runner"

View file

@ -12,6 +12,7 @@
)] )]
#![feature(alloc_error_handler)] #![feature(alloc_error_handler)]
#![feature(allocator_api)] #![feature(allocator_api)]
#![feature(asm_const)]
#![warn(clippy::all)] #![warn(clippy::all)]
#![deny(clippy::must_use_candidate)] #![deny(clippy::must_use_candidate)]
#![deny(clippy::trivially_copy_pass_by_ref)] #![deny(clippy::trivially_copy_pass_by_ref)]

View file

@ -4,10 +4,19 @@ use core::arch::asm;
#[allow(non_snake_case)] #[allow(non_snake_case)]
const fn swi_map(thumb_id: u32) -> u32 {
if cfg!(target_feature="thumb-mode") {
thumb_id
} else {
thumb_id << 16
}
}
pub fn halt() { pub fn halt() {
unsafe { unsafe {
asm!( asm!(
"swi 0x02", "swi {SWI}",
SWI = const { swi_map(0x02) },
lateout("r0") _, lateout("r0") _,
lateout("r1") _, lateout("r1") _,
lateout("r2") _, lateout("r2") _,
@ -19,7 +28,8 @@ pub fn halt() {
pub fn stop() { pub fn stop() {
unsafe { unsafe {
asm!( asm!(
"swi 0x03", "swi {SWI}",
SWI = const { swi_map(0x03) },
lateout("r0") _, lateout("r0") _,
lateout("r1") _, lateout("r1") _,
lateout("r2") _, lateout("r2") _,
@ -31,7 +41,8 @@ pub fn stop() {
pub fn wait_for_interrupt() { pub fn wait_for_interrupt() {
unsafe { unsafe {
asm!( asm!(
"swi 0x04", "swi {SWI}",
SWI = const { swi_map(0x04) },
lateout("r0") _, lateout("r0") _,
lateout("r1") _, lateout("r1") _,
lateout("r2") _, lateout("r2") _,
@ -45,7 +56,8 @@ pub fn wait_for_interrupt() {
pub fn wait_for_vblank() { pub fn wait_for_vblank() {
unsafe { unsafe {
asm!( asm!(
"swi 0x05", "swi {SWI}",
SWI = const { swi_map(0x05) },
lateout("r0") _, lateout("r0") _,
lateout("r1") _, lateout("r1") _,
lateout("r2") _, lateout("r2") _,
@ -61,7 +73,8 @@ pub fn div(numerator: i32, denominator: i32) -> (i32, i32, i32) {
let abs_divide: i32; let abs_divide: i32;
unsafe { unsafe {
asm!( asm!(
"swi 0x06", "swi {SWI}",
SWI = const { swi_map(0x06) },
in("r0") numerator, in("r0") numerator,
in("r1") denominator, in("r1") denominator,
lateout("r0") divide, lateout("r0") divide,
@ -77,7 +90,8 @@ pub fn sqrt(n: i32) -> i32 {
let result: i32; let result: i32;
unsafe { unsafe {
asm!( asm!(
"swi 0x08", "swi {SWI}",
SWI = const { swi_map(0x08) },
in("r0") n, in("r0") n,
lateout("r0") result, lateout("r0") result,
lateout("r1") _, lateout("r1") _,
@ -93,7 +107,8 @@ pub fn arc_tan(n: i16) -> i16 {
let result: i16; let result: i16;
unsafe { unsafe {
asm!( asm!(
"swi 0x09", "swi {SWI}",
SWI = const { swi_map(0x09) },
in("r0") n, in("r0") n,
lateout("r0") result, lateout("r0") result,
lateout("r1") _, lateout("r1") _,
@ -109,7 +124,8 @@ pub fn arc_tan2(x: i16, y: i32) -> i16 {
let result: i16; let result: i16;
unsafe { unsafe {
asm!( asm!(
"swi 0x09", "swi {SWI}",
SWI = const { swi_map(0x09) },
in("r0") x, in("r0") x,
in("r1") y, in("r1") y,
lateout("r0") result, lateout("r0") result,

23
armv4t-none-eabi.json Normal file
View file

@ -0,0 +1,23 @@
{
"arch": "arm",
"asm-args": [
"-mthumb-interwork",
"-march=armv4t",
"-mcpu=arm7tdmi",
"-mlittle-endian"
],
"atomic-cas": false,
"data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
"emit-debug-gdb-scripts": false,
"executables": true,
"features": "+soft-float,+strict-align",
"has-thumb-interworking": true,
"linker": "arm-none-eabi-ld",
"linker-flavor": "ld",
"linker-is-gnu": true,
"llvm-target": "armv4t-none-eabi",
"main-needs-argc-argv": false,
"panic-strategy": "abort",
"relocation-model": "static",
"target-pointer-width": "32"
}

View file

@ -6,5 +6,9 @@ build-std-features = ["compiler-builtins-mem"]
target = "thumbv4t-none-eabi" target = "thumbv4t-none-eabi"
[target.thumbv4t-none-eabi] [target.thumbv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld"] rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt"
[target.armv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt" runner = "mgba-qt"

View file

@ -7,5 +7,9 @@ sparse-registry = true
target = "thumbv4t-none-eabi" target = "thumbv4t-none-eabi"
[target.thumbv4t-none-eabi] [target.thumbv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld"] rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt"
[target.armv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt" runner = "mgba-qt"

View file

@ -6,5 +6,9 @@ build-std-features = ["compiler-builtins-mem"]
target = "thumbv4t-none-eabi" target = "thumbv4t-none-eabi"
[target.thumbv4t-none-eabi] [target.thumbv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld"] rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt"
[target.armv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt" runner = "mgba-qt"

View file

@ -6,5 +6,9 @@ build-std-features = ["compiler-builtins-mem"]
target = "thumbv4t-none-eabi" target = "thumbv4t-none-eabi"
[target.thumbv4t-none-eabi] [target.thumbv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld"] rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt"
[target.armv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt" runner = "mgba-qt"

View file

@ -13,9 +13,11 @@ clippy:
test: test:
just _test-debug agb just _test-debug agb
just _test-debug agb-fixnum just _test-debug agb-fixnum
just _test-debug-arm agb
test-release: test-release:
just _test-release agb just _test-release agb
just _test-release-arm agb
doctest-agb: doctest-agb:
(cd agb && cargo test --doc -Z doctest-xcompile) (cd agb && cargo test --doc -Z doctest-xcompile)
@ -92,9 +94,13 @@ _build-release crate:
_test-release crate: _test-release crate:
just _build-release {{crate}} just _build-release {{crate}}
(cd "{{crate}}" && cargo test --release) (cd "{{crate}}" && cargo test --release)
_test-release-arm crate:
(cd "{{crate}}" && cargo test --release --target="{{justfile_directory()+"/armv4t-none-eabi.json"}}")
_test-debug crate: _test-debug crate:
just _build-debug {{crate}} just _build-debug {{crate}}
(cd "{{crate}}" && cargo test) (cd "{{crate}}" && cargo test)
_test-debug-arm crate:
(cd "{{crate}}" && cargo test --release --target="{{justfile_directory()+"/armv4t-none-eabi.json"}}")
_clippy crate: _clippy crate:
(cd "{{crate}}" && cargo clippy --examples --tests -- {{CLIPPY_ARGUMENTS}}) (cd "{{crate}}" && cargo clippy --examples --tests -- {{CLIPPY_ARGUMENTS}})
_clean crate: _clean crate:

View file

@ -6,5 +6,9 @@ build-std-features = ["compiler-builtins-mem"]
target = "thumbv4t-none-eabi" target = "thumbv4t-none-eabi"
[target.thumbv4t-none-eabi] [target.thumbv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld"] rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt"
[target.armv4t-none-eabi]
rustflags = ["-Clink-arg=-Tgba.ld", "-Ctarget-cpu=arm7tdmi"]
runner = "mgba-qt" runner = "mgba-qt"