head.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * arch/v850/kernel/head.S -- Lowest-level startup code
  3. *
  4. * Copyright (C) 2001,02,03 NEC Electronics Corporation
  5. * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file COPYING in the main directory of this
  9. * archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #include <asm/clinkage.h>
  14. #include <asm/current.h>
  15. #include <asm/entry.h>
  16. #include <asm/thread_info.h>
  17. #include <asm/irq.h>
  18. /* Make a slightly more convenient alias for C_SYMBOL_NAME. */
  19. #define CSYM C_SYMBOL_NAME
  20. .text
  21. // Define `mach_early_init' as a weak symbol
  22. .global CSYM(mach_early_init)
  23. .weak CSYM(mach_early_init)
  24. C_ENTRY(start):
  25. // Make sure interrupts are turned off, just in case
  26. di
  27. #ifdef CONFIG_RESET_GUARD
  28. // See if we got here via an unexpected reset
  29. ld.w RESET_GUARD, r19 // Check current value of reset guard
  30. mov RESET_GUARD_ACTIVE, r20
  31. cmp r19, r20
  32. bne 1f // Guard was not active
  33. // If we get here, the reset guard was active. Load up some
  34. // interesting values as arguments, and jump to the handler.
  35. st.w r0, RESET_GUARD // Allow further resets to succeed
  36. mov lp, r6 // Arg 0: return address
  37. ld.b KM, r7 // Arg 1: kernel mode
  38. mov sp, r9 // Arg 3: stack pointer
  39. ld.w KSP, r19 // maybe switch to kernel stack
  40. cmp r7, r0 // see if already in kernel mode
  41. cmov z, r19, sp, sp // and switch to kernel stack if not
  42. GET_CURRENT_TASK(r8) // Arg 2: task pointer
  43. jr CSYM(unexpected_reset)
  44. 1: st.w r20, RESET_GUARD // Turn on reset guard
  45. #endif /* CONFIG_RESET_GUARD */
  46. // Setup a temporary stack for doing pre-initialization function calls.
  47. //
  48. // We can't use the initial kernel stack, because (1) it may be
  49. // located in memory we're not allowed to touch, and (2) since
  50. // it's in the data segment, calling memcpy to initialize that
  51. // area from ROM will overwrite memcpy's return address.
  52. mov hilo(CSYM(_init_stack_end) - 4), sp
  53. // See if there's a platform-specific early-initialization routine
  54. // defined; it's a weak symbol, so it will have an address of zero if
  55. // there's not.
  56. mov hilo(CSYM(mach_early_init)), r6
  57. cmp r6, r0
  58. bz 3f
  59. // There is one, so call it. If this function is written in C, it
  60. // should be very careful -- the stack pointer is valid, but very
  61. // little else is (e.g., bss is not zeroed yet, and initialized data
  62. // hasn't been).
  63. jarl 2f, lp // first figure out return address
  64. 2: add 3f - ., lp
  65. jmp [r6] // do call
  66. 3:
  67. #ifdef CONFIG_ROM_KERNEL
  68. // Copy the data area from ROM to RAM
  69. mov hilo(CSYM(_rom_copy_dst_start)), r6
  70. mov hilo(CSYM(_rom_copy_src_start)), r7
  71. mov hilo(CSYM(_rom_copy_dst_end)), r8
  72. sub r6, r8
  73. jarl CSYM(memcpy), lp
  74. #endif
  75. // Load the initial thread's stack, and current task pointer (in r16)
  76. mov hilo(CSYM(init_thread_union)), r19
  77. movea THREAD_SIZE, r19, sp
  78. ld.w TI_TASK[r19], CURRENT_TASK
  79. #ifdef CONFIG_TIME_BOOTUP
  80. /* This stuff must come after mach_early_init, because interrupts may
  81. not work until after its been called. */
  82. jarl CSYM(highres_timer_reset), lp
  83. jarl CSYM(highres_timer_start), lp
  84. #endif
  85. // Kernel stack pointer save location
  86. st.w sp, KSP
  87. // Assert that we're in `kernel mode'
  88. mov 1, r19
  89. st.w r19, KM
  90. #ifdef CONFIG_ZERO_BSS
  91. // Zero bss area, since we can't rely upon any loader to do so
  92. mov hilo(CSYM(_sbss)), r6
  93. mov r0, r7
  94. mov hilo(CSYM(_ebss)), r8
  95. sub r6, r8
  96. jarl CSYM(memset), lp
  97. #endif
  98. // What happens if the main kernel function returns (it shouldn't)
  99. mov hilo(CSYM(machine_halt)), lp
  100. // Start the linux kernel. We use an indirect jump to get extra
  101. // range, because on some platforms this initial startup code
  102. // (and the associated platform-specific code in mach_early_init)
  103. // are located far away from the main kernel, e.g. so that they
  104. // can initialize RAM first and copy the kernel or something.
  105. mov hilo(CSYM(start_kernel)), r12
  106. jmp [r12]
  107. C_END(start)