Add more instructions, add segment registers, move types up, read more data
This commit is contained in:
parent
c7ee622847
commit
390fedc848
108
decoder8086.odin
108
decoder8086.odin
@ -20,6 +20,9 @@ Register :: struct {
|
|||||||
OpName :: enum {
|
OpName :: enum {
|
||||||
TBD,
|
TBD,
|
||||||
MOV,
|
MOV,
|
||||||
|
PUSH,
|
||||||
|
POP,
|
||||||
|
XCHG,
|
||||||
ADD,
|
ADD,
|
||||||
SUB,
|
SUB,
|
||||||
CMP,
|
CMP,
|
||||||
@ -69,6 +72,13 @@ registers := [8]Register {
|
|||||||
{fullname = "di", bytename = "bh", code = 0b111},
|
{fullname = "di", bytename = "bh", code = 0b111},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
segment_registers := [4]Register {
|
||||||
|
{fullname = "es", code = 0b000},
|
||||||
|
{fullname = "cs", code = 0b001},
|
||||||
|
{fullname = "ss", code = 0b010},
|
||||||
|
{fullname = "ds", code = 0b011},
|
||||||
|
}
|
||||||
|
|
||||||
RegInfo :: struct {
|
RegInfo :: struct {
|
||||||
in_first_byte: bool,
|
in_first_byte: bool,
|
||||||
shift_offset: u8,
|
shift_offset: u8,
|
||||||
@ -82,11 +92,61 @@ OpCodeId :: enum {
|
|||||||
|
|
||||||
LastBit :: struct{}
|
LastBit :: struct{}
|
||||||
FourthBit :: struct{}
|
FourthBit :: struct{}
|
||||||
|
Force :: struct{}
|
||||||
|
|
||||||
WordSize :: union {
|
WordSize :: union {
|
||||||
None,
|
None,
|
||||||
LastBit,
|
LastBit,
|
||||||
FourthBit,
|
FourthBit,
|
||||||
|
Force,
|
||||||
|
}
|
||||||
|
|
||||||
|
None :: struct {}
|
||||||
|
|
||||||
|
Disp8 :: i8
|
||||||
|
Disp16 :: i16
|
||||||
|
Displacement :: union {
|
||||||
|
None,
|
||||||
|
Disp8,
|
||||||
|
Disp16
|
||||||
|
}
|
||||||
|
|
||||||
|
Value8 :: i8
|
||||||
|
Value16 :: i16
|
||||||
|
Data :: union {
|
||||||
|
None,
|
||||||
|
Value8,
|
||||||
|
Value16
|
||||||
|
}
|
||||||
|
|
||||||
|
ModMemory :: struct {}
|
||||||
|
Mod8BitDisp :: i8
|
||||||
|
Mod16BitDisp :: i16
|
||||||
|
ModRegister :: struct {}
|
||||||
|
|
||||||
|
ModMode :: union {
|
||||||
|
ModMemory,
|
||||||
|
Mod8BitDisp,
|
||||||
|
Mod16BitDisp,
|
||||||
|
ModRegister,
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterId :: distinct u8
|
||||||
|
Immediate8 :: distinct i8
|
||||||
|
Immediate16 :: distinct i16
|
||||||
|
MemoryAddr :: struct {
|
||||||
|
addr_id: u8,
|
||||||
|
displacement: Displacement
|
||||||
|
}
|
||||||
|
Accumulator :: distinct i16
|
||||||
|
SegmentRegister :: distinct i8
|
||||||
|
OperandType :: union {
|
||||||
|
RegisterId,
|
||||||
|
Immediate8,
|
||||||
|
Immediate16,
|
||||||
|
MemoryAddr,
|
||||||
|
Accumulator,
|
||||||
|
SegmentRegister,
|
||||||
}
|
}
|
||||||
|
|
||||||
InstructionInfo :: struct {
|
InstructionInfo :: struct {
|
||||||
@ -182,52 +242,6 @@ instructions := [?]InstructionInfo {
|
|||||||
{ opname = .JCXZ, desc = "Jump on not zero", mask = 0b11111111, encoding = 0b11100011, is_jump = true},
|
{ opname = .JCXZ, desc = "Jump on not zero", mask = 0b11111111, encoding = 0b11100011, is_jump = true},
|
||||||
}
|
}
|
||||||
|
|
||||||
None :: struct {}
|
|
||||||
|
|
||||||
Disp8 :: i8
|
|
||||||
Disp16 :: i16
|
|
||||||
Displacement :: union {
|
|
||||||
None,
|
|
||||||
Disp8,
|
|
||||||
Disp16
|
|
||||||
}
|
|
||||||
|
|
||||||
Value8 :: i8
|
|
||||||
Value16 :: i16
|
|
||||||
Data :: union {
|
|
||||||
None,
|
|
||||||
Value8,
|
|
||||||
Value16
|
|
||||||
}
|
|
||||||
|
|
||||||
ModMemory :: struct {}
|
|
||||||
Mod8BitDisp :: i8
|
|
||||||
Mod16BitDisp :: i16
|
|
||||||
ModRegister :: struct {}
|
|
||||||
|
|
||||||
ModMode :: union {
|
|
||||||
ModMemory,
|
|
||||||
Mod8BitDisp,
|
|
||||||
Mod16BitDisp,
|
|
||||||
ModRegister,
|
|
||||||
}
|
|
||||||
|
|
||||||
RegisterId :: distinct u8
|
|
||||||
Immediate8 :: distinct i8
|
|
||||||
Immediate16 :: distinct i16
|
|
||||||
MemoryAddr :: struct {
|
|
||||||
addr_id: u8,
|
|
||||||
displacement: Displacement
|
|
||||||
}
|
|
||||||
Accumulator :: distinct i16
|
|
||||||
OperandType :: union {
|
|
||||||
RegisterId,
|
|
||||||
Immediate8,
|
|
||||||
Immediate16,
|
|
||||||
MemoryAddr,
|
|
||||||
Accumulator,
|
|
||||||
}
|
|
||||||
|
|
||||||
inst_map := make(map[u8]InstructionInfo)
|
inst_map := make(map[u8]InstructionInfo)
|
||||||
RIGHT_ALIGN_AMOUNT := 35
|
RIGHT_ALIGN_AMOUNT := 35
|
||||||
|
|
||||||
@ -352,7 +366,7 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
defer os.close(f)
|
defer os.close(f)
|
||||||
|
|
||||||
data := make([]u8, 512)
|
data := make([]u8, 1024)
|
||||||
bytes_read, err2 := os.read(f, data)
|
bytes_read, err2 := os.read(f, data)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
// ...
|
// ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user