1
0
Fork 0
forked from AbleOS/ableos

booting on riscv

This commit is contained in:
Able 2022-02-18 10:04:10 -06:00
parent 38a8ae6e20
commit d8d093cb98
21 changed files with 532 additions and 552 deletions

View file

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

204
ableos/Cargo.lock generated
View file

@ -27,52 +27,31 @@ name = "ableos"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ab_glyph", "ab_glyph",
"acpi",
"bootloader", "bootloader",
"cpuio", "cpuio",
"ext2", "ext2",
"externc-libm", "externc-libm",
"facepalm", "facepalm",
"genfs",
"hashbrown", "hashbrown",
"lazy_static", "lazy_static",
"libwasm", "libwasm",
"linked_list_allocator", "linked_list_allocator",
"lliw", "lliw",
"log", "log",
"pc-beeper",
"pci",
"pic8259", "pic8259",
"picorand",
"pretty-hex",
"rdrand",
"rhai", "rhai",
"rkyv", "riscv",
"serde", "serde",
"serde_json", "serde_json",
"shadeable", "shadeable",
"smoltcp",
"spin 0.5.2", "spin 0.5.2",
"uart_16550", "uart_16550",
"unicode-width",
"vga",
"volatile 0.2.7", "volatile 0.2.7",
"wasmi", "wasmi",
"x86_64", "x86_64",
"y-compositor-protocol", "y-compositor-protocol",
] ]
[[package]]
name = "acpi"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55237649c6e747ea67e5ed45125af5e6a35ea1250c5e44995eb6049a955bd004"
dependencies = [
"bit_field",
"log",
"rsdp",
]
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.7.6"
@ -85,12 +64,27 @@ dependencies = [
"version_check", "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]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bare-metal"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603"
[[package]] [[package]]
name = "bit_field" name = "bit_field"
version = "0.10.1" version = "0.10.1"
@ -109,33 +103,12 @@ version = "0.9.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62c8f6168cd106687ee36a2b71a46c4144d73399f72814104d33094b8092fd2" checksum = "a62c8f6168cd106687ee36a2b71a46c4144d73399f72814104d33094b8092fd2"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 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]] [[package]]
name = "const-random" name = "const-random"
version = "0.1.13" version = "0.1.13"
@ -210,12 +183,6 @@ dependencies = [
"log", "log",
] ]
[[package]]
name = "font8x8"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
[[package]] [[package]]
name = "genfs" name = "genfs"
version = "0.1.4" version = "0.1.4"
@ -238,9 +205,6 @@ name = "hashbrown"
version = "0.11.2" version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash",
]
[[package]] [[package]]
name = "instant" name = "instant"
@ -268,9 +232,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.117" version = "0.2.118"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94"
[[package]] [[package]]
name = "libm" name = "libm"
@ -317,10 +281,10 @@ dependencies = [
] ]
[[package]] [[package]]
name = "managed" name = "memchr"
version = "0.8.0" version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]] [[package]]
name = "memory_units" name = "memory_units"
@ -386,22 +350,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92"
[[package]]
name = "pc-beeper"
version = "0.1.0"
source = "git+https://github.com/AbleOS/pc-beeper#9b61a9d60552a9da4285f5ceb39ab2cccbb60b4b"
dependencies = [
"x86_64",
]
[[package]]
name = "pci"
version = "0.0.1"
source = "git+https://gitlab.com/robigalia/pci#4e2fddc61825568b1d14d09fdc669389e6c43f02"
dependencies = [
"bitflags",
]
[[package]] [[package]]
name = "pic8259" name = "pic8259"
version = "0.10.2" version = "0.10.2"
@ -411,18 +359,6 @@ dependencies = [
"x86_64", "x86_64",
] ]
[[package]]
name = "picorand"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6fc30519d2508c7e20e01da371cd27b1d4533fdb98e279955cb636b50210688"
[[package]]
name = "pretty-hex"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131"
[[package]] [[package]]
name = "proc-macro-hack" name = "proc-macro-hack"
version = "0.5.19" version = "0.5.19"
@ -468,19 +404,21 @@ dependencies = [
] ]
[[package]] [[package]]
name = "rand_core" name = "regex"
version = "0.6.3" version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]] [[package]]
name = "rdrand" name = "regex-syntax"
version = "0.8.1" version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4e0d5cb05cb40e4e5805399c27b12a064427cf553081ae9b82bc1a88111a576" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
dependencies = [
"rand_core",
]
[[package]] [[package]]
name = "rhai" name = "rhai"
@ -511,12 +449,32 @@ dependencies = [
] ]
[[package]] [[package]]
name = "rkyv" name = "riscv"
version = "0.7.31" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439655b8d657bcb28264da8e5380d55549e34ffc4149bea9e3521890a122a7bd" checksum = "6907ccdd7a31012b70faf2af85cd9e5ba97657cc3987c4f13f8e4d2c2a088aba"
dependencies = [
"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.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e3791595bf1ee951356964271bea7dafd1e1730e8be812f44a31afc38fa7bba"
dependencies = [ dependencies = [
"hashbrown",
"ptr_meta", "ptr_meta",
"rkyv_derive", "rkyv_derive",
"seahash", "seahash",
@ -524,9 +482,9 @@ dependencies = [
[[package]] [[package]]
name = "rkyv_derive" name = "rkyv_derive"
version = "0.7.31" version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cded413ad606a80291ca84bedba137093807cf4f5b36be8c60f57a7e790d48f6" checksum = "ca655472e721430bfb5c995a5602278e089c329cde96a0a53e1f711e3ba39c55"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -539,15 +497,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe" checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
[[package]]
name = "rsdp"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d3add2fc55ef37511bcf81a08ee7a09eff07b23aae38b06a29024a38c604b1"
dependencies = [
"log",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.9" version = "1.0.9"
@ -588,9 +537,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.78" version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085" checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@ -604,7 +553,6 @@ dependencies = [
"libm", "libm",
"log", "log",
"rhai", "rhai",
"vga",
] ]
[[package]] [[package]]
@ -622,18 +570,6 @@ dependencies = [
"static_assertions", "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]] [[package]]
name = "spin" name = "spin"
version = "0.5.2" version = "0.5.2"
@ -700,12 +636,6 @@ dependencies = [
"x86_64", "x86_64",
] ]
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.2" version = "0.2.2"
@ -718,20 +648,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 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]] [[package]]
name = "volatile" name = "volatile"
version = "0.2.7" version = "0.2.7"

View file

@ -58,22 +58,24 @@ linked_list_allocator = "0.9.0"
lliw = "0.2.0" lliw = "0.2.0"
# qoi_rs = "*" # qoi_rs = "*"
spin = "0.5.2" spin = "0.5.2"
vga = "*" # vga = "*"
log = "*" log = "*"
riscv="*"
pretty-hex = "0.2.1"
unicode-width = "0.1.7" # pretty-hex = "0.2.1"
picorand = "*" # unicode-width = "0.1.7"
# picorand = "*"
# watson = "0.4" # watson = "0.4"
genfs = "0.1.0" # genfs = "0.1.0"
# pc-beeper = "0.1.0" # pc-beeper = "0.1.0"
pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"} # pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"}
rhai = "1.5" rhai = "1.5"
pci = {git="https://gitlab.com/robigalia/pci"} # pci = {git="https://gitlab.com/robigalia/pci"}
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"} libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
acpi = "4.1.0" # acpi = "4.1.0"
# [dependencies.ockam] # [dependencies.ockam]
@ -82,9 +84,9 @@ acpi = "4.1.0"
# features = ["alloc"] # features = ["alloc"]
[dependencies.rdrand] # [dependencies.rdrand]
version = "0.8.1" # version = "0.8.1"
default-features = false # default-features = false
@ -103,15 +105,15 @@ version = "0.11.2"
default-features = false default-features = false
features = ["inline-more"] features = ["inline-more"]
[dependencies.rkyv] # [dependencies.rkyv]
version = "0.7.29" # version = "0.7.29"
default-features = false # default-features = false
features = ["size_64", "alloc"] # features = ["size_64", "alloc"]
[dependencies.smoltcp] # [dependencies.smoltcp]
version = "0.8.0" # version = "0.8.0"
default-features = false # default-features = false
features = ["log", "proto-ipv4"] # features = ["log", "proto-ipv4"]
[dependencies.y-compositor-protocol] [dependencies.y-compositor-protocol]
git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git" git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
@ -141,6 +143,9 @@ version = "1.0"
[dependencies.externc-libm] [dependencies.externc-libm]
git = "https://git.ablecorp.us:443/able/externc-libm.git" git = "https://git.ablecorp.us:443/able/externc-libm.git"
[target.'cfg(target_arch = "x86_64")'.dependencies] [target.'cfg(target_arch = "x86_64")'.dependencies]
bootloader = { version = "0.9.8", features = ["map_physical_memory"] } bootloader = { version = "0.9.8", features = ["map_physical_memory"] }
cpuio = { git = "https://git.ablecorp.us/ondra05/cpuio.git" } cpuio = { git = "https://git.ablecorp.us/ondra05/cpuio.git" }

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 allocator;
pub mod graphics; 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! print
{
($($args:tt)+) => ({
use core::fmt::Write;
let _ = write!(crate::arch::drivers::uart::Uart::new(0x1000_0000), $($args)+);
});
}
#[macro_export]
macro_rules! println
{
() => ({
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,41 @@ unsafe extern "C" fn _boot() -> ! {
} }
extern "C" fn _start() -> ! { extern "C" fn _start() -> ! {
/* let uart = crate::arch::drivers::uart::Uart::new(0x1000_0000);
let uart_data = 0x10000000 as *mut u8; uart.init();
for c in b"Hardcoded serial output\n" {
unsafe { uart_data.write_volatile(*c) }; println!("Hello, world!");
loop {
if let Some(c) = uart.get() {
match c {
10 | 13 => {
uart.put('\n' as u8);
uart.put('\r' as u8);
} }
*/
crate::serial_print!("Hi"); _ => {
crate::kmain::kernel_main(); uart.put(c);
}
}
}
}
println!("Serial connection closed.");
sloop() sloop()
} }
pub fn sloop() -> ! { pub fn sloop() -> ! {
loop { loop {
unsafe { asm!("nop") }; unsafe {
asm!("wfi");
};
} }
} }
use core::arch::asm;
pub fn shutdown() {}
use crate::print;
use crate::println;

