PIT Timer settable
This commit is contained in:
parent
f6143d3895
commit
64d6e1e166
2
ableos/Cargo.lock
generated
2
ableos/Cargo.lock
generated
|
@ -24,7 +24,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ableos"
|
name = "ableos"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ab_glyph",
|
"ab_glyph",
|
||||||
"acpi",
|
"acpi",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
name = "ableos"
|
name = "ableos"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
@ -5,6 +5,7 @@ use crate::{
|
||||||
rhai_shell::KEYBUFF,
|
rhai_shell::KEYBUFF,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use cpuio::outb;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use pic8259::ChainedPics;
|
use pic8259::ChainedPics;
|
||||||
use spin;
|
use spin;
|
||||||
|
@ -20,6 +21,8 @@ pub static PICS: spin::Mutex<ChainedPics> =
|
||||||
pub enum InterruptIndex {
|
pub enum InterruptIndex {
|
||||||
Timer = PIC_1_OFFSET,
|
Timer = PIC_1_OFFSET,
|
||||||
Keyboard,
|
Keyboard,
|
||||||
|
// SecondInterrupt = PIC_2_OFFSET,
|
||||||
|
Cmos = 0x70,
|
||||||
}
|
}
|
||||||
impl InterruptIndex {
|
impl InterruptIndex {
|
||||||
fn as_u8(self) -> u8 {
|
fn as_u8(self) -> u8 {
|
||||||
|
@ -38,10 +41,18 @@ lazy_static! {
|
||||||
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
||||||
unsafe {
|
unsafe {
|
||||||
idt.double_fault.set_handler_fn(double_fault_handler)
|
idt.double_fault.set_handler_fn(double_fault_handler)
|
||||||
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX); // new
|
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This gives fast interrupts
|
||||||
|
set_pit_frequency(1000);
|
||||||
|
|
||||||
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
|
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
|
||||||
idt[InterruptIndex::Keyboard.as_usize()] .set_handler_fn(keyboard_interrupt_handler);
|
idt[InterruptIndex::Keyboard.as_usize()] .set_handler_fn(keyboard_interrupt_handler);
|
||||||
|
|
||||||
|
idt[6].set_handler_fn(floppy_disk_interrupt_handler);
|
||||||
|
|
||||||
|
|
||||||
idt
|
idt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -128,16 +139,17 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
extern "x86-interrupt" fn floppy_disk_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||||
extern "x86-interrupt" fn page_fault_handler(
|
println!("EXCEPTION: FLOPPY DISK");
|
||||||
stack_frame: InterruptStackFrame,
|
}
|
||||||
error_code: PageFaultErrorCode,
|
|
||||||
) {
|
fn set_pit_frequency(freq: u32) {
|
||||||
use x86_64::registers::control::Cr2;
|
let divisor: u16 = (1193180 / freq).try_into().unwrap();
|
||||||
println!["Exception: Page Fault"];
|
|
||||||
println!["Address: {:?}", Cr2::read()];
|
unsafe {
|
||||||
println!["Error Code: {:?}", error_code];
|
outb(0x36, 0x43);
|
||||||
println!["{:#?}", stack_frame];
|
|
||||||
sloop();
|
outb((divisor & 0xFF) as u8, 0x40);
|
||||||
|
outb((divisor >> 8) as u8, 0x40);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ pub fn kernel_main() -> ! {
|
||||||
/// called by arch specific timers to tick up all kernel related functions
|
/// called by arch specific timers to tick up all kernel related functions
|
||||||
pub fn tick() {
|
pub fn tick() {
|
||||||
let mut data = TICK.load(Relaxed);
|
let mut data = TICK.load(Relaxed);
|
||||||
data += 1;
|
data = data.wrapping_add(1);
|
||||||
|
|
||||||
crate::kernel_state::KERNEL_STATE.lock().update_state();
|
crate::kernel_state::KERNEL_STATE.lock().update_state();
|
||||||
// let mut scheduler = SCHEDULER.lock();
|
// let mut scheduler = SCHEDULER.lock();
|
||||||
|
|
|
@ -97,3 +97,5 @@ pub use syscalls::*;
|
||||||
pub mod scratchpad;
|
pub mod scratchpad;
|
||||||
pub use scratchpad::*;
|
pub use scratchpad::*;
|
||||||
pub mod filesystem;
|
pub mod filesystem;
|
||||||
|
|
||||||
|
pub mod messaging;
|
||||||
|
|
0
ableos/src/messaging/NOTES.md
Normal file
0
ableos/src/messaging/NOTES.md
Normal file
100
ableos/src/messaging/mod.rs
Normal file
100
ableos/src/messaging/mod.rs
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
use {
|
||||||
|
crate::{kmain::TICK, proc::PID},
|
||||||
|
alloc::string::String,
|
||||||
|
core::{
|
||||||
|
fmt::{Display, Formatter, Result as FmtResult},
|
||||||
|
result::Result,
|
||||||
|
sync::atomic::Ordering::Relaxed,
|
||||||
|
},
|
||||||
|
libwasm::syscalls::time_calls::SecondsTime,
|
||||||
|
x86_64::instructions::interrupts::{disable, enable},
|
||||||
|
};
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MessagingError {
|
||||||
|
MessageTooLarge,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for MessagingError {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||||
|
match self {
|
||||||
|
MessagingError::MessageTooLarge => write!(f, "Message too large"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Not properly implemented
|
||||||
|
pub fn fetch_time() -> SecondsTime {
|
||||||
|
disable();
|
||||||
|
let time = TICK.load(Relaxed);
|
||||||
|
enable();
|
||||||
|
|
||||||
|
SecondsTime {
|
||||||
|
seconds: time,
|
||||||
|
milliseconds: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type MessageSmall = [u8; 2048];
|
||||||
|
pub type MessageLarge = [u8; 16384];
|
||||||
|
|
||||||
|
pub enum Message {
|
||||||
|
Small(MessageSmall),
|
||||||
|
Large(MessageLarge),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ProcessMessage {
|
||||||
|
pub to_pid: PID,
|
||||||
|
pub from_pid: PID,
|
||||||
|
pub message: Message,
|
||||||
|
pub sender_time: SecondsTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProcessMessage {
|
||||||
|
pub fn new(to_pid: PID, from_pid: PID, message: Message) -> Self {
|
||||||
|
Self {
|
||||||
|
to_pid,
|
||||||
|
from_pid,
|
||||||
|
message,
|
||||||
|
sender_time: fetch_time(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_from_string(
|
||||||
|
to_pid: PID,
|
||||||
|
from_pid: PID,
|
||||||
|
string: String,
|
||||||
|
) -> Result<Self, MessagingError> {
|
||||||
|
let mut mssg = Message::Small([0u8; 2048]);
|
||||||
|
match string.len() {
|
||||||
|
0..=2047 => {
|
||||||
|
let mut message = [0u8; 2048];
|
||||||
|
for (i, c) in string.chars().enumerate() {
|
||||||
|
message[i] = c as u8;
|
||||||
|
}
|
||||||
|
mssg = Message::Small(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
2048..=16383 => {
|
||||||
|
let mut message = [0u8; 16384];
|
||||||
|
for (i, c) in string.chars().enumerate() {
|
||||||
|
message[i] = c as u8;
|
||||||
|
}
|
||||||
|
mssg = Message::Large(message);
|
||||||
|
}
|
||||||
|
_ => return Err(MessagingError::MessageTooLarge),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
to_pid,
|
||||||
|
from_pid,
|
||||||
|
message: mssg,
|
||||||
|
sender_time: fetch_time(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_sync_message(message: ProcessMessage) {}
|
||||||
|
pub fn send_async_message(message: ProcessMessage) {}
|
||||||
|
|
||||||
|
pub fn recv_sync_message() {}
|
||||||
|
pub fn recv_async_message() {}
|
|
@ -49,13 +49,13 @@ pub fn afetch() {
|
||||||
|
|
||||||
disable();
|
disable();
|
||||||
let tick_time = TICK.load(Relaxed);
|
let tick_time = TICK.load(Relaxed);
|
||||||
enable();
|
|
||||||
|
|
||||||
println!("OS: AbleOS");
|
println!("OS: AbleOS");
|
||||||
println!("Host: {}", kstate.hostname);
|
println!("Host: {}", kstate.hostname);
|
||||||
println!("Kernel: AKern-{}-v{}", RELEASE_TYPE, KERNEL_VERSION);
|
println!("Kernel: AKern-{}-v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||||
println!("Uptime: {}", tick_time);
|
println!("Uptime: {}", tick_time);
|
||||||
|
|
||||||
|
enable();
|
||||||
drop(kstate);
|
drop(kstate);
|
||||||
}
|
}
|
||||||
pub fn set_hostname(name: String) {
|
pub fn set_hostname(name: String) {
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
use crate::{absi::colorify, rhai_shell::rhai_shell};
|
use core::arch::asm;
|
||||||
|
|
||||||
|
use alloc::string::{String, ToString};
|
||||||
|
use cpuio::outb;
|
||||||
|
|
||||||
|
use crate::{absi::colorify, messaging::ProcessMessage, rhai_shell::rhai_shell};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
|
@ -38,6 +43,12 @@ pub fn scratchpad() {
|
||||||
*/
|
*/
|
||||||
// interp();
|
// interp();
|
||||||
// crate::experiments::absi::colorify();
|
// crate::experiments::absi::colorify();
|
||||||
|
|
||||||
|
let message = "Hello, world!";
|
||||||
|
|
||||||
|
let xyz = ProcessMessage::new_from_string(PID(123), PID(0), message.to_string());
|
||||||
|
|
||||||
|
// print!("{:?}", xyz);
|
||||||
rhai_shell();
|
rhai_shell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,29 +79,3 @@ impl PortOps for PciIO {
|
||||||
cpuio::outl(val, port as u16);
|
cpuio::outl(val, port as u16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
/// An experimental process message format
|
|
||||||
pub struct ProcessMessage {
|
|
||||||
pub to_pid: PID,
|
|
||||||
pub from_pid: PID,
|
|
||||||
pub message: [u8; 2048],
|
|
||||||
|
|
||||||
pub sender_time: SecondsTime,
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// use libwasm::syscalls::time_calls::SecondsTime;
|
|
||||||
|
|
||||||
impl ProcessMessage {
|
|
||||||
pub fn new(to_pid: PID, from_pid: PID, message: [u8; 2048]) -> Self {
|
|
||||||
ProcessMessage {
|
|
||||||
to_pid,
|
|
||||||
from_pid,
|
|
||||||
message,
|
|
||||||
sender_time: SecondsTime {
|
|
||||||
seconds: 0,
|
|
||||||
milliseconds: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//!
|
//!
|
||||||
//!
|
//!
|
||||||
|
#[inline]
|
||||||
pub fn type_of<T>(_: &T) -> &str {
|
pub fn type_of<T>(_: &T) -> &str {
|
||||||
core::any::type_name::<T>()
|
core::any::type_name::<T>()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue