MyNixOS website logo
Description

Runtime code generation for x86 machine code.

The package contains the following components:

  • An x86 assembler. We provide both low-level code generation in module Harpy.X86CodeGen as well as a (slightly) higher-level implementation in module Harpy.X86Assembler, which figures out addressing modes based on an instruction's operand types.

  • An x86 disassembler which knows most of the opcodes available on modern x86 processors and can display its output both in the style used in Intel documents an in AT&T style, like the GNU tools. The disassembler can be found in module Harpy.X86Disassembler. The disassembler is re-exported from the disassembler package for compatibility with earlier Harpy releases.

  • Some abstractions over the abovementioned code generation modules, such as automatic label management and code generation combinators (for if-then-else statements, while-loops, functions) (module Harpy.X86CGCombinators).

  • All the above modules use the code generation monad defined in module Harpy.CodeGenMonad.

harpy - Runtime code generation for x86 machine code

Codename: Harpy - Haskell Assembler at Run-time produces Y...
  Harpy [myth.]	f: die Harpyie
  http://en.wikipedia.org/wiki/Harpy

Introduction

Harpy is a library for run-time code generation in Haskell programs.

Harpy requires several Haskell extensions and GHC-specific features (the Haskell FFI, Template Haskell, multi-parameter type classes and monad transformers).

Features

The following modules are included in this package:

Harpy.CodeGenMonad: This module defines the code generator monad, which is a combined state/reader/exception monad. It contains all the necessary details for allocating and managing code buffers.

Harpy.X86CodeGen: This module contains all the functions for generating native x86 machine code. The functions are very simple, and it is necessary to specify all addressing modes etc. when emitting an instruction.

Harpy.X86Assembler: A type class based layer on top of X86CodeGen which determines the addressing modes from the types of the operands.

Harpy.X86CGCombinators: Code generation combinators for conditionals, loops, function entry/exit code etc.

Harpy.X86Disassembler: A disassembler for x86 machine code.

Harpy.Call: Exports functions for invoking the generated code.

Notes about the implementation

X86CodeGen.lhs

The file X86CodeGen.lhs is based on a header file called x86-codegen.h from the Mono distribution, which defines macros for emitting x86 machine code directly into a memory buffer. The Haskell module is a nearly one-to-one mapping from the original macros to Haskell functions. The main differences are:

  • Instead of emitting the data directly into a buffer, it uses the CodeGen monad from file CodeGenMonad.lhs.

  • The functions are strongly typed.

Several things should be kept in mind when using this file:

  • Buffer overflow checks have to be done manually with checkBufferSize or ensureBufferSize

  • MMX, SSE, SSE2 and SSE3 instructions and registers are not supported.

  • 64-bit mode is not supported.

  • The disassembler supports (in principle) 64-bit mode and SSE instructions, but this has not been tested.

Metadata

Version

0.6.0.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows