|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dioscuri.module.AbstractModule dioscuri.module.ModuleCPU dioscuri.module.cpu.CPU
public class CPU
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.
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 |
---|
protected boolean asyncEvent
public int ips
public int ipus
protected int codeByte
protected int codeByte2
protected byte[] ax
protected byte[] eax
protected byte[] bx
protected byte[] ebx
protected byte[] cx
protected byte[] ecx
protected byte[] dx
protected byte[] edx
protected byte[] sp
protected byte[] esp
protected byte[] bp
protected byte[] ebp
protected byte[] si
protected byte[] esi
protected byte[] di
protected byte[] edi
protected byte[] cs
protected byte[] ds
protected byte[] ss
protected byte[] es
protected byte[] ip
protected byte[] oldIP
protected boolean[] flags
protected boolean[] cr0
protected boolean[] cr1
protected boolean[] cr2
protected boolean[] cr3
protected boolean[] cr4
protected byte[] gdtr
protected byte[] idtr
protected byte[] ldtr
protected int prefixInstruction
protected boolean prefixRep
protected int prefixRepType
protected boolean doubleWord
protected boolean segmentOverride
protected int segmentOverridePointer
protected Instruction[] singleByteInstructions
protected Instruction[] doubleByteInstructions
public static final int REGISTER_SIZE_GENERAL
public static final int REGISTER_SIZE_INDEX
public static final int REGISTER_SIZE_SEGMENT
public static final int REGISTER_SIZE_SPECIAL
public static final int REGISTER_LOW
public static final int REGISTER_HIGH
public static final int REGISTER_GENERAL_LOW
public static final int REGISTER_GENERAL_HIGH
public static final int REGISTER_INDEX_LOW
public static final int REGISTER_INDEX_HIGH
public static final int REGISTER_SEGMENT_LOW
public static final int REGISTER_SEGMENT_HIGH
public static final int REGISTER_FLAGS_CF
public static final int REGISTER_FLAGS_PF
public static final int REGISTER_FLAGS_AF
public static final int REGISTER_FLAGS_ZF
public static final int REGISTER_FLAGS_SF
public static final int REGISTER_FLAGS_TF
public static final int REGISTER_FLAGS_IF
public static final int REGISTER_FLAGS_DF
public static final int REGISTER_FLAGS_OF
public static final int REGISTER_FLAGS_IOPL1
public static final int REGISTER_FLAGS_IOPL2
public static final int REGISTER_FLAGS_NT
public static final int REGISTER_CR0_PE
public static final int REGISTER_CR0_MP
public static final int REGISTER_CR0_EM
public static final int REGISTER_CR0_TS
public static final int REGISTER_CR0_ET
public static final int REGISTER_CR0_NE
public static final int REGISTER_CR0_WP
public static final int REGISTER_CR0_AM
public static final int REGISTER_CR0_NW
public static final int REGISTER_CR0_CD
public static final int REGISTER_CR0_PG
public static final int SEGMENT_OVERRIDE_CS
public static final int SEGMENT_OVERRIDE_DS
public static final int SEGMENT_OVERRIDE_ES
public static final int SEGMENT_OVERRIDE_SS
public static final byte[] WORD_0X0001
Constructor Detail |
---|
public CPU(Emulator owner)
owner
- Method Detail |
---|
public boolean reset()
reset
in interface Module
reset
in class AbstractModule
AbstractModule
public void start()
start
in interface Module
start
in class AbstractModule
Module
public void stop()
stop
in interface Module
stop
in class AbstractModule
Module
public java.lang.String getDump()
getDump
in interface Module
getDump
in class AbstractModule
AbstractModule
public java.lang.String dumpRegisters()
dumpRegisters
in class ModuleCPU
ModuleCPU
public java.lang.String dumpDebug(java.lang.String data)
data
-
public boolean isAbnormalTermination()
isAbnormalTermination
in class ModuleCPU
ModuleCPU
public boolean isShutdown()
isShutdown
in class ModuleCPU
ModuleCPU
protected void setShutdown(boolean status)
status
- true if emulator should shutdown, false otherwisepublic void setHoldRequest(boolean value, Module originator)
setHoldRequest
in class ModuleCPU
value
- state of the Hold Requestoriginator
- -ModuleCPU
public int getIPS()
getIPS
in class ModuleCPU
ModuleCPU
public void setIPS(int ips)
setIPS
in class ModuleCPU
ips
- the Instructions Per Second (ips) for this CPU.ModuleCPU
public void setIPS(int ips, int lowestUpdatePeriod)
setIPS
in class ModuleCPU
lowestUpdatePeriod
- the lowest update period in microsecondsModuleCPU
protected boolean initRegisters()
initRegisters
in class ModuleCPU
ModuleCPU
protected boolean initInstructionTables()
initInstructionTables
in class ModuleCPU
ModuleCPU
protected void setRunning(boolean status)
setRunning
in class ModuleCPU
status
- sets the isRunning booleanModuleCPU
public byte[] getRegisterValue(java.lang.String registerName)
getRegisterValue
in class ModuleCPU
ModuleCPU
public boolean setRegisterValue(java.lang.String registerName, byte[] value)
setRegisterValue
in class ModuleCPU
value
- containing the value
ModuleCPU
public boolean getFlagValue(char flagLetter)
flagLetter
- First letter of flag name
public java.lang.String getNextInstructionInfo()
getNextInstructionInfo
in class ModuleCPU
ModuleCPU
public long getCurrentInstructionNumber()
getCurrentInstructionNumber
in class ModuleCPU
ModuleCPU
protected void incrementInstructionCounter()
incrementInstructionCounter
in class ModuleCPU
ModuleCPU
public byte getIOPortByte(int portAddress) throws ModuleException
ModuleException
Addressable
public void setIOPortByte(int portAddress, byte data) throws ModuleException
ModuleException
Addressable
public byte[] getIOPortWord(int portAddress) throws ModuleException
ModuleException
Addressable
public void setIOPortWord(int portAddress, byte[] data) throws ModuleException
ModuleException
Addressable
public byte[] getIOPortDoubleWord(int portAddress) throws ModuleException
ModuleException
Addressable
public void setIOPortDoubleWord(int portAddress, byte[] data) throws ModuleException
ModuleException
Addressable
public void interruptRequest(boolean value)
interruptRequest
in class ModuleCPU
ModuleCPU
protected void resetPrefixes()
protected boolean isDoubleByte32BitSupported()
protected byte getByteFromCode()
protected byte getByteFromCode(byte[] displacement)
displacement
- Two byte offset in the current segment
protected byte getByteFromData(byte[] displacement)
displacement
- Two byte offset in the current data segment
protected byte getByteFromStack(byte[] displacement)
displacement
- Two byte offset in the current stack segment
protected byte getByteFromExtra(byte[] displacement)
displacement
-
protected byte[] getWordFromCode()
protected byte[] getWordFromCode(byte[] displacement)
displacement
-
protected byte[] getWordFromData(byte[] displacement)
displacement
- Two byte offset in the current data segment
protected byte[] getWordFromStack()
protected byte[] getWordFromStack(byte[] displacement)
displacement
- Two byte offset in the current stack segment
protected byte[] getWordFromExtra(byte[] displacement)
displacement
- Two byte offset in the current data segment
protected byte getByteFromMemorySegment(byte addressByte, byte[] offset)
addressByte
- byte whose R/M bits indicate which segment register is to be
usedoffset
- byte[] indicating displacement of word in segment
protected byte[] getWordFromMemorySegment(byte addressByte, byte[] offset)
addressByte
- byte whose R/M bits indicate which segment register is to be
usedoffset
- byte[] indicating offset of word in segment
protected void setByteToCode(byte[] displacement, byte value)
displacement
- Two byte offset in the current code segmentvalue
- New value of the byteprotected void setWordToCode(byte[] displacement, byte[] value)
displacement
- Two byte offset in the current code segmentvalue
- New value of the wordprotected void setByteToData(byte[] displacement, byte value)
displacement
- Two byte offset in the current data segmentvalue
- New value of the byteprotected void setWordToData(byte[] displacement, byte[] value)
displacement
- Two byte offset in the current data segmentvalue
- New value of the wordprotected void setByteToExtra(byte[] displacement, byte value)
displacement
- value
- protected void setWordToExtra(byte[] displacement, byte[] word)
displacement
- word
- Value of word to assignprotected void setByteToStack(byte value)
value
- to be pushed on the stackprotected void setByteToStack(byte[] displacement, byte value)
displacement
- value
- to be pushed onto the stackprotected void setWordToStack(byte[] value)
value
- word to be pushed on the stackprotected void setWordToStack(byte[] displacement, byte[] value)
displacement
- Displacement within SS segmentvalue
- word to be stored in SSprotected void setByteInMemorySegment(byte addressByte, byte[] disp, byte value)
addressByte
- byte whose R/M bits indicate which segment register is to be
useddisp
- byte[] indicating displacement of word in segmentvalue
- byte containing value to write to segment:dispprotected void setWordInMemorySegment(byte addressByte, byte[] disp, byte[] value)
addressByte
- byte whose R/M bits indicate which segment register is to be
useddisp
- byte[] indicating displacement of word in segmentvalue
- byte[] containing value to write to segment:dispprotected byte[] decodeMM(int addrByte)
addrByte
- addressbyte following opcode instruction
protected byte[] decodeSSSMemDest(byte addrByte, byte[] displacement)
addrByte
- addressbyte following opcode instructiondisplacement
- memory reference displacement from extra bytes
protected byte[] decodeRegister(boolean operandWord, int rrrsssBits)
operandWord
- boolean indicating byte (false) or word (true) sizerrrsssBits
- integer value (0 - 7) based on rrr/sss bits from addressbyte
protected byte[] decodeExtraRegister(int rrrsssBits)
rrrsssBits
- integer value (0 - 7) based on rrr/sss bits from addressbyte
protected byte[] decodeSegmentRegister(int rrrsssBits)
rrrsssBits
- integer value (0 - 7) based on rrr/sss bits from addressbyte
public java.lang.String getRegisterHex(int register)
getRegisterHex
in class ModuleCPU
ModuleCPU
public boolean getCpuInstructionDebug()
getCpuInstructionDebug
in class ModuleCPU
ModuleCPU
public void setCpuInstructionDebug(boolean cpuInstructionDebug)
setCpuInstructionDebug
in class ModuleCPU
cpuInstructionDebug
- status of instructionDebug (on/off)ModuleCPU
public java.lang.String startDebug()
public java.lang.String registerDump()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |