haskus-system-0.6.0.0: Haskus system programming framework

Safe HaskellNone
LanguageHaskell2010

Haskus.Arch.X86_64.ISA.Encoding

Contents

Description

Instruction encoding

Synopsis

Encoding

data Encoding Source #

Instruction encoding

Constructors

Encoding 

Fields

data EncodingProperties Source #

Encoding properties

Constructors

LongModeSupport

Supported in 64 bit mode

LegacyModeSupport

Supported in legacy/compatibility mode

Lockable

Support LOCK prefix (only if a memory operand is used)

ImplicitLock

Implicitly locked (lock prefix still supported)

BranchHintable

Support branch-hint prefixes

Repeatable

Allow repeat prefix

Commutable

Operands can be commuted

DefaultOperandSize64

Default operand size is 64-bits for this instruction in LongMode

NoOperandSize64

64-bit operand size not supported

DefaultAddressSize64

Default address size is 64-bits for this instruction in LongMode

Extension X86Extension

Required CPU extension

Arch X86Arch

Instruction added starting at the given arch

DefaultSegment Register

Default register

HLE HLEAction

Hardware-lock elision (HLE) prefix support

data HLEAction Source #

Hardware-lock ellision prefixes

Constructors

XAcquire 
XRelease 
XBoth 

encSupportHLE :: HLEAction -> Encoding -> Bool Source #

Test if an encoding support the given Hardware-Lock Ellision prefix

encValidModRMMode :: Encoding -> ValidMode Source #

ModRM.mod only supports the given value

encHasVariableSizedOperand :: Encoding -> Bool Source #

Indicate if a variable-sized operand is encoded (hence the operand-size prefix can be used)

encMayHaveMemoryOperand :: Encoding -> Bool Source #

Indicate if a memory operand may be encoded

encLockable :: Encoding -> Bool Source #

Indicate if LOCK prefix is allowed

encRepeatable :: Encoding -> Bool Source #

Indicate if REPEAT prefix is allowed

encBranchHintable :: Encoding -> Bool Source #

Indicate if branch hint prefixes are allowed

encGenerateOpcodes :: Encoding -> [Word8] Source #

Some instructions store flags and values into the opcode byte. This method returns the list of potential opcodes for an encoding

Generic opcode

data Opcode Source #

Generic opcode

Instances

opcodeByte :: Opcode -> Word8 Source #

Opcode byte

opcodeMap :: Opcode -> OpcodeMap Source #

Get the opcode map

opcodeB :: Opcode -> Word8 Source #

Base extension

opcodeR :: Opcode -> Word8 Source #

Reg extension

opcodeX :: Opcode -> Word8 Source #

Index extension

opcodeW :: Opcode -> Bool Source #

W (64-bit operand size)

opcodeL :: Opcode -> Maybe Bool Source #

Get vector length (stored in VEX.L, XOP.L, etc.)

Legacy prefixes

REX prefix

newtype Rex Source #

Rex prefix

Constructors

Rex Word8 

Instances

Eq Rex Source # 

Methods

(==) :: Rex -> Rex -> Bool #

(/=) :: Rex -> Rex -> Bool #

Show Rex Source # 

Methods

showsPrec :: Int -> Rex -> ShowS #

show :: Rex -> String #

showList :: [Rex] -> ShowS #

rexW :: Rex -> Bool Source #

Test W bit of REX prefix

rexR :: Rex -> Word8 Source #

Test R bit of REX prefix

rexX :: Rex -> Word8 Source #

Test X bit of REX prefix

rexB :: Rex -> Word8 Source #

Test B bit of REX prefix

isRexPrefix :: Word8 -> Bool Source #

Test for a REX prefix

VEX/XOP prefix

data Vex Source #

A VEX prefix

Constructors

Vex2 !Word8

Two-byte VEX prefix

Vex3 !Word8 !Word8

Three-byte VEX prefix

Instances

Eq Vex Source # 

Methods

(==) :: Vex -> Vex -> Bool #

(/=) :: Vex -> Vex -> Bool #

Show Vex Source # 

Methods

showsPrec :: Int -> Vex -> ShowS #

show :: Vex -> String #

showList :: [Vex] -> ShowS #

ModRM/SIB

newtype ModRM Source #

ModRM byte

Constructors

