start.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2005 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  21. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. */
  31. /*
  32. * $Log$
  33. * Revision 1.1 2005/11/03 15:14:27 haraldkipp
  34. * First import.
  35. *
  36. */
  37. #include "avr/io.h"
  38. .text
  39. /*
  40. * Disable interrupts and initialize the stack pointer.
  41. */
  42. .global __boot_entry
  43. __boot_entry:
  44. cli
  45. ldi r18, lo8(RAMEND)
  46. out _SFR_IO_ADDR(SPL), r18
  47. ldi r18, hi8(RAMEND)
  48. out _SFR_IO_ADDR(SPH), r18
  49. /*
  50. * Copy initialized data from ROM to RAM.
  51. */
  52. .global __boot_idata
  53. __boot_idata:
  54. ldi r18, hi8(__data_end)
  55. ldi XL, lo8(__data_start)
  56. ldi XH, hi8(__data_start)
  57. ldi ZL, hh8(__data_load_start)
  58. out _SFR_IO_ADDR(RAMPZ), ZL
  59. ldi ZL, lo8(__data_load_start)
  60. ldi ZH, hi8(__data_load_start)
  61. __boot_idata_next:
  62. cpi XL, lo8(__data_end)
  63. cpc XH, r18
  64. breq __boot_idata_done
  65. elpm r0, Z+
  66. st X+, r0
  67. rjmp __boot_idata_next
  68. __boot_idata_done:
  69. /*
  70. * Clear uninitialized global data.
  71. */
  72. .global __boot_ibss
  73. __boot_ibss:
  74. clr r1
  75. ldi YL, hi8(__bss_end)
  76. ldi XL, lo8(__bss_start)
  77. ldi XH, hi8(__bss_start)
  78. __boot_ibss_next:
  79. cpi XL, lo8(__bss_end)
  80. cpc XH, YL
  81. breq __boot_ibss_done
  82. st X+, r1
  83. rjmp __boot_ibss_next
  84. __boot_ibss_done:
  85. /*
  86. * Call bootloader.
  87. */
  88. .global __boot_start
  89. __boot_start:
  90. call main
  91. /*
  92. * Jump to application.
  93. */
  94. .global exit
  95. exit:
  96. jmp 0