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.
northfuse
Post
by northfuse » Mon Dec 01, 2003 5:27 pm
yes, i'm a newbie. I'm trying to load a new GDT (with lgdt), but when I try to flush the registers, bochs crashes saying:
my code is as follows:
Code: Select all
;.gdt.asm
;------------GDT Table---------------;
GDTR:
GDTsize DW GDT_END-GDT-1
GDTbase DD 0x500
GDT:
NULL_SEL EQU $-GDT ; null descriptor is required (64bit per entry)
DD 0x0
DD 0x0
CODESEL EQU $-GDT ; 4GB Flat Code at 0x0 with max 0xFFFFF limit
DW 0xFFFF ; Limit(2):0xFFFF
DW 0x0 ; Base(3)
DB 0x0 ; Base(2)
DB 0x9A ; Type: present,ring0,code,exec/read/accessed (10011000)
DB 0xCF ; Limit(1):0xF | Flags:4Kb inc,32bit (11001111)
DB 0x0 ; Base(1)
DATASEL EQU $-GDT ; 4GB Flat Data at 0x0 with max 0xFFFFF limit
DW 0xFFFF ; Limit(2):0xFFFF
DW 0x0 ; Base(3)
DB 0x0 ; Base(2)
DB 0x92 ; Type: present,ring0,data/stack,read/write (10010010)
DB 0xCF ; Limit(1):0xF | Flags:4Kb inc,32bit (11001111)
DB 0x0 ; Base(1)
GDT_END:
;----------End GDT Table-------------;
[global gdt_init]
gdt_init:
lgdt [GDTR] ;load GDT
jmp CODESEL:FLUSH ;clear cs/ip/eip
FLUSH:
;refresh all segment registers
mov eax,DATASEL
mov ds,eax
mov es,eax
mov fs,eax
mov gs,eax
mov ss,eax
ret
gdt_init is then called from my main() function in main.c how should i fix this?
thanx
Curufir
Post
by Curufir » Mon Dec 01, 2003 7:31 pm
First thing I'd look at would be this:
Are you sure the base of the GDT is actually here? Are you relocating it within your C code or something?
northfuse
Post
by northfuse » Mon Dec 01, 2003 8:11 pm
duh! i'm so stupid. that fixed everything. just changed it to the address of the GDT base (duh) and it worked. thanx
mr. xsism
Post
by mr. xsism » Tue Dec 02, 2003 11:59 am
you know the reason it was set to 0x500 is that there was code in boot.asm that moved it to that address. You might want to give some credit to whoever coded that.
Code: Select all
; boot.asm
; OS Bootloader
; Version 2.0
; Author: xsism
; Date: 4/14/03
; Memory Layout:
; 0x000000-0x0003FF PC IVT
; 0x000400-0x0004FF PC BDA
; 0x000500-0x000CFF TEMP GDT
; 0x001D00-0x001F00 System Stack
; 0x002000-0x0A0000 System code/data
; 1.44MB Floppy setup: (C/H/S) 80C, 2H/C, 18S/H, 512b/S 2880S
; 000-0001 Boot Sector code
; 001-0143 System code/data
; 144-2880 plugin code/data
; * set these accordingly before you call BIOS read *
; ah=BIOS function al=number of sectors to read into memory
; es:bx= seg:off memory location
; ch=track number cl=starting sector
; dh=head number dl=drive number
; - 2=BIOS read function
; * ah=(on error)sectors that were read in
; 16 bit code that starts at 0x7c00
[bits 16]
[org 0x7c00]
jmp boot ; jump over the data to our code
;=-=-=-=-=-=-=-=-=-=-=-=Data=-=-=-=-=-=-=-=-=-=-=-=;
; ---=[Start GDT Table]=--- ;
GDTR:
GDTsize DW GDT_END-GDT-1
GDTbase DD 0x500
GDT:
NULL_SEL EQU $-GDT ; null descriptor is required (64bit per entry)
DD 0x0
DD 0x0
CODESEL EQU $-GDT ; 4GB Flat Code at 0x0 with max 0xFFFFF limit
DW 0xFFFF ; Limit(2):0xFFFF
DW 0x0 ; Base(3)
DB 0x0 ; Base(2)
DB 0x9A ; Type: present,ring0,code,exec/read/accessed (10011000)
DB 0xCF ; Limit(1):0xF | Flags:4Kb inc,32bit (11001111)
DB 0x0 ; Base(1)
DATASEL EQU $-GDT ; 4GB Flat Data at 0x0 with max 0xFFFFF limit
DW 0xFFFF ; Limit(2):0xFFFF
DW 0x0 ; Base(3)
DB 0x0 ; Base(2)
DB 0x92 ; Type: present,ring0,data/stack,read/write (10010010)
DB 0xCF ; Limit(1):0xF | Flags:4Kb inc,32bit (11001111)
DB 0x0 ; Base(1)
GDT_END:
; ---=[End GDT Table]=--- ;
...
; -[move GDT to 0x500]- ;
xor ax,ax
mov ds,ax
mov es,ax
mov si,GDT ; Move From [DS:SI]
mov di,[GDTbase] ; Move to [ES:DI]
mov cx,[GDTsize] ; size of GDT
cld ; Clear the Direction Flag
rep movsb ; Move it
...