So I think I have successfully switched to Protected Mode, but my printf function still works, therefore I have some doubt as to if it really worked. Is there some function I can call that will definitively fail if I run it in PMode? I have searched google, osdev wiki, osdev forum, and have tried (and failed ) to decipher the intel manuals.
Thanks in Advance,
Robert
Testing Processor Mode
Just call an interrupt, e.g.
If the PC reboots(triple faults) you're in ProtectedMode.
If not, you're in RealMode.
Well this works only as long as you haven't any IDT for ProtectedMode set up.
Code: Select all
int 0x10
If not, you're in RealMode.
Well this works only as long as you haven't any IDT for ProtectedMode set up.
I was able to run sti after I entered PMode, so my Kernel does catch interrupts...
Not looking like its doing anything when I call int 0x10
Heres the Assembler Code:
Most of the Kernel is in C with occasional jumps to Assembler and back.
Here is what Bochs says:
Well, it triple faults in VMWare right off the bat... back to the drawing board...
Not looking like its doing anything when I call int 0x10
Heres the Assembler Code:
Code: Select all
[BITS 32]
[GLOBAL ProtectedMode]
[EXTERN main_p]
ProtectedMode:
cli ; clear interrupts
mov eax, cr0 ; set bit 0 in cr0--enter pmode
or eax, 1
mov cr0, eax
jmp 08h:Stage3 ; far jump to fix CS. Remember that the code selector is 0x8!
Stage3:
;-------------------------------;
; Set registers ;
;-------------------------------;
mov ax, 0x10 ; set data segments to data selector (0x10)
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 90000h ; stack begins from 90000h
sti
call main_p
Here is what Bochs says:
Code: Select all
01123558511d[CPU0 ] Enter Protected Mode
01123558511d[CPU0 ] Protected Mode Activated
01123815139d[CPU0 ] Enter Real Mode
01123815139d[CPU0 ] Real Mode Activated
01123815149d[CPU0 ] interrupt(): vector = 8, INT = 0, EXT = 1
01123815165d[CPU0 ] interrupt(): vector = 28, INT = 1, EXT = 0
01123815177d[CPU0 ] interrupt(): vector = 18, INT = 1, EXT = 0
01123815191d[CPU0 ] Enter Protected Mode
01123815191d[CPU0 ] Protected Mode Activated
01123815236d[CPU0 ] Enter Real Mode
01123815236d[CPU0 ] Real Mode Activated
01123815249d[CPU0 ] interrupt(): vector = 21, INT = 1, EXT = 0
01123815356d[CPU0 ] Enter Protected Mode
01123815356d[CPU0 ] Protected Mode Activated
01123815400d[CPU0 ] Enter Real Mode
01123815400d[CPU0 ] Real Mode Activated
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
You could test to see if bit 0 in the cr0 register is set...
Have fun..
Code: Select all
if (cr0 & 1) {
......
}
....
mov %cr0,%eax
and $0x1,%eax
test %eax,%eax
So after starting from scratch, I think I have this working, although bochs reports that the processor keeps switching between real and protected mode indefinatly...
on and on and on... any ideas?
Code: Select all
00864717350d[CPU0 ] Enter Protected Mode
00864717350d[CPU0 ] Protected Mode Activated
00864717415d[CPU0 ] Enter Real Mode
00864717415d[CPU0 ] Real Mode Activated
00864717438d[CPU0 ] interrupt(): vector = 16, INT = 1, EXT = 0
00864717439d[CPU0 ] interrupt(): vector = 109, INT = 1, EXT = 0
00864717468d[CPU0 ] interrupt(): vector = 16, INT = 1, EXT = 0
00864717469d[CPU0 ] interrupt(): vector = 109, INT = 1, EXT = 0
00864717562d[CPU0 ] interrupt(): vector = 16, INT = 1, EXT = 0
00864717563d[CPU0 ] interrupt(): vector = 109, INT = 1, EXT = 0
- codemastersnake
- Member
- Posts: 148
- Joined: Sun Nov 07, 2004 12:00 am
- Contact: