1
0
Fork 0
forked from AbleOS/ableos

please bugs begone

This commit is contained in:
koniifer 2024-09-16 20:15:51 +01:00 committed by Able
parent 2321efd2e7
commit df74b09134
11 changed files with 121 additions and 141 deletions

35
Cargo.lock generated
View file

@ -390,25 +390,38 @@ dependencies = [
[[package]]
name = "hbbytecode"
version = "0.1.0"
<<<<<<< HEAD
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4a9b9de87fd56a6bbd5d0ca2c622104d4807612b"
=======
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#faf068885a42aedbb6a2bc50e21cb6d34f211cdb"
>>>>>>> 1f4fce0 (please bugs begone)
[[package]]
name = "hbbytecode"
version = "0.1.0"
source = "git+https://git.ablecorp.us/ableos/holey-bytes.git#6968e7d769d905c41fbe4c195d9d34d3339c32cf"
source = "git+https://git.ablecorp.us/ableos/holey-bytes.git#faf068885a42aedbb6a2bc50e21cb6d34f211cdb"
[[package]]
name = "hblang"
version = "0.1.0"
<<<<<<< HEAD
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4a9b9de87fd56a6bbd5d0ca2c622104d4807612b"
=======
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#faf068885a42aedbb6a2bc50e21cb6d34f211cdb"
>>>>>>> 1f4fce0 (please bugs begone)
dependencies = [
"hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
"regalloc2",
]
[[package]]
name = "hbvm"
version = "0.1.0"
<<<<<<< HEAD
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4a9b9de87fd56a6bbd5d0ca2c622104d4807612b"
=======
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#faf068885a42aedbb6a2bc50e21cb6d34f211cdb"
>>>>>>> 1f4fce0 (please bugs begone)
dependencies = [
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
]
@ -416,7 +429,7 @@ dependencies = [
[[package]]
name = "hbvm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/ableos/holey-bytes.git#6968e7d769d905c41fbe4c195d9d34d3339c32cf"
source = "git+https://git.ablecorp.us/ableos/holey-bytes.git#faf068885a42aedbb6a2bc50e21cb6d34f211cdb"
dependencies = [
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/ableos/holey-bytes.git)",
]
@ -526,9 +539,9 @@ dependencies = [
[[package]]
name = "iana-time-zone"
version = "0.1.60"
version = "0.1.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
dependencies = [
"android_system_properties",
"core-foundation-sys",
@ -737,9 +750,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.20.0"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "paste"
@ -899,6 +912,16 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "regalloc2"
version = "0.10.2"
source = "git+https://github.com/jakubDoka/regalloc2.git#34d8424a0d74746d231a96239fdb32e3d5ec0245"
dependencies = [
"hashbrown",
"rustc-hash",
"smallvec",
]
[[package]]
name = "regex-syntax"
version = "0.8.4"

View file

@ -12,7 +12,7 @@ use {
pub const DOUBLE_FAULT_IX: u16 = 0;
const STACK_SIZE: usize = 5 * 1024;
const STACK_ALIGNMENT: usize = 4096;
const STACK_ALIGNMENT: usize = 1;
pub unsafe fn init() {
use x86_64::instructions::{
@ -39,7 +39,7 @@ static TSS: Lazy<TaskStateSegment> = Lazy::new(|| {
let stack_ptr = unsafe {
let layout = alloc::alloc::Layout::from_size_align(STACK_SIZE, STACK_ALIGNMENT)
.expect("Failed to create stack layout");
let stack = alloc::alloc::alloc_zeroed(layout);
let stack = alloc::alloc::alloc(layout);
VirtAddr::from_ptr(stack) + STACK_SIZE as u64
};

View file

@ -1,56 +1,52 @@
// TODO: Turn apic keyboard interrupt into a standard ipc message
use {
core::mem::MaybeUninit,
log::trace,
spin::{Lazy, Mutex},
x2apic::lapic::{LocalApic, LocalApicBuilder},
x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode},
};
pub unsafe fn init() {
trace!("Initialising IDT");
IDT.load();
Lazy::force(&LAPIC);
x86_64::instructions::interrupts::enable();
}
/// Safety: Using LAPIC or IDT before init() is UB
/// Using
static mut LAPIC: LocalApic = unsafe { MaybeUninit::zeroed().assume_init() };
static mut IDT: InterruptDescriptorTable = unsafe { MaybeUninit::zeroed().assume_init() };
#[repr(u8)]
enum Interrupt {
Timer = 32,
ApicErr = u8::MAX - 1,
Spurious = u8::MAX,
}
pub(crate) static LAPIC: Lazy<Mutex<LocalApic>> = Lazy::new(|| {
let mut lapic = LocalApicBuilder::new()
pub unsafe fn init() {
trace!("Initializing IDT and LAPIC");
// Initialize and load the IDT
IDT = InterruptDescriptorTable::new();
IDT.double_fault
.set_handler_fn(double_fault)
.set_stack_index(super::gdt::DOUBLE_FAULT_IX);
IDT.page_fault.set_handler_fn(page_fault);
IDT[Interrupt::ApicErr as u8].set_handler_fn(apic_err);
IDT[Interrupt::Spurious as u8].set_handler_fn(spurious);
IDT[Interrupt::Timer as u8].set_handler_fn(timer);
IDT.load();
LAPIC = LocalApicBuilder::new()
.timer_vector(Interrupt::Timer as usize)
.error_vector(Interrupt::ApicErr as usize)
.spurious_vector(Interrupt::Spurious as usize)
.set_xapic_base(
unsafe { x2apic::lapic::xapic_base() }
x2apic::lapic::xapic_base()
+ super::memory::HHDM_OFFSET.load(core::sync::atomic::Ordering::Relaxed),
)
.build()
.expect("failed to setup Local APIC");
unsafe { lapic.enable() };
Mutex::new(lapic)
});
.expect("Failed to setup Local APIC");
LAPIC.enable();
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
let mut idt = InterruptDescriptorTable::new();
unsafe {
idt.double_fault
.set_handler_fn(double_fault)
.set_stack_index(super::gdt::DOUBLE_FAULT_IX);
}
idt.page_fault.set_handler_fn(page_fault);
idt[Interrupt::ApicErr as u8].set_handler_fn(apic_err);
idt[Interrupt::Spurious as u8].set_handler_fn(spurious);
idt[Interrupt::Timer as u8].set_handler_fn(timer);
idt
});
x86_64::instructions::interrupts::enable();
}
extern "x86-interrupt" fn double_fault(stack_frame: InterruptStackFrame, error_code: u64) -> ! {
panic!("Double fault: error code {error_code} \n{stack_frame:#?}")
@ -64,7 +60,9 @@ extern "x86-interrupt" fn page_fault(
}
extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) {
unsafe { LAPIC.lock().end_of_interrupt() };
unsafe {
LAPIC.end_of_interrupt();
}
}
extern "x86-interrupt" fn apic_err(_: InterruptStackFrame) {
@ -72,5 +70,7 @@ extern "x86-interrupt" fn apic_err(_: InterruptStackFrame) {
}
extern "x86-interrupt" fn spurious(_: InterruptStackFrame) {
unsafe { LAPIC.lock().end_of_interrupt() };
unsafe {
LAPIC.end_of_interrupt();
}
}

View file

@ -13,7 +13,7 @@ use {
pub fn handler(vm: &mut Vm) {
let ecall_number = vm.registers[2].cast::<u64>();
log::info!("eca called :pensive:");
// debug!("Ecall number {:?}", ecall_number);
//info!("Register dump: {:?}", vm.registers);
@ -97,43 +97,35 @@ pub fn handler(vm: &mut Vm) {
let msg_vec = block_read(mem_addr, length);
let msg_type = msg_vec[0];
match msg_type {
0 => {
0 => unsafe {
let size = msg_vec[1];
let addr = u16::from_le_bytes(msg_vec[2..4].try_into().unwrap());
let value = unsafe {
match size {
0 => x86_in::<u8>(addr) as u64,
1 => x86_in::<u16>(addr) as u64,
2 => x86_in::<u32>(addr) as u64,
_ => panic!("how?"),
}
let value = match size {
0 => x86_in::<u8>(addr) as u64,
1 => x86_in::<u16>(addr) as u64,
2 => x86_in::<u32>(addr) as u64,
_ => panic!("Trying to read size other than: 8, 16, 32 from port."),
};
info!("Read the value {} from address {}", value, addr);
// info!("Read the value {} from address {}", value, addr);
vm.registers[1] = hbvm::value::Value(value);
}
1 => {
},
1 => unsafe {
let size = msg_vec[1];
let addr = u16::from_le_bytes(msg_vec[2..4].try_into().unwrap());
trace!("Setting address {}", addr);
unsafe {
match size {
0 => x86_out(addr, msg_vec[4]),
1 => x86_out(
addr,
u16::from_le_bytes(
msg_vec[4..6].try_into().unwrap_unchecked(),
),
),
2 => x86_out(
addr,
u32::from_le_bytes(
msg_vec[4..8].try_into().unwrap_unchecked(),
),
),
_ => panic!("How?"),
}
match size {
0 => x86_out(addr, msg_vec[4]),
1 => x86_out(
addr,
u16::from_le_bytes(msg_vec[4..6].try_into().unwrap_unchecked()),
),
2 => x86_out(
addr,
u32::from_le_bytes(msg_vec[4..8].try_into().unwrap_unchecked()),
),
_ => panic!("How?"),
}
}
},
_ => {}
}
}

View file

@ -1,6 +1,6 @@
use {
crate::holeybytes::{kernel_services::block_read, Vm},
alloc::alloc::{alloc_zeroed, dealloc},
alloc::alloc::{alloc, dealloc},
core::alloc::Layout,
log::{debug, info},
};
@ -17,7 +17,7 @@ pub enum MemoryQuotaType {
}
fn alloc_page(vm: &mut Vm, _mem_addr: u64, _length: usize) -> Result<(), MemoryServiceError> {
let ptr = unsafe { alloc_zeroed(Layout::new::<[u8; 4096]>()) };
let ptr = unsafe { alloc(Layout::from_size_align_unchecked(4096, 4096)) };
info!("Block address: {:?}", ptr);
vm.registers[1] = hbvm::value::Value(ptr as u64);
vm.registers[2] = hbvm::value::Value(4096);
@ -40,9 +40,9 @@ pub fn memory_msg_handler(
log::debug!("Allocating {} pages @ {:x}", page_count, mptr);
let ptr = unsafe {
alloc_zeroed(Layout::from_size_align_unchecked(
alloc(Layout::from_size_align_unchecked(
page_count as usize * 4096,
1,
4096,
))
};
@ -59,7 +59,7 @@ pub fn memory_msg_handler(
unsafe {
dealloc(
mptr as *mut u8,
Layout::from_size_align_unchecked(page_count as usize * 4096, 1),
Layout::from_size_align_unchecked(page_count as usize * 4096, 4096),
)
}
}

View file

@ -3,7 +3,7 @@ mod kernel_services;
mod mem;
use {
alloc::alloc::{alloc_zeroed, dealloc},
alloc::alloc::{alloc, dealloc},
core::{
alloc::Layout,
future::Future,
@ -102,5 +102,5 @@ const fn stack_layout() -> Layout {
#[inline(always)]
fn allocate_stack() -> *mut u8 {
unsafe { alloc_zeroed(stack_layout()) }
unsafe { alloc(stack_layout()) }
}

View file

@ -3,6 +3,7 @@
//! Akern is woefully undersupported at the moment but we are looking to add support improve hardware discovery and make our lives as kernel and operating system developers easier and better
#![no_std]
#![feature(
exclusive_wrapper,
new_uninit,
abi_x86_interrupt,
alloc_error_handler,

View file

@ -1,2 +0,0 @@
# KVStore
This is a small single process in memory key value store.

View file

@ -1,37 +0,0 @@
Message := struct {
msg_type: u8,
key: String,
value: String,
}
/*
# Message Type
0 => Set Key type
1 => Get Key
*/
recv_msg:= fn(): Message {
return Message.{
msg_type: 0,
key: "",
value: "",
}
}
main := fn(): int {
loop {
msg := recv_msg();
if msg.msg_type == 0 {
continue;
}
if msg.msg_type == 1 {
continue;
}
if 2 <= msg.msg_type {
error("Unexpected message type in the bagging area");
continue;
}
}
return 0;
}

View file

@ -6,28 +6,31 @@ send_byte := fn(byte: u8): u8 {
}
main := fn(): int {
send_byte(238)
log.info("PS/2 Driver Loaded\0")
if send_byte(238) == 238 {
log.info("PS/2 Keyboard Echoed\0")
}
a := 0
a += 1
if send_byte(244) == 250 {
log.info("Enabled scanning\0")
}
buf := buffer.create("XKeyboard\0")
ptr := memory.request_page(1)
prev_input := 250
loop {
input := memory.inb(96)
if input == prev_input {
continue
}
prev_input = input
keycode_str := string.display_int(input, ptr)
log.info(string.display_int(input, ptr))
buffer.send_message(keycode_str, buf)
}
memory.outb(96, 238)
// memory.inb(96)
// send_byte(238)
// log.info("PS/2 Driver Loaded\0")
// if send_byte(238) == 238 {
// log.info("PS/2 Keyboard Echoed\0")
// }
// a := 0
// a += 1
// if send_byte(244) == 250 {
// log.info("Enabled scanning\0")
// }
// buf := buffer.create("XKeyboard\0")
// ptr := memory.request_page(1)
// prev_input := 250
// loop {
// input := memory.inb(96)
// if input == prev_input {
// continue
// }
// prev_input = input
// keycode_str := string.display_int(input, ptr)
// log.info(string.display_int(input, ptr))
// buffer.send_message(keycode_str, buf)
// }
return 0
}

View file

@ -1,4 +1,4 @@
.{example} := @use("./examples/colors.hb")
.{example} := @use("./examples/amogus.hb")
main := fn(): void {
@inline(example)