flat assembler
Message board for the users of flat assembler.

Index > OS Construction > ATAPI Read Help

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



Joined: 31 Oct 2004
Posts: 557
smiddy 26 Nov 2015, 15:59
Greetings All,

I'm stuck. I am providing a code fragment for you perusal to see if, where I'm going wrong. If I allow for the interrupt to happen, it fails even if I add 5 seconds to the delay time. I am leveraging the ATAPI C code fragment from http://wiki.osdev.org/ATAPI for the following code:

Code:
.IDEBootDrive:

    ; Leads into loading VENDORS.TXT from CD-ROM, like the floppy interface above
    cmp word [BootDrive.IOPort],0      ; Check for zero in the port address, from BootDrive.ASM [INT 13h AH=48h from EDD]
    je .AHCIBootDrive                  ; If so, go to AHCI drive interface

    ; Need to determine is ATA or ATAPI, assumes ATAPI for now

    ; Read IDE drive information, then get VENDORS.TXT
    mov esi,IDEPortMessage             ; Load IDE Port Message into ESI
    call PrintString32                 ; Print ESI to the screen
    movzx eax,word [BootDrive.IOPort]  ; Place boot drive's IO Port into EAX, from BootDrive.ASM [INT 13h AH=48h from EDD]
    mov cl,16                          ; Setup to display only 16 bits
    call ToHex32                       ; Convert EAX to Hex Text
    mov esi,HexBuffer32                ; Load ESI with Hexed EAX Text
    call PrintString32                 ; Print ESI to the screen

    mov esi,TheEndOfLine
    call PrintString32                 ; Print ESI to the screen

    mov esi,IDEIRQMessage              ; Load ESI with IDE IRQ Message
    call PrintString32                 ; Print ESI to the screen
    movzx eax,byte [BootDrive.IRQ]     ; Place boot drive's IRQ number into EAX, from BootDrive.ASM [INT 13h AH=48h from EDD]
    mov cl,8                           ; Setup to display only 8 bits
    call ToHex32
    mov esi,HexBuffer32
    call PrintString32                 ; Print ESI to the screen

    mov esi,TheEndOfLine
    call PrintString32                 ; Print ESI to the screen

    cli                                ; Stop interrupts
    call DisableAllIRQs                ; Disable all IRQs
    mov esi,IDEISR                     ; IDEISR address into ESI
    movzx eax,byte [BootDrive.IRQ]     ; IRQ number to assign the IDE to, from BootDrive.ASM [INT 13h AH=48h from EDD]
    call AddISRToIDT                   ; Set this IRQ/ISR
    sti                                ; Restart interrupts

    movzx eax,byte [BootDrive.IRQ]     ; IRQ for BootDrive into EAX, from BootDrive.ASM [INT 13h AH=48h from EDD]
    call EnableAnIRQ                   ; Set this IRQ to ON

    mov esi,BootDriveNumberMessage     ; Load ESI with Boot Drive Number Message
    call PrintString32                 ; Print ESI to the screen

    movzx eax,byte [BootDrive.DeviceNumber] ; Load EAX with boot drive's device number, from BootDrive.ASM [INT 13h AH=48h from EDD]
;    shl al,4                           ; Shift 4 bits left [not needed, done in
    mov [Drive32],al                   ; Update variable with unshifted drive number

    mov cl,8                           ; Setup to display 8 bits
    call ToHex32
    mov esi,HexBuffer32
    call PrintString32

    mov esi,TheEndOfLine
    call PrintString32

    mov dword [SectorSize32],2048      ; Setup CD-ROM sector size (hard setting for now)
    mov [StartingSector32],16          ; Setup variable with Primary Volume Descriptor sector
    mov [NumberOfSectors32],1          ; Setup variable with to read in one sector
    mov edi,ATAPIBootSectorData        ; Load EDI with read in destination (will make this dynamic later)
    call IDEATAPIRead                  ; Go read the CD-ROM

    ; Check address 3 and address 2 for size?

    mov eax,dword [ATAPIBootSectorData+158] ; Get the root director sector location (offset 156 should be 34 for the length in bytes of the root directory entry)
; DEBUG ------------------;

    mov esi,StartingCDROMDirectoryMessage ; Load ESI with starting sector of CD-ROM directory entry
    call PrintString32                 ; Print ESI to the screen
    mov cl,32                          ; Setup for 32 bits
    call ToDecimal32                   ; Convert to decimal text
    mov esi,DecimalBuffer32            ; Load ESI with the decimal text buffer
    call PrintString32                 ; Print ESI to the screen
    mov esi,TheEndOfLine               ; Load 13,10,0 into ESI
    call PrintString32                 ; Print ESI to the screen

; DEBUG ------------------;

    jmp .Done                          ; Finito

.AHCIBootDrive:

    mov esi,AHCIDriveLookMessage
    call PrintString32
    jmp .Done                          ; Print ESI to the screen

.Done:

    ret

ATAPIBootSectorData: TIMES 2048 db 0  ; Buffer for reading a sector from the CD-ROM
StartingCDROMDirectoryMessage   db 'Root directory starting sector: ',0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; IDEATAPIPacket - This routine sends a packet to ATAPI device. Originally
;;                  written by Craig Bamford(ASHLEY4 ala Dex4U) over at
;;                  flatassembler. Adjusted for use here.
;;
;; Assumes: ESI = pointer 12 byte packet to be sent
;;          [Port32] = base port of the device
;;          [Drive32] = drive number to use
;;
;; ToDo - buffering for read and (potentially) write operations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

IDEATAPIPacket:

    xor edx,edx
    mov ebx,0ffffh
    mov ecx,ebx
    mov dx,[Port32]                    ; Base Port
    add dx,7                           ; Read Status = 7 + the base = ex. if base port is 170h then 177h

.StatusReg1_1:

    in al,dx                           ; Mov data from port to al
    and al,80h                         ; Check bit 7(busy bit) ,loop if not 0
    jz .WriteCommand1_1                ; Jump to WriteCommand1_1 if al bit7 =0
    loop .StatusReg1_1                 ; If al bit 7 = 1, loop StatusReg1_1

    ret                                ; If CX = 0, return to caller

.WriteCommand1_1:

    dec edx                            ; (ala 176h)
;    xor eax,eax                        ; Bit 4 ,0 to select primary drive, 1 to select secondary drive
    mov al,[Drive32]                   ; Place drive number into AL
    shl al,4                           ; Mov it to the left 4 bits (0 = 0; 1 = 10h after), from BootDrive.ASM [INT 13h AH=48h from EDD Device Number]
    out dx,al                          ; Write AL to port (register)
    mov ecx,ebx                        ; Mov cx, number of loops(bx=0xffff)
    inc edx                            ; Back to status port

.StatusReg2_1:

    in al,dx                           ; Mov data from port to al
    and al,80h                         ; Check bit 7(busy bit) ,loop if not 0
    jz .WriteCommand2_1                ; Jump to WriteCommand2_1 if al bit7 =0
    loop .StatusReg2_1                 ; If al bit 7 =1,loop StatusReg2_1

.DeviceBusy_1:                         ; time out Sad

    ret

 ;----------------------------------------------------;
 ; Write Command                                      ;
 ;----------------------------------------------------;

.WriteCommand2_1:

    mov al,0A0h                        ; Add the 8 bit code to al (Packet command)
    out dx,al                          ; Write al to port (register)
    mov ecx,ebx                        ; Mov cx, number of loops(bx=0xffff)

.StatusReg3_1:

    in al,dx                           ; Mov data from port to al
    test al,80h                        ; Does bit 7 = 0 (busy bit)
    jnz .DrqErrorCheck1_1              ; Jump to "DrqErrorCheck1_1" if bit7 is 1
    test al,8                          ; Does bit3 = 0 (DRQ bit)
    jnz .WriteCommandPacket1_1         ; Jump to label if bit3 is 1,we can transfer data to port:-)

.DrqErrorCheck1_1:

    loop .StatusReg3_1                 ; Loop label

    ret

 ;----------------------------------------------------;
 ; Write Command Packet                               ;
 ;----------------------------------------------------;

.WriteCommandPacket1_1:

    mov dx,[Port32]                    ; Read date/write = 0
    mov cx,6                           ; Mov number of words to mov into cx (12 byte command packet)

.WritePacket1_1:

    lodsw                              ; Mov a word from packet to ax, inc esi 2
    out dx,ax                          ; Write ax to port (register)
    loop .WritePacket1_1               ; Loop label

    mov ecx,ebx                        ; Mov cx, number of loops
    add dx,7                           ; Read Status = 7 + the base = 177h

.StatusReg4_1:

    in al,dx                           ; Mov data from port to al
    test al,80h                        ; Does bit 7 = 0 (busy bit)
    jnz .DrqErrorCheck2_1              ; Jump to "DrqErrorCheck2_1" if bit7 is 1

    ret

 ;----------------------------------------------------;
 ; Drq Error Check                                    ;
 ;----------------------------------------------------;

.DrqErrorCheck2_1:

    push ecx                           ; Save old cx
    mov ecx,ebx                        ; Mov cx, number of loops(bx=0xffff)

.BusyDelay_1:                          ; Label

    nop                                ; Do a null operation(xchg ax,ax)
    nop                                ; Do a null operation(xchg ax,ax)
    nop                                ; Do a null operation(xchg ax,ax)
    nop                                ; Do a null operation(xchg ax,ax)
    loop .BusyDelay_1                  ; Loop label

    pop ecx                            ; Get old cx

    loop .StatusReg4_1                 ; Loop label

.error_1:

    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; IDEATAPIRead - This routine reads ATAPI device sector(s) and fills memory.
;;
;; Assumes: ESI = pointer 12 byte packet to be sent
;;          [Port32] = base port of the device
;;          [Drive32] = drive number to use (already 4 bit moved)
;;          [SectorSize32] = the size of the sector to use
;;          [StartingSector32] = Starting sector number to read
;;          [NumberOfSectors32] = Number of sectors to read
;;          EDI = location where to store data
;;
;; +--------+-----+-----+-----+-----+-----+-----+-----+------+
;; | bit -> |     |     |     |     |     |     |     |      |
;; | | byte |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0   |
;; | v      |     |     |     |     |     |     |     |      |
;; +--------+-----+-----+-----+-----+-----+-----+-----+------+
;; |    0   |      Operation Code = 0A8h (Read)              |
;; +--------+------------------------------------------------+
;; |    1   |                                                |
;; +--------+------------------------------------------------+
;; |    2   |               LBA (32 bit) [MSB]               | LBA = Logical Block Address (from 1 to x, where x = 2^32 - 1)
;; +--------+                                                |
;; |    3   |                                                |
;; +--------+                                                |
;; |    4   |                                                |
;; +--------+                                                |
;; |    5   |               LBA (32 bit) [LSB]               |
;; +--------+------------------------------------------------+
;; |    6   |                 Reserved                       |
;; +--------+------------------------------------------------+
;; |    7   |                 Reserved                       |
;; +--------+------------------------------------------------+
;; |    8   |       Number of Sectors to read (1)            |
;; +--------+------------------------------------------------+
;; |    9   |                                                |
;; +--------+------------------------------------------------+
;; |   10   |                 Reserved*                      |
;; +--------+------------------------------------------------+
;; |   11   |                 Reserved*                      |
;; +--------+------------------------------------------------+
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ReadPacket db 0A8h, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Used below, see table above

IDEATAPIRead:

