Skip to content

Commit cd79a3c

Browse files
committed
kernel: Add mouse
cilibc: Extend stdint. Extend stdlib
1 parent c3dd3a7 commit cd79a3c

File tree

18 files changed

+906
-521
lines changed

18 files changed

+906
-521
lines changed

_todo.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@ command structure for kernel access, not reliant on fio
22
command buffer
33
fire and block
44
fire and forget
5+
6+
no idea what those are ^
7+
8+
message passing
9+
expose kernel font somehow (broadcast message and kernel replies?)
10+
^ done-ish temp file that gives the font when read
11+
12+
sleeping
13+
wait queue, sleep until time is met? maybe that works!

circinus.code-workspace

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"editor.tabSize": 2,
1717
"editor.insertSpaces": true,
1818
"C_Cpp.clang_format_style": "LLVM",
19-
"C_Cpp.enhancedColorization": "enabled"
19+
"C_Cpp.enhancedColorization": "enabled",
20+
"rust-analyzer.cargo.cfgs": {
21+
"target_arch": "x86_64",
22+
}
2023
}
2124
}

environment/Cargo.toml

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ path = "lib.rs"
1212
[dependencies]
1313
log = "0.4.17"
1414
x86 = "0.52.0"
15-
vte = "0.11.0"
15+
vte = "0.13.0"
1616
spin = "0.9.3"
1717
cfg-if = "1.0.0"
18-
bitflags = "1.3.2"
18+
bitflags = "2.4.2"
1919
atomic_refcell = "0.1.8"
20-
pc-keyboard = "0.6.0"
21-
lazy_static = { version = "1.4.0", default-features = false, features = ["spin_no_std"] }
20+
21+
pc-keyboard = "0.7.0"
22+
ps2-mouse = "0.1.4"
23+
24+
lazy_static = { version = "1.4.0", default-features = false, features = [
25+
"spin_no_std",
26+
] }
2227

2328
buddy_system_allocator = { version = "0.8.0", features = ["const_fn"] }
2429
arrayvec = { version = "0.7.2", default-features = false }

environment/lib.rs

+80-74
Original file line numberDiff line numberDiff line change
@@ -7,103 +7,109 @@ extern crate alloc;
77
#[macro_use]
88
extern crate log;
99
use address::UserVAddr;
10+
use ps2_mouse::MouseState;
1011
use utils::static_cell::StaticCell;
1112

1213
#[macro_use]
1314
pub mod print;
1415

1516
pub trait System: Sync {
16-
fn on_console_rx(&self, char: u8);
17-
fn on_irq(&self, irq: u8);
18-
fn on_timer_irq(&self);
19-
fn on_page_fault(
20-
&self,
21-
unaligned_vaddr: Option<UserVAddr>,
22-
ip: usize,
23-
_reason: arch::PageFaultReason,
24-
);
25-
26-
#[allow(clippy::too_many_arguments)]
27-
fn on_syscall(
28-
&self,
29-
a1: usize,
30-
a2: usize,
31-
a3: usize,
32-
a4: usize,
33-
a5: usize,
34-
a6: usize,
35-
n: usize,
36-
frame: *mut arch::PtRegs,
37-
) -> isize;
38-
39-
#[cfg(debug_assertions)]
40-
fn usercopy_hook(&self);
17+
fn on_console_rx(&self, char: u8);
18+
#[cfg(target_arch = "x86_64")]
19+
fn on_mouse_event(&self, mouse_state: MouseState);
20+
fn on_irq(&self, irq: u8);
21+
fn on_timer_irq(&self);
22+
fn on_page_fault(
23+
&self,
24+
unaligned_vaddr: Option<UserVAddr>,
25+
ip: usize,
26+
_reason: arch::PageFaultReason,
27+
);
28+
29+
#[allow(clippy::too_many_arguments)]
30+
fn on_syscall(
31+
&self,
32+
a1: usize,
33+
a2: usize,
34+
a3: usize,
35+
a4: usize,
36+
a5: usize,
37+
a6: usize,
38+
n: usize,
39+
frame: *mut arch::PtRegs,
40+
) -> isize;
41+
42+
#[cfg(debug_assertions)]
43+
fn usercopy_hook(&self);
4144
}
4245

4346
static SYSTEM: StaticCell<&dyn System> = StaticCell::new(&NopSystem);
4447
struct NopSystem;
4548

4649
impl System for NopSystem {
47-
fn on_console_rx(&self, _char: u8) {}
48-
49-
fn on_irq(&self, _irq: u8) {}
50-
51-
fn on_timer_irq(&self) {}
52-
53-
fn on_page_fault(
54-
&self,
55-
_unaligned_vaddr: Option<UserVAddr>,
56-
_ip: usize,
57-
_reason: arch::PageFaultReason,
58-
) {
59-
}
60-
61-
fn on_syscall(
62-
&self,
63-
_a1: usize,
64-
_a2: usize,
65-
_a3: usize,
66-
_a4: usize,
67-
_a5: usize,
68-
_a6: usize,
69-
_n: usize,
70-
_frame: *mut arch::PtRegs,
71-
) -> isize {
72-
0
73-
}
74-
75-
#[cfg(debug_assertions)]
76-
fn usercopy_hook(&self) {}
50+
fn on_console_rx(&self, _char: u8) {}
51+
52+
#[cfg(target_arch = "x86_64")]
53+
fn on_mouse_event(&self, _mouse_state: MouseState) {}
54+
55+
fn on_irq(&self, _irq: u8) {}
56+
57+
fn on_timer_irq(&self) {}
58+
59+
fn on_page_fault(
60+
&self,
61+
_unaligned_vaddr: Option<UserVAddr>,
62+
_ip: usize,
63+
_reason: arch::PageFaultReason,
64+
) {
65+
}
66+
67+
fn on_syscall(
68+
&self,
69+
_a1: usize,
70+
_a2: usize,
71+
_a3: usize,
72+
_a4: usize,
73+
_a5: usize,
74+
_a6: usize,
75+
_n: usize,
76+
_frame: *mut arch::PtRegs,
77+
) -> isize {
78+
0
79+
}
80+
81+
#[cfg(debug_assertions)]
82+
fn usercopy_hook(&self) {}
7783
}
7884

7985
fn system() -> &'static dyn System {
80-
SYSTEM.load()
86+
SYSTEM.load()
8187
}
8288

8389
pub fn set_system(system: &'static dyn System) {
84-
SYSTEM.store(system);
90+
SYSTEM.store(system);
8591
}
8692

8793
mod x64;
8894

8995
pub mod arch {
90-
pub use crate::x64::{
91-
backtrace::Backtrace,
92-
cpu_local::cpu_local_head,
93-
idle::{halt, idle},
94-
interrupt::SavedInterruptStatus,
95-
ioapic::enable_irq,
96-
paging::PageTable,
97-
profile::read_clock_counter,
98-
serial::SERIAL0,
99-
syscall::PtRegs,
100-
tss::TSS,
101-
PageFaultReason, KERNEL_BASE_ADDR, KERNEL_STRAIGHT_MAP_PADDR_END, PAGE_SIZE, TICK_HZ,
102-
};
103-
104-
pub mod x64 {
105-
pub use crate::x64::gdt::{USER_CS64, USER_DS, USER_RPL};
106-
}
96+
pub use crate::x64::{
97+
backtrace::Backtrace,
98+
cpu_local::cpu_local_head,
99+
idle::{halt, idle},
100+
interrupt::SavedInterruptStatus,
101+
ioapic::enable_irq,
102+
paging::PageTable,
103+
profile::read_clock_counter,
104+
serial::SERIAL0,
105+
syscall::PtRegs,
106+
tss::TSS,
107+
PageFaultReason, KERNEL_BASE_ADDR, KERNEL_STRAIGHT_MAP_PADDR_END, PAGE_SIZE, TICK_HZ,
108+
};
109+
110+
pub mod x64 {
111+
pub use crate::x64::gdt::{USER_CS64, USER_DS, USER_RPL};
112+
}
107113
}
108114

109115
pub mod address;

environment/x64/boot.rs

+64-63
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,94 @@
11
use x86::{
2-
controlregs::{self, Cr4, Xcr0},
3-
cpuid::CpuId,
4-
io::outb,
2+
controlregs::{self, Cr4, Xcr0},
3+
cpuid::CpuId,
4+
io::outb,
55
};
66

77
use super::{apic, bootinfo, cpu_local, gdt, idt, ioapic, pit, serial, syscall, tss, vga};
88
use crate::{
9-
address::{PAddr, VAddr},
10-
bootinfo::BootInfo,
11-
logger, page_allocator,
12-
x64::pc8042,
9+
address::{PAddr, VAddr},
10+
bootinfo::BootInfo,
11+
logger, page_allocator,
12+
x64::{mouse, pc8042},
1313
};
1414

1515
fn check_cpuid_feature(name: &str, supported: bool) {
16-
if !supported {
17-
panic!("{} is not supprted on this machine", name);
18-
}
16+
if !supported {
17+
panic!("{} is not supprted on this machine", name);
18+
}
1919
}
2020

2121
/// Enables some CPU features.
2222
unsafe fn common_setup(cpu_local_area: VAddr) {
23-
let feats = CpuId::new().get_feature_info().unwrap();
24-
let ex_feats = CpuId::new().get_extended_feature_info().unwrap();
25-
check_cpuid_feature("XSAVE", feats.has_xsave());
26-
check_cpuid_feature("FSGSBASE", ex_feats.has_fsgsbase());
27-
28-
let mut cr4 = controlregs::cr4();
29-
cr4 |= Cr4::CR4_ENABLE_FSGSBASE
30-
| Cr4::CR4_ENABLE_OS_XSAVE
31-
| Cr4::CR4_ENABLE_SSE
32-
| Cr4::CR4_UNMASKED_SSE;
33-
controlregs::cr4_write(cr4);
34-
35-
let mut xcr0 = controlregs::xcr0();
36-
xcr0 |= Xcr0::XCR0_SSE_STATE | Xcr0::XCR0_AVX_STATE;
37-
controlregs::xcr0_write(xcr0);
38-
39-
cpu_local::init(cpu_local_area);
40-
apic::init();
41-
ioapic::init();
42-
gdt::init();
43-
tss::init();
44-
idt::init();
45-
pit::init();
46-
syscall::init();
23+
let feats = CpuId::new().get_feature_info().unwrap();
24+
let ex_feats = CpuId::new().get_extended_feature_info().unwrap();
25+
check_cpuid_feature("XSAVE", feats.has_xsave());
26+
check_cpuid_feature("FSGSBASE", ex_feats.has_fsgsbase());
27+
28+
let mut cr4 = controlregs::cr4();
29+
cr4 |= Cr4::CR4_ENABLE_FSGSBASE
30+
| Cr4::CR4_ENABLE_OS_XSAVE
31+
| Cr4::CR4_ENABLE_SSE
32+
| Cr4::CR4_UNMASKED_SSE;
33+
controlregs::cr4_write(cr4);
34+
35+
let mut xcr0 = controlregs::xcr0();
36+
xcr0 |= Xcr0::XCR0_SSE_STATE | Xcr0::XCR0_AVX_STATE;
37+
controlregs::xcr0_write(xcr0);
38+
39+
cpu_local::init(cpu_local_area);
40+
apic::init();
41+
ioapic::init();
42+
gdt::init();
43+
tss::init();
44+
idt::init();
45+
pit::init();
46+
syscall::init();
4747
}
4848

4949
/// Disables PIC. We use APIC instead.
5050
unsafe fn init_pic() {
51-
outb(0xa1, 0xff);
52-
outb(0x21, 0xff);
53-
54-
outb(0x20, 0x11);
55-
outb(0xa0, 0x11);
56-
outb(0x21, 0x20);
57-
outb(0xa1, 0x28);
58-
outb(0x21, 0x04);
59-
outb(0xa1, 0x02);
60-
outb(0x21, 0x01);
61-
outb(0xa1, 0x01);
62-
63-
outb(0xa1, 0xff);
64-
outb(0x21, 0xff);
51+
outb(0xa1, 0xff);
52+
outb(0x21, 0xff);
53+
54+
outb(0x20, 0x11);
55+
outb(0xa0, 0x11);
56+
outb(0x21, 0x20);
57+
outb(0xa1, 0x28);
58+
outb(0x21, 0x04);
59+
outb(0xa1, 0x02);
60+
outb(0x21, 0x01);
61+
outb(0xa1, 0x01);
62+
63+
outb(0xa1, 0xff);
64+
outb(0x21, 0xff);
6565
}
6666

6767
extern "Rust" {
68-
fn boot_kernel(bootinfo: &BootInfo) -> !;
68+
fn boot_kernel(bootinfo: &BootInfo) -> !;
6969
}
7070

7171
#[no_mangle]
7272
unsafe extern "C" fn bsp_early_init(boot_magic: u32, boot_params: u64) -> ! {
73-
extern "C" {
74-
static __bsp_cpu_local: u8;
75-
}
73+
extern "C" {
74+
static __bsp_cpu_local: u8;
75+
}
7676

77-
serial::early_init();
78-
vga::init();
79-
logger::init();
77+
serial::early_init();
78+
vga::init();
79+
logger::init();
8080

81-
pc8042::init();
81+
pc8042::init();
82+
mouse::init();
8283

83-
let boot_info = bootinfo::parse(boot_magic, PAddr::new(boot_params as usize));
84-
page_allocator::init(&boot_info.ram_areas);
84+
let boot_info = bootinfo::parse(boot_magic, PAddr::new(boot_params as usize));
85+
page_allocator::init(&boot_info.ram_areas);
8586

86-
logger::set_log_filter(&boot_info.log_filter);
87+
logger::set_log_filter(&boot_info.log_filter);
8788

88-
serial::init(boot_info.use_second_serialport);
89-
init_pic();
90-
common_setup(VAddr::new(&__bsp_cpu_local as *const _ as usize));
89+
serial::init(boot_info.use_second_serialport);
90+
init_pic();
91+
common_setup(VAddr::new(&__bsp_cpu_local as *const _ as usize));
9192

92-
boot_kernel(&boot_info);
93+
boot_kernel(&boot_info);
9394
}

0 commit comments

Comments
 (0)