board.c 1.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
5 6 7 8 9 10
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-09-15     QiuYi        the first version
 * 2006-10-10     Bernard      add hardware related of finsh
 */
wuyangyong's avatar
wuyangyong 已提交
11

12
#include <rthw.h>
13
#include <rtthread.h>
14 15 16

#include <bsp.h>

17 18 19 20
extern unsigned char __bss_start[];
extern unsigned char __bss_end[];
extern void rt_hw_console_init(void);

21 22 23 24
/**
 * @addtogroup QEMU
 */
/*@{*/
25
static void rt_timer_handler(int vector, void* param)
26
{
27
    rt_tick_increase();
M
Ming, Bai 已提交
28 29
}

30
#ifdef RT_USING_HOOK
M
Ming, Bai 已提交
31 32
static void idle_hook(void)
{
33
    asm volatile("sti; hlt": : :"memory");
34
}
35
#endif
36

37 38 39 40 41 42 43 44 45
/* clear .bss */
void rt_hw_clear_bss(void)
{
    unsigned char *dst;
    dst = __bss_start;
    while (dst < __bss_end)
        *dst++ = 0;
}

46 47 48 49 50 51
/**
 * This function will init QEMU
 *
 */
void rt_hw_board_init(void)
{
52 53 54 55 56
    /* clear .bss */
    rt_hw_clear_bss();

    /* init hardware interrupt */
    rt_hw_interrupt_init();
57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    /* init the console */
    rt_hw_console_init();
    rt_console_set_device("console");

    /* initialize 8253 clock to interrupt 1000 times/sec */
    outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT);
    outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) % 256);
    outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) / 256);

    /* install interrupt handler */
    rt_hw_interrupt_install(INTTIMER0, rt_timer_handler, RT_NULL, "tick");
    rt_hw_interrupt_umask(INTTIMER0);

    /* init memory system */
#ifdef RT_USING_HEAP
    /* RAM 16M */
    rt_system_heap_init((void *)&__bss_end, (void *)(1024UL*1024*8));
#endif
M
Ming, Bai 已提交
76

77
#ifdef RT_USING_HOOK
78
    rt_thread_idle_sethook(idle_hook);
79
#endif
80
}
M
Ming, Bai 已提交
81

82
static int reboot(void)
M
Ming, Bai 已提交
83 84 85
{
    outb(KBSTATP, 0xFE); /* pulse reset low */

86
    return 0;
M
Ming, Bai 已提交
87
}
88
MSH_CMD_EXPORT(reboot, reboot system);
89
/*@}*/