http://www.usr.com/support/gpl/USR9107_release1.1.tar.gz
[bcm963xx.git] / kernel / linux / arch / cris / arch-v10 / boot / rescue / kimagerescue.S
1 /* $Id: kimagerescue.S,v 1.1 2001/12/17 13:59:27 bjornw Exp $
2  * 
3  * Rescue code to be prepended on a kimage and copied to the
4  * rescue serial port.
5  * This is called from the rescue code, it will copy received data to
6  * 4004000 and after a timeout jump to it.
7  */
8
9 #include <linux/config.h>
10 #define ASSEMBLER_MACROS_ONLY
11 #include <asm/sv_addr_ag.h>
12
13 #define CODE_START 0x40004000
14 #define CODE_LENGTH 784
15 #define TIMEOUT_VALUE 1000
16         
17                 
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
24 #endif
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
31 #endif
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
38 #endif  
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
45 #endif
46
47         .text
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
52         
53         nop     
54         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)
58         
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]
63         
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]
68         
69         ;; We need to setup the bus registers before we start using the DRAM
70 #include "../../lib/dram_init.S"
71         
72 #endif
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.
76
77         move.d  0x40800000, $sp
78         
79         ;; setup the serial port at 115200 baud
80         
81         moveq   0, $r0
82         move.d  $r0, [SERXOFF] 
83
84         move.b  0x99, $r0
85         move.b  $r0, [SERBAUD]          ; 115.2kbaud for both transmit and receive
86
87         move.b  0x40, $r0               ; rec enable
88         move.b  $r0, [SERRECC] 
89
90
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
95
96 wait_ser:
97         addq    1, $r1
98         subq    1, $r5          ; decrease timeout
99         beq     jump_start      ; timed out
100         nop
101 #ifndef CONFIG_ETRAX_NO_LEDS
102 #ifdef CONFIG_ETRAX_PA_LEDS
103         move.b  CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r2
104 #endif
105 #ifdef CONFIG_ETRAX_PB_LEDS
106         move.b  CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r2
107 #endif
108         move.d  (1 << CONFIG_ETRAX_LED1R) | (1 << CONFIG_ETRAX_LED2R), $r0
109         btstq   16, $r1
110         bpl     1f
111         nop
112         or.d    $r0, $r2                ; set bit
113         ba      2f
114         nop
115 1:      not     $r0             ; clear bit
116         and.d   $r0, $r2
117 2:      
118 #ifdef CONFIG_ETRAX_PA_LEDS
119         move.b  $r2, [R_PORT_PA_DATA]
120 #endif  
121 #ifdef CONFIG_ETRAX_PB_LEDS
122         move.b  $r2, [R_PORT_PB_DATA]
123 #endif
124 #endif
125                 
126         ;; check if we got something on the serial port
127         
128         move.b  [SERSTAT], $r0
129         btstq   0, $r0          ; data_avail
130         bpl     wait_ser
131         nop
132
133         ;; got something - copy the byte and loop
134
135         move.b  [SERRDAT], $r0
136         move.b  $r0, [$r3+]
137         move.d  TIMEOUT_VALUE, $r5      ; reset "timeout"
138         subq    1, $r4          ; decrease length
139         bne     wait_ser
140         nop
141 jump_start:
142         ;; jump into downloaded code
143
144         jump    CODE_START