James Molloys Tutorial - task switch creates a page fault

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
dukedevon
Posts: 21
Joined: Thu Jul 08, 2010 10:02 am
Location: Karlsruhe, Germany
Contact:

James Molloys Tutorial - task switch creates a page fault

Post 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
FlExOS --- Stay tuned ;-)
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

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

Post 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.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
dukedevon
Posts: 21
Joined: Thu Jul 08, 2010 10:02 am
Location: Karlsruhe, Germany
Contact:

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

Post 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
FlExOS --- Stay tuned ;-)
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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
User avatar
dukedevon
Posts: 21
Joined: Thu Jul 08, 2010 10:02 am
Location: Karlsruhe, Germany
Contact:

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

Post 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...
FlExOS --- Stay tuned ;-)
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post by JamesM »

berkus wrote:I still don't like boot.s - i think "cli" should be after call to main.
Why's that?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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)
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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.
Post Reply