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