GDT issue
Posted: Thu Feb 28, 2008 4:22 am
I have written code for implementing gdt. But I thinked a thing... If I setup the gdt directly at boot-time? There can be any problem?
Of course, I must also set gdt for usermode.
Code: Select all
.align 4
gdtr:
.word (gdt_end - gdt - 1) ; // GDT limit.
.long (gdt - ADDRADJUST) ; // GDT linear address.
.align 4
gdt:
; // Dummy descriptor 0x00.
.word 0 ; // Limit 15:0
.word 0 ; // Base 15:0
.byte 0 ; // Base 23:16
.byte 0 ; // Access byte (descriptor type)
.byte 0 ; // Limits 19:16, Flags
.byte 0 ; // Base 31:24
; // Data descriptor 0x08.
.word 0xFFFF ; // Limit 15:0
.word 0 ; // Base 15:0
.byte 0 ; // Base 23:16
.byte 0x92 ; // Data, Present, Writeable (1,0,0,1,0010)
.byte 0xCF ; // G=1, D=1, 0, AVL=0, 1111=F: Limit/Length (1,1,0,0,1111)
.byte 0 ; // Base 31:24
; // Code descriptor 0x10.
.word 0xFFFF ; // Limit 15:0
.word 0 ; // Base 15:0
.byte 0 ; // Base 23:16
.byte 0x9A ; // Code, Present, Non-conforming, Exec/read (1,0,0,1,1110)
.byte 0xCF ; // G=1, D=1, 0, AVL=0, 1111=F: Limit/Length (1,1,0,0,1111)
.byte 0 ; // Base 31:24
gdt_end:
; Reload global descriptor table (GDT).
lgdtl (gdtr)
; Reflush CS register.
ljmp $0x10, $1f
; Update segment registers.
movw $0x08, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs