Top 7.74 KB
Newer Older
Jeffrey Lee's avatar
Jeffrey Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
; Copyright 2009 Castle Technology Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
15 16 17 18

        GET     Hdr:ListOpts
        GET     Hdr:Macros
        GET     Hdr:System
Jeffrey Lee's avatar
Jeffrey Lee committed
19
        GET     Hdr:Machine.<Machine>
20
        GET     Hdr:HALSize.<HALSize>
Jeffrey Lee's avatar
Jeffrey Lee committed
21

22
        GET     Hdr:MEMM.VMSAv6
Jeffrey Lee's avatar
Jeffrey Lee committed
23

24 25 26 27
        GET     Hdr:Proc
        GET     Hdr:OSEntries
        GET     Hdr:HALEntries

Jeffrey Lee's avatar
Jeffrey Lee committed
28
        GET     hdr.omap3530
29
        GET     hdr.StaticWS
Jeffrey Lee's avatar
Jeffrey Lee committed
30 31 32
        GET     hdr.UART
        GET     hdr.Post
        GET     hdr.SDRC
33
        GET     hdr.Copro15ops
34
        GET     hdr.GPIO
Jeffrey Lee's avatar
Jeffrey Lee committed
35

36 37
        AREA    |!!!ROMStart|, CODE, READONLY, PIC

Jeffrey Lee's avatar
Jeffrey Lee committed
38
        IMPORT  rom_checkedout_ok
39
        EXPORT  HAL_Base
Jeffrey Lee's avatar
Jeffrey Lee committed
40
        IMPORT  HAL_DebugTX
41

42 43 44 45 46 47
        MACRO
        CallOSM $entry, $reg
        LDR     ip, [v8, #$entry*4]
        MOV     lr, pc
        ADD     pc, v8, ip
        MEND
48

49 50 51 52 53 54 55 56 57 58
        ; Jump table used to select board config on startup
        ; See board.s for ordering of configs, and therefore what entry corresponds to what board
HAL_Base
        BL      selectconfig
        BL      selectconfig
        BL      selectconfig
        BL      selectconfig
        BL      selectconfig
        BL      selectconfig
JumpTableEnd
59 60 61
        ASSERT  . - HAL_Base < 0x60
        %       0x60 - (. - HAL_Base)
ROMsize
62
        DCD     0 ; patched in by build system. See ROMSizeOffset in Hdr:Machine.Machine
63
        B       selectconfig_linux ; offset &64 - for booting as a uImage/Linux kernel. Uses Linux machine type ID to select board config.
64 65

        ENTRY
66 67 68 69 70 71 72
selectconfig
        ; Get pointer to board config
        ADR     v1, HAL_Base+4
        SUB     v1, lr, v1
        ADR     a1, BoardConfigTable
        MOV     a2, #BoardConfig_Size>>2
        MLA     v1, a2, v1, a1
73 74
foundconfig
        ; v1 = board config
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
        MSR     CPSR_c, #F32_bit+I32_bit+SVC32_mode ; Get into SVC mode now, so we can write to sb without much fear of losing it (we may have been in FIQ)
 [ Debug
        ; Announce ourselves if debug
        ADR     v2, HelloWorld
        MOV     sb, v1
10      LDRB    a1, [v2], #1
        CMP     a1, #0
        ADRNE   lr, %BT10
        BNE     HAL_DebugTX
        ADD     v2, v1, #BoardConfig_Name
10      LDRB    a1, [v2], #1
        CMP     a1, #0
        ADRNE   lr, %BT10
        BNE     HAL_DebugTX
        MOV     a1, #13
        BL      HAL_DebugTX
        MOV     a1, #10
        BL      HAL_DebugTX
 ]
        ; Now copy the config to SRAM
        ; We'll assume that the L3 interconnect has been correctly configured to give us access
        LDR     sb, =IntSRAM_Base
        MOV     a2, #BoardConfig_Size
10      SUBS    a2, a2, #4
        LDR     a3, [v1, a2]
        STR     a3, [sb, a2]
        BGT     %BT10
        ; Now do common init
Jeffrey Lee's avatar
Jeffrey Lee committed
103 104
        B       restart

105 106 107 108
 [ Debug
HelloWorld DCB "OMAP3 HAL init",13,10,"Board config=",0
        ALIGN
 ]
109

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        ; Entry point for masquerading as a Linux kernel
        ; r0=0
        ; r1=machine type ID
        ; r2=ptr to tag list (linux/include/asm/setup.h)
selectconfig_linux
        ADR     v1, BoardConfigTable_End-BoardConfig_Size
        ADR     a3, BoardConfigTable
10
        LDR     a1, [v1, #BoardConfig_MachID]
        CMP     a1, a2
        CMPNE   v1, a3 ; If we can't find a config, abort and use default? (i.e. beagleboard)
        BEQ     foundconfig
        SUB     v1, v1, #BoardConfig_Size
        B       %BT10

Jeffrey Lee's avatar
Jeffrey Lee committed
125
        LTORG
126 127
        GET     board.s
        ASSERT  ((JumpTableEnd-HAL_Base)/4) >= (BoardConfigTable_End-BoardConfigTable)/BoardConfig_Size ; If this fires, we need a bigger jump table!
Jeffrey Lee's avatar
Jeffrey Lee committed
128 129

; ------------------------------------------------------------------------------
130 131
; Perform some Cortex-A8 specific CPU setup
; Then start looking for RAM
132
; In: sb = board config ptr
Jeffrey Lee's avatar
Jeffrey Lee committed
133
restart
134
        DebugChar a3,a4,48
Jeffrey Lee's avatar
Jeffrey Lee committed
135
        MSR     CPSR_c, #F32_bit+I32_bit+SVC32_mode
136
        DebugChar a3,a4,49
Jeffrey Lee's avatar
Jeffrey Lee committed
137

138
        ADRL    v1, HAL_Base + OSROM_HALSize    ; v1 -> RISC OS image
Jeffrey Lee's avatar
Jeffrey Lee committed
139 140 141 142

        LDR     v8, [v1, #OSHdr_Entries]
        ADD     v8, v8, v1                      ; v8 -> RISC OS entry table

Jeffrey Lee's avatar
Jeffrey Lee committed
143 144 145 146
        ; Ensure CPU is set up
        MOV     a1, #0
        CallOSM OS_InitARM
        DebugChar a3,a4,50
Jeffrey Lee's avatar
Jeffrey Lee committed
147

148 149 150 151
        ; Initialise RAM
        BL      init_ram

        ; The first 4K of the first registered block of RAM is used by RISC OS's init code, and also contains the stack
Jeffrey Lee's avatar
Jeffrey Lee committed
152
        ; To keep things simple and safe, we'll relocate the HAL and OS image to the top end of RAM
153
        ; Although with the beagleboard we know we'll be booted from RAM, this code has been written so that it should work if running from ROM
Jeffrey Lee's avatar
Jeffrey Lee committed
154 155 156 157 158 159 160

        ; First, identify the top end of RAM
        ; Then check if we intersect it
        ; If we do, first copy ourselves down
        ; Then copy ourselves up

relocate_code
161
        DebugChar a1,a2,66
Jeffrey Lee's avatar
Jeffrey Lee committed
162
        BL      get_end_of_ram
163
        DebugChar v1,v2,67
Jeffrey Lee's avatar
Jeffrey Lee committed
164 165

        ; How big are we?
166
        ADRL    v1, HAL_Base + OSROM_HALSize
Jeffrey Lee's avatar
Jeffrey Lee committed
167
        LDR     v2, [v1, #OSHdr_ImageSize]
168 169
        SUB     v1, v1, #OSROM_HALSize ; Start of HAL
        ADD     v2, v2, #OSROM_HALSize ; Size of HAL+OS
Jeffrey Lee's avatar
Jeffrey Lee committed
170 171 172 173 174
        ADD     v3, v1, v2 ; End of OS
        MOV     v4, a1 ; End of RAM
        SUB     v5, v4, v2 ; New start address of HAL
        CMP     v1, v5
        BEQ     %FT10 ; No copy needed
175
        BHI     %FT20 ; We're in some ROM above RAM. OK to continue with copy.
Jeffrey Lee's avatar
Jeffrey Lee committed
176
        CMP     v3, v5
177
        BLS     %FT20 ; We're in some ROM/RAM below our copy destination. OK to continue with copy.
Jeffrey Lee's avatar
Jeffrey Lee committed
178 179 180 181 182 183 184 185 186
        ; Else we currently overlap the area we want to copy ourselves into.
        SUB     v5, v1, v2 ; Copy the HAL+OS to just before itself
20
        MOV     a1, v5
        MOV     a2, v1 ; Copy source
        MOV     a3, v2
30
        LDR     a4, [a2], #4
        SUBS    a3, a3, #4
187
        STR     a4, [a1], #4
Jeffrey Lee's avatar
Jeffrey Lee committed
188
        BGT     %BT30
189
        ; Invalidate I-cache, branch predictors
Jeffrey Lee's avatar
Jeffrey Lee committed
190
        MOV     a1, #0
191
        MCR     p15, 0, a1, c7, c5, 0
192 193 194
        MCR     p15, 0, a1, c7, c5, 6
        myDSB ; Wait for I-cache invalidation to complete
        myISB ; Wait for branch predictor invalidation to complete?
195
        DebugChar a1,a2,68
Jeffrey Lee's avatar
Jeffrey Lee committed
196 197 198 199 200 201 202 203 204 205 206
        ; Jump to our new copy
        ADR     a1, relocate_code ; Keep things simple by just running through the same code again
        SUB     a2, v5, v1
        ADD     a1, a1, a2 ; relocate our branch target
        ADD     v8, v8, a2 ; Update OS entry table ptr
        MOV     pc, a1
10
        ; Copy completed OK.
        ; v2 = size of HAL+OS
        ; v4 = end of OS/RAM
        ; v5 = start of HAL
207
        ; v8 = OS entry table ptr
208
        DebugChar a1,a2,69
Jeffrey Lee's avatar
Jeffrey Lee committed
209 210 211 212
        ; Clear RAM up to v5
        MOV     a1, v5
        BL      clear_ram

213
        DebugChar a1,a2,70
Jeffrey Lee's avatar
Jeffrey Lee committed
214

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
; TODO - NEON seems to be on by default, need to work out how to turn it off before I can test code to turn it on!
;        ; Enable power to the NEON unit, if present
;        LDR     a1, =&4800244C ; 'control OMAP status register'
;        LDR     a1, [a1]
;        TST     a1, #1<<4
;        BNE     %FT10
;;        ; NEON is available, make sure it's turned on
;        ; Enable CP10/CP11 access
;        MRC     p15, 0, a1, c1, c0, 2
;        ORR     a1, a1, #&F<<20
;        MCR     p15, 0, a1, c1, c0, 2
;        DCI     &F57FF06F ; ISB {SY}
;        ; Now enable the unit
;        MOV     a1, #1<<30 ; EN bit
;        DCI     &EEE80A10 ; VMSR FPEXC, a1

Jeffrey Lee's avatar
Jeffrey Lee committed
231
        B       rom_checkedout_ok
232

Ben Avison's avatar
Ben Avison committed
233
        GET     RAM.s
234 235 236
        LTORG

        END