dioscuri.module.cpu
Class CPU

java.lang.Object
  extended by dioscuri.module.AbstractModule
      extended by dioscuri.module.ModuleCPU
          extended by dioscuri.module.cpu.CPU
All Implemented Interfaces:
Addressable, Module

public class CPU
extends ModuleCPU

An implementation of an Intel 8086 hardware CPU module.

Contains 8 32-bit general registers, 4 16-bit segment registers, and 2 status/control registers 'flags' and 'ip'.

Reads instruction stored in Memory and executes these using an opcode lookup-table.

See Also:

Metadata module ******************************************** general.type : cpu general.name : x86 CPU based on the Intel 8086 processor general.architecture : Von Neumann general.description : Contains 8 32-bit general registers, 4 16-bit segment registers, and 2 status/control registers 'flags' and 'ip'. general.creator : Tessella Support Services, Koninklijke Bibliotheek, Nationaal Archief of the Netherlands general.version : 1.0 general.keywords : CPU, processor, Intel, 8086 general.relations : memory, motherboard general.yearOfIntroduction : 1978 general.yearOfEnding : 1982 general.ancestor : Intel 8080 general.successor : Intel 80186 cpu.clockrateMinimum : 4.77 MHz cpu.clockrateMaximum : 10.00 MHz

Notes: - Most instructions are implemented as 16 bit. However, a couple of them (including general purpose registers) allow 32-bit computing.

General information about instruction format: 8086 has instruction layout:

. Opcode byte in bits: xxxx xxdw x is the opcode of the instruction d is the direction bit: if d=0, rrr -> sss (addressbyte) if d=1, sss -> rrr (addressbyte) w the size bit if w=0, indicates byte if w=1, indicates word Address byte in bits: 7654 3210 mmrr rsss The interpretation of these bits depend on the opcode, but generally: m specifies what rrr, sss are 00 - memory reference (specified by rrr), sss specifies register 01 - memory reference plus 8 bit offset (follows after addressbyte) 10 - memory reference plus 16 bit offset (follows after addressbyte) 11 - sss is a register, using same lookup table as rrr rrr specifies a process register, (toggle with w), or a memory reference if rrr w0 w1 memref 000 AL AX BX+SI 001 CL CX BX+DI 010 DL DX BP+SI 011 BL BX BP+DI 100 AH SP SI 101 CH BP DI 110 DH SI 2-byte offset specified after addressbyte 111 BH DI BX sss specifies a register

Nested Class Summary
 
Nested classes/interfaces inherited from interface dioscuri.interfaces.Module
Module.Type
 
Field Summary
protected  boolean asyncEvent
           
protected  byte[] ax
           
protected  byte[] bp
           
protected  byte[] bx
           
protected  int codeByte
           
protected  int codeByte2
           
protected  boolean[] cr0
           
protected  boolean[] cr1
           
protected  boolean[] cr2
           
protected  boolean[] cr3
           
protected  boolean[] cr4
           
protected  byte[] cs
           
protected  byte[] cx
           
protected  byte[] di
           
protected  Instruction[] doubleByteInstructions
           
protected  boolean doubleWord
           
protected  byte[] ds
           
protected  byte[] dx
           
protected  byte[] eax
           
protected  byte[] ebp
           
protected  byte[] ebx
           
protected  byte[] ecx
           
protected  byte[] edi
           
protected  byte[] edx
           
protected  byte[] es
           
protected  byte[] esi
           
protected  byte[] esp
           
protected  boolean[] flags
           
protected  byte[] gdtr
           
protected  byte[] idtr
           
protected  byte[] ip
           
 int ips
           
 int ipus
           
protected  byte[] ldtr
           
protected  byte[] oldIP
           
protected  int prefixInstruction
           
protected  boolean prefixRep
           
protected  int prefixRepType
           
static int REGISTER_CR0_AM
           
static int REGISTER_CR0_CD
           
static int REGISTER_CR0_EM
           
static int REGISTER_CR0_ET
           
static int REGISTER_CR0_MP
           
static int REGISTER_CR0_NE
           
static int REGISTER_CR0_NW
           
static int REGISTER_CR0_PE
           
static int REGISTER_CR0_PG
           
static int REGISTER_CR0_TS
           
static int REGISTER_CR0_WP
           
static int REGISTER_FLAGS_AF
           
static int REGISTER_FLAGS_CF
           
static int REGISTER_FLAGS_DF
           
static int REGISTER_FLAGS_IF
           
static int REGISTER_FLAGS_IOPL1
           
static int REGISTER_FLAGS_IOPL2
           
static int REGISTER_FLAGS_NT
           
static int REGISTER_FLAGS_OF
           
static int REGISTER_FLAGS_PF
           
static int REGISTER_FLAGS_SF
           
static int REGISTER_FLAGS_TF
           
static int REGISTER_FLAGS_ZF
           
static int REGISTER_GENERAL_HIGH
           
static int REGISTER_GENERAL_LOW
           
static int REGISTER_HIGH
           
static int REGISTER_INDEX_HIGH
           
static int REGISTER_INDEX_LOW
           
static int REGISTER_LOW
           
static int REGISTER_SEGMENT_HIGH
           
static int REGISTER_SEGMENT_LOW
           
static int REGISTER_SIZE_GENERAL
           
static int REGISTER_SIZE_INDEX
           
static int REGISTER_SIZE_SEGMENT
           
static int REGISTER_SIZE_SPECIAL
           
static int SEGMENT_OVERRIDE_CS
           
static int SEGMENT_OVERRIDE_DS
           
static int SEGMENT_OVERRIDE_ES
           
static int SEGMENT_OVERRIDE_SS
           
protected  boolean segmentOverride
           
protected  int segmentOverridePointer
           
protected  byte[] si
           
protected  Instruction[] singleByteInstructions
           
protected  byte[] sp
           
protected  byte[] ss
           
static byte[] WORD_0X0001
           
 
Fields inherited from class dioscuri.module.AbstractModule
type
 
Constructor Summary
CPU(Emulator owner)
          Class constructor specifying memory
 
Method Summary
protected  byte[] decodeExtraRegister(int rrrsssBits)
          Determine extra register based on rrr/sss bits from addressbyte.
Complete register is returned to ensure pass by reference.
protected  byte[] decodeMM(int addrByte)
          Using mm bits from addressbyte, retrieve value of displacement (if sss indicates a memory destination).
protected  byte[] decodeRegister(boolean operandWord, int rrrsssBits)
          Determine register based on rrr/sss bits from addressbyte.
Complete register is returned to ensure pass by reference.
protected  byte[] decodeSegmentRegister(int rrrsssBits)
          Determine segment register based on rrr/sss bits from addressbyte.
Complete segment register is returned to ensure pass by reference.
protected  byte[] decodeSSSMemDest(byte addrByte, byte[] displacement)
          Determine memory destination based on sss bits from addressbyte.
 java.lang.String dumpDebug(java.lang.String data)
           
 java.lang.String dumpRegisters()
          Returns a dump of the current registers with their value
protected  byte getByteFromCode()
          Retrieves a single byte from the code memory segment; updates the ip by one Note: use this method only when next instruction/addressbyte/immediate is needed!
protected  byte getByteFromCode(byte[] displacement)
          Retrieves a byte from the code memory segment at given displacement.
protected  byte getByteFromData(byte[] displacement)
          Retrieves a byte from the data memory segment.
protected  byte getByteFromExtra(byte[] displacement)
          Retrieves a single byte from the extra memory segment.
protected  byte getByteFromMemorySegment(byte addressByte, byte[] offset)
          Retrieves a byte from segment memory DS or SS, which is determined from the addressbyte
protected  byte getByteFromStack(byte[] displacement)
          Retrieves a single byte from the stack memory segment.
 boolean getCpuInstructionDebug()
          Get CPU instruction debug.
 long getCurrentInstructionNumber()
          Retrieve current number of instruction (instructions executed so far)
 java.lang.String getDump()
          Return a dump of module status
 boolean getFlagValue(char flagLetter)
          Returns the value of a named flag.
 byte getIOPortByte(int portAddress)
          
 byte[] getIOPortDoubleWord(int portAddress)
          
 byte[] getIOPortWord(int portAddress)
          
 int getIPS()
          Get the Instructions Per Second (ips) for this CPU.
 java.lang.String getNextInstructionInfo()
          Retrieve string with information about next instruction to be executed
 java.lang.String getRegisterHex(int register)
          
 byte[] getRegisterValue(java.lang.String registerName)
          Returns the value of a named register.
protected  byte[] getWordFromCode()
          Retrieves a word from the code memory segment; updates the ip by two Note: use this method only when next instruction/addressbyte/immediate is needed!
protected  byte[] getWordFromCode(byte[] displacement)
          Retrieves a word from the code memory segment at given displacement Note: does not update IP
protected  byte[] getWordFromData(byte[] displacement)
          Retrieves a word from the data memory segment.
protected  byte[] getWordFromExtra(byte[] displacement)
          Retrieves a word from extra memory segment.
protected  byte[] getWordFromMemorySegment(byte addressByte, byte[] offset)
          Retrieves a word from segment memory DS or SS, which is determined from the addressbyte
protected  byte[] getWordFromStack()
          Retrieves a word from the stack; increments stack pointer SP by two.
protected  byte[] getWordFromStack(byte[] displacement)
          Retrieves a word from the stack segment.
protected  void incrementInstructionCounter()
          Increment current number of instruction by one
protected  boolean initInstructionTables()
          Initialise the single and double byte opcode lookup arrays with instructions corresponding to the Intel hexadecimal machinecode values.
protected  boolean initRegisters()
          Initialise registers
 void interruptRequest(boolean value)
          Set the interrupt request (IRQ).
 boolean isAbnormalTermination()
          Returns if CPU halted abnormally or not
protected  boolean isDoubleByte32BitSupported()
          Checks if 32-bit is supported by the double byte instruction Note: this instruction should only be used in debug mode, because it unnecessarily slows down the execution.
 boolean isShutdown()
          Returns if CPU halted due to full system shutdown or not
 java.lang.String registerDump()
           
 boolean reset()
          Reset all parameters of module.
protected  void resetPrefixes()
          Reset all prefixes
protected  void setByteInMemorySegment(byte addressByte, byte[] disp, byte value)
          Sets a byte in segment memory DS or SS, which is determined from the addressbyte
protected  void setByteToCode(byte[] displacement, byte value)
          Assigns a byte in the code memory segment (CS:displacement) a new value Note: this method should be avoided because it does not take care of R/M byte differences Instead, use setByteToMemorySegment() Note: does not update IP
protected  void setByteToData(byte[] displacement, byte value)
          Assigns a byte in the data memory segment (DS:displacement) a new value Note: this method should be avoided because it does not take care of R/M byte differences Instead, use setByteToMemorySegment()
protected  void setByteToExtra(byte[] displacement, byte value)
          Sets byte in memory at ES:DI in the extra memory segment
protected  void setByteToStack(byte value)
          Pushes a byte on the stack memory segment (SS:SP) Note: do not use this method, use setWordToMemorySegment instead
protected  void setByteToStack(byte[] displacement, byte value)
          Pushes a byte on the stack memory segment Note: do not use this method, use setByteToMemorySegment instead
 void setCpuInstructionDebug(boolean cpuInstructionDebug)
          Set the CPU instruction debug.
 void setHoldRequest(boolean value, Module originator)
          Sets the CPU hold mode by asserting a Hold Request.
This informs the CPU to avoid using the (non-existent) bus as another device (usually via DMA) is using it; it should be scheduled as a asynchronous event in CPU.
 void setIOPortByte(int portAddress, byte data)
          
 void setIOPortDoubleWord(int portAddress, byte[] data)
          
 void setIOPortWord(int portAddress, byte[] data)
          
 void setIPS(int ips)
          Set the Instructions Per Second (ips) for this CPU.
 void setIPS(int ips, int lowestUpdatePeriod)
          Set the Instructions Per Second (ips) for this CPU.
 boolean setRegisterValue(java.lang.String registerName, byte[] value)
          Sets the value of a named register to given value.
protected  void setRunning(boolean status)
          Set the boolean that starts and stops the CPU loop
protected  void setShutdown(boolean status)
          Set shutdown status
protected  void setWordInMemorySegment(byte addressByte, byte[] disp, byte[] value)
          Sets a word in segment memory DS or SS, which is determined from the addressbyte
protected  void setWordToCode(byte[] displacement, byte[] value)
          Assigns a word in the code memory segment (CS:displacement) a new value Note: do not use this method directly, use setWordToMemorySegment instead Note: does not update IP
protected  void setWordToData(byte[] displacement, byte[] value)
          Assigns a word in the data memory segment (DS:displacement) a new value Note: do not use this method, use setWordToMemorySegment instead
protected  void setWordToExtra(byte[] displacement, byte[] word)
          Sets word in memory at ES:DI in the extra memory segment
protected  void setWordToStack(byte[] value)
          Pushes a word on the stack memory segment (SS:SP); decrements the stack pointer SP by two.
protected  void setWordToStack(byte[] displacement, byte[] value)
          Sets a word in SS segment Note: when using addressbytes, do not use this method, use setWordToMemorySegment instead
 void start()
          Starts the module to become active.
 java.lang.String startDebug()
           
 void stop()
          Stops the module from being active.
 
Methods inherited from class dioscuri.module.AbstractModule
getConnection, getConnections, getDebugMode, getExpectedConnections, getType, isConnected, setConnection, setDebugMode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface dioscuri.interfaces.Module
getConnection, getConnections, getDebugMode, getExpectedConnections, getType, isConnected, setConnection, setDebugMode
 

Field Detail

asyncEvent

