diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-12-28 21:26:42 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-12-28 21:26:42 -0800 |
commit | 431627b242d7f5f2c6b6b13876a255526383f831 (patch) | |
tree | 129b8ec45102e0fa7b6352739f916f94959c887f | |
parent | c2532c2d100ea9cadb63ae506ce2cead753c2130 (diff) | |
download | mu-431627b242d7f5f2c6b6b13876a255526383f831.tar.gz |
4886
-rw-r--r-- | subx/013direct_addressing.cc | 4 | ||||
-rw-r--r-- | subx/015immediate_addressing.cc | 9 | ||||
-rw-r--r-- | subx/031check_operands.cc | 8 | ||||
-rw-r--r-- | subx/053new_segment.subx | 2 | ||||
-rw-r--r-- | subx/055trace.subx | 8 | ||||
-rw-r--r-- | subx/056write.subx | 6 | ||||
-rw-r--r-- | subx/057stop.subx | 2 | ||||
-rw-r--r-- | subx/059read-byte.subx | 2 | ||||
-rw-r--r-- | subx/065error-byte.subx | 2 | ||||
-rw-r--r-- | subx/apps/crenshaw2-1.subx | 4 | ||||
-rw-r--r-- | subx/apps/crenshaw2-1b.subx | 4 | ||||
-rw-r--r-- | subx/apps/hex.subx | 2 | ||||
-rw-r--r-- | subx/examples/ex12.subx | 2 |
13 files changed, 28 insertions, 27 deletions
diff --git a/subx/013direct_addressing.cc b/subx/013direct_addressing.cc index c18b5f5c..3dcd8333 100644 --- a/subx/013direct_addressing.cc +++ b/subx/013direct_addressing.cc @@ -134,7 +134,7 @@ case 0xf7: { } // End Op f7 Subops default: - cerr << "unrecognized sub-opcode after f7: " << NUM(subop) << '\n'; + cerr << "unrecognized subop for opcode f7: " << NUM(subop) << '\n'; exit(1); } break; @@ -250,7 +250,7 @@ case 0xd3: { } // End Op d3 Subops default: - cerr << "unrecognized sub-opcode after d3: " << NUM(subop) << '\n'; + cerr << "unrecognized subop for opcode d3: " << NUM(subop) << '\n'; exit(1); } break; diff --git a/subx/015immediate_addressing.cc b/subx/015immediate_addressing.cc index ce4bc4db..55b4fa37 100644 --- a/subx/015immediate_addressing.cc +++ b/subx/015immediate_addressing.cc @@ -30,7 +30,7 @@ case 0x81: { // combine imm32 with r/m32 break; // End Op 81 Subops default: - cerr << "unrecognized sub-opcode after 81: " << NUM(subop) << '\n'; + cerr << "unrecognized subop for opcode 81: " << NUM(subop) << '\n'; exit(1); } break; @@ -150,7 +150,7 @@ case 0xc1: { } // End Op c1 Subops default: - cerr << "unrecognized sub-opcode after c1: " << NUM(subop) << '\n'; + cerr << "unrecognized subop for opcode c1: " << NUM(subop) << '\n'; exit(1); } break; @@ -614,6 +614,11 @@ put_new(Name, "c7", "copy imm32 to rm32 (mov)"); case 0xc7: { // copy imm32 to r32 const uint8_t modrm = next(); trace(90, "run") << "copy imm32 to r/m32" << end(); + const uint8_t subop = (modrm>>3)&0x7; // middle 3 'reg opcode' bits + if (subop != 0) { + cerr << "unrecognized subop for opcode c7: " << NUM(subop) << " (only 0/copy currently implemented)\n"; + exit(1); + } int32_t* dest = effective_address(modrm); const int32_t src = next32(); trace(90, "run") << "imm32 is 0x" << HEXWORD << src << end(); diff --git a/subx/031check_operands.cc b/subx/031check_operands.cc index f7f931b1..1038bca9 100644 --- a/subx/031check_operands.cc +++ b/subx/031check_operands.cc @@ -229,15 +229,11 @@ void init_permitted_operands() { // 0 1 0 |0 0 1 1 put(Permitted_operands, "c1", 0x23); // combine - //// Class P: op, ModR/M and imm32 - // imm32 imm8 disp32 |disp16 disp8 subop modrm - // 1 0 0 |0 0 0 1 - put(Permitted_operands, "c7", 0x41); // copy - - //// Class Q: op, ModR/M, subop (not r32) and imm32 + //// Class P: op, ModR/M, subop (not r32) and imm32 // imm32 imm8 disp32 |disp16 disp8 subop modrm // 1 0 0 |0 0 1 1 put(Permitted_operands, "81", 0x43); // combine + put(Permitted_operands, "c7", 0x43); // copy // End Init Permitted Operands } diff --git a/subx/053new_segment.subx b/subx/053new_segment.subx index 8d6cdc5f..d88abdc6 100644 --- a/subx/053new_segment.subx +++ b/subx/053new_segment.subx @@ -15,7 +15,7 @@ 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # write to *EAX to check that we have access to the newly-allocated segment - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0x34/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0x34/imm32 # copy to *EAX # syscall(exit, EAX) 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX diff --git a/subx/055trace.subx b/subx/055trace.subx index c19392ad..c420c38a 100644 --- a/subx/055trace.subx +++ b/subx/055trace.subx @@ -63,7 +63,7 @@ initialize-trace-stream: # copy EAX to *Trace-stream 89/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/EAX Trace-stream/disp32 # copy EAX to *Trace-stream # Trace-stream->length = 0x1000/N - 12 - c7 0/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 0xff4/imm32 # copy 0xff4 to *(EAX+8) + c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 0xff4/imm32 # copy 0xff4 to *(EAX+8) c3/return # Append a string to the given trace stream. @@ -149,9 +149,9 @@ clear-trace-stream: # t : (address trace-stream) # ECX = &t->data[t->length] 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX . 1/r32/ECX 0xc/disp8 . # copy EAX+ECX+12 to ECX # t->write = 0 - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX # t->read = 0 - c7/copy 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 0/imm32 # copy to *(EAX+4) + c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 0/imm32 # copy to *(EAX+4) # EAX = t->data 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 0xc/imm32 # add to EAX # while (true) @@ -160,7 +160,7 @@ $clear-trace-stream:loop: 39/compare 3/mod/direct 0/rm32/EAX . . . 1/r32/ECX . . # compare EAX with ECX 7d/jump-if-greater-or-equal $clear-trace-stream:end/disp8 # *EAX = 0 - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX # EAX += 4 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 4/imm32 # add to EAX eb/jump $clear-trace-stream:loop/disp8 diff --git a/subx/056write.subx b/subx/056write.subx index be20387b..3e52b4f2 100644 --- a/subx/056write.subx +++ b/subx/056write.subx @@ -96,9 +96,9 @@ clear-stream: # f : (address stream) -> <void> # ECX = &f->data[f->length] 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX . 1/r32/ECX 0xc/disp8 . # copy EAX+ECX+12 to ECX # f->write = 0 - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX # f->read = 0 - c7/copy 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 0/imm32 # copy to *(EAX+4) + c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 0/imm32 # copy to *(EAX+4) # EAX = f->data 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 0xc/imm32 # add to EAX # while (true) @@ -107,7 +107,7 @@ $clear-stream:loop: 39/compare 3/mod/direct 0/rm32/EAX . . . 1/r32/ECX . . # compare EAX with ECX 7d/jump-if-greater-or-equal $clear-stream:end/disp8 # *EAX = 0 - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX # EAX += 4 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 4/imm32 # add to EAX eb/jump $clear-stream:loop/disp8 diff --git a/subx/057stop.subx b/subx/057stop.subx index 3f165920..b1aee746 100644 --- a/subx/057stop.subx +++ b/subx/057stop.subx @@ -86,7 +86,7 @@ tailor-exit-descriptor: # ed : (address exit-descriptor), nbytes : int -> <void 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 1/r32/ECX 8/disp8 . # copy *(EBP+8) to ECX 89/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . . # copy EAX to *ECX # initialize ed->value - c7/copy 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 0/imm32 # copy to *(ECX+4) + c7 0/subop/copy 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 0/imm32 # copy to *(ECX+4) $tailor-exit-descriptor:end: # . restore registers 59/pop-to-ECX diff --git a/subx/059read-byte.subx b/subx/059read-byte.subx index b280a3b1..e4b54b61 100644 --- a/subx/059read-byte.subx +++ b/subx/059read-byte.subx @@ -264,7 +264,7 @@ test-read-byte-refills-buffer: # pretend buffer is full # . _test-buffered-file->read = 6 # >= _test-buffered-file->length b8/copy-to-EAX _test-buffered-file/imm32 - c7/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 6/imm32 # copy to *(EAX+8) + c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 6/imm32 # copy to *(EAX+8) # read-byte(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 diff --git a/subx/065error-byte.subx b/subx/065error-byte.subx index d945e5a5..bbbf6c36 100644 --- a/subx/065error-byte.subx +++ b/subx/065error-byte.subx @@ -12,7 +12,7 @@ #? 89/copy 3/mod/direct 0/rm32/EAX . . . 4/r32/ESP . . # copy ESP to EAX #? # . configure ed to really exit() #? # . . ed->target = 0 -#? c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX +#? c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX #? # . error-byte(ed, Stdout, msg, 34) #? 68/push 0x34/imm32 #? 68/push "abc"/imm32 diff --git a/subx/apps/crenshaw2-1.subx b/subx/apps/crenshaw2-1.subx index abb9c9c2..e0ab0f47 100644 --- a/subx/apps/crenshaw2-1.subx +++ b/subx/apps/crenshaw2-1.subx @@ -63,7 +63,7 @@ $run-main: 89/copy 3/mod/direct 0/rm32/EAX . . . 4/r32/ESP . . # copy ESP to EAX # configure ed to really exit() # . ed->target = 0 - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX # return compile(Stdin, 1/stdout, 2/stderr, ed) # . . push args 50/push-EAX/ed @@ -105,7 +105,7 @@ compile: # in : (address buffered-file), out : fd or (address stream), err : fd 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX # initialize the stream # . num->length = 7 - c7/copy 1/mod/*+disp8 1/rm32/ECX . . . . 8/disp8 7/imm32 # copy to *(ECX+8) + c7 0/subop/copy 1/mod/*+disp8 1/rm32/ECX . . . . 8/disp8 7/imm32 # copy to *(ECX+8) # . clear-stream(num) # . . push args 51/push-ECX diff --git a/subx/apps/crenshaw2-1b.subx b/subx/apps/crenshaw2-1b.subx index 23aa9c63..268e6400 100644 --- a/subx/apps/crenshaw2-1b.subx +++ b/subx/apps/crenshaw2-1b.subx @@ -63,7 +63,7 @@ $run-main: 89/copy 3/mod/direct 0/rm32/EAX . . . 4/r32/ESP . . # copy ESP to EAX # configure ed to really exit() # . ed->target = 0 - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX # return compile(Stdin, 1/stdout, 2/stderr, ed) # . . push args 50/push-EAX/ed @@ -105,7 +105,7 @@ compile: # in : (address buffered-file), out : fd or (address stream), err : fd 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX # initialize the stream # . num->length = 7 - c7/copy 1/mod/*+disp8 1/rm32/ECX . . . . 8/disp8 7/imm32 # copy to *(ECX+8) + c7 0/subop/copy 1/mod/*+disp8 1/rm32/ECX . . . . 8/disp8 7/imm32 # copy to *(ECX+8) # . clear-stream(num) # . . push args 51/push-ECX diff --git a/subx/apps/hex.subx b/subx/apps/hex.subx index c544a27c..032c1da7 100644 --- a/subx/apps/hex.subx +++ b/subx/apps/hex.subx @@ -57,7 +57,7 @@ $run-main: 89/copy 3/mod/direct 0/rm32/EAX . . . 4/r32/ESP . . # copy ESP to EAX # configure ed to really exit() # . ed->target = 0 - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32 # copy to *EAX # return convert(Stdin, 1/stdout, 2/stderr, ed) # . . push args 50/push-EAX/ed diff --git a/subx/examples/ex12.subx b/subx/examples/ex12.subx index 6d17a39f..872cc53e 100644 --- a/subx/examples/ex12.subx +++ b/subx/examples/ex12.subx @@ -17,7 +17,7 @@ cd/syscall 0x80/imm8 # write to *EAX to check that we have access to the newly-allocated segment - c7/copy 0/mod/direct 0/rm32/EAX . . . . . 0x34/imm32 # copy to *EAX + c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0x34/imm32 # copy to *EAX # syscall(exit, EAX) 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX |