Esempio n. 1
0
def example():

    m = mem.Stackup((FILENAME,), nextto=__file__)
    m2 = mem.WordMem(0, m.hi >> 1, bits=16)
    for a in range(m.lo, m.hi, 2):
       m2[a >> 1] = m.bu16(a)
    cx = hp_hybrid.hp_hybrid()
    cx.m.map(m2, 0x20, offset=0x20)
    cx.flow_check.append(fc_call)

    rom_checksum(cx.m)

    for a, b in SYMBOLS.items():
        if b[0] == '_':
            cx.m.set_label(a, b[1:])
            cx.disass(a)
        elif b[0] == '#':
            cx.m.set_label(a, b[1:])
            y = data.Data(cx.m, a, a + 1)
            y.rendered = ".CONST\t0x%04x" % cx.m[a]
        else:
            cx.m.set_label(a, b)

    pat4244024.appendix_b_1(cx, 0x3a49)
    pat4244024.appendix_b_2(cx, 0x3ac2)
    pat4244024.appendix_b_3(cx, 0x3ca5)
    pat4244024.appendix_b_4(cx, 0x3d2c)
    pat4244024.appendix_b_5(cx, 0x3d4b)
    pat4244024.appendix_b_7(cx, 0x3df0)
    pat4244024.appendix_b_8(cx, 0x3e02)
    pat4244024.appendix_b_9(cx, 0x3e13)
    pat4244024.appendix_b_10(cx, 0x3e30)
    pat4244024.appendix_b_11(cx, 0x3e4a)
    pat4244024.appendix_b_12(cx, 0x3e6c)
    pat4244024.appendix_b_13(cx, 0x3e78)
    pat4244024.appendix_b_15(cx, 0x3e86)
    pat4244024.appendix_b_16(cx, 0x3ebc)
    pat4244024.appendix_b_17(cx, 0x3ebf)
    pat4244024.appendix_b_18(cx, 0x3ec2)
    pat4244024.appendix_b_21(cx, 0x3a35)
    pat4244024.appendix_b_28a(cx, 0x0020)
    pat4244024.appendix_b_28b(cx, 0x0200)

    if True:
        for a in range(0x3ef, 0x40a):
            data.Const(cx.m, a, a + 1)
            y = wgstring(cx.m, cx.m[a])
            y.compact = True
        for a in range(0x1ebb, 0x1ec6):
            data.Const(cx.m, a, a + 1)
            y = wgstring(cx.m, cx.m[a])
            y.compact = True

    cx.disass(0x20)

    code.lcmt_flows(cx.m)

    return NAME, (cx.m,)
    def __init__(self, octets, output_file="/tmp/_", **kwargs):
        self.exp_ins = ExpDisass()
        m = mem.ByteMem(0, len(octets))
        for adr, octet in enumerate(octets):
            m[adr] = octet
        self.cx = mcs51.I8032()
        self.cx.m.map(m, 0)
        self.cx.vectors((
            "RESET",
            "RI_TI",
        ))

        self.common()

        self.distinct()

        code.lcmt_flows(self.cx.m)

        listing.Listing(self.cx.m,
                        fn=output_file,
                        align_blank=True,
                        align_xxx=True,
                        ncol=4,
                        **kwargs)
Esempio n. 3
0
def output(pj):
        code.lcmt_flows(pj)
        listing.Listing(pj, ncol = 4)
Esempio n. 4
0
def output(pj):
    code.lcmt_flows(pj)
    listing.Listing(pj)
Esempio n. 5
0
def do_one(fn, alist):

    print("--------------", fn)

    m = mem.byte_mem(0x000, 0x800)

    orig_src = dict()

    labels = dict()

    def load_xx(m):
        fi = open(fn)
        for i in fi:
            if i[0] != " ":
                continue
            j = i.strip()
            if j == "":
                continue
            j = i.split("*", 1)[0].rstrip()
            if len(j) < 15:
                continue
            if j[8] != "-":
                continue
            if not j[14].isdigit():
                continue
            if j[14:18] == "    ":
                continue
            a = int(j[14:18], 8)
            d = int(j[20:23], 8)
            orig_src[a] = j
            m.wr(a, d)
            lb = j[25:30].strip()
            if lb != "":
                labels[a] = lb
        fi.close()

    load_xx(m)

    pj = pyreveng.Job(m, "HP-9411")

    dx = hp_nanoproc.hp_nanoproc()

    if True:
        for i in alist:
            pj.todo(i, dx.disass)

    pj.apct = "%04o"
    pj.apct = "%03x"

    while pj.run():
        pass

    def fixit(i, a, b):
        if i == a.lo:
            # Check if there are instructions our disass don't know
            if a.mne != b[31:34]:
                print(a.im, b)
        a.lcmt += b + "\n"

    for i, j in orig_src.items():
        x = pj.t.find_range(i, i + 1)
        if len(x[1]) > 0:
            fixit(i, x[1][0], j)
        elif len(x[0]) > 0:
            fixit(i, x[0][0], j)
        else:
            x = pj.add(i, i + 1, "origsrc")
            x.lcmt += j + "\n"
            # print(x)

    for i in labels:
        pj.set_label(i, labels[i])

    if True:
        code.lcmt_flows(pj)
    listing.Listing(pj, fn="/tmp/_.HP" + fn, fmt="o", ncol=1)
