Page 1 of 1

OS Sutdown on changing cr0 register(paging) no Triple fault?

Posted: Mon Jan 20, 2014 8:09 pm
by teenHack42
Hi I'm new to this forum but I have been using the wiki for years now.

the problem happens when I am initializing paging.

the code that is last run before the shutdown is :

Code: Select all

asm volatile("mov %0, %%cr0":: "r"(cr0));
I am fairly new in the paging world and this is driving me crazy. Help is appreciated.

Project on Git Hub https://github.com/teenHack42/MatrixOS
if you would like to contribute to the problem your welcome

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Mon Jan 20, 2014 9:03 pm
by teenHack42
More info:
I handle all of the irq's and none of them are thrown

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Mon Jan 20, 2014 10:58 pm
by thepowersgang
You're lucky, I'm bored (otherwise I'd either ignore this, or tear you to pieces for failing to debug it yourself [i.e. using bochs's debugger, or enabling tracing in qemu])

Looking at your code, I don't see anything truly glaring about the way you're setting up paging... apart from the rather strange source structure and "allocating" pages to the place the kernel is located (which seems to have the intended effect, but it depends on the way the physical memory manager hands out pages)

Hint - Run using bochs' debugger (on windows, this is bochsdbg.exe) and read the log around where your kernel crashes.

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Tue Jan 21, 2014 12:19 am
by VolTeK
I'll contribute to the problem. Probably not the solution though.

Id just google search for posts involving page initialization problems when using JamesM's OS Tutorial code. I'm sure you'll find many who have had the same problem, for some not very unique reasons.

Or, google search how paging works, to help find the problem yourself. It helps the education process greatly, also improves self teaching.

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Tue Jan 21, 2014 12:31 am
by teenHack42
to thepowersgang,
I cannot use bochs as I cant find the bios binarys on my LINUX computer.

VolTeK:
as for the first solution I have tried and failed.
for the second solution I have also tried and have followed. but whatever solution I use for enabling paging have all decided to die at the exact same line of code as above.

The problem is something to do with changing the value of the cr0 register but Im not sure why.

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Tue Jan 21, 2014 12:45 am
by neon
Hello,

A mov eax, cr0 instruction can only issue a #GP with CPL > 0 never a #PF thus is not the cause of your error. If the error is occurring some time after enabling paging, the actual cause is probably interrupt triggers.

Bochs comes with a BIOS image to use; please see its documentation. You need to locate the real source of the error -- I assure you that it is not the mov instruction. I personally don't like how the code appears to be from tutorials; if you don't understand your code the project is doomed to fail.

What file is that instruction at within your source tree?

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Tue Jan 21, 2014 1:25 am
by teenHack42
to neon,
the instruction is located in src/include/paging.c

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Tue Jan 21, 2014 2:45 am
by neon
Hello,

It would appear then that kernel space isn't properly mapped into the address space. That would result in a #PF upon executing that instruction. (The instruction is not the cause though; the cause is the CPU being unable to fetch the next instruction.) Without debugger support however and complete lack of error checking in your code, it will be very hard for anyone to resolve the problem.

You need to narrow down the possible causes:

1. Is the paging structures properly initialized to correct values? Don't guess; check them.
2. Are their any invalid pointers? Always check for invalid references.
3. What is the state of the system prior to executing the above code? Do they look valid? What is the state of the paging structures?
4. Some areas of your software makes assumption on memory size and locations. Make sure there are no conflicts.
5. You also seem to use some C bit fields. Be careful with using them as they are non portable and may break the code.

In short, try to use the debugger to narrow down possible causes and see what the state of the system is right before that instruction executes to see what is wrong. It is better to learn how to use the debugger now with a small system then running into a problem later that will be impossible to solve without good experience with it.

BTW, Your interrupts wont be able to execute if the CPU cannot access the page that which they reside. This farther supports the above -- your paging structures are messed up.

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Tue Jan 21, 2014 3:11 am
by VolTeK
Off-topic, skip if you're still in search of an answer to the OP's problem.

http://stackoverflow.com/questions/2122 ... ry-hobbyos

If you do not try and understand the basics that build up to the concepts of paging, then you are clearly setting yourself up for a very long and difficult learning curve. Statistically, most who just jump in and try the tutorial end up quitting. That's a rock solid more than half of the kids who find their way here instead of stackoverflow. Now while you may have made the right choice and went there first, you decided that you were ready to ask intermediate questions and head on over here.

However, intermediate means "Simple, with the bullshit cut out". The bullshit here, being some of the spoon feeding you are asking for. Simple second hand debugging. You have to clean up your room, we aren't your maids.

OS Tutorials also have prerequisites too. Best to look forward to learning those first. We aren't trying to be mean, but these are the kind of posts you are going to get for an answer to your problem. It's much more helpful then you may think, nicer, and well thought out. The next will be mean, and blunt.

(But if you still didn't get it, go learn some debugging ;) )

Re: OS Sutdown on changing cr0 register(paging) no Triple fa

Posted: Thu Jan 23, 2014 11:49 am
by ApproximateIdentity
teenHack42 wrote:Project on Git Hub https://github.com/teenHack42/MatrixOS
if you would like to contribute to the problem your welcome
I have nothing to add to this specific discussion, but I just wanted to say that you should not add any binary files to your version control. You should only commit source files to your repository. Seeing all your object files floating around is a little odd.