flat assembler
Message board for the users of flat assembler.

Index > OS Construction > pmode

Author
Thread Post new topic Reply to topic
dasyar



Joined: 27 Feb 2005
Posts: 33
dasyar 16 Mar 2005, 22:42
I have a bootsect program that loads programs to 0x0050 location. When I load the following program, I get a general fault error (a reboot). Any ideas as to why this will not start up in protected mode.

Code:
use16
org 0x0050


start:
        mov ax,cs
        mov ds,ax
        mov es,ax       


pmode:
        cli
        lgdt [gdtr]
        mov eax,cr0
        or eax,1
        mov cr0,eax
        
        jmp 0x08:pmsys

use32
pmsys:
        mov ax,0x10
        
        mov ds,ax
        mov es,ax
        mov fs,ax
        mov gs,ax
        mov ss,ax
        mov esp,0x3e7fff
        
        jmp $   

gdt:
  dw 0x0000, 0x0000, 0x0000, 0x0000
codesel:
  dw 0xffff, 0x0000, 0x9800, 0x00cf
datasel:
  dw 0xffff, 0x0000, 0x9200, 0x00cf
gdt_end:

gdtr:
  dw gdt_end - gdt - 1
  dd gdt    


Thanks

moderatpr notoce: please use [ code ] tags around code. (added code tags)
Post 16 Mar 2005, 22:42
View user's profile Send private message Reply with quote
Redragon



Joined: 27 Nov 2004
Posts: 101
Location: U.S.
Redragon 17 Mar 2005, 04:02
i noticed that you didnt start vesa.. could be some of the problem
Post 17 Mar 2005, 04:02
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 17 Mar 2005, 17:21
Ehh... What does VESA has to do with anything..?
Post 17 Mar 2005, 17:21
View user's profile Send private message Reply with quote
Redragon



Joined: 27 Nov 2004
Posts: 101
Location: U.S.
Redragon 17 Mar 2005, 17:38
lol.. i dont really know
Post 17 Mar 2005, 17:38
View user's profile Send private message Reply with quote
asmdemon



Joined: 18 Jan 2004
Posts: 97
Location: Virginia Beach, VA
asmdemon 17 Mar 2005, 21:42
what is the value that is loaded into CS; if it's 0000, then you have a problem of overwriting the interrupt table.
Post 17 Mar 2005, 21:42
View user's profile Send private message Visit poster's website Reply with quote
dasyar



Joined: 27 Feb 2005
Posts: 33
dasyar 19 Mar 2005, 15:46
The following is an updated program. It assembles correctly using fasm, and starts after being loaded by my bootsector program. This may be of interest for those of you who DO NOT want to go into pmode from the bootsector program. This is a conversion of one of the programs in the Geezer PMx.xxx series.

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov ax,cs
        mov ds,ax
        
use16
        

        mov si,test1
        call writestring

        xor ebx,ebx
        mov bx,cs
        shl ebx,4
        lea eax,[ebx]
        mov [gdt2 + 2],ax
        mov [gdt3 + 2],ax
        shr eax,16
        mov [gdt2 + 4],al
        mov [gdt3 + 4],al
        mov [gdt2 + 7],ah
        mov [gdt3 + 7],ah
        
        lea eax,[ebx + gdt]
        mov [gdtr + 2],eax
        
        cli
        
        lgdt [gdtr]
        
        mov eax,cr0
        or al,1
        mov cr0,eax
        
        jmp code_sel:do_pm
        
use32
do_pm:
        mov ax,data_sel
        mov ds,ax
        mov es,ax
        mov fs,ax
        mov gs,ax
        mov ss,ax

        mov ax,linear_sel
        mov es,ax
        
        mov byte [es:dword 0xb8060],'0'
        mov byte [es:dword 0xb8062],'1' 
        
        lea esi,[test2]
        call wrstr

        jmp $

wrch:
        pushf
        push gs
        push ecx
        push ebx
        push eax
        
        cli
        mov ax,linear_sel
        mov gs,ax
        movzx eax,byte [CsrY]
        mov cl,80
        mul cl
        add al,[CsrX]
        adc ah,0
        shl eax,1
        lea ebx,[eax + 0xb8000]
        pop eax
        push eax
        mov [gs:ebx],al
        mov cx,[CsrX]
        inc cl
        cmp cl,80
        jb wrch2
        xor cl,cl
        inc ch
        cmp ch,25
        jb wrch2
        xor ch,ch
wrch2:
        mov [CsrX],cx
        pop eax
        pop ebx
        pop ecx
        pop gs
        popf
ret

wrstr:
        push esi
        push eax
        cld
        jmp wrstr2
wrstr1:
        call wrch
wrstr2:
        lodsb
        or al,al
        jne wrstr1
        
        pop eax
        pop esi
ret

CsrX: db 0
CsrY: db 0

