flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Help understanding CD-ROM booting

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



Joined: 31 Oct 2004
Posts: 559
smiddy
Hi,

I'm writing a boot sector to boot from an El Torito no emulation CD-ROM. What gets returned in the DL is 0h and that doesn't appear correct, though maybe. However when I run INT 13h Function 48h I get a carry flag and the error is 1h which is listed as Invalid Command. This occurs within VirtualBox and on my PC: ASUS i7 965 @ 3.20 GHz. Any ideas?

-smiddy
Post 12 Nov 2011, 14:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17639
Location: In your JS exploiting you and your system
revolution
I couldn't find the source code in your post. It is difficult for us to help you without knowing what you have done. Wink
Post 12 Nov 2011, 15:15
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos
Maybe boot loader was written on CD/DVD incorrectly, i.e. as for floppy emulation mode.
Post 12 Nov 2011, 16:04
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
@Revolution: I will post it, it is in an ugly state...here's the beginning of the snippet:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Start Boot Procedure                                                             ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Begin:                                  ; Begining of instructions

    CLI                                 ; Turn off intterrupts
    MOV [CDDriveNumber],DL              ; Save boot drive
    mov ax,7000h
    mov gs,ax
    mov bx,530h
    mov [gs:bx],dl

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Relocation code; move code to 0x0000:0600 (Linear 00000600)                      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    XOR AX,AX                           ; Place ES and DS at same segment
    MOV SS,AX                           ; Set Stack below new location
    MOV SP,5FEh                         ; 0000:05FE
    MOV ES,AX                           ; ES = 0
    MOV DS,AX                           ; DS = 0
    MOV DI,600h                         ; DI = 600h (The new location)
    CLD                                 ; Clear direction
    MOV CX,80h                          ; Place CX = 128
    MOV SI,7C00h                        ; Offset of this code (Assume segment 0)
    REP MOVSD                           ; Copy code over with DWORDs
    JMP 60h:NewLowerLocation            ; Jump to our new location to force CS = 60h

NewLowerLocation:

    MOV AX,60h                          ; Reestablish segments (60h:0h or linear 600h
    MOV DS,AX                           ;   to 105FFh)
    MOV ES,AX
    MOV FS,AX
    MOV GS,AX

    STI                                 ; Turn interrupts back on

    MOV SI,WelcomeMessage               ; Save pointer to welcome message
    CALL PrintString                    ; Print the welcome message
    MOV SI,TheEndOfTheLine
    CALL PrintString

    MOV AL,[CDDriveNumber]
    MOV CL,8
    CALL ToHex

    MOV SI,DriveNumberReported
    CALL PrintString

    MOV SI,HexBuffer
    CALL PrintString

    MOV SI,AddTheHAtTheEnd
    CALL PrintString

    MOV SI,TheEndOfTheLine
    CALL PrintString

    MOV DL,[CDDriveNumber]              ; Prepare to read CD-ROM, load boot drive
    MOV AH,48h                          ; Use function 41h
    MOV SI,DiskResultsBuffer            ; Results buffer to load
    INT 13h                             ; Call Check Extensions Present?

    JC Failure
      


Code:
Failure:

    mov AL,AH                           ; Put the error into lowest bits
    mov cl,8                            ; only 8 bits
    call ToHex                          ; Get what is in the XX to display

    MOV SI,FailureMessage               ; reboot message
    CALL PrintString
    mov si,HexBuffer
    CALL PrintString
    MOV SI,AddTheHAtTheEnd
    CALL PrintString
    MOV SI,TheEndOfTheLine
    CALL PrintString
    mov SI,PressAnyKeyMessage
    CALL PrintString
    MOV AH,0                            ; Reboot on error
    INT 16h                             ; BIOS GetKey
    INT 19h                             ; BIOS Reboot
    


I am using the beginning of my original floppy boot code, minus all the boot sector stuff needed for FAT12. I am simply relocating the code (which I can bypass if needed), then jumping to the new sector, then doing a INT 13h Function 48h to get the Disk Parameters block, but the carry flag is set and the error code is 1 (invalid command). Sad

@egos: The iso I am creating has No Emulation identified in the Initial/Default Entry:

Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
    ;; Initial/Default Entry
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  

    db 88h                                                     ; Boot indicator
    db 0                                                       ; Media type (0 = "no emulation")
    dw 07C0h                                                   ; Load segment
    db 0                                                       ; Partition type (assumed to be unused for "no emulation")
    db 0                                                       ; Unused, must be 0
    dw (BootLoader.End - BootLoader + 511) / 512               ; Sector count (virtual 512-byte sectors)
    dd (BootLoader - CDROMImageStart) / 2048                   ; First sector number for boot loader
    times 20 db 0                                              ; Unused, must be zero

     
Post 12 Nov 2011, 17:26
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello Wink
First of all you must check the extensions present (AH 41h)
then the cdrom don't never returns the drive parameters for no emulation..
Think about it, if you don't make emulation which drive parameters (Ah 48h) can i return to you Question
CDrom parameters Question
Note that the AH 48h Get drive parameters for me work only with
real HD and USB, but with cdrom boot i don't have get nothing at all in every
pc where i test my cd bootloader Confused

_________________
Nil Volentibus Arduum Razz
Post 12 Nov 2011, 18:42
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos
smiddy, set ds before MOV [CDDriveNumber],DL

DJ Mauretto, if ISO boot loader gets control then extensions are present (though you can check this by hand for absolute guaranties). EDD returns device parameters for CD/DVD as well. It's fundamental info for detecting boot device.
Post 12 Nov 2011, 19:19
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
if ISO boot loader gets control then extensions are present

Question
NO, you can use classic bios ah 02h to get sector from cd without assume EDD is present.
BIOS ah 02h is universal and work with all drive, EDD is not always supported.
Quote:
EDD returns device parameters for CD/DVD as well

No, in all PC that i tryed no drive parameters are present, always carry set, anyway i don't tryed all pc in the world Razz
Quote:
It's fundamental info for detecting boot device.

If you make floppy emulation ah 41 check extensions is not supported at all,
Then What is your boot device ?

_________________
Nil Volentibus Arduum Razz
Post 12 Nov 2011, 19:34
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
@ DJ Mauretto: I had assumed that the CD-ROM parameters would be there. I have read conflicting information on Function 48 and Function 41. I will try 41h first.

@egos: Yeah, I wondered if I should disregard the move portion and leave all the segment registers as the should be from the Initial/Default Entry. I'll give these both a try.

Thanks folks! I'll report back in a little while, my 4 year old if needing attention. Smile
Post 12 Nov 2011, 20:16
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
BTW I just re-read this from El Torito:

Code:
When the boot image is simply a “loader” or stand alone program, and NO EMULATION is desired, the drive
numbers will be unaffected after the boot image is loaded. The specified number of sectors are loaded at the specified
segment (usually 7C0), and then the BIOS jumps to the load address. The software can retrieve a pointer to its boot
information by issuing INT 13, Function 4B, AL=1.    


I think I will try this first, since I'm trying no emulation perhaps I need to run Function 4Bh first?
Post 12 Nov 2011, 20:21
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos
DJ Mauretto wrote:
NO, you can use classic bios ah 02h to get sector from cd without assume EDD is present.
Function 2 is not used for CD/DVD. "El Torito" Spec. is based on EDD Spec. You can't boot from CD/DVD without EDD.

Quote:
No, in all PC that i tryed no drive parameters are present, always carry set, anyway i don't tryed all pc in the world Razz
My kernel detects boot device using info returned by function 48h. And it does this detection successfully (see result tables below). An error can occur only if AHCI mode is enabled in BIOS Setup.

My PC:
Code:
size: 32
part: 0
type: 0
extra: 0
bus type: PCI
interface type: ATAPI
interface: 00 1F 02 00 00 00 00 00
device: 00 00 00 00 00 00 00 00
    


My Bochs:
Code:
size: 32
part: 0
type: 0
extra: 0
bus type: ISA
interface type: ATA
interface: F0 01 00 00 00 00 00 00
device: 00 00 00 00 00 00 00 00
    


Quote:
If you make floppy emulation ah 41 check extensions is not supported at all,
Then What is your boot device ?
I use only "No emulation" mode.

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



Joined: 31 Oct 2004
Posts: 559
smiddy
So, here are the results using INT 13h Function 4B, AL=1: I get a return packet that says the CD-ROM drive is E0h, not 00h form the DL upon boot. When I use the returned CD-ROM drive number in the DL for Functions 41h and 42h, they both work with the returned drive packet. Once I clean up the code for the start I will post it. BTW, I removed all the moveable code stuff, setup the segments as 07C0h and all is well in the world. Very Happy
Post 12 Nov 2011, 23:01
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos
If so DL will hold 0E0h in entry point. Function 41h doesn't return device address packet.
Post 12 Nov 2011, 23:58
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
Function 2 is not used for CD/DVD. "El Torito" Spec. is based on EDD Spec. You can't boot from CD/DVD without EDD.

I never had any problem with Ah 02 function in every PC, but note that i don't use no emulation mode.
I have never seen the data about ATAPI drive parameters that you post Laughing
Maybe you get this data only with no emulation...
Anyway good for you Laughing

_________________
Nil Volentibus Arduum Razz
Post 13 Nov 2011, 08:18
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos
If you don't use "No emulation" mode don't speak about it.
DJ Mauretto wrote:
then the cdrom don't never returns the drive parameters for no emulation..

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



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
If you don't use "No emulation" mode don't speak about it.

Hey Young boy, i am a free person, I do not have to ask permission to talk ,
anyway please post also the drive parameters of your CDrom,
you have skipped it , post all result buffer
Razz
I did the test several years ago, and my actual boot from cd use
ah 02, somehow I have chosen this path many years ago because it was compatible with all pc.

NB:
For me drive parameters are this:
Number of physical cylinders.
Number of physical heads.
Number of physical sectors per track.
Number of physical sectors.
Number of bytes in a sector.
and so on...

Maybe for you the drive parameters are only Interface type = ATAPI Razz

_________________
Nil Volentibus Arduum Razz
Post 13 Nov 2011, 11:20
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos
DJ Mauretto wrote:
anyway please post also the drive parameters of your CDrom,
you have skipped it , post all result buffer
I had shown the structure that is built by the kernel in RM to detect boot device in PM (it is similar with parameter table returned by function 48h starting from offset 32).

Quote:
For me drive parameters are this:
Number of physical cylinders.
Number of physical heads.
...
Do you know what is CD/DVD?

Quote:
Maybe for you the drive parameters are only Interface type = ATAPI
Not only. Look at the structure attentively. And do you know what is IDENTIFY DEVICE command?

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



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
Do you know what is CD/DVD?

Laughing Laughing Laughing
Very funny
Quote:
And do you know what is IDENTIFY DEVICE command?

Laughing Laughing Laughing
You make me laughing Razz
The truth is that ah 48 for cd don't return drive parameters as i told you
Laughing

Perhaps the problem is that we mean 2 completely different things.
You want to know the device path,
I mean the drive parameters as
Number of physical cylinders.
Number of physical heads.
Number of physical sectors per track.
and so on Wink

_________________
Nil Volentibus Arduum Razz
Post 13 Nov 2011, 19:47
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
You two are killing me...Smile
Post 13 Nov 2011, 20:18
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
Ok, so I've gotten it to work and here's the fundamentals:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                                  ;;
;; Project          :   smiddyOS (CD-ROM Booter)                                    ;;
;; Author           :   smiddy                                                      ;;
;; Website          :                                                               ;;
;; Date             :   November 13, 2011                                           ;;
;; Poop             :   Bootloader, read CD-ROM, load kernel (CD_ROM VIEWER)        ;;
;; Filename         :   cdboot1.asm                                                 ;;
;; Assembler Command:   Using FASMW IDE                                             ;;
;;                                                                                  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                                  ;;
;; Useage: Using CDBOOT1.BIN as the boot loader from the created ISO from the       ;;
;;         CD-ROM creating CDROM.ASM from from within FASMW IDE.                    ;;
;;                                                                                  ;;
;;         See CDROM.ASM for further details.                                       ;;
;;                                                                                  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                                  ;;
;; v1.00a - Alpha release; CD-ROM compatible booter; learning the CD/DVD/BD boot    ;;
;;          process. Fill in the blanks and get yourself moving. I am working the   ;;
;;          rest of the code out, now that it boots.                                ;;
;;                                                                                  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

    ORG 0

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 [CDDriveNumber],DL              ; Save boot drive
    mov ax,07C0h                        ; Boot Segment
    mov gs,ax
    mov ds,ax
    mov es,ax
    mov fs,ax

    STI                                 ; Turn interrupts back on

    MOV SI,WelcomeMessage               ; Save pointer to welcome message
    CALL PrintString                    ; Print the welcome message
    MOV SI,TheEndOfTheLine
    CALL PrintString

    MOV AL,[CDDriveNumber]
    MOV CL,8
    CALL ToHex

    MOV SI,DriveNumberReported
    CALL PrintString

    MOV SI,HexBuffer
    CALL PrintString

    MOV SI,AddTheHAtTheEnd
    CALL PrintString

    MOV SI,TheEndOfTheLine
    CALL PrintString

    MOV DL,[CDDriveNumber]              ; Prepare to read CD-ROM, load boot drive
    MOV AH,4Bh                          ; Use function 4Bh
    MOV AL,1
    MOV SI,DiskResultsBuffer            ; Results buffer to load
    INT 13h                             ; Call Check Extensions Present?

    JC Failure

    MOV SI,DiskResultsBufferMessage     ; Loading this one
    CALL PrintString

    MOV SI,SizeOfPacketInBytes
    CALL PrintString

    MOV AL,[DiskResultsBuffer]
    MOV CL,8
    CALL ToHex

    MOV SI,HexBuffer
    CALL PrintString

    MOV SI,AddTheHAtTheEnd
    CALL PrintString

    MOV SI,TheEndOfTheLine
    CALL PrintString

    MOV SI,BootMediaType
    CALL PrintString

    MOV AL,[DiskResultsBuffer+1]
    MOV CL,8
    CALL ToHex

    MOV SI,HexBuffer
    CALL PrintString

    MOV SI,AddTheHAtTheEnd
    CALL PrintString

    MOV SI,TheEndOfTheLine
    CALL PrintString

    MOV SI,DriveNumberFromPacket
    CALL PrintString

    MOV AL,[DiskResultsBuffer+2]
    MOV CL,8
    CALL ToHex

    MOV SI,HexBuffer
    CALL PrintString

    MOV SI,AddTheHAtTheEnd
    CALL PrintString

    MOV SI,TheEndOfTheLine
    CALL PrintString

    MOV DL,[DiskResultsBuffer+2]
    MOV [CDDriveNumber],DL

    MOV DL,[CDDriveNumber]              ; Prepare to read CD-ROM, load boot drive
    MOV AH,41h                          ; Use function 41h
    MOV BX,55AAh                        ; Signature?
    INT 13h                             ; Call Check Extensions Present?

    JC Failure                          ; Nope, get out of here...

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; Need to save the return here:
    ;; AH = Major Version Number
    ;; BX = 0AA55h
    ;; CX = Interface support bitmask:
    ;;      1 - Device Access using packet structure (assumed by me)
    ;;      2 - Drive Locking and Ejecting
    ;;      4 - Enhanced Disk Drive Support
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    MOV AX,CX
    MOV CL,16
    CALL ToHex

    MOV SI,HexBuffer
    CALL PrintString

    MOV SI,AddTheHAtTheEnd
    CALL PrintString

    MOV SI,IsEqualToTheCX
    CALL PrintString

    MOV SI,MessageReadTheDrive
    call PrintString

    MOV DL,[CDDriveNumber]              ; Set it up again
    MOV AH,42h                          ; Read from drive function
    MOV SI,DiskAddressPacket            ; Load SI with address of the Disk Address
                                        ;    Packet
    INT 13h                             ; Call read sector from drive

    JC Failure                          ; Nope, hosed, get out

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; Need to read sector information for the boot directory.
    ;; The Disk Address Packet starts with:
    ;; db 10h - Initial Volume Descriptor, which has the important data we need
    ;;          to get to the root directory where our OS is stored.
    ;; db  0  - Unused, should be zero
    ;; dw  1  - Number of sectors to read (initial one should be one)
    ;; dd 1000:0000 - Initial segment:offset where to load the read in sector(S)
    ;; dq 16  - Starting sector to read in, then we need to get to the root directory
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    MOV ES,[DiskAddressPacket.Segment]
    MOV DI,[DiskAddressPacket.Offset]

    MOV EAX,[ES:DI+158]                 ; LBA of root directory, where all things start.
    MOV CL,32
    CALL ToHex

    MOV SI,HexBuffer
    CALL PrintString

    MOV SI,AddTheHAtTheEnd
    CALL PrintString

    MOV SI,IsEqualToTheEAX
    CALL PrintString

    MOV SI,MessageReadTheDrive
    call PrintString


Failure:

    mov AL,AH                           ; Put the error into lowest bits
    mov cl,8                            ; only 8 bits
    call ToHex                          ; Get what is in the XX to display

    MOV SI,FailureMessage               ; reboot message
    CALL PrintString
    mov si,HexBuffer
    CALL PrintString
    MOV SI,AddTheHAtTheEnd
    CALL PrintString
    MOV SI,TheEndOfTheLine
    CALL PrintString
    mov SI,PressAnyKeyMessage
    CALL PrintString
    MOV AH,0                            ; Reboot on error
    INT 16h                             ; BIOS GetKey
    INT 19h                             ; BIOS Reboot



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PrintString                                                                      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

PrintString:

    PUSHA                               ; Save Registers

.Loop:

    LODSB                               ; Load SI into AL, increment SI one byte
    OR AL,AL                            ; AL = 0?
    JZ .Done                            ; If yes, get out
    MOV AH,0Eh
    MOV BH,0
    MOV BL,7                            ; character attribute
    INT 10h                             ; Display character in AL
    JMP .Loop                           ; Do it again

.Done:

    POPA                                ; Replace registers

    RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PrintMyDot - Increments through the numbers in order to see the number of        ;;
;;              sectors that have been loaded.                                      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

PrintMyDot:

    mov ah,0Eh
    mov al,[BootDotNumber]
    int 10h
    inc al
    cmp al,58
    jb  .PDExit
    mov al,'0'

.PDExit:

    mov [BootDotNumber],al

    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ToHex
;; Loads HexBuffer with ASCII corresponding to 8, 16, or 32 bit interger in
;;    hex.
;; Requires interger in AL, AX, or EAX depending on bit size
;; Requires the number of bits in the CL
;; Returns a full buffer or an empty buffer on error
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ToHex:

        pusha

    MOV BX,0x0000               ; Load BX with pointer offset
    MOV [TheEAX],EAX            ; Save the EAX
    MOV [TheCL],CL              ; Save the CL 
    CMP CL,0x08                 ; Check for 8 bits
    JNE .Check16
    JMP .Loop1                  ; Start loading the buffer

.Check16:

    CMP CL,0x10                 ; Check for 16 bits
    JNE .Check32
    JMP .Loop1                  ; Start loading the buffer

.Check32:

    CMP CL,0x20                 ; Check for 32 bits
    JNE .ErrorBits

.Loop1:

    MOV EAX,[TheEAX]            ; Reload EAX with the converter
    SUB CL,0x04                 ; Lower bit count by 4 bits
    SHR EAX,CL

    AND AL,0x0F
    ADD AL,'0'
    CMP AL,'9'
    JBE .LoadBuff1
    ADD AL,'A'-'0'-10           ; Convert to "A" to "F"

    JMP .LoadBuff1

.Loop2:
    MOV EAX,[TheEAX]            ; Reload EAX again
    SUB CL,4                    ; Lower bit count by 8 bits
    SHR EAX,CL
    AND AL,0x0F
    ADD AL,'0'
    CMP AL,'9'
    JBE .LoadBuff2
    ADD AL,'A'-'0'-10           ; Convert A,B,C,D,E,F

    JMP .LoadBuff2

.LoadBuff1:

    MOV [HexBuffer+BX],AL       ; Load buffer with AL
    INC BX                      ; Increment buffer pointer
    JMP .Loop2                  ; Do next byte

.LoadBuff2:

    MOV [HexBuffer+BX],AL       ; Load buffer with AL
    INC BX                      ; Increment buffer pointer
    CMP CL,0x00                 ; Check if we're done
    JNE .Loop1                  ; Do next Byte 

.ErrorBits:

    MOV AL,0x00
    MOV [HexBuffer+BX],AL       ; End the string with a zero
    
    popa

    RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Program Data                                                                     ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DataSector:               DW 0
CDDriveNumber:            db 0

absoluteSector:           DB 0
absoluteHead:             DB 0
absoluteTrack:            DB 0

BootDotNumber:            DB '1'

Cluster:                  DW 0
FileName:                 DB 'SMIDDYOS.SYS'                ; FAT Filename, 8.3, or 11 characters

DiskResultsBufferMessage: db 'Disk Buffer on in here...',13,10,0
IsEqualToTheCX            db ' = CX contents from INT 13h Function 41h.',13,10,0
IsEqualToTheEAX           db ' = EAX contents is the sector of the root directory contents.',13,10,0
WelcomeMessage:           DB 'smiddy OS CD boot v1.00a',13,10,0   ; Saving space.
MessageReadTheDrive:      db 'Read the Drive, free and clear, make it hap',"'",'n cap',"'",'n!',13,10,0
FailureMessage:           db 'Failure: ',0
DriveNumberReported:      db 'Drive number reported: ',0
PressAnyKeyMessage:       db 'Press any key to reboot...',13,10,0
AddTheHAtTheEnd:          db 'h',0
TheEndOfTheLine:          db 13,10,0                        ; Used to print the end of the line string
SizeOfPacketInBytes:      db 'The size of packet in bytes: ',0
BootMediaType:            db 'The boot media type: ',0
DriveNumberFromPacket:    db 'Drive number from packet: ',0


DiskAddressPacket:        db 16,0
                          dw 1
.Offset:                  dw 0                                ; Offset :0000
.Segment:                 dw 1000h                            ; Segment 1000:
.End:                     dq 16                               ; Sector 16 or 10h on CD-ROM

DiskResultsBuffer: times 30 db 0                              ; Return buffer from int 13h ah=48h
HexBuffer:                  DB 0,0,0,0,0,0,0,0,0              ; Buffer for hex text string
TheEAX:                     dd 0                              ; Saves EAX
TheCL:                      db 0



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 512 Byte Code Boot Signature                                                     ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TIMES 2046-($-BootSector)   DB 0
                            DW 0AA55h           ; Bootloading sector signature (for CD/DVD/BD)    


This works on VirtualBox, Virtual PC, but not on VM Ware 8.0 or my main PC, and a Dell XPS One. It does work on Legacy PCs that I have. I need to figure out why it doesn't on the others. I am guessing it needs UDF and a bootable version at that, which I will research next.

I should have the CDFS from this legacy CD-ROM style setup in the next week or so, so I can sort thru directories and load files.

Enjoy!
Post 14 Nov 2011, 04:22
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Thanks for sharing your code.
I will try it on a few machines and report results...
Post 14 Nov 2011, 19:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.