Page 1 of 1

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

Posted: Tue Sep 12, 2023 8:10 am
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)

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

Posted: Tue Sep 12, 2023 9:34 am
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?

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

Posted: Tue Sep 12, 2023 9:38 am
by linguofreak
Does DS by any chance have a non-zero base?

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

Posted: Tue Sep 12, 2023 11:15 pm
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

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

Posted: Tue Sep 12, 2023 11:33 pm
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.

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

Posted: Wed Sep 13, 2023 2:04 am
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.

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

Posted: Wed Sep 13, 2023 4:21 am
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.

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

Posted: Wed Sep 13, 2023 8:28 am
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

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

Posted: Wed Sep 13, 2023 10:04 pm
by Octocontrabass
How do I run the program that triggers the page fault?

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

Posted: Thu Sep 14, 2023 4:06 am
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

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

Posted: Thu Sep 14, 2023 5:53 am
by Gigasoft
In GAS syntax, the operands are reversed as compared to Intel syntax. It should be mov %%cr2,%0.

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

Posted: Thu Sep 14, 2023 9:13 am
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”)

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

Posted: Thu Sep 14, 2023 9:13 am
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

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

Posted: Thu Sep 14, 2023 8:18 pm
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

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

Posted: Thu Sep 14, 2023 10:09 pm
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!!!!