flat assembler
Message board for the users of flat assembler.

Index > OS Construction > is it a BIOS problem?

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 05 May 2008, 00:29
hello!

i've made a new version of my boot loader, and then, i meet a big problem:

this bootloader have a special disk function (based on INT13h) that will make drive id command, and read the sectors one by one, to avoid floppy problems.

on my old PII it works, on Bochs it works, but on my old laptop, it don't works and freeze just before to jump to the relocated bootloader.

it makes me feel crazy.

****************************************************
*********************************

****************************************************
****************************************************
****************************************************
****************************************************
****************************************************


Problem solved!


Last edited by edfed on 05 May 2008, 11:45; edited 2 times in total
Post 05 May 2008, 00:29
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
sinsi 05 May 2008, 02:24
Is your old laptop old enough to be a 286?
Post 05 May 2008, 02:24
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 05 May 2008, 02:37
no, it is my good old PIII OMNIBOOK XE3

and it is at least the 29th time i try to correct this bug.

it freeze at "B" debug point.

i didn't try this on my 386 and 486, but i'm pretty sure it is ok.
thanx!
Post 05 May 2008, 02:37
View user's profile Send private message Visit poster's website Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 295
Alphonso 05 May 2008, 08:15
Hi Edfed,

did the same on my PIII notebook. Initializing DS seemed to sort it, at least to 'E' anyway. Maybe "push cs, pop ds" at the start will help.
Post 05 May 2008, 08:15
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 05 May 2008, 11:17
thanks Alphonso. Smile Very Happy
it helped,

now the problem is to reboot from drive 80h, it reboot from original boot drive (floppy in this case) instead of hard drive.
it don't work at all, but i'll find a solution.


edit:
problem solved, it was DS that wasn't initialised when return from kernel
Embarassed


Last edited by edfed on 13 May 2008, 13:38; edited 1 time in total
Post 05 May 2008, 11:17
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 12 May 2008, 15:50
hello, one more strange problem with the boot loader.

Code:
;               This comloader.bin file is a bootloader
;          it will be writen on the first sector of a drive
;
;               the kernel will be a .com binary
;        this binary shall be writen from sector 2 and above
;
                      ;;;;;;;;;;;;;;;;;;;;;;;; sector 1
                      ;   bootloader         ;
                      ;                      ;
                      ;;;;;;;;;;;;;;;;;;;;;;;; sector 2
                      ;  .com binary         ;
                      ;                      ;
                      ; this program can be  ;
                      ; any .com program     ;
                      ; but shouldn't depend ;
                      ; on dos INT,          ;
                      ; a simple ret will    ;
                      ; return to the        ;
                      ; bootloader           ;
                      ;;;;;;;;;;;;;;;;;;;;;;;; up to 70h sectors



;version 05/05/2008 01:50;;;;;
comloader:                   ;
;use16                       ; not usefull
        org 7C00h            ;
        push cs              ;
        pop ds               ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
A:                           ; used as a debug point
        mov bx,01241h        ; will fill the screen with "A"
        call cls             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov si,reload        ; point to reload_boot object
        mov [si+disk.drv],dl ; overwrite the drv field with boot device
        call disk            ; execute the object
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
B:                           ; "B" debug point
        mov bx,02342h        ;
        call cls             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;  it hangs there   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;    GRRRRR      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov word[si+disk.off],there
        jmp far dword[si+disk.off]; jump to reloaded boot sector
there:                          ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
C:                           ; "C" debug point
        mov bx,03443h        ;
        call cls             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        push cs              ;
        pop ds               ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov si,kernel        ;
        mov ax,[si+disk.seg] ; point to PSP location
        mov es,ax            ;
        xor bx,bx            ;
        mov cl,psp.end-psp   ;
        mov di,psp           ;
@@:                          ; copy the PSP code at 2000h:0
        mov ax,[di+bx]       ;
        mov [es:bx],ax       ;
        add bx,2             ;
        dec cl               ;
        jne @b               ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
D:                           ; "D" debug point
        mov bx,04544h        ;
        call cls             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov [si+disk.drv],dl ; overwrite the drv param
        call disk            ; will copy it just 100h after PSP, building .com environment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
E:                           ; "E" debug point
        mov bx,05645h        ;
        call cls             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       call far dword[si+disk.off];
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        push cs              ;
        pop ds               ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov bx,0b101h        ; fill the text memory with a blinking smiley
        call cls             ; just for fun while the dos prompt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        mov si,reboot              ; point to the reboot object
        mov byte[si+disk.drv],80h  ; overwrite with C: drive
        call disk                  ; will load the bootloader from hard drive
        jmp far dword[si+disk.off]      ; and reboot on this OS.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cls:                         ;
        mov di,80*25*2-2     ;
        mov ax,0b800h        ;
        mov es,ax            ;
