about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-21 21:17:01 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-21 22:15:55 -0700
commit5af1b6a46a2ac919dbe56274dfcb754e4f56c43f (patch)
tree3d584f58fca5db4ba7224e407d8cd74f63a351d8
parent82a24dfc1fabc29d553de1e7be4c946a4ab7c459 (diff)
downloadmu-5af1b6a46a2ac919dbe56274dfcb754e4f56c43f.tar.gz
4385 - online help on addressing modes
-rw-r--r--subx/010vm.cc2
-rw-r--r--subx/022check_instruction.cc86
2 files changed, 87 insertions, 1 deletions
diff --git a/subx/010vm.cc b/subx/010vm.cc
index 799bcbcc..81a8c12b 100644
--- a/subx/010vm.cc
+++ b/subx/010vm.cc
@@ -206,7 +206,7 @@ if (key == "opcodes") {
     cerr << "  f3 " << HEXBYTE << NUM(p->first) << ": " << p->second << '\n';
   for (map<uint8_t, string>::iterator p = name_f3_0f.begin();  p != name_f3_0f.end();  ++p)
     cerr << "  f3 0f " << HEXBYTE << NUM(p->first) << ": " << p->second << '\n';
-  cerr << "Coming soon: `subx help operands` for details on words like 'r32' and 'disp8'.\n";
+  cerr << "Run `subx help instructions` for details on words like 'r32' and 'disp8'.\n";
   return 0;
 }
 :(before "End Help Contents")
diff --git a/subx/022check_instruction.cc b/subx/022check_instruction.cc
new file mode 100644
index 00000000..599638bf
--- /dev/null
+++ b/subx/022check_instruction.cc
@@ -0,0 +1,86 @@
+//: Catch instructions with the wrong size or type (metadata) of operands.
+
+:(before "End Help Texts")
+put(Help, "instructions",
+  "Each x86 instruction consists of an instruction or opcode and some number of operands.\n"
+  "Each operand has a type. An instruction won't have more than one of any type.\n"
+  "Each instruction has some set of allowed operand types. It'll reject others.\n"
+  "The complete list of operand types: mod, subop, r32 (register), rm32 (register or memory), scale, index, base, disp8, disp16, disp32, imm8, imm32.\n"
+  "Each of these has its own help page. Try reading 'subx help mod' next.\n"
+);
+:(before "End Help Contents")
+cerr << "  instructions\n";
+
+//:: docs on each operand type
+
+:(before "End Help Texts")
+init_operand_type_help();
+:(code)
+void init_operand_type_help() {
+  put(Help, "mod",
+    "2-bit operand controlling the _addressing mode_ of many instructions,\n"
+    "to determine how to compute the _effective address_ to look up memory at\n"
+    "based on the 'rm32' operand and potentially others.\n"
+    "\n"
+    "If mod = 3, just operate on the contents of the register specified by rm32 (direct mode).\n"
+    "If mod = 2, effective address is usually* rm32 + disp32 (indirect mode with displacement).\n"
+    "If mod = 1, effective address is usually* rm32 + disp8 (indirect mode with displacement).\n"
+    "If mod = 0, effective address is usually* rm32 (indirect mode).\n"
+    "(* - The exception is when rm32 is '4'. Register 4 is the stack pointer (ESP). Using it as an address gets more involved.\n"
+    "     For more details, try reading the help pages for 'base', 'index' and 'scale'.)\n"
+    "\n"
+    "For complete details consult the IA-32 software developer's manual, table 2-2,\n"
+    "\"32-bit addressing forms with the ModR/M byte\".\n"
+    "  https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf\n"
+  );
+  put(Help, "subop",
+    "Additional 3-bit operand for determining the instruction when the opcode is 81, 8f or ff.\n"
+    "Can't coexist with operand of type 'r32' in a single instruction, because the two use the same bits.\n"
+  );
+  put(Help, "r32",
+    "3-bit operand specifying a register operand used directly, without any further addressing modes.\n"
+  );
+  put(Help, "rm32",
+    "3-bit operand specifying a register operand whose precise interpretation interacts with 'mod'.\n"
+    "For complete details consult the IA-32 software developer's manual, table 2-2,\n"
+    "\"32-bit addressing forms with the ModR/M byte\".\n"
+    "  https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf\n"
+  );
+  put(Help, "base",
+    "Additional 3-bit operand (when 'rm32' is 4 unless 'mod' is 3) specifying the register containing an address to look up.\n"
+    "This address may be further modified by 'index' and 'scale' operands.\n"
+    "  effective address = base + index*scale + displacement (disp8 or disp32)\n"
+    "For complete details consult the IA-32 software developer's manual, table 2-3,\n"
+    "\"32-bit addressing forms with the SIB byte\".\n"
+    "  https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf\n"
+  );
+  put(Help, "index",
+    "Optional 3-bit operand (when 'rm32' is 4 unless 'mod' is 3) that can be added to the 'base' operand to compute the 'effective address' at which to look up memory.\n"
+    "  effective address = base + index*scale + displacement (disp8 or disp32)\n"
+    "For complete details consult the IA-32 software developer's manual, table 2-3,\n"
+    "\"32-bit addressing forms with the SIB byte\".\n"
+    "  https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf\n"
+  );
+  put(Help, "scale",
+    "Optional 2-bit operand (when 'rm32' is 4 unless 'mod' is 3) that can be multiplied to the 'index' operand before adding the result to the 'base' operand to compute the _effective address_ to operate on.\n"
+    "  effective address = base + index * scale + displacement (disp8 or disp32)\n"
+    "For complete details consult the IA-32 software developer's manual, table 2-3,\n"
+    "\"32-bit addressing forms with the SIB byte\".\n"
+    "  https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf\n"
+  );
+  put(Help, "disp8",
+    "8-bit value to be added in many instructions.\n"
+  );
+  put(Help, "disp16",
+    "16-bit value to be added in many instructions.\n"
+  );
+  put(Help, "disp32",
+    "32-bit value to be added in many instructions.\n"
+  );
+  put(Help, "imm8",
+    "8-bit value for many instructions.\n"
+  );
+  put(Help, "imm32",
+    "32-bit value for many instructions.\n"
+  );
+}
>
672e3e50 ^

4fe9f5e8 ^
76755b28 ^

4690ce81 ^
a654e4ec ^
672e3e50 ^
2f02189d ^
76755b28 ^
672e3e50 ^
2f02189d ^
76755b28 ^
672e3e50 ^

a654e4ec ^









672e3e50 ^

4690ce81 ^
db1f56c8 ^


4690ce81 ^

a654e4ec ^
672e3e50 ^
a654e4ec ^
672e3e50 ^
a654e4ec ^
db1f56c8 ^
76755b28 ^
672e3e50 ^
a654e4ec ^
4690ce81 ^




2f02189d ^
4690ce81 ^
a654e4ec ^
4690ce81 ^

4698dc00 ^





4690ce81 ^

2f02189d ^
4690ce81 ^
672e3e50 ^

a654e4ec ^
4690ce81 ^




76755b28 ^
65361948 ^

672e3e50 ^
a654e4ec ^
4690ce81 ^

4698dc00 ^





4690ce81 ^

2f02189d ^
4690ce81 ^

672e3e50 ^

4690ce81 ^

65361948 ^

4690ce81 ^

b2566a84 ^
2f02189d ^
9542bb11 ^

4690ce81 ^

b2566a84 ^
4690ce81 ^
65361948 ^
672e3e50 ^

a654e4ec ^
76755b28 ^
672e3e50 ^

a654e4ec ^
672e3e50 ^


a654e4ec ^
d009e158 ^
4690ce81 ^
32b8fac2 ^
76755b28 ^
672e3e50 ^
672e3e50 ^


4690ce81 ^

a654e4ec ^
4690ce81 ^
2f02189d ^
672e3e50 ^


4690ce81 ^



c5ffb6e1 ^
65361948 ^

4690ce81 ^



c5ffb6e1 ^
65361948 ^

4690ce81 ^


c5ffb6e1 ^
65361948 ^


32b8fac2 ^

















9570363a ^
672e3e50 ^
4690ce81 ^
9570363a ^
672e3e50 ^



672e3e50 ^
4fe9f5e8 ^
9570363a ^
76755b28 ^
4690ce81 ^
a654e4ec ^
672e3e50 ^

76755b28 ^
672e3e50 ^
4fe9f5e8 ^
76755b28 ^

4690ce81 ^
a654e4ec ^
65361948 ^
76755b28 ^
65361948 ^
76755b28 ^

4690ce81 ^
a654e4ec ^
65361948 ^

76755b28 ^
65361948 ^
76755b28 ^
4690ce81 ^
a654e4ec ^
65361948 ^
76755b28 ^

65361948 ^
76755b28 ^
4690ce81 ^
a654e4ec ^
65361948 ^
76755b28 ^

65361948 ^
32b8fac2 ^

672e3e50 ^
9570363a ^
4690ce81 ^
a654e4ec ^


672e3e50 ^



76755b28 ^
672e3e50 ^
32b8fac2 ^





4690ce81 ^
32b8fac2 ^
4690ce81 ^
62a52ffb ^
a654e4ec ^

32b8fac2 ^
4690ce81 ^
db1f56c8 ^


62a52ffb ^
672e3e50 ^



9570363a ^
4690ce81 ^
a654e4ec ^

672e3e50 ^






9570363a ^
4690ce81 ^
9570363a ^


32b8fac2 ^
672e3e50 ^
65361948 ^
2f02189d ^
32b8fac2 ^

672e3e50 ^
76755b28 ^
672e3e50 ^
4690ce81 ^

a654e4ec ^
9542bb11 ^

dbe12410 ^
4690ce81 ^
62a52ffb ^
a654e4ec ^


4690ce81 ^
db1f56c8 ^


62a52ffb ^
672e3e50 ^



a654e4ec ^
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347