sizemem.c

来自「mips架构的bootloader,99左右的版本 但源代码现在没人更新了」· C语言 代码 · 共 85 行

C
85
字号
/************************************************************* * File: lib/sizemem.c * Purpose: Part of C runtime library * Author: Phil Bunce (pjb@carmel.com) * Revision History: *	970304	Start of revision history *	970325	Replaced Ulong typedef with include of utypes.h */#include <defines.h>#include <mips.h>#include <utypes.h>#if 0 /* old version */#define INCR 0x00010000		/* 64KB per SEG */#define MARKER 0x55#define MAXSEGS 512#else /* new version */#define BLOCKSIZE (16*1024)	/* 16KB per SEG */#define MAXBLOCKS  4096#define MARKER 0xfeedface#endif/* * Modified to support contiguous or non contiguous memory */#ifdef TESTmain(argc,argv)int argc;char *argv[];{unsigned long addr,saved_sr;printf("CLIENTPC=%08x FDATA=%08x\n",CLIENTPC,FDATA);addr = CLIENTPC;if (argc == 2) {	sscanf(argv[1],"%x",&addr);	}	saved_sr = mfc0(C0_SR);mtc0(C0_SR,saved_sr&~SR_IEC);printf("This board has %d Kbytes of available RAM at %08x\n",	sizemem(addr)/1024,addr);#ifdef LR4001CFG4001 &= ~CFG_DBERR;#endifmtc0(C0_SR,saved_sr);}#endif/**************************************************************  sizemem(adr)*	measure the size of memory starting at 'adr'. The return*	value is the number of bytes.*	Note that if the adr specified is not at the start of the*	block of memory, this function will wrap, and report the*	total amount of memory, not just from adr to the end of memory.*/sizemem(adr)Ulong *adr;{int i;Ulong save0,save;volatile Ulong *p,*block0;block0 = (Ulong *)(((Ulong)adr)|K1BASE);save0 = *block0;*block0 = MARKER;if (*block0 != MARKER) return(0);*block0 = 0;if (*block0 != 0) return(0);for (i=1,p=block0;i<MAXBLOCKS;i++) {        p += (BLOCKSIZE/4);        save = *p;        *p = MARKER;        if (*block0 == MARKER) break;        if (*p != MARKER) break;        *p = save;        }*p = save;*block0 = save0;return(i*BLOCKSIZE);}

⌨️ 快捷键说明

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