Compare commits

..

7 Commits

Author SHA1 Message Date
Philipp Oppermann
bb5899e437 Merge branch 'post-03' into post-04 2025-09-03 17:58:33 +02:00
Philipp Oppermann
93d0daa1e0 Merge branch 'post-02' into post-03 2025-09-03 17:58:28 +02:00
Philipp Oppermann
83e6c0bc00 Merge pull request #1436 from phil-opp/post-02-fix-target
Fix: `target-pointer-width` field now expects an integer
2025-09-03 17:56:38 +02:00
Philipp Oppermann
2b11ad8397 Fix: target-pointer-width field now expects an integer 2025-09-03 17:53:14 +02:00
Philipp Oppermann
fa51f3adbf Update to latest bootloader version 2025-09-03 17:52:56 +02:00
Philipp Oppermann
ceb91f955a Merge pull request #1434 from phil-opp/post-04-test-true
Set `test=true` to enable `main.rs` testing again
2025-08-26 16:41:21 +02:00
Philipp Oppermann
3340babf51 Set test=true to enable main.rs testing again
We set `test=false` for previous posts in https://github.com/phil-opp/blog_os/pull/1412 to avoid errors e.g. in rust-analyzer. For this testing post, we want to set it back to `true`.
2025-08-26 16:21:28 +02:00
7 changed files with 8 additions and 45 deletions

4
Cargo.lock generated
View File

@@ -34,9 +34,9 @@ dependencies = [
[[package]] [[package]]
name = "bootloader" name = "bootloader"
version = "0.9.32" version = "0.9.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ea119c3ed05625c179e09d17d0914570a3753ca09c890a73d98f6b72aea00d2" checksum = "7bdfddac270bbdd45903296bc1caf29a7fdce6b326aaf0bbab7f04c5f98b7447"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"

View File

@@ -21,7 +21,7 @@ features = ["spin_no_std"]
[[bin]] [[bin]]
name = "blog_os" name = "blog_os"
test = false test = true
bench = false bench = false

View File

@@ -1,10 +1,10 @@
# Blog OS (CPU Exceptions) # Blog OS (Testing)
[![Build Status](https://github.com/phil-opp/blog_os/workflows/Code/badge.svg?branch=post-05)](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-05) [![Build Status](https://github.com/phil-opp/blog_os/workflows/Code/badge.svg?branch=post-04)](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-04)
This repository contains the source code for the [CPU Exceptions][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series. This repository contains the source code for the [Testing][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
[post]: https://os.phil-opp.com/cpu-exceptions/ [post]: https://os.phil-opp.com/testing/
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.** **Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**

View File

@@ -1,25 +0,0 @@
use crate::println;
use lazy_static::lazy_static;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
lazy_static! {
static ref IDT: InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new();
idt.breakpoint.set_handler_fn(breakpoint_handler);
idt
};
}
pub fn init_idt() {
IDT.load();
}
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
}
#[test_case]
fn test_breakpoint_exception() {
// invoke a breakpoint exception
x86_64::instructions::interrupts::int3();
}

View File

@@ -1,19 +1,14 @@
#![no_std] #![no_std]
#![cfg_attr(test, no_main)] #![cfg_attr(test, no_main)]
#![feature(custom_test_frameworks)] #![feature(custom_test_frameworks)]
#![feature(abi_x86_interrupt)]
#![test_runner(crate::test_runner)] #![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"] #![reexport_test_harness_main = "test_main"]
use core::panic::PanicInfo; use core::panic::PanicInfo;
pub mod interrupts;
pub mod serial; pub mod serial;
pub mod vga_buffer; pub mod vga_buffer;
pub fn init() {
interrupts::init_idt();
}
pub trait Testable { pub trait Testable {
fn run(&self) -> (); fn run(&self) -> ();
} }
@@ -64,7 +59,6 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
#[cfg(test)] #[cfg(test)]
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! { pub extern "C" fn _start() -> ! {
init();
test_main(); test_main();
loop {} loop {}
} }

View File

@@ -11,15 +11,9 @@ use core::panic::PanicInfo;
pub extern "C" fn _start() -> ! { pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!"); println!("Hello World{}", "!");
blog_os::init();
// invoke a breakpoint exception
x86_64::instructions::interrupts::int3();
#[cfg(test)] #[cfg(test)]
test_main(); test_main();
println!("It did not crash!");
loop {} loop {}
} }

View File

@@ -3,7 +3,7 @@
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"arch": "x86_64", "arch": "x86_64",
"target-endian": "little", "target-endian": "little",
"target-pointer-width": "64", "target-pointer-width": 64,
"target-c-int-width": 32, "target-c-int-width": 32,
"os": "none", "os": "none",
"executables": true, "executables": true,