Skip to content

Commit cd49268

Browse files
authored
Merge pull request #7 from Neotron-Compute/region_api_update
Region API update
2 parents 34cd155 + 465708a commit cd49268

File tree

4 files changed

+89
-24
lines changed

4 files changed

+89
-24
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "neotron-common-bios"
3-
version = "0.1.0"
3+
version = "0.4.0-alpha"
44
authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
55
edition = "2018"
66
description = "Common BIOS code and API for all Neotron systems."

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ This BIOS API crate is a work in progress.
3636
Unless you explicitly state otherwise, any contribution intentionally submitted
3737
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
3838
dual licensed as above, without any additional terms or conditions.
39+
40+
## Changelog
41+
42+
### Unreleased Changes
43+
44+
* Changed `memory_get_region` to return a `MemoryRegion`
45+
* Changed `video_set_framebuffer` to take a `*const u8` not `*mut u8` - as the
46+
BIOS doesn't change video RAM.
47+
48+
### v0.3.0
49+
50+
* First published version. `Cargo.toml` reports at `0.1.0`.

src/lib.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub use types::*;
3131
pub use version::Version;
3232

3333
/// BIOS API semantic version for the API defined in this crate.
34-
pub const API_VERSION: Version = Version::new(0, 3, 0);
34+
pub const API_VERSION: Version = Version::new(0, 4, 0);
3535

3636
/// The BIOS API.
3737
///
@@ -147,36 +147,38 @@ pub struct Api {
147147
pub video_get_framebuffer: extern "C" fn() -> *mut u8,
148148
/// Set the framebuffer address.
149149
///
150-
/// Tell the BIOS where it should start fetching pixel or textual data
151-
/// from (depending on the current video mode).
150+
/// Tell the BIOS where it should start fetching pixel or textual data from
151+
/// (depending on the current video mode).
152152
///
153153
/// This value is forgotten after a video mode change and must be
154154
/// re-supplied.
155-
pub video_set_framebuffer: extern "C" fn(*mut u8) -> crate::Result<()>,
156-
/// Find out how large a given region of memory is.
157155
///
158-
/// The first region is the 'application region' and is defined to always
159-
/// start at address `0x2000_0400` (that is, 1 KiB into main SRAM) on a
160-
/// standard Cortex-M system. This application region stops just before
161-
/// the BIOS reserved memory, at the top of the internal SRAM.
156+
/// Once the BIOS has handed over to the OS, it will never write to video
157+
/// memory, only read.
158+
///
159+
/// # Safety
160+
///
161+
/// The region pointed to by `start_address` must be large enough to contain
162+
/// however much video memory is required by both the current video mode,
163+
/// and whatever video modes you subsequently change into.
164+
pub video_set_framebuffer: unsafe extern "C" fn(start_address: *const u8) -> crate::Result<()>,
165+
/// Find out about regions of memory in the system.
166+
///
167+
/// The first region (index `0`) must be the 'application region' which is
168+
/// defined to always start at address `0x2000_0400` (that is, 1 KiB into
169+
/// main SRAM) on a standard Cortex-M system. This application region stops
170+
/// just before the BIOS reserved memory, typically at the top of the
171+
/// internal SRAM.
162172
///
163173
/// Other regions may be located at other addresses (e.g. external DRAM or
164174
/// PSRAM).
165175
///
166-
/// The OS will always load non-relocatable applications into the bottom
167-
/// of Region 0. It can allocate OS specific structures from any other
168-
/// Region (if any), or from the top of Region 0 (although this reduces
169-
/// the maximum application space available). The OS will prefer lower
170-
/// numbered regions (other than Region 0), so faster memory should be
171-
/// listed first.
172-
///
173-
/// If the region number given is invalid, the function returns `(null,
174-
/// 0)`.
175-
pub memory_get_region: extern "C" fn(
176-
region: u8,
177-
out_start: *mut *mut u8,
178-
out_len: *mut usize,
179-
) -> crate::Result<()>,
176+
/// The OS will always load non-relocatable applications into the bottom of
177+
/// Region 0. It can allocate OS specific structures from any other Region
178+
/// (if any), or from the top of Region 0 (although this reduces the maximum
179+
/// application space available). The OS will prefer lower numbered regions
180+
/// (other than Region 0), so faster memory should be listed first.
181+
pub memory_get_region: extern "C" fn(region_index: u8) -> crate::Result<types::MemoryRegion>,
180182
}
181183

182184
// End of file

src/types.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,28 @@ pub struct Time {
126126
pub nsecs: u32,
127127
}
128128

129+
/// The kinds of memory we know about
130+
#[repr(C)]
131+
#[derive(Debug, Clone)]
132+
pub enum MemoryKind {
133+
/// Read-write memory
134+
Ram,
135+
/// Read-only memory
136+
Rom,
137+
}
138+
139+
/// Represents a region in memory.
140+
#[repr(C)]
141+
#[derive(Debug, Clone)]
142+
pub struct MemoryRegion {
143+
/// The address the region starts at
144+
pub start: *mut u8,
145+
/// The length of the region
146+
pub length: usize,
147+
/// The kind of memory found at this region
148+
pub kind: MemoryKind,
149+
}
150+
129151
// ============================================================================
130152
// Impls
131153
// ============================================================================
@@ -302,6 +324,35 @@ impl From<&Time> for chrono::DateTime<chrono::Utc> {
302324
}
303325
}
304326

327+
// MemoryKind
328+
329+
impl core::fmt::Display for MemoryKind {
330+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
331+
write!(
332+
f,
333+
"{}",
334+
match self {
335+
MemoryKind::Rom => "ROM",
336+
MemoryKind::Ram => "RAM",
337+
}
338+
)
339+
}
340+
}
341+
342+
// MemoryRegion
343+
344+
impl core::fmt::Display for MemoryRegion {
345+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
346+
write!(
347+
f,
348+
"{} KiB {} @ {:p}",
349+
self.length / 1024,
350+
self.kind,
351+
self.start
352+
)
353+
}
354+
}
355+
305356
// ============================================================================
306357
// End of File
307358
// ============================================================================

0 commit comments

Comments
 (0)