| Index: embios/trunk/tools/libembios.py |
| — | — | @@ -755,264 +755,146 @@ |
| 756 | 756 | self.__myprint(" done\n, thread ID: 0x%x" % (struct.unpack("<I", response[4:8])), silent)
|
| 757 | 757 |
|
| 758 | 758 |
|
| 759 | | - def getprocinfo(self, offset, size, silent = 0):
|
| | 759 | + def getprocinfo(self, silent = 0):
|
| 760 | 760 | """
|
| 761 | 761 | printout on console window:
|
| 762 | 762 | <silent> = 0: Process information struct version, Process information table size
|
| 763 | 763 | <silent> = 1: nothing
|
| 764 | | -
|
| 765 | | - {'regs': [16I], 'cpsr': I, 'state': I, 'namepointer': I, 'cputime_current': I, 'cputime_total': Q, 'startusec': I,
|
| 766 | | - 'queue_next_pointer': I, 'timeout': I, 'blocked_since': I, 'blocked_by_pointer': I, 'stackpointer': I, 'block_type': B, 'thread_type': B, 'priority': B, 'cpuload': B}
|
| 767 | 764 | """
|
| 768 | | - if (size > self.cin_maxsize - 0x10):
|
| 769 | | - raise Exception ("The data exceeds the maximum amount that can be received with this instruction.")
|
| 770 | 765 |
|
| | 766 | +
|
| 771 | 767 | self.__myprint("Retrieving process information...", silent)
|
| 772 | 768 |
|
| 773 | | - self.handle.bulkWrite(self.__coutep, struct.pack("<IIII", 15, offset, size, 0))
|
| 774 | | - response = self.__getbulk(self.handle, self.__cinep, size + 0x10)
|
| 775 | | - self.__checkstatus(response)
|
| | 769 | + offset = 0
|
| | 770 | + blocklen = size = self.cin_maxsize - 0x10
|
| | 771 | + procinfo = ""
|
| | 772 | + structversion = 0
|
| | 773 | + tablesize = 0
|
| 776 | 774 |
|
| 777 | | - out = []
|
| 778 | | - out[0] = struct.unpack("<I", response[4:8])[0] # Process information struct version
|
| 779 | | - out[1] = struct.unpack("<I", response[8:12])[0] # Process information table size
|
| 780 | | - out[2] = response # raw received data
|
| | 775 | + # reading loop
|
| | 776 | + while (offset < size):
|
| | 777 | + self.handle.bulkWrite(self.__coutep, struct.pack("<IIII", 15, offset, size, 0))
|
| | 778 | + response = self.__getbulk(self.handle, self.__cinep, size + 0x10)
|
| | 779 | + self.__checkstatus(response)
|
| | 780 | +
|
| | 781 | + size = struct.unpack("<I", response[8:12])[0]
|
| | 782 | +
|
| | 783 | + if size <= offset + blocklen:
|
| | 784 | + procinfo += response[0x10:0x10 + size]
|
| | 785 | + structversion = struct.unpack("<I", response[4:])
|
| | 786 | + tablesize = struct.unpack("<I", response[8:])
|
| | 787 | + break
|
| | 788 | + else:
|
| | 789 | + procinfo += response[0x10:0x10 + blocklen]
|
| | 790 | +
|
| | 791 | + size -= blocklen
|
| | 792 | + offset += blocklen
|
| | 793 | +
|
| | 794 | + blocklen = self.cin_maxsize - 0x10
|
| | 795 | + if blocklen > size:
|
| | 796 | + blocklen = size
|
| 781 | 797 |
|
| 782 | | - if (struct.unpack("<I", response[4:8])[0] == 1): # Process information struct version == 1
|
| 783 | | - p = 0x10
|
| 784 | | - process_n = 3 # actually process 0, but there are alread three other elements in out
|
| 785 | | - while True:
|
| 786 | | - # regs ==================================================
|
| 787 | | - keylen = 16
|
| 788 | | - key_offset = 0
|
| 789 | | -
|
| 790 | | - while (offset > 0) and (key_offset < 0x10):
|
| 791 | | - offset -= 0x4
|
| 792 | | - out[process_n]['regs'][key_offset] = None
|
| 793 | | - key_offset += 1
|
| 794 | | -
|
| 795 | | - while (p+(keylen*0x4) - 0x10 > size) and (keylen > 0): keylen -= 1
|
| 796 | | - if (p+(keylen*0x4) - 0x10 > size): break
|
| 797 | | -
|
| 798 | | - while (key_offset < keylen):
|
| 799 | | - out[process_n]['regs'][key_offset] = struct.unpack("<I", response[p + (key_offset * 0x4) :])[0]
|
| 800 | | - key_offset += 1
|
| 801 | | -
|
| 802 | | - p += 16 * 0x4
|
| 803 | | -
|
| 804 | | - # cpsr ==================================================
|
| 805 | | - if (offset > 0):
|
| 806 | | - offset -= 4
|
| 807 | | - out[process_n]['cpsr'] = None
|
| | 798 | +
|
| | 799 | + out = (structversion, tablesize, procinfotolist(procinfo, structversion))
|
| | 800 | +
|
| | 801 | + self.__myprint(" done\n\
|
| | 802 | + Process information struct version: 0x%08x\n\
|
| | 803 | + Total size of process information table: 0x%08x\n\
|
| | 804 | + %s\n\n"
|
| | 805 | + % (out[0], out[1], procinfotostring(out[2], structversion))
|
| | 806 | + , silent)
|
| | 807 | +
|
| | 808 | + return out
|
| | 809 | +
|
| | 810 | + def procinfotolist(self, processinfo, structver):
|
| | 811 | + if (structver == 1): # Process information struct version == 1
|
| | 812 | + ptr = 0x10
|
| | 813 | + process_n = 0
|
| | 814 | + retval = []
|
| | 815 | + while ptr < len(processinfo):
|
| | 816 | + retval.append({})
|
| 808 | 817 |
|
| 809 | | - if (p+0x4 - 0x10 > size): break
|
| 810 | | -
|
| 811 | | - out[process_n]['cpsr'] = struct.unpack("<I", response[p:])[0]
|
| 812 | | -
|
| 813 | | - p += 0x4
|
| 814 | | -
|
| 815 | | - # state =================================================
|
| 816 | | - if (offset > 0):
|
| 817 | | - offset -= 4
|
| 818 | | - out[process_n]['state'] = None
|
| | 818 | + retval[process_n]['regs'] = struct.unpack("<IIIIIIIIIIIIIIII", processinfo[ptr:])
|
| | 819 | + ptr += 16 * 0x4
|
| | 820 | + retval[process_n]['cpsr'] = struct.unpack("<I", processinfo[ptr:])
|
| | 821 | + ptr += 1 * 0x4
|
| | 822 | + retval[process_n]['state'] = struct.unpack("<I", processinfo[ptr:])
|
| | 823 | + ptr += 1 * 0x4
|
| | 824 | + retval[process_n]['name_ptr'] = struct.unpack("<I", processinfo[ptr:])
|
| | 825 | + ptr += 1 * 0x4
|
| | 826 | + retval[process_n]['cputime_current'] = struct.unpack("<I", processinfo[ptr:])
|
| | 827 | + ptr += 1 * 0x4
|
| | 828 | + retval[process_n]['cputime_total'] = struct.unpack("<Q", processinfo[ptr:])
|
| | 829 | + ptr += 1 * 0x8
|
| | 830 | + retval[process_n]['startusec'] = struct.unpack("<I", processinfo[ptr:])
|
| | 831 | + ptr += 1 * 0x4
|
| | 832 | + retval[process_n]['queue_next_ptr'] = struct.unpack("<I", processinfo[ptr:])
|
| | 833 | + ptr += 1 * 0x4
|
| | 834 | + retval[process_n]['timeout'] = struct.unpack("<I", processinfo[ptr:])
|
| | 835 | + ptr += 1 * 0x4
|
| | 836 | + retval[process_n]['blocked_since'] = struct.unpack("<I", processinfo[ptr:])
|
| | 837 | + ptr += 1 * 0x4
|
| | 838 | + retval[process_n]['blocked_by_ptr'] = struct.unpack("<I", processinfo[ptr:])
|
| | 839 | + ptr += 1 * 0x4
|
| | 840 | + retval[process_n]['stack_ptr'] = struct.unpack("<I", processinfo[ptr:])
|
| | 841 | + ptr += 1 * 0x4
|
| | 842 | + retval[process_n]['err_no'] = struct.unpack("<I", processinfo[ptr:])
|
| | 843 | + ptr += 1 * 0x4
|
| | 844 | + retval[process_n]['block_type'] = struct.unpack("<B", processinfo[ptr:])
|
| | 845 | + ptr += 1 * 0x1
|
| | 846 | + retval[process_n]['thread_type'] = struct.unpack("<B", processinfo[ptr:])
|
| | 847 | + ptr += 1 * 0x1
|
| | 848 | + retval[process_n]['priority'] = struct.unpack("<B", processinfo[ptr:])
|
| | 849 | + ptr += 1 * 0x1
|
| | 850 | + retval[process_n]['cpuload'] = struct.unpack("<B", processinfo[ptr:])
|
| | 851 | + ptr += 1 * 0x1
|
| 819 | 852 |
|
| 820 | | - if (p+0x4 - 0x10 > size): break
|
| 821 | | -
|
| 822 | | - out[process_n]['state'] = struct.unpack("<I", response[p:])[0]
|
| 823 | | -
|
| 824 | | - p += 0x4
|
| 825 | | -
|
| 826 | | - # namepointer ===========================================
|
| 827 | | - if (offset > 0):
|
| 828 | | - offset -= 4
|
| 829 | | - out[process_n]['namepointer'] = None
|
| | 853 | + process_n += 1
|
| 830 | 854 |
|
| 831 | | - if (p+0x4 - 0x10 > size): break
|
| 832 | | -
|
| 833 | | - out[process_n]['namepointer'] = struct.unpack("<I", response[p:])[0]
|
| 834 | | -
|
| 835 | | - p += 0x4
|
| 836 | | -
|
| 837 | | - # cputime_current =======================================
|
| 838 | | - if (offset > 0):
|
| 839 | | - offset -= 4
|
| 840 | | - out[process_n]['cputime_current'] = None
|
| | 855 | + return retval
|
| 841 | 856 |
|
| 842 | | - if (p+0x4 - 0x10 > size): break
|
| 843 | | -
|
| 844 | | - out[process_n]['cputime_current'] = struct.unpack("<I", response[p:])[0]
|
| 845 | | -
|
| 846 | | - p += 0x4
|
| 847 | | -
|
| 848 | | - # cputime_total =========================================
|
| 849 | | - if (offset > 0):
|
| 850 | | - offset -= 4
|
| 851 | | - out[process_n]['cputime_total'] = None
|
| 852 | | -
|
| 853 | | - if (p+0x4 - 0x10 > size): break
|
| 854 | | -
|
| 855 | | - out[process_n]['cputime_total'] = struct.unpack("<Q", response[p:])[0]
|
| 856 | | -
|
| 857 | | - p += 0x8
|
| 858 | | -
|
| 859 | | - # startusec =============================================
|
| 860 | | - if (offset > 0):
|
| 861 | | - offset -= 4
|
| 862 | | - out[process_n]['startusec'] = None
|
| 863 | | -
|
| 864 | | - if (p+0x4 - 0x10 > size): break
|
| 865 | | -
|
| 866 | | - out[process_n]['startusec'] = struct.unpack("<I", response[p:])[0]
|
| 867 | | -
|
| 868 | | - p += 0x4
|
| 869 | | -
|
| 870 | | - # queue_next_pointer ====================================
|
| 871 | | - if (offset > 0):
|
| 872 | | - offset -= 4
|
| 873 | | - out[process_n]['queue_next_pointer'] = None
|
| 874 | | -
|
| 875 | | - if (p+0x4 - 0x10 > size): break
|
| 876 | | -
|
| 877 | | - out[process_n]['queue_next_pointer'] = struct.unpack("<I", response[p:])[0]
|
| 878 | | -
|
| 879 | | - p += 0x4
|
| 880 | | -
|
| 881 | | - # timeout ===========================================
|
| 882 | | - if (offset > 0):
|
| 883 | | - offset -= 4
|
| 884 | | - out[process_n]['timeout'] = None
|
| 885 | | -
|
| 886 | | - if (p+0x4 - 0x10 > size): break
|
| 887 | | -
|
| 888 | | - out[process_n]['timeout'] = struct.unpack("<I", response[p:])[0]
|
| 889 | | -
|
| 890 | | - p += 0x4
|
| 891 | | -
|
| 892 | | - # blocked_since =========================================
|
| 893 | | - if (offset > 0):
|
| 894 | | - offset -= 4
|
| 895 | | - out[process_n]['blocked_since'] = None
|
| 896 | | -
|
| 897 | | - if (p+0x4 - 0x10 > size): break
|
| 898 | | -
|
| 899 | | - out[process_n]['blocked_since'] = struct.unpack("<I", response[p:])[0]
|
| 900 | | -
|
| 901 | | - p += 0x4
|
| 902 | | -
|
| 903 | | - # blocked_by_pointer ====================================
|
| 904 | | - if (offset > 0):
|
| 905 | | - offset -= 4
|
| 906 | | - out[process_n]['blocked_by_pointer'] = None
|
| 907 | | -
|
| 908 | | - if (p+0x4 - 0x10 > size): break
|
| 909 | | -
|
| 910 | | - out[process_n]['blocked_by_pointer'] = struct.unpack("<I", response[p:])[0]
|
| 911 | | -
|
| 912 | | - p += 0x4
|
| 913 | | -
|
| 914 | | - # stackpointer ==========================================
|
| 915 | | - if (offset > 0):
|
| 916 | | - offset -= 4
|
| 917 | | - out[process_n]['stackpointer'] = None
|
| 918 | | -
|
| 919 | | - if (p+0x4 - 0x10 > size): break
|
| 920 | | -
|
| 921 | | - out[process_n]['stackpointer'] = struct.unpack("<I", response[p:])[0]
|
| 922 | | -
|
| 923 | | - p += 0x4
|
| 924 | | -
|
| 925 | | - # block_type ============================================
|
| 926 | | - if (offset > 0):
|
| 927 | | - offset -= 1
|
| 928 | | - out[process_n]['block_type'] = None
|
| 929 | | -
|
| 930 | | - if (p+0x1 - 0x10 > size): break
|
| 931 | | -
|
| 932 | | - out[process_n]['block_type'] = struct.unpack("<B", response[p:])[0]
|
| 933 | | -
|
| 934 | | - p += 0x1
|
| 935 | | -
|
| 936 | | - # thread_type ===========================================
|
| 937 | | - if (offset > 0):
|
| 938 | | - offset -= 1
|
| 939 | | - out[process_n]['thread_type'] = None
|
| 940 | | -
|
| 941 | | - if (p+0x1 - 0x10 > size): break
|
| 942 | | -
|
| 943 | | - out[process_n]['thread_type'] = struct.unpack("<B", response[p:])[0]
|
| 944 | | -
|
| 945 | | - p += 0x1
|
| 946 | | -
|
| 947 | | - # priority ==============================================
|
| 948 | | - if (offset > 0):
|
| 949 | | - offset -= 1
|
| 950 | | - out[process_n]['priority'] = None
|
| 951 | | -
|
| 952 | | - if (p+0x1 - 0x10 > size): break
|
| 953 | | -
|
| 954 | | - out[process_n]['priority'] = struct.unpack("<B", response[p:])[0]
|
| 955 | | -
|
| 956 | | - p += 0x1
|
| 957 | | -
|
| 958 | | - # cpuload ===============================================
|
| 959 | | - if (offset > 0):
|
| 960 | | - offset -= 1
|
| 961 | | - out[process_n]['cpuload'] = None
|
| 962 | | -
|
| 963 | | - if (p+0x1 - 0x10 > size): break
|
| 964 | | -
|
| 965 | | - out[process_n]['cpuload'] = struct.unpack("<B", response[p:])[0]
|
| 966 | | -
|
| 967 | | - p += 0x1
|
| 968 | | -
|
| 969 | | - process_n += 1
|
| 970 | | -
|
| 971 | | - procinfoprint = ""
|
| | 857 | +
|
| 972 | 858 |
|
| 973 | | - try:
|
| 974 | | - i = 0
|
| 975 | | - while out[0] == 1 and not silent: # Process information struct version == 1 && !silent
|
| | 859 | + def procinfotostring(self, procinfolist, structver):
|
| | 860 | + processinfoprint = ""
|
| | 861 | + ptr = 0
|
| | 862 | + while structver == 1 and ptr < len(procinfolist): # Process information struct version == 1
|
| 976 | 863 | processinfoprint += "--------------------------------------------------------------------------------"
|
| 977 | 864 | processinfoprint += "R0: 0x%08x, R1: 0x%08x, R2: 0x%08x, R3: 0x%08x,\n\
|
| 978 | 865 | R4: 0x%08x, R5: 0x%08x, R6: 0x%08x, R7: 0x%08x,\n\
|
| 979 | 866 | R8: 0x%08x, R9: 0x%08x, R10: 0x%08x, R11: 0x%08x,\n\
|
| 980 | 867 | R12: 0x%08x, R13: 0x%08x, LR: 0x%08x, PC: 0x%08x\n" \
|
| 981 | | - % (out[i+3]['regs'][0], out[i+3]['regs'][1], out[i+3]['regs'][2], out[i+3]['regs'][3], \
|
| 982 | | - out[i+3]['regs'][4], out[i+3]['regs'][5], out[i+3]['regs'][6], out[i+3]['regs'][7], \
|
| 983 | | - out[i+3]['regs'][8], out[i+3]['regs'][9], out[i+3]['regs'][10], out[i+3]['regs'][11], \
|
| 984 | | - out[i+3]['regs'][12], out[i+3]['regs'][13], out[i+3]['regs'][14], out[i+3]['regs'][15] )
|
| 985 | | - processinfoprint += "cpsr: 0b%032b " % (out[i+3]['cpsr'])
|
| 986 | | - states = ["THREAD_FREE", "THREAD_SUSPENDED", "THREAD_READY", "THREAD_RUNNING", "THREAD_BLOCKED", "THREAD_DEFUNCT", "THREAD_DEFUNCT_ACK"]
|
| 987 | | - processinfoprint += "state: %s " % (states[out[i+3]['state']])
|
| 988 | | - processinfoprint += "nameptr: 0x%08x\n" % (out[i+3]['namepointer'])
|
| 989 | | - processinfoprint += "current cpu time: 0x%08x " % (out[i+3]['cputime_current'])
|
| 990 | | - processinfoprint += "total cpu time: 0x%016x\n" % (out[i+3]['cputime_total'])
|
| 991 | | - processinfoprint += "startusec: 0x%08x " % (out[i+3]['startusec'])
|
| 992 | | - processinfoprint += "queue next ptr: 0x%08x\n" % (out[i+3]['queue_next_pointer'])
|
| 993 | | - processinfoprint += "timeout: 0x%08x\n" % (out[i+3]['timeout'])
|
| 994 | | - processinfoprint += "blocked since: 0x%08x " % (out[i+3]['blocked_since'])
|
| 995 | | - processinfoprint += "blocked by ptr: 0x%08x\n" % (out[i+3]['blocked_by_pointer'])
|
| 996 | | - processinfoprint += "stackptr: 0x%08x " % (out[i+3]['stackpointer'])
|
| 997 | | - blocktype = ["THREAD_NOT_BLOCKED", "THREAD_BLOCK_SLEEP", "THREAD_BLOCK_MUTEX", "THREAD_BLOCK_WAKEUP", "THREAD_DEFUNCT_STKOV", "THREAD_DEFUNCT_PANIC"]
|
| 998 | | - processinfoprint += "block type: %s\n" % (blocktype[out[i+3]['block_type']])
|
| 999 | | - threadtype = ["USER_THREAD", "SYSTEM_THREAD"]
|
| 1000 | | - processinfoprint += "thread type: %s\n" % (threadtype[out[i+3]['thread_type']])
|
| 1001 | | - processinfoprint += "priority: 0x%02x " % (out[i+3]['priority'])
|
| 1002 | | - processinfoprint += "cpu load: 0x%02x\n" % (out[i+3]['cpuload'])
|
| | 868 | + % (procinfolist[ptr]['regs'][0], procinfolist[ptr]['regs'][1], procinfolist[ptr]['regs'][2], procinfolist[ptr]['regs'][3], \
|
| | 869 | + procinfolist[ptr]['regs'][4], procinfolist[ptr]['regs'][5], procinfolist[ptr]['regs'][6], procinfolist[ptr]['regs'][7], \
|
| | 870 | + procinfolist[ptr]['regs'][8], procinfolist[ptr]['regs'][9], procinfolist[ptr]['regs'][10], procinfolist[ptr]['regs'][11], \
|
| | 871 | + procinfolist[ptr]['regs'][12], procinfolist[ptr]['regs'][13], procinfolist[ptr]['regs'][14], procinfolist[ptr]['regs'][15] )
|
| | 872 | + processinfoprint += "cpsr: 0b%032b " % (procinfolist[ptr]['cpsr'])
|
| | 873 | + states = ("THREAD_FREE", "THREAD_SUSPENDED", "THREAD_READY", "THREAD_RUNNING", "THREAD_BLOCKED", "THREAD_DEFUNCT", "THREAD_DEFUNCT_ACK")
|
| | 874 | + processinfoprint += "state: %s " % (states[procinfolist[ptr]['state']])
|
| | 875 | + processinfoprint += "nameptr: 0x%08x\n" % (procinfolist[ptr]['name_ptr'])
|
| | 876 | + processinfoprint += "current cpu time: 0x%08x " % (procinfolist[ptr]['cputime_current'])
|
| | 877 | + processinfoprint += "total cpu time: 0x%016x\n" % (procinfolist[ptr]['cputime_total'])
|
| | 878 | + processinfoprint += "startusec: 0x%08x " % (procinfolist[ptr]['startusec'])
|
| | 879 | + processinfoprint += "queue next ptr: 0x%08x\n" % (procinfolist[ptr]['queue_next_ptr'])
|
| | 880 | + processinfoprint += "timeout: 0x%08x\n" % (procinfolist[ptr]['timeout'])
|
| | 881 | + processinfoprint += "blocked since: 0x%08x " % (procinfolist[ptr]['blocked_since'])
|
| | 882 | + processinfoprint += "blocked by ptr: 0x%08x\n" % (procinfolist[ptr]['blocked_by_ptr'])
|
| | 883 | + processinfoprint += "err_no: 0x%08x " % (procinfolist[ptr]['err_no'])
|
| | 884 | + processinfoprint += "nameptr: 0x%08x\n" % (procinfolist[ptr]['namepointer'])
|
| | 885 | + blocktype = ("THREAD_NOT_BLOCKED", "THREAD_BLOCK_SLEEP", "THREAD_BLOCK_MUTEX", "THREAD_BLOCK_WAKEUP", "THREAD_DEFUNCT_STKOV", "THREAD_DEFUNCT_PANIC")
|
| | 886 | + processinfoprint += "block type: %s\n" % (blocktype[procinfolist[ptr]['block_type']])
|
| | 887 | + threadtype = ("USER_THREAD", "SYSTEM_THREAD")
|
| | 888 | + processinfoprint += "thread type: %s\n" % (threadtype[procinfolist[ptr]['thread_type']])
|
| | 889 | + processinfoprint += "priority: 0x%02x " % (procinfolist[ptr]['priority'])
|
| | 890 | + processinfoprint += "cpu load: 0x%02x\n" % (procinfolist[ptr]['cpuload'])
|
| 1003 | 891 |
|
| 1004 | | - i += 1
|
| 1005 | | -
|
| 1006 | | - except IndexError:
|
| | 892 | + ptr += 1
|
| | 893 | +
|
| 1007 | 894 | processinfoprint += "--------------------------------------------------------------------------------"
|
| | 895 | +
|
| | 896 | + return processinfoprint
|
| 1008 | 897 |
|
| 1009 | | - self.__myprint(" done\n\
|
| 1010 | | - Process information struct version: 0x%08x\n\
|
| 1011 | | - Total size of process information table: 0x%08x\n\
|
| 1012 | | - %s"
|
| 1013 | | - % (out[0], out[1], procinfoprint)
|
| 1014 | | - , silent)
|
| 1015 | 898 |
|
| 1016 | | - return out
|
| 1017 | 899 |
|
| 1018 | 900 |
|
| 1019 | 901 | def execimage(self, offset, silent = 0):
|