Multitasking not working in JamesM tutorial

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
vjain20
Member
Member
Posts: 73
Joined: Wed Apr 04, 2012 9:12 pm

Multitasking not working in JamesM tutorial

Post by vjain20 »

Hi,

I am trying to the run the code downloaded from JamesM tutorial from the
multitasking section but I am getting a page fault.

Page fault! (present) at 0x106d7815 - EIP: 0x106d7815
PANIC(Page fault) at paging.c: 230.


I haven't made any change to the code.
I have seen another post reporting the same problem. If anyone has fixed this issue please
help me.
- Thanks
Vaibhav jain
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Multitasking not working in JamesM tutorial

Post by gravaera »

Yo:

What is at paging.c, line 230?

--Peace out
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
serviper
Member
Member
Posts: 31
Joined: Sat Jul 16, 2011 6:05 am
Location: China
Contact:

Re: Multitasking not working in JamesM tutorial

Post by serviper »

It's better to set up kernel stack and (perhaps a few pages) user stack when initializing paging. Just allocate pages for them and load the base address into esp and ebp, and call another function using the new stack frame - or you may crash because of invalid memory access.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Multitasking not working in JamesM tutorial

Post by JamesM »

berkus wrote:It's not supposed to work, because that stack copying implementation is fragile and mostly invalid.
Indeed, it is shite.

Whoever wrote it deserves a slap. :oops:
vjain20
Member
Member
Posts: 73
Joined: Wed Apr 04, 2012 9:12 pm

Re: Multitasking not working in JamesM tutorial

Post by vjain20 »

It's better to set up kernel stack and (perhaps a few pages) user stack when initializing paging. Just allocate pages for them and load the base address into esp and ebp,
What about the data that is already there in the old stack and is being used ?

and call another function using the new stack frame - or you may crash because of invalid memory access.
Could you please explain this ? I am not getting how will it result in invalid memory access and how calling a function would avoid it ?
- Thanks
Vaibhav jain
User avatar
serviper
Member
Member
Posts: 31
Joined: Sat Jul 16, 2011 6:05 am
Location: China
Contact:

Re: Multitasking not working in JamesM tutorial

Post by serviper »

vjain20 wrote: What about the data that is already there in the old stack and is being used ?
main() uses the old stack. Once we switch to a new stack and call another function, we'll never return to main(). The old stack is abandoned.
vjain20 wrote:
and call another function using the new stack frame - or you may crash because of invalid memory access.
Could you please explain this ? I am not getting how will it result in invalid memory access and how calling a function would avoid it ?
Local auto variables are accessed using ebp (and also esp sometimes). Switching to a new stack means

Code: Select all

asm volatile ("mov %0, %%ebp" :: "r" (new_stack_bottom));
asm volatile ("mov %0, %%esp" :: "r" (new_stack_bottom));
Note that the new stack frame is empty - no locals, no return address and no stack base address of the caller. Any access to the locals may get a garbage value, which may cause unexpected result (e.g, a page fault if you read a garbage pointer value).
Calling another function avoid invalid memory access by allocate space for local autos on the new stack frame, usually by moving esp first or use [ebp+offset] directly.
Post Reply