Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
b754a8f
EXT2: Added (yet untested) and incomplete implementation
amerikrainian Feb 22, 2025
3b4b5f0
Ext2: Add writing support (untested)
amerikrainian Feb 22, 2025
7da325c
Ext2: Add filesys tests
amerikrainian Feb 23, 2025
6d5ecf6
EXT2: Fix directories being written improperly
amerikrainian Feb 25, 2025
2c2ca12
EXT2: Fix tests not respecting 0 as sentinel for allocation
amerikrainian Feb 25, 2025
48a221d
Obey clippy
amerikrainian Mar 28, 2025
b4ca775
Remove dead code
amerikrainian Mar 28, 2025
ec4e851
Merge remote-tracking branch 'src/main' into ext2
kiranchandrasekhar Apr 6, 2025
fd3d795
Made EXT2 Async
kiranchandrasekhar Apr 6, 2025
f4e2641
SD integration of EXT2
kiranchandrasekhar Apr 6, 2025
daf0dcb
Made SD block size for BlockIO configurable
Apr 7, 2025
1b1b81b
Created actual filesystem image
Apr 7, 2025
9d4f636
Fixed formatting
Apr 7, 2025
0b2726f
Add tests for real now
Apr 8, 2025
98f85c2
Make EXT2 on Mac
kiranchandrasekhar Apr 8, 2025
eeeb9ad
Fixed spin in interrupt
kiranchandrasekhar Apr 8, 2025
5a8cfda
Add (currently broken) tests
amerikrainian Apr 10, 2025
a41593b
Passed most ext2 tests
amerikrainian Apr 10, 2025
c6bb40b
Zero out blocks for ext2
amerikrainian Apr 10, 2025
221a47a
Ext2 code refactor
amerikrainian Apr 10, 2025
a9644e4
Remove unnecessary arcs
amerikrainian Apr 11, 2025
337da89
Remove fat16
amerikrainian Apr 11, 2025
a78f2ba
add sysroot script
pgosar Apr 17, 2025
62cb847
add test case to open c executable from file and run it
pgosar Apr 17, 2025
cfcd30c
add mmap call
pgosar Apr 17, 2025
445a399
correctly clean up build artifacts
pgosar Apr 17, 2025
e78df8c
fixed buffer bounds error in read_file
anooprac Apr 17, 2025
170ab98
Migrating to main repo
kiranchandrasekhar Apr 17, 2025
7e99c9f
Merged with mmap
kiranchandrasekhar Apr 17, 2025
d8f23a2
Open skeleton
kiranchandrasekhar Apr 18, 2025
7c00cd0
Merge remote-tracking branch 'origin/main' into syscalls
kiranchandrasekhar Apr 18, 2025
eb290c1
stashed pawait
kiranchandrasekhar Apr 18, 2025
8a5b606
Fake blocking
kiranchandrasekhar Apr 18, 2025
6fdaec2
unknown syscall 107
pgosar Apr 19, 2025
a004a8f
Fix keyboard and mouse to properly follow ps2 protocol
amerikrainian Apr 19, 2025
f0760bb
Merge remote-tracking branch 'origin/sysroot' into syscalls
KshitijKapoor8 Apr 20, 2025
2744a15
merge sysroot - ext2 err
KshitijKapoor8 Apr 20, 2025
5956b12
Basic syscalls, arch_prctl
KshitijKapoor8 Apr 21, 2025
b0357c2
Real block_on
kiranchandrasekhar Apr 21, 2025
c919e09
pulled
kiranchandrasekhar Apr 21, 2025
0600573
register keypresses
pgosar Apr 22, 2025
4c97778
sometimes working shell
pgosar Apr 22, 2025
856669a
properly initialize shell
pgosar Apr 22, 2025
2650790
move up fd to 2
pgosar Apr 22, 2025
327b843
clear keyboard buffer
pgosar Apr 22, 2025
7ece24c
partially nonblocking shell
pgosar Apr 22, 2025
7a53cd7
finished not blocking
pgosar Apr 22, 2025
1f89494
Merge branch 'sysroot' into shell
pgosar Apr 22, 2025
70e94e4
Merged from main
kiranchandrasekhar Apr 22, 2025
96bf5fe
fixed unknown command constantly
pgosar Apr 23, 2025
1b44733
Vma errors
kiranchandrasekhar Apr 23, 2025
4489e7d
cmd arg and env var support for shell and exec
pgosar Apr 23, 2025
7d0b49b
everything working except for envp not being able to be read
pgosar Apr 23, 2025
07a97e3
Major preemption refactor
kiranchandrasekhar Apr 24, 2025
23dfd60
mostly working refactor
kiranchandrasekhar Apr 24, 2025
158a004
Can block from syscalls (make sys_func async and invoke with block_on…
kiranchandrasekhar Apr 24, 2025
e6d542c
continue debugging envp
pgosar Apr 24, 2025
e1bb725
block on mmap
pgosar Apr 24, 2025
280d688
Merge branch 'shell' into syscalls
pgosar Apr 24, 2025
92bc921
remove asm file
pgosar Apr 24, 2025
24fc810
rm ds store
pgosar Apr 24, 2025
8d9f11b
Arch PRCTL
kiranchandrasekhar Apr 25, 2025
707ee6b
Merge branch 'main' into syscalls
pgosar Apr 25, 2025
f545bdb
make shell module
pgosar Apr 25, 2025
67175fe
merge
kiranchandrasekhar Apr 25, 2025
e73ed0d
Fix block memory leak
kiranchandrasekhar Apr 25, 2025
d030427
Fix double reading file working
amerikrainian Apr 27, 2025
3cb6160
Removed unecessary block_on
kiranchandrasekhar Apr 28, 2025
d4ff48a
attempt to add with overflow
pgosar Apr 29, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
*.hdd
*.img
*.txt
*.od

/target
.vscode

.DS_Store
4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

5 changes: 2 additions & 3 deletions kernel/limage_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ base_args = [

# Graphics
"-vga", "std",

"-serial", "stdio",
# Debugging traces
# USB
# "-trace", "usb*",
Expand All @@ -44,7 +44,7 @@ base_args = [

[modes]
terminal = { args = ["-nographic"] }
gui = { args = [] }
gui = { args = ["-serial", "stdio"] }
gdb-terminal = { args = ["-nographic", "-s", "-S"] }
gdb-gui = { args = ["-s", "-S"] }

Expand All @@ -54,6 +54,5 @@ success_exit_code = 33
no_reboot = true
extra_args = [
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04",
"-serial", "stdio",
"-display", "none"
]
4 changes: 2 additions & 2 deletions kernel/src/constants/processes.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Process related constants

// Binaries used for tests
pub const PRINT_EXIT: &[u8] = include_bytes!("../processes/test_binaries/print_exit");

pub const FORK_SIMPLE: &[u8] = include_bytes!("../processes/test_binaries/fork_simple");

pub const TEST_SIMPLE_PROCESS: &[u8] =
Expand All @@ -14,6 +12,8 @@ pub const TEST_PRINT_EXIT: &[u8] = include_bytes!("../processes/test_binaries/te

pub const TEST_WAIT: &[u8] = include_bytes!("../processes/test_binaries/test_wait");

pub const TEST_SLEEP: &[u8] = include_bytes!("../processes/test_binaries/sleep");

pub const TEST_FORK_COW: &[u8] = include_bytes!("../processes/test_binaries/test_fork_cow");

pub const TEST_MMAP_ANON_SHARED: &[u8] =
Expand Down
27 changes: 26 additions & 1 deletion kernel/src/constants/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,37 @@

pub const SYSCALL_EXIT: u32 = 60;
pub const SYSCALL_NANOSLEEP: u32 = 35;
pub const SYSCALL_PRINT: u32 = 3;

pub const SYSCALL_PRINT: u32 = 1003;

pub const SYSCALL_READ: u32 = 0;
pub const SYSCALL_WRITE: u32 = 1;
pub const SYSCALL_OPEN: u32 = 2;
pub const SYSCALL_CLOSE: u32 = 3;

pub const SYSCALL_ACCESS: u32 = 21;

pub const SYSCALL_SCHED_YIELD: u32 = 24;

pub const SYSCALL_CREAT: u32 = 85;

pub const SYSCALL_FUTEX: u32 = 202;
pub const SYSCALL_OPENAT: u32 = 257;

pub const SYSCALL_GETRANDOM: u32 = 318;

pub const SYSCALL_MMAP: u32 = 4;
pub const SYSCALL_MPROTECT: u32 = 10;
pub const SYSCALL_MUNMAP: u32 = 11;
pub const SYSCALL_FORK: u32 = 5;
pub const SYSCALL_WAIT: u32 = 6;
pub const SYSCALL_EXECVE: u32 = 59;

pub const SYSCALL_GETUID: u32 = 102;
pub const SYSCALL_GETEUID: u32 = 107;
pub const SYSCALL_GETGID: u32 = 104;
pub const SYSCALL_GETEGID: u32 = 108;
pub const SYSCALL_ARCH_PRCTL: u32 = 158;

// Mmap
pub const START_MMAP_ADDRESS: u64 = 0x0900_0000_0000;
22 changes: 21 additions & 1 deletion kernel/src/devices/ps2_dev/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::{
devices::ps2_dev::controller,
events::{futures::sync::BlockMutex, schedule_kernel},
events::{futures::sync::BlockMutex, schedule_kernel, yield_now},
interrupts::idt::without_interrupts,
serial_println,
};
Expand All @@ -19,6 +19,7 @@ use lazy_static::lazy_static;
use pc_keyboard::{
layouts, DecodedKey, Error, HandleControl, KeyCode, KeyState, Keyboard, Modifiers, ScancodeSet2,
};
use ps2::flags::ControllerStatusFlags;
use spin::Mutex;

/// Maximum number of keyboard events to store in the buffer
Expand Down Expand Up @@ -258,6 +259,25 @@ pub fn keyboard_handler() {
});
}

pub async fn flush_buffer() {
loop {
if let Ok(mut kb) = KEYBOARD.try_lock() {
// got the lock, clear it
kb.clear_buffer();
controller::with_controller(|ctrl| {
while ctrl
.read_status()
.contains(ControllerStatusFlags::OUTPUT_FULL)
{
let _ = ctrl.read_data();
}
});
return;
}
yield_now().await;
}
}

impl Stream for KeyboardStream {
type Item = KeyboardEvent;

Expand Down
4 changes: 4 additions & 0 deletions kernel/src/events/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl Event {
completed: AtomicBool::new(false),
}
}

pub fn id(&self) -> u64 {
self.eid.0
}
}

impl ArcWake for Event {
Expand Down
23 changes: 20 additions & 3 deletions kernel/src/events/event_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl EventRunner {
if !self.have_unblocked_events() {
break;
}

self.current_event = self.next_event();

let event = self
Expand All @@ -66,6 +65,7 @@ impl EventRunner {

// Executes the event
let ready: bool = future_guard.as_mut().poll(&mut context) != Poll::Pending;
interrupts::disable();

drop(future_guard);

Expand All @@ -84,6 +84,8 @@ impl EventRunner {
// Event is ready, go ahead and remove it
event.completed.swap(true, Ordering::Relaxed);
self.pending_events.write().remove(&event.eid.0);

crate::debug!("Event {} done", event.eid.0);
}
}

Expand All @@ -92,6 +94,8 @@ impl EventRunner {
// Explicitly re-enable interrupts once the current event is unmarked
// Helps with run_process_ring3(), which shouldn't be pre-empted
// TODO can maybe refactor and safely remove

// TODO do a lil work-stealing
interrupts::enable();
}

Expand All @@ -100,8 +104,6 @@ impl EventRunner {
self.awake_next_sleeper();
}

// TODO do a lil work-stealing

// Sleep until next interrupt
interrupts::enable_and_hlt();
}
Expand Down Expand Up @@ -259,6 +261,12 @@ impl EventRunner {
self.current_event.as_ref().map(|e| {
let system_ticks = nanos_to_ticks(nanos);

crate::debug!(
"Sleeping @ {}, to be awoken @ {}",
self.system_clock,
self.system_clock + system_ticks
);

let sleep = Sleep::new(self.system_clock + system_ticks, (*e).clone());
self.sleeping_events.push(sleep.clone());
self.blocked_events.write().insert(e.eid.0);
Expand Down Expand Up @@ -305,6 +313,15 @@ impl EventRunner {
}
}

/// Blocks the current event until awoken
///
/// # Returns
/// * `Option<Block>` - A Block future that can be awaited on (if there is an event to block)
#[allow(dead_code)]
pub fn block_current_event(&mut self) -> Option<Sleep> {
todo!();
}

/// # Returns
/// * `bool` - true if there are blocked events on this runner
fn have_blocked_events(&self) -> bool {
Expand Down
3 changes: 1 addition & 2 deletions kernel/src/events/tasks/yield_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ impl Default for Yield {
impl Future for Yield {
type Output = ();

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
if self.yielded {
Poll::Ready(())
} else {
self.yielded = true;
cx.waker().wake_by_ref();
Poll::Pending
}
}
Expand Down
5 changes: 3 additions & 2 deletions kernel/src/filesys/ext2/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,11 @@ impl Ext2 {

let size = node.size() as usize;
let mut buffer = vec![0; size];
node.read_at(pos as u64, &mut buffer)
let s = node
.read_at(pos as u64, &mut buffer)
.await
.map_err(FilesystemError::NodeError)?;

buffer.resize(s, 0);
Ok(buffer)
}

Expand Down
1 change: 1 addition & 0 deletions kernel/src/filesys/ext2/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ impl Node {

async fn read_raw_at(&self, offset: u64, buffer: &mut [u8]) -> NodeResult<usize> {
let size = self.size();

if offset >= size {
return Ok(0);
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/filesys/ext2/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ mod tests {
#[test_case]
async fn test_superblock_block_size() {
let mut sb = Superblock::default();

// sb.block_size_shift = 0; // 1024 bytes
assert_eq!(sb.block_size(), 1024);

sb.block_size_shift = 1; // 2048 bytes
Expand Down
Loading