resethandler.s 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2018 Damien P. George
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. .syntax unified
  27. .cpu cortex-m4
  28. .thumb
  29. .section .text.Reset_Handler
  30. .global Reset_Handler
  31. .type Reset_Handler, %function
  32. Reset_Handler:
  33. /* Save the first argument to pass through to stm32_main */
  34. mov r4, r0
  35. /* Load the stack pointer */
  36. ldr sp, =_estack
  37. /* Initialise the data section */
  38. ldr r1, =_sidata
  39. ldr r2, =_sdata
  40. ldr r3, =_edata
  41. b .data_copy_entry
  42. .data_copy_loop:
  43. ldr r0, [r1], #4 /* Should be 4-aligned to be as fast as possible */
  44. str r0, [r2], #4
  45. .data_copy_entry:
  46. cmp r2, r3
  47. bcc .data_copy_loop
  48. /* Zero out the BSS section */
  49. movs r0, #0
  50. ldr r1, =_sbss
  51. ldr r2, =_ebss
  52. b .bss_zero_entry
  53. .bss_zero_loop:
  54. str r0, [r1], #4 /* Should be 4-aligned to be as fast as possible */
  55. .bss_zero_entry:
  56. cmp r1, r2
  57. bcc .bss_zero_loop
  58. /* Initialise the system and jump to the main code */
  59. bl SystemInit
  60. mov r0, r4
  61. b stm32_main
  62. .size Reset_Handler, .-Reset_Handler