protected boolean asyncEvent

ips

public int ips

ipus

public int ipus

codeByte

protected int codeByte

codeByte2

protected int codeByte2

ax

protected byte[] ax

eax

protected byte[] eax

bx

protected byte[] bx

ebx

protected byte[] ebx

cx

protected byte[] cx

ecx

protected byte[] ecx

dx

protected byte[] dx

edx

protected byte[] edx

sp

protected byte[] sp

esp

protected byte[] esp

bp

protected byte[] bp

ebp

protected byte[] ebp

si

protected byte[] si

esi

protected byte[] esi

di

protected byte[] di

edi

protected byte[] edi

cs

protected byte[] cs

ds

protected byte[] ds

ss

protected byte[] ss

es

protected byte[] es

ip

protected byte[] ip

oldIP

protected byte[] oldIP

flags

protected boolean[] flags

cr0

protected boolean[] cr0

cr1

protected boolean[] cr1

cr2

protected boolean[] cr2

cr3

protected boolean[] cr3

cr4

protected boolean[] cr4

gdtr

protected byte[] gdtr

idtr

protected byte[] idtr

ldtr

protected byte[] ldtr

prefixInstruction

protected int prefixInstruction

prefixRep

protected boolean prefixRep

prefixRepType

protected int prefixRepType

doubleWord

protected boolean doubleWord

segmentOverride

protected boolean segmentOverride

segmentOverridePointer

protected int segmentOverridePointer

singleByteInstructions

protected Instruction[] singleByteInstructions

doubleByteInstructions

protected Instruction[] doubleByteInstructions

REGISTER_SIZE_GENERAL

public static final int REGISTER_SIZE_GENERAL
See Also:
Constant Field Values

REGISTER_SIZE_INDEX

public static final int REGISTER_SIZE_INDEX
See Also:
Constant Field Values

REGISTER_SIZE_SEGMENT

public static final int REGISTER_SIZE_SEGMENT
See Also:
Constant Field Values

REGISTER_SIZE_SPECIAL

public static final int REGISTER_SIZE_SPECIAL
See Also:
Constant Field Values

REGISTER_LOW

public static final int REGISTER_LOW
See Also:
Constant Field Values

REGISTER_HIGH

public static final int REGISTER_HIGH
See Also:
Constant Field Values

REGISTER_GENERAL_LOW

public static final int REGISTER_GENERAL_LOW
See Also:
Constant Field Values

REGISTER_GENERAL_HIGH

public static final int REGISTER_GENERAL_HIGH
See Also:
Constant Field Values

REGISTER_INDEX_LOW

public static final int REGISTER_INDEX_LOW
See Also:
Constant Field Values

REGISTER_INDEX_HIGH

public static final int REGISTER_INDEX_HIGH
See Also:
Constant Field Values

REGISTER_SEGMENT_LOW

public static final int REGISTER_SEGMENT_LOW
See Also:
Constant Field Values

REGISTER_SEGMENT_HIGH

public static final int REGISTER_SEGMENT_HIGH
See Also:
Constant Field Values

REGISTER_FLAGS_CF

public static final int REGISTER_FLAGS_CF
See Also:
Constant Field Values

REGISTER_FLAGS_PF

public static final int REGISTER_FLAGS_PF
See Also:
Constant Field Values

REGISTER_FLAGS_AF

public static final int REGISTER_FLAGS_AF
See Also:
Constant Field Values

REGISTER_FLAGS_ZF

public static final int REGISTER_FLAGS_ZF
See Also:
Constant Field Values

REGISTER_FLAGS_SF

public static final int REGISTER_FLAGS_SF
See Also:
Constant Field Values

REGISTER_FLAGS_TF

public static final int REGISTER_FLAGS_TF
See Also:
Constant Field Values

REGISTER_FLAGS_IF

public static final int REGISTER_FLAGS_IF
See Also:
Constant Field Values

REGISTER_FLAGS_DF

public static final int REGISTER_FLAGS_DF
See Also:
Constant Field Values

REGISTER_FLAGS_OF

public static final int REGISTER_FLAGS_OF
See Also:
Constant Field Values

REGISTER_FLAGS_IOPL1

public static final int REGISTER_FLAGS_IOPL1
See Also:
Constant Field Values

REGISTER_FLAGS_IOPL2

public static final int REGISTER_FLAGS_IOPL2
See Also:
Constant Field Values

REGISTER_FLAGS_NT

public static final int REGISTER_FLAGS_NT
See Also:
Constant Field Values

REGISTER_CR0_PE

public static final int REGISTER_CR0_PE
See Also:
Constant Field Values

REGISTER_CR0_MP

public static final int REGISTER_CR0_MP
See Also:
Constant Field Values

REGISTER_CR0_EM

public static final int REGISTER_CR0_EM
See Also:
Constant Field Values

REGISTER_CR0_TS

public static final int REGISTER_CR0_TS
See Also:
Constant Field Values

REGISTER_CR0_ET

public static final int REGISTER_CR0_ET
See Also:
Constant Field Values

REGISTER_CR0_NE

public static final int REGISTER_CR0_NE
See Also:
Constant Field Values

REGISTER_CR0_WP

public static final int REGISTER_CR0_WP
See Also:
Constant Field Values

REGISTER_CR0_AM

public static final int REGISTER_CR0_AM
See Also:
Constant Field Values

REGISTER_CR0_NW

public static final int REGISTER_CR0_NW
See Also:
Constant Field Values

REGISTER_CR0_CD

public static final int REGISTER_CR0_CD
See Also:
Constant Field Values

REGISTER_CR0_PG

public static final int REGISTER_CR0_PG
See Also:
Constant Field Values

SEGMENT_OVERRIDE_CS

public static final int SEGMENT_OVERRIDE_CS
See Also:
Constant Field Values

SEGMENT_OVERRIDE_DS

public static final int SEGMENT_OVERRIDE_DS
See Also:
Constant Field Values

SEGMENT_OVERRIDE_ES

public static final int SEGMENT_OVERRIDE_ES
See Also:
Constant Field Values

SEGMENT_OVERRIDE_SS

public static final int SEGMENT_OVERRIDE_SS
See Also:
Constant Field Values

WORD_0X0001

public static final byte[] WORD_0X0001
Constructor Detail

CPU

public CPU(Emulator owner)
Class constructor specifying memory

Parameters:
owner -
Method Detail

reset

public boolean reset()
Reset all parameters of module.

Specified by:
reset in interface Module
Specified by:
reset in class AbstractModule
Returns:
true iff the AbstractModule was reset properly.
See Also:
AbstractModule

start

public void start()
Starts the module to become active.

Provides an empty implementations since many of the subclasses of this abstract module class do not need a start() implementation. The ones that do, can override this method.

Specified by:
start in interface Module
Overrides:
start in class AbstractModule
See Also:
Module

stop

public void stop()
Stops the module from being active.

Provides an empty implementations since many of the subclasses of this abstract module class do not need a stop() implementation. The ones that do, can override this method.

Specified by:
stop in interface Module
Overrides:
stop in class AbstractModule
See Also:
Module

getDump

public java.lang.String getDump()
Return a dump of module status

Provides a dummy implementation since many of the subclasses of this abstract module class do not need or use a getDump() implementation. The ones that do, can override this method.

Specified by:
getDump in interface Module
Overrides:
getDump in class AbstractModule
Returns:
string containing a dump of this module
See Also:
AbstractModule

dumpRegisters

public java.lang.String dumpRegisters()
Returns a dump of the current registers with their value

Specified by:
dumpRegisters in class ModuleCPU
Returns:
String containing a register dump
See Also:
ModuleCPU

dumpDebug

public java.lang.String dumpDebug(java.lang.String data)
Parameters:
data -
Returns:
-

isAbnormalTermination

public boolean isAbnormalTermination()
Returns if CPU halted abnormally or not

Specified by:
isAbnormalTermination in class ModuleCPU
Returns:
boolean abnormalTermination true if abnormal, false otherwise
See Also:
ModuleCPU

isShutdown

public boolean isShutdown()
Returns if CPU halted due to full system shutdown or not

Specified by:
isShutdown in class ModuleCPU
Returns:
boolean shutDown true if emulator should shutdown, false otherwise
See Also:
ModuleCPU

setShutdown

protected void setShutdown(boolean status)
Set shutdown status

Parameters:
status - true if emulator should shutdown, false otherwise

setHoldRequest

public void setHoldRequest(boolean value,
                           Module originator)
Sets the CPU hold mode by asserting a Hold Request.
This informs the CPU to avoid using the (non-existent) bus as another device (usually via DMA) is using it; it should be scheduled as a asynchronous event in CPU.

Specified by:
setHoldRequest in class ModuleCPU
Parameters:
value - state of the Hold Request
originator - -
See Also:
ModuleCPU

getIPS

public int getIPS()
Get the Instructions Per Second (ips) for this CPU.

Specified by:
getIPS in class ModuleCPU
Returns:
the Instructions Per Second (ips) for this CPU.
See Also:
ModuleCPU

setIPS

public void setIPS(int ips)
Set the Instructions Per Second (ips) for this CPU.

Specified by:
setIPS in class ModuleCPU
Parameters:
ips - the Instructions Per Second (ips) for this CPU.
See Also:
ModuleCPU

setIPS

public void setIPS(int ips,
                   int lowestUpdatePeriod)
Set the Instructions Per Second (ips) for this CPU. Also, define what the smallest period is for sending a clockpulse (in microseconds)

Specified by:
setIPS in class ModuleCPU
lowestUpdatePeriod - the lowest update period in microseconds
See Also:
ModuleCPU

initRegisters

protected boolean initRegisters()
Initialise registers

Specified by:
initRegisters in class ModuleCPU
Returns:
true if initialisation is successful, false otherwise
See Also:
ModuleCPU

initInstructionTables

protected boolean initInstructionTables()
Initialise the single and double byte opcode lookup arrays with instructions corresponding to the Intel hexadecimal machinecode values.

Specified by:
initInstructionTables in class ModuleCPU
Returns:
See Also:
ModuleCPU

setRunning

protected void setRunning(boolean status)
Set the boolean that starts and stops the CPU loop

Specified by:
setRunning in class ModuleCPU
Parameters:
status - sets the isRunning boolean
See Also:
ModuleCPU

getRegisterValue

public byte[] getRegisterValue(java.lang.String registerName)
Returns the value of a named register.

Specified by:
getRegisterValue in class ModuleCPU
Returns:
int[] with value of register, null otherwise
See Also:
ModuleCPU

setRegisterValue

public boolean setRegisterValue(java.lang.String registerName,
                                byte[] value)
Sets the value of a named register to given value.

Specified by:
setRegisterValue in class ModuleCPU
value - containing the value
Returns:
true if set was successful, false otherwise
See Also:
ModuleCPU

getFlagValue

public boolean getFlagValue(char flagLetter)
Returns the value of a named flag.

Parameters:
flagLetter - First letter of flag name
Returns:
value of flag

getNextInstructionInfo

public java.lang.String getNextInstructionInfo()
Retrieve string with information about next instruction to be executed

Specified by:
getNextInstructionInfo in class ModuleCPU
Returns:
string containing next instruction information
See Also:
ModuleCPU

getCurrentInstructionNumber

public long getCurrentInstructionNumber()
Retrieve current number of instruction (instructions executed so far)

Specified by:
getCurrentInstructionNumber in class ModuleCPU
Returns:
long containing number of instructions
See Also:
ModuleCPU

incrementInstructionCounter

protected void incrementInstructionCounter()
Increment current number of instruction by one

Specified by:
incrementInstructionCounter in class ModuleCPU
See Also:
ModuleCPU

getIOPortByte

public byte getIOPortByte(int portAddress)
                   throws ModuleException

Returns:
Throws:
ModuleException
See Also:
Addressable

setIOPortByte

public void setIOPortByte(int portAddress,
                          byte data)
                   throws ModuleException

Throws:
ModuleException
See Also:
Addressable

getIOPortWord

public byte[] getIOPortWord(int portAddress)
                     throws ModuleException

Returns:
Throws:
ModuleException
See Also:
Addressable

setIOPortWord

public void setIOPortWord(int portAddress,
                          byte[] data)
                   throws ModuleException

Throws:
ModuleException
See Also:
Addressable

getIOPortDoubleWord

public byte[] getIOPortDoubleWord(int portAddress)
                           throws ModuleException

Returns:
Throws:
ModuleException
See Also:
Addressable

setIOPortDoubleWord

public void setIOPortDoubleWord(int portAddress,
                                byte[] data)
                         throws ModuleException

Throws:
ModuleException
See Also:
Addressable

interruptRequest

public void interruptRequest(boolean value)
Set the interrupt request (IRQ).

Specified by:
interruptRequest in class ModuleCPU
See Also:
ModuleCPU

resetPrefixes

protected void resetPrefixes()
Reset all prefixes


isDoubleByte32BitSupported

protected boolean isDoubleByte32BitSupported()
Checks if 32-bit is supported by the double byte instruction Note: this instruction should only be used in debug mode, because it unnecessarily slows down the execution. Checking is done based on a known 32-bit list. All instructions that are not on the list are assumed to be 16 bit.

Returns:
boolean true if 32 bit is supported, false otherwise

getByteFromCode

protected byte getByteFromCode()
Retrieves a single byte from the code memory segment; updates the ip by one Note: use this method only when next instruction/addressbyte/immediate is needed!

Returns:
byte at memory address CS:IP

getByteFromCode

protected byte getByteFromCode(byte[] displacement)
Retrieves a byte from the code memory segment at given displacement. Note: when working with addressbytes, do not use this method, use getByteFromMemorySegment instead Note: does not update IP

