x86bios.h revision 197571
1/*- 2 * Copyright (c) 2009 Alex Keda <admin@lissyara.su> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27/* 28 * x86 registers were borrowed from x86emu.h x86emu_regs.h 29 * for compatability. 30 * 31 * $FreeBSD: head/sys/compat/x86bios/x86bios.h 197571 2009-09-28 08:14:15Z delphij $ 32 */ 33 34#ifndef _X86BIOS_H_ 35#define _X86BIOS_H_ 36 37#include <sys/types.h> 38#include <sys/endian.h> 39#include <sys/systm.h> 40 41#ifdef __BIG_ENDIAN__ 42 43struct x86_register32 { 44 uint32_t e_reg; 45}; 46 47struct x86_register16 { 48 uint16_t filler0; 49 uint16_t x_reg; 50}; 51 52struct x86_register8 { 53 uint8_t filler0, filler1; 54 uint8_t h_reg, l_reg; 55}; 56 57#else /* !__BIG_ENDIAN__ */ 58 59struct x86_register32 { 60 uint32_t e_reg; 61}; 62 63struct x86_register16 { 64 uint16_t x_reg; 65}; 66 67struct x86_register8 { 68 uint8_t l_reg, h_reg; 69}; 70 71#endif /* __BIG_ENDIAN__ */ 72 73union x86_register { 74 struct x86_register32 I32_reg; 75 struct x86_register16 I16_reg; 76 struct x86_register8 I8_reg; 77}; 78 79struct x86regs { 80 uint16_t padding; /* CS is unused. */ 81 uint16_t register_ds; 82 uint16_t register_es; 83 uint16_t register_fs; 84 uint16_t register_gs; 85 uint16_t register_ss; 86 uint32_t register_flags; 87 union x86_register register_a; 88 union x86_register register_b; 89 union x86_register register_c; 90 union x86_register register_d; 91 92 union x86_register register_sp; 93 union x86_register register_bp; 94 union x86_register register_si; 95 union x86_register register_di; 96}; 97 98typedef struct x86regs x86regs_t; 99 100/* 8 bit registers */ 101#define R_AH register_a.I8_reg.h_reg 102#define R_AL register_a.I8_reg.l_reg 103#define R_BH register_b.I8_reg.h_reg 104#define R_BL register_b.I8_reg.l_reg 105#define R_CH register_c.I8_reg.h_reg 106#define R_CL register_c.I8_reg.l_reg 107#define R_DH register_d.I8_reg.h_reg 108#define R_DL register_d.I8_reg.l_reg 109 110/* 16 bit registers */ 111#define R_AX register_a.I16_reg.x_reg 112#define R_BX register_b.I16_reg.x_reg 113#define R_CX register_c.I16_reg.x_reg 114#define R_DX register_d.I16_reg.x_reg 115 116/* 32 bit extended registers */ 117#define R_EAX register_a.I32_reg.e_reg 118#define R_EBX register_b.I32_reg.e_reg 119#define R_ECX register_c.I32_reg.e_reg 120#define R_EDX register_d.I32_reg.e_reg 121 122/* special registers */ 123#define R_SP register_sp.I16_reg.x_reg 124#define R_BP register_bp.I16_reg.x_reg 125#define R_SI register_si.I16_reg.x_reg 126#define R_DI register_di.I16_reg.x_reg 127#define R_FLG register_flags 128 129/* special registers */ 130#define R_ESP register_sp.I32_reg.e_reg 131#define R_EBP register_bp.I32_reg.e_reg 132#define R_ESI register_si.I32_reg.e_reg 133#define R_EDI register_di.I32_reg.e_reg 134#define R_EFLG register_flags 135 136/* segment registers */ 137#define R_DS register_ds 138#define R_SS register_ss 139#define R_ES register_es 140#define R_FS register_fs 141#define R_GS register_gs 142 143#define SEG_ADDR(x) (((x) >> 4) & 0x00F000) 144#define SEG_OFF(x) ((x) & 0x0FFFF) 145#define FARP(x) ((le32toh(x) & 0xffff) + ((le32toh(x) >> 12) & 0xffff00)) 146 147#define MAPPED_MEMORY_SIZE (1024 * 1024) 148#define PAGE_RESERV (4096 * 5) 149 150__BEGIN_DECLS 151void *x86bios_alloc(int count, int *segs); 152void x86bios_free(void *pbuf, int count); 153void x86bios_intr(struct x86regs *regs, int intno); 154void *x86bios_offset(uint32_t offs); 155__END_DECLS 156 157#endif /* !_X86BIOS_H_ */ 158