flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Help understanding CD-ROM booting

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 15 Nov 2011, 04:42
No problem...I'd be interested in knowing your results and on what specification.

After some reading, it appears that some BIOSes don't report the correct drive number in the DL upon boot up from a CD-ROM. So, in order to get the right boot drive you may have to check all drive numbers from 80h to FFh (or in reverse order, since you can almost be assured that 80h is your hard disk drive). I will include that loop in there in the next iteration.

I was also thinking that some BIOSes would put it somewhere in lower memory (ie. 0040h:0075h) but I can't find that either.

More to come as I research it...
Post 15 Nov 2011, 04:42
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 15 Nov 2011, 10:13
smiddy wrote:
After some reading, it appears that some BIOSes don't report the correct drive number in the DL upon boot up from a CD-ROM.
Did not meet such BIOSes.

_________________
If you have seen bad English in my words, tell me what's wrong, please.
Post 15 Nov 2011, 10:13
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 15 Nov 2011, 12:17
The Virtual PC and VirtualBox both report 00h, then after doing INT 13h Function 4B01h do I get the drive numbers that they should be (E0h and EFh respectively). My AMD 3000+ report a 00h at boot up, it's a circa 2003-ish machine, after running INT 13h Function 4B01h it reports E0h as well. On my other two machines, it fails do to the CARRY FLAG being set. Once the CARRY FLAG is set I don't recheck, this is where I will do the loop to check for each drive decrementing down from FFh until I reach 81h. I probably won't get to that for a week or so, since I will be on business travel this week.
Post 15 Nov 2011, 12:17
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 15 Nov 2011, 19:01
Where are you writing the boot sector to your disk image and have you created the necessary ISO tables (primary partition, boot record, boot catalog etc)?

VirtualBox supports both emulation (ID 0x00, image location 0000, 512 byte sectors) and non-emulation boots (ID 0xE0, image location A000, 2048 byte sectors). I've also had no problems with VirtualPC or QEMU in non-emulation.
Post 15 Nov 2011, 19:01
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 16 Nov 2011, 00:44
Hi cod3b453,

Yep, it took me a while to get the iso built, I created it with FASM and I used MagicISO to check it. Everything is there to boot, I can PM you the code, I'd rather it not be put out "in the wild" until I have finished my boot process. So, it boots as I would expect, but the DL upon boot, always returns 00h no matter the system. So I'm on the learning curve of figuring out how to get the true boot drive, since the code is only on a CD the assumption is (from the code's perspective) that it booted from a CD, but finding the where seems to be the problem. I used INT 13h function 4B01h to get the actual drive number by putting what was given from BIOS in the DL to this function, and in the Disk Results Buffer at offset byte 2, I get the right results. I then read in the Primary Volume Descriptor to get the location of the boot directory.

At this point that is as far as I've gotten. I need to parse the root directory and find the OS file information, then load to memory, and jump to its location to run. I'm a ways form that at the moment, since I'm being distracted by figuring out a decent method to determine the actual drive, since on my real machine I use all the time, it returns 00h in the DL at but AND the CF is indicated when using INT 13h function 4B01h. I want it to boot on my true machine. My legacy machines it works ok thus far.

BTW, I found a BIOS Enhance Disk Drive Services document and I found this excerpt interesting:

Code:
7.1.2    No Emulation Boot
If an image is marked as No Emulation Boot, the system BIOS shall load the specified number of sectors and jump to the specified segment number to start the boot program executing.  Since this is a no emulation boot, the system BIOS shall not provide access to the media through INT 13h FNs 00h through 3Fh.  The system BIOS shall assign the CD-ROM drive a device number.  A common industry number is A0h.  This is outside the range of normal BIOS hard drive numbers (above 9Ah), but still within INT 13h range limitation.
    


It appears that I won't have to cycle down from FFh to 81h, but only to A0h...Smile If I can believe this document.

Oh, BTW, I am using no emulation upon boot. I haven't tried QEMU or Bochs for that matter recently.
Post 16 Nov 2011, 00:44
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 16 Nov 2011, 00:53
Here's a screenshot from VirtualBox of the current progress.


Description:
Filesize: 27.82 KB
Viewed: 6243 Time(s)

smiddyOSBoot - 1.PNG


Post 16 Nov 2011, 00:53
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 16 Nov 2011, 09:04
Bochs reports 0xE0. Try to run this code in VirtualBox:
Code:
        org 7C00h

        xor bx,bx
        cli
        mov ss,bx
        mov sp,$$
        sti
        mov ds,bx
;        jmp 0:@f
@@:
        mov al,dl
        call hexbyte
        mov [disknum],ax
        mov si,msgstr
        call putstr
        mov ah,0
        int 16h
        int 19h
@@:
        push si
        mov bx,7
        mov ah,0Eh
        int 10h
        pop si
putstr:
        mov al,[si]
        inc si
        and al,al
        jg short @b
        ret
hexbyte:
        aam 10h
        cmp al,0Ah
        sbb al,69h
        das
        xchg al,ah
        cmp al,0Ah
        sbb al,69h
        das
        ret
msgstr:
        db 13,10,"BIOS disk number: 0x"
disknum:
        db "??",13,10,"Press any key to reboot...",32,0
        rb 83FEh-$
        dw 0AA55h
    
Post 16 Nov 2011, 09:04
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 16 Nov 2011, 18:28
I posted an ISO image in: http://board.flatassembler.net/topic.php?p=122150 - it's not a particularly amazing example (and is wrong in places Embarassed) but it does work and reports 0xE0 at boot. egos also posted theirs but I've never tried it.

I realise your aim is not to be in CDROM emulation but that's what an ID of 0x00, until you use the BIOS emulation functions int 0x13 ax=0x4B0X, is.
Post 16 Nov 2011, 18:28
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 16 Nov 2011, 19:41
I think the problem is here:
Code:
  MOV [CDDriveNumber],DL
  ...
  MOV DS,AX
  ...
  MOV AL,[CDDriveNumber]
    

I can't understand what's happened with stack initialization too.
Post 16 Nov 2011, 19:41
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 17 Nov 2011, 00:06
egos wrote:
Bochs reports 0xE0. Try to run this code in VirtualBox:
Code:
        org 7C00h

        xor bx,bx
        cli
        mov ss,bx
        mov sp,$$
        sti
        mov ds,bx
;        jmp 0:@f
@@:
        mov al,dl
        call hexbyte
        mov [disknum],ax
        mov si,msgstr
        call putstr
        mov ah,0
        int 16h
        int 19h
@@:
        push si
        mov bx,7
        mov ah,0Eh
        int 10h
        pop si
putstr:
        mov al,[si]
        inc si
        and al,al
        jg short @b
        ret
hexbyte:
        aam 10h
        cmp al,0Ah
        sbb al,69h
        das
        xchg al,ah
        cmp al,0Ah
        sbb al,69h
        das
        ret
msgstr:
        db 13,10,"BIOS disk number: 0x"
disknum:
        db "??",13,10,"Press any key to reboot...",32,0
        rb 83FEh-$
        dw 0AA55h
    


I need to study this more, your code reports E0h, so maybe I'm doing something wrong there...


Description:
Filesize: 21.63 KB
Viewed: 6204 Time(s)

smiddyOSBoot - 2.PNG


Post 17 Nov 2011, 00:06
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 17 Nov 2011, 00:08
cod3b453 wrote:
I posted an ISO image in: http://board.flatassembler.net/topic.php?p=122150 - it's not a particularly amazing example (and is wrong in places Embarassed) but it does work and reports 0xE0 at boot. egos also posted theirs but I've never tried it.
Thanks I will study this too.

cod3b453 wrote:
I realise your aim is not to be in CDROM emulation but that's what an ID of 0x00, until you use the BIOS emulation functions int 0x13 ax=0x4B0X, is.
Yeah, I don't get it. Apparently I'm doing something wrong since ego's code seems to work.


Last edited by smiddy on 17 Nov 2011, 00:14; edited 1 time in total
Post 17 Nov 2011, 00:08
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 17 Nov 2011, 00:13
egos wrote:
I think the problem is here:
Code:
  MOV [CDDriveNumber],DL
  ...
  MOV DS,AX
  ...
  MOV AL,[CDDriveNumber]
    

I can't understand what's happened with stack initialization too.
Ah, I see what you're saying, I'm not setting up the DS prior to assigning CDDriveNumber with the DL.

I am not using the stack (yet) so I'm not pushing and popping. I don't intend to either, yet. Too much to work first, the stack will be part of my memory management plan, which I haven't set down and thought of yet. In my older code I did set it up prior to booting my OS, and I loaded started my os, and began using the same stack there. I don't know if I want to do that this time or not.

I'll correct my code by setting up the DS prior to assigning the CDDriveNumber and report back, I bet that is it.
Post 17 Nov 2011, 00:13
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 17 Nov 2011, 00:20
That did it, I changed it to set all the segment registers (except the stack segment) and it worked:

Code:
   format binary as "bin"               ; Tell FASM to make an BIN image

    ORG 0

DEBUG_MESSAGES:                         ; Comment out to remove debugging messages

BootSector:                             ; Label in order to determine size of code for
                                        ; padding at the end.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Start Boot Procedure                                                             ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Begin:                                  ; Begining of instructions

    CLI                                 ; Turn off intterrupts
    mov ax,07C0h                        ; Boot Segment
    mov gs,ax
    mov ds,ax
    mov es,ax
    mov fs,ax
    MOV [CDDriveNumber],DL              ; Save boot drive, right away

    STI                                 ; Turn interrupts back on
    


Description: See, after setting the segment register before saving the DL, I get what is expected, thanks ego. I am re-learning ASM, apparently slowly. :)
Filesize: 27.42 KB
Viewed: 6200 Time(s)

smiddyOSBoot - 3.PNG


Post 17 Nov 2011, 00:20
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 18 Nov 2011, 19:34
I just stopped in to give advice, but it seems others have already done so...

Oh well, anyway here is what i was going to post...
Code:
org 0
use16

    cli

    jmp 0x07C0:start

start:

    mov ax,cs
    mov ds,ax
    mov es,ax
;   mov fs,ax  ;check CPU type before using these...
;   mov gs,ax
    mov ss,ax
    xor sp,sp

    mov [ds:drive],dl

    sti
    

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 18 Nov 2011, 19:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.