;;DEBUG:
    mov eax,0                          ; Setup EAX with 0
    mov al,byte [SectorSize32+1]       ; Load LSB of Sector Size wanting to be read
    mov ah,al                          ; Mov AL to AH
    mov al,byte [SectorSize32]         ; Load MSB of Sector Size
    mov cl,32                          ; Setup to read 32 bits from EAX
    call ToDecimal32                   ; Convert EAX to decimal text
    mov esi,DecimalBuffer32            ; Load ESI with decimal text
    call PrintString32                 ; Print ESI to the display
    mov esi,TheEndOfLine               ; Load ESI with 13,10,0
    call PrintString32                 ; Print ESI to the display
;;DEBUG:

    ; Need to examine this one...
    mov dx,[Port32]                    ; Get base port
    add dx,6                           ; Convert port number to drive select port
    mov al,[Drive32]                   ; Get drive number
    shl al,4                           ; Shift bits 4 left (for ATA/ATAPI interface) from BootDrive.ASM [INT 13h AH=48h from EDD]
    out dx,al                          ; Send selection

    mov ecx,10                         ; 100 = 1 second (0.1 seconds: > 400 ns requirement)
    call ActiveDelay                   ; In CLOCK.ASM

    sub dx,5                           ; Convert port number to features port
    mov al,0                           ; PIO feature
    out dx,al                          ; Send PIO to controller
    mov al,byte [SectorSize32+1]       ; Grab LSB of the sector size
    add dx,3                           ; Make port Address #2
    out dx,al
    inc dx                             ; Make port Address #3
    mov al,byte [SectorSize32]         ; Grab MSB of the sector size
    out dx,al                          ; Send it to the port (controller)

    mov eax,[StartingSector32]         ; Get Starting Sector
    mov byte [ReadPacket+2],ah         ; Save each byte of starting sector (MSB)
    mov byte [ReadPacket+3],al
    shr eax,16
    mov byte [ReadPacket+4],ah
    mov byte [ReadPacket+5],al         ; Save LSB

    mov al,[NumberOfSectors32]         ; Get number of sectors to read in
    mov [ReadPacket+8],al

    call IDEATAPIPacket                ; Call send an APAPI packet
    call WaitForIDEInterrupt           ; Wait for a IDE interrupt
;    jc .Error                          ; timeout? (this times out every time now, and I don't know why)

    ; Read two words from the data registers
    mov dx,[Port32]                    ; Load DX with the base port address
    add dx,5                           ; Make Address #3
    in ax,dx                           ; Get least significant word
    mov bx,ax                          ; Save into BX
    shl ebx,16                         ; Move 16 bits up
    dec dx                             ; Make Address #2
    in ax,dx                           ; Get most significant word
    mov bx,ax                          ; Save into BX, now EBX holds actual size read

    ; Now compare sizes, error if unequal (weird results)

;; DEBUG:

    push eax
    push ebx
    push ecx

    mov eax,ebx                        ; Display size of the return value
    mov cl,32
    call ToDecimal32
    mov esi,DecimalBuffer32
    call PrintString32
    mov esi,TheEndOfLine
    call PrintString32

    pop ecx
    pop ebx
    pop eax

;; DEBUG:

;    push edx
;    mov edx,0
;    movzx eax,word [SectorSize32]      ; 2048 bytes to read (1024 into ECX)
;    mov ebx,2
;    div ebx
;    mov ecx,eax
;    pop edx
    mov ecx,1024                       ; Force size for now...
;    mov edi,ParametersBuffer32         ; Save to ParametersBuffer (placed into EDI by caller)
    push es                            ; Save ES (flat memory space 0 - 0FFFFFFFFh in 32 bits)
    push ds                            ; Save DS (EXE loaded memory space; offset from 16-bit loading, for variables in code)
    pop es                             ; Set DS to loaded segment
    push edi                           ; Save destination memory location

.ReadDataRegister1:

    in ax,dx                           ; Get a word from the port
    stosw                              ; Store word from AX to DI and increment DI by 2
    loop .ReadDataRegister1            ; Loop until done

    pop edi                            ; Restore DI
    pop es                             ; Restore ES back to flat memory model
    jmp .Done                          ; Get out of here, we're done

.Error:

    mov esi,IDEIOErrorMessage32        ; Load IO Error Message into ESI
    call PrintString32                 ; Print ESI to the screen
    mov esi,TheEndOfLine               ; Load 13,10,0 into ESI
    call PrintString32                 ; Print ESI to the screen

.Done:

    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; IDEISR - IRQ or ISR for IDE drives                                       ;;
;;                                                                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

IDEISR:

    push eax

    mov [IDEInterruptDone],1           ; Update to true
    mov al,20h                         ; Tell PIC we're done (will need to make specific)
    out 20h,al
    out 0A0h,al

    pop eax

    iret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; WaitForIDEInterrupt - Waits for the interrupt to happen.                 ;;
;;                                                                          ;;
;; Out: CF = 1 if timeout                                                   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

WaitForIDEInterrupt:

    push eax                           ; Save used registers
    push ecx

    mov ecx,300                        ; 100 = 1 second (3 seconds)
    call ActiveDelay                   ; In CLOCK.ASM

.Loop1:

    cmp dword [ecx],0                  ; Is timeup?
    je .Error                          ; Yep, we errored, bummer.
    mov ax,[IDEInterruptDone]          ; If not we check for INT
    or ax,ax                           ; Did we interrupt?
    jz .Loop1                          ; No, then loop some more

    clc                                ; Clear the CF
    jmp .Done                          ; Head out...

.Error:

    stc
                                       ; Force CF
.Done:

    pop ecx                            ; Restore used registers
    pop eax

    ret

    


I am also uploading two different views. One from Bochs and one from VirtualBox. On my PC I get the same results as Bochs.

Any help will be appreciated, thanks!


Description: VirtualBox's output, note that the number of bytes requested and the number of bytes read are close, but not accurate.
Filesize: 12.08 KB
Viewed: 21459 Time(s)

VirtualBox_SmiddyOS_26_11_2015_09_39_04.png


Description: Boch's output, note that the number of bytes requested and the number of bytes read are not even close.
Filesize: 26.5 KB
Viewed: 21459 Time(s)

Bochs_11_26_2015_SmiddyOS.png


Post 26 Nov 2015, 15:59
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72 01 Dec 2015, 23:20
That is very interesting....

Even stranger than the error itself, you get different result in Bochs than in VBox. That, and I'm not sure how your code managed to read 4,294,967,925 on a request for 2048. Have you tried this on actual hardware? It could be a problem with Vbox, I have sometimes seen things like this happen due to simulation bugs.
***Edit: If it was an emu bug, then why would it cause issues in Bochs too?

Also, what is your drive configuration in both emulators? It is possible in Vbox that you have a SATA device instead of IDE, it does that in newer releases for "Other" OSes and I almost always forget to change the drive configuration.

***Another edit: I myself haven't done ATAPI controller code myself, so if it is an issue there, I won't really be able to help.
Post 01 Dec 2015, 23:20
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 02 Dec 2015, 01:09
Thanks taking a look. I'll tackle your questions in sequential order:

1) I have tried it on actual hardware. The configuration there is kind of different than these two emulators. But they should, in theory, work the very same. (the read function looks at two words from the I/O port, I'm assuming since something is wrong, it fills them with 0FFFFFFFFh, ala 4,294,967,295 bytes). I do assume that due to their respective settings for the drives and controllers, that may be a part of the anomaly.

2) VirtualBox: Primary IDE controller: Master = my OS iso image (no other HDDs or CD/DVDs). Bochs: ata0-master: type=disk, mode=flat, path="D:\1G-3Copy.img"
ata0-slave: type=cdrom, path="D:\SmiddyOS\OS\booting\iso9660smiddy.iso", status=inserted
ata1-master: type=disk, mode=flat, path="D:\1G-1.img"
ata1-slave: type=disk, mode=flat, path="D:\1G-2Copy.img". I have swapped the drives around, and placed the ISO on a tertiary (non-PCI based controller) and received the same things.

