To ask question about running instruction in P-Mode?

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
leetow2003
Member
Member
Posts: 70
Joined: Fri Nov 19, 2010 6:54 pm

To ask question about running instruction in P-Mode?

Post by leetow2003 »

My codes run well,look:
.386P
cseg segment use16
assume cs:cseg
start:
;Enter into P-Mode
mov eax,cr0
or eax,1
mov cr0,eax ;(1)
;
mov ax,10 ;(2)
mov bx,20

;Return to R-Mode
mov eax,cr0
and eax,0fffffffeh
mov cr0,eax

mov ax,4c00h
int 21h
cseg ends
end start

After executing instruction:mov cr0,eax,it enters into P-Mode,just now the value
of segment CS is not changed,I suppose it is 2000h,and CPU fetch next instruction
according to CS,and just now the valuse(such as 2000h) is regarded as selector,
so CPU should not fetch the instruction:mov ax,10,but my codes run well,why?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: To ask question about running instruction in P-Mode?

Post by thepowersgang »

1. Use code tags.
2. The "value" of segment registers doesn't really matter, what matters is the shadow registers behind the selector (base and limit). These are only updated when the register is set (effectively), so the code continues with the previous values for these (0x20000, 0xFFFF) even though it's in protected mode.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply