18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * IPRT - Fake asm.h routines for use early in a new port.
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2010-2012 Oracle Corporation
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * available from http://www.virtualbox.org. This file is free software;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * you can redistribute it and/or modify it under the terms of the GNU
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * General Public License (GPL) as published by the Free Software
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * The contents of this file may alternatively be used under the terms
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * of the Common Development and Distribution License Version 1.0
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * VirtualBox OSE distribution, in which case the provisions of the
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * CDDL are applicable instead of those of the GPL.
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * You may elect to license modified versions of this file under the
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * terms and conditions of either the GPL or the CDDL or both.
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync/*******************************************************************************
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync* Header Files *
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync*******************************************************************************/
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint8_t) ASMAtomicXchgU8(volatile uint8_t *pu8, uint8_t u8)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint16_t) ASMAtomicXchgU16(volatile uint16_t *pu16, uint16_t u16)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint32_t) ASMAtomicXchgU32(volatile uint32_t *pu32, uint32_t u32)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint64_t) ASMAtomicXchgU64(volatile uint64_t *pu64, uint64_t u64)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMAtomicCmpXchgU8(volatile uint8_t *pu8, const uint8_t u8New, const uint8_t u8Old)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return true;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return false;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMAtomicCmpXchgU32(volatile uint32_t *pu32, const uint32_t u32New, const uint32_t u32Old)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return true;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return false;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMAtomicCmpXchgU64(volatile uint64_t *pu64, const uint64_t u64New, const uint64_t u64Old)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return true;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return false;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMAtomicCmpXchgExU32(volatile uint32_t *pu32, const uint32_t u32New, const uint32_t u32Old, uint32_t *pu32Old)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return true;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return false;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMAtomicCmpXchgExU64(volatile uint64_t *pu64, const uint64_t u64New, const uint64_t u64Old, uint64_t *pu64Old)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return true;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return false;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint32_t) ASMAtomicAddU32(uint32_t volatile *pu32, uint32_t u32)
847234ba18ff2b8956a9eed6c2f4c3369dc09530vboxsyncRTDECL(uint64_t) ASMAtomicAddU64(uint64_t volatile *pu64, uint64_t u64)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint32_t) ASMAtomicIncU32(uint32_t volatile *pu32)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint32_t) ASMAtomicDecU32(uint32_t volatile *pu32)
847234ba18ff2b8956a9eed6c2f4c3369dc09530vboxsyncRTDECL(uint64_t) ASMAtomicIncU64(uint64_t volatile *pu64)
847234ba18ff2b8956a9eed6c2f4c3369dc09530vboxsyncRTDECL(uint64_t) ASMAtomicDecU64(uint64_t volatile *pu64)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMAtomicOrU32(uint32_t volatile *pu32, uint32_t u32)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMAtomicAndU32(uint32_t volatile *pu32, uint32_t u32)
847234ba18ff2b8956a9eed6c2f4c3369dc09530vboxsyncRTDECL(void) ASMAtomicOrU64(uint64_t volatile *pu64, uint64_t u64)
847234ba18ff2b8956a9eed6c2f4c3369dc09530vboxsyncRTDECL(void) ASMAtomicAndU64(uint64_t volatile *pu64, uint64_t u64)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint64_t) ASMAtomicReadU64(volatile uint64_t *pu64)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint64_t) ASMAtomicUoReadU64(volatile uint64_t *pu64)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync uintptr_t volatile *puPtr = (uintptr_t volatile *)pv;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync while (cbLeft-- > 0)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMMemZero32(volatile void *pv, size_t cb)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync while (cbLeft-- > 0)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMMemFill32(volatile void *pv, size_t cb, uint32_t u32)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync while (cb > 0)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(uint8_t) ASMProbeReadByte(const void *pvByte)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMBitSet(volatile void *pvBitmap, int32_t iBit)
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync uint8_t volatile *pau8Bitmap = (uint8_t volatile *)pvBitmap;
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync pau8Bitmap[iBit / 8] |= (uint8_t)RT_BIT_32(iBit & 7);
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMAtomicBitSet(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMBitClear(volatile void *pvBitmap, int32_t iBit)
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync uint8_t volatile *pau8Bitmap = (uint8_t volatile *)pvBitmap;
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync pau8Bitmap[iBit / 8] &= ~((uint8_t)RT_BIT_32(iBit & 7));
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMAtomicBitClear(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMBitToggle(volatile void *pvBitmap, int32_t iBit)
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync uint8_t volatile *pau8Bitmap = (uint8_t volatile *)pvBitmap;
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync pau8Bitmap[iBit / 8] ^= (uint8_t)RT_BIT_32(iBit & 7);
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(void) ASMAtomicBitToggle(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMBitTestAndSet(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return true;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return false;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMAtomicBitTestAndSet(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMBitTestAndClear(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return false;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return true;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMAtomicBitTestAndClear(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMBitTestAndToggle(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMAtomicBitTestAndToggle(volatile void *pvBitmap, int32_t iBit)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(bool) ASMBitTest(const volatile void *pvBitmap, int32_t iBit)
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync uint8_t volatile *pau8Bitmap = (uint8_t volatile *)pvBitmap;
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync return pau8Bitmap[iBit / 8] & (uint8_t)RT_BIT_32(iBit & 7) ? true : false;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(int) ASMBitFirstClear(const volatile void *pvBitmap, uint32_t cBits)
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync uint8_t volatile *pu8 = (uint8_t volatile *)pvBitmap;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(int) ASMBitNextClear(const volatile void *pvBitmap, uint32_t cBits, uint32_t iBitPrev)
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync const volatile uint8_t *pau8Bitmap = (const volatile uint8_t *)pvBitmap;
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync * Inspect the byte containing the unaligned bit.
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * Skip ahead and see if there is anything left to search.
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync * Byte search, let ASMBitFirstClear do the dirty work.
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync iBit = ASMBitFirstClear(&pau8Bitmap[iBitPrev / 8], cBits - iBitPrev);
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(int) ASMBitFirstSet(const volatile void *pvBitmap, uint32_t cBits)
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync uint8_t volatile *pu8 = (uint8_t volatile *)pvBitmap;
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsyncRTDECL(int) ASMBitNextSet(const volatile void *pvBitmap, uint32_t cBits, uint32_t iBitPrev)
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync const volatile uint8_t *pau8Bitmap = (const volatile uint8_t *)pvBitmap;
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync * Inspect the byte containing the unaligned bit.
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync * Skip ahead and see if there is anything left to search.
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync * Byte search, let ASMBitFirstSet do the dirty work.
64b8465fceed06d9ce44e9b3c6ba1367c9f09e08vboxsync iBit = ASMBitFirstSet(&pau8Bitmap[iBitPrev / 8], cBits - iBitPrev);
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync while (iBit-- > 0)
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16));
18c326c55a02b14ef381355b52a03b94dd36ea70vboxsync return RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32));
91c1a72ba0b6ccd8c9babda0928be38202073becvboxsync return RT_MAKE_U64_FROM_U8(RT_BYTE8(u64), RT_BYTE7(u64), RT_BYTE6(u64), RT_BYTE5(u64),