ModRM (BitFields Word8 '[BitField 2 "mode" Word8, BitField 3 "reg" Word8, BitField 3 "rm" Word8]) 

Instances

Eq ModRM Source # 

Methods

(==) :: ModRM -> ModRM -> Bool #

(/=) :: ModRM -> ModRM -> Bool #

Show ModRM Source # 

Methods

showsPrec :: Int -> ModRM -> ShowS #

show :: ModRM -> String #

showList :: [ModRM] -> ShowS #

newtype SIB Source #

SIB byte

Constructors

SIB Word8 

Instances

Eq SIB Source # 

Methods

(==) :: SIB -> SIB -> Bool #

(/=) :: SIB -> SIB -> Bool #

Show SIB Source # 

Methods

showsPrec :: Int -> SIB -> ShowS #

show :: SIB -> String #

showList :: [SIB] -> ShowS #

data Scale Source #

SIB scale factor

Constructors

Scale1 
Scale2 
Scale4 
Scale8 

Instances

Eq Scale Source # 

Methods

(==) :: Scale -> Scale -> Bool #

(/=) :: Scale -> Scale -> Bool #

Show Scale Source # 

Methods

showsPrec :: Int -> Scale -> ShowS #

show :: Scale -> String #

showList :: [Scale] -> ShowS #

data RMMode Source #

Mode for the R/M field

Constructors

RMRegister

Direct register addressing

RMBaseIndex

Memory addressing with only base/index register

RMSIB

Memory addressing with SIB byte

Instances

data Mode Source #

Mode for pattern matching

Constructors

Mode00 
Mode01 
Mode10 
Mode11 

Instances

Enum Mode Source # 

Methods

succ :: Mode -> Mode #

pred :: Mode -> Mode #

toEnum :: Int -> Mode #

fromEnum :: Mode -> Int #

enumFrom :: Mode -> [Mode] #

enumFromThen :: Mode -> Mode -> [Mode] #

enumFromTo :: Mode -> Mode -> [Mode] #

enumFromThenTo :: Mode -> Mode -> Mode -> [Mode] #

Eq Mode Source # 

Methods

(==) :: Mode -> Mode -> Bool #

(/=) :: Mode -> Mode -> Bool #

Show Mode Source # 

Methods

showsPrec :: Int -> Mode -> ShowS #

show :: Mode -> String #

showList :: [Mode] -> ShowS #

newModRM :: Word8 -> Word8 -> Word8 -> ModRM Source #

Create a ModRM byte (check inputs)

rmField :: ModRM -> Word8 Source #

Get r/m field in ModRM

regField :: ModRM -> Word8 Source #

Get reg field in ModRM

modField :: ModRM -> Word8 Source #

Get mod field in ModRM

modeField :: ModRM -> Mode Source #

Get mod field in ModRM

modRMFields :: ModRM -> (Word8, Word8, Word8) Source #

Get the tree fields (mod,reg,rm)

rmMode :: AddressSize -> ModRM -> RMMode Source #

Indicate R/M field mode

useDisplacement :: AddressSize -> Maybe SIB -> ModRM -> Maybe Size Source #

Indicate if displacement bytes follow

useSIB :: AddressSize -> ModRM -> Bool Source #

Indicate if a SIB byte follows

scaleField :: SIB -> Scale Source #

Get SIB scale field

indexField :: SIB -> Word8 Source #

Get SIB index field

baseField :: SIB -> Word8 Source #

Get SIB base field

rmRegMode :: ModRM -> Bool Source #

Indicate if the r/m field contains a register

Operands

data OperandType Source #

Operand types

Constructors

TME OperandType OperandType

One of the two types (for ModRM.rm)

TLE OperandType OperandType

One of the two types depending on Vex.L

TWE OperandType OperandType

One of the two types depending on Rex.W

T_Mem MemType

Memory address

T_Reg RegType

Register

T_SubReg SubRegType RegType

Sub-part of a register

T_Pair OperandType OperandType

Pair (AAA:BBB)

T_Imm ImmType

Immediate value

T_Rel RelType

Memory offset relative to current IP

T_MemOffset

Memory offset relative to the segment base: the offset is address-sized, the value is operand-sized

T_MemDSrAX

Memory whose address is DS:EAX or DS:RAX (64-bit mode)

data OperandEnc Source #

Operand encoding

Constructors

RM

Operand stored in ModRM.rm

Reg

Operand stored in ModRM.reg

Imm

Operand stored in immediate bytes

Imm8h

Operand stored in bits [7:4] of the immediate byte

Imm8l

Operand stored in bits [3:0] of the immediate byte

Implicit

Implicit

Vvvv

Operand stored in Vex.vvvv field

OpcodeLow3

Operand stored in opcode 3 last bits

data OperandSpec Source #

Operand specification

data AccessMode Source #

Operand access mode

Constructors

RO

Read-only

RW

Read-write

WO

Write-only

NA

Meta use of the operand

data Operand Source #

An operand

Constructors

OpImmediate SizedValue

Immediate value

OpReg Register

Register

OpRegPair Register Register

REG:REG

OpMem MemType Addr

Memory address

OpCodeAddr Addr

Code address

OpPtr16_16 !Word16 !Word16

Immediate 16:16 ptr

OpPtr16_32 !Word16 !Word32

Immediate 16:32 ptr

OpStackFrame !Word16 !Word8

Stack frame (cf ENTER)

data Addr Source #

A memory address

Constructors

Addr 

Fields

Instances

Eq Addr Source # 

Methods

(==) :: Addr -> Addr -> Bool #

(/=) :: Addr -> Addr -> Bool #

Show Addr Source # 

Methods

showsPrec :: Int -> Addr -> ShowS #

show :: Addr -> String #

showList :: [Addr] -> ShowS #

data ImmType Source #

Immediate type

Constructors

ImmSize8

8-bit immediate

ImmSize16

16-bit immediate

ImmSizeOp

operand-size immediate

ImmSizeSE

sign-extendable immediate: * if sign-extendable bit is set: sign-extended 8-bit immediate * if 64-bit operand size: sign-extended 32-bit immediate * otherwise: operand-size immediate

ImmConst Int

Constant immediate (used in implicit)

data RegType Source #

Register type

Constructors

RegVec64

64-bit vector register (mmx)

RegVec128

128-bit vector register (xmm)

RegVec256

256-bit vector register (ymm)

RegFixed Register

Fixed register

RegSegment

Segment register

RegControl

Control register

RegDebug

Debug register

Reg8

General purpose 8-bit register

Reg16

General purpose 16-bit register

Reg32

General purpose 32-bit register

Reg64

General purpose 64-bit register

Reg32o64

General purpose 32-bit register in legacy mode, general purpose 64-bit register in 64-bit mode

RegOpSize

General purpose register: 8, 16, 32 or 64-bit

RegST

x87 register

RegCounter

CX, ECX or RCX depending on the address-size

RegAccu

AL, AX, EAX, RAX depending on the operand-size

RegStackPtr

SP, ESP, RSP (default in 64-bit mode)

RegBasePtr

BP, EBP, RBP (default in 64-bit mode)

RegFam RegFamilies

Register family

data SubRegType Source #

Sub register type

Constructors

SubLow8

Low 8-bit of a register

SubLow16

Low 16-bit of a register

SubLow32

Low 32-bit of a register

SubLow64

Low 64-bit of a register

SubHigh64

High 64-bit of a register

SubEven64
63:0
and [191:128], etc.

data MemType Source #

Memory address type

Constructors

MemPair16o32

Pair of words in memory (words are operand-size large)

Mem8

8-bit memory

Mem16

16-bit memory

Mem32

32-bit memory

Mem64

64-bit memory

Mem128

128-bit memory

Mem256

256-bit memory

Mem512

512-bit memory

MemOpSize

operand-size-bit memory

MemVoid

The pointer is used to identify a page, etc. (e.g., CLFLUSH)

MemPtr

m16:16, m16:32 or m16:64 (16-bit selector + offset)

MemDescTable

Descriptor table: m16&32 (legacy) or m16&64 (64-bit mode)

MemFP

m32fp or m64fp (x87)

MemFP80

m80fp (x87)

MemInt

m32int or m16int (x87)

MemInt64

m64int (x87)

MemDec80

Binary coded decimal (m80dec (x87))

MemEnv

14/28 bit FPU environment (x87)

MemFPUState

94/108 bit FPU state (x87)

MemDSrSI

operand-size memory at DS:rSI (rSI depends on address-size, DS if fixed)

MemESrDI

operand-size memory at ES:rDI (rDI depends on address-size, ES is fixed)

MemDSrDI

operand-size memory at DS:rDI (rDI depends on address-size, DS is overridable with prefixes)

MemVSIB32 VSIBType

VSIB: 32-bit memory referred to by the VSIB

MemVSIB64 VSIBType

VSIB: 64-bit memory referred to by the VSIB

MemState

Processor extended states (cf XSAVE/XRSTOR)

data RelType Source #

Relative type

Constructors

Rel8

Relative 8-bit displacement

Rel16o32

Relative 16- or 32-bit displacement (16-bit invalid in 64-bit mode)

data RegFamilies Source #

Register family

Constructors

RegFamAX

AX, EAX, RAX (depending on operand-size)

RegFamBX

BX, EBX, RBX (depending on operand-size)

RegFamCX

CX, ECX, RCX (depending on operand-size)

RegFamDX

DX, EDX, RDX (depending on operand-size)

RegFamSI

SI, ESI, RSI (depending on operand-size)

RegFamDI

DI, EDI, RDI (depending on operand-size)

RegFamDXAX

AX, DX:AX, EDX:EAX, RDX:RAX

data VSIBType Source #

How to use the index register e.g., VSIBType 32 128 --> 32-bit indices in a 128-bits register (XMM)

Constructors

VSIBType Size VSIBIndexReg 

maybeOpTypeReg :: OperandType -> Bool Source #

Indicate if the operand type can be register when stored in ModRM.rm (i.e. ModRM.mod may be 11b)