OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:08 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Memory Management code reboots my kernel
PostPosted: Mon Jun 26, 2017 5:58 am 
Offline

Joined: Sun Aug 21, 2016 10:18 am
Posts: 17
Location: Cyprus, Greece
Hello, i am trying to implement the paging and heap on my kernel, with the help of jmolloy's tutorial, and when i link the page and heap code with the rest and run it, it flashes on the boot screen,(it finds the kernel but then it searches for it and goes), which i think is rebooting. If i remove the paging/heap files, everything works fine. So this made me believe that the problem is in those files. I use a simple custom bootloader, my kernel image is a binary file, and i run it with qemu. I tried to debug it using prints and gdb but i couldn't find what is the problem. Can you help me? If you want more info, tell me.


Top
 Profile  
 
 Post subject: Re: Memory Management code reboots my kernel
PostPosted: Mon Jun 26, 2017 6:19 am 
Offline
Member
Member

Joined: Wed Jun 17, 2015 9:40 am
Posts: 501
Location: Athens, Greece
Hi,


I suggest you don't use the James Molloy's tutorial (see http://wiki.osdev.org/James_Molloy's_Tutorial_Known_Bugs).

As for the paging code, try inspecting your code in an emulator+debugger+objdump/disassembler. Possible causes may be:
  • Invalid cr3 value (not a pointer to the page directory). Note: It has to be aligned on page boundaries.
  • Invalid contents of page directory. Note: Assuming 32-bit x86, the lower 12 bits don't contribute to the physical address and, instead, they are various flags. Make sure "present" and various permissions are set properly!
  • Invalid contents of page tables. Note: The same mentality as with page directories applies here, although the flags are not entirely the same.
  • Some code (even outside the paging/heap files) causes a page fault and the page fault handler is not set up correctly so it causes a double fault and the double fault handler is not set up correctly so a triple fault is triggered and the machine reboots.
  • A combination of the above and/or something else.

In short, you would get far better help if you showed us the code, although debugging, as suggested above, is still a valuable skill to possess.

Hope this helps. :-)


Regards,
glauxosdever


Top
 Profile  
 
 Post subject: Re: Memory Management code reboots my kernel
PostPosted: Mon Jun 26, 2017 7:00 am 
Offline

Joined: Sun Aug 21, 2016 10:18 am
Posts: 17
Location: Cyprus, Greece
Hello, Thanks for the reply :) , the code is attached below. I am also trying to debug it and find the mistake but its a bit hard. As for the tutorial, i am just trying to create a basic version of my os that works, and then try to make it better, and change some of the code, or make a better implementation of something. Do you suggest me any other tutorial or something else?


Attachments:
CPOS.zip [59.22 KiB]
Downloaded 22 times
Top
 Profile  
 
 Post subject: Re: Memory Management code reboots my kernel
PostPosted: Mon Jun 26, 2017 1:25 pm 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 384
Chpetrou wrote:
Hello, Thanks for the reply :) , the code is attached below. I am also trying to debug it and find the mistake but its a bit hard. As for the tutorial, i am just trying to create a basic version of my os that works, and then try to make it better, and change some of the code, or make a better implementation of something. Do you suggest me any other tutorial or something else?

You may want to use the bare bones or meaty skeleton from the wiki, remember to use a cross compiler if you aren't already. Those should always work.

Then read whatever tutorial you prefer, but don't copy the code, understand it and write what you want/need yourself. I don't think it will take much longer doing it this way and I think the results will be better.

Also there are books on the subject, but the reality is that there's no easy shortcuts that would work (or more precisely, it's _extremely_ unlikely you'll find anything you can copy/paste to a significant degree and that it would work the way you want). The reason is that you are creating your _own_ OS, which means nothing is going to match it perfectly and trying to copy/paste usually leads to more issues than it solves, so better do it "the right way" from the beginning.

But if you _must_ use tutorials, then I'd still start with the bare bones or meaty skeleton and add pieces from other tutorials and debug them as you add them.


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

All times are UTC - 6 hours


Who is online

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