Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X86: protected mode, GDT, IDT

I've tried to execute simple kernel with a kolibri bootloader. It's being loaded into 1000:0000. I don't understand, what's wrong in this part:

...
; switch to PM
mov eax, cr0
or  al, 1
mov cr0, eax

use32
PROTECTED_ENTRY:
mov  ax, 00010000b  ; DATA
mov  ds, ax
mov  ss, ax
mov  esp, 0xFFFF

jmp $

mov  ax, 00011000b  ; VIDEO
mov  es, ax
mov  edi, 0

mov  esi, string
int 1

jmp $

'cause in debugger it looks like this enter image description here

What's going on here? Why ES and DS aren't being changed?

P.S. i'm trying to get this kernel working with kolibri loader: http://wasm.ru/article.php?article=ia32int

like image 915
i.y. Avatar asked Dec 02 '25 12:12

i.y.


1 Answers

The processor does not automatically enter protected mode when you set the protected bit in cr0. It enters protected mode when cs is changed after that. The easiest way to do this is to insert a far jump immediately after writing to cr0.

mov cr0, eax
.db 066h
jmp CODE_SEGMENT:PROTECTED_ENTRY

use32
PROTECTED_ENTRY:

Hopefully I got that right. (I'm used to AT&T syntax.) That .db is an operand size override to allow a 32 bit address.

like image 143
ughoavgfhw Avatar answered Dec 04 '25 23:12

ughoavgfhw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!