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

📄 cmd_map.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
字号:
/* $Id*//* * Copyright (c) 2003 Opsycon AB  (www.opsycon.se / www.opsycon.com) *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by Opsycon AB, Sweden. * 4. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#include <stdio.h>#include <stdlib.h>#include <termio.h>#ifdef _KERNEL#undef _KERNEL#endif#include <sys/ioctl.h>#include <sys/param.h>#include <pmon.h>int cmd_map(int, char *[]);const Optdesc         map_opts[] = {	{"-p", "show PCI map"},	{0}};static const Cmd MapCmd[] ={	{"Memory"},	{"map",		"[-p]",			map_opts,			"show memory map",			cmd_map,			1, 4, CMD_REPEAT},	{0, 0}};static int ln, siz;static void init_cmd_map(void) __attribute__ ((constructor));static int print_map(MemDesc *, int);static voidinit_cmd_map(){	cmdlist_expand(MapCmd, 1);}intcmd_map(int ac, char **av){	MemDesc *cur;	int pflag;	int c;	pflag = 0;	optind = 0;	while((c = getopt(ac, av, "p")) != EOF) {		switch(c) {		case 'p':			pflag = 1;			break;		default:			return(-1);		}	}#if 0	if(optind < ac) {		if (!get_rsa(&saddr, av[optind++])) {			return(-1);		}		if(optind < ac) {			if(!get_rsa(&eaddr, av[optind++])) {				return (-1);			}		}	}#endif	cur = &mem_root;	if (cur->sub) {		ln = siz = moresz;		ioctl (STDIN, CBREAK, NULL);		printf("\n");		sprintf(prnbuf, "%~72s", "PHYSICAL ADDRESS MAP");		more(prnbuf, &ln, siz);#if defined(__mips__)		sprintf(prnbuf, "%~22s  %~9s%~9s %~6s%~22s",		    "Address range", "Virtual", "Size", "Type", "Description");#else		sprintf(prnbuf, "%~22s  %~9s %~6s%~25s",		    "Address range", "Size", "Type", "Description");#endif		more(prnbuf, &ln, siz);		print_map(cur->sub, 1);	}	return 0;}static intprint_map(MemDesc *desc, int level){static char *m20 = "------------------------";static char *mtype[] = { "???", "ram", "rom", "flash", "i/o", "code", "data" };	if (level == 1) {		sprintf(prnbuf, ".-%s%s%s-.", m20, m20, m20);		if (more(prnbuf, &ln, siz))			return 1;	}	while (desc != NULL) {#if defined(__mips__)		sprintf(prnbuf, "|%-*s%08x-%08x%-*s %08x %08x  %-6s%-25s|",			level, " ", desc->start, desc->end, 6-level, " ",			PHYS_TO_CACHED(desc->start),			desc->end-desc->start+1, mtype[desc->type],			desc->desc);#else		sprintf(prnbuf, "|%-*s %08x-%08x%-*s %08x  %-6s %-32s|",			level, " ", desc->start, desc->end, 6-level, " ",			desc->end-desc->start+1, mtype[desc->type],			desc->desc);#endif		if (more(prnbuf, &ln, siz))			return 1;		if (desc->sub != NULL)			if (print_map(desc->sub, level+1))				return 1;		desc = desc->next;		if (desc && level == 1) {			sprintf(prnbuf, "|-%s%s%s-|", m20, m20, m20);			if (more(prnbuf, &ln, siz))				return 1;		}	}	if (level == 1) {		sprintf(prnbuf, "'-%s%s%s-'", m20, m20, m20);		if (more(prnbuf, &ln, siz))			return 1;	}	return 0;}

⌨️ 快捷键说明

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