Switching to 386 protected mode
From: Tobias Guggenmoser (guggi_at_netcologne.de)
Date: 01/25/04
- Next message: Phil Carmody: "SSE2 advice"
- Previous message: Phil Carmody: "Re: SSE2"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 25 Jan 2004 19:49:56 +0000 (UTC)
I am currently trying to develop a "mini-os" to get a deeper
understanding of how an operating system works.
I have started in real mode, but I want to let the os switch into
protected mode so it can take of its advantages in memory and because
I want to develop any higher-level stuff like shells, file system
management using gcc.
Unfortunately, my understanding of protected mode is not very
advanced, so I read through a couple of tutorials and some chapters of
the "Intel 80386 Programmer's Reference Manual". I then wrote a simple
program that should be loaded into memory instead of my 16-bit kernel.
Its sole purpose: switching into protected mode, write a "G" on the
screen and then hang with an infinite loop. However, booting this
"kernel" (both in a VMware box and on a real PC) results in nothing
but a hang, and I cannot localize the error. I hope that someone in
this group with a deeper understanding will find it (the program is
attached below in NASM syntax).
Thanks in advance
Tobias
BITS 32
jmp main
GDT_data:
.limit dw 0
.base dd 0
GDT:
.des_null:
times 8 db 0
.des_code:
dw 0xffff ;limit 0-15
dw 0 ;base 0-15
db 0 ;base 16-23
db 10011010b
db 11001111b
db 0 ;base 24-31
.des_data:
dw 0xffff
dw 0
db 0
db 10010010b
db 11000000b
db 0
.des_lin:
dw 0xffff
dw 0x0000
db 0x00
db 10010010b
db 11001111b
db 0
main:
mov ax,cs
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
cli
mov ss,ax
mov sp,0xffff
sti
;set up GDT info data for the 80386
mov word [GDT_data.limit],32 ;store size info
;transform seg:off into linear base
xor eax,eax
mov ax,ds
mov cl,4
shl eax,cl ;multiply seg adress by 0x10
mov ebx,eax
add eax,GDT ;add offset
mov dword [ds:GDT_data.base],eax
mov eax,ebx
mov word [ds:GDT.des_code+2],ax
mov word [ds:GDT.des_data+2],ax
mov cl,16
shr eax,cl
mov byte [ds:GDT.des_code+4],al
mov byte [ds:GDT.des_code+7],ah
mov byte [ds:GDT.des_data+4],al
mov byte [ds:GDT.des_data+7],ah
;finally load it into GDTR
cli ;do not disturb
lgdt [GDT_data]
;****** SWITCH TO PROTECTED MODE! *********
mov eax,1
mov cr0,eax
mov ax,16
mov ds,ax ;selector for data
mov es,ax
mov ss,ax
mov ax,24
mov fs,ax
mov gs,ax
jmp pmcode
;******************************************
pmcode:
mov byte [fs:0xB8000],"G"
infloop: jmp infloop
- Next message: Phil Carmody: "SSE2 advice"
- Previous message: Phil Carmody: "Re: SSE2"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|