예제 #1
0
def TestCodedCall():
    code = InstructionStream()
    proc = Processor()

    a = array.array('d', [3.14])

    load_word(code, code.gp_return, a.buffer_info()[0])

    ppc.set_active_code(code)
    ppc.lfd(code.fp_return, code.gp_return, 0)
    code.print_code()
    r = proc.execute(code, mode='fp', debug=True)
    assert (r == 3.14)
    print 'float result:', r
    return
예제 #2
0
def TestCodedCall():
    code = InstructionStream()
    proc = Processor()

    a = array.array("d", [3.14])

    load_word(code, code.gp_return, a.buffer_info()[0])

    ppc.set_active_code(code)
    ppc.lfd(code.fp_return, code.gp_return, 0)
    code.print_code()
    r = proc.execute(code, mode="fp", debug=True)
    assert r == 3.14
    print "float result:", r
    return
예제 #3
0
    def _synthesize_epilogue(self):
        """
    Save the values in some registers (see PPC ABI p41)
    """

        # Reset the epilogue
        self._epilogue = [self.lbl_epilogue]

        # Restore vrsave
        self._epilogue.append(ppc.mtvrsave(self._vrsave))

        # Get the list of saved registers
        save_gp = [
            reg for reg in self._register_files[GPRegister].get_used()
            if reg in gp_save
        ]
        save_fp = [
            reg for reg in self._register_files[FPRegister].get_used()
            if reg in fp_save
        ]
        save_vx = [
            reg for reg in self._register_files[VMXRegister].get_used()
            if reg in vx_save
        ]

        r_addr = GPRegister(13, None)  # Only available volatile register
        r_idx = GPRegister(14,
                           None)  # Non-volatile; safe to use before restoring

        self._load_word(self._epilogue, r_addr,
                        self._saved_vx_registers.buffer_info()[0])

        for i, reg in enumerate(save_vx):
            #print 'restoring vx:', reg, r_addr, i * WORD_SIZE * 4
            self._load_word(self._epilogue, r_idx, i * WORD_SIZE * 4)
            self._epilogue.append(
                vmx.lvx(reg, r_idx, r_addr, ignore_active=True))

        self._load_word(self._epilogue, r_addr,
                        self._saved_fp_registers.buffer_info()[0])

        for i, reg in enumerate(save_fp):
            # print 'restoring fp:', reg, r_addr, i * WORD_SIZE
            self._epilogue.append(
                ppc.lfd(reg, r_addr, i * WORD_SIZE * 2, ignore_active=True))

        self._load_word(self._epilogue, r_addr,
                        self._saved_gp_registers.buffer_info()[0])

        for i, reg in enumerate(save_gp):
            # print 'restoring gp:', reg, r_addr, i * WORD_SIZE
            self._epilogue.append(
                ppc.lwz(reg, r_addr, i * WORD_SIZE, ignore_active=True))

        self._epilogue.append(ppc.blr(ignore_active=True))
        return
예제 #4
0
    def _synthesize_epilogue(self):
        """
    Save the values in some registers (see PPC ABI p41)
    """

        # Reset the epilogue
        self._epilogue = [self.lbl_epilogue]

        r_addr = GPRegister(13)  # Only available volatile register
        r_idx = GPRegister(14)  # Non-volatile; safe to use before restoring

        # Get the list of saved registers
        save_gp = [r for r in self._used_registers[GPRegister] if r in gp_save]
        save_fp = [r for r in self._used_registers[FPRegister] if r in fp_save]

        if self._enable_vmx:
            save_vx = [
                r for r in self._used_registers[VMXRegister] if r in vx_save
            ]

            if len(save_vx) > 0:
                # Restore vrsave
                self._epilogue.append(
                    ppc.mtvrsave(self._vrsave, ignore_active=True))

                # Restore saved VMX registers
                self._load_word(self._epilogue, r_addr,
                                self._saved_vx_registers.buffer_info()[0])

                for i, reg in enumerate(save_vx):
                    self._load_word(self._epilogue, r_idx, i * WORD_SIZE * 4)
                    self._epilogue.append(
                        vmx.lvx(reg, r_idx, r_addr, ignore_active=True))

        if len(save_fp) > 0:
            # Restore saved FP registers
            self._load_word(self._epilogue, r_addr,
                            self._saved_fp_registers.buffer_info()[0])

            for i, reg in enumerate(save_fp):
                self._epilogue.append(
                    ppc.lfd(reg, r_addr, i * WORD_SIZE * 2,
                            ignore_active=True))

        if len(save_gp) > 0:
            # Restore saved GP registers
            self._load_word(self._epilogue, r_addr,
                            self._saved_gp_registers.buffer_info()[0])

            for i, reg in enumerate(save_gp):
                self._epilogue.append(
                    ppc.lwz(reg, r_addr, i * WORD_SIZE, ignore_active=True))

        self._epilogue.append(ppc.blr(ignore_active=True))
        return
예제 #5
0
def TestFloat():
    code = InstructionStream()
    proc = Processor()
    a = array.array("d", [3.14])

    load_word(code, gp_return, a.buffer_info()[0])
    code.add(ppc.lfd(code.fp_return, code.gp_return, 0))

    r = proc.execute(code, mode="fp", debug=True)
    assert r == 3.14
    print "float result:", r
    return
예제 #6
0
def TestFloat():
    code = InstructionStream()
    proc = Processor()
    a = array.array('d', [3.14])

    load_word(code, gp_return, a.buffer_info()[0])
    code.add(ppc.lfd(code.fp_return, code.gp_return, 0))

    r = proc.execute(code, mode='fp', debug=True)
    assert (r == 3.14)
    print 'float result:', r
    return
예제 #7
0
  def _synthesize_epilogue(self):
    """
    Save the values in some registers (see PPC ABI p41)
    """

    # Reset the epilogue
    self._epilogue = [self.lbl_epilogue]

    r_addr = GPRegister(13) # Only available volatile register
    r_idx = GPRegister(14)  # Non-volatile; safe to use before restoring

    # Get the list of saved registers
    save_gp = [r for r in self._used_registers[GPRegister] if r in gp_save]
    save_fp = [r for r in self._used_registers[FPRegister] if r in fp_save]

    if self._enable_vmx:
      save_vx = [r for r in self._used_registers[VMXRegister] if r in vx_save]

      if len(save_vx) > 0:
        # Restore vrsave
        self._epilogue.append(ppc.mtvrsave(self._vrsave, ignore_active = True))

        # Restore saved VMX registers
        self._load_word(self._epilogue, r_addr,
            self._saved_vx_registers.buffer_info()[0])

        for i, reg in enumerate(save_vx):
          self._load_word(self._epilogue, r_idx, i * WORD_SIZE * 4)
          self._epilogue.append(
              vmx.lvx(reg, r_idx, r_addr, ignore_active = True))

    if len(save_fp) > 0:
      # Restore saved FP registers
      self._load_word(self._epilogue, r_addr,
          self._saved_fp_registers.buffer_info()[0])

      for i, reg in enumerate(save_fp):
        self._epilogue.append(
            ppc.lfd(reg, r_addr, i * WORD_SIZE * 2, ignore_active = True))

    if len(save_gp) > 0:
      # Restore saved GP registers
      self._load_word(self._epilogue, r_addr,
          self._saved_gp_registers.buffer_info()[0])

      for i, reg in enumerate(save_gp):
        self._epilogue.append(
            ppc.lwz(reg, r_addr, i * WORD_SIZE, ignore_active = True))

    self._epilogue.append(ppc.blr(ignore_active = True))
    return
예제 #8
0
def TestFloat():
    prgm = Program()
    code = prgm.get_stream()
    prgm += code
    proc = Processor()
    a = array.array('d', [3.14])

    load_word(code, prgm.gp_return, a.buffer_info()[0])
    code.add(ppc.lfd(prgm.fp_return, prgm.gp_return, 0))

    r = proc.execute(prgm, mode='fp')
    assert (r == 3.14)
    print 'float result:', r
    return
예제 #9
0
def TestFloat():
  prgm = Program()
  code = prgm.get_stream()
  prgm += code
  proc = Processor()
  a = array.array('d', [3.14])

  load_word(code, prgm.gp_return, a.buffer_info()[0])
  code.add(ppc.lfd(prgm.fp_return, prgm.gp_return, 0))

  r = proc.execute(prgm, mode='fp')
  assert(r == 3.14)
  print 'float result:', r
  return
예제 #10
0
  def load(self, addr, offset = 0):

    # If addr is a constant, create a variable and store the value
    if not issubclass(type(addr), spe.Type):
      r_storage = self.code.prgm.acquire_register()
      addr = Bits(addr, reg = r_storage)
    else:
      r_storage = None

    # If offset is a constant, use lfd, otherwise use lfdx
    if issubclass(type(offset), spe.Type):
      self.code.add(ppc.lfdx(self, addr, offset))
    else:
      # TODO: Check size of offset to ensure it fits in the immediate field 
      self.code.add(ppc.lfd(self, addr, offset))

    if r_storage is not None:
      self.code.prgm.release_register(r_storage)

    return
예제 #11
0
ppc.b(prgm.lbl_epilogue)

prgm.add(code)
prgm.print_code(pro=True, epi=True, binary=True)

r = proc.execute(prgm, debug=True)

print 'int result:', r
assert(r == 12)

code.reset()

a = array.array('d', [3.14])

load_word(code, prgm.gp_return, a.buffer_info()[0])
ppc.lfd(prgm.fp_return, prgm.gp_return, 0)

r = proc.execute(prgm, mode='fp', debug=True)
assert(r == 3.14)
print 'float result:', r


code.reset()

load_word(code, prgm.gp_return, 0xFFFFFFFF)

r = proc.execute(prgm, mode='int', debug=True)
print "int result:",r
assert(r == -1)

예제 #12
0
파일: basics.py 프로젝트: tmaone/efi
ppc.b(code.lbl_epilogue)

code.cache_code()
code.print_code(pro=True, epi=True, binary=True)

r = proc.execute(code, debug=True)

print 'int result:', r
assert (r == 12)

code.reset()

a = array.array('d', [3.14])

load_word(code, code.gp_return, a.buffer_info()[0])
ppc.lfd(code.fp_return, code.gp_return, 0)

r = proc.execute(code, mode='fp', debug=True)
assert (r == 3.14)
print 'float result:', r

code.reset()

load_word(code, code.gp_return, 0xFFFFFFFF)

r = proc.execute(code, mode='int', debug=True)
print "int result:", r
assert (r == -1)

code.reset()
예제 #13
0
ppc.b(prgm.lbl_epilogue)

prgm.add(code)
prgm.print_code(pro=True, epi=True, binary=True)

r = proc.execute(prgm, debug=True)

print 'int result:', r
assert (r == 12)

code.reset()

a = array.array('d', [3.14])

load_word(code, prgm.gp_return, a.buffer_info()[0])
ppc.lfd(prgm.fp_return, prgm.gp_return, 0)

r = proc.execute(prgm, mode='fp', debug=True)
assert (r == 3.14)
print 'float result:', r

code.reset()

load_word(code, prgm.gp_return, 0xFFFFFFFF)

r = proc.execute(prgm, mode='int', debug=True)
print "int result:", r
assert (r == -1)

code.reset()