OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 11:38 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Paging error.
PostPosted: Sat Mar 09, 2019 1:18 pm 
Offline
Member
Member

Joined: Wed Feb 13, 2019 3:07 pm
Posts: 28
I wrote simple paging according to this tutorial, and i have some trouble.
When i run my OS , the text on a screen begins to appear and disappear. I don't know what's going on, but if i don't call switch_page_directory() (see - https://github.com/s04v/locOS/blob/mast ... ing.c#L143). All works correctly.


What is the problem??

+ dump of switch_page_directory
Code:
319:   55                      push   %ebp
31a:   89 e5                   mov    %esp,%ebp
31c:   83 ec 10                sub    $0x10,%esp
31f:   8b 45 08                mov    0x8(%ebp),%eax
322:   a3 00 00 00 00          mov    %eax,0x0
         323: R_386_32   current_directory
327:   8b 45 08                mov    0x8(%ebp),%eax
32a:   05 00 10 00 00          add    $0x1000,%eax
32f:   0f 22 d8                mov    %eax,%cr3
332:   0f 20 c0                mov    %cr0,%eax
335:   89 45 fc                mov    %eax,-0x4(%ebp)
338:   81 4d fc 00 00 00 80    orl    $0x80000000,-0x4(%ebp)
33f:   8b 45 fc                mov    -0x4(%ebp),%eax
342:   0f 22 c0                mov    %eax,%cr0
345:   c9                      leave 
346:   c3                      ret   


Top
 Profile  
 
 Post subject: Re: Paging error.
PostPosted: Sat Mar 09, 2019 2:12 pm 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
Maybe you should ¿check this? James Molloy's Tutorial Known Bugs


Top
 Profile  
 
 Post subject: Re: Paging error.
PostPosted: Sat Mar 09, 2019 2:55 pm 
Offline
Member
Member

Joined: Wed Feb 13, 2019 3:07 pm
Posts: 28
hextakatt wrote:
Maybe you should ¿check this? James Molloy's Tutorial Known Bugs


this doesn't help me.


Top
 Profile  
 
 Post subject: Re: Paging error.
PostPosted: Sat Mar 09, 2019 3:05 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
Quick glance.If you run you kernel in BOCHSs and stop right after you enable paging and do info tab you get this:
Code:
0x0000000000000000-0x0000000000008fff -> 0x000000000000-0x000000008fff
0x00000000003f0000-0x00000000003f0fff -> 0x000010006000-0x000010006fff
0x00000000003f1000-0x00000000003f1fff -> 0x000000020000-0x000000020fff
Those are your current mappings. Your code fails when it hits the leave instruction at the end of the function. The reason why? If you look at the register dump when it fails it says this:
Code:
00017537854i[CPU0  ] | EAX=e0000011  EBX=00007d8f  ECX=00008000  EDX=00002adf
00017537854i[CPU0  ] | ESP=0008ffa4  EBP=0008ffb4  ESI=00007dca  EDI=0000ffac
What is important is that ESP is 0008ffb4 which is in memory you haven't mapped (the address may be slightly different because of your compiler), thus leave fails trying to access the stack. I highly recommend using BOCHs for debugging this kind of thing.


Top
 Profile  
 
 Post subject: Re: Paging error.
PostPosted: Sat Mar 09, 2019 3:12 pm 
Offline
Member
Member

Joined: Wed Feb 13, 2019 3:07 pm
Posts: 28
MichaelPetch wrote:
Quick glance.If you run you kernel in BOCHSs and stop right after you enable paging and do info tab you get this:
Code:
0x0000000000000000-0x0000000000008fff -> 0x000000000000-0x000000008fff
0x00000000003f0000-0x00000000003f0fff -> 0x000010006000-0x000010006fff
0x00000000003f1000-0x00000000003f1fff -> 0x000000020000-0x000000020fff
Those are your current mappings. Your code fails when it hits the leave instruction at the end of the function. The reason why? If you look at the register dump when it fails it says this:
Code:
00017537854i[CPU0  ] | EAX=e0000011  EBX=00007d8f  ECX=00008000  EDX=00002adf
00017537854i[CPU0  ] | ESP=0008ffa4  EBP=0008ffb4  ESI=00007dca  EDI=0000ffac
What is important is that ESP is 0008ffb4 which is in memory you haven't mapped (the address may be slightly different because of your compiler), thus leave fails trying to access the stack. I highly recommend using BOCHs for debugging this kind of thing.

I use QEMU.


Top
 Profile  
 
 Post subject: Re: Paging error.
PostPosted: Sat Mar 09, 2019 3:23 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
I use QEMU too, but I will say this. BOCHs is a better tool IMHO for this kind of issue (paging). It took me a matter of seconds to identify this problem in BOCHs. Whether you run this in QEMU or BOCHs your issue is that the stack isn't in a region of memory you have mapped, thus it fails.


Top
 Profile  
 
 Post subject: Re: Paging error.
PostPosted: Sat Mar 09, 2019 3:42 pm 
Offline
Member
Member

Joined: Wed Feb 13, 2019 3:07 pm
Posts: 28
MichaelPetch wrote:
I use QEMU too, but I will say this. BOCHs is a better tool IMHO for this kind of issue (paging). It took me a matter of seconds to identify this problem in BOCHs. Whether you run this in QEMU or BOCHs your issue is that the stack isn't in a region of memory you have mapped, thus it fails.


What should i do to fix it?


Top
 Profile  
 
 Post subject: Re: Paging error.
PostPosted: Sat Mar 09, 2019 4:01 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
You need to create a mapping that includes the region of memory where you have your stack. I also didn't look at your code to determine what mapping you were expecting.What you have seems a bit unusual. The question is - is the mapping I showed from BOCHs what you were expecting to be mapped? If not then you have an issue with mapping already. If it is as you expect then you have to add additional mapping for the stack area.The other alternative is to place the stack in a region of memory that is already mapped.

Since the value of ESP suggests you probably started having your stack grow down from 0x90000 you could start by mapping the 4KiB page at 0x8f000 (which includes 0x8f000 to 0x8ffff) into virtual memory. Just identity map it as a test (virtual address 0x8f000 mapped to physical address 0x8f000). You could also just identity map all the memory in the first megabyte.


Top
 Profile  
 
 Post subject: Re: Paging error.
PostPosted: Sat Mar 09, 2019 4:49 pm 
Offline
Member
Member

Joined: Wed Feb 13, 2019 3:07 pm
Posts: 28
MichaelPetch wrote:
You need to create a mapping that includes the region of memory where you have your stack. I also didn't look at your code to determine what mapping you were expecting.What you have seems a bit unusual. The question is - is the mapping I showed from BOCHs what you were expecting to be mapped? If not then you have an issue with mapping already. If it is as you expect then you have to add additional mapping for the stack area.The other alternative is to place the stack in a region of memory that is already mapped.

Since the value of ESP suggests you probably started having your stack grow down from 0x90000 you could start by mapping the 4KiB page at 0x8f000 (which includes 0x8f000 to 0x8ffff) into virtual memory. Just identity map it as a test (virtual address 0x8f000 mapped to physical address 0x8f000). You could also just identity map all the memory in the first megabyte.


I started VM at 0x100000. and it works, but when page fault happens I continuously receive messages about page fault.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], SemrushBot [Bot] and 115 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