flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Protected Mode HELP!!!

Author
Thread Post new topic Reply to topic
Goat6



Joined: 06 Jan 2006
Posts: 8
Goat6
Hello All.

I have been trying to build a PM OS.
the secondary loader will enter protected mode then load the os.

To simplify the learning curve I striped CDPod's code to the bare PM code.
But when I boot the code the cpu continualy tripple faults and resets over and over.

Can Someone please tell me whats wrong with this code?

BTW: I compile it with FASM into a COM file executable.

Code:
use16
;****************************
; Realmode startup code.
;****************************

start:
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   sp,0x7C00 


;*****************************
; Setting up, to enter pmode.
;*****************************

        cli 
        lgdt  [gdtr]
        
        mov   eax, cr0
        or    al,0x1 
        mov   cr0,eax
 
        jmp   0x10: protected

;*****************************
; Pmode. Wink
;*****************************

use32
protected:
        mov   ax,0x8 
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   esp,0x7C00
;*****************************
; Turn floppy off (if space).
;*****************************

        mov   dx,3F2h
        mov   al,0
        out   dx,al

        lp:

        jmp lp


;*************************************
; GDT. 
;*************************************

gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000
sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CF
gdt_end:

gdtr:       dw gdt_end - gdt - 1                                          
            dd gdt 

    



Arrow Arrow Arrow Cool

_________________
Death is not the opposite of life but rather the absence of it.
Post 30 Mar 2006, 02:11
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
At which address is the code loaded? This is the #1 failure of everyone trying to write code to enter pmode, the address modes! Your in rmode (16bit address) and have segment:offset and to get the 32bit address you have to do segment*16+offset.

In your code you would jump to the address of the label "protected", but the address is somewhere between 0 and 30h and your jump "jmp 0x10:protected" jumps into the nirvana (the rmode int table I guess)!

So we need your code segment, the address at which this code is loaded!
Post 30 Mar 2006, 04:30
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Try that
Code:
org     100huse16start:;*****************************; Setting up, to enter pmode.;*****************************        cli         lgdt  [gdtr]                mov   eax, cr0        or    al,0x1         mov   cr0,eax         jmp   0x10: protected;*****************************; Pmode. Wink;*****************************use32protected:        mov   ax,0x8         mov   ds,ax        mov   es,ax        mov   ss,ax;*****************************; Turn floppy off (if space).;*****************************        mov   dx,3F2h        mov   al,0        out   dx,al        lp:        jmp lp;*************************************; GDT. ;*************************************gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CFsys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CFgdt_end:gdtr:       dw gdt_end - gdt - 1                                                      dd gdt     


Last edited by Dex4u on 30 Mar 2006, 14:10; edited 1 time in total
Post 30 Mar 2006, 08:07
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
@Dex4u

This also wont work, because you assume that the code is loaded at 0x100!

There are 2 options to get the linear address. Calc it at compile time or at run time. I like to know the address at compile time, this is a lot easier!

But with this code you could do it also at run time:

Code:
use16

start:
xor eax,eax
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x7c00

push cs
pop ax
shl eax,4
add [jump.offset],eax
add [gdtr.base],eax

cli
lgdt [gdtr]
mov eax,cr0
or ax,1
mov cr0,eax

jump:
.code:
db 0x66,0xea
.offset:
dd protected
.selector:
dw 0x10

use32
protected:
mov dx,0x3f2
xor eax,eax
out dx,al

jmp $

use16
gdt:
dw 0,0,0,0
dw 0xffff,0,0x9200,0xcf
dw 0xffff,0,0x9a00,0xcf
gdt_end:

gdtr:
.limit:
dw gdt_end - gdt
.base:
dd gdt
    


I also think if you just use "org 0x7c00" it will also work, as I assume that your code is loaded at 0x7c00!
Post 30 Mar 2006, 11:33
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
@FlashBurn, i thought he was loading it as a com file, with something like this: http://alexfru.chat.ru/epm.html#bootprog
If that is so it will work, with "org 100h" added.

But if he is booting it from a floppy boot sector, it need org 0x7C00
on is original, and assembly it as a bin file and use rawrite, then his original should work, (eg: the one he posted).

Note: the com file will not work in window or dosbox.
Post 30 Mar 2006, 14:17
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
Dex4u wrote:
@FlashBurn, i thought he was loading it as a com file, with something like this: http://alexfru.chat.ru/epm.html#bootprog
If that is so it will work, with "org 100h" added.

But if he is booting it from a floppy boot sector, it need org 0x7C00
on is original, and assembly it as a bin file and use rawrite, then his original should work, (eg: the one he posted).

Note: the com file will not work in window or dosbox.


you really love bootprog don't you, you seem to post it here alot Very Happy

just giving you a hard time, the source from that helped me make my first decent bootloader a while back Smile

_________________
redghost.ca
Post 30 Mar 2006, 15:22
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Goat6



Joined: 06 Jan 2006
Posts: 8
Goat6
I thank everyone for the tips.

But I'vw tryed many of them and still cant get anywhare.

I think I will use '[org 0x100]' and the visit my boot strap code to get the
address at which i load the OSLoader file.

I am going to continue to visit this thread for more tips so pease dont stop "tipping".

Thanks again.

Arrow Arrow Arrow Cool

_________________
Death is not the opposite of life but rather the absence of it.
Post 30 Mar 2006, 16:31
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
@Dex4u

It wont work believe me! You need the right base address and the right address of the label for jumping into pmode and in rmode you either know the segment address or you do it like I have written.
Post 30 Mar 2006, 16:50
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
The code did have base, i did not notice, missing as i cut and paste.
I have Tested this code and it works on my pc's.
Code:
org     100huse16start:;*****************************; Setting up, to enter pmode.;*****************************        xor   ebx,ebx        mov   bx,ds        shl   ebx,4        mov   eax,ebx        mov   [sys_code + 2],ax        mov   [sys_data + 2],ax        shr   eax,16        mov   [sys_code + 4],al        mov   [sys_data + 4],al        mov   [sys_code + 7],ah        mov   [sys_data + 7],ah        add   ebx,gdt        mov   [gdtr + 2],ebx        cli        lgdt  [gdtr]        mov   eax, cr0        or    al,0x1        mov   cr0,eax        jmp   0x18: protected;*****************************; Pmode. Wink;*****************************use32protected:        mov   ax,0x10         mov   ds,ax        mov   ss,ax        mov   ax,0x8        mov   es,ax;*****************************; Turn floppy off (if space).;*****************************        mov   dx,3F2h        mov   al,0        out   dx,al        mov   byte [es:0xB8000], "P"        lp:        jmp lp;*************************************; GDT. ;*************************************gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000sys_Lin:    dw    0xFFFF, 0x0000, 0x9200, 0x00CFsys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CFsys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CFgdt_end:gdtr:       dw gdt_end - gdt - 1            dd gdt    

You need the sys_lin or the base is add to screen pointer.
It should print "P" in pmode, run from pure dos or that bootloader.
Post 30 Mar 2006, 17:58
View user's profile Send private message Reply with quote
Goat6



Joined: 06 Jan 2006
Posts: 8
Goat6
The source worked thanks dex4u!


Arrow Arrow Arrow Cool

_________________
Death is not the opposite of life but rather the absence of it.
Post 30 Mar 2006, 18:32
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Your welcome.
Post 30 Mar 2006, 18:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.