xmem.c (1482B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 7 */ 8 9 #include <shared/bsl.h> 10 11 #include <appl/diag/system.h> 12 #include <appl/diag/parse.h> 13 #include <appl/diag/shell.h> 14 15 char cmd_xmem_usage[] = 16 "xmem r addr: read 4 bytes from address\n" 17 "xmem w addr data: write 4 bytes data to address\n"; 18 19 cmd_result_t 20 cmd_xmem(int unit, args_t *a) 21 { 22 char *token; 23 unsigned int addr, data; 24 25 if ((token = ARG_GET(a)) == NULL) { 26 return CMD_USAGE; 27 } 28 29 if (sal_strcasecmp(token, "r") == 0) { 30 if ((token = ARG_GET(a)) == NULL) { 31 return CMD_USAGE; 32 } 33 addr = parse_integer(token); 34 cli_out("0x%x: %08x\n", addr, *((unsigned int *)(INT_TO_PTR(addr)))); 35 } else if (sal_strcasecmp(token, "w") == 0) { 36 if ((token = ARG_GET(a)) == NULL) { 37 return CMD_USAGE; 38 } 39 addr = parse_integer(token); 40 if ((token = ARG_GET(a)) == NULL) { 41 return CMD_USAGE; 42 } 43 data = parse_integer(token); 44 *((unsigned int *)(INT_TO_PTR(addr))) = data; 45 } else { 46 cli_out("%s", cmd_xmem_usage); 47 return CMD_FAIL; 48 } 49 return CMD_OK; 50 } 51 52 53 #if 1 54 int custom_cmd(int unit) 55 { 56 cmd_t cmd = { "xmem", cmd_xmem, cmd_xmem_usage, cmd_xmem_usage }; 57 58 return cmdlist_add(unit, &cmd); 59 } 60 #endif