1 /* $Id: kimagerescue.S,v 1.1 2001/12/17 13:59:27 bjornw Exp $
3 * Rescue code to be prepended on a kimage and copied to the
5 * This is called from the rescue code, it will copy received data to
6 * 4004000 and after a timeout jump to it.
9 #include <linux/config.h>
10 #define ASSEMBLER_MACROS_ONLY
11 #include <asm/sv_addr_ag.h>
13 #define CODE_START 0x40004000
14 #define CODE_LENGTH 784
15 #define TIMEOUT_VALUE 1000
18 #ifdef CONFIG_ETRAX_RESCUE_SER0
19 #define SERXOFF R_SERIAL0_XOFF
20 #define SERBAUD R_SERIAL0_BAUD
21 #define SERRECC R_SERIAL0_REC_CTRL
22 #define SERRDAT R_SERIAL0_REC_DATA
23 #define SERSTAT R_SERIAL0_STATUS
25 #ifdef CONFIG_ETRAX_RESCUE_SER1
26 #define SERXOFF R_SERIAL1_XOFF
27 #define SERBAUD R_SERIAL1_BAUD
28 #define SERRECC R_SERIAL1_REC_CTRL
29 #define SERRDAT R_SERIAL1_REC_DATA
30 #define SERSTAT R_SERIAL1_STATUS
32 #ifdef CONFIG_ETRAX_RESCUE_SER2
33 #define SERXOFF R_SERIAL2_XOFF
34 #define SERBAUD R_SERIAL2_BAUD
35 #define SERRECC R_SERIAL2_REC_CTRL
36 #define SERRDAT R_SERIAL2_REC_DATA
37 #define SERSTAT R_SERIAL2_STATUS
39 #ifdef CONFIG_ETRAX_RESCUE_SER3
40 #define SERXOFF R_SERIAL3_XOFF
41 #define SERBAUD R_SERIAL3_BAUD
42 #define SERRECC R_SERIAL3_REC_CTRL
43 #define SERRDAT R_SERIAL3_REC_DATA
44 #define SERSTAT R_SERIAL3_STATUS
48 ;; This is the entry point of the rescue code
49 ;; 0x80000000 if loaded in flash (as it should be)
50 ;; since etrax actually starts at address 2 when booting from flash, we
51 ;; put a nop (2 bytes) here first so we dont accidentally skip the di
55 #ifndef CONFIG_SVINTO_SIM
56 ;; setup port PA and PB default initial directions and data
57 ;; (so we can flash LEDs, and so that DTR and others are set)
59 move.b CONFIG_ETRAX_DEF_R_PORT_PA_DIR, $r0
60 move.b $r0, [R_PORT_PA_DIR]
61 move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r0
62 move.b $r0, [R_PORT_PA_DATA]
64 move.b CONFIG_ETRAX_DEF_R_PORT_PB_DIR, $r0
65 move.b $r0, [R_PORT_PB_DIR]
66 move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r0
67 move.b $r0, [R_PORT_PB_DATA]
69 ;; We need to setup the bus registers before we start using the DRAM
70 #include "../../lib/dram_init.S"
73 ;; Setup the stack to a suitably high address.
74 ;; We assume 8 MB is the minimum DRAM in an eLinux
75 ;; product and put the sp at the top for now.
77 move.d 0x40800000, $sp
79 ;; setup the serial port at 115200 baud
85 move.b $r0, [SERBAUD] ; 115.2kbaud for both transmit and receive
87 move.b 0x40, $r0 ; rec enable
91 moveq 0, $r1 ; "timer" to clock out a LED red flash
92 move.d CODE_START, $r3 ; destination counter
93 move.d CODE_LENGTH, $r4 ; length
94 move.d TIMEOUT_VALUE, $r5 ; "timeout" until jump
98 subq 1, $r5 ; decrease timeout
99 beq jump_start ; timed out
101 #ifndef CONFIG_ETRAX_NO_LEDS
102 #ifdef CONFIG_ETRAX_PA_LEDS
103 move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r2
105 #ifdef CONFIG_ETRAX_PB_LEDS
106 move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r2
108 move.d (1 << CONFIG_ETRAX_LED1R) | (1 << CONFIG_ETRAX_LED2R), $r0
112 or.d $r0, $r2 ; set bit
115 1: not $r0 ; clear bit
118 #ifdef CONFIG_ETRAX_PA_LEDS
119 move.b $r2, [R_PORT_PA_DATA]
121 #ifdef CONFIG_ETRAX_PB_LEDS
122 move.b $r2, [R_PORT_PB_DATA]
126 ;; check if we got something on the serial port
128 move.b [SERSTAT], $r0
129 btstq 0, $r0 ; data_avail
133 ;; got something - copy the byte and loop
135 move.b [SERRDAT], $r0
137 move.d TIMEOUT_VALUE, $r5 ; reset "timeout"
138 subq 1, $r4 ; decrease length
142 ;; jump into downloaded code