Skip to content

Commit 16ea806

Browse files
authored
Merge pull request #207 from ryanbreen/feat/audio-bell-and-fixes
feat: tab completion bell chime and sound driver cleanup
2 parents 1c3f145 + cc09e5e commit 16ea806

File tree

25 files changed

+1517
-1359
lines changed

25 files changed

+1517
-1359
lines changed

kernel/src/arch_impl/aarch64/elf.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub fn load_elf_into_page_table(
281281
// Validate ELF header
282282
let header = validate_elf_header(data)?;
283283

284-
crate::serial_println!(
284+
log::debug!(
285285
"[elf-arm64] Loading ELF into process page table: entry={:#x}, {} program headers",
286286
header.entry,
287287
header.phnum
@@ -323,7 +323,7 @@ pub fn load_elf_into_page_table(
323323
// Page-align the heap start (4KB alignment)
324324
let heap_start = (max_segment_end + 0xfff) & !0xfff;
325325

326-
crate::serial_println!(
326+
log::debug!(
327327
"[elf-arm64] Loaded: base={:#x}, end={:#x}, entry={:#x}",
328328
if min_load_addr == u64::MAX { 0 } else { min_load_addr },
329329
heap_start,
@@ -359,7 +359,7 @@ fn load_segment_into_page_table(
359359
return Err("Segment data out of bounds");
360360
}
361361

362-
crate::serial_println!(
362+
log::trace!(
363363
"[elf-arm64] Loading segment: vaddr={:#x}, filesz={:#x}, memsz={:#x}, flags={:#x}",
364364
vaddr.as_u64(),
365365
file_size,
@@ -388,7 +388,7 @@ fn load_segment_into_page_table(
388388
page_flags |= PageTableFlags::NO_EXECUTE;
389389
}
390390

391-
crate::serial_println!(
391+
log::trace!(
392392
"[elf-arm64] Segment permissions: R={}, W={}, X={}",
393393
segment_readable,
394394
segment_writable,
@@ -411,7 +411,7 @@ fn load_segment_into_page_table(
411411

412412
let (frame, already_mapped) = if let Some(existing_phys) = existing_phys_opt {
413413
let existing_frame = PhysFrame::containing_address(PhysAddr::new(existing_phys.as_u64()));
414-
crate::serial_println!(
414+
log::trace!(
415415
"[elf-arm64] Page {:#x} already mapped to frame {:#x}, reusing",
416416
page_vaddr.as_u64(),
417417
existing_frame.start_address().as_u64()
@@ -422,7 +422,7 @@ fn load_segment_into_page_table(
422422
let new_frame = crate::memory::frame_allocator::allocate_frame()
423423
.ok_or("Out of memory allocating frame for ELF segment")?;
424424

425-
crate::serial_println!(
425+
log::trace!(
426426
"[elf-arm64] Allocated frame {:#x} for page {:#x}",
427427
new_frame.start_address().as_u64(),
428428
page_vaddr.as_u64()
@@ -473,7 +473,7 @@ fn load_segment_into_page_table(
473473
core::ptr::copy_nonoverlapping(src, dst, copy_size);
474474
}
475475

476-
crate::serial_println!(
476+
log::trace!(
477477
"[elf-arm64] Copied {} bytes to frame {:#x} (page {:#x}) at offset {}",
478478
copy_size,
479479
frame_phys_addr.as_u64(),
@@ -491,7 +491,7 @@ fn load_segment_into_page_table(
491491
count
492492
};
493493

494-
crate::serial_println!(
494+
log::trace!(
495495
"[elf-arm64] Successfully loaded segment with {} pages",
496496
page_count
497497
);

kernel/src/arch_impl/aarch64/syscall_entry.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,14 @@ fn dispatch_syscall(
396396
SyscallNumber::Pause | SyscallNumber::Sigsuspend => (-38_i64) as u64,
397397

398398
// I/O syscalls (ARM64 io module)
399-
SyscallNumber::Write => result_to_u64(crate::syscall::io::sys_write(arg1, arg2, arg3)),
400-
SyscallNumber::Read => result_to_u64(crate::syscall::io::sys_read(arg1, arg2, arg3)),
399+
SyscallNumber::Write => result_to_u64(crate::syscall::handlers::sys_write(arg1, arg2, arg3)),
400+
SyscallNumber::Read => result_to_u64(crate::syscall::handlers::sys_read(arg1, arg2, arg3)),
401401
SyscallNumber::Close => result_to_u64(crate::syscall::pipe::sys_close(arg1 as i32)),
402-
SyscallNumber::Dup => result_to_u64(crate::syscall::io::sys_dup(arg1)),
403-
SyscallNumber::Dup2 => result_to_u64(crate::syscall::io::sys_dup2(arg1, arg2)),
404-
SyscallNumber::Fcntl => result_to_u64(crate::syscall::io::sys_fcntl(arg1, arg2, arg3)),
405-
SyscallNumber::Poll => result_to_u64(crate::syscall::io::sys_poll(arg1, arg2, arg3 as i32)),
406-
SyscallNumber::Select => result_to_u64(crate::syscall::io::sys_select(arg1 as i32, arg2, arg3, arg4, arg5)),
402+
SyscallNumber::Dup => result_to_u64(crate::syscall::handlers::sys_dup(arg1)),
403+
SyscallNumber::Dup2 => result_to_u64(crate::syscall::handlers::sys_dup2(arg1, arg2)),
404+
SyscallNumber::Fcntl => result_to_u64(crate::syscall::handlers::sys_fcntl(arg1, arg2, arg3)),
405+
SyscallNumber::Poll => result_to_u64(crate::syscall::handlers::sys_poll(arg1, arg2, arg3 as i32)),
406+
SyscallNumber::Select => result_to_u64(crate::syscall::handlers::sys_select(arg1 as i32, arg2, arg3, arg4, arg5)),
407407
SyscallNumber::Ioctl => result_to_u64(crate::syscall::ioctl::sys_ioctl(arg1, arg2, arg3)),
408408
SyscallNumber::Pipe => result_to_u64(crate::syscall::pipe::sys_pipe(arg1)),
409409
SyscallNumber::Pipe2 => result_to_u64(crate::syscall::pipe::sys_pipe2(arg1, arg2)),
@@ -488,6 +488,10 @@ fn dispatch_syscall(
488488
SyscallNumber::FbMmap => result_to_u64(crate::syscall::graphics::sys_fbmmap()),
489489
SyscallNumber::GetMousePos => result_to_u64(crate::syscall::graphics::sys_get_mouse_pos(arg1)),
490490

491+
// Audio syscalls
492+
SyscallNumber::AudioInit => result_to_u64(crate::syscall::audio::sys_audio_init()),
493+
SyscallNumber::AudioWrite => result_to_u64(crate::syscall::audio::sys_audio_write(arg1, arg2)),
494+
491495
// Testing/diagnostic syscalls
492496
SyscallNumber::CowStats => sys_cow_stats_aarch64(arg1),
493497
SyscallNumber::SimulateOom => sys_simulate_oom_aarch64(arg1),

kernel/src/drivers/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ pub fn init() -> usize {
5454
}
5555
}
5656

57+
// Initialize VirtIO sound driver
58+
match virtio::sound::init() {
59+
Ok(()) => {
60+
log::info!("VirtIO sound driver initialized successfully");
61+
}
62+
Err(e) => {
63+
log::warn!("VirtIO sound driver initialization failed: {}", e);
64+
}
65+
}
66+
5767
log::info!("Driver subsystem initialized");
5868
device_count
5969
}
@@ -123,6 +133,16 @@ pub fn init() -> usize {
123133
}
124134
}
125135

136+
// Initialize VirtIO sound driver
137+
match virtio::sound_mmio::init() {
138+
Ok(()) => {
139+
serial_println!("[drivers] VirtIO sound driver initialized");
140+
}
141+
Err(e) => {
142+
serial_println!("[drivers] VirtIO sound driver init failed: {}", e);
143+
}
144+
}
145+
126146
serial_println!("[drivers] Driver subsystem initialized");
127147
device_count
128148
}

kernel/src/drivers/pci.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub const VIRTIO_VENDOR_ID: u16 = 0x1AF4;
4545
pub const VIRTIO_BLOCK_DEVICE_ID_LEGACY: u16 = 0x1001;
4646
/// VirtIO block device ID (modern)
4747
pub const VIRTIO_BLOCK_DEVICE_ID_MODERN: u16 = 0x1042;
48+
/// VirtIO sound device ID (legacy)
49+
pub const VIRTIO_SOUND_DEVICE_ID_LEGACY: u16 = 0x1019;
50+
/// VirtIO sound device ID (modern)
51+
pub const VIRTIO_SOUND_DEVICE_ID_MODERN: u16 = 0x1059;
4852
/// VirtIO network device ID (legacy)
4953
pub const VIRTIO_NET_DEVICE_ID_LEGACY: u16 = 0x1000;
5054
/// VirtIO network device ID (modern)
@@ -196,6 +200,12 @@ impl Device {
196200
}
197201

198202
/// Check if this is any network controller
203+
pub fn is_virtio_sound(&self) -> bool {
204+
self.is_virtio()
205+
&& (self.device_id == VIRTIO_SOUND_DEVICE_ID_LEGACY
206+
|| self.device_id == VIRTIO_SOUND_DEVICE_ID_MODERN)
207+
}
208+
199209
pub fn is_network(&self) -> bool {
200210
self.class == DeviceClass::Network
201211
}
@@ -679,3 +689,13 @@ pub fn find_virtio_net_devices() -> Vec<Device> {
679689
None => Vec::new(),
680690
}
681691
}
692+
693+
/// Find all VirtIO sound devices
694+
#[allow(dead_code)] // Part of public API, will be used by VirtIO sound driver
695+
pub fn find_virtio_sound_devices() -> Vec<Device> {
696+
let devices = PCI_DEVICES.lock();
697+
match devices.as_ref() {
698+
Some(devs) => devs.iter().filter(|d| d.is_virtio_sound()).cloned().collect(),
699+
None => Vec::new(),
700+
}
701+
}

kernel/src/drivers/virtio/input_mmio.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,18 @@ pub fn handle_interrupt() {
644644
}
645645
}
646646

647+
// Generate VT100 escape sequences for special keys
648+
// (arrows, Home, End, Delete) that can't be represented
649+
// as a single character.
650+
if let Some(seq) = keycode_to_escape_seq(keycode) {
651+
for &b in seq {
652+
if !crate::tty::push_char_nonblock(b) {
653+
crate::ipc::stdin::push_byte_from_irq(b);
654+
}
655+
}
656+
continue;
657+
}
658+
647659
let shift = SHIFT_PRESSED.load(core::sync::atomic::Ordering::Relaxed);
648660
let caps = CAPS_LOCK_ACTIVE.load(core::sync::atomic::Ordering::Relaxed);
649661
let ctrl = CTRL_PRESSED.load(core::sync::atomic::Ordering::Relaxed);
@@ -900,6 +912,21 @@ pub fn keycode_to_char(code: u16, shift: bool) -> Option<char> {
900912
Some(c)
901913
}
902914

915+
/// Convert a Linux keycode to a VT100 escape sequence for special keys
916+
/// that require multi-byte output (arrow keys, Home, End, Delete).
917+
fn keycode_to_escape_seq(code: u16) -> Option<&'static [u8]> {
918+
match code {
919+
103 => Some(b"\x1b[A"), // Up
920+
108 => Some(b"\x1b[B"), // Down
921+
106 => Some(b"\x1b[C"), // Right
922+
105 => Some(b"\x1b[D"), // Left
923+
102 => Some(b"\x1b[H"), // Home
924+
107 => Some(b"\x1b[F"), // End
925+
111 => Some(b"\x1b[3~"), // Delete
926+
_ => None,
927+
}
928+
}
929+
903930
/// Check if a keycode is a modifier key
904931
pub fn is_modifier(code: u16) -> bool {
905932
matches!(code,

kernel/src/drivers/virtio/mmio.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub mod device_id {
5656
pub const SCSI: u32 = 8;
5757
pub const GPU: u32 = 16;
5858
pub const INPUT: u32 = 18;
59+
pub const SOUND: u32 = 25;
5960
}
6061

6162
/// VirtIO MMIO register offsets
@@ -403,6 +404,7 @@ pub fn device_type_name(device_id: u32) -> &'static str {
403404
device_id::SCSI => "SCSI",
404405
device_id::GPU => "GPU",
405406
device_id::INPUT => "input",
407+
device_id::SOUND => "sound",
406408
_ => "unknown",
407409
}
408410
}

kernel/src/drivers/virtio/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ pub mod net_mmio;
3333
pub mod gpu_mmio;
3434
#[cfg(target_arch = "aarch64")]
3535
pub mod input_mmio;
36+
#[cfg(target_arch = "aarch64")]
37+
pub mod sound_mmio;
38+
39+
#[cfg(target_arch = "x86_64")]
40+
pub mod sound;
3641

3742
#[cfg(target_arch = "x86_64")]
3843
use x86_64::instructions::port::Port;

0 commit comments

Comments
 (0)