Page 1 of 1

James Molloys Tutorial - task switch creates a page fault

Posted: Wed Jun 01, 2011 3:03 pm
by dukedevon
Hi all,

I'm trying to implement multitasking by following James Molloys tutorial, but every time I do a task switch, it gives me a page fault. The problem seems to be in the original code to, because if I compile the downloadable source and compile it, I get the same result. I think its the instruction pointer, because it points to the address which gives me the page fault.

Currently it starts the processes sequentially, so there shouldn't be any race conditions or other freaky synchronization issues.
I was wondering about the page table. The one in the first process looks like this:

Code: Select all

0x00000000 - 0x00110FFF => 0x0000000000000000 - 0x0000000000110FFF        //Kernel code - ID-Mapped
0xC0000000 - 0xC00FFFFF => 0x0000000000111000 - 0x0000000000210FFF        //Kernel Heap
0xC0100000 - 0xC0101FFF => 0x0000000000216000 - 0x0000000000217FFF
0xDFFFE000 - 0xDFFFEFFF => 0x0000000000213000 - 0x0000000000213FFF
0XDFFFF000 - 0xDFFFFFFF => 0x0000000000212000 - 0x0000000000212FFF
0xE0000000 - 0xE0000FFF => 0x0000000000211000 - 0x0000000000211FFF        //Stack
After the failing switch it looks like this:

Code: Select all

0x00000000 - 0x00110FFF => 0x0000000000000000 - 0x0000000000110FFF        //Kernel code - ID-Mapped
0xC0000000 - 0xC00FFFFF => 0x0000000000111000 - 0x0000000000210FFF        //Kernel Heap
0xC0100000 - 0xC0101FFF => 0x0000000000216000 - 0x0000000000217FFF
0xDFFFE000 - 0xDFFFFFFF => 0x0000000000214000 - 0x0000000000215FFF
0xE0000000 - 0xE0000FFF => 0x0000000000218000 - 0x0000000000218FFF        //Stack
This problem occurs in my own implementation and the original one.

The Tutorial, as well as the sourcecode is available here: http://www.jamesmolloy.co.uk/tutorial_h ... sking.html

Is it possible to say what is wrong here or do you need any more information?

[edit] The only thing i changed was the initial ramdisk, basically my textfiles have different content. It should harm my pagetable though :-/

greetz
dukedevon

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Wed Jun 01, 2011 9:42 pm
by Chandra
JamesM himself has admitted that he's too busy to make changes to these tutorials. I'm sure you'll find updated code if you give a little push.

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Thu Jun 02, 2011 6:24 am
by dukedevon
I think I'll try to fix it myself. I contacted him earlier and I think he doesn't really have the time. Perhaps I find out whats wrong and send him the hopefully corrected version. Thanks.

Chris

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Thu Jun 02, 2011 7:18 am
by JamesM
Yes - alas I would love to help but these sort of problems can really stem from almost anything, and I have a job.

I considered taking the tutorials down because I just do not have time to work with them, but decided against it in the end given how many people were still using them and finding them useful. There are several bugs, most of which are small typos (lack of parentheses around an &/== expression, for example), which some have said makes it less likely for "noobs" to just copy-paste in a braindead fashion.

I don't personally follow that consensus, but inadvertently went along with it in the name of idleness.

Berkus did say he'd help get the new version of the tutorials documented, but doesn't seem to have done anything. Not that I'm complaining - I can't expect anyone else to have time where I don't.

Anyways, hope you solve it soon enough, and be sure to post your answer here so the next person has an easier job searching.

Cheers,

James

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Thu Jun 02, 2011 7:40 am
by dukedevon
To make it easier for me to locale the issue: am I right in assuming that the second page table is incorrect?
I mean, if I copy and link them, they should have the same number of entries, I think...

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Thu Jun 02, 2011 10:33 am
by JamesM
berkus wrote:I'm fairly busy and writing tutorials in a tutorial way, not as a bunch of steps to unconditionally follow is something I cannot take atm.

initialise_paging() certainly did map less pages than necessary. Also move_stack() is prone to fail, it makes sense to throw this function out and replace it with statically allocated stack space in BSS segment.
Yeah, I went and looked at starting to rewrite the things and just gave up before I'd begun. It takes a lot of effort to get the prose simplified enough to be easily understandable by laymen non-native speakers.

The code is done, just need the docs.

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Fri Jun 03, 2011 3:39 pm
by JamesM
Right, having been given a kick up the arse by you lot I'm working on them.

Expect them by the end of the weekend. Anyone who wants in, give me a shout.

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Sat Jun 04, 2011 8:52 am
by JamesM
berkus wrote:I'd be glad to review and give input.
Cheers, I'm up to the IRQ chapter. Expect to be up to the heap by the end of tomorrow.

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Sat Jun 04, 2011 4:54 pm
by JamesM
berkus wrote:I still don't like boot.s - i think "cli" should be after call to main.
Why's that?

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Sat Jun 04, 2011 4:55 pm
by JamesM
berkus wrote:I've reviewed up to IRQ/IDT chapter, waiting for the next batch.
Cool - it is the stuff in the "doc" folder you're checking, right? not the "docs"? (doc is newer, docs is the older version)

Re: James Molloys Tutorial - task switch creates a page faul

Posted: Sun Jun 05, 2011 3:25 am
by JamesM
berkus wrote:
JamesM wrote:
berkus wrote:I've reviewed up to IRQ/IDT chapter, waiting for the next batch.
Cool - it is the stuff in the "doc" folder you're checking, right? not the "docs"? (doc is newer, docs is the older version)
Yes, the sphinx markup in doc/.

For the cli - as I commented, we enter boot.s with interrupts disabled (a guarantee by Multiboot spec), but after we come back from main() they may be enabled, and cause side effects to our jmp $ in the end.
Excellent, cheers.