Exemple #1
0
// format disk track
static void
disk_1305(struct bregs *regs, struct drive_s *drive_g)
{
    debug_stub(regs);

    u16 nlc, nlh, nlspt;
    fillLCHS(drive_g, &nlc, &nlh, &nlspt);

    u8 num_sectors = regs->al;
    u8 head        = regs->dh;

    if (head >= nlh || num_sectors == 0 || num_sectors > nlspt) {
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    struct disk_op_s dop;
    dop.drive_g = drive_g;
    dop.command = CMD_FORMAT;
    dop.lba = head;
    dop.count = num_sectors;
    dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
    int status = send_disk_op(&dop);
    disk_ret(regs, status);
}
Exemple #2
0
static void
handle_legacy_disk(struct bregs *regs, u8 extdrive)
{
    if (! CONFIG_DRIVES) {
        // XXX - support handle_1301 anyway?
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    if (extdrive < EXTSTART_HD) {
        struct drive_s *drive_g = getDrive(EXTTYPE_FLOPPY, extdrive);
        if (!drive_g)
            goto fail;
        floppy_13(regs, drive_g);
        return;
    }

    struct drive_s *drive_g;
    if (extdrive >= EXTSTART_CD)
        drive_g = getDrive(EXTTYPE_CD, extdrive - EXTSTART_CD);
    else
        drive_g = getDrive(EXTTYPE_HD, extdrive - EXTSTART_HD);
    if (!drive_g)
        goto fail;
    disk_13(regs, drive_g);
    return;

fail:
    // XXX - support 1301/1308/1315 anyway?
    disk_ret(regs, DISK_RET_EPARAM);
}
Exemple #3
0
// format disk track
static void noinline
disk_1305(struct bregs *regs, struct drive_s *drive_gf)
{
    debug_stub(regs);

    struct chs_s chs = getLCHS(drive_gf);
    u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;

    u8 count = regs->al;
    u8 cylinder = regs->ch;
    u8 head = regs->dh;

    if (cylinder >= nlc || head >= nlh || count == 0 || count > nls) {
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    struct disk_op_s dop;
    dop.drive_gf = drive_gf;
    dop.command = CMD_FORMAT;
    dop.lba = (((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nls;
    dop.count = count;
    dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
    int status = send_disk_op(&dop);
    disk_ret(regs, status);
}
Exemple #4
0
// Perform read/write/verify using new-style "int13ext" accesses.
static void noinline
extended_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
{
    struct disk_op_s dop;
    // Get lba and check.
    dop.lba = GET_INT13EXT(regs, lba);
    dop.command = command;
    dop.drive_g = drive_g;
    if (dop.lba >= GET_GLOBAL(drive_g->sectors)) {
        warn_invalid(regs);
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    dop.buf_fl = SEGOFF_TO_FLATPTR(GET_INT13EXT(regs, data));
    dop.count = GET_INT13EXT(regs, count);
    if (! dop.count) {
        // Nothing to do.
        disk_ret(regs, DISK_RET_SUCCESS);
        return;
    }

    int status = send_disk_op(&dop);

    SET_INT13EXT(regs, count, dop.count);

    disk_ret(regs, status);
}
Exemple #5
0
// IBM/MS eject media
static void
disk_1346(struct bregs *regs, struct drive_s *drive_g)
{
    if (regs->dl < EXTSTART_CD) {
        // Volume Not Removable
        disk_ret(regs, DISK_RET_ENOTREMOVABLE);
        return;
    }

    int cdid = regs->dl - EXTSTART_CD;
    u8 locks = GET_EBDA(cdrom_locks[cdid]);
    if (locks != 0) {
        disk_ret(regs, DISK_RET_ELOCKED);
        return;
    }

    // FIXME should handle 0x31 no media in device
    // FIXME should handle 0xb5 valid request failed

    // Call removable media eject
    struct bregs br;
    memset(&br, 0, sizeof(br));
    br.ah = 0x52;
    call16_int(0x15, &br);

    if (br.ah || br.flags & F_CF) {
        disk_ret(regs, DISK_RET_ELOCKED);
        return;
    }
    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #6
0
// Perform read/write/verify using new-style "int13ext" accesses.
static void noinline
extended_access(struct bregs *regs, struct drive_s *drive_gf, u16 command)
{
    struct disk_op_s dop;
    struct int13ext_s *param_far = (struct int13ext_s*)(regs->si+0);
    // Get lba and check.
    dop.lba = GET_FARVAR(regs->ds, param_far->lba);
    dop.command = command;
    dop.drive_gf = drive_gf;
    if (dop.lba >= GET_GLOBALFLAT(drive_gf->sectors)) {
        warn_invalid(regs);
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    dop.buf_fl = SEGOFF_TO_FLATPTR(GET_FARVAR(regs->ds, param_far->data));
    dop.count = GET_FARVAR(regs->ds, param_far->count);
    if (! dop.count) {
        // Nothing to do.
        disk_ret(regs, DISK_RET_SUCCESS);
        return;
    }

    int status = send_disk_op(&dop);

    SET_FARVAR(regs->ds, param_far->count, dop.count);

    disk_ret(regs, status);
}
Exemple #7
0
static void
disk_1316(struct bregs *regs, struct drive_s *drive_g)
{
    if (regs->dl >= EXTSTART_HD) {
        // Hard drive
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }
    disk_ret(regs, DISK_RET_ECHANGED);
}
Exemple #8
0
// read disk drive parameters
static void noinline
disk_1308(struct bregs *regs, struct drive_s *drive_g)
{
    u16 ebda_seg = get_ebda_seg();
    // Get logical geometry from table
    u16 nlc, nlh, nlspt;
    fillLCHS(drive_g, &nlc, &nlh, &nlspt);
    nlc--;
    nlh--;
    u8 count;
    if (regs->dl < EXTSTART_HD) {
        // Floppy
        count = GET_GLOBAL(FloppyCount);

        if (CONFIG_CDROM_EMU
            && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf)))
            regs->bx = GET_EBDA2(ebda_seg, cdemu.media) * 2;
        else
            regs->bx = GET_GLOBAL(drive_g->floppy_type);

        // set es & di to point to 11 byte diskette param table in ROM
        regs->es = SEG_BIOS;
        regs->di = (u32)&diskette_param_table2;
    } else if (regs->dl < EXTSTART_CD) {
        // Hard drive
        count = GET_BDA(hdcount);
        nlc--;  // last sector reserved
    } else {
        // Not supported on CDROM
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    if (CONFIG_CDROM_EMU && GET_EBDA2(ebda_seg, cdemu.active)) {
        u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
        if (((emudrive ^ regs->dl) & 0x80) == 0)
            // Note extra drive due to emulation.
            count++;
        if (regs->dl < EXTSTART_HD && count > 2)
            // Max of two floppy drives.
            count = 2;
    }

    regs->al = 0;
    regs->ch = nlc & 0xff;
    regs->cl = ((nlc >> 2) & 0xc0) | (nlspt & 0x3f);
    regs->dh = nlh;

    disk_ret(regs, DISK_RET_SUCCESS);
    regs->dl = count;
}
Exemple #9
0
// lock
static void
disk_134500(struct bregs *regs, struct drive_s *drive_gf)
{
    int cdid = regs->dl - EXTSTART_CD;
    u8 locks = GET_LOW(CDRom_locks[cdid]);
    if (locks == 0xff) {
        regs->al = 1;
        disk_ret(regs, DISK_RET_ETOOMANYLOCKS);
        return;
    }
    SET_LOW(CDRom_locks[cdid], locks + 1);
    regs->al = 1;
    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #10
0
// lock
static void
disk_134500(struct bregs *regs, struct drive_s *drive_g)
{
    u16 ebda_seg = get_ebda_seg();
    int cdid = regs->dl - EXTSTART_CD;
    u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]);
    if (locks == 0xff) {
        regs->al = 1;
        disk_ret(regs, DISK_RET_ETOOMANYLOCKS);
        return;
    }
    SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks + 1);
    regs->al = 1;
    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #11
0
// unlock
static void
disk_134501(struct bregs *regs, struct drive_s *drive_gf)
{
    int cdid = regs->dl - EXTSTART_CD;
    u8 locks = GET_LOW(CDRom_locks[cdid]);
    if (locks == 0x00) {
        regs->al = 0;
        disk_ret(regs, DISK_RET_ENOTLOCKED);
        return;
    }
    locks--;
    SET_LOW(CDRom_locks[cdid], locks);
    regs->al = (locks ? 1 : 0);
    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #12
0
// ElTorito - Terminate disk emu
void
cdemu_134b(struct bregs *regs)
{
    // FIXME ElTorito Hardcoded
    SET_INT13ET(regs, size, 0x13);
    SET_INT13ET(regs, media, GET_LOW(CDEmu.media));
    SET_INT13ET(regs, emulated_drive, GET_LOW(CDEmu.emulated_extdrive));
    struct drive_s *drive_gf = GET_LOW(CDEmu.emulated_drive_gf);
    u8 cntl_id = 0;
    if (drive_gf)
        cntl_id = GET_GLOBALFLAT(drive_gf->cntl_id);
    SET_INT13ET(regs, controller_index, cntl_id / 2);
    SET_INT13ET(regs, device_spec, cntl_id % 2);
    SET_INT13ET(regs, ilba, GET_LOW(CDEmu.ilba));
    SET_INT13ET(regs, buffer_segment, GET_LOW(CDEmu.buffer_segment));
    SET_INT13ET(regs, load_segment, GET_LOW(CDEmu.load_segment));
    SET_INT13ET(regs, sector_count, GET_LOW(CDEmu.sector_count));
    SET_INT13ET(regs, cylinders, GET_LOW(CDEmu.lchs.cylinders));
    SET_INT13ET(regs, sectors, GET_LOW(CDEmu.lchs.spt));
    SET_INT13ET(regs, heads, GET_LOW(CDEmu.lchs.heads));

    // If we have to terminate emulation
    if (regs->al == 0x00) {
        // FIXME ElTorito Various. Should be handled accordingly to spec
        SET_LOW(CDEmu.active, 0x00); // bye bye

        // XXX - update floppy/hd count.
    }

    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #13
0
// unlock
static void
disk_134501(struct bregs *regs, struct drive_s *drive_g)
{
    u16 ebda_seg = get_ebda_seg();
    int cdid = regs->dl - EXTSTART_CD;
    u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]);
    if (locks == 0x00) {
        regs->al = 0;
        disk_ret(regs, DISK_RET_ENOTLOCKED);
        return;
    }
    locks--;
    SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks);
    regs->al = (locks ? 1 : 0);
    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #14
0
// IBM/MS installation check
static void
disk_1341(struct bregs *regs, struct drive_s *drive_g)
{
    regs->bx = 0xaa55;  // install check
    regs->cx = 0x0007;  // ext disk access and edd, removable supported
    disk_ret(regs, DISK_RET_SUCCESS);
    regs->ah = 0x30;    // EDD 3.0
}
Exemple #15
0
// status
static void
disk_134502(struct bregs *regs, struct drive_s *drive_g)
{
    int cdid = regs->dl - EXTSTART_CD;
    u8 locks = GET_EBDA(cdrom_locks[cdid]);
    regs->al = (locks ? 1 : 0);
    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #16
0
// disk controller reset
static void
disk_1300(struct bregs *regs, struct drive_s *drive_g)
{
    struct disk_op_s dop;
    dop.drive_g = drive_g;
    dop.command = CMD_RESET;
    int status = send_disk_op(&dop);
    disk_ret(regs, status);
}
Exemple #17
0
// Perform read/write/verify using old-style chs accesses
static void
basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
{
    struct disk_op_s dop;
    dop.drive_g = drive_g;
    dop.command = command;

    u8 count = regs->al;
    u16 cylinder = regs->ch | ((((u16)regs->cl) << 2) & 0x300);
    u16 sector = regs->cl & 0x3f;
    u16 head = regs->dh;

    if (count > 128 || count == 0 || sector == 0) {
        dprintf(1, "int13_harddisk: function %02x, parameter out of range!\n"
                , regs->ah);
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }
    dop.count = count;

    u16 nlc, nlh, nlspt;
    fillLCHS(drive_g, &nlc, &nlh, &nlspt);

    // sanity check on cyl heads, sec
    if (cylinder >= nlc || head >= nlh || sector > nlspt) {
        dprintf(1, "int13_harddisk: function %02x, parameters out of"
                " range %04x/%04x/%04x!\n"
                , regs->ah, cylinder, head, sector);
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    // translate lchs to lba
    dop.lba = (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt)
               + (u32)sector - 1);

    dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);

    int status = send_disk_op(&dop);

    regs->al = dop.count;

    disk_ret(regs, status);
}
Exemple #18
0
// check drive ready
static void
disk_1310(struct bregs *regs, struct drive_s *drive_g)
{
    // should look at 40:8E also???

    struct disk_op_s dop;
    dop.drive_g = drive_g;
    dop.command = CMD_ISREADY;
    int status = send_disk_op(&dop);
    disk_ret(regs, status);
}
Exemple #19
0
// Perform read/write/verify using old-style chs accesses
static void noinline
basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
{
    struct disk_op_s dop;
    dop.drive_g = drive_g;
    dop.command = command;

    u8 count = regs->al;
    u16 cylinder = regs->ch | ((((u16)regs->cl) << 2) & 0x300);
    u16 sector = regs->cl & 0x3f;
    u16 head = regs->dh;

    if (count > 128 || count == 0 || sector == 0) {
        warn_invalid(regs);
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }
    dop.count = count;

    u16 nlc, nlh, nlspt;
    fillLCHS(drive_g, &nlc, &nlh, &nlspt);

    // sanity check on cyl heads, sec
    if (cylinder >= nlc || head >= nlh || sector > nlspt) {
        warn_invalid(regs);
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    // translate lchs to lba
    dop.lba = (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt)
               + (u32)sector - 1);

    dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);

    int status = send_disk_op(&dop);

    regs->al = dop.count;

    disk_ret(regs, status);
}
Exemple #20
0
// IBM/MS extended media change
static void
disk_1349(struct bregs *regs, struct drive_s *drive_g)
{
    if (regs->dl < EXTSTART_CD) {
        // Always success for HD
        disk_ret(regs, DISK_RET_SUCCESS);
        return;
    }
    set_invalid(regs);
    // always send changed ??
    regs->ah = DISK_RET_ECHANGED;
}
Exemple #21
0
// ElTorito - Terminate disk emu
static void
cdemu_134b(struct bregs *regs)
{
    memcpy_far(regs->ds, (void*)(regs->si+0), SEG_LOW, &CDEmu, sizeof(CDEmu));

    // If we have to terminate emulation
    if (regs->al == 0x00) {
        // FIXME ElTorito Various. Should be handled accordingly to spec
        SET_LOW(CDEmu.media, 0x00); // bye bye

        // XXX - update floppy/hd count.
    }

    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #22
0
// Perform read/write/verify using new-style "int13ext" accesses.
static void
extended_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
{
    struct disk_op_s dop;
    // Get lba and check.
    dop.lba = GET_INT13EXT(regs, lba);
    dop.command = command;
    dop.drive_g = drive_g;
    if (dop.lba >= GET_GLOBAL(drive_g->sectors)) {
        dprintf(1, "int13_harddisk: function %02x. LBA out of range\n"
                , regs->ah);
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    dop.buf_fl = SEGOFF_TO_FLATPTR(GET_INT13EXT(regs, data));
    dop.count = GET_INT13EXT(regs, count);

    int status = send_disk_op(&dop);

    SET_INT13EXT(regs, count, dop.count);

    disk_ret(regs, status);
}
Exemple #23
0
// IBM/MS lock/unlock drive
static void
disk_1345(struct bregs *regs, struct drive_s *drive_g)
{
    if (regs->dl < EXTSTART_CD) {
        // Always success for HD
        disk_ret(regs, DISK_RET_SUCCESS);
        return;
    }

    switch (regs->al) {
    case 0x00: disk_134500(regs, drive_g); break;
    case 0x01: disk_134501(regs, drive_g); break;
    case 0x02: disk_134502(regs, drive_g); break;
    default:   disk_1345XX(regs, drive_g); break;
    }
}
Exemple #24
0
// read disk drive size
static void noinline
disk_1315(struct bregs *regs, struct drive_s *drive_gf)
{
    disk_ret(regs, DISK_RET_SUCCESS);
    if (regs->dl < EXTSTART_HD || regs->dl >= EXTSTART_CD) {
        // Floppy or cdrom
        regs->ah = 1;
        return;
    }
    // Hard drive

    // Get logical geometry from table
    struct chs_s chs = getLCHS(drive_gf);
    u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;

    // Compute sector count seen by int13
    u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nls;
    regs->cx = lba >> 16;
    regs->dx = lba & 0xffff;
    regs->ah = 3; // hard disk accessible
}
Exemple #25
0
// read disk drive size
static void
disk_1315(struct bregs *regs, struct drive_s *drive_g)
{
    disk_ret(regs, DISK_RET_SUCCESS);
    if (regs->dl < EXTSTART_HD || regs->dl >= EXTSTART_CD) {
        // Floppy or cdrom
        regs->ah = 1;
        return;
    }
    // Hard drive

    // Get logical geometry from table
    u16 nlc, nlh, nlspt;
    fillLCHS(drive_g, &nlc, &nlh, &nlspt);

    // Compute sector count seen by int13
    u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nlspt;
    regs->cx = lba >> 16;
    regs->dx = lba & 0xffff;
    regs->ah = 3; // hard disk accessible
}
Exemple #26
0
// IBM/MS get drive parameters
static void
disk_1348(struct bregs *regs, struct drive_s *drive_gf)
{
    int ret = fill_edd(SEGOFF(regs->ds, regs->si), drive_gf);
    disk_ret(regs, ret);
}
Exemple #27
0
static void
disk_134eXX(struct bregs *regs, struct drive_s *drive_g)
{
    disk_ret(regs, DISK_RET_EPARAM);
}
Exemple #28
0
static void
disk_134e06(struct bregs *regs, struct drive_s *drive_g)
{
    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #29
0
// IBM/MS get drive parameters
static void
disk_1348(struct bregs *regs, struct drive_s *drive_g)
{
    u16 size = GET_INT13DPT(regs, size);

    // Buffer is too small
    if (size < 26) {
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    // EDD 1.x

    u8  type    = GET_GLOBAL(drive_g->type);
    u16 npc     = GET_GLOBAL(drive_g->pchs.cylinders);
    u16 nph     = GET_GLOBAL(drive_g->pchs.heads);
    u16 npspt   = GET_GLOBAL(drive_g->pchs.spt);
    u64 lba     = GET_GLOBAL(drive_g->sectors);
    u16 blksize = GET_GLOBAL(drive_g->blksize);

    dprintf(DEBUG_HDL_13, "disk_1348 size=%d t=%d chs=%d,%d,%d lba=%d bs=%d\n"
            , size, type, npc, nph, npspt, (u32)lba, blksize);

    SET_INT13DPT(regs, size, 26);
    if (type == DTYPE_ATAPI) {
        // 0x74 = removable, media change, lockable, max values
        SET_INT13DPT(regs, infos, 0x74);
        SET_INT13DPT(regs, cylinders, 0xffffffff);
        SET_INT13DPT(regs, heads, 0xffffffff);
        SET_INT13DPT(regs, spt, 0xffffffff);
        SET_INT13DPT(regs, sector_count, (u64)-1);
    } else {
        if (lba > (u64)npspt*nph*0x3fff) {
            SET_INT13DPT(regs, infos, 0x00); // geometry is invalid
            SET_INT13DPT(regs, cylinders, 0x3fff);
        } else {
            SET_INT13DPT(regs, infos, 0x02); // geometry is valid
            SET_INT13DPT(regs, cylinders, (u32)npc);
        }
        SET_INT13DPT(regs, heads, (u32)nph);
        SET_INT13DPT(regs, spt, (u32)npspt);
        SET_INT13DPT(regs, sector_count, lba);
    }
    SET_INT13DPT(regs, blksize, blksize);

    if (size < 30 || (type != DTYPE_ATA && type != DTYPE_ATAPI)) {
        disk_ret(regs, DISK_RET_SUCCESS);
        return;
    }

    // EDD 2.x

    u16 ebda_seg = get_ebda_seg();
    SET_INT13DPT(regs, size, 30);

    SET_INT13DPT(regs, dpte_segment, ebda_seg);
    SET_INT13DPT(regs, dpte_offset
                 , offsetof(struct extended_bios_data_area_s, dpte));

    // Fill in dpte
    u8 ataid = GET_GLOBAL(drive_g->cntl_id);
    u8 channel = ataid / 2;
    u8 slave = ataid % 2;
    u16 iobase1 = GET_GLOBAL(ATA_channels[channel].iobase1);
    u16 iobase2 = GET_GLOBAL(ATA_channels[channel].iobase2);
    u8 irq = GET_GLOBAL(ATA_channels[channel].irq);

    u16 options = 0;
    if (type == DTYPE_ATA) {
        u8 translation = GET_GLOBAL(drive_g->translation);
        if (translation != TRANSLATION_NONE) {
            options |= 1<<3; // CHS translation
            if (translation == TRANSLATION_LBA)
                options |= 1<<9;
            if (translation == TRANSLATION_RECHS)
                options |= 3<<9;
        }
    } else {
        // ATAPI
        options |= 1<<5; // removable device
        options |= 1<<6; // atapi device
    }
    options |= 1<<4; // lba translation
    if (CONFIG_ATA_PIO32)
        options |= 1<<7;

    SET_EBDA2(ebda_seg, dpte.iobase1, iobase1);
    SET_EBDA2(ebda_seg, dpte.iobase2, iobase2 + ATA_CB_DC);
    SET_EBDA2(ebda_seg, dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
                                      | ATA_CB_DH_LBA));
    SET_EBDA2(ebda_seg, dpte.unused, 0xcb);
    SET_EBDA2(ebda_seg, dpte.irq, irq);
    SET_EBDA2(ebda_seg, dpte.blkcount, 1);
    SET_EBDA2(ebda_seg, dpte.dma, 0);
    SET_EBDA2(ebda_seg, dpte.pio, 0);
    SET_EBDA2(ebda_seg, dpte.options, options);
    SET_EBDA2(ebda_seg, dpte.reserved, 0);
    SET_EBDA2(ebda_seg, dpte.revision, 0x11);

    u8 sum = checksum_far(
                 ebda_seg, (void*)offsetof(struct extended_bios_data_area_s, dpte), 15);
    SET_EBDA2(ebda_seg, dpte.checksum, -sum);

    if (size < 66) {
        disk_ret(regs, DISK_RET_SUCCESS);
        return;
    }

    // EDD 3.x
    SET_INT13DPT(regs, key, 0xbedd);
    SET_INT13DPT(regs, dpi_length, 36);
    SET_INT13DPT(regs, reserved1, 0);
    SET_INT13DPT(regs, reserved2, 0);

    int bdf = GET_GLOBAL(ATA_channels[channel].pci_bdf);
    if (bdf != -1) {
        SET_INT13DPT(regs, host_bus[0], 'P');
        SET_INT13DPT(regs, host_bus[1], 'C');
        SET_INT13DPT(regs, host_bus[2], 'I');
        SET_INT13DPT(regs, host_bus[3], 0);

        u32 path = (pci_bdf_to_bus(bdf) | (pci_bdf_to_dev(bdf) << 8)
                    | (pci_bdf_to_fn(bdf) << 16));
        SET_INT13DPT(regs, iface_path, path);
    } else {
        // ISA
        SET_INT13DPT(regs, host_bus[0], 'I');
        SET_INT13DPT(regs, host_bus[1], 'S');
        SET_INT13DPT(regs, host_bus[2], 'A');
        SET_INT13DPT(regs, host_bus[3], 0);

        SET_INT13DPT(regs, iface_path, iobase1);
    }

    SET_INT13DPT(regs, iface_type[0], 'A');
    SET_INT13DPT(regs, iface_type[1], 'T');
    SET_INT13DPT(regs, iface_type[2], 'A');
    SET_INT13DPT(regs, iface_type[3], 0);
    SET_INT13DPT(regs, iface_type[4], 0);
    SET_INT13DPT(regs, iface_type[5], 0);
    SET_INT13DPT(regs, iface_type[6], 0);
    SET_INT13DPT(regs, iface_type[7], 0);

    SET_INT13DPT(regs, device_path, slave);

    SET_INT13DPT(regs, checksum
                 , -checksum_far(regs->ds, (void*)(regs->si+30), 35));

    disk_ret(regs, DISK_RET_SUCCESS);
}
Exemple #30
0
// IBM/MS get drive parameters
static void
disk_1348(struct bregs *regs, struct drive_s *drive_g)
{
    u16 size = GET_INT13DPT(regs, size);
    u16 t13 = size == 74;

    // Buffer is too small
    if (size < 26) {
        disk_ret(regs, DISK_RET_EPARAM);
        return;
    }

    // EDD 1.x

    u8  type    = GET_GLOBAL(drive_g->type);
    u16 npc     = GET_GLOBAL(drive_g->pchs.cylinders);
    u16 nph     = GET_GLOBAL(drive_g->pchs.heads);
    u16 npspt   = GET_GLOBAL(drive_g->pchs.spt);
    u64 lba     = GET_GLOBAL(drive_g->sectors);
    u16 blksize = GET_GLOBAL(drive_g->blksize);

    dprintf(DEBUG_HDL_13, "disk_1348 size=%d t=%d chs=%d,%d,%d lba=%d bs=%d\n"
            , size, type, npc, nph, npspt, (u32)lba, blksize);

    SET_INT13DPT(regs, size, 26);
    if (type == DTYPE_ATAPI) {
        // 0x74 = removable, media change, lockable, max values
        SET_INT13DPT(regs, infos, 0x74);
        SET_INT13DPT(regs, cylinders, 0xffffffff);
        SET_INT13DPT(regs, heads, 0xffffffff);
        SET_INT13DPT(regs, spt, 0xffffffff);
        SET_INT13DPT(regs, sector_count, (u64)-1);
    } else {
        if (lba > (u64)npspt*nph*0x3fff) {
            SET_INT13DPT(regs, infos, 0x00); // geometry is invalid
            SET_INT13DPT(regs, cylinders, 0x3fff);
        } else {
            SET_INT13DPT(regs, infos, 0x02); // geometry is valid
            SET_INT13DPT(regs, cylinders, (u32)npc);
        }
        SET_INT13DPT(regs, heads, (u32)nph);
        SET_INT13DPT(regs, spt, (u32)npspt);
        SET_INT13DPT(regs, sector_count, lba);
    }
    SET_INT13DPT(regs, blksize, blksize);

    if (size < 30 ||
        (type != DTYPE_ATA && type != DTYPE_ATAPI &&
         type != DTYPE_VIRTIO_BLK && type != DTYPE_VIRTIO_SCSI)) {
        disk_ret(regs, DISK_RET_SUCCESS);
        return;
    }

    // EDD 2.x

    int bdf;
    u16 iobase1 = 0;
    u64 device_path = 0;
    u8 channel = 0;
    SET_INT13DPT(regs, size, 30);
    if (type == DTYPE_ATA || type == DTYPE_ATAPI) {
        u16 ebda_seg = get_ebda_seg();

        SET_INT13DPT(regs, dpte_segment, ebda_seg);
        SET_INT13DPT(regs, dpte_offset
                     , offsetof(struct extended_bios_data_area_s, dpte));

        // Fill in dpte
        struct atadrive_s *adrive_g = container_of(
            drive_g, struct atadrive_s, drive);
        struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
        u8 slave = GET_GLOBAL(adrive_g->slave);
        u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
        u8 irq = GET_GLOBALFLAT(chan_gf->irq);
        iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
        bdf = GET_GLOBALFLAT(chan_gf->pci_bdf);
        device_path = slave;
        channel = GET_GLOBALFLAT(chan_gf->chanid);

        u16 options = 0;
        if (type == DTYPE_ATA) {
            u8 translation = GET_GLOBAL(drive_g->translation);
            if (translation != TRANSLATION_NONE) {
                options |= 1<<3; // CHS translation
                if (translation == TRANSLATION_LBA)
                    options |= 1<<9;
                if (translation == TRANSLATION_RECHS)
                    options |= 3<<9;
            }
        } else {
            // ATAPI
            options |= 1<<5; // removable device
            options |= 1<<6; // atapi device
        }
        options |= 1<<4; // lba translation
        if (CONFIG_ATA_PIO32)
            options |= 1<<7;

        SET_EBDA2(ebda_seg, dpte.iobase1, iobase1);
        SET_EBDA2(ebda_seg, dpte.iobase2, iobase2 + ATA_CB_DC);
        SET_EBDA2(ebda_seg, dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
                                          | ATA_CB_DH_LBA));
        SET_EBDA2(ebda_seg, dpte.unused, 0xcb);
        SET_EBDA2(ebda_seg, dpte.irq, irq);
        SET_EBDA2(ebda_seg, dpte.blkcount, 1);
        SET_EBDA2(ebda_seg, dpte.dma, 0);
        SET_EBDA2(ebda_seg, dpte.pio, 0);
        SET_EBDA2(ebda_seg, dpte.options, options);
        SET_EBDA2(ebda_seg, dpte.reserved, 0);
        SET_EBDA2(ebda_seg, dpte.revision, 0x11);

        u8 sum = checksum_far(
            ebda_seg, (void*)offsetof(struct extended_bios_data_area_s, dpte), 15);
        SET_EBDA2(ebda_seg, dpte.checksum, -sum);
    } else {