diff options
Diffstat (limited to 'subx/056write.subx')
-rw-r--r-- | subx/056write.subx | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/subx/056write.subx b/subx/056write.subx index cf2c3194..6638b174 100644 --- a/subx/056write.subx +++ b/subx/056write.subx @@ -16,9 +16,9 @@ # data: (array byte) # prefixed by length as usual == code -# instruction effective address operand displacement immediate -# op subop mod rm32 base index scale r32 -# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes +# instruction effective address register displacement immediate +# . op subop mod rm32 base index scale r32 +# . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes # main: e8/call run-tests/disp32 # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'. @@ -31,23 +31,23 @@ write: # f : fd or (address stream), s : (address array byte) -> bytes_written/ # (If we ever leave the Linux kernel behind, it may be better to return # the number of bytes *not* written. Success would then be signaled by # returning 0.) - # prolog + # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # if (f < 0x08000000) _write(f, s), return # f can't be a user-mode address, so treat it as a kernel file descriptor 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 8/disp8 0x08000000/imm32 # compare *(EBP+8) 7d/jump-if-greater-or-equal $write:fake/disp8 - # push args + # . . push args ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0xc/disp8 . # push *(EBP+12) ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 8/disp8 . # push *(EBP+8) - # call + # . . call e8/call _write/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP eb/jump $write:end/disp8 $write:fake: # otherwise, treat 'f' as a stream to append to - # save registers + # . save registers 51/push-ECX 52/push-EDX 53/push-EBX @@ -66,27 +66,27 @@ $write:fake: # push &f->data[f->write] 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 2/index/EDX . 3/r32/EBX 0xc/disp8 . # copy ECX+EDX+12 to EBX 53/push-EBX - # call + # . . call e8/call _append-3/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # f->write += EAX 01/add 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . . # add EAX to *ECX - # restore registers + # . restore registers 5b/pop-to-EBX 5a/pop-to-EDX 59/pop-to-ECX $write:end: - # epilog + # . epilog 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP 5d/pop-to-EBP c3/return clear-stream: # f : (address stream) -> <void> - # prolog + # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # save registers + # . save registers 50/push-EAX 51/push-ECX # EAX = f @@ -112,87 +112,87 @@ $clear-stream:loop: 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 4/imm32 # add to EAX eb/jump $clear-stream:loop/disp8 $clear-stream:end: - # restore registers + # . restore registers 59/pop-to-ECX 58/pop-to-EAX - # epilog + # . epilog 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP 5d/pop-to-EBP c3/return test-write-single: # clear-stream(_test-stream) - # push args + # . . push args 68/push _test-stream/imm32 - # call + # . . call e8/call clear-stream/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # write(_test-stream, "Ab") - # push args + # . . push args 68/push "Ab"/imm32 68/push _test-stream/imm32 - # call + # . . call e8/call write/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # check-ints-equal(EAX, 2) - # push args + # . . push args 68/push "F - test-read-single: return EAX"/imm32 68/push 2/imm32 50/push-EAX - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # check-ints-equal(*_test-stream->data, 41/A 62/b 00 00, msg) - # push args + # . . push args 68/push "F - test-write-single"/imm32 68/push 0x006241/imm32/Ab # push *_test-stream->data b8/copy-to-EAX _test-stream/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 . # push *(EAX+12) - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # end c3/return test-write-appends: # clear-stream(_test-stream) - # push args + # . . push args 68/push _test-stream/imm32 - # call + # . . call e8/call clear-stream/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # write(_test-stream, "C") - # push args + # . . push args 68/push "C"/imm32 68/push _test-stream/imm32 - # call + # . . call e8/call write/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # write(_test-stream, "D") - # push args + # . . push args 68/push "D"/imm32 68/push _test-stream/imm32 - # call + # . . call e8/call write/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # check-ints-equal(*_test-stream->data, 43/C 44/D 00 00, msg) - # push args + # . . push args 68/push "F - test-write-appends"/imm32 68/push 0x00004443/imm32/C-D # push *_test-stream->data b8/copy-to-EAX _test-stream/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 . # push *(EAX+12) - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # end c3/return @@ -209,4 +209,4 @@ _test-stream: # data 00 00 00 00 00 00 00 00 # 8 bytes -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 |