-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the 32 Bit Arm architectures.
- Loading branch information
1 parent
5644679
commit 3bb3690
Showing
9 changed files
with
167 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright (c) 2024 Philipp Schulz <[email protected]> | ||
|
||
//! AArch32. | ||
use crate::QEMUExit; | ||
use core::arch::asm; | ||
|
||
const EXIT_SUCCESS: u32 = 0; | ||
const EXIT_FAILURE: u32 = 1; | ||
|
||
#[allow(non_upper_case_globals)] | ||
const ADP_Stopped_ApplicationExit: u32 = 0x20026; | ||
|
||
/// The parameter block layout that is expected by QEMU. | ||
/// | ||
/// If QEMU finds `ADP_Stopped_ApplicationExit` in the first parameter, it uses the second parameter | ||
/// as exit code. | ||
/// | ||
/// If first paraemter != `ADP_Stopped_ApplicationExit`, exit code `1` is used. | ||
#[repr(C)] | ||
struct QEMUParameterBlock { | ||
arg0: u32, | ||
arg1: u32, | ||
} | ||
|
||
/// AArch32 configuration. | ||
pub struct AArch32 {} | ||
|
||
/// A Semihosting call using `0x20` - `SYS_EXIT_EXTENDED`. | ||
fn semihosting_sys_exit_call(block: &QEMUParameterBlock) -> ! { | ||
unsafe { | ||
asm!( | ||
"bkpt #0xab", | ||
in("r0") 0x20, | ||
in("r1") block as *const _ as u32, | ||
options(nostack) | ||
); | ||
|
||
// For the case that the QEMU exit attempt did not work, transition into an infinite loop. | ||
// Calling `panic!()` here is unfeasible, since there is a good chance this function here is | ||
// the last expression in the `panic!()` handler itself. This prevents a possible | ||
// infinite loop. | ||
loop { | ||
asm!("wfe", options(nomem, nostack)); | ||
} | ||
} | ||
} | ||
|
||
impl AArch32 { | ||
/// Create an instance. | ||
pub const fn new() -> Self { | ||
AArch32 {} | ||
} | ||
} | ||
|
||
impl QEMUExit for AArch32 { | ||
fn exit(&self, code: u32) -> ! { | ||
let block = QEMUParameterBlock { | ||
arg0: ADP_Stopped_ApplicationExit, | ||
arg1: code as u32, | ||
}; | ||
|
||
semihosting_sys_exit_call(&block) | ||
} | ||
|
||
fn exit_success(&self) -> ! { | ||
self.exit(EXIT_SUCCESS) | ||
} | ||
|
||
fn exit_failure(&self) -> ! { | ||
self.exit(EXIT_FAILURE) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* SPDX-License-Identifier: MIT OR Apache-2.0 | ||
* | ||
* Copyright (c) 2024 Philipp Schulz <[email protected]> | ||
*/ | ||
ENTRY(_vectors) | ||
|
||
SECTIONS | ||
{ | ||
. = 0x0; | ||
.boot : | ||
{ | ||
KEEP(*(.text.boot)) | ||
KEEP(*(.data.boot)) | ||
} | ||
|
||
.text : | ||
{ | ||
*(.vectors) | ||
*(.text._start) | ||
*(.text) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright (c) 2024 Philipp Schulz <[email protected]> | ||
|
||
//! AArch32 specific setup code. | ||
use core::arch::global_asm; | ||
|
||
global_asm!( | ||
include_str!("./startup.S") | ||
); | ||
|
||
#[no_mangle] | ||
extern "C" fn entry() { | ||
super::test_main() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.section ".text.boot","ax" | ||
|
||
.thumb | ||
.thumb_func | ||
.globl _vectors | ||
_vectors: | ||
.word 0x2000 | ||
.word reset | ||
|
||
.thumb_func | ||
reset: | ||
bl entry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters