OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Very new to this. Usercode data gets overwritten with 0s
PostPosted: Sat Oct 30, 2021 12:01 pm 
Offline

Joined: Sat Oct 30, 2021 11:57 am
Posts: 1
First of all, I'm sorry if I have made very obvious mistakes. We were given a version of Pure64 that has a lot of the more complex stuff solved. What we have to do is implement some exceptions management, syscalls, and use that to code a very basic shell and some games from the Userspace.

The problem I'm having and I really don't understand why this happens is that, sometimes changing a line of code that has no relation whatsoever with other .c files somehow ends up messing up other binary code. Another thing I noticed is that a lot of the times, static variables that are intialized to zero for some reason have a completely different value when I run the code with gdb.

From what I understand, the first step that happens when running the os is that the Userspace code gets copied to address 0x400000, so I don't get why modifying something in kernel code could affect it.

Example 1:

When I initialize some variables from 'naiveConsole.c' with a zero:
Image



And I try to see its value when I call a naiveConsole function from 'initializeKernelBinary' I get this:
Image


So, it isn't that I am messing up something from the code on the Userspace (I think) since it hasn't even had the chance to run yet.

Example 2:

If I make an objdump of the Userspace code, and compare it to what gdb shows, in some functions the binary code is exactly the same, but in others, the content changes depending on what I write on 'naiveConsole.c':

The debugger shows me this:


Image

the consecutive 'add' instructions make it seem as if some repetitive data is corrupting the code maybe? (actually, the binary code for the instruction is a set of zeros, but I don't know where it comes from). The screen is supposed to start from address 0xB8000 so unless I'm messing something up with the prints, it shouldn't be happening

In reality it should be this:
Image

My professors could grade this as a pass, but I am probably going to keep working on this after, and I feel like the fact that it is *kind of* working is pure luck. If someone could give me an idea on where I could get more informed to understand what is wrong with it I would greatly appreciate it.

This is the Repo: https://github.com/Khato1319/naiveOS


Top
 Profile  
 
 Post subject: Re: Very new to this. Usercode data gets overwritten with 0s
PostPosted: Sun Oct 31, 2021 1:38 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
khato wrote:
(actually, the binary code for the instruction is a set of zeros, but I don't know where it comes from)

Sounds like it's time to set some breakpoints and see if you can catch whatever is overwriting it.

Try it with your corrupted variables, too.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 89 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