@@:                          ;
        mov [es:di],bx       ;
        sub di,2             ;
        jnl @b               ;
        ret                  ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
psp:                         ;
        push cs              ;
        pop ds               ;
        mov ax,100h          ;
        call ax              ;
        retf                 ;
.end:                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 4                                    ;
reload:;  dd disk                           ;
         dd 00010002h,1,1000h:7c00h,0;,0      ; disk operation, read the boot sector from floppy at 1000h:7C00h
kernel:;  dd disk                           ;
         dd 00700002h,2,2000h:0100h,0;,0      ; disk operation, read 70h sectors after boot from floppy
reboot:;  dd disk                           ;
         dd 00018002h,1,0000:7c00h,0;,0      ; disk operation, read the boot sector from hard drive at boot entry
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
include 'disk.inc'           ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
free =  510-(padding-$$)
padding rb free
        dw 0aa55h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; macro from the boot an Adam Marquis's sector , an user of FASM board Very Happy ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d1 = '0'+ free shr 8 and 0Fh
d2 = '0'+ free shr 4 and 0Fh
d3 = '0'+ free and 0Fh
if d1>'9' 
d1 = d1 + 7 
end if 
if d2>'9' 
d2 = d2 + 7 
end if 
if d3>'9' 
d3 = d3 + 7 
end if 
display d1,d2,d3,'h '
display 'free bytes ',13,10
    

the problem is simple, it blocks at "B" when i run it at Boot or in bochs, but it works when making the same thing in a dos program:
Code:
        org 100h
        mov ax,cs
        mov word[there+2],ax
        mov si,there-8
        mov word[si+8],start
        jmp far [si+8]
start:
....
there dd 0:0
    
Post 12 May 2008, 15:50
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 12 May 2008, 16:29
So the same thing as before, you are not initialising the segment for the far call?
Code:
        mov word[si+disk.off],there
        mov word[si+disk.off+2],cs ;which segment do you want? Or is this 32bit mode?
        jmp far dword[si+disk.off]; jump to reloaded boot sector
there:    
Post 12 May 2008, 16:29
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 12 May 2008, 17:33
Quote:
So the same thing as before, you are not initialising the segment for the far call?

not true. and i'm not so stupid to make the same error two consecutive times. Very Happy
i initialise the segment.
it is initialised during compilation there:
Code:
reload:;  dd disk                           ; 
         dd 00010002h,1,1000h:7c00h,0;,0     
     

and used as an object to reload the boot sector elsewhere, then, jump to the far ptr in the structure.

in the second case i initialise the ptr with the curent value of CS because i just want to do a jmp far [xx] with xx pointing to a far pointer. and just before the jump, i set the segment part to current cs.

in the first case, the far pointer is defined in source code, and will be modified during execution to set th eright address whereto jump...

but it don't works.
Post 12 May 2008, 17:33
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 12 May 2008, 17:50
If 'B' prints and 'C' does not print then the only place for a mistake is the jmp far. So are you sure your segment is correct? Are you sure the offset is correct? Is 'there:' still at the correct offset? Are you changing IP at any point and making all your compiled offsets wrong?
Post 12 May 2008, 17:50
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 12 May 2008, 18:08
it worked with the direct far pointer.
Code:
jmp 1000h:there
    

i'm sure the segment is correct.
i'm sure the offset is correct.
"there" is at the right offset, the org 7c00h permit to localise it.
ip never changes until the supposed jump.
only some calls and ints are made.
the disk.inc funtion is not the reason of errors, it don't affect anything.

i use the far pointer as a reference where to reload the boot loader, then, i modify the offset field.
but it don't works at boot time... it looks like an impossible thing to do.
what a pity.

maybe it is the default segment for si the guilty...
is it possible that si uses es by default in real mode???
Post 12 May 2008, 18:08
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 12 May 2008, 18:25
What is the value of disk.off? You haven't shown all the code so it is difficult to know where is your mistake.

And of course si default segment is ds. Why would you thing it is different in realmode?
Post 12 May 2008, 18:25
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 12 May 2008, 18:57
Quote:
What is the value of disk.off? You haven't shown all the code so it is difficult to know where is your mistake.

