board.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2006-09-15 QiuYi the first version
  9. * 2006-10-10 Bernard add hardware related of finsh
  10. */
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include <bsp.h>
  14. extern unsigned char __bss_start[];
  15. extern unsigned char __bss_end[];
  16. extern void rt_hw_console_init(void);
  17. /**
  18. * @addtogroup QEMU
  19. */
  20. /*@{*/
  21. static void rt_timer_handler(int vector, void* param)
  22. {
  23. rt_tick_increase();
  24. }
  25. #ifdef RT_USING_HOOK
  26. static void idle_hook(void)
  27. {
  28. asm volatile("sti; hlt": : :"memory");
  29. }
  30. #endif
  31. /* clear .bss */
  32. void rt_hw_clear_bss(void)
  33. {
  34. unsigned char *dst;
  35. dst = __bss_start;
  36. while (dst < __bss_end)
  37. *dst++ = 0;
  38. }
  39. /**
  40. * This function will init QEMU
  41. *
  42. */
  43. void rt_hw_board_init(void)
  44. {
  45. /* clear .bss */
  46. rt_hw_clear_bss();
  47. /* init hardware interrupt */
  48. rt_hw_interrupt_init();
  49. /* init the console */
  50. rt_hw_console_init();
  51. rt_console_set_device("console");
  52. /* initialize 8253 clock to interrupt 1000 times/sec */
  53. outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT);
  54. outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) % 256);
  55. outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) / 256);
  56. /* install interrupt handler */
  57. rt_hw_interrupt_install(INTTIMER0, rt_timer_handler, RT_NULL, "tick");
  58. rt_hw_interrupt_umask(INTTIMER0);
  59. /* init memory system */
  60. #ifdef RT_USING_HEAP
  61. /* RAM 16M */
  62. rt_system_heap_init((void *)&__bss_end, (void *)(1024UL*1024*8));
  63. #endif
  64. #ifdef RT_USING_HOOK
  65. rt_thread_idle_sethook(idle_hook);
  66. #endif
  67. }
  68. static int reboot(void)
  69. {
  70. outb(KBSTATP, 0xFE); /* pulse reset low */
  71. return 0;
  72. }
  73. MSH_CMD_EXPORT(reboot, reboot system);
  74. /*@}*/