-
Notifications
You must be signed in to change notification settings - Fork 0
/
csb335.c
129 lines (100 loc) · 2.95 KB
/
csb335.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Copyright (c) 2001 by William A. Gatliff
All rights reserved. [email protected]
See the file COPYING for details.
This file is provided "as-is", and without any express or implied
warranties, including, without limitation, the implied warranties of
merchantability and fitness for a particular purpose.
The author welcomes feedback regarding this file.
**
$Id: csb335.c,v 1.3 2003/12/11 15:30:14 bgat Exp $
*/
#define CPU_HZ 77000000
#include "gdb.h"
#include "arm7tdmi.h"
#include "arm7tdmi-lh79520.h"
#define UARTFR UART0FR
#define UARTDR UART0DR
extern void arm7tdmi_und_handler (void);
void arm7tdmi_lh79520_startup (void)
{
/* TODO: for now, assume uMON has us covered */
}
int gdb_putc (int c)
{
while (!(UARTFR_TXFE & *UARTFR))
;
*UARTDR = c;
return c & 0xff;
}
int gdb_getc (void)
{
int retval;
while ((UARTFR_RXFE & *UARTFR))
;
retval = *UARTDR;
return retval;
}
void gdb_kill (void)
{
}
void gdb_detach (void)
{
}
/* uMON sets us up pretty nice, stick with that */
void _start (void)
{
const int cpsr_system = 0xdf;
/* go to System mode, in case we aren't there already */
__asm__ volatile ("msr cpsr, %0" : : "r"(cpsr_system) : "cc");
/* remap memory, in case it isn't already */
*(long*)0xfffe2008 = 1;
/* write an 'ldr pc, [pc, #0x18]' to the exception vector table */
*(long*)0x4 = 0xe59ff018;
/* aim the undefined exception to arm7tdmi_und_handler */
*(long*)0x24 = (long)arm7tdmi_und_handler;
gdb_startup();
/* load some registers, force a "breakpoint" */
__asm__ volatile (" mov r0, #0");
__asm__ volatile (" mov r1, #1");
__asm__ volatile (" mov r2, #2");
__asm__ volatile (" mov r3, #3");
__asm__ volatile (" mov r4, #4");
__asm__ volatile (" mov r5, #5");
__asm__ volatile (" mov r6, #6");
__asm__ volatile (" mov r7, #7");
__asm__ volatile (".word 0xe7ffdefe");
/* some test code */
__asm__ volatile ("top: mov r0, #0");
__asm__ volatile (" mov r1, #1");
__asm__ volatile (" mov r2, #2");
__asm__ volatile (" mov r3, #3");
__asm__ volatile (" mov r4, #4");
__asm__ volatile (" mov r5, #5");
__asm__ volatile (" mov r6, #6");
__asm__ volatile (" mov r7, #7");
__asm__ volatile (" b 1f");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile ("1: nop");
__asm__ volatile (" mov lr, pc");
__asm__ volatile (" add lr, lr, #12");
__asm__ volatile (" mov pc, lr");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" mov lr, pc");
__asm__ volatile (" add lr, lr, #20");
__asm__ volatile (" stmfd sp!, {r1,lr}");
__asm__ volatile (" mov r1, #0");
__asm__ volatile (" ldmfd sp!, {r1,pc}");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" nop");
__asm__ volatile (" b top");
}