1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * MOUSSE-specific commands File: ui_mousse.c 5 * 6 * A temporary sandbox for misc test routines and commands. 7 * 8 * Author: Mitch Lichtenberg 9 * 10 ********************************************************************* 11 * 12 * Copyright 2000,2001,2002,2003 13 * Broadcom Corporation. All rights reserved. 14 * 15 * This software is furnished under license and may be used and 16 * copied only in accordance with the following terms and 17 * conditions. Subject to these conditions, you may download, 18 * copy, install, use, modify and distribute modified or unmodified 19 * copies of this software in source and/or binary form. No title 20 * or ownership is transferred hereby. 21 * 22 * 1) Any source code used, modified or distributed must reproduce 23 * and retain this copyright notice and list of conditions 24 * as they appear in the source file. 25 * 26 * 2) No right is granted to use any trade name, trademark, or 27 * logo of Broadcom Corporation. The "Broadcom Corporation" 28 * name may not be used to endorse or promote products derived 29 * from this software without the prior written permission of 30 * Broadcom Corporation. 31 * 32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR 33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED 34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT, 38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 44 * THE POSSIBILITY OF SUCH DAMAGE. 45 ********************************************************************* */ 46 47 48#include "cfe.h" 49#include "ui_command.h" 50 51#include "ppcdefs.h" 52#include "mpc824x.h" 53 54#include "mousse.h" 55 56int ui_init_moussecmds(void); 57static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[]); 58static int ui_cmd_crash(ui_cmdline_t *cmd,int argc,char *argv[]); 59static int ui_cmd_read_hid0(ui_cmdline_t *cmd,int argc,char *argv[]); 60static int ui_cmd_write_hid0(ui_cmdline_t *cmd,int argc,char *argv[]); 61static int ui_cmd_read_hid1(ui_cmdline_t *cmd,int argc,char *argv[]); 62static int ui_cmd_read_msr(ui_cmdline_t *cmd,int argc,char *argv[]); 63static int ui_cmd_write_msr(ui_cmdline_t *cmd,int argc,char *argv[]); 64static int ui_cmd_read_bats(ui_cmdline_t *cmd,int argc,char *argv[]); 65 66 67 68/* ********************************************************************* 69 * ui_init_moussecmds() 70 * 71 * Add MOUSSE-specific commands to the command table 72 * 73 * Input parameters: 74 * nothing 75 * 76 * Return value: 77 * 0 78 ********************************************************************* */ 79 80 81int ui_init_moussecmds(void) 82{ 83 cmd_addcmd("test timer", 84 ui_cmd_timertest, 85 NULL, 86 "Test the timer", 87 "test timer", 88 ""); 89 90 cmd_addcmd("crash", 91 ui_cmd_crash, 92 NULL, 93 "Cause an exception", 94 "crash", 95 "-divby0;Cause a division by zero exception|" 96 "-align;Cause an alignment exception|" 97 "-addr;Cause an address fault|" 98 "-syscall;Do a syscall"); 99 100 101 cmd_addcmd("read hid0", 102 ui_cmd_read_hid0, 103 NULL, 104 "Read HID0 register", 105 "read hid0", 106 ""); 107 108 cmd_addcmd("write hid0", 109 ui_cmd_write_hid0, 110 NULL, 111 "Write HID0 register.", 112 "write hid0 [value]", 113 ""); 114 115 cmd_addcmd("read hid1", 116 ui_cmd_read_hid1, 117 NULL, 118 "Read HID1 register", 119 "read hid1", 120 ""); 121 122 cmd_addcmd("read msr", 123 ui_cmd_read_msr, 124 NULL, 125 "Read MSR register.", 126 "read msr", 127 ""); 128 129 cmd_addcmd("write msr", 130 ui_cmd_write_msr, 131 NULL, 132 "Write MSR register.", 133 "write msr [value]", 134 ""); 135 136 137 cmd_addcmd("read bats", 138 ui_cmd_read_bats, 139 NULL, 140 "Reat BAT registers.", 141 "read bats", 142 ""); 143 144 145 return 0; 146} 147 148 149static int ui_cmd_crash(ui_cmdline_t *cmd,int argc,char *argv[]) 150{ 151 if (cmd_sw_isset(cmd,"-divby0")) { 152 int a = 1; 153 int b = 0; 154 printf("whoopie! %d\n",a/b); 155 } 156 else if (cmd_sw_isset(cmd,"-align")) { 157 uint32_t a = 17; 158 __asm __volatile ("stmw 14,0(%0)" : : "r"(a)); 159 } 160 else if (cmd_sw_isset(cmd,"-addr")) { 161 } 162 else if (cmd_sw_isset(cmd,"-syscall")) { 163 __asm __volatile ("li 0,0x0999 ; li 4,0x0444 ; li 10,0x0aaa ; li 30,0x0eee ; sc"); 164 } 165 166 return 0; 167} 168 169 170static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[]) 171{ 172 int64_t t; 173 174 t = cfe_ticks; 175 176 while (!console_status()) { 177 cfe_sleep(CFE_HZ); 178 if (t != cfe_ticks) { 179 xprintf("Time is %lld\n",cfe_ticks); 180 t = cfe_ticks; 181 } 182 } 183 184 return 0; 185} 186 187extern uint32_t read_hid0(void); 188extern void write_hid0(uint32_t); 189 190static int ui_cmd_read_hid0(ui_cmdline_t *cmd,int argc,char *argv[]) 191{ 192 printf("HID0 = 0x%08X\n",read_hid0()); 193 return 0; 194} 195 196static int ui_cmd_write_hid0(ui_cmdline_t *cmd,int argc,char *argv[]) 197{ 198 char *x; 199 uint32_t val; 200 201 if ((x = cmd_getarg(cmd,0)) == NULL) return ui_showusage(cmd); 202 203 val = xtoi(x); 204 write_hid0(val); 205 206 return 0; 207} 208 209 210extern uint32_t read_hid1(void); 211 212static int ui_cmd_read_hid1(ui_cmdline_t *cmd,int argc,char *argv[]) 213{ 214 uint32_t hid1 = read_hid1(); 215 216 printf("HID1 = 0x%08X, pllconfig=0x%02X\n",hid1,G_HID1_PLLCFG(hid1)); 217 return 0; 218} 219 220extern uint32_t read_msr(void); 221extern void write_msr(uint32_t); 222 223static int ui_cmd_read_msr(ui_cmdline_t *cmd,int argc,char *argv[]) 224{ 225 printf("MSR = 0x%08X\n",read_msr()); 226 return 0; 227} 228 229static int ui_cmd_write_msr(ui_cmdline_t *cmd,int argc,char *argv[]) 230{ 231 char *x; 232 uint32_t val; 233 234 if ((x = cmd_getarg(cmd,0)) == NULL) return ui_showusage(cmd); 235 236 val = xtoi(x); 237 write_msr(val); 238 239 return 0; 240} 241 242extern void read_bats(uint32_t *); 243static int ui_cmd_read_bats(ui_cmdline_t *cmd,int argc,char *argv[]) 244{ 245 uint32_t bats[16]; 246 int idx; 247 248 read_bats(bats); 249 250 for (idx = 0; idx < 8; idx += 2) { 251 printf("IBAT%d U:%08X L:%08X\n",idx/2,bats[idx],bats[idx+1]); 252 } 253 for (idx = 8; idx < 16; idx += 2) { 254 printf("DBAT%d U:%08X L:%08X\n",(idx-8)/2,bats[idx],bats[idx+1]); 255 } 256 return 0; 257} 258