Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 52 additions & 9 deletions crates/console/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,32 @@ mod vt100;
use display_client::proto;
use gfx::{color, format};

use ulib::sys::{pipe, pwrite_all, spawn_elf, FileDesc, SpawnArgs};
use ulib::sys::{pipe, pwrite_all, spawn_elf, ArgStr, FileDesc, SpawnArgs};

#[no_mangle]
pub extern "C" fn main() {
fn main(argc: usize, argv: *const *const u8) {
let argv_array = unsafe { core::slice::from_raw_parts(argv, argc) };
let args = argv_array
.iter()
.copied()
.map(|arg| unsafe { core::ffi::CStr::from_ptr(arg) }.to_bytes())
.map(|arg| core::str::from_utf8(arg).unwrap())
.collect::<alloc::vec::Vec<_>>();

let remaining_args;
let mut scale = 1;

if let (Some("--scale"), Some(scale_str)) = (args.get(1).map(|s| *s), args.get(2)) {
if let Ok(s) = scale_str.parse::<usize>() {
scale = s;
}
remaining_args = &args[3..];
} else if args.len() > 0 {
remaining_args = &args[1..];
} else {
remaining_args = &[];
}

// Useful font resources:
// - https://adafruit.github.io/web-bdftopcf/
// - https://github.com/Tecate/bitmap-fonts
Expand All @@ -31,22 +53,19 @@ pub extern "C" fn main() {
.unwrap();
let mut font_data = alloc::vec![0; size as usize];
let font_data = lz4::decode_into(compressed_font, &mut font_data).unwrap();

let font = format::pcf::load_pcf(font_data).unwrap();

let mut buf = display_client::connect(320, 240);
let mut buf = display_client::connect(320 * scale as u16, 240 * scale as u16);

let (width, height) = (
buf.video_meta.width as usize,
buf.video_meta.height as usize,
);
let row_stride = buf.video_meta.row_stride as usize / 4;

println!("Filling screen");
buf.video_mem().fill(color::rgba(0, 0, 0, 255));

let char_dims = font.dimensions();
let scale = 1;
let hpad = 2;
let vpad = 0;

Expand All @@ -69,15 +88,34 @@ pub extern "C" fn main() {
let mut editor = editor::LineEditor::new();

let cwd = 3;
let fd = ulib::sys::openat(cwd, b"shell", 0, 0).unwrap();
let fd;

if remaining_args.len() > 1 {
fd = ulib::sys::openat(cwd, remaining_args[0].as_bytes(), 0, 0);
} else {
fd = ulib::sys::openat(cwd, b"/shell", 0, 0);
}
let fd = match fd {
Ok(f) => f,
Err(_) => {
println!("Failed to open executable.");
ulib::sys::exit(1);
}
};

let (_shell, shell_stdin_tx, shell_stdout_rx) = {
let (shell, shell_stdin_tx, shell_stdout_rx) = {
let (shell_stdin_rx, shell_stdin_tx) = pipe(0).unwrap();
let (shell_stdout_rx, shell_stdout_tx) = pipe(0).unwrap();

let shell = spawn_elf(&SpawnArgs {
fd,
args: &[],
args: &remaining_args
.iter()
.map(|a| ArgStr {
len: a.len(),
ptr: a.as_ptr(),
})
.collect::<alloc::vec::Vec<_>>(),
stdin: Some(shell_stdin_rx),
stdout: Some(shell_stdout_tx),
stderr: Some(shell_stdout_tx),
Expand All @@ -89,6 +127,11 @@ pub extern "C" fn main() {
'outer: loop {
let time_us = unsafe { ulib::sys::sys_get_time_ms() as u64 } * 1000;

if let Some(_) = ulib::sys::try_wait(shell) {
println!("Console child exited, exiting.");
break;
}

while let Some(ev) = buf.server_to_client_queue().try_recv() {
match ev.kind {
proto::EventKind::INPUT => {
Expand Down
8 changes: 4 additions & 4 deletions crates/display-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn handle_incoming(
}

fn init_buffer(width: usize, height: usize) -> BufferInfo {
println!("init_buffer");
// println!("[disp] init_buffer({}, {})", width, height);
let vmem_size = width * height * 4;

let header_size = size_of::<proto::BufferHeader>().next_multiple_of(4096);
Expand All @@ -93,7 +93,7 @@ fn init_buffer(width: usize, height: usize) -> BufferInfo {
let fd = unsafe { ulib::sys::sys_memfd_create() } as u32;

let buffer = unsafe { mmap(0, total_size, 0, 0, fd, 0) }.unwrap();
println!("buffer allocated, {buffer:p}");
// println!("buffer allocated, {buffer:p}");

let present_sem_fd = ulib::sys::sem_create(0).unwrap();
let present_sem = proto::SemDescriptor(1);
Expand Down Expand Up @@ -126,10 +126,10 @@ fn init_buffer(width: usize, height: usize) -> BufferInfo {
present_sem,
};

println!("Writing header");
// println!("Writing header");
let ptr = buffer.cast::<proto::BufferHeader>();
unsafe { ptr.write(header) };
println!("init done");
// println!("init done");

BufferInfo {
fd,
Expand Down
90 changes: 0 additions & 90 deletions crates/init/ls.rs

This file was deleted.

167 changes: 0 additions & 167 deletions crates/init/shell.rs

This file was deleted.

Loading
Loading