startup.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-06-25 Bernard first version
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include <cache.h>
  17. #include "board.h"
  18. #define A_K0BASE 0x80000000
  19. /**
  20. * @addtogroup Loongson SoC3210
  21. */
  22. /*@{*/
  23. extern unsigned char __bss_start;
  24. extern unsigned char __bss_end;
  25. extern int rt_application_init(void);
  26. void dump_mem(const unsigned char* addr)
  27. {
  28. int size;
  29. rt_kprintf("---- memory: 0x%08x ----\n", addr);
  30. for (size = 0; size < 32 * 4; size ++)
  31. {
  32. rt_kprintf("%02x ", (*addr) & 0xff);
  33. addr ++;
  34. if ((size + 1) % 16 == 0)
  35. rt_kprintf("\n");
  36. }
  37. rt_kprintf("\n");
  38. }
  39. extern void tlb_refill_exception(void);
  40. extern void general_exception(void);
  41. extern void irq_exception(void);
  42. /**
  43. * This function will startup RT-Thread RTOS.
  44. */
  45. void rtthread_startup(void)
  46. {
  47. /* init cache */
  48. rt_hw_cache_init();
  49. /* init hardware interrupt */
  50. rt_hw_interrupt_init();
  51. /* copy vector */
  52. memcpy((void *)A_K0BASE, tlb_refill_exception, 0x20);
  53. memcpy((void *)(A_K0BASE + 0x180), general_exception, 0x20);
  54. memcpy((void *)(A_K0BASE + 0x200), irq_exception, 0x20);
  55. /* init board */
  56. rt_hw_board_init();
  57. rt_show_version();
  58. /* init tick */
  59. rt_system_tick_init();
  60. /* init timer system */
  61. rt_system_timer_init();
  62. #ifdef RT_USING_HEAP
  63. rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END);
  64. #endif
  65. /* init scheduler system */
  66. rt_system_scheduler_init();
  67. #ifdef RT_USING_DEVICE
  68. /* init all device */
  69. rt_device_init_all();
  70. #endif
  71. /* init application */
  72. rt_application_init();
  73. #ifdef RT_USING_FINSH
  74. /* init finsh */
  75. finsh_system_init();
  76. finsh_set_device(FINSH_DEVICE_NAME);
  77. #endif
  78. /* init idle thread */
  79. rt_thread_idle_init();
  80. /* start scheduler */
  81. rt_system_scheduler_start();
  82. /* never reach here */
  83. return ;
  84. }
  85. /*@}*/