head.S 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /* Boot entry point for MN10300 kernel
  2. *
  3. * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/threads.h>
  13. #include <linux/linkage.h>
  14. #include <linux/serial_reg.h>
  15. #include <asm/thread_info.h>
  16. #include <asm/page.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/frame.inc>
  19. #include <asm/param.h>
  20. #include <unit/serial.h>
  21. #ifdef CONFIG_SMP
  22. #include <asm/smp.h>
  23. #include <asm/intctl-regs.h>
  24. #include <asm/cpu-regs.h>
  25. #include <proc/smp-regs.h>
  26. #endif /* CONFIG_SMP */
  27. __HEAD
  28. ###############################################################################
  29. #
  30. # bootloader entry point
  31. #
  32. ###############################################################################
  33. .globl _start
  34. .type _start,@function
  35. _start:
  36. #ifdef CONFIG_SMP
  37. #
  38. # If this is a secondary CPU (AP), then deal with that elsewhere
  39. #
  40. mov (CPUID),d3
  41. and CPUID_MASK,d3
  42. bne startup_secondary
  43. #
  44. # We're dealing with the primary CPU (BP) here, then.
  45. # Keep BP's D0,D1,D2 register for boot check.
  46. #
  47. # Set up the Boot IPI for each secondary CPU
  48. mov 0x1,a0
  49. loop_set_secondary_icr:
  50. mov a0,a1
  51. asl CROSS_ICR_CPU_SHIFT,a1
  52. add CROSS_GxICR(SMP_BOOT_IRQ,0),a1
  53. movhu (a1),d3
  54. or GxICR_ENABLE|GxICR_LEVEL_0,d3
  55. movhu d3,(a1)
  56. movhu (a1),d3 # flush
  57. inc a0
  58. cmp NR_CPUS,a0
  59. bne loop_set_secondary_icr
  60. #endif /* CONFIG_SMP */
  61. # save commandline pointer
  62. mov d0,a3
  63. # preload the PGD pointer register
  64. mov swapper_pg_dir,d0
  65. mov d0,(PTBR)
  66. clr d0
  67. movbu d0,(PIDR)
  68. # turn on the TLBs
  69. mov MMUCTR_IIV|MMUCTR_DIV,d0
  70. mov d0,(MMUCTR)
  71. #ifdef CONFIG_AM34_2
  72. mov MMUCTR_ITE|MMUCTR_DTE|MMUCTR_CE|MMUCTR_WTE,d0
  73. #else
  74. mov MMUCTR_ITE|MMUCTR_DTE|MMUCTR_CE,d0
  75. #endif
  76. mov d0,(MMUCTR)
  77. # turn on AM33v2 exception handling mode and set the trap table base
  78. movhu (CPUP),d0
  79. or CPUP_EXM_AM33V2,d0
  80. movhu d0,(CPUP)
  81. mov CONFIG_INTERRUPT_VECTOR_BASE,d0
  82. mov d0,(TBR)
  83. # invalidate and enable both of the caches
  84. #ifdef CONFIG_SMP
  85. mov ECHCTR,a0
  86. clr d0
  87. mov d0,(a0)
  88. #endif
  89. mov CHCTR,a0
  90. clr d0
  91. movhu d0,(a0) # turn off first
  92. mov CHCTR_ICINV|CHCTR_DCINV,d0
  93. movhu d0,(a0)
  94. setlb
  95. mov (a0),d0
  96. btst CHCTR_ICBUSY|CHCTR_DCBUSY,d0 # wait till not busy
  97. lne
  98. #ifdef CONFIG_MN10300_CACHE_ENABLED
  99. #ifdef CONFIG_MN10300_CACHE_WBACK
  100. #ifndef CONFIG_MN10300_CACHE_WBACK_NOWRALLOC
  101. mov CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRBACK,d0
  102. #else
  103. mov CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRBACK|CHCTR_DCALMD,d0
  104. #endif /* NOWRALLOC */
  105. #else
  106. mov CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRTHROUGH,d0
  107. #endif /* WBACK */
  108. movhu d0,(a0) # enable
  109. #endif /* ENABLED */
  110. # turn on RTS on the debug serial port if applicable
  111. #ifdef CONFIG_MN10300_UNIT_ASB2305
  112. bset UART_MCR_RTS,(ASB2305_DEBUG_MCR)
  113. #endif
  114. # clear the BSS area
  115. mov __bss_start,a0
  116. mov __bss_stop,a1
  117. clr d0
  118. bssclear:
  119. cmp a1,a0
  120. bge bssclear_end
  121. mov d0,(a0)
  122. inc4 a0
  123. bra bssclear
  124. bssclear_end:
  125. # retrieve the parameters (including command line) before we overwrite
  126. # them
  127. cmp 0xabadcafe,d1
  128. bne __no_parameters
  129. __copy_parameters:
  130. mov redboot_command_line,a0
  131. mov a0,a1
  132. add COMMAND_LINE_SIZE,a1
  133. 1:
  134. movbu (a3),d0
  135. inc a3
  136. movbu d0,(a0)
  137. inc a0
  138. cmp a1,a0
  139. blt 1b
  140. mov redboot_platform_name,a0
  141. mov a0,a1
  142. add COMMAND_LINE_SIZE,a1
  143. mov d2,a3
  144. 1:
  145. movbu (a3),d0
  146. inc a3
  147. movbu d0,(a0)
  148. inc a0
  149. cmp a1,a0
  150. blt 1b
  151. __no_parameters:
  152. # set up the registers with recognisable rubbish in them
  153. mov init_thread_union+THREAD_SIZE-12,sp
  154. mov 0xea01eaea,d0
  155. mov d0,(4,sp) # EPSW save area
  156. mov 0xea02eaea,d0
  157. mov d0,(8,sp) # PC save area
  158. mov 0xeb0060ed,d0
  159. mov d0,mdr
  160. mov 0xeb0061ed,d0
  161. mov d0,mdrq
  162. mov 0xeb0062ed,d0
  163. mov d0,mcrh
  164. mov 0xeb0063ed,d0
  165. mov d0,mcrl
  166. mov 0xeb0064ed,d0
  167. mov d0,mcvf
  168. mov 0xed0065ed,a3
  169. mov a3,usp
  170. mov 0xed00e0ed,e0
  171. mov 0xed00e1ed,e1
  172. mov 0xed00e2ed,e2
  173. mov 0xed00e3ed,e3
  174. mov 0xed00e4ed,e4
  175. mov 0xed00e5ed,e5
  176. mov 0xed00e6ed,e6
  177. mov 0xed00e7ed,e7
  178. mov 0xed00d0ed,d0
  179. mov 0xed00d1ed,d1
  180. mov 0xed00d2ed,d2
  181. mov 0xed00d3ed,d3
  182. mov 0xed00a0ed,a0
  183. mov 0xed00a1ed,a1
  184. mov 0xed00a2ed,a2
  185. mov 0,a3
  186. # set up the initial kernel stack
  187. SAVE_ALL
  188. mov 0xffffffff,d0
  189. mov d0,(REG_ORIG_D0,fp)
  190. # put different recognisable rubbish in the regs
  191. mov 0xfb0060ed,d0
  192. mov d0,mdr
  193. mov 0xfb0061ed,d0
  194. mov d0,mdrq
  195. mov 0xfb0062ed,d0
  196. mov d0,mcrh
  197. mov 0xfb0063ed,d0
  198. mov d0,mcrl
  199. mov 0xfb0064ed,d0
  200. mov d0,mcvf
  201. mov 0xfd0065ed,a0
  202. mov a0,usp
  203. mov 0xfd00e0ed,e0
  204. mov 0xfd00e1ed,e1
  205. mov 0xfd00e2ed,e2
  206. mov 0xfd00e3ed,e3
  207. mov 0xfd00e4ed,e4
  208. mov 0xfd00e5ed,e5
  209. mov 0xfd00e6ed,e6
  210. mov 0xfd00e7ed,e7
  211. mov 0xfd00d0ed,d0
  212. mov 0xfd00d1ed,d1
  213. mov 0xfd00d2ed,d2
  214. mov 0xfd00d3ed,d3
  215. mov 0xfd00a0ed,a0
  216. mov 0xfd00a1ed,a1
  217. mov 0xfd00a2ed,a2
  218. # we may be holding current in E2
  219. #ifdef CONFIG_MN10300_CURRENT_IN_E2
  220. mov init_task,e2
  221. #endif
  222. # initialise the processor and the unit
  223. call processor_init[],0
  224. call unit_init[],0
  225. #ifdef CONFIG_SMP
  226. # mark the primary CPU in cpu_boot_map
  227. mov cpu_boot_map,a0
  228. mov 0x1,d0
  229. mov d0,(a0)
  230. # signal each secondary CPU to begin booting
  231. mov 0x1,d2 # CPU ID
  232. loop_request_boot_secondary:
  233. mov d2,a0
  234. # send SMP_BOOT_IPI to secondary CPU
  235. asl CROSS_ICR_CPU_SHIFT,a0
  236. add CROSS_GxICR(SMP_BOOT_IRQ,0),a0
  237. movhu (a0),d0
  238. or GxICR_REQUEST|GxICR_DETECT,d0
  239. movhu d0,(a0)
  240. movhu (a0),d0 # flush
  241. # wait up to 100ms for AP's IPI to be received
  242. clr d3
  243. wait_on_secondary_boot:
  244. mov DELAY_TIME_BOOT_IPI,d0
  245. call __delay[],0
  246. inc d3
  247. mov cpu_boot_map,a0
  248. mov (a0),d0
  249. lsr d2,d0
  250. btst 0x1,d0
  251. bne 1f
  252. cmp TIME_OUT_COUNT_BOOT_IPI,d3
  253. bne wait_on_secondary_boot
  254. 1:
  255. inc d2
  256. cmp NR_CPUS,d2
  257. bne loop_request_boot_secondary
  258. #endif /* CONFIG_SMP */
  259. #ifdef CONFIG_GDBSTUB
  260. call gdbstub_init[],0
  261. #ifdef CONFIG_GDBSTUB_IMMEDIATE
  262. .globl __gdbstub_pause
  263. __gdbstub_pause:
  264. bra __gdbstub_pause
  265. #endif
  266. #endif
  267. jmp start_kernel
  268. .size _start,.-_start
  269. ###############################################################################
  270. #
  271. # Secondary CPU boot point
  272. #
  273. ###############################################################################
  274. #ifdef CONFIG_SMP
  275. startup_secondary:
  276. # preload the PGD pointer register
  277. mov swapper_pg_dir,d0
  278. mov d0,(PTBR)
  279. clr d0
  280. movbu d0,(PIDR)
  281. # turn on the TLBs
  282. mov MMUCTR_IIV|MMUCTR_DIV,d0
  283. mov d0,(MMUCTR)
  284. #ifdef CONFIG_AM34_2
  285. mov MMUCTR_ITE|MMUCTR_DTE|MMUCTR_CE|MMUCTR_WTE,d0
  286. #else
  287. mov MMUCTR_ITE|MMUCTR_DTE|MMUCTR_CE,d0
  288. #endif
  289. mov d0,(MMUCTR)
  290. # turn on AM33v2 exception handling mode and set the trap table base
  291. movhu (CPUP),d0
  292. or CPUP_EXM_AM33V2,d0
  293. movhu d0,(CPUP)
  294. # set the interrupt vector table
  295. mov CONFIG_INTERRUPT_VECTOR_BASE,d0
  296. mov d0,(TBR)
  297. # invalidate and enable both of the caches
  298. mov ECHCTR,a0
  299. clr d0
  300. mov d0,(a0)
  301. mov CHCTR,a0
  302. clr d0
  303. movhu d0,(a0) # turn off first
  304. mov CHCTR_ICINV|CHCTR_DCINV,d0
  305. movhu d0,(a0)
  306. setlb
  307. mov (a0),d0
  308. btst CHCTR_ICBUSY|CHCTR_DCBUSY,d0 # wait till not busy (use CPU loop buffer)
  309. lne
  310. #ifdef CONFIG_MN10300_CACHE_ENABLED
  311. #ifdef CONFIG_MN10300_CACHE_WBACK
  312. #ifndef CONFIG_MN10300_CACHE_WBACK_NOWRALLOC
  313. mov CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRBACK,d0
  314. #else
  315. mov CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRBACK|CHCTR_DCALMD,d0
  316. #endif /* !NOWRALLOC */
  317. #else
  318. mov CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRTHROUGH,d0
  319. #endif /* WBACK */
  320. movhu d0,(a0) # enable
  321. #endif /* ENABLED */
  322. # Clear the boot IPI interrupt for this CPU
  323. movhu (GxICR(SMP_BOOT_IRQ)),d0
  324. and ~GxICR_REQUEST,d0
  325. movhu d0,(GxICR(SMP_BOOT_IRQ))
  326. movhu (GxICR(SMP_BOOT_IRQ)),d0 # flush
  327. /* get stack */
  328. mov CONFIG_INTERRUPT_VECTOR_BASE + CONFIG_BOOT_STACK_OFFSET,a0
  329. mov (CPUID),d0
  330. and CPUID_MASK,d0
  331. mulu CONFIG_BOOT_STACK_SIZE,d0
  332. sub d0,a0
  333. mov a0,sp
  334. # init interrupt for AP
  335. call smp_prepare_cpu_init[],0
  336. # mark this secondary CPU in cpu_boot_map
  337. mov (CPUID),d0
  338. mov 0x1,d1
  339. asl d0,d1
  340. mov cpu_boot_map,a0
  341. bset d1,(a0)
  342. or EPSW_IE|EPSW_IM_1,epsw # permit level 0 interrupts
  343. nop
  344. nop
  345. #ifdef CONFIG_MN10300_CACHE_WBACK
  346. # flush the local cache if it's in writeback mode
  347. call mn10300_local_dcache_flush_inv[],0
  348. setlb
  349. mov (CHCTR),d0
  350. btst CHCTR_DCBUSY,d0 # wait till not busy (use CPU loop buffer)
  351. lne
  352. #endif
  353. # now sleep waiting for further instructions
  354. secondary_sleep:
  355. mov CPUM_SLEEP,d0
  356. movhu d0,(CPUM)
  357. nop
  358. nop
  359. bra secondary_sleep
  360. .size startup_secondary,.-startup_secondary
  361. #endif /* CONFIG_SMP */
  362. ###############################################################################
  363. #
  364. #
  365. #
  366. ###############################################################################
  367. ENTRY(__head_end)
  368. /*
  369. * This is initialized to disallow all access to the low 2G region
  370. * - the high 2G region is managed directly by the MMU
  371. * - range 0x70000000-0x7C000000 are initialised for use by VMALLOC
  372. */
  373. .section .bss
  374. .balign PAGE_SIZE
  375. ENTRY(swapper_pg_dir)
  376. .space PTRS_PER_PGD*4
  377. /*
  378. * The page tables are initialized to only 8MB here - the final page
  379. * tables are set up later depending on memory size.
  380. */
  381. .balign PAGE_SIZE
  382. ENTRY(empty_zero_page)
  383. .space PAGE_SIZE
  384. .balign PAGE_SIZE
  385. ENTRY(empty_bad_page)
  386. .space PAGE_SIZE
  387. .balign PAGE_SIZE
  388. ENTRY(empty_bad_pte_table)
  389. .space PAGE_SIZE
  390. .balign PAGE_SIZE
  391. ENTRY(large_page_table)
  392. .space PAGE_SIZE
  393. .balign PAGE_SIZE
  394. ENTRY(kernel_vmalloc_ptes)
  395. .space ((VMALLOC_END-VMALLOC_START)/PAGE_SIZE)*4