Subversion Repositories Kolibri OS

Rev

Rev 7983 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7983 Rev 8097
Line 419... Line 419...
419
 
419
 
420
 
420
 
421
PROCEDURE xchg (reg1, reg2: INTEGER);
421
PROCEDURE xchg (reg1, reg2: INTEGER);
422
BEGIN
-
 
423
    Push(reg1);
422
BEGIN
424
    Push(reg2);
423
    Push(reg1);
425
    Pop(reg1);
424
    mov(reg1, reg2);
Line 426... Line 425...
426
    Pop(reg2)
425
    Pop(reg2)
Line 817... Line 816...
817
        |IL.opADD:
816
        |IL.opADD:
818
            BinOp(reg1, reg2);
817
            BinOp(reg1, reg2);
819
            Op2(opADD, reg2 * 256, reg1);
818
            Op2(opADD, reg2 * 256, reg1);
820
            drop
819
            drop
Line 821... Line 820...
821
 
820
 
822
        |IL.opADDL, IL.opADDR:
821
        |IL.opADDC:
823
            IF param2 # 0 THEN
822
            IF param2 # 0 THEN
824
                UnOp(reg1);
823
                UnOp(reg1);
825
                Op2(opADD, imm(param2), reg1)
824
                Op2(opADD, imm(param2), reg1)
Line 878... Line 877...
878
 
877
 
879
            drop;
878
            drop;
880
            cc := cond(opcode);
879
            cc := cond(opcode);
Line 881... Line 880...
881
            next := cmd.next(COMMAND);
880
            next := cmd.next(COMMAND);
882
 
881
 
883
            IF next.opcode = IL.opJE THEN
882
            IF next.opcode = IL.opJNZ THEN
884
                jcc(cc, next.param1);
883
                jcc(cc, next.param1);
885
                cmd := next
884
                cmd := next
886
            ELSIF next.opcode = IL.opJNE THEN
885
            ELSIF next.opcode = IL.opJZ THEN
887
                jcc(ORD(BITS(cc) / {0}), next.param1);
886
                jcc(ORD(BITS(cc) / {0}), next.param1);
888
                cmd := next
887
                cmd := next
889
            ELSE
888
            ELSE
Line 890... Line 889...
890
                setcc(cc, GetAnyReg())
889
                setcc(cc, GetAnyReg())
Line 891... Line 890...
891
            END
890
            END
892
 
891
 
Line 893... Line -...
893
        |IL.opNOP:
-
 
894
 
-
 
895
        |IL.opCODE:
-
 
896
            EmitWord(param2)
-
 
897
 
-
 
898
        |IL.opACC:
-
 
899
            IF (R.top # 0) OR (R.stk[0] # ACC) THEN
-
 
900
                PushAll(0);
-
 
901
                GetRegA;
892
        |IL.opNOP, IL.opAND, IL.opOR:
902
                Pop(ACC);
893
 
903
                DEC(R.pushed)
894
        |IL.opCODE:
Line 904... Line 895...
904
            END
895
            EmitWord(param2)
905
 
896
 
906
        |IL.opDROP:
897
        |IL.opDROP:
907
            UnOp(reg1);
898
            UnOp(reg1);
Line 908... Line -...
908
            drop
-
 
909
 
-
 
910
        |IL.opJNZ:
-
 
911
            UnOp(reg1);
-
 
912
            Test(reg1);
-
 
913
            jcc(jne, param1)
899
            drop
914
 
900
 
915
        |IL.opJZ:
901
        |IL.opJNZ1:
916
            UnOp(reg1);
902
            UnOp(reg1);
Line 917... Line 903...
917
            Test(reg1);
903
            Test(reg1);
918
            jcc(je, param1)
904
            jcc(jne, param1)
919
 
905
 
920
        |IL.opJG:
906
        |IL.opJG:
921
            UnOp(reg1);
907
            UnOp(reg1);
Line 922... Line 908...
922
            Test(reg1);
908
            Test(reg1);
923
            jcc(jg, param1)
909
            jcc(jg, param1)
924
 
910
 
925
        |IL.opJE:
911
        |IL.opJNZ:
926
            UnOp(reg1);
912
            UnOp(reg1);
Line 956... Line 942...
956
        |IL.opGETC:
942
        |IL.opGETC:
957
            UnOp(reg2);
943
            UnOp(reg2);
958
            drop;
944
            drop;
959
            Op2(opMOV + bw(param2 = 1), src_x(param1, SR), dst_x(0, reg2))
945
            Op2(opMOV + bw(param2 = 1), src_x(param1, SR), dst_x(0, reg2))
Line -... Line 946...
-
 
946
 
-
 
947
        |IL.opCHKBYTE:
-
 
948
            BinOp(reg1, reg2);
-
 
949
            Op2(opCMP, imm(256), reg1);
-
 
950
            jcc(jb, param1)
960
 
951
 
961
        |IL.opCHKIDX:
952
        |IL.opCHKIDX:
962
            UnOp(reg1);
953
            UnOp(reg1);
963
            Op2(opCMP, imm(param2), reg1);
954
            Op2(opCMP, imm(param2), reg1);
Line 1077... Line 1068...
1077
        |IL.opSUBS:
1068
        |IL.opSUBS:
1078
            BinOp(reg1, reg2);
1069
            BinOp(reg1, reg2);
1079
            Op2(opBIC, reg2 * 256, reg1);
1070
            Op2(opBIC, reg2 * 256, reg1);
1080
            drop
1071
            drop
Line 1081... Line 1072...
1081
 
1072
 
1082
        |IL.opADDSL, IL.opADDSR:
1073
        |IL.opADDSC:
1083
            UnOp(reg1);
1074
            UnOp(reg1);
Line 1084... Line 1075...
1084
            Op2(opBIS, imm(param2), reg1)
1075
            Op2(opBIS, imm(param2), reg1)
1085
 
1076
 
Line 1187... Line 1178...
1187
            END;
1178
            END;
Line 1188... Line 1179...
1188
 
1179
 
1189
            INCL(R.regs, reg1);
1180
            INCL(R.regs, reg1);
Line 1190... Line -...
1190
            ASSERT(REG.GetReg(R, reg1))
-
 
1191
 
-
 
1192
        |IL.opCHKBYTE:
-
 
1193
            BinOp(reg1, reg2);
-
 
1194
            Op2(opCMP, imm(256), reg1);
-
 
1195
            jcc(jb, param1)
1181
            ASSERT(REG.GetReg(R, reg1))
1196
 
1182
 
1197
        |IL.opLSL, IL.opASR, IL.opROR, IL.opLSR:
1183
        |IL.opLSL, IL.opASR, IL.opROR, IL.opLSR:
1198
            PushAll(2);
1184
            PushAll(2);
1199
            CASE opcode OF
1185
            CASE opcode OF
Line 1616... Line 1602...
1616
END epilog;
1602
END epilog;
Line 1617... Line 1603...
1617
 
1603
 
1618
 
1604
 
1619
PROCEDURE CodeGen* (outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS);
1605
PROCEDURE CodeGen* (outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS);
Line 1620... Line 1606...
1620
VAR
1606
VAR
Line 1621... Line 1607...
1621
    i, adr, heap, stack, TextSize, TypesSize, bits, n: INTEGER;
1607
    i, adr, heap, stack, TextSize, TypesSize, bits, n, val: INTEGER;
Line 1622... Line 1608...
1622
 
1608
 
Line 1623... Line -...
1623
    Code, Data, Bss, Free: RECORD address, size: INTEGER END;
-
 
1624
 
-
 
1625
    ram, rom: INTEGER;
1609
    Code, Data, Bss, Free: RECORD address, size: INTEGER END;
1626
 
1610
 
1627
    reloc: RELOC;
1611
    ram, rom: INTEGER;
Line 1628... Line 1612...
1628
 
1612
 
Line 1685... Line 1669...
1685
    PutWord(heap, adr);
1669
    PutWord(heap, adr);
Line 1686... Line 1670...
1686
 
1670
 
1687
    reloc := RelList.first(RELOC);
1671
    reloc := RelList.first(RELOC);
1688
    WHILE reloc # NIL DO
1672
    WHILE reloc # NIL DO
-
 
1673
        adr := reloc.WordPtr.offset * 2;
1689
        adr := reloc.WordPtr.offset * 2;
1674
        val := reloc.WordPtr.val;
1690
        CASE reloc.section OF
1675
        CASE reloc.section OF
1691
        |RCODE: PutWord(LabelOffs(reloc.WordPtr.val) * 2, adr)
1676
        |RCODE: PutWord(LabelOffs(val) * 2, adr)
1692
        |RDATA: PutWord(reloc.WordPtr.val + Data.address, adr)
1677
        |RDATA: PutWord(val + Data.address, adr)
1693
        |RBSS:  PutWord(reloc.WordPtr.val + Bss.address, adr)
1678
        |RBSS:  PutWord(val + Bss.address, adr)
1694
        END;
1679
        END;
1695
        reloc := reloc.next(RELOC)
1680
        reloc := reloc.next(RELOC)
Line 1696... Line 1681...
1696
    END;
1681
    END;
Line 1731... Line 1716...
1731
 
1716
 
1732
    FOR i := 0 TO LEN(IV) - 1 DO
1717
    FOR i := 0 TO LEN(IV) - 1 DO
1733
        PutWord(LabelOffs(IV[i]) * 2, adr)
1718
        PutWord(LabelOffs(IV[i]) * 2, adr)
Line 1734... Line 1719...
1734
    END;
1719
    END;
Line 1735... Line 1720...
1735
 
1720
 
1736
    file := WR.Create(outname);
1721
    WR.Create(outname);
1737
 
1722
 
Line 1738... Line 1723...
1738
    HEX.Data(file, mem, Code.address, TextSize);
1723
    HEX.Data(mem, Code.address, TextSize);
Line 1739... Line 1724...
1739
    HEX.Data(file, mem, 10000H - IntVectorSize - TypesSize, IntVectorSize + TypesSize);
1724
    HEX.Data(mem, 10000H - IntVectorSize - TypesSize, IntVectorSize + TypesSize);
1740
    HEX.End(file);
1725
    HEX.End;
Line 1741... Line 1726...
1741
 
1726