comparison packages/hal/mips/jmr3904/current/src/hal_stub.c @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 /* hal-stub.c - helper functions for stub, specific to ECC HAL
2 *
3 * Copyright (c) 1998 Cygnus Support
4 *
5 * The authors hereby grant permission to use, copy, modify, distribute,
6 * and license this software and its documentation for any purpose, provided
7 * that existing copyright notices are retained in all copies and that this
8 * notice is included verbatim in any distributions. No written agreement,
9 * license, or royalty fee is required for any of the authorized uses.
10 * Modifications to this software may be copyrighted by their authors
11 * and need not follow the licensing terms described here, provided that
12 * the new terms are clearly indicated on the first page of each file where
13 * they apply.
14 */
15
16 #include <stddef.h>
17
18 //#include <signal.h>
19 //#include "board.h"
20
21 #include <cyg/hal/hal_stub.h>
22
23 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
24
25 #include <cyg/hal/hal_arch.h>
26 #include <cyg/hal/hal_io.h>
27 #include <cyg/hal/hal_diag.h>
28 #include <cyg/hal/hal_cache.h>
29
30 /*---------------------------------------------------------------------------*/
31
32 #define DIAG_BASE 0xfffff300
33 #define DIAG_SLCR (DIAG_BASE+0x00)
34 #define DIAG_SLSR (DIAG_BASE+0x04)
35 #define DIAG_SLDICR (DIAG_BASE+0x08)
36 #define DIAG_SLDISR (DIAG_BASE+0x0C)
37 #define DIAG_SFCR (DIAG_BASE+0x10)
38 #define DIAG_SBRG (DIAG_BASE+0x14)
39 #define DIAG_TFIFO (DIAG_BASE+0x20)
40 #define DIAG_RFIFO (DIAG_BASE+0x30)
41
42 #define BRG_T0 0x0000
43 #define BRG_T2 0x0100
44 #define BRG_T4 0x0200
45 #define BRG_T5 0x0300
46
47 /*---------------------------------------------------------------------------*/
48
49 /* External data */
50
51 extern int output_debug; /* dvemon.c */
52 extern int (*read_vector) (int, char *, int); /* read.c */
53 extern int (*write_vector) (int, char *, int); /* write.c */
54
55 /* External functions */
56
57 //int outbyte (unsigned char byte); /* dvemon.c */
58 //unsigned char inbyte (); /* dvemon.c */
59 //void general_exception (void); /* tx39-exc.S */
60
61
62 /* Local data */
63
64
65 /* If ENABLED is non-zero, supply a memory fault handler that traps
66 subsequent memory errors and sets _mem_err to 1. Otherwise, memory
67 faults are processed as exceptions. */
68
69 void __set_mem_fault_trap (int enable) {}
70
71 static int serial_initialized = 0;
72
73 static void serial_init()
74 {
75 //hal_diag_led(0x10);
76 HAL_WRITE_UINT16( DIAG_SLCR , 0x0020 );
77
78 HAL_WRITE_UINT16( DIAG_SLDICR , 0x0000 );
79
80 HAL_WRITE_UINT16( DIAG_SFCR , 0x0000 );
81
82 // HAL_WRITE_UINT16( DIAG_SBRG , BRG_T2 | 20 );
83 // HAL_WRITE_UINT16( DIAG_SBRG , BRG_T2 | 10 );
84 HAL_WRITE_UINT16( DIAG_SBRG , BRG_T2 | 5 );
85
86 serial_initialized = 1;
87
88 //hal_diag_led(0x10);
89 }
90
91 /* Write C to the current serial port. */
92
93 void putDebugChar (int c)
94 {
95 #ifdef CYG_HAL_MIPS_SIM
96
97 #else
98 CYG_WORD16 disr;
99
100 //hal_diag_led(0x20);
101
102 if( !serial_initialized ) serial_init();
103
104 for(;;)
105 {
106 HAL_READ_UINT16( DIAG_SLDISR , disr );
107
108 if( disr & 0x0002 ) break;
109 }
110
111 disr = disr & ~0x0002;
112
113 HAL_WRITE_UINT8( DIAG_TFIFO, c );
114
115 HAL_WRITE_UINT16( DIAG_SLDISR , disr );
116
117 //hal_diag_led(0x20);
118 // HAL_DIAG_WRITE_CHAR( c );
119 #endif
120 }
121
122 /* Read one character from the current serial port. */
123
124 int getDebugChar (void)
125 {
126 #ifdef CYG_HAL_MIPS_SIM
127 static char input[] = "+$s#73";
128 static int i = 0;
129 return input[i++];
130 #else
131 char c;
132
133 CYG_WORD16 disr;
134
135 if( !serial_initialized ) serial_init();
136
137 //hal_diag_led(0x40);
138 for(;;)
139 {
140
141 HAL_READ_UINT16( DIAG_SLDISR , disr );
142
143 if( disr & 0x0001 ) break;
144 }
145
146 disr = disr & ~0x0001;
147
148 HAL_READ_UINT8( DIAG_RFIFO, c );
149
150 HAL_WRITE_UINT16( DIAG_SLDISR , disr );
151
152 //hal_diag_led(0x40);
153
154 // HAL_DIAG_READ_CHAR(c);
155 // diag_printf("<%02x:%c>",c);
156
157 return c;
158
159 #endif
160 }
161
162
163 /* Install the standard set of trap handlers for the stub. */
164
165 void __install_traps (void)
166 {
167 // Nothing to do, the HAL will call handle_exception when one occurs.
168 }
169
170 /* Flush the instruction cache. */
171 void flush_i_cache (void) { HAL_ICACHE_INVALIDATE_ALL(); }
172
173
174 /* Reset the board. */
175 void __reset (void) {}
176
177
178 /* Set the baud rate for the current serial port. */
179 void __set_baud_rate (int baud) {}
180
181
182 /* Initialize the hardware. */
183 void initHardware (void) {}
184
185 #if 0
186 /* Alternate read function for use when stub is running. It
187 reads the data for standard input from the remote GDB. */
188
189 int dve_read (int fd, char *buf, int nbytes)
190 {
191 __get_gdb_input (buf, nbytes, 1);
192 }
193
194 /* Alternate write function for use when stub is running. It
195 writes the data for standard output to the remote GDB. */
196
197 int dve_write (int fd, char *buf, int nbytes)
198 {
199 __output_gdb_string (buf, nbytes);
200 }
201
202 #endif
203
204 /* Install traps and otherwise initialize stub. */
205
206 void set_debug_traps (void)
207 {
208 // output_debug = 0; /* disable control-O prefixing on output */
209 initialize_stub (); /* will call __install_traps and initHardware */
210 // read_vector = dve_read; /* alternate read() function for stub */
211 // write_vector = dve_write; /* alternate write() function for stub */
212 }
213
214
215 /* This function will generate a breakpoint exception. It is used at the
216 beginning of a program to sync up with a debugger and can be used
217 otherwise as a quick means to stop program execution and "break" into
218 the debugger. */
219
220 void
221 breakpoint()
222 {
223 #ifdef CYG_HAL_MIPS_SIM
224
225 // This code causes a fake breakpoint.
226 asm volatile (
227 "lui $24,0x0000;"
228 "ori $24,0x0024;"
229 "mtc0 $24,$13;"
230 "lui $25,%%hi(1f);"
231 "ori $25,$25,%%lo(1f);"
232 "j other_vector;"
233 "nop;"
234 ".global _breakinst;"
235 "_breakinst:"
236 "1: nop;"
237 :
238 :
239 : "t8", "t9"
240 );
241
242 #else
243
244 HAL_BREAKPOINT(_breakinst);
245
246 #endif
247
248 }
249
250
251 /* This function returns the opcode for a 'break 5' instruction. */
252
253 unsigned long __break_opcode ()
254 {
255 return HAL_BREAKINST;
256 }
257
258 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS