Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
d52f14ee1f | |||
4cd7a76ee7 | |||
f3a4a6b4f5 | |||
f5aac570ee |
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,6 +1,4 @@
|
|||
{
|
||||
"editor.insertSpaces": false,
|
||||
"editor.detectIndentation": false,
|
||||
"rust-analyzer.checkOnSave.allTargets": false,
|
||||
"rust-analyzer.showUnlinkedFileNotification": false,
|
||||
"C_Cpp.errorSquiggles": "disabled"
|
||||
|
|
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -213,12 +213,12 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "hbbytecode"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0"
|
||||
|
||||
[[package]]
|
||||
name = "hblang"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"hbbytecode",
|
||||
|
@ -229,7 +229,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "hbvm"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0"
|
||||
dependencies = [
|
||||
"hbbytecode",
|
||||
]
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
# Style Guide
|
||||
This style guide has two modes that a guideline may be.
|
||||
|
||||
`strict` means that prs will be rejected if they do not follow the guideline.
|
||||
|
||||
`loose` means that a pr would be accepted but should later be fixed.
|
||||
|
||||
## Empty Functions | loose
|
||||
Empty functions are typically a sign of an unfinished program or driver.
|
||||
|
||||
In cases where there is a clear reason to have an empty function it will be allowed.
|
||||
For example FakeAlloc is only empty functions because it is a example of an the allocator api.
|
||||
|
||||
### Allowed
|
||||
```rust
|
||||
/// in example.hb
|
||||
a := fn(): void {}
|
||||
```
|
||||
### Not Allowed
|
||||
```rust
|
||||
/// in fat32.hb
|
||||
a := fn(): void {}
|
||||
```
|
||||
|
||||
|
||||
## Magic Numbers | loose
|
||||
The policy on magic numbers is make them const and have a comment above them. Typically linking to a source of information about the magic number.
|
||||
|
||||
This helps cut down on magic numbers while making acceptable names and atleast half assed documentation.
|
||||
|
||||
Constants are inlined anyways, so its the same thing in the binary.
|
||||
|
||||
```rust
|
||||
// The standard vga port is mapped at 0xB8000
|
||||
$VGA_PTR := 0xB8000
|
||||
```
|
||||
|
||||
## Tabs Vs Spaces | strict
|
||||
I prefer for hblang code to use hard tabs.
|
||||
|
||||
The rational behind this is that a tab is `1 Indent` which some developers might want to be various different sizes when displayed
|
||||
|
||||
Soft tabs do not allow this user/editor specific as soft tabs always become spaces.
|
||||
|
||||
Bottom line is this is an accessibility feature.
|
||||
|
||||
There are some samples below.
|
||||
```
|
||||
\t means hard tab
|
||||
\n means new line
|
||||
\0x20 means space
|
||||
```
|
||||
|
||||
### Allowed
|
||||
```rust
|
||||
if x == y {\n
|
||||
\tlog(z)\n
|
||||
}\n
|
||||
```
|
||||
|
||||
### Not Allowed
|
||||
```rust
|
||||
if x == y {\n
|
||||
\0x20\0x20\0x20\0x20log(z)\n
|
||||
}\n
|
||||
```
|
|
@ -4,25 +4,81 @@ extern crate syn;
|
|||
use {
|
||||
proc_macro::TokenStream,
|
||||
quote::quote,
|
||||
syn::{parse_macro_input, ItemFn}
|
||||
syn::{parse::Parse, parse_macro_input, Expr, ItemFn, Token}
|
||||
};
|
||||
|
||||
struct KtestInput {
|
||||
lhs: Expr,
|
||||
_comma: Token![,],
|
||||
rhs: Expr,
|
||||
}
|
||||
|
||||
impl Parse for KtestInput {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
Ok(Self {
|
||||
lhs: input.parse()?,
|
||||
_comma: input.parse()?,
|
||||
rhs: input.parse()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn ktest_eq(item: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(item as KtestInput);
|
||||
|
||||
let lhs = input.lhs;
|
||||
let rhs = input.rhs;
|
||||
|
||||
let out = quote! {
|
||||
if #lhs != #rhs {
|
||||
return Err(name);
|
||||
}
|
||||
};
|
||||
TokenStream::from(out)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn ktest_neq(item: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(item as KtestInput);
|
||||
|
||||
let lhs = input.lhs;
|
||||
let rhs = input.rhs;
|
||||
|
||||
let out = quote! {
|
||||
if #lhs == #rhs {
|
||||
return Err(name);
|
||||
}
|
||||
};
|
||||
TokenStream::from(out)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn ktest(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(item as ItemFn);
|
||||
let test_name = &input.sig.ident;
|
||||
let test_string = test_name.to_string();
|
||||
let static_var_name = syn::Ident::new(
|
||||
&format!("__ktest_{}", test_name),
|
||||
&format!("__ktest_{}", test_name).to_uppercase(),
|
||||
test_name.span(),
|
||||
);
|
||||
let out = quote! {
|
||||
// #[cfg(feature = "ktest")]
|
||||
#input
|
||||
|
||||
// #[cfg(feature = "ktest")]
|
||||
let block = &input.block;
|
||||
let out = quote! {
|
||||
#[cfg(feature = "ktest")]
|
||||
fn #test_name() -> Result<String, String> {
|
||||
use crate::alloc::string::ToString;
|
||||
let name = #test_string.to_string();
|
||||
|
||||
#block
|
||||
|
||||
return Ok(name);
|
||||
}
|
||||
|
||||
#[cfg(feature = "ktest")]
|
||||
#[unsafe(link_section = ".note.ktest")]
|
||||
#[used]
|
||||
pub static #static_var_name: fn() = #test_name;
|
||||
pub static #static_var_name: fn() -> Result<String, String> = #test_name;
|
||||
};
|
||||
|
||||
TokenStream::from(out)
|
||||
|
|
|
@ -22,11 +22,10 @@ use {
|
|||
pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
||||
debug!("Entered kmain");
|
||||
|
||||
#[cfg(feature = "ktest")]
|
||||
{
|
||||
use crate::ktest;
|
||||
debug!("TESTING");
|
||||
ktest::test_main();
|
||||
#[cfg(feature = "ktest")] {
|
||||
use crate::ktest::test_main;
|
||||
debug!("Running tests");
|
||||
test_main();
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
@ -132,7 +131,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
|||
|
||||
executor.run();
|
||||
};
|
||||
log::info!("Started AbleOS");
|
||||
|
||||
crate::arch::spin_loop()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,38 +1,52 @@
|
|||
pub use ktest_macro::ktest;
|
||||
use log::debug;
|
||||
use {
|
||||
alloc::string::String,
|
||||
log::debug,
|
||||
};
|
||||
|
||||
pub use ktest_macro::*;
|
||||
|
||||
|
||||
#[allow(improper_ctypes)]
|
||||
extern "C" {
|
||||
static __ktest_start: fn();
|
||||
static __ktest_end: fn();
|
||||
static __ktest_start: fn() -> Result<String, String>;
|
||||
static __ktest_end: fn() -> Result<String, String>;
|
||||
}
|
||||
|
||||
// TODO: Get test_fn linker name (may require no_mangle in macro)
|
||||
// More info on tests (run the rest even if panic)
|
||||
// Implement ktest for arm and riscv (Later problems, see below)
|
||||
// TODO: Implement ktest for arm and riscv (Later problems, see below)
|
||||
// Allow for arch specific tests (Leave for now)
|
||||
// Allow for ktest test name attr
|
||||
// Usefull message at the end of testing
|
||||
// Should panic tests
|
||||
pub fn test_main() {
|
||||
unsafe {
|
||||
let mut current_test = &__ktest_start as *const fn();
|
||||
let mut current = 1;
|
||||
let test_end = &__ktest_end as *const fn();
|
||||
let mut current_test = &__ktest_start as *const fn() -> Result<String, String>;
|
||||
let test_end = &__ktest_end as *const fn() -> Result<String, String>;
|
||||
|
||||
let mut pass = 0;
|
||||
let mut fail = 0;
|
||||
|
||||
while current_test < test_end {
|
||||
let test_fn = *current_test;
|
||||
|
||||
debug!("Running test {}", current);
|
||||
|
||||
test_fn();
|
||||
debug!("Test {} passed", current);
|
||||
let test_name = test_fn();
|
||||
match test_name {
|
||||
Ok(name) => {
|
||||
debug!("Test: {} passed", name);
|
||||
pass += 1;
|
||||
},
|
||||
Err(name) => {
|
||||
debug!("Test: {} failed", name);
|
||||
fail += 1;
|
||||
}
|
||||
}
|
||||
|
||||
current_test = current_test.add(1);
|
||||
current += 1;
|
||||
}
|
||||
|
||||
debug!("{}/{} tests passed", pass, pass + fail);
|
||||
}
|
||||
}
|
||||
|
||||
#[ktest]
|
||||
pub fn trivial_assertion() {
|
||||
assert_eq!(1, 1);
|
||||
fn trivial_assertion() {
|
||||
ktest_eq!(1, 1);
|
||||
ktest_neq!(0, 1);
|
||||
}
|
|
@ -27,15 +27,12 @@ mod handle;
|
|||
mod holeybytes;
|
||||
mod ipc;
|
||||
mod kmain;
|
||||
mod ktest;
|
||||
mod logger;
|
||||
mod memory;
|
||||
mod task;
|
||||
mod utils;
|
||||
|
||||
// #[cfg(feature = "tests")]
|
||||
mod ktest;
|
||||
|
||||
use alloc::string::ToString;
|
||||
use versioning::Version;
|
||||
|
||||
/// Kernel's version
|
||||
|
@ -48,6 +45,8 @@ pub const VERSION: Version = Version {
|
|||
#[panic_handler]
|
||||
#[cfg(target_os = "none")]
|
||||
fn panic(info: &core::panic::PanicInfo) -> ! {
|
||||
use crate::alloc::string::ToString;
|
||||
|
||||
arch::register_dump();
|
||||
|
||||
if let Some(loc) = info.location() {
|
||||
|
|
|
@ -485,7 +485,7 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
|
|||
#[rustfmt::skip]
|
||||
com.args([
|
||||
"-M", "virt",
|
||||
"-cpu", "max",
|
||||
"-cpu", "neoverse-n2",
|
||||
"-device", "ramfb",
|
||||
"-device", "qemu-xhci",
|
||||
"-device", "usb-kbd",
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
AllocReturn := struct {
|
||||
byte_count: uint,
|
||||
ptr: ?^u8,
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
.{log, panic} := @use("../lib.hb")
|
||||
alloc_return := @use("alloc_return.hb")
|
||||
|
||||
/* the block size is 64 bytes, 64 blocks of 64 bytes.
|
||||
this will very quickly lead to exhaustion of free blocks.
|
||||
*/
|
||||
BlockAlloc := struct {
|
||||
// hi
|
||||
state: uint,
|
||||
ptr: ?^u8,
|
||||
|
||||
$init := fn(): Self {
|
||||
return .(0, null)
|
||||
}
|
||||
|
||||
alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn {
|
||||
offset := 1
|
||||
a := 1
|
||||
loop {
|
||||
// a = self.state >> offset
|
||||
// check if the `offset` bit is 1, if it is move to the next offset
|
||||
if a == 1 {
|
||||
offset += 1
|
||||
log.info("Already Allocated\0")
|
||||
} else {
|
||||
// self it to 1 and return the ptr to the allocation
|
||||
self.state |= a
|
||||
// return ptr + offset * 64
|
||||
if self.ptr != null {
|
||||
return .(64, self.ptr + offset * 64)
|
||||
} else {
|
||||
// panic.panic("Allocator is not inited.\0")
|
||||
// return .(0, null)
|
||||
}
|
||||
}
|
||||
// there are only 64 blocks
|
||||
if offset >= 64 {
|
||||
return .(0, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void {
|
||||
// size := size_of(alloc_type)*count
|
||||
size := 64
|
||||
// get the size alligned to the nearest block
|
||||
// rounded_size := nearest_block_size_rounded_up(size)
|
||||
rounded_size := 64
|
||||
|
||||
state_bit_start := {
|
||||
// Do math here to figure out what starting ptr corresponds to what bit
|
||||
3
|
||||
}
|
||||
|
||||
offset := 0
|
||||
|
||||
loop {
|
||||
if rounded_size > 0 {
|
||||
// set state_bit_start+offset to 0
|
||||
|
||||
// at the end move to the next one
|
||||
offset += 1
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
rounded_size -= 64
|
||||
}
|
||||
return void
|
||||
}
|
||||
|
||||
$deinit := fn(self: Self): void {
|
||||
self.state = 0
|
||||
self.ptr = null
|
||||
}
|
||||
}
|
||||
|
||||
// request a kernel page
|
||||
// ptr := memory.alloc(1)
|
|
@ -1,19 +0,0 @@
|
|||
alloc_return := @use("alloc_return.hb")
|
||||
|
||||
FakeAlloc := struct {
|
||||
$init := fn(): Self {
|
||||
return .()
|
||||
}
|
||||
|
||||
$alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn {
|
||||
return .(0, null)
|
||||
}
|
||||
|
||||
$dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void {
|
||||
return void
|
||||
}
|
||||
// Nothing to clean up here
|
||||
$deinit := fn(self: Self): void {
|
||||
return void
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
.{BlockAlloc} := @use("block_alloc.hb");
|
||||
.{FakeAlloc} := @use("fake_alloc.hb")
|
|
@ -1,25 +0,0 @@
|
|||
allocators := @use("alloc/alloc.hb")
|
||||
|
||||
AStruct := struct {
|
||||
a_field: u8,
|
||||
}
|
||||
|
||||
main := fn():void{
|
||||
alloc := allocators.FakeAlloc.init()
|
||||
astruct := alloc.alloc(AStruct, 2)
|
||||
if astruct.ptr != null{
|
||||
panic("FakeAlloc actually allocated.")
|
||||
}
|
||||
alloc.dealloc(astruct_ptr, AStruct, 2)
|
||||
alloc.deinit()
|
||||
|
||||
balloc := allocators.BlockAlloc.init()
|
||||
bstruct_ptr := balloc.alloc(AStruct, 2)
|
||||
if bstruct_ptr == null {
|
||||
panic("BlockAlloc actually didn't allocate.")
|
||||
}
|
||||
balloc.dealloc(bstruct_ptr, AStruct, 2)
|
||||
balloc.deinit()
|
||||
|
||||
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
acs := @use("acs.hb")
|
||||
allocators := @use("alloc/lib.hb")
|
||||
string := @use("string.hb")
|
||||
log := @use("log.hb")
|
||||
memory := @use("memory.hb")
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
# alloc_test
|
|
@ -1,11 +0,0 @@
|
|||
[package]
|
||||
name = "alloc_test"
|
||||
authors = [""]
|
||||
|
||||
[dependants.libraries]
|
||||
|
||||
[dependants.binaries]
|
||||
hblang.version = "1.0.0"
|
||||
|
||||
[build]
|
||||
command = "hblang src/main.hb"
|
|
@ -1,28 +0,0 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{allocators, panic, log} := stn
|
||||
|
||||
AStruct := struct {
|
||||
a_field: u8,
|
||||
}
|
||||
|
||||
main := fn(): void {
|
||||
// alloc := allocators.FakeAlloc.init()
|
||||
// astruct := alloc.alloc(AStruct, 2)
|
||||
// if astruct.ptr != null{
|
||||
// panic.panic("FakeAlloc actually allocated.")
|
||||
// }
|
||||
// alloc.dealloc(&astruct.ptr, AStruct, 2)
|
||||
// alloc.deinit()
|
||||
|
||||
balloc := allocators.BlockAlloc.init()
|
||||
defer balloc.deinit()
|
||||
bstruct := balloc.alloc(AStruct, 2)
|
||||
if bstruct.ptr == null {
|
||||
log.info("Hi\0")
|
||||
// panic.panic("BlockAlloc actually didn't allocate.")
|
||||
} else {
|
||||
log.info("Allocator functioned.\0")
|
||||
}
|
||||
// balloc.dealloc(bstruct_ptr, AStruct, 2)
|
||||
return
|
||||
}
|
|
@ -1 +1 @@
|
|||
.{example: main} := @use("./examples/orbit.hb")
|
||||
.{example: main} := @use("./examples/text.hb")
|
|
@ -28,23 +28,20 @@ resolution = "1024x768x24"
|
|||
# [boot.limine.ableos.modules.horizon]
|
||||
# path = "boot:///horizon.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.ps2_mouse_driver]
|
||||
# path = "boot:///ps2_mouse_driver.hbf"
|
||||
[boot.limine.ableos.modules.ps2_mouse_driver]
|
||||
path = "boot:///ps2_mouse_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
||||
# path = "boot:///ps2_keyboard_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_client]
|
||||
# path = "boot:///sunset_client.hbf"
|
||||
[boot.limine.ableos.modules.sunset_client]
|
||||
path = "boot:///sunset_client.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_client_2]
|
||||
# path = "boot:///sunset_client_2.hbf"
|
||||
[boot.limine.ableos.modules.sunset_client_2]
|
||||
path = "boot:///sunset_client_2.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_server]
|
||||
# path = "boot:///sunset_server.hbf"
|
||||
[boot.limine.ableos.modules.sunset_server]
|
||||
path = "boot:///sunset_server.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.processes]
|
||||
# path = "boot:///processes.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.alloc_test]
|
||||
path = "boot:///alloc_test.hbf"
|
Loading…
Reference in a new issue