Mercurial > repos > tabletprog
comparison modules/x86.tp @ 348:a840e9a068a2
Get sample builtin to il module working again
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 10 Apr 2015 00:48:42 -0700 |
parents | f987bb2a1911 |
children | a3b06d53bcb9 |
comparison
equal
deleted
inserted
replaced
347:ff7ea11b4b60 | 348:a840e9a068a2 |
---|---|
224 ilist fold: idx with: :idx byte { | 224 ilist fold: idx with: :idx byte { |
225 dest set: idx byte | 225 dest set: idx byte |
226 idx + 1 | 226 idx + 1 |
227 } | 227 } |
228 } | 228 } |
229 string <- { (ilist map: :el { hex: el}) join: " "} | |
229 } | 230 } |
230 } | 231 } |
231 multiInst <- :instarr { | 232 multiInst <- :instarr { |
232 #{ | 233 #{ |
233 length <- { | 234 length <- { |
237 } | 238 } |
238 flattenTo:at <- :dest :idx { | 239 flattenTo:at <- :dest :idx { |
239 instarr fold: idx with: :idx inst { | 240 instarr fold: idx with: :idx inst { |
240 inst flattenTo: dest at: idx | 241 inst flattenTo: dest at: idx |
241 } | 242 } |
243 } | |
244 string <- { | |
245 (instarr map: :inst { | |
246 (inst map: :el { hex: el}) join: " " | |
247 }) join: "\n" | |
242 } | 248 } |
243 } | 249 } |
244 } | 250 } |
245 | 251 |
246 op:withCode:withImmed:withOpEx <- :src dst size :normal :immed :myopex { | 252 op:withCode:withImmed:withOpEx <- :src dst size :normal :immed :myopex { |
447 } | 453 } |
448 _forwardRefs <- #[] | 454 _forwardRefs <- #[] |
449 } | 455 } |
450 idx | 456 idx |
451 } | 457 } |
458 string <- { "label: " . _offset } | |
452 withOffset:else <- :fun :elsefun { | 459 withOffset:else <- :fun :elsefun { |
453 if: hasOffset? { | 460 if: hasOffset? { |
454 fun: _offset | 461 fun: _offset |
455 } else: { | 462 } else: { |
456 _forwardRefs append: fun | 463 _forwardRefs append: fun |
501 } else: { | 508 } else: { |
502 _size <- 5 | 509 _size <- 5 |
503 } | 510 } |
504 idx + _size | 511 idx + _size |
505 } | 512 } |
513 string <- { | |
514 "jmp " . jmpDest | |
515 } | |
506 } | 516 } |
507 } else: { | 517 } else: { |
508 inst: 0xFFu8 | (mod_rm: (opex: 5u8) jmpDest) | 518 inst: 0xFFu8 | (mod_rm: (opex: 5u8) jmpDest) |
509 } | 519 } |
510 } | 520 } |
538 } else: { | 548 } else: { |
539 _size <- 6 | 549 _size <- 6 |
540 } | 550 } |
541 idx + _size | 551 idx + _size |
542 } | 552 } |
553 string <- { | |
554 "jcc " . jmpDest | |
555 } | |
543 } | 556 } |
544 } | 557 } |
545 | 558 |
546 call <- :callDest { | 559 call <- :callDest { |
547 if: (callDest label?) { | 560 if: (callDest label?) { |
556 dest set: (idx + 3) (uint8: (rshift: rel by: 16)) | 569 dest set: (idx + 3) (uint8: (rshift: rel by: 16)) |
557 dest set: (idx + 4) (uint8: (rshift: rel by: 24)) | 570 dest set: (idx + 4) (uint8: (rshift: rel by: 24)) |
558 } else: { | 571 } else: { |
559 } | 572 } |
560 idx + 5 | 573 idx + 5 |
574 } | |
575 string <- { | |
576 "call " . callDest | |
561 } | 577 } |
562 } | 578 } |
563 } else: { | 579 } else: { |
564 inst: 0xFFu8 | (mod_rm: (opex: 2u8) callDest) | 580 inst: 0xFFu8 | (mod_rm: (opex: 2u8) callDest) |
565 } | 581 } |
730 opmap <- #[ | 746 opmap <- #[ |
731 { outarr append: (add: (inst in) (inst out) (mapSize: (inst size))) } | 747 { outarr append: (add: (inst in) (inst out) (mapSize: (inst size))) } |
732 { outarr append: (and: (inst in) (inst out) (mapSize: (inst size))) } | 748 { outarr append: (and: (inst in) (inst out) (mapSize: (inst size))) } |
733 { outarr append: (or: (inst in) (inst out) (mapSize: (inst size))) } | 749 { outarr append: (or: (inst in) (inst out) (mapSize: (inst size))) } |
734 { outarr append: (xor: (inst in) (inst out) (mapSize: (inst size))) } | 750 { outarr append: (xor: (inst in) (inst out) (mapSize: (inst size))) } |
735 //mul | 751 { } //muls |
736 //div | 752 { } //mulu |
753 { } //divs | |
754 { } //divu | |
737 { outarr append: (sub: (inst in) (inst out) (mapSize: (inst size))) } | 755 { outarr append: (sub: (inst in) (inst out) (mapSize: (inst size))) } |
738 { outarr append: (cmp: (inst in) (inst out) (mapSize: (inst size))) } | 756 { outarr append: (cmp: (inst in) (inst out) (mapSize: (inst size))) } |
739 { outarr append: (bnot: (inst arg) (mapSize: (inst size))) } | 757 { outarr append: (bnot: (inst arg) (mapSize: (inst size))) } |
740 { outarr append: (shl: (inst in) (inst out) (mapSize: (inst size))) } //sl | 758 { outarr append: (shl: (inst in) (inst out) (mapSize: (inst size))) } //sl |
741 { outarr append: (sar: (inst in) (inst out) (mapSize: (inst size))) } //asr | 759 { outarr append: (sar: (inst in) (inst out) (mapSize: (inst size))) } //asr |
787 convertIL: inst to: outarr withLabels: labels withSaved: saved | 805 convertIL: inst to: outarr withLabels: labels withSaved: saved |
788 } | 806 } |
789 outarr append: endlab | 807 outarr append: endlab |
790 } | 808 } |
791 //skipIf:else | 809 //skipIf:else |
810 { } | |
792 { | 811 { |
793 //save | 812 //save |
794 newsave <- [] | 813 newsave <- [] |
795 foreach: (inst tosave) :_ reg { | 814 foreach: (inst tosave) :_ reg { |
796 outarr append: (push: reg) | 815 outarr append: (push: reg) |
797 newsave <- reg | newsave | 816 newsave <- reg | newsave |
798 } | 817 } |
799 foreach: (inst scope) :_ inst { | 818 foreach: (inst scope) :_ inst { |
800 convertIL: inst to: outarr withLabels: labels withSaved: newsave | 819 convertIL: inst to: outarr withLabels: labels withSaved: newsave |
801 } | 820 } |
802 if: ((inst scope) length) = 0 || (((inst scope) get: ((inst scope) length) - 1) opcode) != 14 { | 821 if: ((inst scope) length) = 0 || (((inst scope) get: ((inst scope) length) - 1) opcode) != 18 { |
803 foreach: newsave :_ reg { | 822 foreach: newsave :_ reg { |
804 outarr append: (pop: reg) | 823 outarr append: (pop: reg) |
805 } | 824 } |
806 } | 825 } |
807 } | 826 } |
808 //bool | 827 //bool |
828 { } | |
809 ] | 829 ] |
830 print: "Opcode: " . (inst opcode) . "\n" | |
810 fun <- opmap get: (inst opcode) | 831 fun <- opmap get: (inst opcode) |
811 fun: | 832 fun: |
812 outarr | 833 outarr |
813 } | 834 } |
814 | 835 |