booting on riscv

master
Able 2022-02-18 10:04:10 -06:00
parent 619e4061c7
commit e3bf757efd
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
21 changed files with 532 additions and 552 deletions

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"]

204
ableos/Cargo.lock generated
View File

@ -27,52 +27,31 @@ name = "ableos"
version = "0.1.0"
dependencies = [
"ab_glyph",
"acpi",
"bootloader",
"cpuio",
"ext2",
"externc-libm",
"facepalm",
"genfs",
"hashbrown",
"lazy_static",
"libwasm",
"linked_list_allocator",
"lliw",
"log",
"pc-beeper",
"pci",
"pic8259",
"picorand",
"pretty-hex",
"rdrand",
"rhai",
"rkyv",
"riscv",
"serde",
"serde_json",
"shadeable",
"smoltcp",
"spin 0.5.2",
"uart_16550",
"unicode-width",
"vga",
"volatile 0.2.7",
"wasmi",
"x86_64",
"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]]
name = "ahash"
version = "0.7.6"
@ -85,12 +64,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 = "bit_field"
version = "0.10.1"
@ -109,33 +103,12 @@ version = "0.9.21"
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"
[[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"
@ -210,12 +183,6 @@ dependencies = [
"log",
]
[[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"
@ -238,9 +205,6 @@ name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash",
]
[[package]]
name = "instant"
@ -268,9 +232,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.117"
version = "0.2.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94"
[[package]]
name = "libm"
@ -317,10 +281,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"
@ -386,22 +350,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "pic8259"
version = "0.10.2"
@ -411,18 +359,6 @@ dependencies = [
"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]]
name = "proc-macro-hack"
version = "0.5.19"
@ -468,19 +404,21 @@ dependencies = [
]
[[package]]
name = "rand_core"
version = "0.6.3"
name = "regex"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "rdrand"
version = "0.8.1"
name = "regex-syntax"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4e0d5cb05cb40e4e5805399c27b12a064427cf553081ae9b82bc1a88111a576"
dependencies = [
"rand_core",
]
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "rhai"
@ -511,12 +449,32 @@ 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 = [
"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 = [
"hashbrown",
"ptr_meta",
"rkyv_derive",
"seahash",
@ -524,9 +482,9 @@ dependencies = [
[[package]]
name = "rkyv_derive"
version = "0.7.31"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cded413ad606a80291ca84bedba137093807cf4f5b36be8c60f57a7e790d48f6"
checksum = "ca655472e721430bfb5c995a5602278e089c329cde96a0a53e1f711e3ba39c55"
dependencies = [
"proc-macro2",
"quote",
@ -539,15 +497,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
[[package]]
name = "rsdp"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d3add2fc55ef37511bcf81a08ee7a09eff07b23aae38b06a29024a38c604b1"
dependencies = [
"log",
]
[[package]]
name = "ryu"
version = "1.0.9"
@ -588,9 +537,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.78"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085"
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
dependencies = [
"itoa",
"ryu",
@ -604,7 +553,6 @@ dependencies = [
"libm",
"log",
"rhai",
"vga",
]
[[package]]
@ -622,18 +570,6 @@ 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"
@ -700,12 +636,6 @@ dependencies = [
"x86_64",
]
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.2.2"
@ -718,20 +648,6 @@ 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.2.7"

View File

@ -54,26 +54,28 @@ test-args = [
]
[dependencies]
linked_list_allocator = "0.9.0"
linked_list_allocator = "0.9.0"
lliw = "0.2.0"
# qoi_rs = "*"
spin = "0.5.2"
vga = "*"
# vga = "*"
log = "*"
riscv="*"
pretty-hex = "0.2.1"
unicode-width = "0.1.7"
picorand = "*"
# pretty-hex = "0.2.1"
# unicode-width = "0.1.7"
# picorand = "*"
# watson = "0.4"
genfs = "0.1.0"
# genfs = "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"
pci = {git="https://gitlab.com/robigalia/pci"}
# pci = {git="https://gitlab.com/robigalia/pci"}
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
acpi = "4.1.0"
# acpi = "4.1.0"
# [dependencies.ockam]
@ -82,9 +84,9 @@ acpi = "4.1.0"
# features = ["alloc"]
[dependencies.rdrand]
version = "0.8.1"
default-features = false
# [dependencies.rdrand]
# version = "0.8.1"
# default-features = false
@ -103,15 +105,15 @@ version = "0.11.2"
default-features = false
features = ["inline-more"]
[dependencies.rkyv]
version = "0.7.29"
default-features = false
features = ["size_64", "alloc"]
# [dependencies.rkyv]
# 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"
@ -141,6 +143,9 @@ version = "1.0"
[dependencies.externc-libm]
git = "https://git.ablecorp.us:443/able/externc-libm.git"
[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" }

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! 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() -> ! {
/*
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 {
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,8 +1,5 @@
use crate::{
arch::drivers::vga::{set_vga_color, Color},
kprint,
};
/*
// TODO improve tokenizer/parser
pub fn colorify(eval: &str) {
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 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 alloc::{boxed::Box, vec, vec::Vec};
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,8 +126,8 @@ impl ScreenBuffer {
// TODO force clear
pub fn force_redraw(&mut self) {
use shadeable::pixel_format::into_vga_16;
VGAE.lock().clear_screen(vga::colors::Color16::Black);
// use shadeable::pixel_format::into_vga_16;
// VGAE.lock().clear_screen(vga::colors::Color16::Black);
}
/// Draw a glyph on the screen at the given position
@ -200,6 +200,7 @@ impl ScreenBuffer {
}
}
}
/*
pub trait VgaBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn;
@ -209,6 +210,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;
@ -216,12 +218,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,24 +1,25 @@
#![allow(clippy::empty_loop)]
use acpi::AcpiTables;
use x86_64::instructions::interrupts::{disable, enable};
// use acpi::AcpiTables;
// use x86_64::instructions::interrupts::{disable, enable};
use crate::scratchpad;
// use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER};
use {
crate::{
arch::{init, sloop},
boot_conf,
boot_conf::BootConfig,
capabilities::FileAccess,
experiments::{
info::master,
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
},
file::PathRep,
// capabilities::FileAccess,
experiments::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,
},
alloc::{
format,
@ -29,8 +30,8 @@ use {
facepalm::start_facepalm,
lazy_static::lazy_static,
log::*,
shadeable::pixel_format::from_vga_16,
vga::colors::Color16,
// shadeable::pixel_format::from_vga_16,
// vga::colors::Color16,
};
lazy_static! {
@ -43,10 +44,15 @@ lazy_static! {
#[no_mangle]
pub fn kernel_main() -> ! {
init::init();
log::set_max_level(BOOT_CONF.log_level());
// log::set_max_level(BOOT_CONF.log_level());
/*
let mut scheduler = SCHEDULER.lock();
use crate::scheduler::Priority::*;
let mut process_1 = scheduler.new_process(High);
process_1.capabilities.files = FileAccess::Some(vec![PathRep {
@ -59,22 +65,27 @@ 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();
}
mode.copy_to_buffer();
}
*/
/*
// TODO: create a scratchpad module
if false {
// Currently not implemented
@ -85,25 +96,31 @@ pub fn kernel_main() -> ! {
}
}
start_facepalm();
scratchpad();
*/
// 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()
}
@ -124,27 +141,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!(
"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)]
@ -166,3 +186,4 @@ impl acpi::AcpiHandler for AcpiStruct {
todo!("unmap_physical_region");
}
}
*/

View File

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

View File

@ -1,12 +1,16 @@
use core::sync::atomic::Ordering;
use crate::kmain::TICK;
use crate::serial_println;
// use crate::println;
use alloc::format;
// use alloc::fmt;
use lliw::{Fg, Reset};
pub use log::{debug, info, trace, warn};
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;
// 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::Trace => color = (Fg::Yellow, "$YELLOW$"),
}
serial_println!(
let xyz = format!(
"[{}{}{}][{}{}{}] {}",
color.0,
record.level(),
@ -40,7 +43,7 @@ impl log::Log for SimpleLogger {
Fg::Green,
time_float,
Reset,
record.args(),
record.args()
);
}
}

View File

@ -1,3 +1,5 @@
use alloc::string::ToString;
use {crate::arch::sloop, core::panic::PanicInfo};
/// 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.
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
error!("{}", info);
// error!("{}", info);
// 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()
}

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

View File

@ -4,46 +4,46 @@ use clap::Parser;
#[clap(version = clap::crate_version!(), author = clap::crate_authors!("\n"))]
/// Hello Remember this is a feature
enum Command {
Run {
#[clap(long, short)]
debug: bool,
Run {
#[clap(long, short)]
debug: bool,
#[clap(long, short, arg_enum)]
machine: Option<MachineType>,
},
#[clap(long, short, arg_enum)]
machine: Option<MachineType>,
},
Doc {
#[clap(long, short, arg_enum)]
machine: Option<MachineType>,
},
Doc {
#[clap(long, short, arg_enum)]
machine: Option<MachineType>,
},
}
#[derive(clap::ArgEnum, Debug, Clone)]
enum MachineType {
X86,
RISCV,
ARM,
X86,
RISCV,
ARM,
}
fn main() -> anyhow::Result<()> {
let args = Command::parse();
let args = Command::parse();
match args {
Command::Run { debug, machine } => {
let _dir = xshell::pushd("./ableos");
match args {
Command::Run { debug, machine } => {
let _dir = xshell::pushd("./ableos");
let _debug_log: &[&str] = match debug {
true => &["-D", "debug.log"],
false => &[],
};
match machine.unwrap_or(MachineType::X86) {
MachineType::X86 => {
xshell::cmd!("cargo run --release").run()?;
}
MachineType::ARM => {
xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json")
.run()?;
#[rustfmt::skip]
let _debug_log: &[&str] = match debug {
true => &["-D", "debug.log"],
false => &[],
};
match machine.unwrap_or(MachineType::X86) {
MachineType::X86 => {
xshell::cmd!("cargo run --release").run()?;
}
MachineType::ARM => {
xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json")
.run()?;
#[rustfmt::skip]
xshell::cmd!(
"qemu-system-aarch64
-machine virt
@ -53,10 +53,11 @@ fn main() -> anyhow::Result<()> {
-device virtio-keyboard
"
).run()?;
}
MachineType::RISCV => {
xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf").run()?;
#[rustfmt::skip]
}
MachineType::RISCV => {
xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf")
.run()?;
#[rustfmt::skip]
xshell::cmd!(
"qemu-system-riscv64
-machine virt
@ -64,28 +65,31 @@ 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()?;
}
}
}
}
}
Command::Doc { machine } => {
let _dir = xshell::pushd("./ableos");
Command::Doc { machine } => {
let _dir = xshell::pushd("./ableos");
match machine.unwrap_or(MachineType::X86) {
MachineType::X86 => {
xshell::cmd!("cargo doc --open").run()?;
match machine.unwrap_or(MachineType::X86) {
MachineType::X86 => {
xshell::cmd!("cargo doc --open").run()?;
}
MachineType::ARM => {
xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json")
.run()?;
}
MachineType::RISCV => {
xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?;
}
}
MachineType::ARM => {
xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json").run()?;
}
MachineType::RISCV => {
xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?;
}
}
}
}
}
}
Ok(())
Ok(())
}

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,74 +1,72 @@
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 {
rgba.bitand(0xff_00_00_00).shr(0o30) as u8
rgba.bitand(0xff_00_00_00).shr(0o30) as u8
}
pub fn get_g(rgba: Rgba64) -> u8 {
rgba.bitand(0xff_00_00).shr(0o20) as u8
rgba.bitand(0xff_00_00).shr(0o20) as u8
}
pub fn get_b(rgba: Rgba64) -> u8 {
rgba.bitand(0xff_00).shr(0o10) as u8
rgba.bitand(0xff_00).shr(0o10) as u8
}
pub fn get_a(rgba: Rgba64) -> u8 {
(rgba & 0xff) as u8
(rgba & 0xff) as u8
}
pub fn set_r(rgba: Rgba64, r: u8) -> Rgba64 {
rgba
.bitand(0xffffffff_00_ff_ff_ff)
.bitor((r as Rgba64).shr(0o30))
rgba.bitand(0xffffffff_00_ff_ff_ff)
.bitor((r as Rgba64).shr(0o30))
}
pub fn set_g(rgba: Rgba64, g: u8) -> Rgba64 {
rgba
.bitand(0xffffffff_ff_00_ff_ff)
.bitor((g as Rgba64).shr(0o20))
rgba.bitand(0xffffffff_ff_00_ff_ff)
.bitor((g as Rgba64).shr(0o20))
}
pub fn set_b(rgba: Rgba64, b: u8) -> Rgba64 {
rgba
.bitand(0xffffffff_ff_ff_00_ff)
.bitor((b as Rgba64).shr(0o10))
rgba.bitand(0xffffffff_ff_ff_00_ff)
.bitor((b as Rgba64).shr(0o10))
}
pub fn set_a(rgba: Rgba64, a: u8) -> Rgba64 {
rgba.bitand(0xffffffff_ff_ff_ff_00).bitor(a as Rgba64)
rgba.bitand(0xffffffff_ff_ff_ff_00).bitor(a as Rgba64)
}
pub fn rgba_div(a: Rgba64, b: Rgba64) -> Rgba64 {
set_r(0, get_r(a) / get_r(b))
| set_g(0, get_g(a) / get_g(b))
| set_g(0, get_b(a) / get_b(b))
| set_g(0, get_a(a) / get_a(b))
set_r(0, get_r(a) / get_r(b))
| set_g(0, get_g(a) / get_g(b))
| set_g(0, get_b(a) / get_b(b))
| set_g(0, get_a(a) / get_a(b))
}
pub fn new_rgba64(r: u8, g: u8, b: u8, a: u8) -> Rgba64 {
set_r(0, r) | set_g(0, g) | set_b(0, b) | set_a(0, a)
set_r(0, r) | set_g(0, g) | set_b(0, b) | set_a(0, a)
}
enum ChannelValue {
Dark,
Low,
Mid,
High,
Dark,
Low,
Mid,
High,
}
impl From<u8> for ChannelValue {
fn from(b: u8) -> Self {
use ChannelValue::*;
match b {
0x00..=0x3f => Dark,
0x40..=0x7f => Low,
0x80..=0xbf => Mid,
0xc0..=0xff => High,
}
}
fn from(b: u8) -> Self {
use ChannelValue::*;
match b {
0x00..=0x3f => Dark,
0x40..=0x7f => Low,
0x80..=0xbf => Mid,
0xc0..=0xff => High,
}
}
}
/*
pub fn into_vga_16(rgba_64: Rgba64) -> Color16 {
use ChannelValue::*;
@ -168,3 +166,4 @@ pub fn from_vga_16(color: Color16) -> Rgba64 {
LightRed => new_rgba64(0xff, 204, 203, 0),
}
}
*/