master
c 59 lines 1.25 KB
Raw
1 /*
2 * x86_64 cpu related code
3 *
4 * Copyright (c) 2013 Stacey D. Son
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "qemu/osdep.h"
10
11 #include "cpu.h"
12 #include "qemu.h"
13 #include "qemu/timer.h"
14
15 #include "target_arch.h"
16
17 static uint64_t *idt_table;
18
19 uint64_t cpu_get_tsc(CPUX86State *env)
20 {
21 return cpu_get_host_ticks();
22 }
23
24 void bsd_x86_64_write_dt(void *ptr, unsigned long addr,
25 unsigned long limit, int flags)
26 {
27 unsigned int e1, e2;
28 uint32_t *p;
29 e1 = (addr << 16) | (limit & 0xffff);
30 e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000);
31 e2 |= flags;
32 p = ptr;
33 p[0] = tswap32(e1);
34 p[1] = tswap32(e2);
35 }
36
37 static void set_gate64(void *ptr, unsigned int type, unsigned int dpl,
38 uint64_t addr, unsigned int sel)
39 {
40 uint32_t *p, e1, e2;
41 e1 = (addr & 0xffff) | (sel << 16);
42 e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
43 p = ptr;
44 p[0] = tswap32(e1);
45 p[1] = tswap32(e2);
46 p[2] = tswap32(addr >> 32);
47 p[3] = 0;
48 }
49
50 /* only dpl matters as we do only user space emulation */
51 void bsd_x86_64_set_idt(int n, unsigned int dpl)
52 {
53 set_gate64(idt_table + n * 2, 0, dpl, 0, 0);
54 }
55
56 void bsd_x86_64_set_idt_base(uint64_t base)
57 {
58 idt_table = g2h_untagged(base);
59 }