summaryrefslogtreecommitdiff
path: root/bsp/x86/drivers/board.c
blob: cb92a3a0bf20ba06861728bb704ae057989f112a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-09-15     QiuYi        the first version
 * 2006-10-10     Bernard      add hardware related of finsh
 */

#include <rtthread.h>
#include <rthw.h>

#include <bsp.h>

/**
 * @addtogroup QEMU
 */
/*@{*/

static void rt_timer_handler(int vector, void* param)
{
    rt_tick_increase();
}

#ifdef RT_USING_HOOK
static void idle_hook(void)
{
    asm volatile("sti; hlt": : :"memory");
}
#endif

/**
 * This function will init QEMU
 *
 */
void rt_hw_board_init(void)
{
    /* 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);

#ifdef RT_USING_HOOK
    rt_thread_idle_sethook(idle_hook);
#endif
}

void restart(void)
{
    outb(KBSTATP, 0xFE); /* pulse reset low */
    while(1);
}

#ifdef RT_USING_FINSH
#include <finsh.h>
FINSH_FUNCTION_EXPORT(restart, reboot PC)

void reboot(void)
{
    restart();
}
FINSH_FUNCTION_EXPORT(reboot, reboot PC)
#endif
/*@}*/