ctr_firmware/trunk/bootrom/include/brom/mi/memory.h
nakasima 0501947d93 MIライブラリ追加。
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@118 b871894f-2f95-9b40-918c-086798483c85
2008-12-17 11:04:24 +00:00

717 lines
28 KiB
C

/*---------------------------------------------------------------------------*
Project: CtrBrom - MI - include
File: memory.h
Copyright 2008 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Date:: $
$Rev$
$Author$
*---------------------------------------------------------------------------*/
#ifndef BROM_MI_MEMORY_H_
#define BROM_MI_MEMORY_H_
#include <brom/misc.h>
#include <brom/types.h>
#ifdef __cplusplus
extern "C" {
#endif
//======================================================================
void i_miCpuClear16(u16 data, void *destp, u32 size);
void i_miCpuCopy16(const void *srcp, void *destp, u32 size);
void i_miCpuSend16(const void *srcp, volatile void *destp, u32 size);
void i_miCpuRecv16(volatile const void *srcp, void *destp, u32 size);
void i_miCpuPipe16(volatile const void *srcp, volatile void *destp, u32 size);
void i_miCpuMove16(const void *src, void *dest, u32 size);
void* i_miCpuFind16(const void *src, u16 data, u32 size);
int i_miCpuComp16(const void *mem1, const void *mem2, u32 size);
void i_miCpuClear32(u32 data, void *destp, u32 size);
void i_miCpuCopy32(const void *srcp, void *destp, u32 size);
void i_miCpuSend32(const void *srcp, volatile void *destp, u32 size);
void i_miCpuRecv32(volatile const void *srcp, void *destp, u32 size);
void i_miCpuPipe32(volatile const void *srcp, volatile void *destp, u32 size);
void i_miCpuMove32(const void *src, void *dest, u32 size);
void* i_miCpuFind32(const void *src, u32 data, u32 size);
int i_miCpuComp32(const void *mem1, const void *mem2, u32 size);
void i_miCpuClearFast(u32 data, void *destp, u32 size);
void i_miCpuCopyFast(const void *srcp, void *destp, u32 size);
void i_miCpuSendFast(const void *srcp, volatile void *destp, u32 size);
void i_miCpuRecvFast(volatile const void *srcp, void *destp, u32 size);
void i_miCpuMoveFast(const void *src, void *dest, u32 size);
//================================================================================
// 32 bit version
//================================================================================
/*---------------------------------------------------------------------------*
Name: miCpuFill32
Description: fill memory with specified data. (32 bit version)
Arguments: dest : destination address to fill data, must be in 4 byte alignment
data : data to fill
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuFill32(void *dest, u32 data, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuClear32(data, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuCopy32
Description: copy memory data (32 bit version)
Arguments: src : source address, must be in 4 byte alignment
dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuCopy32(const void *src, void *dest, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuCopy32(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuClear32
Description: fill memory with 0 (32 bit version)
Arguments: dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuClear32(void *dest, u32 size)
{
miCpuFill32(dest, 0, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuSend32
Description: write some data to fixed address (32 bit version)
Arguments: src : source address, must be in 4 byte alignment
dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuSend32(const void *src, volatile void *dest, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuSend32(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuRecv32
Description: receive u32 data from fixed address
32bit version
Arguments: src : source address. not incremented
dest : data buffer to receive
size : size (byte)
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuRecv32(volatile const void *src, void *dest, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuRecv32(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuPipe32
Description: pipe data from fixed address to fixed address.
32bit version
Arguments: src : source address. not incremented
dest : destination address. not incremented
size : size (byte)
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuPipe32(volatile const void *src, volatile void *dest, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuPipe32(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuMove32
Description: move memory data (32 bit version)
Arguments: src : source address, must be in 4 byte alignment
dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuMove32(const void *src, void *dest, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuMove32(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuFind32
Description: find memory data (32 bit version)
Arguments: src : source address, must be in 4 byte alignment
data : target data
size : size (byte), must be in 4 byte alignment
Returns: pointer to found data or NULL.
*---------------------------------------------------------------------------*/
static inline void* miCpuFind32(const void *src, u32 data, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
return i_miCpuFind32(src, data, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuComp32
Description: compare memory data (32 bit version)
Arguments: mem1 : target address 1, must be in 4 byte alignment
mem2 : target address 2, must be in 4 byte alignment
size : size (byte), must be in 4 byte alignment
Returns: < 0 : mem1 smaller than mem2
= 0 : mem1 equals mem2
> 0 : mem1 larger than mem2
*---------------------------------------------------------------------------*/
static inline int miCpuComp32(const void *mem1, const void *mem2, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)mem1 & 3) == 0, "target address 1 must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)mem2 & 3) == 0, "target address 2 must be in 4-byte alignment");
return i_miCpuComp32(mem1, mem2, size);
}
//================================================================================
// 16 bit version
//================================================================================
/*---------------------------------------------------------------------------*
Name: miCpuFill16
Description: fill memory with specified data. (16 bit version)
Arguments: dest : destination address to fill data, must be in 2 byte alignment
data : data to fill
size : size (byte), must be in 2 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuFill16(void *dest, u16 data, u32 size)
{
SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0");
SDK_ASSERTMSG(((u32)dest & 1) == 0, "source address must be in 2-byte alignment");
i_miCpuClear16(data, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuCopy16
Description: copy memory data (16 bit version)
Arguments: src : source address, must be in 2 byte alignment
dest : destination address, must be in 2 byte alignment
size : size (byte), must be in 2 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuCopy16(const void *src, void *dest, u32 size)
{
SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0");
SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment");
SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment");
i_miCpuCopy16(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuClear16
Description: fill memory with 0 (16 bit version)
Arguments: dest : destination address, must be in 2 byte alignment
size : size (byte), must be in 2 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuClear16(void *dest, u32 size)
{
miCpuFill16(dest, 0, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuSend16
Description: write some data to fixed address (16 bit version)
Arguments: src : source address, must be in 2 byte alignment
dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 2 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuSend16(const void *src, volatile void *dest, u32 size)
{
SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0");
SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment");
SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment");
i_miCpuSend16(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuRecv16
Description: receive u16 data from fixed address
16bit version
Arguments: src : source address. not incremented
dest : data buffer to receive
size : size (byte)
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuRecv16(volatile const void *src, void *dest, u32 size)
{
SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0");
SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment");
SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment");
i_miCpuRecv16(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuRecv16
Description: pipe data from fixed address to fixed address.
16bit version
Arguments: src : source address. not incremented
dest : destination address. not incremented
size : size (byte)
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuPipe16(volatile const void *src, volatile void *dest, u32 size)
{
SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0");
SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment");
SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment");
i_miCpuPipe16(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuMove16
Description: move memory data (16 bit version)
Arguments: src : source address, must be in 2 byte alignment
dest : destination address, must be in 2 byte alignment
size : size (byte), must be in 2 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuMove16(const void *src, void *dest, u32 size)
{
SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0");
SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment");
SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment");
i_miCpuMove16(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuFind16
Description: find memory data (16 bit version)
Arguments: src : source address, must be in 2 byte alignment
data : target data
size : size (byte), must be in 2 byte alignment
Returns: pointer to found data or NULL.
*---------------------------------------------------------------------------*/
static inline void* miCpuFind16(const void *src, u16 data, u32 size)
{
SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0");
SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment");
return i_miCpuFind16(src, data, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuComp16
Description: compare memory data (16 bit version)
Arguments: mem1 : target address 1, must be in 2 byte alignment
mem2 : target address 2, must be in 2 byte alignment
size : size (byte), must be in 2 byte alignment
Returns: < 0 : mem1 smaller than mem2
= 0 : mem1 equals mem2
> 0 : mem1 larger than mem2
*---------------------------------------------------------------------------*/
static inline int miCpuComp16(const void *mem1, const void *mem2, u32 size)
{
SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0");
SDK_ASSERTMSG(((u32)mem1 & 1) == 0, "target address 1 must be in 2-byte alignment");
SDK_ASSERTMSG(((u32)mem2 & 1) == 0, "target address 2 must be in 2-byte alignment");
return i_miCpuComp16(mem1, mem2, size);
}
//================================================================================
// 32 byte unit version
//================================================================================
/*---------------------------------------------------------------------------*
Name: miCpuFillFast
Description: fill memory with specified data quickly. (32 byte unit version)
Arguments: dest : destination address to fill data
data : data to fill
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuFillFast(void *dest, u32 data, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "source address must be in 4-byte alignment");
i_miCpuClearFast(data, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuCopyFast
Description: copy memory data quickly (32 byte unit version)
Arguments: src : source address, must be in 4 byte alignment
dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuCopyFast(const void *src, void *dest, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuCopyFast(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuClearFast
Description: fill memory with 0 quickly (32 byte unit version)
Arguments: dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 4-byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuClearFast(void *dest, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
miCpuFillFast(dest, 0, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuSendFast
Description: move memory data (32 byte unit version)
Arguments: src : data stream to send
dest : destination address, not incremented
size : size (byte)
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuSendFast( register const void *src, register volatile void *dest, register u32 size )
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuSendFast(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuRecvFast
Description: move memory data (32 byte unit version)
Arguments: src : source address. not incremented
dest : data buffer to receive
size : size (byte)
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuRecvFast(volatile const void *src, register void *dest, register u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuRecvFast(src, dest, size);
}
/*---------------------------------------------------------------------------*
Name: miCpuMoveFast
Description: move memory data (32 byte unit version)
Arguments: src : source address, must be in 4 byte alignment
dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuMoveFast(const void *src, void *dest, u32 size)
{
SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0");
SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment");
SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment");
i_miCpuMoveFast(src, dest, size);
}
//================================================================================
// 8 bit version
//================================================================================
/*---------------------------------------------------------------------------*
Name: miCpuFill8
Description: fill memory with specified data. (8 bit version)
Arguments: dest : destination address to fill data, no limitation for alignment
data : data to fill
size : size (byte), no limitation for alignment
Returns: None
*---------------------------------------------------------------------------*/
void miCpuFill8(void *dest, u8 data, u32 size);
/*---------------------------------------------------------------------------*
Name: miCpuCopy8
Description: copy memory data (8 bit version)
Arguments: src : source address, no limitation for alignment
dest : destination address, no limitation for alignment
size : size (byte), no limitation for alignment
Returns: None
*---------------------------------------------------------------------------*/
void miCpuCopy8(const void *src, void *dest, u32 size);
/*---------------------------------------------------------------------------*
Name: miCpuFind8
Description: find memory data (8 bit version)
Arguments: src : source address, no limitation for alignment
data : target data
size : size (byte), no limitation for alignment
Returns: pointer to found data or NULL.
*---------------------------------------------------------------------------*/
void* miCpuFind8(const void *src, u8 data, u32 size);
/*---------------------------------------------------------------------------*
Name: miCpuComp8
Description: compare memory data (8 bit version)
Arguments: mem1 : target address 1, no limitation for alignment
mem2 : target address 2, no limitation for alignment
size : size (byte), no limitation for alignment
Returns: < 0 : mem1 smaller than mem2
= 0 : mem1 equals mem2
> 0 : mem1 larger than mem2
*---------------------------------------------------------------------------*/
int miCpuComp8(const void *mem1, const void *mem2, u32 size);
/*---------------------------------------------------------------------------*
Name: miCpuClear8
Description: fill memory with 0 (8 bit version)
Arguments: dest : destination address, no limitation for alignment
size : size (byte), no limitation for alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuClear8(void *dest, u32 size)
{
miCpuFill8(dest, 0, size);
}
//================================================================================
// 32 bit version
//================================================================================
/*---------------------------------------------------------------------------*
Name: miReadWord
Description: read 32 bit data from specified address
Arguments: adrs : address to read
Returns: data which is read
*---------------------------------------------------------------------------*/
#ifndef SDK_ASM
#define miReadWord( adrs ) (*(vu32 *)(adrs))
#endif
/*---------------------------------------------------------------------------*
Name: miWriteWord
Description: write 32 bit data to specified adress
Arguments: adrs : address to write
val : data to write
Returns: None
*---------------------------------------------------------------------------*/
#ifndef SDK_ASM
#define miWriteWord( adrs, val ) do { (*(vu32 *)(adrs)) = (u32)(val); } while(0)
#endif
//================================================================================
// mixed version
//================================================================================
/*---------------------------------------------------------------------------*
Name: miCpuFill
Description: fill memory with specified data. (mixed version)
Arguments: dest : destination address to fill data, no limitation for alignment
data : data to fill
size : size (byte), no limitation for alignment
Returns: None
*---------------------------------------------------------------------------*/
void miCpuFill(void *dest, u8 data, u32 size);
/*---------------------------------------------------------------------------*
Name: miCpuCopy
Description: copy memory data (mixed version)
Arguments: src : source address, no limitation for alignment
dest : destination address, no limitation for alignment
size : size (byte), no limitation for alignment
Returns: None
*---------------------------------------------------------------------------*/
void miCpuCopy(const void *srcp, void *destp, u32 size);
/*---------------------------------------------------------------------------*
Name: miCpuMove
Description: move memory data (mixed version)
Arguments: src : source address, must be in 4 byte alignment
dest : destination address, must be in 4 byte alignment
size : size (byte), must be in 4 byte alignment
Returns: None
*---------------------------------------------------------------------------*/
void miCpuMove(const void *srcp, void *destp, u32 size);
/*---------------------------------------------------------------------------*
Name: miCpuClear
Description: fill memory with 0 (mixed version)
Arguments: dest : destination address, no limitation for alignment
size : size (byte), no limitation for alignment
Returns: None
*---------------------------------------------------------------------------*/
static inline void miCpuClear(void *dest, u32 size)
{
miCpuFill(dest, 0, size);
}
//================================================================================
// the following functions are prepared for SDK private use.
// don't use in application thoughtlessly
//================================================================================
void miCopy16B(register const void *pSrc, register void *pDest);
void miCopy32B(register const void *pSrc, register void *pDest);
void miCopy36B(register const void *pSrc, register void *pDest);
void miCopy48B(register const void *pSrc, register void *pDest);
void miCopy64B(register const void *pSrc, register void *pDest);
void miCopy128B(register const void *pSrc, register void *pDest);
void miZero32B(register void *pDest);
void miZero36B(register void *pDest);
void miZero48B(register void *pDest);
void miZero64B(register void *pDest);
#ifdef __cplusplus
} /* extern "C" */
#endif
/* BROM_MI_MEMORY_H_ */
#endif