Page 1 of 1
Paging error.
Posted: Sat Mar 09, 2019 1:18 pm
by Shvets04
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: Select all
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
Re: Paging error.
Posted: Sat Mar 09, 2019 2:12 pm
by deleted8917
Re: Paging error.
Posted: Sat Mar 09, 2019 2:55 pm
by Shvets04
Re: Paging error.
Posted: Sat Mar 09, 2019 3:05 pm
by MichaelPetch
Quick glance.If you run you kernel in BOCHSs and stop right after you enable paging and do
info tab you get this:
Code: Select all
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: Select all
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.
Re: Paging error.
Posted: Sat Mar 09, 2019 3:12 pm
by Shvets04
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: Select all
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: Select all
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.
Re: Paging error.
Posted: Sat Mar 09, 2019 3:23 pm
by MichaelPetch
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.
Re: Paging error.
Posted: Sat Mar 09, 2019 3:42 pm
by Shvets04
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?
Re: Paging error.
Posted: Sat Mar 09, 2019 4:01 pm
by MichaelPetch
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.
Re: Paging error.
Posted: Sat Mar 09, 2019 4:49 pm
by Shvets04
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.