x86bios.h revision 209472
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 * 26198251Sjkim * $FreeBSD: head/sys/compat/x86bios/x86bios.h 209472 2010-06-23 17:20:51Z jkim $ 27197571Sdelphij */ 28197571Sdelphij/* 29197383Sdelphij * x86 registers were borrowed from x86emu.h x86emu_regs.h 30197383Sdelphij * for compatability. 31197383Sdelphij */ 32197383Sdelphij 33197383Sdelphij#ifndef _X86BIOS_H_ 34198251Sjkim#define _X86BIOS_H_ 35197383Sdelphij 36197383Sdelphij#include <sys/endian.h> 37197383Sdelphij#include <sys/systm.h> 38198251Sjkim#include <sys/types.h> 39197383Sdelphij 40197383Sdelphij#ifdef __BIG_ENDIAN__ 41197383Sdelphij 42197383Sdelphijstruct x86_register32 { 43198251Sjkim uint32_t e_reg; 44197383Sdelphij}; 45197383Sdelphij 46197383Sdelphijstruct x86_register16 { 47198251Sjkim uint16_t filler0; 48198251Sjkim uint16_t x_reg; 49197383Sdelphij}; 50197383Sdelphij 51197383Sdelphijstruct x86_register8 { 52198251Sjkim uint8_t filler0; 53198251Sjkim uint8_t filler1; 54198251Sjkim uint8_t h_reg; 55198251Sjkim uint8_t l_reg; 56197383Sdelphij}; 57197383Sdelphij 58197383Sdelphij#else /* !__BIG_ENDIAN__ */ 59197383Sdelphij 60197383Sdelphijstruct x86_register32 { 61198251Sjkim uint32_t e_reg; 62197383Sdelphij}; 63197383Sdelphij 64197383Sdelphijstruct x86_register16 { 65198251Sjkim uint16_t x_reg; 66197383Sdelphij}; 67197383Sdelphij 68197383Sdelphijstruct x86_register8 { 69198251Sjkim uint8_t l_reg; 70198251Sjkim uint8_t h_reg; 71197383Sdelphij}; 72197383Sdelphij 73197383Sdelphij#endif /* __BIG_ENDIAN__ */ 74197383Sdelphij 75197383Sdelphijunion x86_register { 76197383Sdelphij struct x86_register32 I32_reg; 77197383Sdelphij struct x86_register16 I16_reg; 78197383Sdelphij struct x86_register8 I8_reg; 79197383Sdelphij}; 80197383Sdelphij 81197383Sdelphijstruct x86regs { 82198251Sjkim uint16_t _pad0; /* CS */ 83198251Sjkim uint16_t _pad1; /* DS */ 84197383Sdelphij uint16_t register_es; 85197383Sdelphij uint16_t register_fs; 86197383Sdelphij uint16_t register_gs; 87198251Sjkim uint16_t _pad2; /* SS */ 88197383Sdelphij uint32_t register_flags; 89197383Sdelphij union x86_register register_a; 90197383Sdelphij union x86_register register_b; 91197383Sdelphij union x86_register register_c; 92197383Sdelphij union x86_register register_d; 93197383Sdelphij 94198251Sjkim union x86_register _pad3; /* SP */ 95197383Sdelphij union x86_register register_bp; 96197383Sdelphij union x86_register register_si; 97197383Sdelphij union x86_register register_di; 98197383Sdelphij}; 99197383Sdelphij 100197383Sdelphijtypedef struct x86regs x86regs_t; 101197383Sdelphij 102197383Sdelphij/* 8 bit registers */ 103198251Sjkim#define R_AH register_a.I8_reg.h_reg 104198251Sjkim#define R_AL register_a.I8_reg.l_reg 105198251Sjkim#define R_BH register_b.I8_reg.h_reg 106198251Sjkim#define R_BL register_b.I8_reg.l_reg 107198251Sjkim#define R_CH register_c.I8_reg.h_reg 108198251Sjkim#define R_CL register_c.I8_reg.l_reg 109198251Sjkim#define R_DH register_d.I8_reg.h_reg 110198251Sjkim#define R_DL register_d.I8_reg.l_reg 111197383Sdelphij 112197383Sdelphij/* 16 bit registers */ 113198251Sjkim#define R_AX register_a.I16_reg.x_reg 114198251Sjkim#define R_BX register_b.I16_reg.x_reg 115198251Sjkim#define R_CX register_c.I16_reg.x_reg 116198251Sjkim#define R_DX register_d.I16_reg.x_reg 117197383Sdelphij 118197383Sdelphij/* 32 bit extended registers */ 119198251Sjkim#define R_EAX register_a.I32_reg.e_reg 120198251Sjkim#define R_EBX register_b.I32_reg.e_reg 121198251Sjkim#define R_ECX register_c.I32_reg.e_reg 122198251Sjkim#define R_EDX register_d.I32_reg.e_reg 123197383Sdelphij 124197383Sdelphij/* special registers */ 125198251Sjkim#define R_BP register_bp.I16_reg.x_reg 126198251Sjkim#define R_SI register_si.I16_reg.x_reg 127198251Sjkim#define R_DI register_di.I16_reg.x_reg 128198251Sjkim#define R_FLG register_flags 129197383Sdelphij 130197383Sdelphij/* special registers */ 131198251Sjkim#define R_EBP register_bp.I32_reg.e_reg 132198251Sjkim#define R_ESI register_si.I32_reg.e_reg 133198251Sjkim#define R_EDI register_di.I32_reg.e_reg 134198251Sjkim#define R_EFLG register_flags 135197383Sdelphij 136197383Sdelphij/* segment registers */ 137198251Sjkim#define R_ES register_es 138198251Sjkim#define R_FS register_fs 139198251Sjkim#define R_GS register_gs 140197383Sdelphij 141198251Sjkim#define X86BIOS_PHYSTOSEG(x) (((x) >> 4) & 0xffff) 142198251Sjkim#define X86BIOS_PHYSTOOFF(x) ((x) & 0x000f) 143197383Sdelphij 144197383Sdelphij__BEGIN_DECLS 145209472Sjkimvoid *x86bios_alloc(uint32_t *offset, size_t size, int flags); 146198251Sjkimvoid x86bios_call(struct x86regs *regs, uint16_t seg, uint16_t off); 147198251Sjkimvoid x86bios_free(void *addr, size_t size); 148198251Sjkimuint32_t x86bios_get_intr(int intno); 149198251Sjkimvoid *x86bios_get_orm(uint32_t offset); 150198251Sjkimvoid x86bios_init_regs(struct x86regs *regs); 151198251Sjkimvoid x86bios_intr(struct x86regs *regs, int intno); 152198251Sjkimint x86bios_match_device(uint32_t offset, device_t dev); 153198251Sjkimvoid *x86bios_offset(uint32_t offset); 154197383Sdelphij__END_DECLS 155197383Sdelphij 156197383Sdelphij#endif /* !_X86BIOS_H_ */ 157