Esempio n. 6
0
def output(pj):
	code.lcmt_flows(pj)
	listing.Listing(pj, "HP3455A_Inguard.lst")
Esempio n. 7
0
def task(pj, cx):

	if False:
		pj.a.address_space("xrom", m)
		pj.a.address_space("xdata", mem.address_space(0, 0x10000))
		pj.a.address_space("idata", mem.address_space(0, 0x100))

		for i in pj.a:
			print(i, pj.a[i])
		exit(0)


	cx.set_adr_mask(0xfff)

	cx.vectors(pj)

	# Random
	# pj.todo(0x7d2, cx.disass)

	for i in range(0, 0x18, 8):
		data.Txt(pj, 0x0a2 + i, 0x0a2 + i + 0x08, label=False)

	for i in range(0, 0x18, 8):
		data.Txt(pj, 0x78a + i, 0x78a + i + 0x08, label=False)

	#######################################################################

	while pj.run():
		pass


	code.lcmt_flows(pj)

	#######################################################################
	def cmd_func(a1, a2, n):
		pj.set_label(a1, "DO_CMD%d" % n)
		a = a2
		while True:
			if pj.m[a] != 0xb4:
				break
			c = pj.m[a + 1]
			d = pj.m[a + 2]
			pj.set_label(a, "CMD%d_%02x" % (n, c))
			a += 3 + d


	cmd_func(0xbf3, 0xbf7, 1)
	cmd_func(0x823, 0x827, 2)
	cmd_func(0x84f, 0x851, 3)
	#######################################################################

	pj.set_label(0x028, "ZERO_RAM")
	pj.set_label(0x039, "MAIN_LOOP")
	pj.set_label(0x050, "SETUP")
	pj.set_label(0x70e, "CHAR_XLAT")
	# 0x5b...0x5d are bits to blink characters
	pj.set_label(0x72e, "CHAR_BLINK")
	pj.set_label(0x76d, "WATCHDOG")
	pj.set_label(0x800, "MAIN_CMD")
	pj.set_label(0xc8c, "RX_INTR")
	pj.set_label(0xc54, "TX_INTR")

	#######################################################################
	for a in range(0xba, 0x100, 2):
		x = data.Const(pj, a, a + 2)
		x.typ = ".WORD"
		x.val = pj.m.lu16(a)
		x.fmt = "0x%04x" % x.val

	#######################################################################

	x = pj.add(0x100, 0x600, "chargen")
	x.rendered = "*CHARGEN*"
	x.compact = True

	if False:
		for c in range(256):
			print("%02x" % c)
			for r in range(8):
				s = ""
				j = 0x80 >> r
				for a in range(0x100, 0x600, 0x100):
					v = pj.m[a + c]
					if v & j:
						s += "#"
					else:
						s += "-"
				print(s)
			print("")
Esempio n. 8
0
def do_one(fn, alist):

    print("--------------", fn)

    m = mem.byte_mem(0x000, 0x800)

    orig_src = dict()

    labels = dict()

    def load_xx(m):
        fi = open(fn)
        for i in fi:
            if i[0] != ' ':
                continue
            j = i.strip()
            if j == "":
                continue
            j = i.split('*', 1)[0].rstrip()
            if len(j) < 15:
                continue
            if j[8] != "-":
                continue
            if not j[14].isdigit():
                continue
            if j[14:18] == '    ':
                continue
            a = int(j[14:18], 8)
            d = int(j[20:23], 8)
            orig_src[a] = j
            m.wr(a, d)
            lb = j[25:30].strip()
            if lb != "":
                labels[a] = lb
        fi.close()

    load_xx(m)

    pj = pyreveng.Job(m, "HP-9411")

    dx = hp_nanoproc.hp_nanoproc()

    if True:
        for i in alist:
            pj.todo(i, dx.disass)

    pj.apct = "%04o"
    pj.apct = "%03x"

    while pj.run():
        pass

    def fixit(i, a, b):
        if i == a.lo:
            # Check if there are instructions our disass don't know
            if a.mne != b[31:34]:
                print(a.im, b)
        a.lcmt += b + "\n"

    for i, j in orig_src.items():
        x = pj.t.find_range(i, i + 1)
        if len(x[1]) > 0:
            fixit(i, x[1][0], j)
        elif len(x[0]) > 0:
            fixit(i, x[0][0], j)
        else:
            x = pj.add(i, i + 1, "origsrc")
            x.lcmt += j + "\n"
            # print(x)

    for i in labels:
        pj.set_label(i, labels[i])

    if True:
        code.lcmt_flows(pj)
    listing.Listing(pj, fn="/tmp/_.HP" + fn, fmt="o", ncol=1)
Esempio n. 9
0
"""
Run all examples
"""

from __future__ import print_function

import glob, os, sys, importlib
from pyreveng import code, listing

if len(sys.argv) == 1:
    l = glob.glob("*/example*.py")
else:
    l = glob.glob(sys.argv[1] + "/example*.py")

try:
    os.mkdir("_output")
except:
    pass

l.sort()

for i in l:
    j = i.split("/")
    k = j[1].replace(".py", "")
    print(j[0], k)
    y = importlib.import_module(j[0] + "." + k)
    pj, cx = y.setup()
    y.task(pj, cx)
    code.lcmt_flows(pj)
    listing.Listing(pj, ncol=8, fn="_output/" + pj.name + ".txt")
Esempio n. 10
0
	hints(pj, cpu)

	symb(pj, cpu)

	if pj.pg == 4:
		lexer(pj)
		cpu.vectors(pj)

	while pj.run():
		pass

	while do_switch():
		continue

	while pj.run():
		pass

	prologues(pj, cpu)

	code.lcmt_flows(pj)

	listing.Listing(pj)

	import example2

	example2.analyse(pj)

	pj.name = pj.name + "_A"

	listing.Listing(pj)
Esempio n. 11
0
def output(pj):
	code.lcmt_flows(pj)
	listing.Listing(pj, "HP3455A_Inguard.lst")
Esempio n. 12
0
def task(pj, cx):

    if False:
        pj.a.address_space("xrom", m)
        pj.a.address_space("xdata", mem.address_space(0, 0x10000))
        pj.a.address_space("idata", mem.address_space(0, 0x100))

        for i in pj.a:
            print(i, pj.a[i])
        exit(0)

    cx.set_adr_mask(0xfff)

    cx.vectors(pj)

    # Random
    # pj.todo(0x7d2, cx.disass)

    for i in range(0, 0x18, 8):
        data.Txt(pj, 0x0a2 + i, 0x0a2 + i + 0x08, label=False)

    for i in range(0, 0x18, 8):
        data.Txt(pj, 0x78a + i, 0x78a + i + 0x08, label=False)

    #######################################################################

    while pj.run():
        pass

    code.lcmt_flows(pj)

    #######################################################################
    def cmd_func(a1, a2, n):
        pj.set_label(a1, "DO_CMD%d" % n)
        a = a2
        while True:
            if pj.m[a] != 0xb4:
                break
            c = pj.m[a + 1]
            d = pj.m[a + 2]
            pj.set_label(a, "CMD%d_%02x" % (n, c))
            a += 3 + d

    cmd_func(0xbf3, 0xbf7, 1)
    cmd_func(0x823, 0x827, 2)
    cmd_func(0x84f, 0x851, 3)
    #######################################################################

    pj.set_label(0x028, "ZERO_RAM")
    pj.set_label(0x039, "MAIN_LOOP")
    pj.set_label(0x050, "SETUP")
    pj.set_label(0x70e, "CHAR_XLAT")
    # 0x5b...0x5d are bits to blink characters
    pj.set_label(0x72e, "CHAR_BLINK")
    pj.set_label(0x76d, "WATCHDOG")
    pj.set_label(0x800, "MAIN_CMD")
    pj.set_label(0xc8c, "RX_INTR")
    pj.set_label(0xc54, "TX_INTR")

    #######################################################################
    for a in range(0xba, 0x100, 2):
        x = data.Const(pj, a, a + 2)
        x.typ = ".WORD"
        x.val = pj.m.lu16(a)
        x.fmt = "0x%04x" % x.val

    #######################################################################

    x = pj.add(0x100, 0x600, "chargen")
    x.rendered = "*CHARGEN*"
    x.compact = True

    if False:
        for c in range(256):
            print("%02x" % c)
            for r in range(8):
                s = ""
                j = 0x80 >> r
                for a in range(0x100, 0x600, 0x100):
                    v = pj.m[a + c]
                    if v & j:
                        s += "#"
                    else:
                        s += "-"
                print(s)
            print("")