Parameters:
displacement - Two byte offset in the current segment
Returns:
byte at memory address CS:DISP

getByteFromData

protected byte getByteFromData(byte[] displacement)
Retrieves a byte from the data memory segment. Note: when working with addressbytes, do not use this method, use getByteFromMemorySegment instead

Parameters:
displacement - Two byte offset in the current data segment
Returns:
byte at memory address DS:DISP

getByteFromStack

protected byte getByteFromStack(byte[] displacement)
Retrieves a single byte from the stack memory segment. Note: when working with addressbytes, do not use this method, use getByteFromMemorySegment instead

Parameters:
displacement - Two byte offset in the current stack segment
Returns:
byte at memory address SS:DISP

getByteFromExtra

protected byte getByteFromExtra(byte[] displacement)
Retrieves a single byte from the extra memory segment. Note: when working with addressbytes, do not use this method, use getByteFromMemorySegment instead

Parameters:
displacement -
Returns:
byte at memory address ES:DI

getWordFromCode

protected byte[] getWordFromCode()
Retrieves a word from the code memory segment; updates the ip by two Note: use this method only when next instruction/addressbyte/immediate is needed!

Returns:
byte[] with word at memory address CS:IP

getWordFromCode

protected byte[] getWordFromCode(byte[] displacement)
Retrieves a word from the code memory segment at given displacement Note: does not update IP

Parameters:
displacement -
Returns:
byte[] with word at memory address displacement

getWordFromData

protected byte[] getWordFromData(byte[] displacement)
Retrieves a word from the data memory segment. Note: when working with addressbytes, do not use this method, use getWordFromMemorySegment instead

Parameters:
displacement - Two byte offset in the current data segment
Returns:
word at memory address DS:DISP

getWordFromStack

protected byte[] getWordFromStack()
Retrieves a word from the stack; increments stack pointer SP by two. Note: when working with addressbytes, do not use this method, use getWordFromMemorySegment instead

Returns:
word at memory address SS:SP

getWordFromStack

protected byte[] getWordFromStack(byte[] displacement)
Retrieves a word from the stack segment. Note: when working with addressbytes, do not use this method, use getWordFromMemorySegment instead

Parameters:
displacement - Two byte offset in the current stack segment
Returns:
word at memory address SS:DISP

getWordFromExtra

protected byte[] getWordFromExtra(byte[] displacement)
Retrieves a word from extra memory segment. Note: when working with addressbytes, do not use this method, use getWordFromMemorySegment instead

Parameters:
displacement - Two byte offset in the current data segment
Returns:
word at memory address ES:DISP

getByteFromMemorySegment

protected byte getByteFromMemorySegment(byte addressByte,
                                        byte[] offset)
Retrieves a byte from segment memory DS or SS, which is determined from the addressbyte

Parameters:
addressByte - byte whose R/M bits indicate which segment register is to be used
offset - byte[] indicating displacement of word in segment
Returns:
byte at memory address SS:disp or DS:disp

getWordFromMemorySegment

protected byte[] getWordFromMemorySegment(byte addressByte,
                                          byte[] offset)
Retrieves a word from segment memory DS or SS, which is determined from the addressbyte

Parameters:
addressByte - byte whose R/M bits indicate which segment register is to be used
offset - byte[] indicating offset of word in segment
Returns:
word at memory address SS:disp or DS:disp

setByteToCode

protected void setByteToCode(byte[] displacement,
                             byte value)
Assigns a byte in the code memory segment (CS:displacement) a new value Note: this method should be avoided because it does not take care of R/M byte differences Instead, use setByteToMemorySegment() Note: does not update IP

Parameters:
displacement - Two byte offset in the current code segment
value - New value of the byte

setWordToCode

protected void setWordToCode(byte[] displacement,
                             byte[] value)
Assigns a word in the code memory segment (CS:displacement) a new value Note: do not use this method directly, use setWordToMemorySegment instead Note: does not update IP

Parameters:
displacement - Two byte offset in the current code segment
value - New value of the word

setByteToData

protected void setByteToData(byte[] displacement,
                             byte value)
Assigns a byte in the data memory segment (DS:displacement) a new value Note: this method should be avoided because it does not take care of R/M byte differences Instead, use setByteToMemorySegment()

Parameters:
displacement - Two byte offset in the current data segment
value - New value of the byte

setWordToData

protected void setWordToData(byte[] displacement,
                             byte[] value)
Assigns a word in the data memory segment (DS:displacement) a new value Note: do not use this method, use setWordToMemorySegment instead

Parameters:
displacement - Two byte offset in the current data segment
value - New value of the word

setByteToExtra

protected void setByteToExtra(byte[] displacement,
                              byte value)