Code:
disk:
;.call=0     ; not usefull for bootloader
.cmd=0;4     ; then, relocate the fields
.drv=1;5     ; and will save 4 bytes by objects.
.cnt=2;6
.s=4;8
.h=5;9
.c=6;10
.off=8;12
.seg=10;14
.s0=12;16
.h0=13;17
.c0=14;18
;.kb0=20     ; not usefull for now, save 4 bytes + source code.
.n=2
        call .id
        mov al,[si+.s]
        mov ah,[si+.h]
        mov bx,[si+.c]
        mov cx,[si+.cnt]
        mov dx,[si+.off]
        push cx dx es
.next:
        sub word[si+.cnt],.n
        jl .end
        push ax bx
        mov cx,bx
        mov bl,cl
        mov cl,ch
        mov ch,bl
        shl cl,6
        and cl,0c0h
        or cl,al
        mov dh,ah
        pushaw
        call .atom
        jnc @f
        popaw
        pushaw
        call .atom
        jnc @f
        popaw
        pushaw
        call .atom
        jnc @f
.error:
        popaw
        pop bx ax
        clc
        jmp .tchao
@@:
        add word[si+.off],512*.n
        popaw
        pop bx ax
        inc al
        cmp al,[si+.s0]
        jne @f
        mov al,1
        inc ah
        cmp ah,[si+.h0]
        jl @f
        mov ah,0
        inc bx
        cmp bx,[si+.c0]
        jl .next
        mov bx,0
@@:
        jmp .next
.atom:
        call .reset
        mov bx,[si+.seg]
        mov es,bx
        mov bx,[si+.off]
        mov ah,[si+.cmd]
        mov al,.n
        mov dl,[si+.drv]
        int 13h
        ret
.reset:
        mov dl,[si+.drv]
        mov ah,0
        int 13h
        ret
@@:
        clc
        ret
.id:
        cmp byte[si+.drv],0
        jnl .floppy
        call .reset
        jc @b
        mov ah,8
        mov dl,[si+.drv]
        int 13h
        inc dh
        mov [si+.h0],dh
        mov bx,cx
        and cl,not 0c0h
        mov [si+.s0],cl
        mov cl,ch
        mov ch,bl
        shr ch,6
        inc cx
        mov [si+.c0],cx
@@:
;        movzx ax,byte[si+.s0]
;        movzx bx,byte[si+.h0]
;        mov cx,word[si+.c0]
;        imul ax,bx
;        imul ax,cx
;        shr ax,1
;        mov [si+.kb0],ax
        stc
        ret
.floppy:
        mov word[si+.c0],80
        mov byte[si+.h0],2
        mov byte[si+.s0],18
        jmp @b
.end:
        stc
.tchao:
        pop es dx cx
        mov [si+.off],dx
        mov [si+.cnt],cx
        ret
    


Quote:

And of course si default segment is ds. Why would you thing it is different in realmode?


i assumed that because of the lods instructions.
Post 12 May 2008, 18:57
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 12 May 2008, 19:34
What happens if you insert this line before the jmp far?
Code:
        mov word[si+disk.off+2],0x1000    
Post 12 May 2008, 19:34
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 12 May 2008, 19:45
it don't change anything.

i've tried all possibilities, from reversing the prt:components to overwrite them.
i've posted the code as it is supposed to work. but i sould say it is breaking my mind.
Sad

indeed, thanks for your help.. maybe we'll find the solution.
Post 12 May 2008, 19:45
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 12 May 2008, 20:02
Code:
reload:;  dd disk                           ; 
         dd 00010002h,1,1000h:7c00h,0;,0    
'.cnt'=1, and
Code:
.n=2
...
        sub word[si+.cnt],.n
        jl .end     
So your count is 1 sector, but you never load it because your disk function needs a multiple of 2 sectors.
Post 12 May 2008, 20:02
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 12 May 2008, 20:25
Laughing

thanks.

little story about .n=2

i tryed to increase the speed of disk.read function by reading at least 2 sectors. i forgot this dumb idea right now, as it is not that fast.
and i meat some problems to compute the right count of sectors function of .n


now it works.

thanks a lot revolution...
Post 12 May 2008, 20:25
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 12 May 2008, 20:29
edfed wrote:
the disk.inc funtion is not the reason of errors, it don't affect anything.
Hmm, one can never assume such things.
Post 12 May 2008, 20:29
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 12 May 2008, 20:31
Quote:

Hmm, one can never assume such things.


exact. at least, today, i learnt to be carefull about this kind of assumptions.

thanks again. Very Happy it took me 7 days to decide to ask for help.

and now, i have a new version to upload:


Description: this one is object oriented, but not enough advanced...
hte world does not construct in one day.

Download
Filename: comload.zip
Filesize: 4.38 KB
Downloaded: 294 Time(s)

Post 12 May 2008, 20:31
View user's profile Send private message Visit poster's website 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.