cleanup in compute-offset and fix bug in compute-width
This commit is contained in:
parent
9ac5834194
commit
b95060262e
|
@ -1142,47 +1142,38 @@ compute-width: # word : (address array byte)
|
||||||
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
|
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
|
||||||
# . save registers
|
# . save registers
|
||||||
51/push-ECX
|
51/push-ECX
|
||||||
|
|
||||||
# EAX = word
|
# EAX = word
|
||||||
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 8/disp8 . # copy *(EBP+8) to ECX
|
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 8/disp8 . # copy *(EBP+8) to ECX
|
||||||
|
|
||||||
# ECX = word + word->length
|
# ECX = word + word->length
|
||||||
8b/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . . # copy *EAX to ECX
|
8b/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . . # copy *EAX to ECX
|
||||||
8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX . 1/r32/ECX 4/disp8 . # copy EAX+ECX+4 to ECX
|
8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX . 1/r32/ECX 4/disp8 . # copy EAX+ECX+4 to ECX
|
||||||
# EAX = word->data
|
# EAX = word->data
|
||||||
05/add-to-EAX 4/imm32
|
05/add-to-EAX 4/imm32
|
||||||
|
|
||||||
# var in/ECX : (address slice) = {EAX, ECX}
|
# var in/ECX : (address slice) = {EAX, ECX}
|
||||||
51/push-ECX
|
51/push-ECX
|
||||||
50/push-EAX
|
50/push-EAX
|
||||||
89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX
|
89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX
|
||||||
|
|
||||||
# if has-metadata?(word, "imm32") or has-metadata?(word, "disp32"): return 4
|
# if has-metadata?(word, "imm32") or has-metadata?(word, "disp32"): return 4
|
||||||
# . has-metadata?(word, "imm32")
|
# . has-metadata?(word, "imm32")
|
||||||
68/push "imm32"/imm32
|
68/push "imm32"/imm32
|
||||||
51/push-ECX
|
51/push-ECX
|
||||||
|
|
||||||
e8/call has-metadata?/disp32
|
e8/call has-metadata?/disp32
|
||||||
# . . discard args
|
# . . discard args
|
||||||
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
||||||
|
|
||||||
# . if EAX: return 4
|
# . if EAX: return 4
|
||||||
3d/compare-EAX-and 1/imm32
|
3d/compare-EAX-and 1/imm32
|
||||||
b8/copy-to-EAX 4/imm32 # ZF is set, so we can overwrite EAX now
|
b8/copy-to-EAX 4/imm32 # ZF is set, so we can overwrite EAX now
|
||||||
74/jump-if-equal $compute-width:end/disp8
|
74/jump-if-equal $compute-width:end/disp8
|
||||||
|
|
||||||
# . has-metadata?(word, "disp32")
|
# . has-metadata?(word, "disp32")
|
||||||
68/push "disp32"/imm32
|
68/push "disp32"/imm32
|
||||||
51/push-ECX
|
51/push-ECX
|
||||||
e8/call has-metadata?/disp32
|
e8/call has-metadata?/disp32
|
||||||
# . . discard args
|
# . . discard args
|
||||||
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
||||||
|
|
||||||
# . if EAX: return 4
|
# . if EAX: return 4
|
||||||
3d/compare-EAX-and 1/imm32
|
3d/compare-EAX-and 1/imm32
|
||||||
b8/copy-to-EAX 4/imm32 # ZF is set, so we can overwrite EAX now
|
b8/copy-to-EAX 4/imm32 # ZF is set, so we can overwrite EAX now
|
||||||
74/jump-if-equal $compute-width:end/disp8
|
74/jump-if-equal $compute-width:end/disp8
|
||||||
|
|
||||||
# if has-metadata?(word, "imm16") or has-metadata?(word, "disp16"): return 2
|
# if has-metadata?(word, "imm16") or has-metadata?(word, "disp16"): return 2
|
||||||
# . has-metadata?(word, "imm16")
|
# . has-metadata?(word, "imm16")
|
||||||
68/push "imm16"/imm32
|
68/push "imm16"/imm32
|
||||||
|
@ -1190,31 +1181,27 @@ compute-width: # word : (address array byte)
|
||||||
e8/call has-metadata?/disp32
|
e8/call has-metadata?/disp32
|
||||||
# . . discard args
|
# . . discard args
|
||||||
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
||||||
|
|
||||||
# . if EAX: return 2
|
# . if EAX: return 2
|
||||||
3d/compare-EAX-and 1/imm32
|
3d/compare-EAX-and 1/imm32
|
||||||
b8/copy-to-EAX 2/imm32 # ZF is set, so we can overwrite EAX now
|
b8/copy-to-EAX 2/imm32 # ZF is set, so we can overwrite EAX now
|
||||||
74/jump-if-equal $compute-width:end/disp8
|
74/jump-if-equal $compute-width:end/disp8
|
||||||
|
|
||||||
# . has-metadata?(word, "disp16")
|
# . has-metadata?(word, "disp16")
|
||||||
68/push "disp16"/imm32
|
68/push "disp16"/imm32
|
||||||
51/push-ECX
|
51/push-ECX
|
||||||
e8/call has-metadata?/disp32
|
e8/call has-metadata?/disp32
|
||||||
# . . discard args
|
# . . discard args
|
||||||
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
||||||
|
|
||||||
# . if EAX: return 2
|
# . if EAX: return 2
|
||||||
3d/compare-EAX-and 1/imm32
|
3d/compare-EAX-and 1/imm32
|
||||||
b8/copy-to-EAX 2/imm32 # ZF is set, so we can overwrite EAX now
|
b8/copy-to-EAX 2/imm32 # ZF is set, so we can overwrite EAX now
|
||||||
74/jump-if-equal $compute-width:end/disp8
|
74/jump-if-equal $compute-width:end/disp8
|
||||||
|
|
||||||
# else: return 1
|
# else: return 1
|
||||||
b8/copy-to-EAX 1/imm32
|
b8/copy-to-EAX 1/imm32
|
||||||
|
|
||||||
$compute-width:end:
|
$compute-width:end:
|
||||||
|
# . discard locals
|
||||||
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
||||||
# . restore registers
|
# . restore registers
|
||||||
59/pop-to-ECX
|
59/pop-to-ECX
|
||||||
|
|
||||||
# . epilog
|
# . epilog
|
||||||
89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP
|
89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP
|
||||||
5d/pop-to-EBP
|
5d/pop-to-EBP
|
||||||
|
|
|
@ -397,11 +397,11 @@ compute-offsets: # in : (address buffered-file), segments : (address stream {st
|
||||||
# var curr-segment-name = 0
|
# var curr-segment-name = 0
|
||||||
# var file-offset = 0, segment-offset = 0
|
# var file-offset = 0, segment-offset = 0
|
||||||
# var line = new-stream(512, 1)
|
# var line = new-stream(512, 1)
|
||||||
# while true
|
# while true # line loop
|
||||||
# clear-stream(line)
|
# clear-stream(line)
|
||||||
# read-line-buffered(in, line)
|
# read-line-buffered(in, line)
|
||||||
# if (line->write == 0) break # end of file
|
# if (line->write == 0) break # end of file
|
||||||
# while true
|
# while true # word loop
|
||||||
# var word-slice = next-word(line)
|
# var word-slice = next-word(line)
|
||||||
# if slice-empty?(word-slice) # end of line
|
# if slice-empty?(word-slice) # end of line
|
||||||
# break
|
# break
|
||||||
|
@ -480,7 +480,7 @@ $compute-offsets:line-loop:
|
||||||
e8/call clear-stream/disp32
|
e8/call clear-stream/disp32
|
||||||
# . discard args
|
# . discard args
|
||||||
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP
|
||||||
# read-line-buffered(in, line/ECX)
|
# read-line-buffered(in, line/EAX)
|
||||||
51/push-ECX
|
51/push-ECX
|
||||||
ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8)
|
ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8)
|
||||||
e8/call read-line-buffered/disp32
|
e8/call read-line-buffered/disp32
|
||||||
|
@ -488,11 +488,11 @@ $compute-offsets:line-loop:
|
||||||
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
|
||||||
# if(line->write == 0)
|
# if(line->write == 0)
|
||||||
# . EAX = line/ECX->write
|
# . EAX = line/ECX->write
|
||||||
8b/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . . # copy *EAX to EAX
|
8b/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . . # copy *ECX to EAX
|
||||||
# . line->write/EAX == 0 ?
|
# . line->write/EAX == 0 ?
|
||||||
3d/compare-EAX-and 0/imm32
|
3d/compare-EAX-and 0/imm32
|
||||||
# . if so, break
|
# . if so, break
|
||||||
0f 84/jump-if-equal $compute-offsets:line-loop:break/disp32
|
0f 84/jump-if-equal $compute-offsets:end/disp32
|
||||||
$compute-offsets:word-loop:
|
$compute-offsets:word-loop:
|
||||||
# var word-slice/EDX = {0, 0}
|
# var word-slice/EDX = {0, 0}
|
||||||
c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . compute-offsets:word-slice/disp32 0/imm32 # copy to *compute-offsets:word-slice
|
c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . compute-offsets:word-slice/disp32 0/imm32 # copy to *compute-offsets:word-slice
|
||||||
|
@ -512,8 +512,8 @@ $compute-offsets:word-loop:
|
||||||
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP
|
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP
|
||||||
# . EAX == 1 ?
|
# . EAX == 1 ?
|
||||||
3d/compare-EAX-and 1/imm32
|
3d/compare-EAX-and 1/imm32
|
||||||
# . if so, break
|
# . if so, break (go to top of outer loop)
|
||||||
0f 84/jump-if-equal $compute-offsets:line-loop:break/disp32
|
0f 84/jump-if-equal $compute-offsets:line-loop/disp32
|
||||||
# if slice-starts-with?(word-slice, "#") continue
|
# if slice-starts-with?(word-slice, "#") continue
|
||||||
68/push "#"/imm32
|
68/push "#"/imm32
|
||||||
52/push-EDX
|
52/push-EDX
|
||||||
|
@ -565,7 +565,7 @@ $compute-offsets:label:
|
||||||
# . . call
|
# . . call
|
||||||
e8/call trace-snsns/disp32
|
e8/call trace-snsns/disp32
|
||||||
# continue
|
# continue
|
||||||
0f 84/jump-if-equal $compute-offsets:word-loop/disp32
|
e9/jump $compute-offsets:word-loop/disp32
|
||||||
$compute-offsets:segment:
|
$compute-offsets:segment:
|
||||||
# if slice-equal?(word-slice/EDX, "==")
|
# if slice-equal?(word-slice/EDX, "==")
|
||||||
# . EAX = slice-equal?(word-slice/EDX, "==")
|
# . EAX = slice-equal?(word-slice/EDX, "==")
|
||||||
|
@ -604,7 +604,7 @@ $compute-offsets:segment:
|
||||||
# . EBX = *file-offset
|
# . EBX = *file-offset
|
||||||
8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX compute-offsets:file-offset/disp32 # copy *file-offset to EBX
|
8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX compute-offsets:file-offset/disp32 # copy *file-offset to EBX
|
||||||
# . ECX = seg->starting-offset
|
# . ECX = seg->starting-offset
|
||||||
8b/copy 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/EBX 4/disp8 . # copy *(EAX+4) to ECX
|
8b/copy 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/ECX 4/disp8 . # copy *(EAX+4) to ECX
|
||||||
# . EBX -= ECX
|
# . EBX -= ECX
|
||||||
29/subtract 3/mod/direct 3/rm32/EBX . . . 1/r32/ECX . . # subtract ECX from EBX
|
29/subtract 3/mod/direct 3/rm32/EBX . . . 1/r32/ECX . . # subtract ECX from EBX
|
||||||
# . seg->size = EBX
|
# . seg->size = EBX
|
||||||
|
@ -700,7 +700,7 @@ $compute-offsets:construct-next-segment:
|
||||||
# . discard args
|
# . discard args
|
||||||
# segment-offset = 0
|
# segment-offset = 0
|
||||||
c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . compute-offsets:segment-offset/disp32 0/imm32 # copy to *segment-offset
|
c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . compute-offsets:segment-offset/disp32 0/imm32 # copy to *segment-offset
|
||||||
eb/jump $compute-offsets:line-loop:break/disp8
|
e9/jump $compute-offsets:line-loop/disp32
|
||||||
$compute-offsets:else:
|
$compute-offsets:else:
|
||||||
# EAX = slice-to-string(curr-segment-name)
|
# EAX = slice-to-string(curr-segment-name)
|
||||||
52/push-EDX
|
52/push-EDX
|
||||||
|
@ -725,8 +725,7 @@ $compute-offsets:else:
|
||||||
# . *file-offset/EBX += EAX/width
|
# . *file-offset/EBX += EAX/width
|
||||||
03/add 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # add EAX to EBX
|
03/add 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # add EAX to EBX
|
||||||
89/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX compute-offsets:file-offset/disp32 # copy EBX to *compute-offsets:file-offset
|
89/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX compute-offsets:file-offset/disp32 # copy EBX to *compute-offsets:file-offset
|
||||||
$compute-offsets:line-loop:break:
|
e9/jump $compute-offsets:line-loop/disp32
|
||||||
e9/jump $compute-offsets:line-loop/disp32
|
|
||||||
$compute-offsets:end:
|
$compute-offsets:end:
|
||||||
# . reclaim locals
|
# . reclaim locals
|
||||||
# . restore registers
|
# . restore registers
|
||||||
|
|
Loading…
Reference in New Issue
Block a user