1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  BMW-specific commands			File: ui_bmw.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
50#include "ui_command.h"
51
52#include "ppcdefs.h"
53#include "mpc824x.h"
54
55#include "bmw.h"
56
57
58int ui_init_bmwcmds(void);
59static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[]);
60static int ui_cmd_crash(ui_cmdline_t *cmd,int argc,char *argv[]);
61static int ui_cmd_read_hid0(ui_cmdline_t *cmd,int argc,char *argv[]);
62static int ui_cmd_write_hid0(ui_cmdline_t *cmd,int argc,char *argv[]);
63static int ui_cmd_read_msr(ui_cmdline_t *cmd,int argc,char *argv[]);
64static int ui_cmd_write_msr(ui_cmdline_t *cmd,int argc,char *argv[]);
65
66
67/*  *********************************************************************
68    *  ui_init_bmwcmds()
69    *
70    *  Add BMW-specific commands to the command table
71    *
72    *  Input parameters:
73    *  	   nothing
74    *
75    *  Return value:
76    *  	   0
77    ********************************************************************* */
78
79
80int ui_init_bmwcmds(void)
81{
82    cmd_addcmd("test timer",
83	       ui_cmd_timertest,
84	       NULL,
85	       "Test the timer",
86	       "test timer",
87	       "");
88
89    cmd_addcmd("crash",
90	       ui_cmd_crash,
91	       NULL,
92	       "cause an exception",
93	       "crash",
94	       "-divby0;Cause a division by zero exception|"
95	       "-align;Cause an alignment exception|"
96               "-addr;Cause an address fault|"
97	       "-syscall;Do a syscall");
98
99
100    cmd_addcmd("read hid0",
101	       ui_cmd_read_hid0,
102	       NULL,
103	       "read HID0 register.",
104	       "read hid0",
105	       "");
106
107
108    cmd_addcmd("write hid0",
109	       ui_cmd_write_hid0,
110	       NULL,
111	       "write HID0 register.",
112	       "read hid0 [value]",
113	       "");
114
115
116    cmd_addcmd("read msr",
117	       ui_cmd_read_msr,
118	       NULL,
119	       "read MSR register.",
120	       "read msr",
121	       "");
122
123
124    cmd_addcmd("write msr",
125	       ui_cmd_write_msr,
126	       NULL,
127	       "write MSR register.",
128	       "read msr [value]",
129	       "");
130
131
132    return 0;
133}
134
135static int ui_cmd_crash(ui_cmdline_t *cmd,int argc,char *argv[])
136{
137    if (cmd_sw_isset(cmd,"-divby0")) {
138	int a = 1;
139	int b = 0;
140	printf("whoopie! %d\n",a/b);
141	}
142    else if (cmd_sw_isset(cmd,"-align")) {
143	uint32_t a = *((volatile uint32_t *) 17);
144	a = a;
145	}
146    else if (cmd_sw_isset(cmd,"-addr")) {
147	}
148    else if (cmd_sw_isset(cmd,"-syscall")) {
149	__asm __volatile ("li 0,0x0999 ; li 4,0x0444 ; li 10,0x0aaa ; li 30,0x0eee ;  sc");
150	}
151
152    return 0;
153}
154
155
156static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[])
157{
158    int64_t t;
159
160    t = cfe_ticks;
161
162    while (!console_status()) {
163	cfe_sleep(CFE_HZ);
164	if (t != cfe_ticks) {
165	    xprintf("Time is %lld\n",cfe_ticks);
166	    t = cfe_ticks;
167	    }
168	}
169
170    return 0;
171}
172
173
174extern uint32_t read_hid0(void);
175extern void write_hid0(uint32_t);
176static int ui_cmd_read_hid0(ui_cmdline_t *cmd,int argc,char *argv[])
177{
178    printf("HID0 = 0x%08X\n",read_hid0());
179    return 0;
180}
181
182static int ui_cmd_write_hid0(ui_cmdline_t *cmd,int argc,char *argv[])
183{
184    char *x;
185    uint32_t val;
186
187    if ((x = cmd_getarg(cmd,0)) == NULL) return ui_showusage(cmd);
188
189    val = xtoi(x);
190    write_hid0(val);
191
192    return 0;
193}
194
195extern uint32_t read_msr(void);
196extern void write_msr(uint32_t);
197static int ui_cmd_read_msr(ui_cmdline_t *cmd,int argc,char *argv[])
198{
199    printf("MSR = 0x%08X\n",read_msr());
200    return 0;
201}
202
203static int ui_cmd_write_msr(ui_cmdline_t *cmd,int argc,char *argv[])
204{
205    char *x;
206    uint32_t val;
207
208    if ((x = cmd_getarg(cmd,0)) == NULL) return ui_showusage(cmd);
209
210    val = xtoi(x);
211    write_msr(val);
212
213    return 0;
214}
215
216