Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
I try to write my oun OS and would like to ask:
When booting, immediately after entering from real to the protected mode ( by enabling the PE bit in CR0), the value of the cs register iz zero.It means that from this moment, being in protected mode, the processor uses the null selector, when computing the address of the current instruction. This crashes the system. How can I solve this problem ?
Thanks in advance.
xyoavx

Actually, switching to protected mode won't do anything with CS. What you need to do is switch to the new mode, then do a long jump in the code. You can do this by either pushing the new segment selector and offset onto the stack and doing a retf, or by just doing a jmp 0x??:0x?? with the new selector and offset.
The values in selectors aren't actually ACCESSED per se until they are used. The switch to protected mode will check that there is a valid value in the register (ie 0,0x8,0x10...), but for other reasons 0 must be the null selector and is not used, so you need to do a long jump in the code to "wake up" CS to where you are.
Hope that helps!

Hello Birdman
Thank you very much for your answer.From your email,I understand that immediately after enabling the PE bit in CR0,CS is not yet used as a selector.When performing the jump,CS is used in its "regular" way.CS will be used as a selector only after the jump.So,my question is:how the processor "knows" when it should begin to use the CS as a selector ?
If the jump will not be done,will the processor continue to use CS like in real mode ?
Thanks in advance
xyoavx

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |