1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * Core hacking commands File: ui_corecmds.c 5 * 6 * Core mutilation enabler 7 * 8 * Author: Justin Carlson 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 49#include "cfe.h" 50#include "sbmips.h" 51 52#include "ui_command.h" 53 54 55 56 57 58int ui_init_corecmds(void); 59extern void _cfe_flushcache(int); 60extern void sb1250_l2cache_flush(void); 61 62static int ui_cmd_defeature(ui_cmdline_t *cmd,int argc,char *argv[]); 63static int ui_cmd_show_defeature(ui_cmdline_t *cmd,int argc,char *argv[]); 64static int ui_cmd_show_tlb(ui_cmdline_t *cmd,int argc,char *argv[]); 65 66/* 67 * This is sneaky and cruel. Basically we muck with the return 68 * address and don't tell the compiler about it. That way 69 * we return happily to the desired segment. Return 70 * bits 31-29 of the address in the top posi 71 */ 72#if CFG_RUNFROMKSEG0 73static void segment_bounce(unsigned int bits) 74{ 75 __asm__ __volatile__ ( 76 ".set push \n" 77 ".set noat \n" 78 ".set noreorder \n" 79 " lui $8,0x1FFF \n" 80 " ori $8,$8,0xFFFF \n" 81 " move $2, $31 \n" 82 " and $31, $31, $8 \n" 83 " or $31, $31, $4 \n" 84 ".set pop \n" 85 : 86 : 87 :"$1","$8" /* *NOT* $31! We don't want the compiler saving it */ 88 ); 89} 90#endif 91 92 93int ui_init_corecmds(void) 94{ 95 cmd_addcmd("defeature", 96 ui_cmd_defeature, 97 NULL, 98 "Set the state of the defeature mask", 99 "defeature <hex mask>\n\n" 100 "This command pokes the given value into cp0 register 23 select 2\n" 101 "to defeature functionality. The mask is not checked for sanity\n" 102 "so use this command carefully!\n", 103 ""); 104 105 cmd_addcmd("show defeature", 106 ui_cmd_show_defeature, 107 NULL, 108 "Show the state of the defeature mask", 109 "show defeature\n\n" 110 "Gets the current state of the defeature mask from xp0 reg 23,\n" 111 "select 2 and prints it\n", 112 ""); 113 114 cmd_addcmd("show tlb", 115 ui_cmd_show_tlb, 116 NULL, 117 "Show the contents of the TLB", 118 "show tlb [low [high]]\n\n" 119 "Displays all the entries in the TLB\n" 120 "You can specify a range of TLB entries, in decimal", 121 ""); 122 123 return 0; 124} 125 126static int ui_cmd_defeature(ui_cmdline_t *cmd,int argc,char *argv[]) 127{ 128 char *value_str; 129 unsigned int value; 130 131 value_str = cmd_getarg(cmd, 0); 132 133 if (value_str == NULL) { 134 return ui_showusage(cmd); 135 } 136 137 value = lib_xtoi(value_str); 138 139#if CFG_RUNFROMKSEG0 140 segment_bounce(0xa0000000); 141 _cfe_flushcache(0); 142 sb1250_l2cache_flush(); 143#endif 144 145 __asm__ __volatile__ ( 146 ".set push ; .set mips64 ; mtc0 %0, $23, 2 ; .set pop\n" 147 : /* No outputs */ 148 : "r" (value) 149 ); 150 151#if CFG_RUNFROMKSEG0 152// _cfe_flushcache(0); 153// sb1250_l2cache_flush(); 154 segment_bounce(0x80000000); 155#endif 156 157 return 0; 158} 159 160static int ui_cmd_show_defeature(ui_cmdline_t *cmd,int argc,char *argv[]) 161{ 162 unsigned int value; 163 164 __asm__ __volatile__ ( 165 " .set push ; .set mips64 ; mfc0 %0, $23, 2 ; .set pop\n" 166 : "=r" (value)); 167 xprintf("Defeature mask is currently %08X\n", value); 168 return 0; 169} 170 171static int ui_cmd_show_tlb(ui_cmdline_t *cmd,int argc,char *argv[]) 172{ 173 uint64_t valuehi,valuelo0,valuelo1; 174 int idx; 175 int low = 0; 176 int high = K_NTLBENTRIES; 177 char *x; 178 179 if ((x = cmd_getarg(cmd,0))) { 180 low = atoi(x); 181 high = low+1; 182 } 183 if ((x = cmd_getarg(cmd,1))) { 184 high = atoi(x)+1; 185 } 186 187 188 for (idx = low ; idx < high; idx++) { 189 190 __asm__ __volatile__ ( 191 " .set push ; .set mips64 \n" 192 " mtc0 %3, $0 \n" 193 " tlbr \n" 194 " dmfc0 %0,$10 \n" 195 " dmfc0 %1,$2 \n" 196 " dmfc0 %2,$3 \n" 197 " .set pop \n" 198 : "=r" (valuehi) , "=r" (valuelo0) , "=r" (valuelo1) 199 : "r" (idx) 200 ); 201 202 printf("Entry %2d %016llX %016llX %016llX\n",idx,valuehi,valuelo0,valuelo1); 203 } 204 205 return 0; 206} 207 208 209