Why I can't get the address that triggers 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
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Why I can't get the address that triggers Page Fault

Post by min0911 »

I know the address will store in cr2 register, but I actually read cr2, but I get a wrong answer.
like this:
first,
Image
I will execute this instruction.
I think it will set cr2 register to 0x1004a080, but it doesn't

when I push the step button, I see cr2 is like this.
Image

Why is cr2 0x10056618 rather than 0x1004a080

and how can I get the correct value?(such as 0x1004a080)
User avatar
iansjack
Member
Member
Posts: 4604
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Why I can't get the address that triggers Page Fault

Post by iansjack »

I think we would need to see your complete code (particularly the exception handlers and their setup) before knowing what is happening. As a matter of interest, what is the address of your page fault handler? Also, what debugger are you using? And what is the error code from the page fault?
linguofreak
Member
Member
Posts: 509
Joined: Wed Mar 09, 2011 3:55 am

Re: Why I can't get the address that triggers Page Fault

Post by linguofreak »

Does DS by any chance have a non-zero base?
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Re: Why I can't get the address that triggers Page Fault

Post by min0911 »

linguofreak wrote:Does DS by any chance have a non-zero base?
No, the base is 0, So I am so weird in it
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Re: Why I can't get the address that triggers Page Fault

Post by min0911 »

iansjack wrote:I think we would need to see your complete code (particularly the exception handlers and their setup) before knowing what is happening. As a matter of interest, what is the address of your page fault handler? Also, what debugger are you using? And what is the error code from the page fault?
I don't know which part of code I need to provide. do you really need the complete code? I think it doesn't cause by Page Fault handler. because I only read cr2, but I don't get a correct value

and the error code is 0x00000007
I am using bochs. and I've tried qemu, I can't also get the correct value, so it is not the problem of emulator

And as you see, I just ran one command by pushing step button, so I don't think it causes by Page Fault handler.

I think maybe there is some attributes in pte or pde need to set it correct, but i don't know anything about it.

and the base of ds is 0.
User avatar
iansjack
Member
Member
Posts: 4604
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Why I can't get the address that triggers Page Fault

Post by iansjack »

One more question - what is the content of address 0x1004a080?

Edit: And another - what is the value of the stack pointer when the exception occurs?

Obviously there is something wrong with your code or with the debugger you are using. Since you don't show us the code and don't tell us what debugger you are using it's difficult to second-guess what you are doing wrong.

It is good practice to supply a link to a repository of your entire code base when seeking help as the fault could be anywhere in it. We try to help, but you have to help us help.
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Re: Why I can't get the address that triggers Page Fault

Post by min0911 »

iansjack wrote:One more question - what is the content of address 0x1004a080?

Edit: And another - what is the value of the stack pointer when the exception occurs?

Obviously there is something wrong with your code or with the debugger you are using. Since you don't show us the code and don't tell us what debugger you are using it's difficult to second-guess what you are doing wrong.

It is good practice to supply a link to a repository of your entire code base when seeking help as the fault could be anywhere in it. We try to help, but you have to help us help.
i am sorry about that, but my code is so bad and we come from different countries , so I am afraid you can’t understand it (comments ), would you mind it? But anyway,I will upload the code later.

question 1: I am using bochs debugger
question 2: I saw it is 0
I don’t know what the value of stack pointer is. Please wait for me, I need to see it and tell you.

At last, i am sorry for the way i asked the question.
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Re: Why I can't get the address that triggers Page Fault

Post by min0911 »

iansjack wrote:One more question - what is the content of address 0x1004a080?

Edit: And another - what is the value of the stack pointer when the exception occurs?

Obviously there is something wrong with your code or with the debugger you are using. Since you don't show us the code and don't tell us what debugger you are using it's difficult to second-guess what you are doing wrong.

It is good practice to supply a link to a repository of your entire code base when seeking help as the fault could be anywhere in it. We try to help, but you have to help us help.
ok there is the code https://gitlab.com/min0911/PlantOS
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why I can't get the address that triggers Page Fault

Post by Octocontrabass »

How do I run the program that triggers the page fault?
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Re: Why I can't get the address that triggers Page Fault

Post by min0911 »

Octocontrabass wrote:How do I run the program that triggers the page fault?
I am sorry, I haven’t uploaded the loader, so you can’t build and run now.Please wait for me,I am about to upload the loader
Gigasoft
Member
Member
Posts: 854
Joined: Sat Nov 21, 2009 5:11 pm

Re: Why I can't get the address that triggers Page Fault

Post by Gigasoft »

In GAS syntax, the operands are reversed as compared to Intel syntax. It should be mov %%cr2,%0.
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Re: Why I can't get the address that triggers Page Fault

Post by min0911 »

Octocontrabass wrote:How do I run the program that triggers the page fault?
I have uploaded all the code, you need to do:
1. go to loader, then make
2. go to apps, then make
3. go to kernel, then make
and you can use qemu or bochs to run
the command is in run.sh
or you can run "bochs"

and to trigger page fault, you need to change to disk c or disk d by running C: or D: in the shell(if you are using qemu, change to disk d, or else, change to disk c)
And run lua.bin, try the following code twice, it will be blocked when the second run, you will see the page fault
os.execute(“dir”)
Last edited by min0911 on Thu Sep 14, 2023 9:43 am, edited 5 times in total.
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Re: Why I can't get the address that triggers Page Fault

Post by min0911 »

Gigasoft wrote:In GAS syntax, the operands are reversed as compared to Intel syntax. It should be mov %%cr2,%0.
I know this, not cause by it
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why I can't get the address that triggers Page Fault

Post by Octocontrabass »

min0911 wrote:
Gigasoft wrote:In GAS syntax, the operands are reversed as compared to Intel syntax. It should be mov %%cr2,%0.
I know this, not cause by it
That is the cause. It should be "mov %%cr2,%0".

Open Powerint_DOS_386.img in your hex editor and disassemble the instruction at 0x32806. The operands are reversed.

Code: Select all

00032806 	0F 22 D0 	mov 	cr2, eax
I corrected the instruction and now it works.

Code: Select all

00032806 	0F 20 D0 	mov 	eax, cr2
fixed.png
min0911
Posts: 11
Joined: Fri Jul 08, 2022 2:05 am

Re: Why I can't get the address that triggers Page Fault

Post by min0911 »

Octocontrabass wrote:
min0911 wrote:
Gigasoft wrote:In GAS syntax, the operands are reversed as compared to Intel syntax. It should be mov %%cr2,%0.
I know this, not cause by it
That is the cause. It should be "mov %%cr2,%0".

Open Powerint_DOS_386.img in your hex editor and disassemble the instruction at 0x32806. The operands are reversed.

Code: Select all

00032806 	0F 22 D0 	mov 	cr2, eax
I corrected the instruction and now it works.

Code: Select all

00032806 	0F 20 D0 	mov 	eax, cr2
fixed.png
oh I know,thank you so much!!!!
Post Reply