| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 1 | /* |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Rescue code to be prepended on a kimage and copied to the |
| 3 | * rescue serial port. |
| 4 | * This is called from the rescue code, it will copy received data to |
| 5 | * 4004000 and after a timeout jump to it. |
| 6 | */ |
| 7 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #define ASSEMBLER_MACROS_ONLY |
| Jesper Nilsson | 556dcee | 2008-10-21 17:45:58 +0200 | [diff] [blame] | 9 | #include <arch/sv_addr_ag.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
| 11 | #define CODE_START 0x40004000 |
| 12 | #define CODE_LENGTH 784 |
| 13 | #define TIMEOUT_VALUE 1000 |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 14 | |
| 15 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_ETRAX_RESCUE_SER0 |
| 17 | #define SERXOFF R_SERIAL0_XOFF |
| 18 | #define SERBAUD R_SERIAL0_BAUD |
| 19 | #define SERRECC R_SERIAL0_REC_CTRL |
| 20 | #define SERRDAT R_SERIAL0_REC_DATA |
| 21 | #define SERSTAT R_SERIAL0_STATUS |
| 22 | #endif |
| 23 | #ifdef CONFIG_ETRAX_RESCUE_SER1 |
| 24 | #define SERXOFF R_SERIAL1_XOFF |
| 25 | #define SERBAUD R_SERIAL1_BAUD |
| 26 | #define SERRECC R_SERIAL1_REC_CTRL |
| 27 | #define SERRDAT R_SERIAL1_REC_DATA |
| 28 | #define SERSTAT R_SERIAL1_STATUS |
| 29 | #endif |
| 30 | #ifdef CONFIG_ETRAX_RESCUE_SER2 |
| 31 | #define SERXOFF R_SERIAL2_XOFF |
| 32 | #define SERBAUD R_SERIAL2_BAUD |
| 33 | #define SERRECC R_SERIAL2_REC_CTRL |
| 34 | #define SERRDAT R_SERIAL2_REC_DATA |
| 35 | #define SERSTAT R_SERIAL2_STATUS |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 36 | #endif |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #ifdef CONFIG_ETRAX_RESCUE_SER3 |
| 38 | #define SERXOFF R_SERIAL3_XOFF |
| 39 | #define SERBAUD R_SERIAL3_BAUD |
| 40 | #define SERRECC R_SERIAL3_REC_CTRL |
| 41 | #define SERRDAT R_SERIAL3_REC_DATA |
| 42 | #define SERSTAT R_SERIAL3_STATUS |
| 43 | #endif |
| 44 | |
| 45 | .text |
| 46 | ;; This is the entry point of the rescue code |
| 47 | ;; 0x80000000 if loaded in flash (as it should be) |
| 48 | ;; since etrax actually starts at address 2 when booting from flash, we |
| 49 | ;; put a nop (2 bytes) here first so we dont accidentally skip the di |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 50 | |
| 51 | nop |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | di |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 53 | #ifndef CONFIG_SVINTO_SIM |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | ;; setup port PA and PB default initial directions and data |
| 55 | ;; (so we can flash LEDs, and so that DTR and others are set) |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 56 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | move.b CONFIG_ETRAX_DEF_R_PORT_PA_DIR, $r0 |
| 58 | move.b $r0, [R_PORT_PA_DIR] |
| 59 | move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r0 |
| 60 | move.b $r0, [R_PORT_PA_DATA] |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 61 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | move.b CONFIG_ETRAX_DEF_R_PORT_PB_DIR, $r0 |
| 63 | move.b $r0, [R_PORT_PB_DIR] |
| 64 | move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r0 |
| 65 | move.b $r0, [R_PORT_PB_DATA] |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 66 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | ;; We need to setup the bus registers before we start using the DRAM |
| 68 | #include "../../lib/dram_init.S" |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 69 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #endif |
| 71 | ;; Setup the stack to a suitably high address. |
| 72 | ;; We assume 8 MB is the minimum DRAM in an eLinux |
| 73 | ;; product and put the sp at the top for now. |
| 74 | |
| 75 | move.d 0x40800000, $sp |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 76 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | ;; setup the serial port at 115200 baud |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 78 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | moveq 0, $r0 |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 80 | move.d $r0, [SERXOFF] |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | move.b 0x99, $r0 |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 83 | move.b $r0, [SERBAUD] ; 115.2kbaud for both transmit |
| 84 | ; and receive |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | move.b 0x40, $r0 ; rec enable |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 87 | move.b $r0, [SERRECC] |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 90 | moveq 0, $r1 ; "timer" to clock out a LED red flash |
| 91 | move.d CODE_START, $r3 ; destination counter |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | move.d CODE_LENGTH, $r4 ; length |
| 93 | move.d TIMEOUT_VALUE, $r5 ; "timeout" until jump |
| 94 | |
| 95 | wait_ser: |
| 96 | addq 1, $r1 |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 97 | subq 1, $r5 ; decrease timeout |
| 98 | beq jump_start ; timed out |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | nop |
| 100 | #ifndef CONFIG_ETRAX_NO_LEDS |
| 101 | #ifdef CONFIG_ETRAX_PA_LEDS |
| 102 | move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r2 |
| 103 | #endif |
| 104 | #ifdef CONFIG_ETRAX_PB_LEDS |
| 105 | move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r2 |
| 106 | #endif |
| 107 | move.d (1 << CONFIG_ETRAX_LED1R) | (1 << CONFIG_ETRAX_LED2R), $r0 |
| 108 | btstq 16, $r1 |
| 109 | bpl 1f |
| 110 | nop |
| 111 | or.d $r0, $r2 ; set bit |
| 112 | ba 2f |
| 113 | nop |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 114 | 1: not $r0 ; clear bit |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | and.d $r0, $r2 |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 116 | 2: |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #ifdef CONFIG_ETRAX_PA_LEDS |
| 118 | move.b $r2, [R_PORT_PA_DATA] |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 119 | #endif |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #ifdef CONFIG_ETRAX_PB_LEDS |
| 121 | move.b $r2, [R_PORT_PB_DATA] |
| 122 | #endif |
| 123 | #endif |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 124 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | ;; check if we got something on the serial port |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 126 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | move.b [SERSTAT], $r0 |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 128 | btstq 0, $r0 ; data_avail |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | bpl wait_ser |
| 130 | nop |
| 131 | |
| 132 | ;; got something - copy the byte and loop |
| 133 | |
| 134 | move.b [SERRDAT], $r0 |
| 135 | move.b $r0, [$r3+] |
| 136 | move.d TIMEOUT_VALUE, $r5 ; reset "timeout" |
| Jesper Nilsson | ef8028a | 2008-01-17 11:30:21 +0100 | [diff] [blame] | 137 | subq 1, $r4 ; decrease length |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | bne wait_ser |
| 139 | nop |
| 140 | jump_start: |
| 141 | ;; jump into downloaded code |
| 142 | |
| 143 | jump CODE_START |