summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authornatrixaeria <upezu@student.kit.edu>2019-11-15 20:03:23 +0100
committernatrixaeria <upezu@student.kit.edu>2019-11-15 20:03:23 +0100
commitfe488737784da2196b84dbc22b658bf12a5f58f9 (patch)
tree1e4b39c0668380407e21bb35484a172410eb4d7a /kernel
parent57850278fd6540dbf485db38d6819cbf40e0adf0 (diff)
parent8ee78510c4e182c636bd1ae851e38124985952fd (diff)
Merge branch 'master' of dennis:/var/repos/uff-os
Diffstat (limited to 'kernel')
-rw-r--r--kernel/.cargo/config7
-rw-r--r--kernel/Cargo.toml3
-rwxr-xr-xkernel/run41
-rw-r--r--kernel/src/asm/boot.asm7
-rw-r--r--kernel/src/interrupts/exceptions.rs26
-rw-r--r--kernel/src/interrupts/idt.rs2
-rw-r--r--kernel/src/interrupts/mod.rs11
-rw-r--r--kernel/tests/int3.rs2
-rw-r--r--kernel/tests/stack_overflow.rs2
9 files changed, 55 insertions, 46 deletions
diff --git a/kernel/.cargo/config b/kernel/.cargo/config
index b74f97c..992b819 100644
--- a/kernel/.cargo/config
+++ b/kernel/.cargo/config
@@ -2,5 +2,8 @@
target = "x86_64-uff.json"
rustflags = ["-Clink-arg=-r","-Clink-dead-code"]
-[target.'cfg(target_os = "none")']
-runner = "./run test -test"
+[target.'cfg(all(target_os = "none", feature = "testing_qemu"))']
+runner = "./run -test -serial"
+
+[target.'cfg(all(target_os = "none", not(feature = "testing_qemu")))']
+runner = "./run -test"
diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml
index 1baefdb..75f5503 100644
--- a/kernel/Cargo.toml
+++ b/kernel/Cargo.toml
@@ -13,6 +13,9 @@ harness = false
name = "stack_overflow"
harness = false
+[features]
+testing_qemu = []
+
[package.metadata.cargo-xbuild]
sysroot_path = "target/sysroot"
diff --git a/kernel/run b/kernel/run
index d7d6e85..3420ac1 100755
--- a/kernel/run
+++ b/kernel/run
@@ -8,7 +8,7 @@ onerr() {
trap onerr ERR
name="uff"
-build_mode=release
+build_mode=debug
action=help
target=x86_64
test_mode=false
@@ -28,19 +28,16 @@ function define_vars() {
define_vars
print_help() {
- echo "usage: $0 (options) [action]"
+ echo "usage: $0 (options) [Path]"
+ echo " build and lauch the iso in qemu"
+ echo
echo "options:"
echo " -name=<str> set application name (standard: $name)"
echo " -mode=<str> set build mode (standard: $build_mode)"
echo " -target=<str> set target (standard: $target)"
echo " -test enable test mode (standard: disabled)"
echo " -serial enable serial mode (standard: disabled)"
- echo
- echo "actions:"
- echo " build build the iso"
- echo " run build and lauch the iso in qemu"
- echo " test build iso in test mode and run it in qemu"
- echo " help show this help message"
+ echo " -help show this help message"
exit
}
@@ -76,14 +73,6 @@ build() {
if test ! -d "$iso_path/isofiles"; then
prepare_iso
fi
- #if $test_mode; then
- # RUSTFLAGS="-Clink-arg=-r -Clink-dead-code" cargo xtest --no-run
- #else
- # cargo xbuild
- #fi
- if ! $test_mode; then
- cargo xbuild "--$build_mode"
- fi
build_iso
}
@@ -93,9 +82,9 @@ run() {
qemu="qemu-system-x86_64 -cdrom $iso_path/$name.iso -cpu kvm64,+apic"
if $test_mode; then
qemu="$qemu -device isa-debug-exit,iobase=0xf4,iosize=0x04 -serial stdio -no-reboot "
- if $serial_mode; then
- qemu="$qemu -display none"
- fi
+ fi
+ if $serial_mode; then
+ qemu="$qemu -display none"
fi
$qemu
case "$?" in
@@ -122,21 +111,15 @@ for arg in "$@"; do
test_mode=true; define_vars;;
-serial)
serial_mode=true; define_vars;;
- "run") action=run;;
- "build") action=build;;
- "test") action=test;;
- "help") action=help;;
+ -help)
+ print_help;;
*)
# echo "warn: ignoring unknown option '$arg'"
kernel_libary=$arg;;
esac
done
-case "$action" in
- "help") print_help;;
- "build") build;;
- "test") test_mode=true; build; run;;
- "run") build; run;;
-esac
+build
+run
echo -e "\x1b[1;32mdone\x1b[m"
diff --git a/kernel/src/asm/boot.asm b/kernel/src/asm/boot.asm
index 9964636..6449d66 100644
--- a/kernel/src/asm/boot.asm
+++ b/kernel/src/asm/boot.asm
@@ -91,10 +91,13 @@ setup_page_tables:
mov eax, p2_table
or eax, 0b11 ; present + writable
mov [p3_table], eax
+
+ mov eax, 0b10000111 ; huge + no caching + writable + present
+ mov [p2_table], eax
; map each P2 entry to a huge 2MiB page
- mov ecx, 0 ; counter variable
- mov eax, 0b10000011 ; huge + writable + present
+ mov ecx, 8 ; counter variable
+ mov eax, 0x200000 + 0b10000011 ; huge + writable + present
.map_p2_table:
cmp eax, 0b10000011 + stack_bottom
diff --git a/kernel/src/interrupts/exceptions.rs b/kernel/src/interrupts/exceptions.rs
index f6d5176..a3ecf9d 100644
--- a/kernel/src/interrupts/exceptions.rs
+++ b/kernel/src/interrupts/exceptions.rs
@@ -13,10 +13,10 @@ macro_rules! exception_default {
};
}
-static mut expected_fault: Interrupts = Interrupts::NONE;
+static mut expected_fault: Interrupts = Interrupts::None;
pub unsafe fn expect_fault(int: Interrupts) {
- if expected_fault == Interrupts::NONE {
+ if expected_fault == Interrupts::None {
expected_fault = int;
}
}
@@ -27,7 +27,7 @@ fn get_expected_fault() -> Interrupts {
pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) {
match get_expected_fault() {
- Interrupts::BREAKPOINT => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ Interrupts::Breakpoint => qemu::exit_qemu(qemu::QemuExitCode::Success),
_ => panic!(
"BREAKPOINT exception thrown\n\n{}",
exception_default!(stack_frame)
@@ -35,6 +35,20 @@ pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStac
}
}
+pub extern "x86-interrupt" fn general_protection_fault_handler(
+ stack_frame: &mut InterruptStackFrame,
+ error_code: u64,
+) {
+ match get_expected_fault() {
+ Interrupts::GeneralProtectionFault => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ _ => panic!(
+ "GENERAL PROTECTION exception thrown\nerror code: {:x}\n{}",
+ error_code,
+ exception_default!(stack_frame)
+ ),
+ }
+}
+
pub extern "x86-interrupt" fn page_fault_handler(
stack_frame: &mut InterruptStackFrame,
error_code: PageFaultErrorCode,
@@ -42,7 +56,7 @@ pub extern "x86-interrupt" fn page_fault_handler(
use x86_64::registers::control::Cr2;
match get_expected_fault() {
- Interrupts::PAGE_FAULT => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ Interrupts::PageFault => qemu::exit_qemu(qemu::QemuExitCode::Success),
_ => panic!(
"PAGE FAULT while accessing address: 0x{:08x}\nerror code: {:?}(0x{:x})\n{}",
Cr2::read().as_u64(),
@@ -58,7 +72,7 @@ pub extern "x86-interrupt" fn segment_not_present_handler(
error_code: u64,
) {
match get_expected_fault() {
- Interrupts::NOT_PRESENT => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ Interrupts::NotPresent => qemu::exit_qemu(qemu::QemuExitCode::Success),
_ => panic!(
"SEGMENT NOT PRESENT exception\nerror code: 0x{:x}\n{}",
error_code,
@@ -72,7 +86,7 @@ pub extern "x86-interrupt" fn double_fault_handler(
_error_code: u64, // code is always zero
) {
match get_expected_fault() {
- Interrupts::NOT_PRESENT => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ Interrupts::DoubleFault => qemu::exit_qemu(qemu::QemuExitCode::Success),
_ => panic!(
"DOUBLE FAULT\nthis is a fatal exception\n{}",
exception_default!(stack_frame)
diff --git a/kernel/src/interrupts/idt.rs b/kernel/src/interrupts/idt.rs
index 9541f22..e85ef5a 100644
--- a/kernel/src/interrupts/idt.rs
+++ b/kernel/src/interrupts/idt.rs
@@ -8,6 +8,8 @@ lazy_static! {
.set_handler_fn(super::exceptions::breakpoint_handler);
idt.segment_not_present
.set_handler_fn(super::exceptions::segment_not_present_handler);
+ idt.general_protection_fault
+ .set_handler_fn(super::exceptions::general_protection_fault_handler);
unsafe {
idt.double_fault
.set_handler_fn(super::exceptions::double_fault_handler)
diff --git a/kernel/src/interrupts/mod.rs b/kernel/src/interrupts/mod.rs
index 9753b6b..609fb6d 100644
--- a/kernel/src/interrupts/mod.rs
+++ b/kernel/src/interrupts/mod.rs
@@ -6,9 +6,10 @@ pub mod idt;
#[repr(usize)]
#[derive(PartialEq, Clone, Copy)]
pub enum Interrupts {
- NONE,
- PAGE_FAULT,
- DOUBLE_FAULT,
- NOT_PRESENT,
- BREAKPOINT,
+ None,
+ PageFault,
+ DoubleFault,
+ NotPresent,
+ Breakpoint,
+ GeneralProtectionFault,
}
diff --git a/kernel/tests/int3.rs b/kernel/tests/int3.rs
index f4e2116..f5b5470 100644
--- a/kernel/tests/int3.rs
+++ b/kernel/tests/int3.rs
@@ -13,7 +13,7 @@ use kernel::io::qemu;
extern "C" fn _start() -> ! {
kernel::init();
unsafe {
- exceptions::expect_fault(interrupts::Interrupts::BREAKPOINT);
+ exceptions::expect_fault(interrupts::Interrupts::Breakpoint);
}
x86_64::instructions::interrupts::int3();
panic!("BREAKPOINT not caught");
diff --git a/kernel/tests/stack_overflow.rs b/kernel/tests/stack_overflow.rs
index eedb3b5..9e75f59 100644
--- a/kernel/tests/stack_overflow.rs
+++ b/kernel/tests/stack_overflow.rs
@@ -14,7 +14,7 @@ use kernel::io::qemu;
extern "C" fn _start() -> ! {
kernel::init();
unsafe {
- exceptions::expect_fault(interrupts::Interrupts::NOT_PRESENT);
+ exceptions::expect_fault(interrupts::Interrupts::PageFault);
}
_loop(0);
panic!("PAGE_FAULT not caught");