summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2019-10-31 21:06:46 +0100
committerDennis Kobert <dennis@kobert.dev>2019-10-31 21:06:46 +0100
commit6c09097e5441eafc971c8d5d414963a4e66a892f (patch)
treec1af76085f453dc2503ce85030bcafcc0c234110
parent5a00ecaa8bdc60e1849de1df8c1655fa84faf984 (diff)
Add testing to build
-rwxr-xr-xkernel/build.sh27
-rw-r--r--kernel/src/io/mod.rs3
-rw-r--r--kernel/src/io/serial.rs26
-rw-r--r--kernel/src/io/text_buffer.rs0
-rw-r--r--kernel/src/io/vga_text.rs (renamed from kernel/src/vga_text.rs)31
5 files changed, 66 insertions, 21 deletions
diff --git a/kernel/build.sh b/kernel/build.sh
index d8086b6..86842b1 100755
--- a/kernel/build.sh
+++ b/kernel/build.sh
@@ -9,10 +9,13 @@ GRUB_CFG_PATH="src/grub.cfg"
ARCH="x86_64"
TARGET="$ARCH-uff"
RUST_BIN="$TARGET_PATH/$TARGET/debug/libkernel.a"
+QUEMU="qemu-system-x86_64 -cdrom $TARGET_PATH/uff.iso"
-remove_target() {
- rm -rf $TMP_PATH/* &> /dev/null
+cleanup_target() {
rm -f $TARGET_PATH/uff.iso &> /dev/null
+ rm -rf $TARGET_PATH/kernel.bin
+
+ cleanup_temp
}
create_target() {
@@ -54,7 +57,11 @@ build_init() {
}
build_launch() {
- qemu-system-x86_64 -cdrom $TARGET_PATH/uff.iso
+ $QUEMU
+}
+
+build_launch_serial() {
+ $QEMU -device isa-debug-exit,iobase=0xf4,iosize=0x04 -serial stdio #-display none
}
build_run() {
@@ -65,16 +72,20 @@ build_run() {
}
build_clean() {
- remove_target
+ cleanup_target
}
build_build() {
cargo xbuild
- rm -rf $TARGET_PATH/sysroot
- rm -rf $TARGET_PATH/kernel.bin
- rm -rf $TARGET_PATH/uff.iso
+ cleanup_target
build_run
}
+build_build() {
+ cargo xbuild --features testing
+ cleanup_target
+ build_kernel_iso
+ build_launch_serial
+}
build_all() {
build_kernel_elf
@@ -91,6 +102,7 @@ for arg in "$@"; do
"run") build_run;;
"clean") build_clean;;
"build") build_build;;
+ "test") build_tests;;
"all") build_all;;
*)
echo "warn: ignoring unknown option '$arg'"
@@ -107,6 +119,7 @@ print_help() {
echo " clean cleanup binaries"
echo " launch launch iso in qemu"
echo " run creates iso if necessary and runs it in qemu"
+ echo " test runs tests in qemu"
echo
echo " kernel-elf build the kernel-elf"
echo " kernel-iso build the kernel-elf if necessary and the kernel-iso"
diff --git a/kernel/src/io/mod.rs b/kernel/src/io/mod.rs
new file mode 100644
index 0000000..8a0652e
--- /dev/null
+++ b/kernel/src/io/mod.rs
@@ -0,0 +1,3 @@
+pub mod serial;
+pub mod vga_text;
+
diff --git a/kernel/src/io/serial.rs b/kernel/src/io/serial.rs
new file mode 100644
index 0000000..bab770d
--- /dev/null
+++ b/kernel/src/io/serial.rs
@@ -0,0 +1,26 @@
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[repr(u32)]
+pub enum QemuExitCode {
+ Success = 0x10, // The actual exit code is (value << 1) | 1.
+ 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);
+ }
+}
+
+#[test_case]
+fn trivial_assertion() {
+ use crate::vga_text::OStream;
+ let mut stdout = OStream::new();
+ stdout.clear();
+
+ stdout.print(b"trivial assertion... ");
+ assert_eq!(0, 1);
+ stdout.print(b"[ok]");
+}
diff --git a/kernel/src/io/text_buffer.rs b/kernel/src/io/text_buffer.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/kernel/src/io/text_buffer.rs
diff --git a/kernel/src/vga_text.rs b/kernel/src/io/vga_text.rs
index a292c8c..f60e6e1 100644
--- a/kernel/src/vga_text.rs
+++ b/kernel/src/io/vga_text.rs
@@ -18,6 +18,9 @@ pub enum Color {
White = 15,
}
+pub const WIDTH = 80;
+pub const HEIGHT = 25;
+
#[derive(Clone, Copy)]
pub struct CharState(pub u8);
@@ -27,7 +30,7 @@ impl CharState {
}
pub fn set_fg(&mut self, fg: Color) {
- self.0 = (self.0 & 240) | (fg as u8)
+ self.0 = (self.0 & HEIGHT - 10) | (fg as u8)
}
pub fn set_bg(&mut self, bg: Color) {
@@ -64,25 +67,25 @@ impl OStream {
}
fn at(n: usize) -> *mut VgaChar {
- (0xb8000 + (n << 1)) as *mut VgaChar
+ (0xbWIDTH00 + (n << 1)) as *mut VgaChar
}
fn compute_cursor(&mut self) {
- self.cursor = Self::at(self.pos.0 as usize + self.pos.1 as usize * 80)
+ self.cursor = Self::at(self.pos.0 as usize + self.pos.1 as usize * WIDTH)
}
pub fn set_col(&mut self, col: u8) {
- self.pos.0 = core::cmp::min(col, 79);
+ self.pos.0 = core::cmp::min(col, WIDTH - 1);
self.compute_cursor()
}
pub fn set_row(&mut self, row: u8) {
- self.pos.1 = core::cmp::min(row, 24);
+ self.pos.1 = core::cmp::min(row, HEIGHT - 1);
self.compute_cursor()
}
pub fn set_cursor(&mut self, col: u8, row: u8) {
- self.pos = (core::cmp::min(col, 79), core::cmp::min(row, 24));
+ self.pos = (core::cmp::min(col, WIDTH - 1), core::cmp::min(row, HEIGHT - 1));
self.compute_cursor()
}
@@ -93,7 +96,7 @@ impl OStream {
pub fn put_char(&mut self, c: VgaChar) {
if c.byte == b'\n' {
self.new_line();
- } else if self.pos.0 >= 79 {
+ } else if self.pos.0 >= WIDTH - 1 {
self.new_line();
self.put_char(c);
} else {
@@ -109,16 +112,16 @@ impl OStream {
pub fn clear(&self) {
let c = VgaChar::from_state_and_byte(self.state, b' ');
- for i in 0..2000 {
+ for i in 0..(WIDTH * HEIGHT) {
unsafe {Self::at(i).write_volatile(c)}
}
}
pub fn new_line(&mut self) {
- if self.pos.1 >= 24 {
+ if self.pos.1 >= HEIGHT - 1 {
self.set_col(0);
for i in 0..1920 {
- unsafe {Self::at(i).write_volatile(*Self::at(i + 80))}
+ unsafe {Self::at(i).write_volatile(*Self::at(i + WIDTH))}
}
} else {
self.set_cursor(0, self.pos.1 + 1);
@@ -140,15 +143,15 @@ impl OStream {
let mut n = 0;
let slast = s.len() - 1;
for (i, &b) in s.iter().enumerate() {
- if n >= 80 {
+ if n >= WIDTH {
self.set_col(0);
- self.print(&line[..80]);
- line = &line[80..];
+ self.print(&line[..WIDTH]);
+ line = &line[WIDTH..];
n = 0;
}
if b == b'\n' || i == slast {
if b != b'\n' { n += 1 }
- self.set_col(((80 - n) / 2) as u8);
+ self.set_col(((WIDTH - n) / 2) as u8);
self.print(&line[..n]);
self.new_line();
if i == slast { return; }