mirror of
https://github.com/LIV2/lide.device.git
synced 2025-12-06 00:32:45 +00:00
Remove 64-bit math
Reduces code size by ~4K
This commit is contained in:
parent
5124c1c830
commit
4207fb75a4
39
ata.c
39
ata.c
@ -21,9 +21,9 @@
|
||||
#include "sleep.h"
|
||||
#include "lide_alib.h"
|
||||
|
||||
static BYTE write_taskfile_lba(struct IDEUnit *unit, UBYTE command, unsigned long long lba, UBYTE sectorCount, UBYTE features);
|
||||
static BYTE write_taskfile_lba48(struct IDEUnit *unit, UBYTE command, unsigned long long, UBYTE sectorCount, UBYTE features);
|
||||
static BYTE write_taskfile_chs(struct IDEUnit *unit, UBYTE command, unsigned long long lba, UBYTE sectorCount, UBYTE features);
|
||||
static BYTE write_taskfile_lba(struct IDEUnit *unit, UBYTE command, uint64_t lba, UBYTE sectorCount, UBYTE features);
|
||||
static BYTE write_taskfile_lba48(struct IDEUnit *unit, UBYTE command, uint64_t lba, UBYTE sectorCount, UBYTE features);
|
||||
static BYTE write_taskfile_chs(struct IDEUnit *unit, UBYTE command, uint64_t lba, UBYTE sectorCount, UBYTE features);
|
||||
|
||||
/**
|
||||
* ata_status_reg_delay
|
||||
@ -416,9 +416,9 @@ bool ata_init_unit(struct IDEUnit *unit, void *base) {
|
||||
unit->flags.lba48 = true;
|
||||
Info("INIT: Large drive, using LBA48 mode \n");
|
||||
unit->logicalSectors = 0;
|
||||
unit->logicalSectors |= ((unsigned long long)buf[ata_identify_lba48_sectors]) << 0;
|
||||
unit->logicalSectors |= ((unsigned long long)buf[ata_identify_lba48_sectors+1]) << 16;
|
||||
unit->logicalSectors |= ((unsigned long long)buf[ata_identify_lba48_sectors+2]) << 32;
|
||||
unit->logicalSectors |= ((uint64_t)buf[ata_identify_lba48_sectors]) << 0;
|
||||
unit->logicalSectors |= ((uint64_t)buf[ata_identify_lba48_sectors+1]) << 16;
|
||||
unit->logicalSectors |= ((uint64_t)buf[ata_identify_lba48_sectors+2]) << 32;
|
||||
|
||||
unit->write_taskfile = &write_taskfile_lba48;
|
||||
|
||||
@ -439,15 +439,15 @@ bool ata_init_unit(struct IDEUnit *unit, void *base) {
|
||||
|
||||
if (unit->logicalSectors >= 267382800) {
|
||||
// For drives larger than 127GB fudge the geometry
|
||||
unit->heads = 63;
|
||||
unit->sectorsPerTrack = 255;
|
||||
unit->cylinders = (unit->logicalSectors / (63*255));
|
||||
unit->heads = 64;
|
||||
unit->sectorsPerTrack = 256;
|
||||
unit->cylinders = unit->logicalSectors >> 14;
|
||||
} else if (unit->logicalSectors >= 16514064) {
|
||||
// If a drive is larger than 8GB then the drive will report a geometry of 16383/16/63 (CHS)
|
||||
// In this case generate a new Cylinders value
|
||||
unit->heads = 16;
|
||||
unit->heads = 16;
|
||||
unit->sectorsPerTrack = 255;
|
||||
unit->cylinders = (unit->logicalSectors / (16*255));
|
||||
unit->cylinders = ((ULONG)unit->logicalSectors / (16*255));
|
||||
Info("INIT: Adjusting geometry, new geometry; 16/255/%ld\n",unit->cylinders);
|
||||
}
|
||||
|
||||
@ -537,7 +537,7 @@ bool ata_set_multiple(struct IDEUnit *unit, BYTE multiple) {
|
||||
* @param unit Pointer to the unit structure
|
||||
* @returns error
|
||||
*/
|
||||
BYTE ata_read(void *buffer, unsigned long long lba, ULONG count, struct IDEUnit *unit) {
|
||||
BYTE ata_read(void *buffer, uint64_t lba, ULONG count, struct IDEUnit *unit) {
|
||||
Trace("ata_read enter\n");
|
||||
Trace("ATA: Request sector count: %ld\n",count);
|
||||
|
||||
@ -625,7 +625,7 @@ BYTE ata_read(void *buffer, unsigned long long lba, ULONG count, struct IDEUnit
|
||||
* @param unit Pointer to the unit structure
|
||||
* @returns error
|
||||
*/
|
||||
BYTE ata_write(void *buffer, unsigned long long lba, ULONG count, struct IDEUnit *unit) {
|
||||
BYTE ata_write(void *buffer, uint64_t lba, ULONG count, struct IDEUnit *unit) {
|
||||
Trace("ata_write enter\n");
|
||||
Trace("ATA: Request sector count: %ld\n",count);
|
||||
|
||||
@ -746,10 +746,11 @@ void ata_write_unaligned_long(void *source asm("a0"), void *destination asm("a1"
|
||||
* @param unit Pointer to an IDEUnit struct
|
||||
* @param lba Pointer to the LBA variable
|
||||
*/
|
||||
static BYTE write_taskfile_chs(struct IDEUnit *unit, UBYTE command, unsigned long long lba, UBYTE sectorCount, UBYTE features) {
|
||||
UWORD cylinder = (lba / (unit->heads * unit->sectorsPerTrack));
|
||||
UBYTE head = ((lba / unit->sectorsPerTrack) % unit->heads) & 0xF;
|
||||
UBYTE sector = (lba % unit->sectorsPerTrack) + 1;
|
||||
static BYTE write_taskfile_chs(struct IDEUnit *unit, UBYTE command, uint64_t lba, UBYTE sectorCount, UBYTE features) {
|
||||
|
||||
UWORD cylinder = ((ULONG)lba / (unit->heads * unit->sectorsPerTrack));
|
||||
UBYTE head = (((ULONG)lba / unit->sectorsPerTrack) % unit->heads) & 0xF;
|
||||
UBYTE sector = ((ULONG)lba % unit->sectorsPerTrack) + 1;
|
||||
|
||||
BYTE devHead;
|
||||
|
||||
@ -776,7 +777,7 @@ static BYTE write_taskfile_chs(struct IDEUnit *unit, UBYTE command, unsigned lon
|
||||
* @param unit Pointer to an IDEUnit struct
|
||||
* @param lba Pointer to the LBA variable
|
||||
*/
|
||||
static BYTE write_taskfile_lba(struct IDEUnit *unit, UBYTE command, unsigned long long lba, UBYTE sectorCount, UBYTE features) {
|
||||
static BYTE write_taskfile_lba(struct IDEUnit *unit, UBYTE command, uint64_t lba, UBYTE sectorCount, UBYTE features) {
|
||||
BYTE devHead;
|
||||
|
||||
if (!ata_wait_ready(unit,ATA_RDY_WAIT_COUNT))
|
||||
@ -802,7 +803,7 @@ static BYTE write_taskfile_lba(struct IDEUnit *unit, UBYTE command, unsigned lon
|
||||
* @param unit Pointer to an IDEUnit struct
|
||||
* @param lba Pointer to the LBA variable
|
||||
*/
|
||||
static BYTE write_taskfile_lba48(struct IDEUnit *unit, UBYTE command, unsigned long long lba, UBYTE sectorCount, UBYTE features) {
|
||||
static BYTE write_taskfile_lba48(struct IDEUnit *unit, UBYTE command, uint64_t lba, UBYTE sectorCount, UBYTE features) {
|
||||
|
||||
if (!ata_wait_ready(unit,ATA_RDY_WAIT_COUNT))
|
||||
return HFERR_SelTimeout;
|
||||
|
||||
4
ata.h
4
ata.h
@ -110,8 +110,8 @@ bool ata_identify(struct IDEUnit *, UWORD *);
|
||||
bool ata_set_multiple(struct IDEUnit *unit, BYTE multiple);
|
||||
void ata_set_xfer(struct IDEUnit *unit, enum xfer method);
|
||||
|
||||
BYTE ata_read(void *buffer, unsigned long long lba, ULONG count, struct IDEUnit *unit);
|
||||
BYTE ata_write(void *buffer, unsigned long long lba, ULONG count, struct IDEUnit *unit);
|
||||
BYTE ata_read(void *buffer, uint64_t lba, ULONG count, struct IDEUnit *unit);
|
||||
BYTE ata_write(void *buffer, uint64_t lba, ULONG count, struct IDEUnit *unit);
|
||||
BYTE ata_set_pio(struct IDEUnit *unit, UBYTE pio);
|
||||
BYTE scsi_ata_passthrough( struct IDEUnit *unit, struct SCSICmd *cmd);
|
||||
|
||||
|
||||
4
device.h
4
device.h
@ -47,7 +47,7 @@ struct IDEUnit {
|
||||
struct ExecBase *SysBase;
|
||||
struct IOTask *itask;
|
||||
struct Drive drive;
|
||||
BYTE (*write_taskfile)(struct IDEUnit *, UBYTE, unsigned long long, UBYTE, UBYTE);
|
||||
BYTE (*write_taskfile)(struct IDEUnit *, UBYTE, uint64_t, UBYTE, UBYTE);
|
||||
enum xfer xferMethod;
|
||||
ata_xfer_func read_fast;
|
||||
ata_xfer_func write_fast;
|
||||
@ -65,7 +65,7 @@ struct IDEUnit {
|
||||
UWORD blockSize;
|
||||
UWORD blockShift;
|
||||
ULONG cylinders;
|
||||
unsigned long long logicalSectors;
|
||||
uint64_t logicalSectors;
|
||||
struct MinList changeInts;
|
||||
UBYTE multipleCount;
|
||||
struct {
|
||||
|
||||
15
iotask.c
15
iotask.c
@ -111,7 +111,7 @@ static BYTE handle_scsi_command(struct IOStdReq *ioreq) {
|
||||
UBYTE *data = (APTR)scsi_command->scsi_Data;
|
||||
UBYTE *command = (APTR)scsi_command->scsi_Command;
|
||||
|
||||
unsigned long long lba;
|
||||
uint64_t lba;
|
||||
ULONG count;
|
||||
BYTE error = 0;
|
||||
scsi_command->scsi_SenseActual = 0;
|
||||
@ -383,7 +383,8 @@ static void process_ioreq(struct IOTask *itask, struct IOStdReq *ioreq) {
|
||||
struct IOExtTD *iotd;
|
||||
struct IDEUnit *unit;
|
||||
UWORD blockShift;
|
||||
unsigned long long lba;
|
||||
uint64_t lba;
|
||||
ULONG lba_high, lba_low;
|
||||
ULONG count;
|
||||
BYTE error = 0;
|
||||
enum xfer_dir direction = WRITE;
|
||||
@ -483,7 +484,15 @@ transfer:
|
||||
}
|
||||
|
||||
blockShift = ((struct IDEUnit *)ioreq->io_Unit)->blockShift;
|
||||
lba = (((unsigned long long)ioreq->io_Actual << 32 | ioreq->io_Offset) >> blockShift);
|
||||
|
||||
// This looks like a lond-winded way to get the LBA doesn't it?
|
||||
// Splitting up the operation like this results in smaller code size (avoids 64-bit math from libgcc)
|
||||
lba_high = ioreq->io_Actual >> blockShift;
|
||||
lba_low = ioreq->io_Actual << (32 - blockShift);
|
||||
lba_low |= (ioreq->io_Offset >> blockShift);
|
||||
|
||||
lba = ((uint64_t)lba_high << 32 | lba_low);
|
||||
|
||||
count = (ioreq->io_Length >> blockShift);
|
||||
|
||||
if (count == 0) {
|
||||
|
||||
@ -169,7 +169,7 @@ static void DumpUnit(struct IOStdReq *req) {
|
||||
printf("Supports LBA: %s\n", (unit->flags.lba) ? "Yes" : "No");
|
||||
printf("Supports LBA48: %s\n", (unit->flags.lba48) ? "Yes" : "No");
|
||||
printf("C/H/S: %d/%d/%d\n", unit->cylinders, unit->heads, unit->sectorsPerTrack);
|
||||
printf("Logical Sectors: %llu\n", (unsigned long long)unit->logicalSectors);
|
||||
printf("Logical Sectors: %llu\n", (uint64_t)unit->logicalSectors);
|
||||
printf("READ/WRITE Multiple: %s\n", (unit->flags.xferMultiple) ? "Yes" : "No");
|
||||
printf("Multiple count: %d\n", unit->multipleCount);
|
||||
printf("Last Error: ");
|
||||
|
||||
13
scsi.c
13
scsi.c
@ -225,19 +225,8 @@ BYTE scsi_read_capacity_16_emu(struct IDEUnit *unit, struct SCSICmd *scsi_comman
|
||||
return error;
|
||||
}
|
||||
|
||||
struct SCSI_READ_CAPACITY_16 *cdb = (struct SCSI_READ_CAPACITY_16 *)scsi_command->scsi_Command;
|
||||
|
||||
data->block_size = unit->blockSize;
|
||||
|
||||
|
||||
if (cdb->flags & 0x01) {
|
||||
// Partial Medium Indicator - Return end of cylinder
|
||||
// Implement this so HDToolbox stops moaning about track size
|
||||
ULONG spc = unit->sectorsPerTrack * unit->heads;
|
||||
data->lba = (((cdb->lba / spc) + 1) * spc) - 1;
|
||||
} else {
|
||||
data->lba = (unit->logicalSectors) - 1;
|
||||
}
|
||||
data->lba = unit->logicalSectors - 1;
|
||||
|
||||
scsi_command->scsi_Actual = 8;
|
||||
|
||||
|
||||
30
scsi.h
30
scsi.h
@ -72,12 +72,12 @@ struct __attribute__((packed)) SCSI_CDB_10 {
|
||||
};
|
||||
|
||||
struct __attribute__((packed)) SCSI_CDB_16 {
|
||||
UBYTE operation;
|
||||
UBYTE flags;
|
||||
unsigned long long lba;
|
||||
ULONG length;
|
||||
UBYTE group;
|
||||
UBYTE control;
|
||||
UBYTE operation;
|
||||
UBYTE flags;
|
||||
uint64_t lba;
|
||||
ULONG length;
|
||||
UBYTE group;
|
||||
UBYTE control;
|
||||
};
|
||||
|
||||
struct __attribute__((packed)) SCSI_READ_CAPACITY_10 {
|
||||
@ -89,12 +89,12 @@ struct __attribute__((packed)) SCSI_READ_CAPACITY_10 {
|
||||
UBYTE control;
|
||||
};
|
||||
struct __attribute__((packed)) SCSI_READ_CAPACITY_16 {
|
||||
UBYTE operation;
|
||||
UBYTE serviceAction;
|
||||
unsigned long long lba;
|
||||
ULONG allocation;
|
||||
UBYTE flags;
|
||||
UBYTE control;
|
||||
UBYTE operation;
|
||||
UBYTE serviceAction;
|
||||
uint64_t lba;
|
||||
ULONG allocation;
|
||||
UBYTE flags;
|
||||
UBYTE control;
|
||||
};
|
||||
|
||||
struct __attribute__((packed)) SCSI_CAPACITY_10 {
|
||||
@ -103,9 +103,9 @@ struct __attribute__((packed)) SCSI_CAPACITY_10 {
|
||||
};
|
||||
|
||||
struct __attribute__((packed)) SCSI_CAPACITY_16 {
|
||||
unsigned long long lba;
|
||||
ULONG block_size;
|
||||
char reserved[3];
|
||||
uint64_t lba;
|
||||
ULONG block_size;
|
||||
char reserved[3];
|
||||
};
|
||||
|
||||
struct __attribute__((packed)) SCSI_FIXED_SENSE {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user