139 lines
2.2 KiB
Odin
139 lines
2.2 KiB
Odin
package sim_8086
|
|
|
|
Register :: struct {
|
|
fullname: string,
|
|
value: struct #raw_union {
|
|
using _: struct {
|
|
low, high: byte,
|
|
},
|
|
full: u16,
|
|
},
|
|
code: u8,
|
|
}
|
|
|
|
Flags :: struct {
|
|
ZF: bool,
|
|
SF: bool,
|
|
}
|
|
|
|
WordSize :: enum {
|
|
None,
|
|
LastBit,
|
|
FourthBit,
|
|
Always8,
|
|
Always16,
|
|
}
|
|
|
|
None :: struct {}
|
|
Disp8 :: i8
|
|
Disp16 :: i16
|
|
Displacement :: union {
|
|
None,
|
|
Disp8,
|
|
Disp16
|
|
}
|
|
|
|
RegisterAccess :: enum {
|
|
Low,
|
|
High,
|
|
Full,
|
|
}
|
|
|
|
RegisterId :: struct {
|
|
access: RegisterAccess,
|
|
id: int,
|
|
}
|
|
ImmediateSize :: enum {
|
|
Signed8,
|
|
Unsigned8,
|
|
Signed16,
|
|
}
|
|
Immediate :: struct {
|
|
value: u16,
|
|
size: ImmediateSize,
|
|
}
|
|
MemoryAddr :: struct {
|
|
addr_id: u8,
|
|
displacement: Displacement,
|
|
}
|
|
DirectAddress :: distinct i16
|
|
Jump :: distinct i8
|
|
Repeat :: string
|
|
Intersegment :: struct {
|
|
ip: i16,
|
|
cs: i16,
|
|
}
|
|
|
|
Operand :: union {
|
|
None,
|
|
RegisterId,
|
|
Immediate,
|
|
MemoryAddr,
|
|
DirectAddress,
|
|
Jump,
|
|
Repeat,
|
|
Intersegment,
|
|
}
|
|
|
|
OperandInfo :: enum {
|
|
None,
|
|
Register,
|
|
SegmentRegister,
|
|
RegisterMemory,
|
|
Immediate,
|
|
ImmediateUnsigned,
|
|
Accumulator,
|
|
DirectAddress,
|
|
Jump,
|
|
VariablePort,
|
|
ShiftRotate,
|
|
Repeat,
|
|
DirectWithinSegment,
|
|
Intersegment,
|
|
}
|
|
|
|
RegisterEncodingBits :: enum {
|
|
None,
|
|
FirstByteLast3,
|
|
SecondByteMiddle3,
|
|
SecondByteLast3,
|
|
FirstByteMiddle3,
|
|
}
|
|
|
|
InstructionInfo :: struct {
|
|
mask: u8,
|
|
encoding: u8,
|
|
opname: Op,
|
|
desc: string,
|
|
src: OperandInfo,
|
|
dst: OperandInfo,
|
|
word_size: WordSize,
|
|
reg_info: RegisterEncodingBits,
|
|
has_flip: bool,
|
|
has_sign_extension: bool,
|
|
check_second_encoding: bool,
|
|
consume_extra_bytes: int,
|
|
shift_rotate_flag: bool,
|
|
}
|
|
|
|
Instruction :: struct {
|
|
opname: Op,
|
|
src: Operand,
|
|
dst: Operand,
|
|
info: InstructionInfo,
|
|
is_word: bool,
|
|
indirect_intersegment: bool,
|
|
// TODO: This is trickier than I thought, it's more than just the one instruction
|
|
// that uses it
|
|
has_segment: Maybe(Register),
|
|
has_lock: bool,
|
|
bytes_read: int,
|
|
raw_data: []u8,
|
|
debug_msg: string,
|
|
}
|
|
|
|
Cpu :: struct {
|
|
flags: Flags,
|
|
memory: [dynamic]u8,
|
|
}
|