View file

@ -1,8 +1,5 @@
use crate::{
arch::drivers::vga::{set_vga_color, Color},
kprint,
};
/*
// TODO improve tokenizer/parser // TODO improve tokenizer/parser
pub fn colorify(eval: &str) { pub fn colorify(eval: &str) {
let y = eval.split("$"); let y = eval.split("$");
@ -65,3 +62,9 @@ pub fn colorify(eval: &str) {
} }
} }
} }
*/
pub fn colorify(eval: &str) {}

View file

@ -3,7 +3,7 @@
pub mod absi; pub mod absi;
pub mod clip; pub mod clip;
pub mod futex; pub mod futex;
pub mod info; // pub mod info;
pub mod kinfo; pub mod kinfo;
pub mod mail; pub mod mail;
pub mod server; 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 ab_glyph::{Font, FontRef, Glyph};
use alloc::{boxed::Box, vec, vec::Vec}; use alloc::{boxed::Box, vec, vec::Vec};
use shadeable::{evaluate_shader, pixel_format::Rgba64}; use shadeable::{evaluate_shader, pixel_format::Rgba64};
use spin; use spin;
use vga::{colors::Color16, writers::GraphicsWriter}; // use vga::{colors::Color16, writers::GraphicsWriter};
#[derive(Debug)] #[derive(Debug)]
pub struct ScreenSize { pub struct ScreenSize {
@ -126,8 +126,8 @@ impl ScreenBuffer {
// TODO force clear // TODO force clear
pub fn force_redraw(&mut self) { pub fn force_redraw(&mut self) {
use shadeable::pixel_format::into_vga_16; // use shadeable::pixel_format::into_vga_16;
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 /// Draw a glyph on the screen at the given position
@ -200,6 +200,7 @@ impl ScreenBuffer {
} }
} }
} }
/*
pub trait VgaBuffer { pub trait VgaBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn; fn copy_to_buffer(&self) -> GraphicsReturn;
@ -209,6 +210,7 @@ impl VgaBuffer for ScreenBuffer {
let mode = VGAE.lock(); let mode = VGAE.lock();
for y in 0..self.size.y { for y in 0..self.size.y {
for x in 0..self.size.x { for x in 0..self.size.x {
use shadeable::pixel_format::into_vga_16; use shadeable::pixel_format::into_vga_16;
let vga_color = into_vga_16(self.buff[y * self.size.x + x]); let vga_color = into_vga_16(self.buff[y * self.size.x + x]);
// let vga_color = vga::colors::Color16::Cyan; // let vga_color = vga::colors::Color16::Cyan;
@ -216,12 +218,21 @@ impl VgaBuffer for ScreenBuffer {
if Color16::Cyan != vga_color { if Color16::Cyan != vga_color {
mode.set_pixel(x, y, vga_color); mode.set_pixel(x, y, vga_color);
} }
} }
} }
GraphicsReturn::Ok GraphicsReturn::Ok
} }
} }
*/
pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)> { pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)> {
let mut coordinates: Vec<(usize, usize)> = vec![]; let mut coordinates: Vec<(usize, usize)> = vec![];
let dx: i32 = i32::abs(x2 - x1); let dx: i32 = i32::abs(x2 - x1);

View file

@ -1,24 +1,25 @@
#![allow(clippy::empty_loop)] #![allow(clippy::empty_loop)]
use acpi::AcpiTables; // use acpi::AcpiTables;
use x86_64::instructions::interrupts::{disable, enable}; // use x86_64::instructions::interrupts::{disable, enable};
use crate::scratchpad; // use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER};
use { use {
crate::{ crate::{
arch::{init, sloop}, arch::{init, sloop},
boot_conf, boot_conf,
boot_conf::BootConfig, boot_conf::BootConfig,
capabilities::FileAccess, // capabilities::FileAccess,
experiments::{ experiments::systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
info::master, // file::PathRep,
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
},
file::PathRep,
relib::network::socket::{SimpleSock, Socket}, relib::network::socket::{SimpleSock, Socket},
scheduler::SCHEDULER, // scheduler::SCHEDULER,
VgaBuffer, SCREEN_BUFFER, // VgaBuffer,
// SCREEN_BUFFER,
scratchpad,
// SCHEDULER,
SCREEN_BUFFER,
}, },
alloc::{ alloc::{
format, format,
@ -29,8 +30,8 @@ use {
facepalm::start_facepalm, facepalm::start_facepalm,
lazy_static::lazy_static, lazy_static::lazy_static,
log::*, log::*,
shadeable::pixel_format::from_vga_16, // shadeable::pixel_format::from_vga_16,
vga::colors::Color16, // vga::colors::Color16,
}; };
lazy_static! { lazy_static! {
@ -43,10 +44,15 @@ lazy_static! {
#[no_mangle] #[no_mangle]
pub fn kernel_main() -> ! { pub fn kernel_main() -> ! {
init::init(); init::init();
log::set_max_level(BOOT_CONF.log_level()); // log::set_max_level(BOOT_CONF.log_level());
/*
let mut scheduler = SCHEDULER.lock(); let mut scheduler = SCHEDULER.lock();
use crate::scheduler::Priority::*; use crate::scheduler::Priority::*;
let mut process_1 = scheduler.new_process(High); let mut process_1 = scheduler.new_process(High);
process_1.capabilities.files = FileAccess::Some(vec![PathRep { process_1.capabilities.files = FileAccess::Some(vec![PathRep {
@ -59,8 +65,12 @@ pub fn kernel_main() -> ! {
} }
drop(scheduler); drop(scheduler);
use crate::proto_filetable::file::FileLocations;
*/
// use crate::proto_filetable::file::FileLocations;
/*
if false { if false {
let mut sock_print_id = SimpleSock::new(); let mut sock_print_id = SimpleSock::new();
sock_print_id.register_protocol("Screen Printer".to_string()); sock_print_id.register_protocol("Screen Printer".to_string());
@ -70,11 +80,12 @@ pub fn kernel_main() -> ! {
mode.force_redraw(); mode.force_redraw();
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() { 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.draw_char(0, 0, current, from_vga_16(Color16::Red));
} }
mode.copy_to_buffer(); // mode.copy_to_buffer();
} }
*/
/*
// TODO: create a scratchpad module // TODO: create a scratchpad module
if false { if false {
// Currently not implemented // Currently not implemented
@ -85,25 +96,31 @@ pub fn kernel_main() -> ! {
} }
} }
start_facepalm();
scratchpad();
*/
// start_facepalm();
// scratchpad();
/*
if false { if false {
disable(); // disable();
let mut mode = SCREEN_BUFFER.lock(); let mut mode = SCREEN_BUFFER.lock();
mode.force_redraw(); mode.force_redraw();
mode.copy_to_buffer(); // mode.copy_to_buffer();
mode.clear(); mode.clear();
mode.draw_char(0, 0, 'v', 0xff00ffff); mode.draw_char(0, 0, 'v', 0xff00ffff);
mode.copy_to_buffer(); // mode.copy_to_buffer();
drop(mode); drop(mode);
enable() // enable()
// sloop::halt(); // sloop::halt();
} }
*/
sloop() sloop()
} }
@ -124,27 +141,30 @@ pub fn cpu_socket_startup() {
let mut cpu_info_socket = SimpleSock::new(); let mut cpu_info_socket = SimpleSock::new();
cpu_info_socket.register_protocol("CPU_INFO".to_string()); cpu_info_socket.register_protocol("CPU_INFO".to_string());
let x = master().unwrap(); // let x = master().unwrap();
let _xyz = x.brand_string().unwrap(); // let _xyz = x.brand_string().unwrap();
} }
pub fn log_version_data() { pub fn log_version_data() {
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
info!( info!(
"Brand String: {}", "Brand String: ",
master().unwrap().brand_string().unwrap() // master().unwrap().brand_string().unwrap()
); );
} }
// TODO: Split up into the randomness and the password generation // TODO: Split up into the randomness and the password generation
pub fn generate_process_pass() -> u128 { pub fn generate_process_pass() -> u128 {
// TODO: Move this into entropy_pool module // TODO: Move this into entropy_pool module
use rdrand::RdRand; // use rdrand::RdRand;
let gen = RdRand::new().unwrap(); // let gen = RdRand::new().unwrap();
// TODO: Split off into process module // TODO: Split off into process module
let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128); // let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128);
ret // ret
123
} }
/*
// TODO: move to a better place // TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -166,3 +186,4 @@ impl acpi::AcpiHandler for AcpiStruct {
todo!("unmap_physical_region"); todo!("unmap_physical_region");
} }
} }
*/

View file

@ -32,8 +32,8 @@ pub mod arch;
#[macro_use] #[macro_use]
pub mod print; pub mod print;
pub mod devices; // pub mod devices;
pub mod wasm_jumploader; // pub mod wasm_jumploader;
#[macro_use] #[macro_use]
pub extern crate log; pub extern crate log;
@ -51,12 +51,12 @@ pub mod keyboard;
pub mod kmain; pub mod kmain;
pub mod logger; pub mod logger;
pub mod panic; pub mod panic;
pub mod proto_filetable; // pub mod proto_filetable;
pub mod relib; pub mod relib;
pub mod scheduler; // pub mod scheduler;
mod unicode_utils; mod unicode_utils;
pub mod utils; pub mod utils;
pub mod vga_e; // pub mod vga_e;
pub mod wasm; pub mod wasm;
pub extern crate alloc; pub extern crate alloc;
@ -74,25 +74,26 @@ pub use kernel_state::*;
pub use keyboard::*; pub use keyboard::*;
pub use logger::*; pub use logger::*;
pub use panic::*; pub use panic::*;
pub use proto_filetable::*; // pub use proto_filetable::*;
pub use relib::*; pub use relib::*;
pub use scheduler::*; // pub use scheduler::*;
pub use utils::*; pub use utils::*;
pub use vga_e::*; // pub use vga_e::*;
pub use wasm::*; pub use wasm::*;
////////////////// //////////////////
pub mod virtio; pub mod virtio;
pub use virtio::*; pub use virtio::*;
pub mod alias_table; // pub mod alias_table;
pub use alias_table::*; // pub use alias_table::*;
/*
pub mod tests; pub mod tests;
pub use tests::*; pub use tests::*;
/*pub mod syscalls; pub mod syscalls;
pub use syscalls::*; pub use syscalls::*;
*/ */
pub mod scratchpad; pub mod scratchpad;
pub use scratchpad::*; pub use scratchpad::*;
pub mod filesystem; // pub mod filesystem;

View file

@ -1,12 +1,16 @@
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
use crate::kmain::TICK; use crate::kmain::TICK;
use crate::serial_println; // use crate::println;
use alloc::format;
// use alloc::fmt;
use lliw::{Fg, Reset}; use lliw::{Fg, Reset};
pub use log::{debug, info, trace, warn}; pub use log::{debug, info, trace, warn};
use log::{Level, Metadata, Record}; use log::{Level, Metadata, Record};
use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ; // use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ;
pub const TIMER_INTERRUPT_HERTZ: f64 = 100.0;
struct SimpleLogger; struct SimpleLogger;
// TODO: Rebuild this to take advantage of sockets // TODO: Rebuild this to take advantage of sockets
@ -31,8 +35,7 @@ impl log::Log for SimpleLogger {
log::Level::Debug => color = (Fg::Blue, "$BLUE$"), log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"), log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
} }
let xyz = format!(
serial_println!(
"[{}{}{}][{}{}{}] {}", "[{}{}{}][{}{}{}] {}",
color.0, color.0,
record.level(), record.level(),
@ -40,7 +43,7 @@ impl log::Log for SimpleLogger {
Fg::Green, Fg::Green,
time_float, time_float,
Reset, Reset,
record.args(), record.args()
); );
} }
} }

View file

@ -1,3 +1,5 @@
use alloc::string::ToString;
use {crate::arch::sloop, core::panic::PanicInfo}; use {crate::arch::sloop, core::panic::PanicInfo};
/// A function to handle a panic in the kernel. /// A function to handle a panic in the kernel.
@ -11,9 +13,15 @@ use {crate::arch::sloop, core::panic::PanicInfo};
/// This function is unsafe because it does not guarantee that the panic is handled. /// This function is unsafe because it does not guarantee that the panic is handled.
#[panic_handler] #[panic_handler]
fn panic(info: &PanicInfo) -> ! { fn panic(info: &PanicInfo) -> ! {
error!("{}", info); // error!("{}", info);
// help me use facepalm::start_facepalm; // help me use facepalm::start_facepalm;
let uart_data = 0x10000000 as *mut u8;
for c in b"panic" {
unsafe { uart_data.write_volatile(*c) };
}
sloop() sloop()
} }

View file

@ -1,61 +1 @@
// TODO: refactor this file
// TODO: make STDOUT redirect to a socket owned
// by the process named "stdout"
pub struct Stdout;
use core::fmt::{Arguments, Error};
impl Stdout {
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
{
let _ = core::fmt::Write::write_fmt(self, arg);
// Ok(())
}
}
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")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
use crate::experiments::absi::colorify;
colorify(s);
// kprint!("{}", s);
Ok(())
}
#[cfg(target_arch = "riscv64")]
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)
}
}
#[macro_export]
macro_rules! print {
() => {
::core::writeln!($crate::print::Stdout, "")
};
($($tt:tt)*) => {
::core::write!($crate::print::Stdout, $($tt)*)
};
}
#[macro_export]
macro_rules! println {
// TODO: The panic here should not be here
() =>{
// ::core::writeln!($crate::print::Stdout, "\n")
panic![];
};
($($tt:tt)*) => {
::core::writeln!($crate::print::Stdout, $($tt)*)
// panic![];
};
}

View file

@ -1,16 +1,10 @@
use { use alloc::{format, vec::Vec};
crate::{
devices::{pci_inner::DeviceClass, Device, DEVICE_TABLE},
proc::PID,
wasm_jumploader::interp,
},
alloc::{format, vec::Vec},
pci::PortOps,
};
/// Experimental scratchpad for testing. /// Experimental scratchpad for testing.
pub fn scratchpad() { pub fn scratchpad() {
/*
let mut dev_list = Vec::new(); let mut dev_list = Vec::new();
let bus_scan; let bus_scan;
unsafe { unsafe {
bus_scan = pci::scan_bus(&PciIO {}, pci::CSpaceAccessMethod::IO); bus_scan = pci::scan_bus(&PciIO {}, pci::CSpaceAccessMethod::IO);
@ -28,7 +22,7 @@ pub fn scratchpad() {
.devices .devices
.insert(device_name.clone(), Device::Pci(x)); .insert(device_name.clone(), Device::Pci(x));
} }
*/
/* /*
for (key, _value) in device_table.devices.iter() { for (key, _value) in device_table.devices.iter() {
debug!("{}", key); debug!("{}", key);
@ -38,7 +32,7 @@ pub fn scratchpad() {
// rhai_shell(); // rhai_shell();
} }
/*
pub struct PciIO {} pub struct PciIO {}
impl PortOps for PciIO { impl PortOps for PciIO {
@ -66,6 +60,7 @@ impl PortOps for PciIO {
cpuio::outl(val, port as u16); cpuio::outl(val, port as u16);
} }
} }
*/
/* /*
/// An experimental process message format /// An experimental process message format
pub struct ProcessMessage { pub struct ProcessMessage {
@ -99,8 +94,9 @@ pub fn rhai_shell() {
let ret = engine.eval::<i64>("1 + 2"); let ret = engine.eval::<i64>("1 + 2");
match ret { match ret {
Ok(x) => println!("{}", x), // Ok(x) => println!("{}", x),
Err(e) => println!("{}", e), // Err(e) => println!("{}", e),
_ => (),
} }
loop {} loop {}
@ -110,7 +106,3 @@ lazy_static::lazy_static!(
Vec::new()) Vec::new())
; ;
); );
use alloc::string::String;
use crate::arch::sloop;

View file

@ -55,7 +55,8 @@ fn main() -> anyhow::Result<()> {
).run()?; ).run()?;
} }
MachineType::RISCV => { MachineType::RISCV => {
xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf").run()?; xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf")
.run()?;
#[rustfmt::skip] #[rustfmt::skip]
xshell::cmd!( xshell::cmd!(
"qemu-system-riscv64 "qemu-system-riscv64
@ -64,7 +65,9 @@ fn main() -> anyhow::Result<()> {
-smp 8 -smp 8
-m 128M -m 128M
-bios src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin -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()?; ).run()?;
} }
} }
@ -78,7 +81,8 @@ fn main() -> anyhow::Result<()> {
xshell::cmd!("cargo doc --open").run()?; xshell::cmd!("cargo doc --open").run()?;
} }
MachineType::ARM => { MachineType::ARM => {
xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json").run()?; xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json")
.run()?;
} }
MachineType::RISCV => { MachineType::RISCV => {
xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?; xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").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" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 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]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 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]] [[package]]
name = "const-random" name = "const-random"
version = "0.1.13" version = "0.1.13"
@ -90,12 +63,6 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "font8x8"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.4" version = "0.2.4"
@ -134,15 +101,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" 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]] [[package]]
name = "log" name = "log"
version = "0.4.14" version = "0.4.14"
@ -226,12 +184,6 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "shadeable" name = "shadeable"
version = "0.1.0" version = "0.1.0"
@ -239,7 +191,6 @@ dependencies = [
"libm", "libm",
"log", "log",
"rhai", "rhai",
"vga",
] ]
[[package]] [[package]]
@ -257,15 +208,6 @@ dependencies = [
"static_assertions", "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]] [[package]]
name = "static_assertions" name = "static_assertions"
version = "1.1.0" version = "1.1.0"
@ -304,39 +246,8 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 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]] [[package]]
name = "wasi" name = "wasi"
version = "0.10.2+wasi-snapshot-preview1" version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" 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] [dependencies]
vga = "*" # vga = "*"
libm = "*" libm = "*"
log ="*" log ="*"

View file

@ -1,6 +1,6 @@
use core::ops::{BitAnd, BitOr, Shr}; use core::ops::{BitAnd, BitOr, Shr};
use vga::colors::Color16; // use vga::colors::Color16;
pub type Rgba64 = u64; pub type Rgba64 = u64;
pub fn get_r(rgba: Rgba64) -> u8 { pub fn get_r(rgba: Rgba64) -> u8 {
@ -19,20 +19,17 @@ pub fn get_a(rgba: Rgba64) -> u8 {
} }
pub fn set_r(rgba: Rgba64, r: u8) -> Rgba64 { pub fn set_r(rgba: Rgba64, r: u8) -> Rgba64 {
rgba rgba.bitand(0xffffffff_00_ff_ff_ff)
.bitand(0xffffffff_00_ff_ff_ff)
.bitor((r as Rgba64).shr(0o30)) .bitor((r as Rgba64).shr(0o30))
} }
pub fn set_g(rgba: Rgba64, g: u8) -> Rgba64 { pub fn set_g(rgba: Rgba64, g: u8) -> Rgba64 {
rgba rgba.bitand(0xffffffff_ff_00_ff_ff)
.bitand(0xffffffff_ff_00_ff_ff)
.bitor((g as Rgba64).shr(0o20)) .bitor((g as Rgba64).shr(0o20))
} }
pub fn set_b(rgba: Rgba64, b: u8) -> Rgba64 { pub fn set_b(rgba: Rgba64, b: u8) -> Rgba64 {
rgba rgba.bitand(0xffffffff_ff_ff_00_ff)
.bitand(0xffffffff_ff_ff_00_ff)
.bitor((b as Rgba64).shr(0o10)) .bitor((b as Rgba64).shr(0o10))
} }
@ -69,6 +66,7 @@ impl From<u8> for ChannelValue {
} }
} }
} }
/*
pub fn into_vga_16(rgba_64: Rgba64) -> Color16 { pub fn into_vga_16(rgba_64: Rgba64) -> Color16 {
use ChannelValue::*; use ChannelValue::*;
@ -168,3 +166,4 @@ pub fn from_vga_16(color: Color16) -> Rgba64 {
LightRed => new_rgba64(0xff, 204, 203, 0), LightRed => new_rgba64(0xff, 204, 203, 0),
} }
} }
*/