VirtualBox

Ignore:
Timestamp:
Dec 9, 2011 2:24:33 PM (13 years ago)
Author:
vboxsync
Message:

Made ATAPI command building somewhat sane.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/BIOS-new/eltorito.c

    r39567 r39571  
    8080#define FLAGS   r.ra.flags.u.r16.flags
    8181
     82#pragma pack(1)
     83
     84/* READ_10/WRITE_10 CDB padded to 12 bytes for ATAPI. */
     85typedef struct {
     86    uint16_t    command;    /* Command. */
     87    uint32_t    lba;        /* LBA, MSB first! */
     88    uint8_t     pad1;       /* Unused. */
     89    uint16_t    nsect;      /* Sector count, MSB first! */
     90    uint8_t     pad2[3];    /* Unused. */
     91} cdb_atapi;
     92
     93#pragma pack()
     94
     95ct_assert(sizeof(cdb_atapi) == 12);
    8296
    8397// ---------------------------------------------------------------------------
     
    221235    // @TODO: a macro or a function for getting the EBDA segment
    222236    uint16_t        ebda_seg=read_word(0x0040,0x000E);
    223     uint8_t         atacmd[12], buffer[2048];
     237    uint8_t         buffer[2048];
     238    cdb_atapi       atapicmd;
    224239    uint32_t        lba;
    225240    uint16_t        boot_segment, nbsectors, i, error;
     
    241256   
    242257    /* Read the Boot Record Volume Descriptor (BRVD). */
    243     _fmemset(&atacmd, 0, 12);
    244     //@todo: use some sane byte swapping routines here
    245     atacmd[0] = 0x28;                       // READ command
    246     atacmd[7] = (0x01 & 0xff00) >> 8;       // Sectors
    247     atacmd[8] = (0x01 & 0x00ff);            // Sectors
    248     atacmd[2] = (0x11 & 0xff000000) >> 24;  // LBA
    249     atacmd[3] = (0x11 & 0x00ff0000) >> 16;
    250     atacmd[4] = (0x11 & 0x0000ff00) >> 8;
    251     atacmd[5] = (0x11 & 0x000000ff);
     258    _fmemset(&atapicmd, 0, sizeof(atapicmd));
     259    atapicmd.command = 0x28;    // READ 10 command
     260    atapicmd.lba     = swap_32(0x11);
     261    atapicmd.nsect   = swap_16(0x01);
    252262
    253263    for (read_try = 0; read_try <= 4; ++read_try)
     
    255265        //@todo: Use indirect calls instead?
    256266        if (device > BX_MAX_ATA_DEVICES)
    257             error = ahci_cmd_packet(device, 12, &atacmd, 0, 2048L, ATA_DATA_IN, &buffer);
     267            error = ahci_cmd_packet(device, 12, (char __far *)&atapicmd, 0, 2048L, ATA_DATA_IN, &buffer);
    258268        else
    259             error = ata_cmd_packet(device, 12, &atacmd, 0, 2048L, ATA_DATA_IN, &buffer);
     269            error = ata_cmd_packet(device, 12, (char __far *)&atapicmd, 0, 2048L, ATA_DATA_IN, &buffer);
    260270        if (!error)
    261271            break;
     
    282292
    283293    /* Now we read the Boot Catalog. */
    284     _fmemset(&atacmd,0,12);
    285     //@todo: use some sane byte swapping routines here
    286     atacmd[0] = 0x28;                       // READ command
    287     atacmd[7] = (0x01 & 0xff00) >> 8;       // Sectors
    288     atacmd[8] = (0x01 & 0x00ff);            // Sectors
    289     atacmd[2] = (lba & 0xff000000) >> 24;   // LBA
    290     atacmd[3] = (lba & 0x00ff0000) >> 16;
    291     atacmd[4] = (lba & 0x0000ff00) >> 8;
    292     atacmd[5] = (lba & 0x000000ff);
     294    _fmemset(&atapicmd, 0, sizeof(atapicmd));   //@todo: should be redundant
     295    atapicmd.command = 0x28;    // READ 10 command
     296    atapicmd.lba     = swap_32(lba);
     297    atapicmd.nsect   = swap_16(0x01);
    293298
    294299    if (device > BX_MAX_ATA_DEVICES)
    295         error = ahci_cmd_packet(device, 12, &atacmd, 0, 2048L, ATA_DATA_IN, &buffer);
     300        error = ahci_cmd_packet(device, 12, (char __far *)&atapicmd, 0, 2048L, ATA_DATA_IN, &buffer);
    296301    else
    297         error = ata_cmd_packet(device, 12, &atacmd, 0, 2048L, ATA_DATA_IN, &buffer);
     302        error = ata_cmd_packet(device, 12, (char __far *)&atapicmd, 0, 2048L, ATA_DATA_IN, &buffer);
    298303
    299304    if (error != 0)
     
    343348   
    344349    /* Read the image into memory. */
    345     _fmemset(&atacmd, 0, 12);
    346     atacmd[0] = 0x28;                               // READ command
    347     atacmd[7] = ((1+(nbsectors-1)/4) & 0xff00) >> 8;// Sectors
    348     atacmd[8] = ((1+(nbsectors-1)/4) & 0x00ff);     // Sectors
    349     atacmd[2] = (lba & 0xff000000) >> 24;           // LBA
    350     atacmd[3] = (lba & 0x00ff0000) >> 16;
    351     atacmd[4] = (lba & 0x0000ff00) >> 8;
    352     atacmd[5] = (lba & 0x000000ff);
     350    _fmemset(&atapicmd, 0, sizeof(atapicmd));   //@todo: should be redundant
     351    atapicmd.command = 0x28;    // READ 10 command
     352    atapicmd.lba     = swap_32(lba);
     353    atapicmd.nsect   = swap_16(1 + (nbsectors - 1) / 4);
    353354
    354355    if (device > BX_MAX_ATA_DEVICES)
    355         error = ahci_cmd_packet(device, 12, &atacmd, 0, nbsectors*512L, ATA_DATA_IN, MK_FP(boot_segment,0));
     356        error = ahci_cmd_packet(device, 12, (char __far *)&atapicmd, 0, nbsectors*512L, ATA_DATA_IN, MK_FP(boot_segment,0));
    356357    else
    357         error = ata_cmd_packet(device, 12, &atacmd, 0, nbsectors*512L, ATA_DATA_IN, MK_FP(boot_segment,0));
     358        error = ata_cmd_packet(device, 12, (char __far *)&atapicmd, 0, nbsectors*512L, ATA_DATA_IN, MK_FP(boot_segment,0));
    358359    if (error != 0)
    359360        return 12;
     
    417418    uint32_t        vlba, ilba, slba, elba;
    418419    uint16_t        before, segment, offset;
    419     uint8_t         atacmd[12];
     420    cdb_atapi       atapicmd;
    420421    cdemu_t __far   *cdemu;
    421422
     
    515516        // end lba on cd
    516517        elba = (uint32_t)(vlba+nbsectors-1)/4;
    517        
    518         _fmemset(&atacmd, 0, 12);
    519         //@todo: use some sane byte swapping routines here
    520         atacmd[0] = 0x28;                                   // READ command
    521         atacmd[7] = ((uint16_t)(elba-slba+1) & 0xff00) >> 8;// Sectors
    522         atacmd[8] = ((uint16_t)(elba-slba+1) & 0x00ff);     // Sectors
    523         atacmd[2] = (ilba+slba & 0xff000000) >> 24;         // LBA
    524         atacmd[3] = (ilba+slba & 0x00ff0000) >> 16;
    525         atacmd[4] = (ilba+slba & 0x0000ff00) >> 8;
    526         atacmd[5] = (ilba+slba & 0x000000ff);
     518
     519        _fmemset(&atapicmd, 0, sizeof(atapicmd));
     520        atapicmd.command = 0x28;    // READ 10 command
     521        atapicmd.lba     = swap_32(ilba + slba);
     522        atapicmd.nsect   = swap_16(elba - slba + 1);
    527523
    528524        if (device > BX_MAX_ATA_DEVICES)
    529             status = ahci_cmd_packet(device, 12, &atacmd, before*512, nbsectors*512L, ATA_DATA_IN, MK_FP(segment,offset));
     525            status = ahci_cmd_packet(device, 12, (char __far *)&atapicmd, before*512, nbsectors*512L, ATA_DATA_IN, MK_FP(segment,offset));
    530526        else
    531             status = ata_cmd_packet(device, 12, &atacmd, before*512, nbsectors*512L, ATA_DATA_IN, MK_FP(segment,offset));
     527            status = ata_cmd_packet(device, 12, (char __far *)&atapicmd, before*512, nbsectors*512L, ATA_DATA_IN, MK_FP(segment,offset));
    532528
    533529        if (status != 0) {
     
    617613    uint16_t            ebda_seg = read_word(0x0040,0x000E);
    618614    uint8_t             device, status, locks;
    619     uint8_t             atacmd[12];
     615    cdb_atapi           atapicmd;
    620616    uint32_t            lba;
    621617    uint16_t            count, segment, offset, size;
     
    719715                          __func__, count, lba, segment, offset);
    720716
    721         _fmemset(&atacmd, 0, 12);
    722         //@todo: use some sane byte swapping routines here
    723         atacmd[0] = 0x28;                     // READ command
    724         atacmd[7] = (count & 0xff00) >> 8;    // Sectors
    725         atacmd[8] = (count & 0x00ff);         // Sectors
    726         atacmd[2] = (lba & 0xff000000) >> 24; // LBA
    727         atacmd[3] = (lba & 0x00ff0000) >> 16;
    728         atacmd[4] = (lba & 0x0000ff00) >> 8;
    729         atacmd[5] = (lba & 0x000000ff);
     717        _fmemset(&atapicmd, 0, sizeof(atapicmd));
     718        atapicmd.command = 0x28;    // READ 10 command
     719        atapicmd.lba     = swap_32(lba);
     720        atapicmd.nsect   = swap_16(count);
    730721
    731722        if (device > BX_MAX_ATA_DEVICES)
    732             status = ahci_cmd_packet(device, 12, &atacmd, 0, count*2048L, ATA_DATA_IN, MK_FP(segment,offset));
     723            status = ahci_cmd_packet(device, 12, (char __far *)&atapicmd, 0, count*2048L, ATA_DATA_IN, MK_FP(segment,offset));
    733724        else
    734             status = ata_cmd_packet(device, 12, &atacmd, 0, count*2048L, ATA_DATA_IN, MK_FP(segment,offset));
     725            status = ata_cmd_packet(device, 12, (char __far *)&atapicmd, 0, count*2048L, ATA_DATA_IN, MK_FP(segment,offset));
    735726
    736727        count = (uint16_t)(bios_dsk->drqp.trsfbytes >> 11);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette