diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-03-12 18:56:55 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-03-12 19:14:12 -0700 |
commit | 4a943d4ed313eff001504c2b5c472266e86a38af (patch) | |
tree | a5757233a8c81b303a808f251180c7344071ed51 /subx/017jump_disp8.cc | |
parent | 43711b0e9f18e0225ce14687fb6ea0902aa6fc61 (diff) | |
download | mu-4a943d4ed313eff001504c2b5c472266e86a38af.tar.gz |
5001 - drop the :(scenario) DSL
I've been saying for a while[1][2][3] that adding extra abstractions makes things harder for newcomers, and adding new notations doubly so. And then I notice this DSL in my own backyard. Makes me feel like a hypocrite. [1] https://news.ycombinator.com/item?id=13565743#13570092 [2] https://lobste.rs/s/to8wpr/configuration_files_are_canary_warning [3] https://lobste.rs/s/mdmcdi/little_languages_by_jon_bentley_1986#c_3miuf2 The implementation of the DSL was also highly hacky: a) It was happening in the tangle/ tool, but was utterly unrelated to tangling layers. b) There were several persnickety constraints on the different kinds of lines and the specific order they were expected in. I kept finding bugs where the translator would silently do the wrong thing. Or the error messages sucked, and readers may be stuck looking at the generated code to figure out what happened. Fixing error messages would require a lot more code, which is one of my arguments against DSLs in the first place: they may be easy to implement, but they're hard to design to go with the grain of the underlying platform. They require lots of iteration. Is that effort worth prioritizing in this project? On the other hand, the DSL did make at least some readers' life easier, the ones who weren't immediately put off by having to learn a strange syntax. There were fewer quotes to parse, fewer backslash escapes. Anyway, since there are also people who dislike having to put up with strange syntaxes, we'll call that consideration a wash and tear this DSL out. --- This commit was sheer drudgery. Hopefully it won't need to be redone with a new DSL because I grow sick of backslashes.
Diffstat (limited to 'subx/017jump_disp8.cc')
-rw-r--r-- | subx/017jump_disp8.cc | 424 |
1 files changed, 254 insertions, 170 deletions
diff --git a/subx/017jump_disp8.cc b/subx/017jump_disp8.cc index 24467f5c..22ae6567 100644 --- a/subx/017jump_disp8.cc +++ b/subx/017jump_disp8.cc @@ -5,16 +5,22 @@ :(before "End Initialize Op Names") put_new(Name, "eb", "jump disp8 bytes away (jmp)"); -:(scenario jump_rel8) -== 0x1 -# op ModR/M SIB displacement immediate - eb 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: eb -+run: jump 5 -+run: 0x00000008 opcode: 05 --run: 0x00000003 opcode: 05 +:(code) +void test_jump_rel8() { + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " eb 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: eb\n" + "run: jump 5\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05"); +} :(before "End Single-Byte Opcodes") case 0xeb: { // jump rel8 @@ -29,17 +35,23 @@ case 0xeb: { // jump rel8 :(before "End Initialize Op Names") put_new(Name, "74", "jump disp8 bytes away if equal, if ZF is set (jcc/jz/je)"); -:(scenario je_rel8_success) -% ZF = true; -== 0x1 -# op ModR/M SIB displacement immediate - 74 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 74 -+run: jump 5 -+run: 0x00000008 opcode: 05 --run: 0x00000003 opcode: 05 +:(code) +void test_je_rel8_success() { + ZF = true; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 74 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 74\n" + "run: jump 5\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05"); +} :(before "End Single-Byte Opcodes") case 0x74: { // jump rel8 if ZF @@ -51,34 +63,46 @@ case 0x74: { // jump rel8 if ZF break; } -:(scenario je_rel8_fail) -% ZF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 74 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 74 -+run: 0x00000003 opcode: 05 -+run: 0x00000008 opcode: 05 --run: jump 5 +:(code) +void test_je_rel8_fail() { + ZF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 74 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 74\n" + "run: 0x00000003 opcode: 05\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: jump 5"); +} //:: jump if not equal/not zero :(before "End Initialize Op Names") put_new(Name, "75", "jump disp8 bytes away if not equal, if ZF is not set (jcc/jnz/jne)"); -:(scenario jne_rel8_success) -% ZF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 75 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 75 -+run: jump 5 -+run: 0x00000008 opcode: 05 --run: 0x00000003 opcode: 05 +:(code) +void test_jne_rel8_success() { + ZF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 75 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 75\n" + "run: jump 5\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05"); +} :(before "End Single-Byte Opcodes") case 0x75: { // jump rel8 unless ZF @@ -90,36 +114,48 @@ case 0x75: { // jump rel8 unless ZF break; } -:(scenario jne_rel8_fail) -% ZF = true; -== 0x1 -# op ModR/M SIB displacement immediate - 75 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 75 -+run: 0x00000003 opcode: 05 -+run: 0x00000008 opcode: 05 --run: jump 5 +:(code) +void test_jne_rel8_fail() { + ZF = true; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 75 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 75\n" + "run: 0x00000003 opcode: 05\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: jump 5"); +} //:: jump if greater :(before "End Initialize Op Names") put_new(Name, "7f", "jump disp8 bytes away if greater, if ZF is unset and SF == OF (jcc/jg/jnle)"); -:(scenario jg_rel8_success) -% ZF = false; -% SF = false; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7f 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7f -+run: jump 5 -+run: 0x00000008 opcode: 05 --run: 0x00000003 opcode: 05 +:(code) +void test_jg_rel8_success() { + ZF = false; + SF = false; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7f 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7f\n" + "run: jump 5\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05"); +} :(before "End Single-Byte Opcodes") case 0x7f: { // jump rel8 if !SF and !ZF @@ -131,37 +167,49 @@ case 0x7f: { // jump rel8 if !SF and !ZF break; } -:(scenario jg_rel8_fail) -% ZF = false; -% SF = true; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7f 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7f -+run: 0x00000003 opcode: 05 -+run: 0x00000008 opcode: 05 --run: jump 5 +:(code) +void test_jg_rel8_fail() { + ZF = false; + SF = true; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7f 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7f\n" + "run: 0x00000003 opcode: 05\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: jump 5"); +} //:: jump if greater or equal :(before "End Initialize Op Names") put_new(Name, "7d", "jump disp8 bytes away if greater or equal, if SF == OF (jcc/jge/jnl)"); -:(scenario jge_rel8_success) -% SF = false; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7d 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7d -+run: jump 5 -+run: 0x00000008 opcode: 05 --run: 0x00000003 opcode: 05 +:(code) +void test_jge_rel8_success() { + SF = false; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7d 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7d\n" + "run: jump 5\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05"); +} :(before "End Single-Byte Opcodes") case 0x7d: { // jump rel8 if !SF @@ -173,37 +221,49 @@ case 0x7d: { // jump rel8 if !SF break; } -:(scenario jge_rel8_fail) -% SF = true; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7d 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7d -+run: 0x00000003 opcode: 05 -+run: 0x00000008 opcode: 05 --run: jump 5 +:(code) +void test_jge_rel8_fail() { + SF = true; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7d 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7d\n" + "run: 0x00000003 opcode: 05\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: jump 5"); +} //:: jump if lesser :(before "End Initialize Op Names") put_new(Name, "7c", "jump disp8 bytes away if lesser, if SF != OF (jcc/jl/jnge)"); -:(scenario jl_rel8_success) -% ZF = false; -% SF = true; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7c 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7c -+run: jump 5 -+run: 0x00000008 opcode: 05 --run: 0x00000003 opcode: 05 +:(code) +void test_jl_rel8_success() { + ZF = false; + SF = true; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7c 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7c\n" + "run: jump 5\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05"); +} :(before "End Single-Byte Opcodes") case 0x7c: { // jump rel8 if SF and !ZF @@ -215,52 +275,70 @@ case 0x7c: { // jump rel8 if SF and !ZF break; } -:(scenario jl_rel8_fail) -% ZF = false; -% SF = false; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7c 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7c -+run: 0x00000003 opcode: 05 -+run: 0x00000008 opcode: 05 --run: jump 5 +:(code) +void test_jl_rel8_fail() { + ZF = false; + SF = false; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7c 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7c\n" + "run: 0x00000003 opcode: 05\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: jump 5"); +} //:: jump if lesser or equal :(before "End Initialize Op Names") put_new(Name, "7e", "jump disp8 bytes away if lesser or equal, if ZF is set or SF != OF (jcc/jle/jng)"); -:(scenario jle_rel8_equal) -% ZF = true; -% SF = false; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7e 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7e -+run: jump 5 -+run: 0x00000008 opcode: 05 --run: 0x00000003 opcode: 05 - -:(scenario jle_rel8_lesser) -% ZF = false; -% SF = true; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7e 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7e -+run: jump 5 -+run: 0x00000008 opcode: 05 --run: 0x00000003 opcode: 05 +:(code) +void test_jle_rel8_equal() { + ZF = true; + SF = false; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7e 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7e\n" + "run: jump 5\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05"); +} + +:(code) +void test_jle_rel8_lesser() { + ZF = false; + SF = true; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7e 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7e\n" + "run: jump 5\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05"); +} :(before "End Single-Byte Opcodes") case 0x7e: { // jump rel8 if SF or ZF @@ -272,16 +350,22 @@ case 0x7e: { // jump rel8 if SF or ZF break; } -:(scenario jle_rel8_greater) -% ZF = false; -% SF = false; -% OF = false; -== 0x1 -# op ModR/M SIB displacement immediate - 7e 05 # skip 1 instruction - 05 00 00 00 01 - 05 00 00 00 02 -+run: 0x00000001 opcode: 7e -+run: 0x00000003 opcode: 05 -+run: 0x00000008 opcode: 05 --run: jump 5 +:(code) +void test_jle_rel8_greater() { + ZF = false; + SF = false; + OF = false; + run( + "== 0x1\n" // code segment + // op ModR/M SIB displacement immediate + " 7e 05 \n" // skip 1 instruction + " 05 00 00 00 01 \n" + " 05 00 00 00 02 \n" + ); + CHECK_TRACE_CONTENTS( + "run: 0x00000001 opcode: 7e\n" + "run: 0x00000003 opcode: 05\n" + "run: 0x00000008 opcode: 05\n" + ); + CHECK_TRACE_DOESNT_CONTAIN("run: jump 5"); +} |