refactor: apply newtypes throughout userspace API and display types
Every syscall stub now uses proper types from types/ — CapSlot,
EntryPoint, StackPointer, VirtualAddress, PageCount, ProcessId,
PermissionSet, Ticks. The compiler prevents swapping entry/stack,
passing a ProcessId where a CapSlot is expected, or using an
address as a page count.
New display types in types/display.rs:
- Color(u32) with rgb() constructor
- ScreenCoord(u16) for x/y positions
- Dimension(u16) for width/height
Updated throughout:
- userspace/syscall.rs: all params typed, returns Option instead
of sentinel usize::MAX
- server-framework: endpoint param is CapSlot
- port-framebuffer: trait uses Color, ScreenCoord, Dimension
- hw-virtio: DmaAddrs uses PhysicalAddress/VirtualAddress,
GPU commands use Dimension
- All servers, drivers, bins, apps updated for new signatures
- permission-manager: process field uses ProcessId
- PermissionSet: added bits() accessor
89 tests pass, full QEMU boot verified.
This commit is contained in:
@@ -5,3 +5,4 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
port-framebuffer = { workspace = true }
|
||||
types = { workspace = true }
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
#![no_std]
|
||||
|
||||
use port_framebuffer::Framebuffer;
|
||||
use types::display::{Color, Dimension, ScreenCoord};
|
||||
|
||||
pub struct MockFramebuffer {
|
||||
width: u16,
|
||||
height: u16,
|
||||
pixels: [(u16, u16, u32); 4096],
|
||||
width: Dimension,
|
||||
height: Dimension,
|
||||
pixels: [(ScreenCoord, ScreenCoord, Color); 4096],
|
||||
pixel_count: usize,
|
||||
flushed: bool,
|
||||
}
|
||||
|
||||
impl MockFramebuffer {
|
||||
pub fn new(width: u16, height: u16) -> Self {
|
||||
pub fn new(width: Dimension, height: Dimension) -> Self {
|
||||
Self {
|
||||
width,
|
||||
height,
|
||||
pixels: [(0, 0, 0); 4096],
|
||||
pixels: [(ScreenCoord::new(0), ScreenCoord::new(0), Color::from_raw(0)); 4096],
|
||||
pixel_count: 0,
|
||||
flushed: false,
|
||||
}
|
||||
@@ -29,31 +30,31 @@ impl MockFramebuffer {
|
||||
self.flushed
|
||||
}
|
||||
|
||||
pub fn pixel_at(&self, index: usize) -> (u16, u16, u32) {
|
||||
pub fn pixel_at(&self, index: usize) -> (ScreenCoord, ScreenCoord, Color) {
|
||||
self.pixels[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl Framebuffer for MockFramebuffer {
|
||||
fn width(&self) -> u16 { self.width }
|
||||
fn height(&self) -> u16 { self.height }
|
||||
fn width(&self) -> Dimension { self.width }
|
||||
fn height(&self) -> Dimension { self.height }
|
||||
|
||||
fn write_pixel(&mut self, x: u16, y: u16, color: u32) {
|
||||
fn write_pixel(&mut self, x: ScreenCoord, y: ScreenCoord, color: Color) {
|
||||
if self.pixel_count < self.pixels.len() {
|
||||
self.pixels[self.pixel_count] = (x, y, color);
|
||||
self.pixel_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn fill_rect(&mut self, x: u16, y: u16, w: u16, h: u16, color: u32) {
|
||||
for dy in 0..h {
|
||||
for dx in 0..w {
|
||||
self.write_pixel(x + dx, y + dy, color);
|
||||
fn fill_rect(&mut self, x: ScreenCoord, y: ScreenCoord, w: Dimension, h: Dimension, color: Color) {
|
||||
for dy in 0..h.raw() {
|
||||
for dx in 0..w.raw() {
|
||||
self.write_pixel(ScreenCoord::new(x.raw() + dx), ScreenCoord::new(y.raw() + dy), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn clear(&mut self, _color: u32) {
|
||||
fn clear(&mut self, _color: Color) {
|
||||
self.pixel_count = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user