Skip to content

Commit 4dadf92

Browse files
committed
Support using the Neotron OS as a library.
In case you want to use it in a BIOS as a library, rather than compiling in separately. The feature flag turns off variable initialisation (the start-up already did that), and turns off the panic handler (your binary should do that).
1 parent 78e7d1e commit 4dadf92

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ chrono = { version = "0.4", default-features = false }
5151
embedded-sdmmc = { version = "0.5", default-features = false }
5252
neotron-api = "0.1"
5353

54+
[features]
55+
lib-mode = []

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl core::fmt::Write for Ctx {
188188

189189
/// Initialise our global variables - the BIOS will not have done this for us
190190
/// (as it doesn't know where they are).
191-
#[cfg(target_os = "none")]
191+
#[cfg(all(target_os = "none", not(feature = "lib-mode")))]
192192
unsafe fn start_up_init() {
193193
extern "C" {
194194

@@ -205,7 +205,7 @@ unsafe fn start_up_init() {
205205
r0::init_data(&mut __sdata, &mut __edata, &__sidata);
206206
}
207207

208-
#[cfg(not(target_os = "none"))]
208+
#[cfg(any(not(target_os = "none"), feature = "lib-mode"))]
209209
unsafe fn start_up_init() {
210210
// Nothing to do
211211
}
@@ -217,7 +217,7 @@ unsafe fn start_up_init() {
217217
/// This is the function the BIOS calls. This is because we store the address
218218
/// of this function in the ENTRY_POINT_ADDR variable.
219219
#[no_mangle]
220-
pub extern "C" fn main(api: &bios::Api) -> ! {
220+
pub extern "C" fn os_main(api: &bios::Api) -> ! {
221221
unsafe {
222222
start_up_init();
223223
API.store(api);
@@ -351,6 +351,7 @@ pub extern "C" fn main(api: &bios::Api) -> ! {
351351
/// Called when we have a panic.
352352
#[inline(never)]
353353
#[panic_handler]
354+
#[cfg(not(feature = "lib-mode"))]
354355
fn panic(info: &core::panic::PanicInfo) -> ! {
355356
IS_PANIC.store(true, Ordering::SeqCst);
356357
println!("PANIC!\n{:#?}", info);

0 commit comments

Comments
 (0)