Exemplo n.º 1
0
def runforever(insts=0x7fffffffffffffff,ss=None,bout=1,va_pass=[0x122000],va_fail=[0x122020]):
    """
    insts: number of instructions to run per strand, default is MAXINT
    ss: array of strand-ids, e.g., [0,1,2]. default is None, means all strands
    bout: upon hitting pass/fail, 1 means exit, 0 means returns to caller
    va_pass: array of 'pass' VAs, default is 0x122000
    va_fail: array of 'fail' VAs, default is 0x122020
    """
    strands = []
    if ss == None:
        # special case, step through all strands
        for s in sim.s:
            strands.append(s)
    else:
        # otherwise only step through specified strands
        for sid in ss:
            strands.append(sim.s[sid])
    # set 'pass' breakpoints
    bp_pass = {}
    for s in strands:
	bp_pass[s.strand_id] = []
        for va in va_pass:
            bp_pass[s.strand_id].append(s.brk.on_inst_va(va))
    # set 'fail' breakpoints
    bp_fail = {}
    for s in strands:
	bp_fail[s.strand_id] = []
        for va in va_fail:
            bp_fail[s.strand_id].append(s.brk.on_inst_va(va))
    # step through strands
    sam.ui_exec('stepi %d' % insts)
    # check for pass/fail breakpoint
    for s in strands:
        bp = s.brk.hit()
        if bp:
            if bp[0] in bp_pass[s.strand_id]:
                if bout:
                    sys.exit(0)
                else:
                    return 0
            elif bp[0] in bp_fail[s.strand_id]:
                if bout:
                    sys.exit(1)
                else:
                    return 1
    # if nothing hit, consider it is good
    if bout:
        sys.exit(0)
    else:
        return 0
Exemplo n.º 2
0
def runshow(step=1,sid=0,fd=sys.stdout,sym=1):
    """
    step: number of instruction to be executed, default is 1
    sid: strand id, default is 0
    fd: write the output to a file descriptor, default to stdout
    sym: show (PC) symbol if available

    example:
      sam>>> fd1=open('0-tmp','w')
      sam>>> runshow(10,fd=fd1)
      sam>>> runshow(100,fd=fd1)
      sam>>> fd1.close()
    """
    global pyobj
    global icount
    global symTable
    prevPC = 0x0L
    newPC = 0x0L
    prevTL = 0
    newTL = 0
    i = 0
    done = 0
    while (done == 0) and (i < step):
        i += 1
        icount += 1
        newPC = sim.s[sid].pc
        (len,instr,type) = RS_disassemblePC(sid, pyobj)
        sam.ui_exec('stepi')
        newTL = sim.s[sid].tl
        # check for hitting breakpoint
        for s in sim.s:
            if s.brk.hit():
                done = 1
                break
        if done == 0:
            if (newPC != prevPC+4) or (newTL != prevTL):
                # display PC or related symbol when PC moves to a different
                # path
                if (sym == 1) and (symTable != None):
                    fd.write('%s, TL=%d:\n' % (symTable.va2symbol(newPC), newTL))
                else:
                    fd.write('PC=%#x, TL=%d:\n' % (newPC, newTL))
            fd.write('sid=%d, ic=%d, pc=%#x, %s\n' % (sid, icount, newPC, instr))
            prevPC = newPC
            prevTL = newTL
