xref: /openbmc/qemu/bsd-user/x86_64/target_arch_cpu.c (revision 031fe7af8a856cf42b0d1d9fb6188acbf7b64fd1)
1e2a74729SWarner Losh /*
2e2a74729SWarner Losh  *  x86_64 cpu related code
3e2a74729SWarner Losh  *
4*031fe7afSWarner Losh  * Copyright (c) 2013 Stacey Son <sson@FreeBSD.org>
5e2a74729SWarner Losh  *
6e2a74729SWarner Losh  *  This program is free software; you can redistribute it and/or modify
7e2a74729SWarner Losh  *  it under the terms of the GNU General Public License as published by
8e2a74729SWarner Losh  *  the Free Software Foundation; either version 2 of the License, or
9e2a74729SWarner Losh  *  (at your option) any later version.
10e2a74729SWarner Losh  *
11e2a74729SWarner Losh  *  This program is distributed in the hope that it will be useful,
12e2a74729SWarner Losh  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13e2a74729SWarner Losh  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14e2a74729SWarner Losh  *  GNU General Public License for more details.
15e2a74729SWarner Losh  *
16e2a74729SWarner Losh  *  You should have received a copy of the GNU General Public License
17e2a74729SWarner Losh  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18e2a74729SWarner Losh  */
19e2a74729SWarner Losh 
20e2a74729SWarner Losh #include <sys/types.h>
21e2a74729SWarner Losh 
22e2a74729SWarner Losh #include "qemu/osdep.h"
23e2a74729SWarner Losh #include "cpu.h"
24e2a74729SWarner Losh #include "qemu.h"
25e2a74729SWarner Losh #include "qemu/timer.h"
26e2a74729SWarner Losh 
27e2a74729SWarner Losh #include "target_arch.h"
28e2a74729SWarner Losh 
29e2a74729SWarner Losh static uint64_t *idt_table;
30e2a74729SWarner Losh 
31e2a74729SWarner Losh uint64_t cpu_get_tsc(CPUX86State *env)
32e2a74729SWarner Losh {
33e2a74729SWarner Losh     return cpu_get_host_ticks();
34e2a74729SWarner Losh }
35e2a74729SWarner Losh 
36e2a74729SWarner Losh int cpu_get_pic_interrupt(CPUX86State *env)
37e2a74729SWarner Losh {
38e2a74729SWarner Losh     return -1;
39e2a74729SWarner Losh }
40e2a74729SWarner Losh 
41e2a74729SWarner Losh void bsd_x86_64_write_dt(void *ptr, unsigned long addr,
42e2a74729SWarner Losh         unsigned long limit, int flags)
43e2a74729SWarner Losh {
44e2a74729SWarner Losh     unsigned int e1, e2;
45e2a74729SWarner Losh     uint32_t *p;
46e2a74729SWarner Losh     e1 = (addr << 16) | (limit & 0xffff);
47e2a74729SWarner Losh     e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000);
48e2a74729SWarner Losh     e2 |= flags;
49e2a74729SWarner Losh     p = ptr;
50e2a74729SWarner Losh     p[0] = tswap32(e1);
51e2a74729SWarner Losh     p[1] = tswap32(e2);
52e2a74729SWarner Losh }
53e2a74729SWarner Losh 
54e2a74729SWarner Losh static void set_gate64(void *ptr, unsigned int type, unsigned int dpl,
55e2a74729SWarner Losh         uint64_t addr, unsigned int sel)
56e2a74729SWarner Losh {
57e2a74729SWarner Losh     uint32_t *p, e1, e2;
58e2a74729SWarner Losh     e1 = (addr & 0xffff) | (sel << 16);
59e2a74729SWarner Losh     e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
60e2a74729SWarner Losh     p = ptr;
61e2a74729SWarner Losh     p[0] = tswap32(e1);
62e2a74729SWarner Losh     p[1] = tswap32(e2);
63e2a74729SWarner Losh     p[2] = tswap32(addr >> 32);
64e2a74729SWarner Losh     p[3] = 0;
65e2a74729SWarner Losh }
66e2a74729SWarner Losh 
67e2a74729SWarner Losh /* only dpl matters as we do only user space emulation */
68e2a74729SWarner Losh void bsd_x86_64_set_idt(int n, unsigned int dpl)
69e2a74729SWarner Losh {
70e2a74729SWarner Losh     set_gate64(idt_table + n * 2, 0, dpl, 0, 0);
71e2a74729SWarner Losh }
72e2a74729SWarner Losh 
73e2a74729SWarner Losh void bsd_x86_64_set_idt_base(uint64_t base)
74e2a74729SWarner Losh {
75e2a74729SWarner Losh     idt_table = g2h_untagged(base);
76e2a74729SWarner Losh }
77