3) I will be working on AHCI, SATA, USB, and SAS interfaces in the future. I do have it configured for the IDE interface (double check the port I/O being announced, also, ambiguous in this display for DEBUG only, the interface number indicates ISA/IDE. This comes from BIOS on boot up INT 13h AH=48h from the EDD).

The fact that you haven't done so doesn't mean you can't be helpful. That is part of the learning process in my mind. Plus you'll get to experience my pitfalls and perhaps avoid them on your own attempts.

I have done some changes to the code and did get some different results (see attachments).

Note that now I have three different results from three different emulators. Hyper-V doesn't even allow the packet to be sent to the controller with the information to read. VirtualBox I can at least read the base sector (sector 16) of the CD now, but subsequent reads fail. With Bochs I'm able to read the boot sector (Primary Volume Descriptor) and discern the information there and read the root directory from the CD-ROM.

My next step probably tomorrow, is to try to read in the file, one sector at a time for now, based on the root directory information (what is displayed there is the filename, the size in bytes, and the beginning sector in LBA where it is located on the CD-ROM.

Secondary NOTE: none of these does the IRQ fire, I'm bypassing that for the moment.

I am looking on and off at using the bus master DMA since it seems I can get 64k chunks of data at a time, but it requires the IRQ to fire.


Description: Bochs seems promising, note that I'm reading the root directory structure.
Filesize: 25.65 KB
Viewed: 21429 Time(s)

Bochs_12_1_2015_SmiddyOS.png


Description: I'm not certain what is happening here, only that I am currently not sending the ATAPI package. This one resembles what transpires on my real hardware.
Filesize: 12.05 KB
Viewed: 21429 Time(s)

Hyper-V_12_1_2015_SmiddyOS.png


Description: This one only allows for one ATAPI package to work.
Filesize: 10.8 KB
Viewed: 21429 Time(s)

VirtualBox_SmiddyOS_01_12_2015_19_00_33.png


Post 02 Dec 2015, 01:09
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72 02 Dec 2015, 01:19
Hmm, do you have any source code or images i can use for testing of my own? I can try to help to the extent of my knowledge and am willing to learn more if I have to (that's why we have Google!).

***Edit: Does the BIOS put E0 int DL for the boot drive for all cases?
Post 02 Dec 2015, 01:19
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 02 Dec 2015, 03:13
Attached are the ISO (CD-ROM) image and a floppy image. It is certainly not ready for prime time...

Well, scratch that, I tried to upload the iso and vfd, but both file extensions are not allowed.
Post 02 Dec 2015, 03:13
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 02 Dec 2015, 03:16
nkeck72 wrote:
Hmm, do you have any source code or images i can use for testing of my own? I can try to help to the extent of my knowledge and am willing to learn more if I have to (that's why we have Google!).

***Edit: Does the BIOS put E0 int DL for the boot drive for all cases?


No, on Hyper-V it is EF for the CD-ROM. My PC it is F0.
Post 02 Dec 2015, 03:16
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72 02 Dec 2015, 03:20
Could you perhaps post a link to the source, I can compile and test from there.
Post 02 Dec 2015, 03:20
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 02 Dec 2015, 12:04
No, it isn't ready. I will post it once I've completed version 1.0.0, which will not be for a long time, since it is taking me forever to work it.

I will zip those two image files up though, when I get home from work. I seem to recall zip files where acceptable file extensions.
Post 02 Dec 2015, 12:04
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 03 Dec 2015, 02:47
Let's see if a zip file works:


Description: Contains a CD-ROM ISO image and a FLOPPY image file. One boots form the CD drive and the other a floppy drive.
Download
Filename: SmiddyOS.zip
Filesize: 308.67 KB
Downloaded: 707 Time(s)

Post 03 Dec 2015, 02:47
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72 05 Dec 2015, 18:18
Very strange, I also must point out that I personally do not see in your code where this might screw up... And when I used the floppy image the bootloader mysteriously prints a repeating "1234567890" string before the Smiddy OS message. Other than that, the floppy image seems to boot up fine and proceeds to load VENDORS.TXT. Until that point I do not see the OS load an IDE driver, so I think you have every right to assume that there is something wrong with the ATAPI packet. I have not yet figured out what, but it does look awful suspicious...

I must ask, in the routine when you are trying to create the ATAPI packet, do you mean to read LBA 0?

Code:
ReadPacket db 0A8h, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Used below, see table above 
    


This may be causing problems, seeing as you are reading the bootloader. Note also that you are setting the drive to read 0 sectors, and that might be why the CD won't get read.
Post 05 Dec 2015, 18:18
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 05 Dec 2015, 20:30
Smile

The floppy loader I have displaying repeating numbers, sequentially (80 across the screen or 80 sectors, so I know which sectors it load through) to show it is working.

I am working towards getting the IDE interface (HDD and CD-ROMs; CD-ROMs first) to load VENDORS.TXT file. Incidentally, is a database downloaded, and can be updated from, PCIDatabase.com. It interfaces or is used with the PCI routine, which is scanned to display what hardware is installed on the system it is running on.

ATAPI packet variable ReadPacket is updated on the fly with the sector number to read, and the number of sectors to read. Initially for a CD-ROM it reads sector 16. NOTE: CD-ROM sectors are 2,048 bytes in size. It then reads the contents of sector 16 (Primary Volume Descriptor, see ISO-9660) to determine where the boot directory is located, then updates teh packet variable again with the directory's (starting) sector, and reads in the first sector (for now, will be dynamic later). then I display the contents of the first five director entries (will again, be dynamic later).

When I get back from running (5 miles of trail, love me some trail), I will update it to do a similar thing to loading of VENDORS.TXT from the CD-ROM since it appears Bochs seems to work, one sector at a time like the floppy.

In the mean time, I have read up on the IDE controller some more. As it turns out, these controllers are all DMA boot mastering controller. That means I can setup a 64k memory area to have the controller download disc data to the memory area in 64k junks, so I will work that too.

I still don't understand why it doesn't do an interrupt. NOTE: like the floppy, I set it up the very same way, so I'm at a loss as to why at the moment.

I still don't understand why on my real machine and the Hyper-V emulator that it times out trying to send the read packet variable. The similarity between those two is that they are actually PCI interface controllers, versus the other are using ISA. There is likely something to that, and perhaps I'm force to use DMA transfers instead of PIO, which is what I'm trying to use, although it is interesting that it seems to call for an interrupt. So I need to understand that too.

Thanks for trying it out.

Did you try any of the the other commands? (Type HELP)

Smiddy
Post 05 Dec 2015, 20:30
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72 06 Dec 2015, 02:14
Yes I also tried a few commands, and all the ones I tried seem to be fully functional. Is it normal for me to boot from the floppy and it tell me "[No Drive]:\>"? All the commands work, but it does not appear to show me the current (logged) drive.

It could be that the PCI systems and ISA systems differ in the use of PIO/DMA, I would experiment with that and see if you can implement a fix by detecting which type of controller there is present on the system.

Also, you may want to double check this -- x86 processors are little endian devices, which means the words are byte-swapped when you load them into the registers. It's just a guess, but perhaps you meant to load up the packet as they are listed in order in RAM, but forget that you are loading the packet as 6 words and not 12 bytes. More than once I have done that in my own OS. Embarassed

_________________
It may look hard, but it won't take long if you take it one byte at a time.

NOS: www.github.com/nkeck720/nos
Post 06 Dec 2015, 02:14
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 06 Dec 2015, 13:49
I don't have the drive information setup yet, which is why it says [No Drive]. I'm not sure about my convention yet, but was thinking of using numbers, 1 to n, where n is the last drive found in sequence, the boot drive of course being 1. I will implement that once I get it to boot from HDD, as then I will have all the boot types completed.

Yeah, I suspect there is something to the PCI versus ISA thing.

Yep, I have rechecked the Endian-ness, that's all good. Also the packet load is all good (works on Bochs). I should get the opportunity to work it today and load the file on Bochs. Once I do I'll post the resulting iso/floppy image.
Post 06 Dec 2015, 13:49
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 07 Dec 2015, 12:24
Well, I got VENDORS.TXT to load within Bochs, however I uncovered a pointer problem with the PCI routine. So time to fix that before moving on...
Post 07 Dec 2015, 12:24
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72 07 Dec 2015, 21:01
I thought it might be something PCI/ISA related. Send an ISO once you get that fixed!

Also, do you happen to have a Git repo set up or a GitHub or (dare I say it) SourceForge page for this?

_________________
It may look hard, but it won't take long if you take it one byte at a time.

NOS: www.github.com/nkeck720/nos
Post 07 Dec 2015, 21:01
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 08 Dec 2015, 12:32
Nope, I'm not using an online repository. I may once it is at the 1.0.0 stage.

I solved the PCI routine issue with the pointer (this routine shows the installed devices; it uses VENDORS.TXT to display that information). I'll zip up the ISO and FLOPPY images after work today, then put them on here.

So, my problem still is:

- No interrupt firing
- ATAPI read doesn't work on VirtualBox after first read
-- I am assuming this is related to the interrupts not firing and general cleanup of that since the first read works (reading the boot directory or Primary Volume Descriptor)
- Time out trying to send ATAPI packet on Hyper-V and real PC
-- Both are PCI bus interfaces instead of so may have to use DMA transfer

ToDo:

- Study Bus Mastering ATAPI read, and implement that if available
- Study up on IDE interrupt usage, implement usage

I am going to work on saving the IDE drive information for retrieval now, rather than work the above first, then I will get back to trying to make it work with the other virtual machines and my PC. It working in Bochs is enough for now.

After I get this working, then I'll start on AHCI. Oh, and IDE HDDs before AHCI...
Post 08 Dec 2015, 12:32
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 08 Dec 2015, 19:32
On VBox I noticed:
Quote:
00:00:10.259038 Guest Log: BIOS: int13_cdrom: unsupported AH=08
The patterns of reads:
Quote:
Offset Length
34816 2048
38916 2048
40960 2048
32768 2048
47104 2048
49152 65536
114688 45056
32768 131072
Not sure this matches what you described - first sector looks to be 17?

The code I have for this doesn't wait for IRQ and just polls the status but everything else looks like same values and IO...
Post 08 Dec 2015, 19:32
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 08 Dec 2015, 20:16
Thanks cod3b453!

I forget to look at those screens.

The first sector should be 16, and it is reading it. However, the second read fails to load the directory sector, which it does when I use Bochs. Everything I've read so far says that I should wait for an interrupt after a read, but none of the emulators nor my PC do an interrupt within 3 seconds (I've upped that to 10 too on the delay).

I'll give it a quick look again tonight, but I have less time tonight.
Post 08 Dec 2015, 20:16
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 08 Dec 2015, 22:14
Here's the latest build. Note the screen shots from Bochs.


Description: This shows that the data is actually being used to determine the installed PCI devices.
Filesize: 25.26 KB
Viewed: 21304 Time(s)

Bochs_12_8_2015_PCI_Function.png


Description: CD-ROM Loaded fine with ATAPI driver.
Filesize: 24.57 KB
Viewed: 21304 Time(s)

Bochs_12_8_2015_VENDORS_TXT_Loaded.png


Description: ISO and FLOPPY images of the latest build.
Download
Filename: SmiddyOS.zip
Filesize: 320.73 KB
Downloaded: 684 Time(s)

Post 08 Dec 2015, 22:14
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 08 Dec 2015, 22:16
Here's what is happening on the VirtualBox. Note how the Root Directory Starting Sector is 23, so it is loading correctly the very first sector to read, but the subsequent one it fails.


Description: VirutalBox fails to load the CD-ROM.
Filesize: 47.96 KB
Viewed: 21303 Time(s)

VirtualBox_12_8_2015_CD_ROM_Load_Fail.png


Post 08 Dec 2015, 22:16
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.