Hi,
nergzd723 wrote:
Thank you all for replies!
Quote:
I think you should set up GDT here and the segment registers before you make a call to kmain (even if that's just a temporary hardcoded GDT and not the final one).
If I do that, the multiboot info would be wrong somewhy, magic is bad.
Don't do anything complex that changes registers. Just a single "lgdt" instruction with a static GDT. Then you can use segments in your jmp_tomod.
Calling a function uses SS register, don't do that until you're sure you have a valid one. For example:
Code:
; hardcoded temporary GDT until we set it up properly
align 16
GDT_table: dd 0, 0 ;null descriptor
dd 0000FFFFh,008F9200h ;32 bit prot mode flat ds
dd 0000FFFFh,00CF9A00h ;32 bit prot mode ring0 cs
GDT_value: dw GDT_value-GDT_table
dd GDT_table
start:
cld ; Clear the direction flag for string operations
mov esp, eax ; save eax in esp register which we will set anyway
lgdt [GDT_value] ; set up segment registers
mov ax, 8
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov eax, esp ; restore eax with magic
mov esp, kernel_stack_top ; Set up the stack
; ...
(note: this is just a simple example I wrote from memory, could be typos in it. You also need to tailor it to your needs. Some assembler needs "$8" etc. To set up CS as well, you'll need a far call to 16:kmain.)
nergzd723 wrote:
Then, I tried initializing GDT and IDT and set up syscall handler and nothing more
Don't complicate your life, it's enough if you set up IDT later. Just focus on GDT.
Cheers,
bzt