test2 db "In 32 bit mode",0


writestring:
        pusha
  .wloop:
        lodsb
        or al,al
        jz .done
        mov ah,0x0e
        mov bh,0
        mov bl,7
        int 0x10
        jmp .wloop
  .done:
        popa
ret

test1: db 13,10,'In 16 bit mode',0

gdtr:  dw gdt_end - gdt - 1
       dd gdt
       
gdt: dw 0
     dw 0
     db 0
     db 0
     db 0
     db 0
     
linear_sel = $ - gdt
     dw 0xffff
     dw 0
     db 0
     db 0x92
     db 0xcf
     db 0
     
code_sel = $ - gdt
gdt2: dw 0xffff
      dw 0
      db 0
      db 0x9a
      db 0xcf
      db 0
data_sel = $ - gdt
gdt3: dw 0xffff
      dw 0
      db 0
      db 0x92
      db 0xcf
      db 0
     
gdt_end:    


moderator notoce: please use [ code ] tags around code. (added code tags)
Post 19 Mar 2005, 15:46
View user's profile Send private message Reply with quote
AdamMarquis



Joined: 20 Jun 2003
Posts: 22
Location: La Sarre, Quebec, Canada
AdamMarquis 27 Apr 2005, 18:08
Look at my post titled: "IDE Bootloader take two",
the code patches its 16bits calls into 32bits ones,
and have a neat working pmode entry snippet.
Post 27 Apr 2005, 18:08
View user's profile Send private message Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 04 May 2005, 20:21
Dasyar, where is your magic number?

_________________
Sorry for my bad English Sad
Post 04 May 2005, 20:21
View user's profile Send private message Reply with quote
dasyar



Joined: 27 Feb 2005
Posts: 33
dasyar 05 May 2005, 12:44
Othername, I am not sure what you are refering to. What is the real question?
Post 05 May 2005, 12:44
View user's profile Send private message Reply with quote
thomasantony



Joined: 18 Aug 2004
Posts: 8
Location: Kerala, India
thomasantony 07 May 2005, 04:11
Hi,
I think he is talking about the Boot Signature. The bytes 55h, AAh at the bottom of the boot sector

Thomas
Post 07 May 2005, 04:11
View user's profile Send private message Visit poster's website Reply with quote
dasyar



Joined: 27 Feb 2005
Posts: 33
dasyar 07 May 2005, 12:56
The idea here was to enter into pmode from a loadable file, and not within the boot sector. So the "magic number" is within the boot sector program. Their are quite a few snippets of pmode entry within the boot sector, I wanted to do it within a loadable file. That way you could still do some stuff while still in 16 bit mode. So, in other words, this is not a "bootable" program, it is a loadable program.
Post 07 May 2005, 12:56
View user's profile Send private message Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 07 May 2005, 21:59
I had EXACLY such problem, and i didn't resolve it. At first i wrote bootsect whitch entered to PM, everything was OK. But when i changet it to simple prog whitch was booted from another bootsec(as you doing now), i got reboot. Now i boot'ing my loadable program(kernel) with GRUB.
I don't know why linux bootsector when it gets control relocates himself to 0x9000, maby you can try to do this.
Post 07 May 2005, 21:59
View user's profile Send private message Reply with quote
thomasantony



Joined: 18 Aug 2004
Posts: 8
Location: Kerala, India
thomasantony 08 May 2005, 15:46
Hi,
Where are you loading this code? I think linux bootsect relocates itself to load some other file at 7C00h

Thomas
Post 08 May 2005, 15:46
View user's profile Send private message Visit poster's website Reply with quote
deltre



Joined: 17 Apr 2005
Posts: 12
Location: Netherlands
deltre 23 May 2005, 09:37
Quote:

Hi,
I think he is talking about the Boot Signature. The bytes 55h, AAh at the bottom of the boot sector

Thomas


Isn't AA55h FAT only?

I'm a beginner in pmode, so if I'm saying something stupid, please be gentile Smile
Don't you have to open the A20 line before addressing such a large number in ESP?
Post 23 May 2005, 09:37
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 24 May 2005, 15:54
AA55h is the "magic number" for the BIOS to know the disk is bootable so it doesn't load any non-bootable partitions and try to boot from them. So, if you're going to make a boot loader it needs AA55h, or else BIOS won't recognize it, won't boot from it, and won't work.

BTW that I wouldn't recommend putting a boot sector on a hard drive with another OS unless you back the original one up. Use floppy disks at first, then later use hard disks. You might want to get a hard disk with nothing on it for testing purposes, so you don't mess anything up.
Post 24 May 2005, 15:54
View user's profile Send private message AIM Address Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 28 May 2005, 13:04
What if you write 'pword' before the jmp operand?
Code:
jmp pword 0x08:pmsys    
Post 28 May 2005, 13:04
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.