Skip to content

Commit 9e0a438

Browse files
committed
Various updates when testing with Neotron Desktop BIOS.
* Screen is cleared from the OS side, with the default attributes. * It now builds a .so file if it can * The thumb target is not longer the default, as it's a pain to turn off default targets to build native (I wish there was --target=native). Updates to BIOS API 0.6.0
2 parents f9e94c8 + 8f632b8 commit 9e0a438

File tree

5 files changed

+60
-19
lines changed

5 files changed

+60
-19
lines changed

.cargo/config

Lines changed: 0 additions & 2 deletions
This file was deleted.

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ name = "flash0002"
2323
test = false
2424
bench = false
2525

26+
[lib]
27+
crate-type = ["rlib", "cdylib"]
28+
2629
[profile.release]
2730
lto = true
2831
debug = true
2932
codegen-units = 1
3033
opt-level = "s"
34+
panic = "abort"
35+
36+
[profile.dev]
37+
panic = "abort"
3138

3239
[dependencies]
33-
neotron-common-bios = "0.4.0"
40+
neotron-common-bios = { version = "0.6.0", path = "../neotron-common-bios" }
3441
r0 = "1.0"
3542
postcard = "0.5"
3643
serde = { version = "1.0", default-features = false }

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Neotron OS
22

3-
This is the Neotron OS. It will run on any system which can execute ARM Thumb v7-M instructions, and has an implementation of the [Neotron BIOS](https://github.com/neotron-compute/Neotron-BIOS).
3+
This is the Neotron OS. It will run on any system which has an implementation
4+
of the [Neotron BIOS](https://github.com/neotron-compute/Neotron-BIOS).
45

56
## Status
67

@@ -24,23 +25,30 @@ OpenOCD or some other programming tool running for your particular board. See
2425
your BIOS instructions for more details.
2526

2627
We compile one version of Neotron OS, but we link it three times to produce
27-
three binaries:
28+
three different binaries:
2829

2930
* `flash0002` - is linked to run from address `0x0002_0000`
3031
* `flash1002` - is linked to run from address `0x1002_0000`
3132
* `flash0802` - is linked to run from address `0x0802_0000`
3233

33-
```
34+
```console
3435
$ git clone https://github.com/neotron-compute/Neotron-OS.git
3536
$ cd Neotron-OS
36-
$ git submodule update --init
37-
$ cargo build --release
38-
$ ls ./target/thumbv6m-none-eabi/release/flash{10,08,00}02
37+
$ cargo build --target thumbv6m-none-eabi --release --bins
38+
$ ls ./target/thumbv6m-none-eabi/release/flash*02
3939
./target/thumbv6m-none-eabi/release/flash0002 ./target/thumbv6m-none-eabi/release/flash0802 ./target/thumbv6m-none-eabi/release/flash1002
4040
```
4141

4242
Your BIOS should tell you which one you want and how to load it onto your system.
4343

44+
You can also build a *shared object* to load into a Windows/Linux/macOS application.
45+
46+
```console
47+
$ cargo build --lib
48+
$ ls ./target/debug/*.so
49+
./target/debug/libneotron_os.so
50+
```
51+
4452
## Changelog
4553

4654
### Unreleased Changes ([Source](https://github.com/neotron-compute/Neotron-OS/tree/master))

build.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
use std::env;
12
fn main() {
2-
println!("cargo:rustc-link-arg-bin=flash1002=-Tneotron-flash-1002.ld");
3-
println!("cargo:rustc-link-arg-bin=flash0802=-Tneotron-flash-0802.ld");
4-
println!("cargo:rustc-link-arg-bin=flash0002=-Tneotron-flash-0002.ld");
3+
4+
match env::var("CARGO_CFG_TARGET_OS").as_deref() {
5+
Ok("none") => {
6+
println!("cargo:rustc-link-arg-bin=flash1002=-Tneotron-flash-1002.ld");
7+
println!("cargo:rustc-link-arg-bin=flash0802=-Tneotron-flash-0802.ld");
8+
println!("cargo:rustc-link-arg-bin=flash0002=-Tneotron-flash-0002.ld");
9+
}
10+
_ => {
11+
// No args
12+
}
13+
}
514

615
if let Ok(cmd_output) = std::process::Command::new("git")
716
.arg("describe")

src/lib.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ struct VgaConsole {
7070
}
7171

7272
impl VgaConsole {
73-
const DEFAULT_ATTR: u8 = (2 << 3) | (1 << 0);
73+
/// White on Black
74+
const DEFAULT_ATTR: u8 = (15 << 3) | 0;
7475

7576
fn move_char_right(&mut self) {
7677
self.col += 1;
@@ -91,6 +92,18 @@ impl VgaConsole {
9192
}
9293
}
9394

95+
fn clear(&mut self) {
96+
for row in 0..self.height {
97+
for col in 0..self.width {
98+
self.row = row;
99+
self.col = col;
100+
self.write(b' ', Some(Self::DEFAULT_ATTR));
101+
}
102+
}
103+
self.row = 0;
104+
self.col = 0;
105+
}
106+
94107
fn write(&mut self, glyph: u8, attr: Option<u8>) {
95108
let offset = ((self.row * self.width) + self.col) * 2;
96109
unsafe { core::ptr::write_volatile(self.addr.offset(offset), glyph) };
@@ -376,6 +389,7 @@ impl core::default::Default for Config {
376389

377390
/// Initialise our global variables - the BIOS will not have done this for us
378391
/// (as it doesn't know where they are).
392+
#[cfg(target_os = "none")]
379393
unsafe fn start_up_init() {
380394
extern "C" {
381395

@@ -392,6 +406,11 @@ unsafe fn start_up_init() {
392406
r0::init_data(&mut __sdata, &mut __edata, &__sidata);
393407
}
394408

409+
#[cfg(not(target_os = "none"))]
410+
unsafe fn start_up_init() {
411+
// Nothing to do
412+
}
413+
395414
// ===========================================================================
396415
// Public functions / impl for public types
397416
// ===========================================================================
@@ -402,6 +421,9 @@ unsafe fn start_up_init() {
402421
pub extern "C" fn main(api: &'static bios::Api) -> ! {
403422
unsafe {
404423
start_up_init();
424+
if (api.api_version_get)() != neotron_common_bios::API_VERSION {
425+
panic!("API mismatch!");
426+
}
405427
API = Some(api);
406428
}
407429

@@ -418,13 +440,14 @@ pub extern "C" fn main(api: &'static bios::Api) -> ! {
418440
let (width, height) = (mode.text_width(), mode.text_height());
419441

420442
if let (Some(width), Some(height)) = (width, height) {
421-
let vga = VgaConsole {
443+
let mut vga = VgaConsole {
422444
addr: (api.video_get_framebuffer)(),
423445
width: width as isize,
424446
height: height as isize,
425447
row: 0,
426448
col: 0,
427449
};
450+
vga.clear();
428451
unsafe {
429452
VGA_CONSOLE = Some(vga);
430453
}
@@ -460,11 +483,7 @@ pub extern "C" fn main(api: &'static bios::Api) -> ! {
460483
print!(".");
461484
}
462485
println!("{}", i);
463-
// An awfully crude delay loop. We all the API to ensure the loop isn't
464-
// optimised away.
465-
for _delay in 0..2_000_000 {
466-
let _ver = (api.api_version_get)();
467-
}
486+
(api.delay)(neotron_common_bios::Timeout::new_ms(250));
468487
}
469488

470489
panic!("Testing a panic...");

0 commit comments

Comments
 (0)