⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memlib.c

📁 Boot code for ADM5120 with serial console for Edimax router.
💻 C
字号:
/*****************************************************************************;;    Project : ADM5120;    Creator : Dan Everett;    File    : memlib.c;    Abstract: ;;*****************************************************************************/#include <ctype.h>#include <mips.h>#include <mips4kc.h>#include <adm5120.h>#include <except.h>#include <linuxld.h>void *MemAlloc(UINT32 NumOfByte, UINT32 clear);void *SharedMemAlloc(UINT32 NumOfByte, UINT32 clear);#define MEM_ALIGN				4#define SHARED_MEM_ALIGN		16/* LINUXLD_MEMPOOL_START details in 'param'c'    *//* It's A0600000 (Kseg1) and 00600000 (Kuseg)    *//* LINUXLD_MEMPOOL_SIZE defined as 200000 (2 MB) */#define MEM_HEAP_PAEND			KVA2PA((LINUXLD_MEMPOOL_START + LINUXLD_MEMPOOL_SIZE))/*********  Global Variables ********/void *_heap_h;UINT32 MemHead;		// A Physical Address completely local to this file/*	MemAlloc returns mempry in Kseg0, unmapped but cached. */void *MemAlloc(UINT32 NumOfBytes, UINT32 clear){	int s;	UINT32 MemStart, MemEnd;	/*	Critical section starts.  Disable interrupts. */	s = mips_int_lock();	MemEnd = MemHead + NumOfBytes;	if (MemEnd & (MEM_ALIGN - 1)) 		MemEnd = (MemEnd + MEM_ALIGN - 1) & ~(MEM_ALIGN - 1);	/*	Make sure not to allocate beyond the 2 MByte heap */	if (MemEnd <= MEM_HEAP_PAEND) {		/*	Yeah, we got that... */		MemStart = MemHead;		MemHead = MemEnd;		/*	Result in Kseg0 */		MemStart = MIPS_KSEG0A(MemStart);		if (clear)			memset((void *) MemStart, 0, NumOfBytes);	} else {		/*	Out of memory */		MemStart = (UINT32) NULL;	}	// Critical section ends.  Restore interrupts.	mips_int_unlock(s);	return (void *) MemStart;}/*	SharedMemAlloc returns mempry in Kseg1, unmapped and uncached. */void *SharedMemAlloc(UINT32 NumOfBytes, UINT32 clear){	int s;	UINT32 MemStart, MemEnd;	// Critical section starts. Disable the interrupts	s = mips_int_lock();	// Align the start address to cache line boundry	if (MemHead & (SHARED_MEM_ALIGN - 1))		MemHead = (MemHead + SHARED_MEM_ALIGN - 1) & ~(SHARED_MEM_ALIGN - 1);	MemEnd = MemHead + NumOfBytes;	/**********************************************************************/	/* ALWAYS keep the shared memory block aligned on cache line boundary */	/**********************************************************************/	if (MemEnd & (SHARED_MEM_ALIGN - 1))		MemEnd = (MemEnd + SHARED_MEM_ALIGN - 1) & ~(SHARED_MEM_ALIGN - 1);	/*	Make sure not to allocate beyond the 2 MByte heap */	if (MemEnd <= MEM_HEAP_PAEND) {		/*	Yeah, we got that... */		MemStart = MemHead;		MemHead = MemEnd;		/*	Result in Kseg1 */		MemStart = MIPS_KSEG1A(MemStart);		if (clear)			memset((void *) MemStart, 0, NumOfBytes);	} else {		/*	Out of memory */		MemStart = (UINT32) NULL;	}	// Critical section ends. Restore the interrupts mode	mips_int_unlock(s);	return (void *) MemStart;}/*	The memory library keeps track of memory regions in physical memory.	Regular allocations are provided as Kseg0 addresses, i.e. unmapped but cached.	Shared allocations  are provided as Kseg1 addresses, i.e. unmapped and uncached. */void memlib_init(void){	int s, i;	unsigned long reg_offset, reg;	/*	LINUXLD_MEMPOOL_START = LINUXLD_KERNEL_START + LINUXLD_KERNEL_SIZE = A0600000 */	/*	LINUXLD_MEMPOOL_SIZE                                               =   200000 */	/*	mempool in Kseg1, Unmapped and Uncached                                       */	_heap_h = (void *) LINUXLD_MEMPOOL_START;	/*	In vector.S */	s = mips_int_lock();	/*	Map VA to PA - KVA2PA simply sets the top 3 bits to zero */	/*	Resulting in a Kuseg address, i.e. 00600000 (6 MB)       */	MemHead = KVA2PA((UINT32) _heap_h);	/*	Totally unnecessary as long as LINUXLD_MEMPOOL_START is aligned properly */	if (MemHead & (MEM_ALIGN - 1))		MemHead = (MemHead + MEM_ALIGN - 1) & ~(MEM_ALIGN - 1);	mips_int_unlock(s);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -