-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move lots of test functions to lib.rs and basicboot
- Loading branch information
1 parent
78086b5
commit e8e9feb
Showing
4 changed files
with
161 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,56 @@ | ||
# runix | ||
|
||
*"rust written microkernel soon hopefully"* | ||
***"rust written microkernel hopefully"*** | ||
|
||
ok so far i think you need to switch to nightly rust and then run cargo install bootimage and rustup component add llvm-tools-preview and then you can run `cargo bootimage` and then you can run the cargo run command and it should work. | ||
---- | ||
|
||
## Features | ||
- [x] Booting | ||
- [x] VGA Text Mode | ||
- [x] Serial Output | ||
- bout it so far | ||
|
||
|
||
## Roadmap | ||
- [ ] ISO Generation or IMG Generation | ||
- [ ] Memory Management | ||
- [ ] Multitasking | ||
- [ ] Filesystem | ||
- [ ] Userland | ||
- [ ] Networking | ||
|
||
|
||
## Building | ||
|
||
```bash | ||
rustup default nightly | ||
cargo install bootimage | ||
rustup component add llvm-tools-preview | ||
cargo run | ||
``` | ||
|
||
## License | ||
|
||
``` | ||
MIT License | ||
Copyright (c) 2023 Amarnath P. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#![no_std] | ||
#![no_main] | ||
#![feature(custom_test_frameworks)] | ||
#![test_runner(crate::test_runner)] | ||
#![reexport_test_harness_main = "test_main"] | ||
|
||
use core::panic::PanicInfo; | ||
|
||
#[no_mangle] // i wonder why compilers mangle names lol | ||
pub extern "C" fn _start() -> ! { | ||
test_main(); | ||
loop {} | ||
} | ||
|
||
fn test_runner(tests: &[&dyn Fn()]) { | ||
unimlpemented!(); | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(info: &PanicInfo) -> ! { | ||
loop {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#![no_std] | ||
#![cfg_attr(test, no_main)] | ||
#![feature(custom_test_frameworks)] | ||
#![test_runner(crate::test_runner)] | ||
#![reexport_test_harness_main = "test_main"] | ||
|
||
use core::panic::PanicInfo; | ||
pub mod serial; | ||
pub mod vga_buffer; | ||
|
||
pub trait Testable { | ||
fn run(&self) -> (); | ||
} | ||
|
||
impl<T> Testable for T | ||
where | ||
T: Fn(), | ||
{ | ||
fn run(&self) { | ||
serial_print!("{}...\t", core::any::type_name::<T>()); | ||
self(); | ||
serial_println!("[ok]"); | ||
} | ||
} | ||
|
||
pub fn test_runner(tests: &[&dyn Testable]) { | ||
serial_println!("Running {} tests", tests.len()); | ||
for test in tests { | ||
test.run(); | ||
} | ||
exit_qemu(QemuExitCode::Success); | ||
} | ||
|
||
pub fn test_panic_handler(info: &PanicInfo) -> ! { | ||
serial_println!("[failed]\n"); | ||
serial_println!("Error: {}\n", info); | ||
exit_qemu(QemuExitCode::Failed); | ||
loop {} | ||
} | ||
|
||
/// entry point for cargo test-tickles | ||
#[cfg(test)] | ||
#[no_mangle] | ||
|
||
pub extern "C" fn _start() -> ! { | ||
test_main(); | ||
loop {} | ||
} | ||
|
||
#[cfg(test)] | ||
#[panic_handler] | ||
|
||
fn panic(info: &PanicInfo) -> ! { | ||
test_panic_handler(info) | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
#[repr(u32)] | ||
|
||
pub enum QemuExitCode { | ||
Success = 0x10, | ||
Failed = 0x11, | ||
} | ||
|
||
pub fn exit_qemu(exit_code: QemuExitCode) { | ||
use x86_64::instructions::port::Port; | ||
|
||
unsafe { | ||
let mut port = Port::new(0xf4); | ||
port.write(exit_code as u32); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters