Support armv4t-none-eabi target as well.

This commit is contained in:
lifning 2022-08-01 02:20:03 -07:00
parent a7e038aa18
commit 22e9cbccc0
2 changed files with 25 additions and 8 deletions

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,