I have a LGDT problem too...
Posted: Tue Aug 07, 2007 11:46 pm
I have a problem with LGDT too, sympton wise, it's very similar to another thread here.
http://www.osdev.org/phpBB2/viewtopic.php?t=14542
However, I think I'm using the stable toolchain, gcc version 4.1.2 20070502 (Red Hat 4.1.2-12)
The code skeleton is from the operating system class of mit opencourseware... a few other schools use the same code/materials for their classes.
Anyway, the code looks like this:
The sympton is the system resets after "mov gs, ax",
Before:
After mov gs, ax:
Need some help to figure out why it is happening... I compared the instruction and symbol file, gdt entries look correct
f010124b: 0f 01 15 50 33 11 f0 lgdtl 0xf0113350
f0113350 D gdt_pd
I attached the tar file; gmake will generate the image file.
Thanks.
http://www.osdev.org/phpBB2/viewtopic.php?t=14542
However, I think I'm using the stable toolchain, gcc version 4.1.2 20070502 (Red Hat 4.1.2-12)
The code skeleton is from the operating system class of mit opencourseware... a few other schools use the same code/materials for their classes.
Anyway, the code looks like this:
Code: Select all
struct Segdesc gdt[] =
{
// 0x0 - unused (always faults -- for trapping NULL far pointers)
SEG_NULL,
// 0x8 - kernel code segment
[GD_KT >> 3] = SEG(STA_X | STA_R, 0x0, 0xffffffff, 0),
// 0x10 - kernel data segment
[GD_KD >> 3] = SEG(STA_W, 0x0, 0xffffffff, 0),
// 0x18 - user code segment
[GD_UT >> 3] = SEG(STA_X | STA_R, 0x0, 0xffffffff, 3),
// 0x20 - user data segment
[GD_UD >> 3] = SEG(STA_W, 0x0, 0xffffffff, 3),
// 0x28 - tss, initialized in idt_init()
[GD_TSS >> 3] = SEG_NULL
};
struct Pseudodesc gdt_pd = {
sizeof(gdt) - 1, (unsigned long) gdt
};
......
// Map VA 0:4MB same as VA KERNBASE, i.e. to PA 0:4MB.
// (Limits our kernel to <4MB)
pgdir[0] = pgdir[PDX(KERNBASE)];
// Install page table.
lcr3(boot_cr3);
// Turn on paging.
cr0 = rcr0();
cr0 |= CR0_PE|CR0_PG|CR0_AM|CR0_WP|CR0_NE|CR0_TS|CR0_EM|CR0_MP;
cr0 &= ~(CR0_TS|CR0_EM);
lcr0(cr0);
// Current mapping: KERNBASE+x => x => x.
// (x < 4MB so uses paging pgdir[0])
// Reload all segment registers.
asm volatile("lgdt gdt_pd");
asm volatile("movw %%ax,%%gs" :: "a" (GD_UD|3));
asm volatile("movw %%ax,%%fs" :: "a" (GD_UD|3));
asm volatile("movw %%ax,%%es" :: "a" (GD_KD));
asm volatile("movw %%ax,%%ds" :: "a" (GD_KD));
asm volatile("movw %%ax,%%ss" :: "a" (GD_KD));
asm volatile("ljmp %0,$1f\n 1:\n" :: "i" (GD_KT)); // reload cs
asm volatile("lldt %%ax" :: "a" (0));
// Final mapping: KERNBASE+x => KERNBASE+x => x.
// This mapping was only used after paging was turned on but
// before the segment registers were reloaded.
pgdir[0] = 0;
// Flush the TLB for good measure, to kill the pgdir[0] mapping.
lcr3(boot_cr3);
Before:
Code: Select all
CPU#0
eax:0x80050033, ebx:0xf0114000, ecx:0x000005f0, edx:0x00000000
ebp:0xf0112fd8, esp:0xf0112fc0, esi:0x00010094, edi:0x0008fd7a
eip:0xf010124b, eflags:0x00000086, inhibit_mask:0
cs:s=0x0008, dl=0x0000ffff, dh=0x10cf9a00, valid=1
ss:s=0x0010, dl=0x0000ffff, dh=0x10cf9300, valid=7
ds:s=0x0010, dl=0x0000ffff, dh=0x10cf9200, valid=7
es:s=0x0010, dl=0x0000ffff, dh=0x10cf9300, valid=1
fs:s=0x0010, dl=0x0000ffff, dh=0x00cf9300, valid=1
gs:s=0x0010, dl=0x0000ffff, dh=0x00cf9300, valid=1
ldtr:s=0x0000, dl=0x0000ffff, dh=0x00008200, valid=1
tr:s=0x0000, dl=0x0000ffff, dh=0x00008300, valid=1
gdtr:base=0x00113000, limit=0x17
idtr:base=0x00000000, limit=0x3ff
dr0:0x00000000, dr1:0x00000000, dr2:0x00000000
dr3:0x00000000, dr6:0xffff0ff0, dr7:0x00000400
cr0:0x80050033, cr1:0x00000000, cr2:0x00000000
cr3:0x00114000, cr4:0x00000000
Code: Select all
CPU#0
eax:0x00000000, ebx:0x00000000, ecx:0x00000000, edx:0x00000683
ebp:0x00000000, esp:0x00000000, esi:0x00000000, edi:0x00000000
eip:0x0000fff0, eflags:0x00000002, inhibit_mask:0
cs:s=0xf000, dl=0x0000ffff, dh=0xff009bff, valid=1
ss:s=0x0000, dl=0x0000ffff, dh=0x00009300, valid=1
ds:s=0x0000, dl=0x0000ffff, dh=0x00009300, valid=1
es:s=0x0000, dl=0x0000ffff, dh=0x00009300, valid=1
fs:s=0x0000, dl=0x0000ffff, dh=0x00009300, valid=1
gs:s=0x0000, dl=0x0000ffff, dh=0x00009300, valid=1
ldtr:s=0x0000, dl=0x0000ffff, dh=0x00008200, valid=1
tr:s=0x0000, dl=0x0000ffff, dh=0x00008300, valid=1
gdtr:base=0x00000000, limit=0xffff
idtr:base=0x00000000, limit=0xffff
dr0:0x00000000, dr1:0x00000000, dr2:0x00000000
dr3:0x00000000, dr6:0xffff0ff0, dr7:0x00000400
cr0:0x00000010, cr1:0x00000000, cr2:0x00000000
cr3:0x00000000, cr4:0x00000000
f010124b: 0f 01 15 50 33 11 f0 lgdtl 0xf0113350
f0113350 D gdt_pd
I attached the tar file; gmake will generate the image file.
Thanks.