OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:32 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Kernel runtime error.
PostPosted: Sun Jun 23, 2019 2:35 pm 
Offline

Joined: Sun Jun 23, 2019 2:06 pm
Posts: 1
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 #-o 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.


Top
 Profile  
 
 Post subject: Re: Kernel runtime error.
PostPosted: Wed Jun 26, 2019 10:53 am 
Offline
Member
Member
User avatar

Joined: Mon May 22, 2017 5:56 am
Posts: 812
Location: Hyperspace
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! :D

_________________
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie


Top
 Profile  
 
 Post subject: Re: Kernel runtime error.
PostPosted: Wed Jun 26, 2019 12:24 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], thewrongchristian and 79 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group