x86bios.h revision 197571
1197383Sdelphij/*- 2197571Sdelphij * Copyright (c) 2009 Alex Keda <admin@lissyara.su> 3197571Sdelphij * All rights reserved. 4197383Sdelphij * 5197571Sdelphij * Redistribution and use in source and binary forms, with or without 6197571Sdelphij * modification, are permitted provided that the following conditions 7197571Sdelphij * are met: 8197571Sdelphij * 1. Redistributions of source code must retain the above copyright 9197571Sdelphij * notice, this list of conditions and the following disclaimer. 10197571Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 11197571Sdelphij * notice, this list of conditions and the following disclaimer in the 12197571Sdelphij * documentation and/or other materials provided with the distribution. 13197571Sdelphij * 14197571Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15197571Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16197571Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17197571Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18197571Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19197571Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20197571Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21197571Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22197571Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23197571Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24197571Sdelphij * SUCH DAMAGE. 25197571Sdelphij * 26197571Sdelphij */ 27197571Sdelphij/* 28197383Sdelphij * x86 registers were borrowed from x86emu.h x86emu_regs.h 29197383Sdelphij * for compatability. 30197383Sdelphij * 31197383Sdelphij * $FreeBSD: head/sys/compat/x86bios/x86bios.h 197571 2009-09-28 08:14:15Z delphij $ 32197383Sdelphij */ 33197383Sdelphij 34197383Sdelphij#ifndef _X86BIOS_H_ 35197383Sdelphij#define _X86BIOS_H_ 36197383Sdelphij 37197383Sdelphij#include <sys/types.h> 38197383Sdelphij#include <sys/endian.h> 39197383Sdelphij#include <sys/systm.h> 40197383Sdelphij 41197383Sdelphij#ifdef __BIG_ENDIAN__ 42197383Sdelphij 43197383Sdelphijstruct x86_register32 { 44197383Sdelphij uint32_t e_reg; 45197383Sdelphij}; 46197383Sdelphij 47197383Sdelphijstruct x86_register16 { 48197383Sdelphij uint16_t filler0; 49197383Sdelphij uint16_t x_reg; 50197383Sdelphij}; 51197383Sdelphij 52197383Sdelphijstruct x86_register8 { 53197383Sdelphij uint8_t filler0, filler1; 54197383Sdelphij uint8_t h_reg, l_reg; 55197383Sdelphij}; 56197383Sdelphij 57197383Sdelphij#else /* !__BIG_ENDIAN__ */ 58197383Sdelphij 59197383Sdelphijstruct x86_register32 { 60197383Sdelphij uint32_t e_reg; 61197383Sdelphij}; 62197383Sdelphij 63197383Sdelphijstruct x86_register16 { 64197383Sdelphij uint16_t x_reg; 65197383Sdelphij}; 66197383Sdelphij 67197383Sdelphijstruct x86_register8 { 68197383Sdelphij uint8_t l_reg, h_reg; 69197383Sdelphij}; 70197383Sdelphij 71197383Sdelphij#endif /* __BIG_ENDIAN__ */ 72197383Sdelphij 73197383Sdelphijunion x86_register { 74197383Sdelphij struct x86_register32 I32_reg; 75197383Sdelphij struct x86_register16 I16_reg; 76197383Sdelphij struct x86_register8 I8_reg; 77197383Sdelphij}; 78197383Sdelphij 79197383Sdelphijstruct x86regs { 80197493Sjkim uint16_t padding; /* CS is unused. */ 81197383Sdelphij uint16_t register_ds; 82197383Sdelphij uint16_t register_es; 83197383Sdelphij uint16_t register_fs; 84197383Sdelphij uint16_t register_gs; 85197383Sdelphij uint16_t register_ss; 86197383Sdelphij uint32_t register_flags; 87197383Sdelphij union x86_register register_a; 88197383Sdelphij union x86_register register_b; 89197383Sdelphij union x86_register register_c; 90197383Sdelphij union x86_register register_d; 91197383Sdelphij 92197383Sdelphij union x86_register register_sp; 93197383Sdelphij union x86_register register_bp; 94197383Sdelphij union x86_register register_si; 95197383Sdelphij union x86_register register_di; 96197383Sdelphij}; 97197383Sdelphij 98197383Sdelphijtypedef struct x86regs x86regs_t; 99197383Sdelphij 100197383Sdelphij/* 8 bit registers */ 101197383Sdelphij#define R_AH register_a.I8_reg.h_reg 102197383Sdelphij#define R_AL register_a.I8_reg.l_reg 103197383Sdelphij#define R_BH register_b.I8_reg.h_reg 104197383Sdelphij#define R_BL register_b.I8_reg.l_reg 105197383Sdelphij#define R_CH register_c.I8_reg.h_reg 106197383Sdelphij#define R_CL register_c.I8_reg.l_reg 107197383Sdelphij#define R_DH register_d.I8_reg.h_reg 108197383Sdelphij#define R_DL register_d.I8_reg.l_reg 109197383Sdelphij 110197383Sdelphij/* 16 bit registers */ 111197383Sdelphij#define R_AX register_a.I16_reg.x_reg 112197383Sdelphij#define R_BX register_b.I16_reg.x_reg 113197383Sdelphij#define R_CX register_c.I16_reg.x_reg 114197383Sdelphij#define R_DX register_d.I16_reg.x_reg 115197383Sdelphij 116197383Sdelphij/* 32 bit extended registers */ 117197383Sdelphij#define R_EAX register_a.I32_reg.e_reg 118197383Sdelphij#define R_EBX register_b.I32_reg.e_reg 119197383Sdelphij#define R_ECX register_c.I32_reg.e_reg 120197383Sdelphij#define R_EDX register_d.I32_reg.e_reg 121197383Sdelphij 122197383Sdelphij/* special registers */ 123197383Sdelphij#define R_SP register_sp.I16_reg.x_reg 124197383Sdelphij#define R_BP register_bp.I16_reg.x_reg 125197383Sdelphij#define R_SI register_si.I16_reg.x_reg 126197383Sdelphij#define R_DI register_di.I16_reg.x_reg 127197383Sdelphij#define R_FLG register_flags 128197383Sdelphij 129197383Sdelphij/* special registers */ 130197383Sdelphij#define R_ESP register_sp.I32_reg.e_reg 131197383Sdelphij#define R_EBP register_bp.I32_reg.e_reg 132197383Sdelphij#define R_ESI register_si.I32_reg.e_reg 133197383Sdelphij#define R_EDI register_di.I32_reg.e_reg 134197383Sdelphij#define R_EFLG register_flags 135197383Sdelphij 136197383Sdelphij/* segment registers */ 137197383Sdelphij#define R_DS register_ds 138197383Sdelphij#define R_SS register_ss 139197383Sdelphij#define R_ES register_es 140197383Sdelphij#define R_FS register_fs 141197383Sdelphij#define R_GS register_gs 142197383Sdelphij 143197383Sdelphij#define SEG_ADDR(x) (((x) >> 4) & 0x00F000) 144197383Sdelphij#define SEG_OFF(x) ((x) & 0x0FFFF) 145197383Sdelphij#define FARP(x) ((le32toh(x) & 0xffff) + ((le32toh(x) >> 12) & 0xffff00)) 146197383Sdelphij 147197493Sjkim#define MAPPED_MEMORY_SIZE (1024 * 1024) 148197493Sjkim#define PAGE_RESERV (4096 * 5) 149197383Sdelphij 150197383Sdelphij__BEGIN_DECLS 151197466Sjkimvoid *x86bios_alloc(int count, int *segs); 152197466Sjkimvoid x86bios_free(void *pbuf, int count); 153197466Sjkimvoid x86bios_intr(struct x86regs *regs, int intno); 154197466Sjkimvoid *x86bios_offset(uint32_t offs); 155197383Sdelphij__END_DECLS 156197383Sdelphij 157197383Sdelphij#endif /* !_X86BIOS_H_ */ 158