test GDT?
Posted: Mon Aug 11, 2003 6:55 pm
I have implemented a GDT in my OS and I was wondering if it possible to somehow test GDT to see if I have defined everything right (ie. run some code to excercise GDT)
thanks
thanks
Well I call my loadGDT function which is defined in another file . Then I call prinft which seems to be writing correctly. However I am using Grub. How can I be sure I am not using Grub's temporary GDT??try to write at offset 0xB8000 on a 0-based segment and see if it something appears on screen.
Code: Select all
ia32Descriptor mygdt[]={
IA32_INVALID(0),
IA32_CODE(0,0xFFFFFFFF),
IA32_DATA(0,0xFFFFFFFF),
IA32_DATA(0xB8000,80*25*2),
};
void test() {
printf("GRuB's GDT @%x", sgdt());
install_gdt(mygdt);
printf("now GDT is @%x", sgdt());
far_poke_w(0x18,'H'+256*(WHITE+BACKGROUND*BLUE));
far_poke_w(0x18,'i'+256*(WHITE+BACKGROUND*BLUE));
}
Code: Select all
gdt.o: file format elf32-i386
Disassembly of section .text:
00000000 <loadGDT>:
0: 0f 01 15 20 00 00 00 lgdtl 0x20
7: 66 b8 10 00 mov $0x10,%ax
b: 8e d8 mov %eax,%ds
d: 8e c0 mov %eax,%es
f: 8e d0 mov %eax,%ss
11: 8e e0 mov %eax,%fs
13: 8e e8 mov %eax,%gs
15: c3 ret
Disassembly of section .data:
00000000 <gdt>:
...
10: ff (bad)
11: ff 00 incl (%eax)
13: 00 00 add %al,(%eax)
15: 92 xchg %eax,%edx
16: cf iret
17: 00 ff add %bh,%bh
19: ff 00 incl (%eax)
1b: 00 00 add %al,(%eax)
1d: 9a cf 00 1f 00 00 00 lcall $0x0,$0x1f00cf
00000020 <gdt_end>:
20: 1f pop %ds
21: 00 00 add %al,(%eax)
23: 00 00 add %al,(%eax)
...
Code: Select all
[BITS 32]
GLOBAL loadGDT
loadGDT:
; stop using bootloader GDT, and load new GDT
lgdt [gdt_ptr]
mov ax,LINEAR_DATA_SEL
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov gs,ax
ret
;--------------------
; GDT loading info
;--------------------
SECTION .data
gdt:
; NULL descriptor
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; unused descriptor
dw 0
dw 0
db 0
db 0
db 0
db 0
LINEAR_DATA_SEL equ $-gdt
dw 0FFFFh
dw 0
db 0
db 92h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
LINEAR_CODE_SEL equ $-gdt
dw 0FFFFh
dw 0
db 0
db 9Ah ; present,ring 0,code,non-conforming,readable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
gdt_end:
gdt_ptr:
dw gdt_end - gdt - 1
dd gdt
Code: Select all
gdt.o: file format elf32-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000003 R_386_32 .data
RELOCATION RECORDS FOR [.data]:
OFFSET TYPE VALUE
00000022 R_386_32 .data
Code: Select all
gdt.o: file format elf32-i386
Disassembly of section .text:
00000000 <loadGDT>:
0: 0f 01 15 20 00 00 00 lgdtl 0x20
3: R_386_32 .data
7: 66 b8 10 00 mov $0x10,%ax
b: 8e d8 mov %eax,%ds
d: 8e c0 mov %eax,%es
f: 8e d0 mov %eax,%ss
11: 8e e0 mov %eax,%fs
13: 8e e8 mov %eax,%gs
15: c3 ret
Code: Select all
VIDEO_SEL equ $-gdt
dw 0FFFFh
dw 0x8000
db 0x000b
db 92h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
Code: Select all
mov ax,VIDEO_SEL
mov gs,ax
mov [gs:0],'.i.h'
Code: Select all
mov ax,VIDEO_SEL
mov gs,ax
mov [gs:0],'.i.h'
Code: Select all
mov dword [gs:0],'.i.h'
That gave me the same error: "operation size not specified"I'm a bit rusty but i think it should be:-
Code: Select all
mov dword [gs:0], 0x3e693e48
Code: Select all
mov ax,VIDEO_SEL
mov gs,ax
mov dword [gs:0], 0x3E693E48 ; 4bytes = 2char + 2attr
Code: Select all
int gdtdesc[2];
char* ptr= ((char*)gdtdesc) + 2;
asm("sgdt (%0)": "=r" (ptr));