Skip to content

Commit 8ec18a1

Browse files
authored
Merge pull request #47 from Neotron-Compute/lib-mode
Support using the Neotron OS as a library.
2 parents 78e7d1e + f4aef60 commit 8ec18a1

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
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/bin/flash0002.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
/// of our portion of Flash.
1414
#[link_section = ".entry_point"]
1515
#[used]
16-
pub static ENTRY_POINT_ADDR: extern "C" fn(&neotron_common_bios::Api) -> ! = neotron_os::main;
16+
pub static ENTRY_POINT_ADDR: extern "C" fn(&neotron_common_bios::Api) -> ! = neotron_os::os_main;

src/bin/flash0802.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
/// of our portion of Flash.
1414
#[link_section = ".entry_point"]
1515
#[used]
16-
pub static ENTRY_POINT_ADDR: extern "C" fn(&neotron_common_bios::Api) -> ! = neotron_os::main;
16+
pub static ENTRY_POINT_ADDR: extern "C" fn(&neotron_common_bios::Api) -> ! = neotron_os::os_main;

src/bin/flash1002.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
/// of our portion of Flash.
1414
#[link_section = ".entry_point"]
1515
#[used]
16-
pub static ENTRY_POINT_ADDR: extern "C" fn(&neotron_common_bios::Api) -> ! = neotron_os::main;
16+
pub static ENTRY_POINT_ADDR: extern "C" fn(&neotron_common_bios::Api) -> ! = neotron_os::os_main;

src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ mod fs;
1818
mod program;
1919
mod vgaconsole;
2020

21+
pub use config::Config as OsConfig;
22+
2123
// ===========================================================================
2224
// Global Variables
2325
// ===========================================================================
@@ -188,7 +190,7 @@ impl core::fmt::Write for Ctx {
188190

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

@@ -205,7 +207,7 @@ unsafe fn start_up_init() {
205207
r0::init_data(&mut __sdata, &mut __edata, &__sidata);
206208
}
207209

208-
#[cfg(not(target_os = "none"))]
210+
#[cfg(any(not(target_os = "none"), feature = "lib-mode"))]
209211
unsafe fn start_up_init() {
210212
// Nothing to do
211213
}
@@ -217,7 +219,7 @@ unsafe fn start_up_init() {
217219
/// This is the function the BIOS calls. This is because we store the address
218220
/// of this function in the ENTRY_POINT_ADDR variable.
219221
#[no_mangle]
220-
pub extern "C" fn main(api: &bios::Api) -> ! {
222+
pub extern "C" fn os_main(api: &bios::Api) -> ! {
221223
unsafe {
222224
start_up_init();
223225
API.store(api);
@@ -344,13 +346,33 @@ pub extern "C" fn main(api: &bios::Api) -> ! {
344346
println!("Failed to get HID events: {:?}", e);
345347
}
346348
}
349+
if let Some((uart_dev, _serial_conf)) = menu.context.config.get_serial_console() {
350+
loop {
351+
let mut buffer = [0u8; 8];
352+
let wrapper = neotron_common_bios::ApiBuffer::new(&mut buffer);
353+
match (api.serial_read)(uart_dev, wrapper, neotron_common_bios::Option::None) {
354+
neotron_common_bios::Result::Ok(n) if n == 0 => {
355+
break;
356+
}
357+
neotron_common_bios::Result::Ok(n) => {
358+
for b in &buffer[0..n] {
359+
menu.input_byte(*b);
360+
}
361+
}
362+
_ => {
363+
break;
364+
}
365+
}
366+
}
367+
}
347368
(api.power_idle)();
348369
}
349370
}
350371

351372
/// Called when we have a panic.
352373
#[inline(never)]
353374
#[panic_handler]
375+
#[cfg(not(feature = "lib-mode"))]
354376
fn panic(info: &core::panic::PanicInfo) -> ! {
355377
IS_PANIC.store(true, Ordering::SeqCst);
356378
println!("PANIC!\n{:#?}", info);

src/program.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ impl TransientProgramArea {
177177
return Err(Error::BadAddress(start_addr));
178178
}
179179
println!("OK!");
180-
drop(application_ram);
181180
let result = unsafe {
182181
let code: extern "C" fn(*const neotron_api::Api) -> i32 =
183182
::core::mem::transmute(start_addr as *const ());

0 commit comments

Comments
 (0)