Commit 5fae36af authored by Sebastien Badia's avatar Sebastien Badia

Imported Upstream version 1.4

parent 4e4314f9
changelog
VERSION
License information
-------------------
The x86emu library is under a BSD style license, comaptible
with the XFree86 and X licenses used by XFree86. The
original x86emu libraries were under the GNU General Public
License. Due to license incompatibilities between the GPL
and the XFree86 license, the original authors of the code
decided to allow a license change. If you have submitted
code to the original x86emu project, and you don't agree
with the license change, please contact us and let you
know. Your code will be removed to comply with your wishes.
If you have any questions about this, please send email to
x86emu@linuxlabs.com or KendallB@scitechsoft.com for
clarification.
ARCH := $(shell uname -m)
ifneq ($(filter i386 i486 i586 i686, $(ARCH)),)
ARCH := i386
endif
GIT2LOG := $(shell if [ -x ./git2log ] ; then echo ./git2log --update ; else echo true ; fi)
GITDEPS := $(shell [ -d .git ] && echo .git/HEAD .git/refs/heads .git/refs/tags)
CC = gcc
CFLAGS = -g -O2 -fPIC -fomit-frame-pointer -Wall
ifneq ($(filter x86_64, $(ARCH)),)
LIBDIR = /usr/lib64
else
LIBDIR = /usr/lib
endif
LIBX86 = libx86emu
VERSION := $(shell $(GIT2LOG) --version VERSION ; cat VERSION)
MAJOR_VERSION := $(shell $(GIT2LOG) --version VERSION ; cut -d . -f 1 VERSION)
CFILES = $(wildcard *.c)
OBJS = $(CFILES:.c=.o)
LIB_NAME = $(LIBX86).so.$(VERSION)
LIB_SONAME = $(LIBX86).so.$(MAJOR_VERSION)
.PHONY: all shared install test clean
%.o: %.c
$(CC) -c $(CFLAGS) $<
all: changelog shared
changelog: $(GITDEPS)
$(GIT2LOG) --changelog changelog
shared: $(LIB_NAME)
install: shared
install -D $(LIB_NAME) $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
ln -snf $(LIB_NAME) $(DESTDIR)$(LIBDIR)/$(LIB_SONAME)
ln -snf $(LIB_SONAME) $(DESTDIR)$(LIBDIR)/$(LIBX86).so
install -m 644 -D include/x86emu.h $(DESTDIR)/usr/include/x86emu.h
$(LIB_NAME): .depend $(OBJS)
$(CC) -shared -Wl,-soname,$(LIB_SONAME) $(OBJS) -o $(LIB_NAME)
test:
make -C test
clean:
make -C test clean
rm -f *.o *~ include/*~ *.so.* .depend
ifneq "$(MAKECMDGOALS)" "clean"
.depend: $(CFILES)
@$(CC) -MG -MM $(CFLAGS) $(CFILES) >$@
-include .depend
endif
x86 emulation library
=====================
API functions
-------------
- create new emulation object
x86emu_t *x86emu_new(unsigned def_mem_perm, unsigned def_io_perm);
def_mem_perm are the default permissions for memory accesses, def_io_perm for io. See
x86emu_set_perm(), x86emu_set_io_perm().
Free object later with x86emu_done().
- delete emulation object
x86emu_t *x86emu_done(x86emu_t *emu);
Frees all memory; returns NULL;
- clone emulation object
x86emu_t *x86emu_clone(x86emu_t *emu);
Creates a copy of emu. Free the copy later with x86emu_done().
- reset cpu state
void x86emu_reset(x86emu_t *emu);
Does a normal cpu reset (clear registers, set cs:eip).
- start emulation
unsigned x86emu_run(x86emu_t *emu, unsigned flags);
- flags:
X86EMU_RUN_TIMEOUT
X86EMU_RUN_MAX_INSTR
X86EMU_RUN_NO_EXEC
X86EMU_RUN_NO_CODE
X86EMU_RUN_LOOP
X86EMU_RUN_TIMEOUT: set emu->timeout to max. seconds to run.
X86EMU_RUN_MAX_INSTR: set emu->max_instr to max. instructions to emulate.
Return value indicates why x86emu_run() stopped (see flags).
Note: copies emu to global variable x86emu while running!
- stop emulation
void x86emu_stop(x86emu_t *emu);
Use this function in callbacks (e.g. interrupt handler) to tell the emulator
to stop. The emulator returns from x86emu_run() when the current instruction
has been finished.
- set log buffer
void x86emu_set_log(x86emu_t *emu, char *buffer, unsigned buffer_size, x86emu_flush_func_t flush);
typedef void (* x86emu_flush_func_t)(x86emu_t *emu, char *buf, unsigned size);
If the log buffer is full, flush() is called (if not NULL). The buffer is freed in x86emu_done().
- write to log
void x86emu_log(x86emu_t *emu, const char *format, ...) __attribute__ ((format (printf, 1, 2)));
- clear log
void x86emu_clear_log(x86emu_t *emu, int flush);
Clear log buffer. If flush != 0, write current log via flush() function (see x86emu_set_log()).
- dump emulator state
void x86emu_dump(x86emu_t *emu, int flags);
- flags:
X86EMU_DUMP_REGS
X86EMU_DUMP_MEM
X86EMU_DUMP_ACC_MEM
X86EMU_DUMP_INV_MEM
X86EMU_DUMP_ATTR
X86EMU_DUMP_ASCII
X86EMU_DUMP_IO
X86EMU_DUMP_INTS
X86EMU_DUMP_TIME
Writes emulator state to log.
- memory permissions
void x86emu_set_perm(x86emu_t *emu, unsigned start, unsigned end, unsigned perm);
- perm: bitmask of
X86EMU_PERM_R
X86EMU_PERM_W
X86EMU_PERM_X
X86EMU_PERM_VALID
X86EMU_ACC_R
X86EMU_ACC_W
X86EMU_ACC_X
X86EMU_ACC_INVALID
X86EMU_PERM_{R,W,X}: memory is readable, writable, executable
X86EMU_PERM_VALID: memory has been initialized (say, been written to)
X86EMU_ACC_{R,W,X}: memory has been read, written, executed
X86EMU_ACC_INVALID: there was an invalid access (e.g. tried to read but not readable)
- direct memory access
void x86emu_set_page(x86emu_t *emu, unsigned offset, void *address);
Map memory area of X86EMU_PAGE_SIZE size at address into emulator at offset. offset
must be X86EMU_PAGE_SIZE aligned, address needs not.
Memory permissions still apply (via x86emu_set_perm()).
If address is NULL, switch back to emulated memory.
- io permissions
void x86emu_set_io_perm(x86emu_t *emu, unsigned start, unsigned end, unsigned perm);
- perm: see x86emu_set_perm()
- reset memory access statistics
void x86emu_reset_access_stats(x86emu_t *emu);
Resets the X86EMU_ACC_* bits for the whole memory (see x86emu_set_perm()).
- execution hook
x86emu_code_handler_t x86emu_set_code_handler(x86emu_t *emu, x86emu_code_handler_t handler);
typedef int (* x86emu_code_handler_t)(x86emu_t *emu);
If defined, the function is called before a new instruction is decoded and
emulated. If logging is enabled the current cpu state has already been
logged. If the function returns a value != 0, the emulation is stopped.
- set interrupt handler
x86emu_intr_handler_t x86emu_set_intr_handler(x86emu_t *emu, x86emu_intr_handler_t handler);
typedef int (* x86emu_intr_handler_t)(x86emu_t *emu, u8 num, unsigned type);
- type:
INTR_TYPE_SOFT
INTR_TYPE_FAULT
+ bitmask of
INTR_MODE_RESTART
INTR_MODE_ERRCODE
If defined, the interrupt handler is called at the start of the interrupt
handling procedure. The handler should return 1 to indicate the interrupt
handling is complete and the emulator can skip its own interrupt processing
or 0 to indicate the emulator should continue with normal interrupt processing.
- set alternative callback function that handles memory and io accesses
x86emu_memio_handler_t x86emu_set_memio_handler(x86emu_t *emu, x86emu_memio_handler_t handler);
typedef unsigned (* x86emu_memio_handler_t)(x86emu_t *emu, u32 addr, u32 *val, unsigned type);
- type: one of
X86EMU_MEMIO_8
X86EMU_MEMIO_16
X86EMU_MEMIO_32
X86EMU_MEMIO_8_NOPERM
+ one of
X86EMU_MEMIO_R
X86EMU_MEMIO_W
X86EMU_MEMIO_X
X86EMU_MEMIO_I
X86EMU_MEMIO_O
Returns old function.
- raise an interrupt
void x86emu_intr_raise(x86emu_t *emu, u8 intr_nr, unsigned type, unsigned err);
The interrupt is handled before the next instruction. For type see
x86emu_set_intr_func(); if INTR_MODE_ERRCODE is set, err is the error
code pushed to the stack.
- memory access functions
unsigned x86emu_read_byte(x86emu_t *emu, unsigned addr);
unsigned x86emu_read_byte_noperm(x86emu_t *emu, unsigned addr);
unsigned x86emu_read_word(x86emu_t *emu, unsigned addr);
unsigned x86emu_read_dword(x86emu_t *emu, unsigned addr);
void x86emu_write_byte(x86emu_t *emu, unsigned addr, unsigned val);
void x86emu_write_byte_noperm(x86emu_t *emu, unsigned addr, unsigned val);
void x86emu_write_word(x86emu_t *emu, unsigned addr, unsigned val);
void x86emu_write_dword(x86emu_t *emu, unsigned addr, unsigned val);
Convenience functions to access emulator memory. Memory access restrictions
(see x86emu_set_perm()) apply except for x86emu_*_noperm() which do not
check permissions.
- set segment register
void x86emu_set_seg_register(x86emu_t *emu, sel_t *seg, u16 val);
R_CS_SEL, R_DS_SEL, R_ES_SEL, R_FS_SEL, R_GS_SEL, R_SS_SEL
Example:
x86emu_set_seg_register(emu, emu->x86.R_CS_SEL, 0x7c0);
debug instruction
-----------------
If the X86EMU_TRACE_DEBUG flags is set, the emulator interprets a special debug intruction:
db 0x67, 0xeb, LEN, DATA...
which is basically a short jump with address size prefix (an instruction normally not
used). LEN is the size of DATA.
DATA can be:
- db 0x01
db STRING
Print STRING to log. STRING is not 0-zerminated.
- db 0x02
dd flags
Set trace flags.
- db 0x03
dd flags
Clear trace flags.
- db 0x04
dd flags
Dump emulator state. For flags, see x86emu_dump().
- db 0x05
Reset memory access stats. See x86emu_reset_access_stats().
This diff is collapsed.
2013-02-28: 1.4
- avoid using reserved c++ words
2011-01-26: 1.3
- better invalid code detection
- fix instruction log for some instructions
2010-09-23: 1.2
- more Makefile fixes
- fix Makefile
- remove debug line
- create VERSION and changelog from git repo
- log message
- don't use 'i386'
- properly decode all descriptor types
2009-06-09: 1.1
- export only API functions in shared lib
- new mem interface
- fix build on non-x86 arch
2008-12-12: 0.1
- basic msr support
- inw fix
- log tsc
- lowercase, no tabs
- move to lowercase
libx86emu (1.4-1) unstable; urgency=low
* Initial release
-- Sebastien Badia <seb@sebian.fr> Wed, 27 Nov 2013 22:09:41 +0100
Source: libx86emu
Section: libs
Priority: optional
Maintainer: Sebastien Badia <seb@sebian.fr>
Build-Depends: debhelper (>= 8.0.0)
Standards-Version: 3.9.5
Homepage: http://gitorious.org/x86emu/libx86emu
Vcs-Git: git://git.debian.org/collab-maint/libx86emu.git
Vcs-Browser: http://git.debian.org/?p=collab-maint/libx86emu.git;a=summary
Package: libx86emu
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: x86 emulation library
Small x86 emulation library with focus of easy usage and
extended execution logging functions.
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: libx86emu
Source: http://gitorious.org/x86emu/libx86emu
Files: *
Copyright: 2007-2013 Steffen Winterfeldt <wfeldt@opensuse.org>
License: BSD
The x86emu library is under a BSD style license, comaptible
with the XFree86 and X licenses used by XFree86. The
original x86emu libraries were under the GNU General Public
License. Due to license incompatibilities between the GPL
and the XFree86 license, the original authors of the code
decided to allow a license change. If you have submitted
code to the original x86emu project, and you don't agree
with the license change, please contact us and let you
know. Your code will be removed to comply with your wishes.
.
If you have any questions about this, please send email to
x86emu@linuxlabs.com or KendallB@scitechsoft.com for
clarification.
Files: debian/*
Copyright: 2013 Sebastien Badia <sebastien@badia.fr>
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
.
On Debian systems, the complete text of the GNU General
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
[DEFAULT]
upstream-branch=upstream
debian-branch=master
pristine-tar = True
#!/bin/bash
set -eu
repo=https://git.gitorious.org/x86emu/libx86emu.git
if [ $# = 0 ]; then
echo "Available tags:"
git ls-remote $repo \
| awk '{ print $2 }' | egrep 'refs/tags/[0-9]+' \
| awk 'FS="/" { print $3 }' | xargs echo
exit 0
fi
version=$1
tmp=$(mktemp -d)
name="libx86emu-${version}.tar.gz"
(
cd $tmp
git clone ${repo} libx86emu
cd libx86emu
git reset --hard ${version}
# the build system needs this
make changelog # this creates VERSION as well
rm -rf ./.git ./.depend
tar cfz ../${name} .
)
cp ${tmp}/${name} ../..
rm -rf ${tmp}
echo "The archive saved as ${name}"
#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@
get-orig-source:
bash get-tarball.sh $(VERSION)
version=3
opts=filenamemangle=s/\S*download=//g \
http://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=gitorious/x86emu/libx86emu \
.*=libx86emu(?:[_\-]v?|)(\d[^\s/]*)\.(?:tar\.xz|txz|tar\.bz2|tbz2|tar\.gz|tgz)
This diff is collapsed.
#! /usr/bin/perl
use Getopt::Long;
sub usage;
usage 0 if !@ARGV;
@deps = qw ( .git/HEAD .git/refs/heads .git/refs/tags );
GetOptions(
'help' => sub { usage 0 },
'version' => \$opt_version,
'update' => \$opt_update,
'log|changelog' => \$opt_log,
) || usage 1;
usage 1 if @ARGV > 1 || !($opt_log || $opt_version);
$opt_file = @ARGV ? shift : '-';
die "no git repo\n" unless -d ".git";
if($opt_update && $opt_file ne '-' && -f($opt_file)) {
$ok = 1;
$t = (stat $opt_file)[9];
for (@deps) {
$ok = 0 if (stat)[9] > $t;
}
exit 0 if $ok;
}
for (`git branch`) {
if(/^\*\s+(\S+)/) {
$branch = $1;
last;
}
}
die "no branch?\n" unless $branch;
# print STDERR "writing log for branch $branch\n";
@tags = `git tag`;
chomp @tags;
for (@tags) {
if(/^\d/) {
s/(\d+)/sprintf "%04d", $1/eg;
push @ntags, $_;
}
elsif(s/^$branch\-//) {
s/(\d+)/sprintf "%04d", $1/eg;
push @ntags, "$branch-$_";
}
}
@tags = sort @ntags;
die "no tags?\n" unless @tags;
if($opt_version) {
$t = $tags[-1];
$t =~ s/(\d+)/$1 + 0/eg;
if(`git log --pretty=medium --date=iso '$t..HEAD'`) {
$t =~ s/(\d+)$/$1 + 1/e;
}
$t =~ s/^$branch\-//;
open F, ">$opt_file";
print F "$t\n";
close F;
exit 0;
}
if($branch ne 'master') {
for ($i = 0; $i < @tags; $i++) {
if($tags[$i] =~ /^$branch\-(\S+)/) {
$i2 = $i;
$bi = $1;
last;
}
}
# print STDERR ">> $branch-$bi\n";
die "no tags in this branch?\n" unless $bi;
for ($i = 0; $i < $i2; $i++) {
if($tags[$i] eq $bi) {
$i1 = $i;
last;
}
}
splice @tags, $i1, $i2 - $i1;
}
map { s/(\d+)/$1 + 0/eg } @tags;
# for (@tags) { print "$_\n"; }
push @tags, "HEAD";
open F, ">$opt_file";
for ($i = @tags - 1; $i > 0; $i--) {
$date = undef;
@t = `git log --pretty=medium --date=iso '$tags[$i-1]..$tags[$i]'`;
chomp @t;
for (@t) {
if(/^Date:\s*(\S+)/) {
$date = $1;
last;
}
}
@t = grep { !/^(commit|Author:|Date:|Merge:|\s*$)|created.*tag/ } @t;
if(@t) {
# rewrite a bit to have it look more consistent
map { s/(fate|bnc)#/$1 #/g } @t;
map { s/\(#/(bnc #/g } @t;
map { s/bug\s*#/bnc #/g } @t;
map { s/feat(\.|ure)?\s*#?(\d+)/fate #$2/g } @t;
map { s/^ {4}// } @t;
map { s/^ {8}// } @t;
map { s/^([^-\s])/- $1/ } @t;
map { s/^- - /- / } @t;
map { s/^- \+\s+(- )?/- / } @t;
map { s/^/\t/ } @t;
$t = $tags[$i];
$t = "${branch}-$t" if $branch ne 'master' && $t eq "HEAD";
print F "$date:\t$t\n";
print F join("\n", @t), "\n\n";
}
}
close F;
sub usage
{
my $err = shift;
print <<" usage";
Usage: git2log [OPTIONS] [FILE]
Create changelog and project version from git repo.
--changelog Write changelog to FILE.
--version Write version number to FILE.
--update Write changelog or version only if FILE is outdated.
--help Print this help text.
usage
exit $err;
}
/****************************************************************************
*
* Realmode X86 Emulator Library
*
* Copyright (C) 1996-1999 SciTech Software, Inc.
* Copyright (C) David Mosberger-Tang
* Copyright (C) 1999 Egbert Eich
*
* ========================================================================
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of the authors not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The authors makes no
* representations about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* ========================================================================
*
* Language: ANSI C
* Environment: Any
* Developer: Kendall Bennett
*
* Description: Header file for instruction decoding logic.
*
****************************************************************************/
#ifndef __X86EMU_DECODE_H
#define __X86EMU_DECODE_H
/*---------------------- Macros and type definitions ----------------------*/
/* Instruction Decoding */
#define OP_DECODE(a) \
memcpy(M.x86.disasm_ptr, a, sizeof a - 1), \
M.x86.disasm_ptr += sizeof a - 1
#define SEGPREF_DECODE \
memcpy(M.x86.disasm_ptr, M.x86.decode_seg, 4), \
M.x86.disasm_ptr += M.x86.default_seg ? 4 : 1
#define DECODE_HEX1(ofs) decode_hex1(&M.x86.disasm_ptr, ofs)
#define DECODE_HEX2(ofs) decode_hex2(&M.x86.disasm_ptr, ofs)
#define DECODE_HEX4(ofs) decode_hex4(&M.x86.disasm_ptr, ofs)
#define DECODE_HEX8(ofs) decode_hex8(&M.x86.disasm_ptr, ofs)
#define DECODE_HEX2S(ofs) decode_hex2s(&M.x86.disasm_ptr, ofs)
#define DECODE_HEX4S(ofs) decode_hex4s(&M.x86.disasm_ptr, ofs)
#define DECODE_HEX8S(ofs) decode_hex8s(&M.x86.disasm_ptr, ofs)
#define DECODE_HEX_ADDR(ofs) decode_hex_addr(&M.x86.disasm_ptr, ofs)