1
0
Fork 0

some big endian improvents and drive_fat fixes. (jmarsh)

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4330
This commit is contained in:
Peter Veenstra 2020-02-22 12:06:40 +00:00
parent fd11108206
commit 57bf045cc8
2 changed files with 75 additions and 38 deletions

View file

@ -57,20 +57,39 @@ MemHandle MEM_NextHandleAt(MemHandle handle,Bitu where);
Working on big or little endian machines
*/
#if defined(WORDS_BIGENDIAN) || !defined(C_UNALIGNED_MEMORY)
static INLINE Bit8u host_readb(HostPt off) {
return off[0];
}
static INLINE void host_writeb(HostPt off,Bit8u val) {
off[0]=val;
}
// use __builtin_bswap* for gcc >= 4.3
#if defined(WORDS_BIGENDIAN) && defined(__GNUC__) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
static INLINE Bit16u host_readw(HostPt off) {
return __builtin_bswap16(*(Bit16u *)off);
}
static INLINE Bit32u host_readd(HostPt off) {
return __builtin_bswap32(*(Bit32u *)off);
}
static INLINE void host_writew(HostPt off, Bit16u val) {
*(Bit16u *)off = __builtin_bswap16(val);
}
static INLINE void host_writed(HostPt off, Bit32u val) {
*(Bit32u *)off = __builtin_bswap32(val);
}
#elif defined(WORDS_BIGENDIAN) || !defined(C_UNALIGNED_MEMORY)
static INLINE Bit16u host_readw(HostPt off) {
return off[0] | (off[1] << 8);
}
static INLINE Bit32u host_readd(HostPt off) {
return off[0] | (off[1] << 8) | (off[2] << 16) | (off[3] << 24);
}
static INLINE void host_writeb(HostPt off,Bit8u val) {
off[0]=val;
}
static INLINE void host_writew(HostPt off,Bit16u val) {
off[0]=(Bit8u)(val);
off[1]=(Bit8u)(val >> 8);
@ -84,18 +103,12 @@ static INLINE void host_writed(HostPt off,Bit32u val) {
#else
static INLINE Bit8u host_readb(HostPt off) {
return *(Bit8u *)off;
}
static INLINE Bit16u host_readw(HostPt off) {
return *(Bit16u *)off;
}
static INLINE Bit32u host_readd(HostPt off) {
return *(Bit32u *)off;
}
static INLINE void host_writeb(HostPt off,Bit8u val) {
*(Bit8u *)(off)=val;
}
static INLINE void host_writew(HostPt off,Bit16u val) {
*(Bit16u *)(off)=val;
}
@ -118,6 +131,14 @@ static INLINE void var_write(Bit32u * var, Bit32u val) {
host_writed((HostPt)var, val);
}
static INLINE Bit16u var_read(Bit16u * var) {
return host_readw((HostPt)var);
}
static INLINE Bit32u var_read(Bit32u * var) {
return host_readd((HostPt)var);
}
/* The Folowing six functions are slower but they recognize the paged memory system */
Bit8u mem_readb(PhysPt pt);

View file

@ -223,20 +223,12 @@ bool fatFile::Write(Bit8u * data, Bit16u *size) {
if(loadedSector) myDrive->writeSector(currentSector, sectorBuffer);
currentSector = myDrive->getAbsoluteSectFromBytePos(firstCluster, seekpos);
if(currentSector == 0) {
/* EOC reached before EOF - try to increase file allocation */
myDrive->appendCluster(firstCluster);
/* Try getting sector again */
currentSector = myDrive->getAbsoluteSectFromBytePos(firstCluster, seekpos);
if(currentSector == 0) {
/* No can do. lets give up and go home. We must be out of room */
loadedSector = false;
goto finalizeWrite;
}
if(currentSector == 0) loadedSector = false;
else {
curSectOff = 0;
myDrive->readSector(currentSector, sectorBuffer);
loadedSector = true;
}
curSectOff = 0;
myDrive->readSector(currentSector, sectorBuffer);
loadedSector = true;
}
--sizedec;
}
@ -333,7 +325,7 @@ Bit32u fatDrive::getClusterValue(Bit32u clustNum) {
switch(fattype) {
case FAT12:
clustValue = *((Bit16u *)&fatSectBuffer[fatentoff]);
clustValue = var_read((Bit16u *)&fatSectBuffer[fatentoff]);
if(clustNum & 0x1) {
clustValue >>= 4;
} else {
@ -341,10 +333,10 @@ Bit32u fatDrive::getClusterValue(Bit32u clustNum) {
}
break;
case FAT16:
clustValue = *((Bit16u *)&fatSectBuffer[fatentoff]);
clustValue = var_read((Bit16u *)&fatSectBuffer[fatentoff]);
break;
case FAT32:
clustValue = *((Bit32u *)&fatSectBuffer[fatentoff]);
clustValue = var_read((Bit32u *)&fatSectBuffer[fatentoff]);
break;
}
@ -380,7 +372,7 @@ void fatDrive::setClusterValue(Bit32u clustNum, Bit32u clustValue) {
switch(fattype) {
case FAT12: {
Bit16u tmpValue = *((Bit16u *)&fatSectBuffer[fatentoff]);
Bit16u tmpValue = var_read((Bit16u *)&fatSectBuffer[fatentoff]);
if(clustNum & 0x1) {
clustValue &= 0xfff;
clustValue <<= 4;
@ -392,14 +384,14 @@ void fatDrive::setClusterValue(Bit32u clustNum, Bit32u clustValue) {
tmpValue &= 0xf000;
tmpValue |= (Bit16u)clustValue;
}
*((Bit16u *)&fatSectBuffer[fatentoff]) = tmpValue;
var_write((Bit16u *)&fatSectBuffer[fatentoff], tmpValue);
break;
}
case FAT16:
*((Bit16u *)&fatSectBuffer[fatentoff]) = (Bit16u)clustValue;
var_write((Bit16u *)&fatSectBuffer[fatentoff], (Bit16u)clustValue);
break;
case FAT32:
*((Bit32u *)&fatSectBuffer[fatentoff]) = clustValue;
var_write((Bit32u *)&fatSectBuffer[fatentoff], clustValue);
break;
}
for(int fc=0;fc<bootbuffer.fatcopies;fc++) {
@ -731,6 +723,8 @@ fatDrive::fatDrive(const char *sysFilename, Bit32u bytesector, Bit32u cylsector,
for(m=0;m<4;m++) {
/* Pick the first available partition */
if(mbrData.pentry[m].partSize != 0x00) {
mbrData.pentry[m].absSectStart = var_read(&mbrData.pentry[m].absSectStart);
mbrData.pentry[m].partSize = var_read(&mbrData.pentry[m].partSize);
LOG_MSG("Using partition %d on drive; skipping %d sectors", m, mbrData.pentry[m].absSectStart);
startSector = mbrData.pentry[m].absSectStart;
break;
@ -755,6 +749,16 @@ fatDrive::fatDrive(const char *sysFilename, Bit32u bytesector, Bit32u cylsector,
loadedDisk->Read_AbsoluteSector(0+partSectOff,&bootbuffer);
bootbuffer.bytespersector = var_read(&bootbuffer.bytespersector);
bootbuffer.reservedsectors = var_read(&bootbuffer.reservedsectors);
bootbuffer.rootdirentries = var_read(&bootbuffer.rootdirentries);
bootbuffer.totalsectorcount = var_read(&bootbuffer.totalsectorcount);
bootbuffer.sectorsperfat = var_read(&bootbuffer.sectorsperfat);
bootbuffer.sectorspertrack = var_read(&bootbuffer.sectorspertrack);
bootbuffer.headcount = var_read(&bootbuffer.headcount);
bootbuffer.hiddensectorcount = var_read(&bootbuffer.hiddensectorcount);
bootbuffer.totalsecdword = var_read(&bootbuffer.totalsecdword);
if (!is_hdd) {
/* Identify floppy format */
if ((bootbuffer.nearjmp[0] == 0x69 || bootbuffer.nearjmp[0] == 0xe9 ||
@ -1039,6 +1043,18 @@ char* trimString(char* str) {
return removeTrailingSpaces(removeLeadingSpaces(str));
}
static void copyDirEntry(const direntry *src, direntry *dst) {
memcpy(dst, src, 14); // single byte fields
var_write(&dst->crtTime, src->crtTime);
var_write(&dst->crtDate, src->crtDate);
var_write(&dst->accessDate, src->accessDate);
var_write(&dst->hiFirstClust, src->hiFirstClust);
var_write(&dst->modTime, src->modTime);
var_write(&dst->modDate, src->modDate);
var_write(&dst->loFirstClust, src->loFirstClust);
var_write(&dst->entrysize, src->entrysize);
}
bool fatDrive::FindNextInternal(Bit32u dirClustNumber, DOS_DTA &dta, direntry *foundEntry) {
direntry sectbuf[16]; /* 16 directory entries per sector */
Bit32u logentsector; /* Logical entry sector */
@ -1110,11 +1126,11 @@ nextfile:
/* Compare name to search pattern */
if(!WildFileCmp(find_name,srch_pattern)) goto nextfile;
//dta.SetResult(find_name, sectbuf[entryoffset].entrysize, sectbuf[entryoffset].crtDate, sectbuf[entryoffset].crtTime, sectbuf[entryoffset].attrib);
copyDirEntry(&sectbuf[entryoffset], foundEntry);
dta.SetResult(find_name, sectbuf[entryoffset].entrysize, sectbuf[entryoffset].modDate, sectbuf[entryoffset].modTime, sectbuf[entryoffset].attrib);
//dta.SetResult(find_name, foundEntry->entrysize, foundEntry->crtDate, foundEntry->crtTime, foundEntry->attrib);
memcpy(foundEntry, &sectbuf[entryoffset], sizeof(direntry));
dta.SetResult(find_name, foundEntry->entrysize, foundEntry->modDate, foundEntry->modTime, foundEntry->attrib);
return true;
}
@ -1189,7 +1205,7 @@ bool fatDrive::directoryBrowse(Bit32u dirClustNumber, direntry *useEntry, Bit32s
--entNum;
}
memcpy(useEntry, &sectbuf[entryoffset],sizeof(direntry));
copyDirEntry(&sectbuf[entryoffset], useEntry);
return true;
}
@ -1223,9 +1239,9 @@ bool fatDrive::directoryChange(Bit32u dirClustNumber, direntry *useEntry, Bit32s
--entNum;
}
if(tmpsector != 0) {
memcpy(&sectbuf[entryoffset], useEntry, sizeof(direntry));
copyDirEntry(useEntry, &sectbuf[entryoffset]);
writeSector(tmpsector, sectbuf);
return true;
return true;
} else {
return false;
}
@ -1264,7 +1280,7 @@ bool fatDrive::addDirectoryEntry(Bit32u dirClustNumber, direntry useEntry) {
/* Deleted file entry or end of directory list */
if ((sectbuf[entryoffset].entryname[0] == 0xe5) || (sectbuf[entryoffset].entryname[0] == 0x00)) {
sectbuf[entryoffset] = useEntry;
copyDirEntry(&useEntry, &sectbuf[entryoffset]);
writeSector(tmpsector,sectbuf);
break;
}