1 /* Author: Domen Puncer <domen@cba.si>. License: WTFPL, see file LICENSE */
8 #ifdef ARCH_ARM_CORTEX_M3
9 #include <arch/cm3_regs.h>
13 static int command_x(const char *_cmd
)
18 char *cmd
= (char*)_cmd
; /* we don't change it, but strtol is idiotic */
20 if (cmd
[0] != 'x' || isalpha(cmd
[1]))
27 len
= strtoul(cmd
, &cmd
, 0);
28 /* just some sanity */
32 // while, check for xs...
41 printf("E: invalid argument for size\n");
50 addr
= strtoul(cmd
, NULL
, 0);
53 /* currently it only works for hex, with size 4 */
55 printf("%#010x: ", addr
);
56 for (i
=0; i
<len
; i
++) {
57 if (i
% 8 == 0 && i
) {
58 printf("\n%#010x: ", addr
);
60 printf("%#010x ", *(u32
*)addr
);
68 static int command_boot(const char *cmd
)
70 if (strcmp(cmd
, "boot") != 0)
73 #ifdef ARCH_ARM_CORTEX_M3
74 AIRCR
= (AIRCR
& 0x8700) | 0x05FA<<16 /* magic */ | 1<<2 /* SYSRESETREQ */;
81 static int command_fail(const char *cmd
)
83 volatile u32
*tmp
= (volatile u32
*)0x12345678;
84 void (*f
)() = (void (*)())0x23456789;
86 if (strncmp(cmd
, "fail ", 5) != 0)
91 /* invalid pointer deference */
95 /* invalid pointer deference */
99 /* invalid stack pointer */
100 #ifdef ARCH_ARM_CORTEX_M3
101 asm volatile ("ldr sp, =#0x87654321\n\t");
105 /* undefined instruction */
106 #ifdef ARCH_ARM_CORTEX_M3
107 *(u32
*)0xe000ed24 |= 1<<18; /* enable usage fault */
108 /* http://www.keil.com/support/man/docs/armasm/armasm_cihjijca.htm */
109 asm volatile (".short 0xdead\n\t"); /* arm arm says, 0xdexx for thumb */
110 /* some other document said 1101 011... 1 xxxx for arm mode */
115 #ifdef ARCH_ARM_CORTEX_M3
116 asm volatile ("svc #0\n");
121 printf("%s: unknown argument %c\n", __func__
, cmd
[5]);
122 printf("fail arguments: \n"
123 "\t0 - write to invalid pointer\n"
124 "\t1 - call invalid function\n"
125 "\ts - corrupt stack pointer\n"
126 "\tu - undefined instruction\n"
132 static int command_test(const char *cmd
)
134 if (strncmp(cmd
, "test ", 5) != 0)
137 strncpy(foo
, cmd
+5, 16);
141 printf("%s: %02x %02x %02x %02x\n", __func__
, foo
[0], foo
[1], foo
[2], foo
[3]);
145 static int command_help(const char *cmd
)
147 if (strcmp(cmd
, "help") != 0)
149 printf("something helpful should be written here\n");
152 static int command_invalid(const char *cmd
)
155 printf("invalid command\n");
159 /* 1 for handled, 0 for not handled, negative for error (should abort handling) */
160 int (* const command_list
[])(const char *cmd
) = {