OSDev.org

The Place to Start for Operating System Developers
It is currently Sun May 12, 2024 11:53 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Why I can't get the address that triggers Page Fault
PostPosted: Tue Sep 12, 2023 8:10 am 
Offline

Joined: Fri Jul 08, 2022 2:05 am
Posts: 11
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)


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Tue Sep 12, 2023 9:34 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
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?


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Tue Sep 12, 2023 9:38 am 
Offline
Member
Member

Joined: Wed Mar 09, 2011 3:55 am
Posts: 509
Does DS by any chance have a non-zero base?


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Tue Sep 12, 2023 11:15 pm 
Offline

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

No, the base is 0, So I am so weird in it


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Tue Sep 12, 2023 11:33 pm 
Offline

Joined: Fri Jul 08, 2022 2:05 am
Posts: 11
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.


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Wed Sep 13, 2023 2:04 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Wed Sep 13, 2023 4:21 am 
Offline

Joined: Fri Jul 08, 2022 2:05 am
Posts: 11
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.


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Wed Sep 13, 2023 8:28 am 
Offline

Joined: Fri Jul 08, 2022 2:05 am
Posts: 11
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


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Wed Sep 13, 2023 10:04 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5156
How do I run the program that triggers the page fault?


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Thu Sep 14, 2023 4:06 am 
Offline

Joined: Fri Jul 08, 2022 2:05 am
Posts: 11
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


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Thu Sep 14, 2023 5:53 am 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 853
In GAS syntax, the operands are reversed as compared to Intel syntax. It should be mov %%cr2,%0.


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Thu Sep 14, 2023 9:13 am 
Offline

Joined: Fri Jul 08, 2022 2:05 am
Posts: 11
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.

Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Thu Sep 14, 2023 9:13 am 
Offline

Joined: Fri Jul 08, 2022 2:05 am
Posts: 11
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


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Thu Sep 14, 2023 8:18 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5156
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:
00032806    0F 22 D0    mov    cr2, eax

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


Attachment:
fixed.png
fixed.png [ 29.42 KiB | Viewed 32450 times ]


Top
 Profile  
 
 Post subject: Re: Why I can't get the address that triggers Page Fault
PostPosted: Thu Sep 14, 2023 10:09 pm 
Offline

Joined: Fri Jul 08, 2022 2:05 am
Posts: 11
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:
00032806    0F 22 D0    mov    cr2, eax

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


Attachment:
fixed.png

oh I know,thank you so much!!!!


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 12 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