summaryrefslogtreecommitdiff
path: root/src/code/reference_decoder/sim86_instruction.h
blob: 191635a35bb42703029fb633be2a64eee22d49c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* ========================================================================

   (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
   
   This software is provided 'as-is', without any express or implied
   warranty. In no event will the authors be held liable for any damages
   arising from the use of this software.
   
   Please see https://computerenhance.com for more information
   
   ======================================================================== */

typedef u32 register_index;

// NOTE(casey): To make it easier to compile with languages which do not
// have auto-typedef'ing (like C, etc.), all types are manually typedef'd here.
typedef struct register_access register_access;
typedef struct effective_address_term effective_address_term;
typedef struct effective_address_expression effective_address_expression;
typedef struct immediate immediate;
typedef struct instruction_operand instruction_operand;
typedef struct instruction instruction;

typedef enum operation_type : u32
{
    Op_None,
    
#define INST(Mnemonic, ...) Op_##Mnemonic,
#define INSTALT(...)
#include "sim86_instruction_table.inl"
    
    Op_Count,
} operation_type;

enum instruction_flag
{
    Inst_Lock = 0x1,
    Inst_Rep = 0x2,
    Inst_Segment = 0x4,
    Inst_Wide = 0x8,
    Inst_Far = 0x10,
    Inst_RepNE = 0x20, // NOTE(casey): For user convenience, this will be set _in addition to_ Inst_Rep for REPNE/REPNZ
};

struct register_access
{
    register_index Index;
    u32 Offset;
    u32 Count;
};

struct effective_address_term
{
    register_access Register;
    s32 Scale;
};

enum effective_address_flag
{
    Address_ExplicitSegment = 0x1,
};
struct effective_address_expression
{
    effective_address_term Terms[2];
    u32 ExplicitSegment;
    s32 Displacement;
    u32 Flags;
};

enum immediate_flag
{
    Immediate_RelativeJumpDisplacement = 0x1,
};
struct immediate
{
    s32 Value;
    u32 Flags;
};

typedef enum operand_type : u32
{
    Operand_None,
    Operand_Register,
    Operand_Memory,
    Operand_Immediate,
} operand_type;
struct instruction_operand
{
    operand_type Type;
    union
    {
        effective_address_expression Address;
        register_access Register;
        immediate Immediate;
    };
};

struct instruction
{
    u32 Address;
    u32 Size;
    
    operation_type Op;
    u32 Flags;
    
    instruction_operand Operands[2];
    
    register_index SegmentOverride;
};