1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <sys/types.h>
21
22#include "qemu/osdep.h"
23#include "cpu.h"
24#include "qemu.h"
25#include "qemu/timer.h"
26
27#include "target_arch.h"
28
29static uint64_t *idt_table;
30
31uint64_t cpu_get_tsc(CPUX86State *env)
32{
33 return cpu_get_host_ticks();
34}
35
36void bsd_i386_write_dt(void *ptr, unsigned long addr, unsigned long limit,
37 int flags)
38{
39 unsigned int e1, e2;
40 uint32_t *p;
41 e1 = (addr << 16) | (limit & 0xffff);
42 e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000);
43 e2 |= flags;
44 p = ptr;
45 p[0] = tswap32(e1);
46 p[1] = tswap32(e2);
47}
48
49
50static void set_gate(void *ptr, unsigned int type, unsigned int dpl,
51 uint32_t addr, unsigned int sel)
52{
53 uint32_t *p, e1, e2;
54 e1 = (addr & 0xffff) | (sel << 16);
55 e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
56 p = ptr;
57 p[0] = tswap32(e1);
58 p[1] = tswap32(e2);
59}
60
61
62void bsd_i386_set_idt(int n, unsigned int dpl)
63{
64 set_gate(idt_table + n, 0, dpl, 0, 0);
65}
66
67void bsd_i386_set_idt_base(uint64_t base)
68{
69 idt_table = g2h_untagged(base);
70}
71
72