OSDev.org https://forum.osdev.org/ |
|
Kernel runtime error. https://forum.osdev.org/viewtopic.php?f=1&t=33740 |
Page 1 of 1 |
Author: | alittlepotato [ Sun Jun 23, 2019 2:35 pm ] |
Post subject: | Kernel runtime error. |
I'm coding an OS in Assembly and Rust. I use my own bootloader assembled in NASM and I load the Kernel from floppy. My problem is that my os crash when I increment a structure int variable or a public static (global) int variable. Code: //A pub fn display(&mut self, data: &str) -> u8{ for byte in data.bytes(){ // [...] self.column += 1; // for example it will crash here. if self.column == 80{ self.newline(); self.column = 0; } } return 0; } I first thought it was a problem of memory then I realised that I forgot to enable A20 line but it still doesn't work. The bootloader's steps (if I forgot something) : Boot Read kernel Switch to PM, Boot second stage Enable A20 Switch Long Mode Call kernel at 0x1000. (I assemble the second stage as ELF64 and I link it to the Rust code (kernel) using LD then I link it to the first stage BIN file). Sorry if I did basics mistakes I'm still learning. Thanks. |
Author: | eekee [ Wed Jun 26, 2019 10:53 am ] |
Post subject: | Re: Kernel runtime error. |
Um... I don't know anything about Rust specifically, but just looking at the wiki page, did you include the annotation to use only the core library? I'm wondering if it's a problem with missing runtime allocation, and guessing the compiler would catch it if you included the annotation. Of course, I could easily be waaay off target. Looking at a few links, Rust seems really nice for building kernels, minimizing the fuss of getting the compiler and language to output appropriate code... except for floating point being a mandatory part of libcore. There's something wrong with everything! |
Author: | Ethin [ Wed Jun 26, 2019 12:24 pm ] |
Post subject: | Re: Kernel runtime error. |
I'm surprised Rust is letting you do this at all (modifying a mutable static -- or even interacting with one -- is unsafe). Try storing all your contextual data (I'm assuming this is the VGA buffer) in a struct, then use the lazy_static crate to initialize it on its first use. (I'd highly recommend you also use the spin crate and lock a spinlock around it to prevent a data race.) Finally, ensure your running on the nightly channel; OS Development requires a lot of unsafe and unstable features . Some crates that will help you greatly: x86_64 - allows you to use some asm instructions and read/write to some CPU registers uart_16550 - serial port output (but not input) volatile - ensures that volatile reads/writes to memory are not optimized away spin - great, handy, useful spinlocks pic8259_simple - simple interaction with the 8259 PIC (I still don't know how to use the APIC, am trying to get ACPI in haha) pc-keyboard - decoding and processing of keys. (Don't use this as your sole keyboard processor though, build a keyboard driver -- its much better that way IMO)! raw-cpuid - easy CPU identification cpuio - CPU IO to ports bit_field - easy manipulation of bit fields |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |