memgen.c
来自「SMDK2440 boot code, base on vivi」· C语言 代码 · 共 292 行
C
292 行
/* * vivi/lib/memory.c: * * Copyright (C) 2002 MIZI Research, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * Author: Janghoon Lyu <nandy@mizi.com> * Date : $Date: 2003/08/12 11:02:09 $ * * $Revision: 1.4 $ * $Id: memgen.c,v 1.4 2003/08/12 11:02:09 nandy Exp $ * * * History * * 2002-02-25: Janghoon Lyu <nandy@mizi.com> * - Initial code * * 2002-07-08: Janghoon Lyu <nandy@mizi.com> * - 肯傈洒 内靛 货肺 累己. * * 2002-07-15: Janghoon Lyu <nandy@mizi.com> * - 官诧 疙飞绢 眉拌俊 蝶弗 荐沥 * - 叼伐 农扁 茫酒 郴绰 内靛 荐沥. (PPCBOOT俊辑 蝶咳) * * 2003-08-06: Janghoon Lyu <nandy@mizi.com> * - 空芒 沥府窃. 喊肺 荤侩窍瘤 臼绰 内靛 沥府. * - 窜鉴拳 矫糯. 1byte档 酒滨促. * - 皋葛府 农扁 茫绰 内靛 昏力. * */#include <config.h>#include <machine.h>#include <memory.h>#include <command.h>#include <hardware.h>#include <vstring.h>#include <sizes.h>#include <types.h>#include <string.h>void print_mem_map(void){ long sp = 0; __asm__("mov %0, sp" : "=r" (sp)); printk("SDRAM size=%dM\n", (DRAM_SIZE >> 20)); printk("Free memory=%dM\n\n", (RAM_SIZE >> 20)); printk("Available memory region: 0x%08lx - 0x%08lx\n", RAM_BASE, (RAM_BASE + RAM_SIZE)); printk("Stack base address=0x%08lx\n", (STACK_BASE + STACK_SIZE - 4)); printk("Current stack pointer=0x%08lx\n", sp);}void print_mem_ctrl_regs(void){ printk("\nMemory control register vlaues\n");#if defined(CONFIG_ARCH_S3C2400) printk(" BWSCON = 0x%08lx\n", _BWSCON); printk(" BANKCON0 = 0x%08lx\n", _BANKCON0); printk(" BANKCON1 = 0x%08lx\n", _BANKCON1); printk(" BANKCON2 = 0x%08lx\n", _BANKCON2); printk(" BANKCON3 = 0x%08lx\n", _BANKCON3); printk(" BANKCON4 = 0x%08lx\n", _BANKCON4); printk(" BANKCON5 = 0x%08lx\n", _BANKCON5); printk(" BANKCON6 = 0x%08lx\n", _BANKCON6); printk(" BANKCON7 = 0x%08lx\n", _BANKCON7); printk(" REFRESH = 0x%08lx\n", _REFRESH);#elif defined(CONFIG_ARCH_S3C2410) || defined(CONFIG_ARCH_S3C2440) printk(" BWSCON = 0x%08lx\n", BWSCON); printk(" BANKCON0 = 0x%08lx\n", BANKCON0); printk(" BANKCON1 = 0x%08lx\n", BANKCON1); printk(" BANKCON2 = 0x%08lx\n", BANKCON2); printk(" BANKCON3 = 0x%08lx\n", BANKCON3); printk(" BANKCON4 = 0x%08lx\n", BANKCON4); printk(" BANKCON5 = 0x%08lx\n", BANKCON5); printk(" BANKCON6 = 0x%08lx\n", BANKCON6); printk(" BANKCON7 = 0x%08lx\n", BANKCON7); printk(" REFRESH = 0x%08lx\n", REFRESH); printk(" BANKSIZE = 0x%08lx\n", BANKSIZE); printk(" MRSRB6 = 0x%08lx\n", MRSRB6); printk(" MRSRB7 = 0x%08lx\n", MRSRB7);#elif defined(CONFIG_ARCH_SA1100) printk("SDRAM bank0:\n"); printk(" mdcnfg = 0x%08lx\n", CTL_REG_READ(SA1100_DRAM_CONFIGURATION_BASE+SA1100_MDCNFG)); printk(" mdrefr = 0x%08lx\n", CTL_REG_READ(SA1100_DRAM_CONFIGURATION_BASE+SA1100_MDREFR));#elif defined(CONFIG_ARCH_PXA250) printk(" MSC0 = 0x%08lx\n", MSC0); printk(" MSC1 = 0x%08lx\n", MSC1); printk(" MSC2 = 0x%08lx\n", MSC2); printk(" MDCNFG = 0x%08lx\n", MDCNFG); printk(" MDREFR = 0x%08lx\n", MDREFR); printk(" MDMRS = 0x%08lx\n", MDMRS); printk(" MECR = 0x%08lx\n", MECR); printk(" MCMEM0 = 0x%08lx\n", MCMEM0); printk(" MCMEM1 = 0x%08lx\n", MCMEM1); printk(" MCATT0 = 0x%08lx\n", MCATT0); printk(" MCATT1 = 0x%08lx\n", MCATT1); printk(" MCIO0 = 0x%08lx\n", MCIO0); printk(" MCIO1 = 0x%08lx\n", MCIO1);#else printk("UNKNOWN ARCHITECTURE!\n");#endif}static void mem_info(void){ printk("\nRAM Information:\n"); print_mem_map(); print_mem_ctrl_regs();}/* * Commands */static voidusage(void){ printk("mem - manage memory\n"); printk("Usage:\n"); printk(" mem info - Display memory informations\n"); printk(" mem read <addr> - read 4 bytes\n"); printk(" mem write <addr> <value> - write 4 bytes\n"); printk(" mem compare <addr> <addr> <len> - compare memory\n"); printk(" mem copy <dest> <src> <len> - copy memory\n");}void command_mem(int argc, const char **argv){ switch (argc) { case 2: if (strncmp("info", argv[1], 4) == 0) { mem_info(); return; } break; case 3: if (strncmp("read", argv[1], 4) == 0) { volatile ulong *addr = (volatile ulong *)simple_strtoul(argv[2], NULL, 0); ulong value = *addr; printk("addr: 0x%08lx, value: 0x%08lx\n", addr, value); return; } case 4: if (strncmp("write", argv[1], 5) == 0) { volatile ulong *addr = (volatile long *)simple_strtoul(argv[2], NULL, 0); ulong value = simple_strtoul(argv[3], NULL, 0); *addr = value; printk("addr: 0x%08lx, value: 0x%08lx\n", addr, value); return; } break; case 5: { unsigned long a0, a1, len; a0 = simple_strtoul(argv[2], NULL, 0); a1 = simple_strtoul(argv[3], NULL, 0); len = simple_strtoul(argv[4], NULL, 0); if (strncmp("compare", argv[1], 7) == 0) { printk("Comparing... "); if (memcmp((void *)a0, (void *)a1, len)) { printk("not matched\n"); return; } printk("matched\n"); return; } if (strncmp("copy", argv[1], 4) == 0) { printk("Copying... "); memcpy((void *)a0, (void *)a1, len); printk("ok\n"); return; } } break; default: usage(); return; } usage();}user_command_t mem_cmd = { "mem", command_mem, NULL};/* * dump hex */#define BL_ISPRINT(ch) (((ch) >= ' ') && ((ch) < 128))void hex_dump(unsigned char *data, size_t num){ int i; long oldNum; char buf[90]; char *bufp; int line_resid; while (num) { bufp = buf; simple_bin2hex(bufp, (unsigned long)data, 4); bufp += 8; *bufp++ = ':'; *bufp++ = ' '; oldNum = num; for (i = 0; i < 16 && num; i++, num--) { simple_bin2hex(bufp, (unsigned long)data[i], 1); bufp += 2; *bufp++ = (i == 7) ? '-' : ' '; } line_resid = (16 - i) * 3; if (line_resid) { memset(bufp, ' ', line_resid); bufp += line_resid; } memcpy(bufp, "| ", 2); bufp += 2; for (i = 0; i < 16 && oldNum; i++, oldNum--) *bufp++ = BL_ISPRINT(data[i]) ? data[i] : '.'; line_resid = 16 - i; if (line_resid) { memset(bufp, ' ', 16 - i); bufp += 16 - i; } *bufp++ = '\n'; *bufp++ = '\0'; printk(buf); data += 16; }}/* dump command */void command_dump(int argc, const char **argv){ size_t num; unsigned char *p = (unsigned char *)(RAM_BASE); switch (argc) { case 2: num = 16; break; case 3: num = simple_strtoul(argv[2], NULL, 0); break; default: printk("dump - Display (hex dump) a range of memory.\n"); printk("Usage: dump <addr> [length]\n"); return; } p = (unsigned char *)simple_strtoul(argv[1], NULL, 0); hex_dump(p, num);}user_command_t dump_cmd = { "dump", command_dump, NULL};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?