Merge branch 'riscv'

pls-build-on-my-machine
Able 2022-03-11 14:20:28 -06:00
commit 912206078c
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
25 changed files with 501 additions and 329 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ qprofiler
userland/*/target
kernel/target
kernel/target

View File

@ -1,5 +1,5 @@
[build]
target = "./json_targets/x86_64-ableos.json"
target = "riscv64gc-unknown-none-elf"
[unstable]
build-std = ["core", "compiler_builtins", "alloc"]

177
ableos/Cargo.lock generated
View File

@ -4,9 +4,9 @@ version = 3
[[package]]
name = "ab_glyph"
version = "0.2.13"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61caed9aec6daeee1ea38ccf5fb225e4f96c1eeead1b4a5c267324a63cf02326"
checksum = "24606928a235e73cdef55a0c909719cadd72fce573e5713d58cb2952d8f5794c"
dependencies = [
"ab_glyph_rasterizer",
"libm",
@ -48,17 +48,17 @@ dependencies = [
"pretty-hex",
"rdrand",
"rhai",
"riscv",
"rkyv",
"serde",
"shadeable",
"smoltcp",
"spin 0.5.2",
"toml",
"uart_16550",
"unicode-width",
"vga",
"volatile 0.2.7",
"wasmi",
"watson",
"x86_64",
"y-compositor-protocol",
]
@ -92,12 +92,27 @@ dependencies = [
"version_check",
]
[[package]]
name = "aho-corasick"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bare-metal"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603"
[[package]]
name = "beef"
version = "0.5.1"
@ -118,15 +133,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bootloader"
version = "0.9.21"
version = "0.9.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62c8f6168cd106687ee36a2b71a46c4144d73399f72814104d33094b8092fd2"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
checksum = "de78decc37247c7cfac5dbf3495c7298c6ac97cb355161caa7e15969c6648e6c"
[[package]]
name = "cfg-if"
@ -134,21 +143,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "conquer-once"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c6d3a9775a69f6d1fe2cc888999b67ed30257d3da4d2af91984e722f2ec918a"
dependencies = [
"conquer-util",
]
[[package]]
name = "conquer-util"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e763eef8846b13b380f37dfecda401770b0ca4e56e95170237bd7c25c7db3582"
[[package]]
name = "const-random"
version = "0.1.13"
@ -229,12 +223,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "font8x8"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
[[package]]
name = "genfs"
version = "0.1.4"
@ -243,9 +231,9 @@ checksum = "65b9e52a0ffd4c2f11f9f84e8885a40cb99f490971eee78bbd7ddffd6ac023d6"
[[package]]
name = "getrandom"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [
"cfg-if",
"libc",
@ -267,6 +255,12 @@ name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "hashbrown"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
dependencies = [
"ahash 0.7.6",
]
@ -300,9 +294,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.117"
version = "0.2.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
[[package]]
name = "libm"
@ -373,10 +367,10 @@ dependencies = [
]
[[package]]
name = "managed"
version = "0.8.0"
name = "memchr"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "memory_units"
@ -423,15 +417,15 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.9.0"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "owned_ttf_parser"
version = "0.14.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ef05f2882a8b3e7acc10c153ade2631f7bfc8ce00d2bf3fb8f4e9d2ae6ea5c3"
checksum = "4fb1e509cfe7a12db2a90bfa057dfcdbc55a347f5da677c506b53dd099cfec9d"
dependencies = [
"ttf-parser",
]
@ -530,6 +524,17 @@ dependencies = [
"rand_core",
]
[[package]]
name = "regex"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.25"
@ -565,12 +570,33 @@ dependencies = [
]
[[package]]
name = "rkyv"
version = "0.7.31"
name = "riscv"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439655b8d657bcb28264da8e5380d55549e34ffc4149bea9e3521890a122a7bd"
checksum = "6907ccdd7a31012b70faf2af85cd9e5ba97657cc3987c4f13f8e4d2c2a088aba"
dependencies = [
"hashbrown 0.11.2",
"bare-metal",
"bit_field",
"riscv-target",
]
[[package]]
name = "riscv-target"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88aa938cda42a0cf62a20cfe8d139ff1af20c2e681212b5b34adb5a58333f222"
dependencies = [
"lazy_static",
"regex",
]
[[package]]
name = "rkyv"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cdcf5caf69bcc87b1e3f5427b4f21a32fdd53c2847687bdf9861abb1cdaa0d8"
dependencies = [
"hashbrown 0.12.0",
"ptr_meta",
"rkyv_derive",
"seahash",
@ -578,9 +604,9 @@ dependencies = [
[[package]]
name = "rkyv_derive"
version = "0.7.31"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cded413ad606a80291ca84bedba137093807cf4f5b36be8c60f57a7e790d48f6"
checksum = "a6cf557da1f81b8c7e889c59c9c3abaf6978f7feb156b9579e4f8bf6d7a2bada"
dependencies = [
"proc-macro2",
"quote",
@ -641,7 +667,6 @@ dependencies = [
"libm",
"log",
"rhai",
"vga",
]
[[package]]
@ -652,25 +677,13 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]]
name = "smartstring"
version = "0.2.9"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31aa6a31c0c2b21327ce875f7e8952322acfcfd0c27569a6e18a647281352c9b"
checksum = "e714dff2b33f2321fdcd475b71cec79781a692d846f37f415fb395a1d2bcd48e"
dependencies = [
"static_assertions",
]
[[package]]
name = "smoltcp"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2308a1657c8db1f5b4993bab4e620bdbe5623bd81f254cf60326767bb243237"
dependencies = [
"bitflags",
"byteorder",
"log",
"managed",
]
[[package]]
name = "spin"
version = "0.5.2"
@ -732,9 +745,9 @@ dependencies = [
[[package]]
name = "ttf-parser"
version = "0.14.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ccbe8381883510b6a2d8f1e32905bddd178c11caef8083086d0c0c9ab0ac281"
checksum = "c74c96594835e10fa545e2a51e8709f30b173a092bfd6036ef2cec53376244f3"
[[package]]
name = "uart_16550"
@ -775,20 +788,6 @@ name = "versioning"
version = "0.1.2"
source = "git+https://git.ablecorp.us/able/versioning#ef472283e6e7a2e395ee56434087b3a6fad53ff2"
[[package]]
name = "vga"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67cbcb7bfff998d176ffb8f2c3dfd6cb0fe62740e36dee6c64fc3928c01001bf"
dependencies = [
"bitflags",
"conquer-once",
"font8x8",
"num-traits",
"spinning_top",
"x86_64",
]
[[package]]
name = "volatile"
version = "0.2.7"
@ -831,6 +830,22 @@ dependencies = [
"parity-wasm",
]
[[package]]
name = "watson"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cea7ead78c402dbf14e7f11911b0b48955ea13d46e012e2d98775e23c65d4ef"
dependencies = [
"serde",
"webassembly",
]
[[package]]
name = "webassembly"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d1a10e1dedffff9cfcbdd33c289c65b87da634259a460a3f23d513649fa7a8c"
[[package]]
name = "x86_64"
version = "0.14.8"

View File

@ -55,17 +55,17 @@ linked_list_allocator = "0.9.0"
lliw = "0.2.0"
# qoi_rs = "*"
spin = "0.5.2"
vga = "*"
# vga = "*"
log = "*"
pretty-hex = "0.2.1"
unicode-width = "0.1.7"
picorand = "*"
# watson = "0.4"
watson = "0.4"
genfs = "0.1.0"
# pc-beeper = "0.1.0"
pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"}
rhai = "1.5"
# pci = {git="https://gitlab.com/robigalia/pci"}
@ -103,13 +103,14 @@ version = "0.7.29"
default-features = false
features = ["size_64", "alloc"]
[dependencies.smoltcp]
version = "0.8.0"
default-features = false
features = ["log", "proto-ipv4"]
# [dependencies.smoltcp]
# version = "0.8.0"
# default-features = false
# features = ["log", "proto-ipv4"]
[dependencies.y-compositor-protocol]
git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
[dependencies.ext2]
git = "https://git.ablecorp.us:443/able/ext2-rs.git"
@ -145,6 +146,11 @@ version = "1.0"
[dependencies.externc-libm]
git = "https://git.ablecorp.us:443/able/externc-libm.git"
[target.'cfg(target_arch = "riscv")'.dependencies]
riscv="*"
[target.'cfg(target_arch = "x86_64")'.dependencies]
bootloader = { version = "0.9.8", features = ["map_physical_memory"] }
cpuio = { git = "https://git.ablecorp.us/ondra05/cpuio.git" }
@ -152,3 +158,4 @@ pic8259 = "0.10.1"
uart_16550 = "0.2.0"
volatile = "0.2.6"
x86_64 = "*"
pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"}

View File

@ -0,0 +1,36 @@
/// # Safety
///
/// We label the mmio function unsafe since
/// we will be working with raw memory. Rust cannot
/// make any guarantees when we do this.
///
#[inline(always)]
fn mmio_write(address: usize, offset: usize, value: u8) {
// Set the pointer based off of the address
let reg = address as *mut u8;
// write_volatile is a member of the *mut raw
// and we can use the .add() to give us another pointer
// at an offset based on the original pointer's memory
// address. NOTE: The add uses pointer arithmetic so it is
// new_pointer = old_pointer + sizeof(pointer_type) * offset
unsafe {
reg.add(offset).write_volatile(value);
}
}
/// # Safety
///
/// We label the mmio function unsafe since
/// we will be working with raw memory. Rust cannot
/// make any guarantees when we do this.
fn mmio_read(address: usize, offset: usize, value: u8) -> u8 {
// Set the pointer based off of the address
let reg = address as *mut u8;
// read_volatile() is much like write_volatile() except it
// will grab 8-bits from the pointer and give that value to us.
// We don't add a semi-colon at the end here so that the value
// is "returned".
unsafe { reg.add(offset).read_volatile() }
}

View File

@ -1,3 +1,4 @@
pub mod allocator;
pub mod graphics;
pub mod serial;
pub mod mmio;
pub mod uart;

View File

@ -1,47 +0,0 @@
/// Prints to the host through the serial interface.
#[macro_export]
macro_rules! serial_print {
($($arg:tt)*) => {
crate::arch::drivers::serial::SERIAL.lock().out(format_args!($($arg)*))
};
}
/// Prints to the host through the serial interface, appending a newline.
#[macro_export]
macro_rules! serial_println {
() => {
crate::arch::drivers::serial::SERIAL
.lock()
.out(format_args!("\r\n"))
};
($($arg:tt)*) => ($crate::print!("{}\r\n", format_args!($($arg)*)));
}
pub struct Serial123 {
uart_data: u32,
}
impl Serial123 {
pub fn out(&mut self, s: ::core::fmt::Arguments) {
let uart_data = self.uart_data as *mut u8;
for c in b"Hello, world!\n" {
unsafe { uart_data.write_volatile(*c) };
}
}
}
lazy_static! {
pub static ref SERIAL: Mutex<Serial123> = {
let serial_port = Serial123 {
/// UART port for the serial bus
uart_data: 0x10000000,
};
Mutex::new(serial_port)
};
}
use {
core::fmt::{Arguments, Error},
lazy_static::lazy_static,
spin::Mutex,
};

View File

@ -0,0 +1,154 @@
use core::fmt::Write;
use core::fmt::Error;
/// Initialize the UART driver by setting
/// the word length, FIFOs, and interrupts
pub fn uart_init(base_addr: usize) {
let ptr = base_addr as *mut u8;
unsafe {
// First, set the word length, which
// are bits 0, and 1 of the line control register (LCR)
// which is at base_address + 3
// We can easily write the value 3 here or 0b11, but I'm
// extending it so that it is clear we're setting two individual
// fields
// Word 0 Word 1
// ~~~~~~ ~~~~~~
let lcr = (1 << 0) | (1 << 1);
ptr.add(3).write_volatile(lcr);
// Now, enable the FIFO, which is bit index 0 of the FIFO
// control register (FCR at offset 2).
// Again, we can just write 1 here, but when we use left shift,
// it's easier to see that we're trying to write bit index #0.
ptr.add(2).write_volatile(1 << 0);
// Enable receiver buffer interrupts, which is at bit index
// 0 of the interrupt enable register (IER at offset 1).
ptr.add(1).write_volatile(1 << 0);
// If we cared about the divisor, the code below would set the divisor
// from a global clock rate of 22.729 MHz (22,729,000 cycles per second)
// to a signaling rate of 2400 (BAUD). We usually have much faster signalling
// rates nowadays, but this demonstrates what the divisor actually does.
// The formula given in the NS16500A specification for calculating the divisor
// is:
// divisor = ceil( (clock_hz) / (baud_sps x 16) )
// So, we substitute our values and get:
// divisor = ceil( 22_729_000 / (2400 x 16) )
// divisor = ceil( 22_729_000 / 38_400 )
// divisor = ceil( 591.901 ) = 592
// The divisor register is two bytes (16 bits), so we need to split the value
// 592 into two bytes. Typically, we would calculate this based on measuring
// the clock rate, but again, for our purposes [qemu], this doesn't really do
// anything.
let divisor: u16 = 592;
let divisor_least: u8 = (divisor & 0xff).try_into().unwrap();
let divisor_most: u8 = (divisor >> 8).try_into().unwrap();
// Notice that the divisor register DLL (divisor latch least) and DLM (divisor
// latch most) have the same base address as the receiver/transmitter and the
// interrupt enable register. To change what the base address points to, we
// open the "divisor latch" by writing 1 into the Divisor Latch Access Bit
// (DLAB), which is bit index 7 of the Line Control Register (LCR) which
// is at base_address + 3.
ptr.add(3).write_volatile(lcr | 1 << 7);
// Now, base addresses 0 and 1 point to DLL and DLM, respectively.
// Put the lower 8 bits of the divisor into DLL
ptr.add(0).write_volatile(divisor_least);
ptr.add(1).write_volatile(divisor_most);
// Now that we've written the divisor, we never have to touch this again. In
// hardware, this will divide the global clock (22.729 MHz) into one suitable
// for 2,400 signals per second. So, to once again get access to the
// RBR/THR/IER registers, we need to close the DLAB bit by clearing it to 0.
ptr.add(3).write_volatile(lcr);
}
}
fn uart_get(base_addr: usize) -> Option<u8> {
let ptr = base_addr as *mut u8;
unsafe {
// Bit index #5 is the Line Control Register.
if ptr.add(5).read_volatile() & 1 == 0 {
// The DR bit is 0, meaning no data
None
} else {
// The DR bit is 1, meaning data!
Some(ptr.add(0).read_volatile())
}
}
}
fn uart_put(base_addr: usize, c: u8) {
let ptr = base_addr as *mut u8;
unsafe {
// If we get here, the transmitter is empty, so transmit
// our stuff!
ptr.add(0).write_volatile(c);
}
}
pub struct Uart {
base_address: usize,
}
impl Uart {
pub fn new(base_address: usize) -> Self {
Uart { base_address }
}
pub fn get(&self) -> Option<u8> {
uart_get(self.base_address)
}
pub fn put(&self, c: u8) {
uart_put(self.base_address, c);
}
pub fn init(&self) {
uart_init(self.base_address);
}
}
// This is a slightly different syntax. Write is this "trait", meaning it is much like
// an interface where we're just guaranteeing a certain function signature. In the Write
// trait, one is absolutely required to be implemented, which is write_str. There are other
// functions, but they all rely on write_str(), so their default implementation is OK for now.
impl Write for Uart {
// The trait Write expects us to write the function write_str
// which looks like:
fn write_str(&mut self, s: &str) -> Result<(), Error> {
for c in s.bytes() {
self.put(c);
}
// Return that we succeeded.
Ok(())
}
}
// ///////////////////////////////////
// / RUST MACROS
// ///////////////////////////////////
#[macro_export]
macro_rules! sprint
{
($($args:tt)+) => ({
use core::fmt::Write;
let _ = write!(crate::arch::drivers::uart::Uart::new(0x1000_0000), $($args)+);
});
}
#[macro_export]
macro_rules! sprintln
{
() => ({
print!("\r\n")
});
($fmt:expr) => (print!(concat!($fmt, "\r\n")));
($fmt:expr, $($args:tt)+) => ({
print!(concat!($fmt, "\r\n"), $($args)+)
});
}

View File

@ -31,19 +31,42 @@ unsafe extern "C" fn _boot() -> ! {
}
extern "C" fn _start() -> ! {
/*
let uart_data = 0x10000000 as *mut u8;
for c in b"Hardcoded serial output\n" {
unsafe { uart_data.write_volatile(*c) };
let uart = crate::arch::drivers::uart::Uart::new(0x1000_0000);
uart.init();
println!("Hello, world!");
loop {
if let Some(c) = uart.get() {
match c {
66 => break,
10 | 13 => {
uart.put('\n' as u8);
uart.put('\r' as u8);
}
_ => {
uart.put(c);
}
}
}
}
*/
crate::serial_print!("Hi");
crate::kmain::kernel_main();
println!("Serial connection closed.");
sloop()
}
pub fn sloop() -> ! {
loop {
unsafe { asm!("nop") };
unsafe {
asm!("wfi");
};
}
}
use core::arch::asm;
pub fn shutdown() {}
use crate::print;
use crate::println;

View File

@ -1,66 +1,61 @@
use crate::{
arch::drivers::vga::{set_vga_color, Color},
kprint,
};
// TODO improve tokenizer/parser
pub fn colorify(eval: &str) {
let y = eval.split("$");
for z in y {
match z {
"BLACK" => {
set_vga_color(Color::Black, Color::Black);
// set_vga_color(Color::Black, Color::Black);
}
"RED" => {
set_vga_color(Color::Red, Color::Black);
// set_vga_color(Color::Red, Color::Black);
}
"GREEN" => {
set_vga_color(Color::Green, Color::Black);
// set_vga_color(Color::Green, Color::Black);
}
"BLUE" => {
set_vga_color(Color::Blue, Color::Black);
// set_vga_color(Color::Blue, Color::Black);
}
"CYAN" => {
set_vga_color(Color::Cyan, Color::Black);
// set_vga_color(Color::Cyan, Color::Black);
}
"MAGENTA" => {
set_vga_color(Color::Magenta, Color::Black);
// set_vga_color(Color::Magenta, Color::Black);
}
"BROWN" => {
set_vga_color(Color::Brown, Color::Black);
// set_vga_color(Color::Brown, Color::Black);
}
"LIGHTGRAY" => {
set_vga_color(Color::LightGray, Color::Black);
// set_vga_color(Color::LightGray, Color::Black);
}
"DARKGRAY" => {
set_vga_color(Color::DarkGray, Color::Black);
// set_vga_color(Color::DarkGray, Color::Black);
}
"LIGHTBLUE" => {
set_vga_color(Color::LightBlue, Color::Black);
// set_vga_color(Color::LightBlue, Color::Black);
}
"LIGHTGREEN" => {
set_vga_color(Color::LightGreen, Color::Black);
// set_vga_color(Color::LightGreen, Color::Black);
}
"LIGHTCYAN" => {
set_vga_color(Color::LightCyan, Color::Black);
// set_vga_color(Color::LightCyan, Color::Black);
}
"LIGHTRED" => {
set_vga_color(Color::LightRed, Color::Black);
// set_vga_color(Color::LightRed, Color::Black);
}
"PINK" => {
set_vga_color(Color::Pink, Color::Black);
// set_vga_color(Color::Pink, Color::Black);
}
"YELLOW" => {
set_vga_color(Color::Yellow, Color::Black);
// set_vga_color(Color::Yellow, Color::Black);
}
"WHITE" => {
set_vga_color(Color::White, Color::Black);
// set_vga_color(Color::White, Color::Black);
}
"RESET" => {
set_vga_color(Color::White, Color::Black);
// set_vga_color(Color::White, Color::Black);
}
elk => {
kprint!("{}", elk);
// kprint!("{}", elk);
}
}
}
@ -90,13 +85,13 @@ pub fn colorify_2(eval: &str) {
use Token::*;
match token {
Red => {
set_vga_color(Color::Red, Color::Black);
// set_vga_color(Color::Red, Color::Black);
}
Reset => {
set_vga_color(Color::White, Color::Black);
// set_vga_color(Color::White, Color::Black);
}
Text(text) => {
kprint!("{}", text);
// kprint!("{}", text);
}
err => {
error!("Error parsing {:?}", err);
@ -105,6 +100,8 @@ pub fn colorify_2(eval: &str) {
}
}
use logos::Lexer;
// use crate::kprint;
fn parse_text(lex: &mut Lexer<Token>) -> Option<String> {
let slice = lex.slice();
Some(String::from(slice))

View File

@ -3,7 +3,7 @@
pub mod absi;
pub mod clip;
pub mod futex;
pub mod info;
// pub mod info;
pub mod kinfo;
pub mod mail;
pub mod server;

View File

@ -1,9 +1,9 @@
use crate::vga_e::VGAE;
// use crate::vga_e::VGAE;
use ab_glyph::{Font, FontRef, Glyph};
use shadeable::{evaluate_shader, pixel_format::Rgba64};
use spin;
use vga::{colors::Color16, writers::GraphicsWriter};
// use vga::{colors::Color16, writers::GraphicsWriter};
#[derive(Debug)]
pub struct ScreenSize {
@ -126,7 +126,7 @@ impl ScreenBuffer {
// TODO force clear
pub fn force_redraw(&mut self) {
VGAE.lock().clear_screen(vga::colors::Color16::Black);
// VGAE.lock().clear_screen(vga::colors::Color16::Black);
}
/// Draw a glyph on the screen at the given position
@ -199,6 +199,7 @@ impl ScreenBuffer {
}
}
}
/*
pub trait VgaBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn;
@ -208,6 +209,7 @@ impl VgaBuffer for ScreenBuffer {
let mode = VGAE.lock();
for y in 0..self.size.y {
for x in 0..self.size.x {
use shadeable::pixel_format::into_vga_16;
let vga_color = into_vga_16(self.buff[y * self.size.x + x]);
// let vga_color = vga::colors::Color16::Cyan;
@ -215,12 +217,21 @@ impl VgaBuffer for ScreenBuffer {
if Color16::Cyan != vga_color {
mode.set_pixel(x, y, vga_color);
}
}
}
GraphicsReturn::Ok
}
}
*/
pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)> {
let mut coordinates: Vec<(usize, usize)> = vec![];
let dx: i32 = i32::abs(x2 - x1);

View File

@ -1,26 +1,24 @@
#![allow(clippy::empty_loop)]
use x86_64::instructions::interrupts::{disable, enable};
// use acpi::AcpiTables;
// use x86_64::instructions::interrupts::{disable, enable};
use crate::{boot_conf::KernelConfig, scratchpad};
// use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER};
use {
crate::{
arch::{init, sloop},
capabilities::FileAccess,
experiments::{
info::master,
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
},
file::PathRep,
relib::network::socket::{SimpleSock, Socket},
scheduler::SCHEDULER,
VgaBuffer, SCREEN_BUFFER,
// scheduler::SCHEDULER,
// VgaBuffer,
// SCREEN_BUFFER,
scratchpad,
// SCHEDULER,
SCREEN_BUFFER,
},
facepalm::start_facepalm,
lazy_static::lazy_static,
shadeable::pixel_format::from_vga_16,
vga::colors::Color16,
};
lazy_static! {
@ -40,6 +38,11 @@ pub fn kernel_main() -> ! {
}
let mut scheduler = SCHEDULER.lock();
/*
use crate::scheduler::Priority::*;
let mut process_1 = scheduler.new_process(High);
@ -53,41 +56,70 @@ pub fn kernel_main() -> ! {
}
drop(scheduler);
use crate::proto_filetable::file::FileLocations;
if false {
let mut sock_print_id = SimpleSock::new();
sock_print_id.register_protocol("Screen Printer".to_string());
sock_print_id.write(format!("🐑").into());
let mut mode = SCREEN_BUFFER.lock();
*/
// use crate::proto_filetable::file::FileLocations;
mode.force_redraw();
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
mode.draw_char(0, 0, current, from_vga_16(Color16::Red));
/*
if false {
let mut sock_print_id = SimpleSock::new();
sock_print_id.register_protocol("Screen Printer".to_string());
sock_print_id.write(format!("🐑").into());
let mut mode = SCREEN_BUFFER.lock();
mode.force_redraw();
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
// mode.draw_char(0, 0, current, from_vga_16(Color16::Red));
}
// mode.copy_to_buffer();
}
<<<<<<< HEAD
*/
/*
// TODO: create a scratchpad module
if false {
// Currently not implemented
let acpi_handler = AcpiStruct {};
let mut table;
unsafe {
table = AcpiTables::search_for_rsdp_bios(acpi_handler);
}
}
mode.copy_to_buffer();
}
start_facepalm();
scratchpad();
=======
mode.copy_to_buffer();
}
start_facepalm();
scratchpad();
>>>>>>> master
*/
// start_facepalm();
// scratchpad();
/*
if false {
disable();
// disable();
let mut mode = SCREEN_BUFFER.lock();
mode.force_redraw();
mode.copy_to_buffer();
// mode.copy_to_buffer();
mode.clear();
mode.draw_char(0, 0, 'v', 0xff00ffff);
mode.copy_to_buffer();
// mode.copy_to_buffer();
drop(mode);
enable()
// enable()
// sloop::halt();
}
*/
sloop()
}
@ -95,27 +127,30 @@ pub fn cpu_socket_startup() {
let mut cpu_info_socket = SimpleSock::new();
cpu_info_socket.register_protocol("CPU_INFO".to_string());
let x = master().unwrap();
let _xyz = x.brand_string().unwrap();
// let x = master().unwrap();
// let _xyz = x.brand_string().unwrap();
}
pub fn log_version_data() {
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
info!("{} v{:?}", RELEASE_TYPE, KERNEL_VERSION);
info!(
"Brand String: {}",
master().unwrap().brand_string().unwrap()
"Brand String: ",
// master().unwrap().brand_string().unwrap()
);
}
// TODO: Split up into the randomness and the password generation
pub fn generate_process_pass() -> u128 {
// TODO: Move this into entropy_pool module
use rdrand::RdRand;
let gen = RdRand::new().unwrap();
// use rdrand::RdRand;
// let gen = RdRand::new().unwrap();
// TODO: Split off into process module
let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128);
ret
// let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128);
// ret
123
}
/*
// TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -137,3 +172,8 @@ impl acpi::AcpiHandler for AcpiStruct {
todo!("unmap_physical_region");
}
}
*/
use kernel::KERNEL_VERSION;
use crate::{boot_conf::KernelConfig, scheduler::SCHEDULER, systeminfo::RELEASE_TYPE};

View File

@ -34,10 +34,12 @@ pub mod arch;
#[macro_use]
pub mod print;
pub mod devices;
pub mod port_io;
pub mod rhai_shell;
pub mod wasm_jumploader;
#[cfg(target_arch = "x86_64")]
pub mod port_io;
#[macro_use]
pub extern crate log;
@ -57,7 +59,7 @@ pub mod relib;
pub mod scheduler;
mod unicode_utils;
pub mod utils;
pub mod vga_e;
// pub mod vga_e;
pub mod wasm;
pub extern crate alloc;
@ -75,18 +77,20 @@ pub use keyboard::*;
pub use logger::*;
pub use proto_filetable::*;
pub use relib::*;
pub use scheduler::*;
// pub use scheduler::*;
pub use utils::*;
pub use vga_e::*;
// pub use vga_e::*;
pub use wasm::*;
pub mod boot_conf;
pub mod virtio;
pub use virtio::*;
pub mod alias_table;
pub use alias_table::*;
// pub mod alias_table;
// pub use alias_table::*;
#[cfg(target_arch = "x86_64")]
pub mod tests;
#[cfg(target_arch = "x86_64")]
pub use tests::*;
pub mod scratchpad;

View File

@ -1,7 +1,7 @@
use core::sync::atomic::Ordering;
use crate::network::socket::{SimpleSock, Socket};
use crate::serial_println;
// use crate::serial_println;
use kernel::TICK;
use lliw::{Fg, Reset};
@ -37,7 +37,9 @@ impl log::Log for SimpleLogger {
time_float,
record.args()
);
serial_println!(
// NOTE: This needs to be fixed before merge
println!(
"[{}{}{}][{}{}{}] {}",
color.0,
record.level(),
@ -45,7 +47,7 @@ impl log::Log for SimpleLogger {
Fg::Green,
time_float,
Reset,
record.args(),
record.args()
);
let log_socket_id = SimpleSock::grab_socket("Logger".to_string());

View File

@ -14,7 +14,6 @@ impl core::fmt::Write for Stdout {
#[cfg(target_arch = "aarch64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
// Don't actually print anything yet lmao
Ok(())
}
#[cfg(target_arch = "x86_64")]
@ -27,11 +26,9 @@ impl core::fmt::Write for Stdout {
fn write_str(&mut self, s: &str) -> Result<(), Error> {
Ok(())
}
fn write_char(&mut self, c: char) -> core::fmt::Result {
self.write_str(c.encode_utf8(&mut [0; 4]))
}
fn write_fmt(mut self: &mut Self, args: Arguments<'_>) -> core::fmt::Result {
core::fmt::write(&mut self, args)
}

View File

@ -1,7 +1,5 @@
#![allow(missing_docs)]
use crate::file::PathRep;
pub type SoundCardID = u8;
pub type DeviceID = u8;
pub type ControllerID = u8;
@ -9,7 +7,7 @@ pub type ControllerID = u8;
#[derive(Clone, Debug, PartialEq)]
pub enum FileAccess {
All,
Some(Vec<PathRep>),
Some(Vec<u8>),
None,
}

View File

@ -15,7 +15,7 @@ use proc::{Process, PID};
#[cfg(test)]
mod tests;
use crate::{file::PathRep, kmain::generate_process_pass};
use crate::kmain::generate_process_pass;
use self::capabilities::Capabilities;
@ -39,7 +39,7 @@ pub enum Priority {
#[derive(Clone, Debug)]
pub enum FileAccessTypes {
All,
Some(Vec<PathRep>),
Some(Vec<u8>),
None,
}

View File

@ -1,8 +1,8 @@
use crate::{
capabilities::Capabilities,
kmain::generate_process_pass,
proc::{Process, PID},
Priority,
scheduler::capabilities::Capabilities,
scheduler::proc::{Process, PID},
scheduler::Priority,
};
/// Add additional wake conditions to the list
pub enum WakeCondition {

View File

@ -1,6 +1,6 @@
use acpi::AcpiTables;
use crate::{kmain::AcpiStruct, rhai_shell::rhai_shell};
use crate::rhai_shell::rhai_shell;
/// Experimental scratchpad for testing.
pub fn scratchpad() {
@ -17,3 +17,21 @@ pub fn acpi() {
_table = AcpiTables::search_for_rsdp_bios(acpi_handler);
}
}
// TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AcpiStruct {}
impl acpi::AcpiHandler for AcpiStruct {
unsafe fn map_physical_region<T>(
&self,
physical_address: usize,
size: usize,
) -> acpi::PhysicalMapping<Self, T> {
info!("PHYS ADDR: {:?}", physical_address);
info!("Size: {:?}", size);
todo!("map_physical_region");
}
fn unmap_physical_region<T>(_region: &acpi::PhysicalMapping<Self, T>) {
todo!("unmap_physical_region");
}
}

View File

@ -35,9 +35,9 @@ impl Externals for HostExternals {
GET_TIME_INDEX => {
use core::sync::atomic::Ordering::*;
x86_64::instructions::interrupts::disable();
// x86_64::instructions::interrupts::disable();
let tick_time = kernel::TICK.load(Relaxed);
x86_64::instructions::interrupts::enable();
// x86_64::instructions::interrupts::enable();
let ret = RuntimeValue::I64(tick_time.try_into().unwrap());
Ok(Some(ret))

View File

@ -65,7 +65,9 @@ fn main() -> anyhow::Result<()> {
-smp 8
-m 128M
-bios src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin
-kernel target/riscv64gc-unknown-none-elf/release/ableos"
-kernel target/riscv64gc-unknown-none-elf/release/ableos
"
// -serial stdio
).run()?;
}
}

89
shadeable/Cargo.lock generated
View File

@ -20,39 +20,12 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bit_field"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "conquer-once"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c6d3a9775a69f6d1fe2cc888999b67ed30257d3da4d2af91984e722f2ec918a"
dependencies = [
"conquer-util",
]
[[package]]
name = "conquer-util"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e763eef8846b13b380f37dfecda401770b0ca4e56e95170237bd7c25c7db3582"
[[package]]
name = "const-random"
version = "0.1.13"
@ -90,12 +63,6 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "font8x8"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
[[package]]
name = "getrandom"
version = "0.2.4"
@ -134,15 +101,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
[[package]]
name = "lock_api"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.14"
@ -226,12 +184,6 @@ dependencies = [
"syn",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "shadeable"
version = "0.1.0"
@ -239,7 +191,6 @@ dependencies = [
"libm",
"log",
"rhai",
"vga",
]
[[package]]
@ -257,15 +208,6 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "spinning_top"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75adad84ee84b521fb2cca2d4fd0f1dab1d8d026bda3c5bea4ca63b5f9f9293c"
dependencies = [
"lock_api",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
@ -304,39 +246,8 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vga"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67cbcb7bfff998d176ffb8f2c3dfd6cb0fe62740e36dee6c64fc3928c01001bf"
dependencies = [
"bitflags",
"conquer-once",
"font8x8",
"num-traits",
"spinning_top",
"x86_64",
]
[[package]]
name = "volatile"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4c2dbd44eb8b53973357e6e207e370f0c1059990df850aca1eca8947cf464f0"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "x86_64"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb611915c917c6296d11e23f71ff1ecfe49c5766daba92cd3df52df6b58285b6"
dependencies = [
"bit_field",
"bitflags",
"volatile",
]

View File

@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
vga = "*"
# vga = "*"
libm = "*"
log ="*"

View File

@ -1,6 +1,6 @@
use core::ops::{BitAnd, BitOr, Shr};
use vga::colors::Color16;
// use vga::colors::Color16;
pub type Rgba64 = u64;
pub fn get_r(rgba: Rgba64) -> u8 {
@ -66,6 +66,7 @@ impl From<u8> for ChannelValue {
}
}
}
/*
pub fn into_vga_16(rgba_64: Rgba64) -> Color16 {
use ChannelValue::*;
@ -165,3 +166,4 @@ pub fn from_vga_16(color: Color16) -> Rgba64 {
LightRed => new_rgba64(0xff, 204, 203, 0),
}
}
*/