Skip to content

Commit 8f632b8

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
1 parent f0be8ec commit 8f632b8

File tree

5 files changed

+53
-28
lines changed

5 files changed

+53
-28
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.1.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: 19 additions & 16 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;
@@ -88,23 +89,16 @@ impl VgaConsole {
8889
}
8990
}
9091

91-
fn read(&self) -> (u8, u8) {
92-
let offset =
93-
((isize::from(self.row) * isize::from(self.width)) + isize::from(self.col)) * 2;
94-
let glyph = unsafe { core::ptr::read_volatile(self.addr.offset(offset)) };
95-
let attr = unsafe { core::ptr::read_volatile(self.addr.offset(offset + 1)) };
96-
(glyph, attr)
97-
}
98-
99-
fn find_start_row(&mut self) {
92+
fn clear(&mut self) {
10093
for row in 0..self.height {
101-
self.row = row;
102-
let g = self.read().0;
103-
if (g == b'\0') || (g == b' ') {
104-
// Found a line with nothing on it - start here!
105-
break;
94+
for col in 0..self.width {
95+
self.row = row;
96+
self.col = col;
97+
self.write(b' ', Some(Self::DEFAULT_ATTR));
10698
}
10799
}
100+
self.row = 0;
101+
self.col = 0;
108102
}
109103

110104
fn write(&mut self, glyph: u8, attr: Option<u8>) {
@@ -253,6 +247,7 @@ impl core::default::Default for Config {
253247

254248
/// Initialise our global variables - the BIOS will not have done this for us
255249
/// (as it doesn't know where they are).
250+
#[cfg(target_os = "none")]
256251
unsafe fn start_up_init() {
257252
extern "C" {
258253

@@ -269,6 +264,11 @@ unsafe fn start_up_init() {
269264
r0::init_data(&mut __sdata, &mut __edata, &__sidata);
270265
}
271266

267+
#[cfg(not(target_os = "none"))]
268+
unsafe fn start_up_init() {
269+
// Nothing to do
270+
}
271+
272272
// ===========================================================================
273273
// Public functions / impl for public types
274274
// ===========================================================================
@@ -279,6 +279,9 @@ unsafe fn start_up_init() {
279279
pub extern "C" fn main(api: &'static bios::Api) -> ! {
280280
unsafe {
281281
start_up_init();
282+
if (api.api_version_get)() != neotron_common_bios::API_VERSION {
283+
panic!("API mismatch!");
284+
}
282285
API = Some(api);
283286
}
284287

@@ -296,7 +299,7 @@ pub extern "C" fn main(api: &'static bios::Api) -> ! {
296299
row: 0,
297300
col: 0,
298301
};
299-
vga.find_start_row();
302+
vga.clear();
300303
unsafe {
301304
VGA_CONSOLE = Some(vga);
302305
}

0 commit comments

Comments
 (0)