Sets byte in memory at ES:DI in the extra memory segment

Parameters:
displacement -
value -

setWordToExtra

protected void setWordToExtra(byte[] displacement,
                              byte[] word)
Sets word in memory at ES:DI in the extra memory segment

Parameters:
displacement -
word - Value of word to assign

setByteToStack

protected void setByteToStack(byte value)
Pushes a byte on the stack memory segment (SS:SP) Note: do not use this method, use setWordToMemorySegment instead

Parameters:
value - to be pushed on the stack

setByteToStack

protected void setByteToStack(byte[] displacement,
                              byte value)
Pushes a byte on the stack memory segment Note: do not use this method, use setByteToMemorySegment instead

Parameters:
displacement -
value - to be pushed onto the stack

setWordToStack

protected void setWordToStack(byte[] value)
Pushes a word on the stack memory segment (SS:SP); decrements the stack pointer SP by two. Note: do not use this method, use setWordToMemorySegment instead

Parameters:
value - word to be pushed on the stack

setWordToStack

protected void setWordToStack(byte[] displacement,
                              byte[] value)
Sets a word in SS segment Note: when using addressbytes, do not use this method, use setWordToMemorySegment instead

Parameters:
displacement - Displacement within SS segment
value - word to be stored in SS

setByteInMemorySegment

protected void setByteInMemorySegment(byte addressByte,
                                      byte[] disp,
                                      byte value)
Sets a byte in segment memory DS or SS, which is determined from the addressbyte

Parameters:
addressByte - byte whose R/M bits indicate which segment register is to be used
disp - byte[] indicating displacement of word in segment
value - byte containing value to write to segment:disp

setWordInMemorySegment

protected void setWordInMemorySegment(byte addressByte,
                                      byte[] disp,
                                      byte[] value)
Sets a word in segment memory DS or SS, which is determined from the addressbyte

Parameters:
addressByte - byte whose R/M bits indicate which segment register is to be used
disp - byte[] indicating displacement of word in segment
value - byte[] containing value to write to segment:disp

decodeMM

protected byte[] decodeMM(int addrByte)
Using mm bits from addressbyte, retrieve value of displacement (if sss indicates a memory destination).

Parameters:
addrByte - addressbyte following opcode instruction
Returns:
memory reference displacement indicated by extra bytes.

decodeSSSMemDest

protected byte[] decodeSSSMemDest(byte addrByte,
                                  byte[] displacement)
Determine memory destination based on sss bits from addressbyte.

Parameters:
addrByte - addressbyte following opcode instruction
displacement - memory reference displacement from extra bytes
Returns:
memory location indication by sss and displacement

decodeRegister

protected byte[] decodeRegister(boolean operandWord,
                                int rrrsssBits)
Determine register based on rrr/sss bits from addressbyte.
Complete register is returned to ensure pass by reference.

Parameters:
operandWord - boolean indicating byte (false) or word (true) size
rrrsssBits - integer value (0 - 7) based on rrr/sss bits from addressbyte
Returns:
register indicated by relevant bits from addressbyte

decodeExtraRegister

protected byte[] decodeExtraRegister(int rrrsssBits)
Determine extra register based on rrr/sss bits from addressbyte.
Complete register is returned to ensure pass by reference.

Parameters:
rrrsssBits - integer value (0 - 7) based on rrr/sss bits from addressbyte
Returns:
register indicated by relevant bits from addressbyte

decodeSegmentRegister

protected byte[] decodeSegmentRegister(int rrrsssBits)
Determine segment register based on rrr/sss bits from addressbyte.
Complete segment register is returned to ensure pass by reference.

Parameters:
rrrsssBits - integer value (0 - 7) based on rrr/sss bits from addressbyte
Returns:
segment register indicated by relevant bits from addressbyte

getRegisterHex

public java.lang.String getRegisterHex(int register)

Specified by:
getRegisterHex in class ModuleCPU
Returns:
See Also:
ModuleCPU

getCpuInstructionDebug

public boolean getCpuInstructionDebug()
Get CPU instruction debug.

Specified by:
getCpuInstructionDebug in class ModuleCPU
Returns:
cpuInstructionDebug.
See Also:
ModuleCPU

setCpuInstructionDebug

public void setCpuInstructionDebug(boolean cpuInstructionDebug)
Set the CPU instruction debug.

Specified by:
setCpuInstructionDebug in class ModuleCPU
Parameters:
cpuInstructionDebug - status of instructionDebug (on/off)
See Also:
ModuleCPU

startDebug

public java.lang.String startDebug()
Returns:
-

registerDump

public java.lang.String registerDump()
Returns:
-