From 423401f9ea83daffc754864b922f56f06a84cbab Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Thu, 24 Dec 2009 08:31:31 +0000 Subject: 1. Fix bug in some boundary cases to calculate SectorCountExp. 2. Add assertion to ensure the boolean value must be 0 or 1 before the use of array index git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9597 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c index d2a9182..aea6af5 100644 --- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c +++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c @@ -409,6 +409,11 @@ TransferAtaDevice ( EFI_ATA_PASS_THRU_COMMAND_PACKET *Packet; // + // Ensure AtaDevice->Lba48Bit and IsWrite are valid boolean values + // + ASSERT ((UINTN) AtaDevice->Lba48Bit < 2); + ASSERT ((UINTN) IsWrite < 2); + // // Prepare for ATA command block. // Acb = ZeroMem (&AtaDevice->Acb, sizeof (*Acb)); @@ -417,15 +422,15 @@ TransferAtaDevice ( Acb->AtaCylinderLow = (UINT8) RShiftU64 (StartLba, 8); Acb->AtaCylinderHigh = (UINT8) RShiftU64 (StartLba, 16); Acb->AtaDeviceHead = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4)); + Acb->AtaSectorCount = (UINT8) TransferLength; if (AtaDevice->Lba48Bit) { Acb->AtaSectorNumberExp = (UINT8) RShiftU64 (StartLba, 24); + Acb->AtaCylinderLowExp = (UINT8) RShiftU64 (StartLba, 32); + Acb->AtaCylinderHighExp = (UINT8) RShiftU64 (StartLba, 40); + Acb->AtaSectorCountExp = (UINT8) (TransferLength >> 8); } else { Acb->AtaDeviceHead = (UINT8) (Acb->AtaDeviceHead | RShiftU64 (StartLba, 24)); } - Acb->AtaCylinderLowExp = (UINT8) RShiftU64 (StartLba, 32); - Acb->AtaCylinderHighExp = (UINT8) RShiftU64 (StartLba, 40); - Acb->AtaSectorCount = (UINT8) TransferLength; - Acb->AtaSectorCountExp = (UINT8) (TransferLength >> 8); // // Prepare for ATA pass through packet. @@ -475,6 +480,10 @@ AccessAtaDevice( UINTN TransferBlockNumber; UINTN BlockSize; + // + // Ensure AtaDevice->Lba48Bit is a valid boolean value + // + ASSERT ((UINTN) AtaDevice->Lba48Bit < 2); MaxTransferBlockNumber = mMaxTransferBlockNumber[AtaDevice->Lba48Bit]; BlockSize = AtaDevice->BlockMedia.BlockSize; do { -- cgit v1.1