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:
@@ -1,9 +1,10 @@
|
||||
use server_framework::{Decode, Encode};
|
||||
use types::display::{Color, Dimension, ScreenCoord};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum DisplayRequest {
|
||||
DrawRect { x: u16, y: u16, w: u16, h: u16, color: u32 },
|
||||
Clear { color: u32 },
|
||||
DrawRect { x: ScreenCoord, y: ScreenCoord, w: Dimension, h: Dimension, color: Color },
|
||||
Clear { color: Color },
|
||||
Flush,
|
||||
GetDimensions,
|
||||
}
|
||||
@@ -11,7 +12,7 @@ pub enum DisplayRequest {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum DisplayResponse {
|
||||
Ok,
|
||||
Dimensions { width: u16, height: u16 },
|
||||
Dimensions { width: Dimension, height: Dimension },
|
||||
Error,
|
||||
}
|
||||
|
||||
@@ -19,11 +20,11 @@ impl Encode for DisplayRequest {
|
||||
fn encode(&self) -> [usize; 4] {
|
||||
match self {
|
||||
DisplayRequest::DrawRect { x, y, w, h, color } => {
|
||||
let xy = (*x as usize) | ((*y as usize) << 16);
|
||||
let wh = (*w as usize) | ((*h as usize) << 16);
|
||||
[0, xy, wh, *color as usize]
|
||||
let xy = (x.raw() as usize) | ((y.raw() as usize) << 16);
|
||||
let wh = (w.raw() as usize) | ((h.raw() as usize) << 16);
|
||||
[0, xy, wh, color.raw() as usize]
|
||||
}
|
||||
DisplayRequest::Clear { color } => [1, *color as usize, 0, 0],
|
||||
DisplayRequest::Clear { color } => [1, color.raw() as usize, 0, 0],
|
||||
DisplayRequest::Flush => [2, 0, 0, 0],
|
||||
DisplayRequest::GetDimensions => [3, 0, 0, 0],
|
||||
}
|
||||
@@ -34,14 +35,14 @@ impl Decode for DisplayRequest {
|
||||
fn decode(words: [usize; 4]) -> Option<Self> {
|
||||
match words[0] {
|
||||
0 => {
|
||||
let x = (words[1] & 0xFFFF) as u16;
|
||||
let y = ((words[1] >> 16) & 0xFFFF) as u16;
|
||||
let w = (words[2] & 0xFFFF) as u16;
|
||||
let h = ((words[2] >> 16) & 0xFFFF) as u16;
|
||||
let color = words[3] as u32;
|
||||
let x = ScreenCoord::new((words[1] & 0xFFFF) as u16);
|
||||
let y = ScreenCoord::new(((words[1] >> 16) & 0xFFFF) as u16);
|
||||
let w = Dimension::new((words[2] & 0xFFFF) as u16);
|
||||
let h = Dimension::new(((words[2] >> 16) & 0xFFFF) as u16);
|
||||
let color = Color::from_raw(words[3] as u32);
|
||||
Some(DisplayRequest::DrawRect { x, y, w, h, color })
|
||||
}
|
||||
1 => Some(DisplayRequest::Clear { color: words[1] as u32 }),
|
||||
1 => Some(DisplayRequest::Clear { color: Color::from_raw(words[1] as u32) }),
|
||||
2 => Some(DisplayRequest::Flush),
|
||||
3 => Some(DisplayRequest::GetDimensions),
|
||||
_ => None,
|
||||
@@ -54,7 +55,7 @@ impl Encode for DisplayResponse {
|
||||
match self {
|
||||
DisplayResponse::Ok => [0, 0, 0, 0],
|
||||
DisplayResponse::Dimensions { width, height } => {
|
||||
[1, *width as usize, *height as usize, 0]
|
||||
[1, width.raw() as usize, height.raw() as usize, 0]
|
||||
}
|
||||
DisplayResponse::Error => [2, 0, 0, 0],
|
||||
}
|
||||
@@ -66,8 +67,8 @@ impl Decode for DisplayResponse {
|
||||
match words[0] {
|
||||
0 => Some(DisplayResponse::Ok),
|
||||
1 => Some(DisplayResponse::Dimensions {
|
||||
width: words[1] as u16,
|
||||
height: words[2] as u16,
|
||||
width: Dimension::new(words[1] as u16),
|
||||
height: Dimension::new(words[2] as u16),
|
||||
}),
|
||||
2 => Some(DisplayResponse::Error),
|
||||
_ => None,
|
||||
|
||||
Reference in New Issue
Block a user