From: bxing Date: Mon, 10 Jul 2006 02:56:56 +0000 (+0000) Subject: 1. Fixed a logical error in PciReadBuffer() and PciWriteBuffer() X-Git-Tag: edk2-stable201903~25000 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=9748aecca6cad6a4a1782b415445d086af4e2bba 1. Fixed a logical error in PciReadBuffer() and PciWriteBuffer() 2. Fixed GetInterruptState() on IPF to return the state of interrupts correctly git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@850 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdePkg/Library/BaseLib/Ipf/GetInterruptState.s b/MdePkg/Library/BaseLib/Ipf/GetInterruptState.s index 66eb17f3df..d5b5fc852f 100644 --- a/MdePkg/Library/BaseLib/Ipf/GetInterruptState.s +++ b/MdePkg/Library/BaseLib/Ipf/GetInterruptState.s @@ -22,6 +22,6 @@ .type GetInterruptState, @function GetInterruptState:: mov r8 = psr - dep.z r8 = r8, 14, 1 + extr.u r8 = r8, 14, 1 br.ret.sptk.many b0 .endp GetInterruptState diff --git a/MdePkg/Library/BasePciCf8Lib/PciLib.c b/MdePkg/Library/BasePciCf8Lib/PciLib.c index 9421d8b99d..ca9b17abe2 100644 --- a/MdePkg/Library/BasePciCf8Lib/PciLib.c +++ b/MdePkg/Library/BasePciCf8Lib/PciLib.c @@ -1295,18 +1295,21 @@ PciCf8ReadBuffer ( OUT VOID *Buffer ) { - UINTN EndAddress; + UINTN ReturnValue; - ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0); + ASSERT_INVALID_PCI_ADDRESS (StartAddress); ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100); if (Size == 0) { - return 0; + return Size; } ASSERT (Buffer != NULL); - EndAddress = StartAddress + Size; + // + // Save Size for return + // + ReturnValue = Size; if ((StartAddress & 1) != 0) { // @@ -1314,44 +1317,48 @@ PciCf8ReadBuffer ( // *(UINT8*)Buffer = PciCf8Read8 (StartAddress); StartAddress += sizeof (UINT8); + Size -= sizeof (UINT8); Buffer = (UINT8*)Buffer + 1; } - if ((StartAddress < EndAddress) && ((StartAddress & 2) != 0)) { + if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) { // // Read a word if StartAddress is word aligned // *(UINT16*)Buffer = PciCf8Read16 (StartAddress); StartAddress += sizeof (UINT16); + Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; } - while ((EndAddress - StartAddress) >= 4) { + while (Size >= sizeof (UINT32)) { // // Read as many double words as possible // *(UINT32*)Buffer = PciCf8Read32 (StartAddress); StartAddress += sizeof (UINT32); + Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; } - if ((EndAddress & 2) != 0) { + if (Size >= sizeof (UINT16)) { // // Read the last remaining word if exist // *(UINT16*)Buffer = PciCf8Read16 (StartAddress); StartAddress += sizeof (UINT16); + Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; } - if ((EndAddress & 1) != 0) { + if (Size >= sizeof (UINT8)) { // // Read the last remaining byte if exist // *(UINT8*)Buffer = PciCf8Read8 (StartAddress); } - return Size; + return ReturnValue; } /** @@ -1387,61 +1394,68 @@ PciCf8WriteBuffer ( IN VOID *Buffer ) { - UINTN EndAddress; + UINTN ReturnValue; - ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0); + ASSERT_INVALID_PCI_ADDRESS (StartAddress); ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100); if (Size == 0) { return 0; } - ASSERT (Buffer != 0); + ASSERT (Buffer != NULL); - EndAddress = StartAddress + Size; + // + // Save Size for return + // + ReturnValue = Size; - if ((StartAddress & 1)!= 0) { + if ((StartAddress & 1) != 0) { // // Write a byte if StartAddress is byte aligned // PciCf8Write8 (StartAddress, *(UINT8*)Buffer); StartAddress += sizeof (UINT8); + Size -= sizeof (UINT8); Buffer = (UINT8*)Buffer + 1; } - if ((StartAddress < EndAddress) && ((StartAddress & 2) != 0)) { + if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) { // // Write a word if StartAddress is word aligned // PciCf8Write16 (StartAddress, *(UINT16*)Buffer); StartAddress += sizeof (UINT16); + Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; } - while ((EndAddress - StartAddress) >= 4) { + while (Size >= sizeof (UINT32)) { // // Write as many double words as possible // PciCf8Write32 (StartAddress, *(UINT32*)Buffer); StartAddress += sizeof (UINT32); + Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; } - if ((EndAddress & 2) != 0) { + if (Size >= sizeof (UINT16)) { // // Write the last remaining word if exist // PciCf8Write16 (StartAddress, *(UINT16*)Buffer); StartAddress += sizeof (UINT16); + Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; } - if ((EndAddress & 1) != 0) { + if (Size >= sizeof (UINT8)) { // // Write the last remaining byte if exist // PciCf8Write8 (StartAddress, *(UINT8*)Buffer); } - return Size; + return ReturnValue; } diff --git a/MdePkg/Library/BasePciExpressLib/PciLib.c b/MdePkg/Library/BasePciExpressLib/PciLib.c index acd3103483..771c18f811 100644 --- a/MdePkg/Library/BasePciExpressLib/PciLib.c +++ b/MdePkg/Library/BasePciExpressLib/PciLib.c @@ -1192,18 +1192,21 @@ PciExpressReadBuffer ( OUT VOID *Buffer ) { - UINTN EndAddress; + UINTN ReturnValue; ASSERT_INVALID_PCI_ADDRESS (StartAddress); ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000); if (Size == 0) { - return 0; + return Size; } ASSERT (Buffer != NULL); - EndAddress = StartAddress + Size; + // + // Save Size for return + // + ReturnValue = Size; if ((StartAddress & 1) != 0) { // @@ -1211,44 +1214,48 @@ PciExpressReadBuffer ( // *(UINT8*)Buffer = PciExpressRead8 (StartAddress); StartAddress += sizeof (UINT8); + Size -= sizeof (UINT8); Buffer = (UINT8*)Buffer + 1; } - if ((StartAddress < EndAddress) && ((StartAddress & 2) != 0)) { + if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) { // // Read a word if StartAddress is word aligned // *(UINT16*)Buffer = PciExpressRead16 (StartAddress); StartAddress += sizeof (UINT16); + Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; } - while ((EndAddress - StartAddress) >= 4) { + while (Size >= sizeof (UINT32)) { // // Read as many double words as possible // *(UINT32*)Buffer = PciExpressRead32 (StartAddress); StartAddress += sizeof (UINT32); + Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; } - if ((EndAddress & 2) != 0) { + if (Size >= sizeof (UINT16)) { // // Read the last remaining word if exist // *(UINT16*)Buffer = PciExpressRead16 (StartAddress); StartAddress += sizeof (UINT16); + Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; } - if ((EndAddress & 1) != 0) { + if (Size >= sizeof (UINT8)) { // // Read the last remaining byte if exist // *(UINT8*)Buffer = PciExpressRead8 (StartAddress); } - return Size; + return ReturnValue; } /** @@ -1283,7 +1290,7 @@ PciExpressWriteBuffer ( IN VOID *Buffer ) { - UINTN EndAddress; + UINTN ReturnValue; ASSERT_INVALID_PCI_ADDRESS (StartAddress); ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000); @@ -1294,7 +1301,10 @@ PciExpressWriteBuffer ( ASSERT (Buffer != NULL); - EndAddress = StartAddress + Size; + // + // Save Size for return + // + ReturnValue = Size; if ((StartAddress & 1) != 0) { // @@ -1302,42 +1312,46 @@ PciExpressWriteBuffer ( // PciExpressWrite8 (StartAddress, *(UINT8*)Buffer); StartAddress += sizeof (UINT8); + Size -= sizeof (UINT8); Buffer = (UINT8*)Buffer + 1; } - if ((StartAddress < EndAddress) && ((StartAddress & 2) != 0)) { + if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) { // // Write a word if StartAddress is word aligned // PciExpressWrite16 (StartAddress, *(UINT16*)Buffer); StartAddress += sizeof (UINT16); + Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; } - while ((EndAddress - StartAddress) >= 4) { + while (Size >= sizeof (UINT32)) { // // Write as many double words as possible // PciExpressWrite32 (StartAddress, *(UINT32*)Buffer); StartAddress += sizeof (UINT32); + Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; } - if ((EndAddress & 2) != 0) { + if (Size >= sizeof (UINT16)) { // // Write the last remaining word if exist // PciExpressWrite16 (StartAddress, *(UINT16*)Buffer); StartAddress += sizeof (UINT16); + Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; } - if ((EndAddress & 1) != 0) { + if (Size >= sizeof (UINT8)) { // // Write the last remaining byte if exist // PciExpressWrite8 (StartAddress, *(UINT8*)Buffer); } - return Size; + return ReturnValue; }