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