Esempio n. 1
0
 def test_neg(self):
     a = PPCBuilder()
     a.load_imm(r10, 0x0000F0F0)
     a.neg(3, 10)
     a.blr()
     f = a.get_assembler_function()
     assert f() == hex_to_signed_int("FFFF0F10")
Esempio n. 2
0
 def test_neg(self):
     a = PPCBuilder()
     a.load_imm(r10, 0x0000F0F0)
     a.neg(3, 10)
     a.blr()
     f = a.get_assembler_function()
     assert f() == hex_to_signed_int("FFFF0F10")
Esempio n. 3
0
    def test_call_function(self):
        functype = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
        call_addr = rffi.cast(lltype.Signed, llhelper(functype, func))
        a = PPCBuilder()

        # NOW EXPLICITLY:
        #
        # - Load the address of the function to call into a register x
        # - Move the content of this register x into CTR
        # - Set the LR manually (or with bctrl)
        # - Do jump

        a.li(3, 50)
        if IS_PPC_32:
            a.load_imm(r10, call_addr)
        elif IS_BIG_ENDIAN:
            # load the 3-words descriptor
            a.load_from_addr(r10, call_addr)
            a.load_from_addr(r2, call_addr + WORD)
            a.load_from_addr(r11, call_addr + 2 * WORD)
        else:
            # no descriptor on little-endian, but the ABI says r12 must
            # contain the function pointer
            a.load_imm(r10, call_addr)
            a.mr(12, 10)
        a.mtctr(10)
        a.bctr()
        a.blr()

        f = a.get_assembler_function()
        assert f() == 65
Esempio n. 4
0
    def test_call_function(self):
        functype = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
        call_addr = rffi.cast(lltype.Signed, llhelper(functype, func))
        a = PPCBuilder()

        # NOW EXPLICITLY:
        #
        # - Load the address of the function to call into a register x
        # - Move the content of this register x into CTR
        # - Set the LR manually (or with bctrl)
        # - Do jump

        a.li(3, 50)
        if IS_PPC_32:
            a.load_imm(r10, call_addr)
        elif IS_BIG_ENDIAN:
            # load the 3-words descriptor
            a.load_from_addr(r10, SCRATCH2, call_addr)
            a.load_from_addr(r2, SCRATCH2, call_addr + WORD)
            a.load_from_addr(r11, SCRATCH2, call_addr + 2 * WORD)
        else:
            # no descriptor on little-endian, but the ABI says r12 must
            # contain the function pointer
            a.load_imm(r10, call_addr)
            a.mr(12, 10)
        a.mtctr(10)
        a.bctr()
        a.blr()

        f = a.get_assembler_function()
        assert f() == 65
Esempio n. 5
0
    def test_load_from(self):
        a = PPCBuilder()

        p = lltype.malloc(rffi.CArray(rffi.LONG), 1, flavor="raw")
        addr = rffi.cast(lltype.Signed, p)
        p[0] = rffi.cast(rffi.LONG, 200)

        a.load_from_addr(r3, addr)
        a.blr()
        f = a.get_assembler_function()
        assert f() == 200
        p[0] = rffi.cast(rffi.LONG, 300)
        assert f() == 300
        lltype.free(p, flavor="raw")
Esempio n. 6
0
    def test_load_from(self):
        a = PPCBuilder()

        p = lltype.malloc(rffi.CArray(rffi.LONG), 1, flavor="raw")
        addr = rffi.cast(lltype.Signed, p)
        p[0] = rffi.cast(rffi.LONG, 200)

        a.load_from_addr(r3, SCRATCH2, addr)
        a.blr()
        f = a.get_assembler_function()
        assert f() == 200
        p[0] = rffi.cast(rffi.LONG, 300)
        assert f() == 300
        lltype.free(p, flavor="raw")
Esempio n. 7
0
    def test_load_and_store(self):
        a = PPCBuilder()
        word1 = 1000
        word2 = 2000
        p = lltype.malloc(rffi.CArray(lltype.Signed), 2, flavor="raw")

        a.load_imm(r10, word1)
        a.load_imm(r11, word2)

        a.load_imm(r8, rffi.cast(lltype.Signed, p))
        a.load_imm(r9, rffi.cast(lltype.Signed, p) + WORD)

        a.stw(10, 8, 0)
        a.stw(11, 9, 0)
        a.lwz(4, 8, 0)
        a.lwz(5, 9, 0)
        a.add(3, 4, 5)
        a.blr()
        f = a.get_assembler_function()
        assert f() == word1 + word2
        lltype.free(p, flavor="raw")
Esempio n. 8
0
    def test_load_and_store(self):
        a = PPCBuilder()
        word1 = 1000
        word2 = 2000
        p = lltype.malloc(rffi.CArray(lltype.Signed), 2, flavor="raw")

        a.load_imm(r10, word1)
        a.load_imm(r11, word2)

        a.load_imm(r8, rffi.cast(lltype.Signed, p))
        a.load_imm(r9, rffi.cast(lltype.Signed, p) + WORD)

        a.stw(10, 8, 0)
        a.stw(11, 9, 0)
        a.lwz(4, 8, 0)
        a.lwz(5, 9, 0)
        a.add(3, 4, 5)
        a.blr()
        f = a.get_assembler_function()
        assert f() == word1 + word2
        lltype.free(p, flavor="raw")
Esempio n. 9
0
        def newtest(self):
            memory_ptrs = []
            a = PPCBuilder()
            for (bytes, type, values) in memory:
                # alloc
                adr = lltype.malloc(rffi.CArray(char), bytes, flavor="raw")
                memory_ptrs.append(adr)
                address = adr
                for i,value in enumerate(values):
                    rffi.cast(rffi.CArrayPtr(type), adr)[i] = rffi.cast(type, value)

            expected = test(self, a, *[rffi.cast(lltype.Signed, m) for m in memory_ptrs])
            f = a.get_assembler_function()
            f()
            for expect, type, ptr in expected:
                value = rffi.cast(rffi.CArrayPtr(type), ptr)[0]
                assert value == expect

            while memory_ptrs:
                ptr = memory_ptrs.pop()
                lltype.free(ptr, flavor="raw")
Esempio n. 10
0
        def newtest(self):
            memory_ptrs = []
            a = PPCBuilder()
            for (bytes, type, values) in memory:
                # alloc
                adr = lltype.malloc(rffi.CArray(char), bytes, flavor="raw")
                memory_ptrs.append(adr)
                address = adr
                for i, value in enumerate(values):
                    rffi.cast(rffi.CArrayPtr(type),
                              adr)[i] = rffi.cast(type, value)

            expected = test(
                self, a, *[rffi.cast(lltype.Signed, m) for m in memory_ptrs])
            f = a.get_assembler_function()
            f()
            for expect, type, ptr in expected:
                value = rffi.cast(rffi.CArrayPtr(type), ptr)[0]
                assert value == expect

            while memory_ptrs:
                ptr = memory_ptrs.pop()
                lltype.free(ptr, flavor="raw")
Esempio n. 11
0
 def newtest(self):
     a = PPCBuilder()
     test(self, a)
     f = a.get_assembler_function()
     assert f() == expected
Esempio n. 12
0
 def newtest(self):
     a = PPCBuilder()
     test(self, a)
     f = a.get_assembler_function()
     assert f() == expected
Esempio n. 13
0
 def make_function_returning_stack_pointer(self):
     mc = PPCBuilder()
     mc.mr(r.r3.value, r.r1.value)
     mc.blr()
     return rffi.cast(lltype.Signed, mc.get_assembler_function())