Exemplo n.º 3
0
    def issueCmd (self, cmd, output, riesReposit):
	"""
	"""
	tokens = cmd.split()
	if tokens[0] in self.cmdMap:
	    if tokens[0] == 'file':
		# process the file line-by-line
		return 'execfile("%s")' % (tokens[1])
	    else:
		if ((tokens[0] == 'ssi') or (tokens[0] == 'runfast')):
		    sys.stderr.write('ERROR: command %s is not supported in SAM, use "stepi N" or "run N" instead\n' % (tokens[0]))
		    return None
		elif (tokens[0] == 'run'):
		    if (len(tokens) > 1):
			# 'run' is a non-blocking call, if we see 'run N', 
			# convert that to 'stepi N'
                        cmd = 'stepi ' + ' '.join(tokens[1:])
		    else:
			# 'run' alone becomes a non-blocking call, we should
			# get UI prompt back right the way
                        cmd = tokens[0]
		elif (tokens[0] == 'pmask'):
		    if len(tokens) == 1:
			# query current pmask
			sys.stderr.write('%#x\n' % riesReposit.pmask)
			return None
		    else:
			if not sam.is_stopped():
			    sys.stderr.write('Simulator is running, issue "stop" before changing pmask\n')
			    return None
			# set blaze penable accordingly
			newMask = long(tokens[1], 16)
			toDisable = riesReposit.pmask & (~newMask & 0xffffffffffffffffL)
			toEnable = (~riesReposit.pmask & 0xffffffffffffffffL) & newMask
			#sys.stderr.write('DBX: newMask=%#x  toDisable=%#x  toEnable=%#x\n' % (newMask, toDisable, toEnable))
			# disable currently enabled, but to be disabled strands
			for i in range(riesReposit.blazeNumcpu):
			    if ((toDisable >> i) &0x1) == 0x1:
				cmd = 'pdisable th%d' % i
				#sys.stderr.write('DBX: cmd=%s\n' % cmd)
				#self.blaze.command(cmd)
				sam.ui_exec(cmd);
			# disable currently disabled, but to be enabled strands
			for i in range(riesReposit.blazeNumcpu):
			    if ((toEnable >> i) &0x1) == 0x1:
				cmd = 'penable th%d' % i
				#sys.stderr.write('DBX: cmd=%s\n' % cmd)
				#self.blaze.command(cmd)
				sam.ui_exec(cmd);
			# update to the new mask
			riesReposit.pmask = newMask
			return None

		if type(output) is types.ListType:
		    #output = output.append(self.blaze.command(cmd))
		    sam.ui_exec(cmd);
		else:
		    #self.blaze.command(cmd)
		    sam.ui_exec(cmd);


		if cmd == 'run':
		    riesReposit.running = 1
		    #print "start running...."
		    #sys.ps1 = 'run>'
		#elif (cmd == 'stop') or (cmd.startswith('stepi ')):
		elif cmd == 'stop':
		    # don't check 'stepi' here. If we first do 'run', then
		    # enter either 'run N' or 'stepi N', blaze will issue
		    # 'is running' and return without doing anything, at this
		    # time blaze is still in the first 'run', so we cannot
		    # set running to 0 for 'run N' or 'stepi N', as they may
		    # not be executed at all.
		    riesReposit.running = 0
		    #print "stop command was issued."
		    #sys.ps1 = 'stop>'

		if len(tokens) > 2 and (tokens[0] == 'mod' and 
					tokens[1] == 'load'):
		    # mod load xxx yyy, register 'xxx' as a command prefix, as all
		    # module 'yyy' related commands will use that prefix
		    if not tokens[2] in self.cmdMap:
			self.cmdMap.append(tokens[2])
	        return None
	else:
	    return cmd
Exemplo n.º 4
0
    done = 0
    while (done == 0) and (i < step):
        i += 1
        icount += 1
        newPC = sim.s[sid].pc
        (len,instr,type) = RS_disassemblePC(sid, pyobj)
        # check breakpoints
	if newPC in bpoints:
            if symTable != None:
                fd.write('BREAKPOINT: sid=%d, pc=%#x [%s]\n' % (sid, newPC, symTable.va2symbol(newPC)))
            else:
                fd.write('BREAKPOINT: sid=%d, pc=%#x\n' % (sid, newPC))
            done = 1
        else:
            # execute the next instr if no breakpoint is hit
            sam.ui_exec('stepi')
            newTL = sim.s[sid].tl
            for s in sim.s:
                if s.brk.hit():
                    done = 1
                    break
            if done == 0:
                if (newPC != prevPC+4) or (newTL != prevTL):
                    # display PC or related symbol when PC moves to a 
                    # different path
                    if (sym == 1) and (symTable != None):
                        fd.write('%s, TL=%d:\n' % (symTable.va2symbol(newPC), newTL))
                    else:
                        fd.write('PC=%#x, TL=%d:\n' % (newPC, newTL))
                fd.write('sid=%d, ic=%d, pc=%#x, %s\n' % (sid, icount, newPC, instr))
                prevPC = newPC