limine-bootloader / limine-rust-template

A simple template for building a Limine-compliant kernel in Rust.
BSD Zero Clause License
24 stars 4 forks source link

Not booting #10

Closed commitcompanion closed 1 month ago

commitcompanion commented 1 month ago

1.It is possible to edit the file so that no funktionality is inside and the cpu stops. (File 1) main.rs.txt 2.When a new funktionality is build in the kernel will not boot: Rust:

[no_mangle]

unsafe extern "C" fn _start() -> ! { // All limine requests must also be referenced in a called function, otherwise they may be // removed by the linker. assert!(BASE_REVISION.is_supported());

if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() {
    if let Some(framebuffer) = framebuffer_response.framebuffers().next() {
        let width = framebuffer.width() as usize;
        let height = framebuffer.height() as usize;
        let center_x = width / 2;
        let center_y = height / 2;
        let pixel_offset = center_y * framebuffer.pitch() + center_x * 4;

        // Write 0xFFFFFFFF to the provided pixel offset to fill it white.
        *(framebuffer.addr().add(pixel_offset) as *mut u32) = 0xFFFFFFFF;
    }
}

hcf();

}


  1. In this case the compiler don't find any bugs.
  2. limine tries to boot the kernel and does not make any error
  3. the virtual machine is rebooting.

Is it right that normaqly the cpu should stop if an error happend? and not that limine or the kernel are rebooting ? why it works with the example code?

Thank you for answers!

Ps: the vga print code is from the https://os.phil-opp.com/minimal-rust-kernel/ guide, because its smaler than the other methods to do something like this. If there would be an error, cargo would say it or the code will do nothing and the cpu halts

commitcompanion commented 1 month ago

Of course, the code would be implemented differently.

commitcompanion commented 1 month ago

another example code:#[no_mangle] unsafe extern "C" fn _start() -> ! { assert!(BASE_REVISION.is_supported());

let vga_buffer = 0xb8000 as *mut u8;
let message = b"Hello, world!";
let color = 0x07; // white text on black background

for (i, &byte) in message.iter().enumerate() {
    *vga_buffer.offset(i as isize * 2) = byte;
    *vga_buffer.offset(i as isize * 2 + 1) = color;
}

hcf();

}

qookei commented 1 month ago

You can't write to the VGA text mode buffer like that. Firstly, there is no identity mapping with base revision 1 (which is the default if you just use BaseRevision::new()), and secondly, Limine does not guarantee that text mode will exist, and does not provide it at all (and for example, if you're on UEFI, it's just plain unavailable).

commitcompanion commented 1 month ago

Thank you! But why the kernel just reboots? If the debugger detects nothing, and there is an error it should halt the cpu. But the vm reboots.

48cf commented 1 month ago

It reboots as a result of a triple fault, which occurs when the CPU fails to invoke the double fault exception handler. A double fault exception is an exception raised when the CPU fails to invoke an exception handler. Since you're accessing unmapped memory (the VGA memory att 0xb8000) the CPU raises a page fault exception, and since you did not install an IDT the CPU can't handle the exception resulting in a chain of exceptions I described above.

commitcompanion commented 1 month ago

Is there a library or method that is compatible with the template?

lylythechosenone commented 1 month ago

What do you mean by that? Writing to the VGA text buffer will never be supported with Limine. However, the Limine creators do have another package, flanterm, that provides a simple terminal interface.

commitcompanion commented 1 month ago

and flantterm works in a freestanding binary?

lylythechosenone commented 1 month ago

Yes. That's the only place it works.

commitcompanion commented 1 month ago

can i use the flanterm_bindings crate?

lylythechosenone commented 1 month ago

Yes. However, this is no longer an issue about limine-rs, so I am going to close it. For assistance, I suggest that you ask on the osdev or limine discord servers.