confusion about GDT enrties

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
MuteX

confusion about GDT enrties

Post by MuteX »

Following is the jist of my IPL, its loaded at 0x0500:0x0000, at the moment im experimenting with the IPL and following is the abbreviated code fragment of interst (Which by the way is not working and crashes , if anyone can point out why i'll be grateful) .. im using a macro desc for creating enteries in the GDT .. my question is about the base of the entries that i have to set ..

I've seen sources for so many Oses out there and almost all of them in the IPL stage set the base for code and data descriptors to be 0. Since my ipl is loaded at 0x500 wouldnt it make sense to define the base to be 0x5000 (which is the linear address where ipl is loaded), i've tried that and it doesnt work either (in fact i cudnt get rid of the crash so cant really say that it works or not), but im still confused

if i set the base to be 0x0 shudnt i code the jmp to be like
jmp code_selector:entry32 + 0x5000 ??

what is that im missing here ?
i've only tested the code on bochs.

;-----------------------------------------------------------------------

%define KERNEL_BASE_SEG    0x0500

loaderMain:
mov   si, boot_message
call  _printf

call  enableA20
cli

lgdt [gdtr]

mov eax,cr0
or al,1
mov cr0,eax

jmp code_selector:entry32  ; this one is causing exceptions

[bits 32]
entry32:
            mov eax, data_selector
            mov ds, ax
            mov es, ax
            mov ax, video_selector
            mov gs, ax
            mov word [gs:0], 0x777   ; print something on screen
hng:     jmp hng

[bits 16]
gdtr:
  dw gdt_end - gdtr - 1
  dd gdtr
gdt
        desc 0,0,0
data_selector equ $-gdt    
        desc 0x0000, 0xffffffff,D_DATA + D_WRITE+ D_BIG

code_selector equ $-gdt  
        desc 0x0000, 0xffffffff,D_CODE + D_READ + D_BIG

video_selector equ $-gdt    ; = 0x18
        desc 0xB8000, 0x3999,D_CODE + D_READ + D_BIG
gdt_end:
agafaed

RE:confusion about GDT enrties

Post by agafaed »

It should be
[code]
gdtr:
  dw gdt_end - gdt - 1
  dd gdt
[/code]
MuteX

RE:confusion about GDT enrties

Post by MuteX »

tx .. figured that out and so many other weirdos ...
Post Reply