| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: disassem.c,v 1.23 2014/01/10 23:52:53 matt Exp $ */ | | 1 | /* $NetBSD: disassem.c,v 1.24 2014/03/03 08:51:39 matt Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996 Mark Brinicombe. | | 4 | * Copyright (c) 1996 Mark Brinicombe. |
5 | * Copyright (c) 1996 Brini. | | 5 | * Copyright (c) 1996 Brini. |
6 | * | | 6 | * |
7 | * All rights reserved. | | 7 | * All rights reserved. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -39,27 +39,27 @@ | | | @@ -39,27 +39,27 @@ |
39 | * | | 39 | * |
40 | * Kernel disassembler | | 40 | * Kernel disassembler |
41 | * | | 41 | * |
42 | * Created : 10/02/96 | | 42 | * Created : 10/02/96 |
43 | * | | 43 | * |
44 | * Structured after the sparc/sparc/db_disasm.c by David S. Miller & | | 44 | * Structured after the sparc/sparc/db_disasm.c by David S. Miller & |
45 | * Paul Kranenburg | | 45 | * Paul Kranenburg |
46 | * | | 46 | * |
47 | * This code is not complete. Not all instructions are disassembled. | | 47 | * This code is not complete. Not all instructions are disassembled. |
48 | */ | | 48 | */ |
49 | | | 49 | |
50 | #include <sys/param.h> | | 50 | #include <sys/param.h> |
51 | | | 51 | |
52 | __KERNEL_RCSID(0, "$NetBSD: disassem.c,v 1.23 2014/01/10 23:52:53 matt Exp $"); | | 52 | __KERNEL_RCSID(0, "$NetBSD: disassem.c,v 1.24 2014/03/03 08:51:39 matt Exp $"); |
53 | | | 53 | |
54 | #include <sys/systm.h> | | 54 | #include <sys/systm.h> |
55 | | | 55 | |
56 | #include <arch/arm/arm/disassem.h> | | 56 | #include <arch/arm/arm/disassem.h> |
57 | #include <arm/armreg.h> | | 57 | #include <arm/armreg.h> |
58 | | | 58 | |
59 | #ifndef _KERNEL | | 59 | #ifndef _KERNEL |
60 | #include <stdio.h> | | 60 | #include <stdio.h> |
61 | #endif | | 61 | #endif |
62 | | | 62 | |
63 | /* | | 63 | /* |
64 | * General instruction format | | 64 | * General instruction format |
65 | * | | 65 | * |
| @@ -112,48 +112,61 @@ __KERNEL_RCSID(0, "$NetBSD: disassem.c,v | | | @@ -112,48 +112,61 @@ __KERNEL_RCSID(0, "$NetBSD: disassem.c,v |
112 | * # - co-processor number | | 112 | * # - co-processor number |
113 | */ | | 113 | */ |
114 | | | 114 | |
115 | struct arm32_insn { | | 115 | struct arm32_insn { |
116 | u_int mask; | | 116 | u_int mask; |
117 | u_int pattern; | | 117 | u_int pattern; |
118 | const char* name; | | 118 | const char* name; |
119 | const char* format; | | 119 | const char* format; |
120 | }; | | 120 | }; |
121 | | | 121 | |
122 | static const struct arm32_insn arm32_i[] = { | | 122 | static const struct arm32_insn arm32_i[] = { |
123 | { 0x0fffffff, 0x0ff00000, "imb", "c" }, /* Before swi */ | | 123 | { 0x0fffffff, 0x0ff00000, "imb", "c" }, /* Before swi */ |
124 | { 0x0fffffff, 0x0ff00001, "imbrange", "c" }, /* Before swi */ | | 124 | { 0x0fffffff, 0x0ff00001, "imbrange", "c" }, /* Before swi */ |
| | | 125 | { 0x0fffffff, 0x0320f003, "yield", "" }, /* Before swi */ |
| | | 126 | { 0x0fffffff, 0x0320f002, "wfe", "" }, /* Before swi */ |
| | | 127 | { 0x0fffffff, 0x0320f003, "wfi", "" }, /* Before swi */ |
125 | { 0x0f000000, 0x0f000000, "swi", "c" }, | | 128 | { 0x0f000000, 0x0f000000, "swi", "c" }, |
126 | { 0xfe000000, 0xfa000000, "blx", "t" }, /* Before b and bl */ | | 129 | { 0xfe000000, 0xfa000000, "blx", "t" }, /* Before b and bl */ |
127 | { 0x0f000000, 0x0a000000, "b", "b" }, | | 130 | { 0x0f000000, 0x0a000000, "b", "b" }, |
128 | { 0x0f000000, 0x0b000000, "bl", "b" }, | | 131 | { 0x0f000000, 0x0b000000, "bl", "b" }, |
129 | { 0x0fe000f0, 0x00000090, "mul", "Snms" }, | | 132 | { 0x0fe000f0, 0x00000090, "mul", "Snms" }, |
130 | { 0x0fe000f0, 0x00200090, "mla", "Snmsd" }, | | 133 | { 0x0fe000f0, 0x00200090, "mla", "Snmsd" }, |
131 | { 0x0fe000f0, 0x00800090, "umull", "Sdnms" }, | | 134 | { 0x0fe000f0, 0x00800090, "umull", "Sdnms" }, |
132 | { 0x0fe000f0, 0x00c00090, "smull", "Sdnms" }, | | 135 | { 0x0fe000f0, 0x00c00090, "smull", "Sdnms" }, |
133 | { 0x0fe000f0, 0x00a00090, "umlal", "Sdnms" }, | | 136 | { 0x0fe000f0, 0x00a00090, "umlal", "Sdnms" }, |
134 | { 0x0fe000f0, 0x00e00090, "smlal", "Sdnms" }, | | 137 | { 0x0fe000f0, 0x00e00090, "smlal", "Sdnms" }, |
135 | { 0x0d700000, 0x04200000, "strt", "daW" }, | | 138 | { 0x0d700000, 0x04200000, "strt", "daW" }, |
136 | { 0x0d700000, 0x04300000, "ldrt", "daW" }, | | 139 | { 0x0d700000, 0x04300000, "ldrt", "daW" }, |
137 | { 0x0d700000, 0x04600000, "strbt", "daW" }, | | 140 | { 0x0d700000, 0x04600000, "strbt", "daW" }, |
138 | { 0x0d700000, 0x04700000, "ldrbt", "daW" }, | | 141 | { 0x0d700000, 0x04700000, "ldrbt", "daW" }, |
139 | { 0x0c500000, 0x04000000, "str", "daW" }, | | 142 | { 0x0c500000, 0x04000000, "str", "daW" }, |
140 | { 0x0c500000, 0x04100000, "ldr", "daW" }, | | 143 | { 0x0c500000, 0x04100000, "ldr", "daW" }, |
141 | { 0x0c500000, 0x04400000, "strb", "daW" }, | | 144 | { 0x0c500000, 0x04400000, "strb", "daW" }, |
142 | { 0x0c500000, 0x04500000, "ldrb", "daW" }, | | 145 | { 0x0c500000, 0x04500000, "ldrb", "daW" }, |
| | | 146 | { 0x0fff0000, 0x092d0000, "push", "l" }, /* separate out r13 base */ |
| | | 147 | { 0x0fff0000, 0x08bd0000, "pop", "l" }, /* separate out r13 base */ |
143 | { 0x0e1f0000, 0x080d0000, "stm", "YnWl" },/* separate out r13 base */ | | 148 | { 0x0e1f0000, 0x080d0000, "stm", "YnWl" },/* separate out r13 base */ |
144 | { 0x0e1f0000, 0x081d0000, "ldm", "YnWl" },/* separate out r13 base */ | | 149 | { 0x0e1f0000, 0x081d0000, "ldm", "YnWl" },/* separate out r13 base */ |
145 | { 0x0e100000, 0x08000000, "stm", "XnWl" }, | | 150 | { 0x0e100000, 0x08000000, "stm", "XnWl" }, |
146 | { 0x0e100000, 0x08100000, "ldm", "XnWl" }, | | 151 | { 0x0e100000, 0x08100000, "ldm", "XnWl" }, |
| | | 152 | { 0x0ff00fff, 0x01900f9f, "ldrex", "da" }, |
| | | 153 | { 0x0ff00fff, 0x01b00f9f, "ldrexd", "da" }, |
| | | 154 | { 0x0ff00fff, 0x01d00f9f, "ldrexb", "da" }, |
| | | 155 | { 0x0ff00fff, 0x01f00f9f, "ldrexh", "da" }, |
| | | 156 | { 0x0ff00ff0, 0x01800f90, "strex", "dma" }, |
| | | 157 | { 0x0ff00ff0, 0x01a00f90, "strexd", "dma" }, |
| | | 158 | { 0x0ff00ff0, 0x01c00f90, "strexb", "dma" }, |
| | | 159 | { 0x0ff00ff0, 0x01e00f90, "strexh", "dma" }, |
147 | { 0x0e1000f0, 0x00100090, "ldrb", "de" }, | | 160 | { 0x0e1000f0, 0x00100090, "ldrb", "de" }, |
148 | { 0x0e1000f0, 0x00000090, "strb", "de" }, | | 161 | { 0x0e1000f0, 0x00000090, "strb", "de" }, |
149 | { 0x0e1000f0, 0x001000d0, "ldrsb", "de" }, | | 162 | { 0x0e1000f0, 0x001000d0, "ldrsb", "de" }, |
150 | { 0x0e1000f0, 0x001000b0, "ldrh", "de" }, | | 163 | { 0x0e1000f0, 0x001000b0, "ldrh", "de" }, |
151 | { 0x0e1000f0, 0x000000b0, "strh", "de" }, | | 164 | { 0x0e1000f0, 0x000000b0, "strh", "de" }, |
152 | { 0x0e1000f0, 0x001000f0, "ldrsh", "de" }, | | 165 | { 0x0e1000f0, 0x001000f0, "ldrsh", "de" }, |
153 | { 0x0f200090, 0x00200090, "und", "x" }, /* Before data processing */ | | 166 | { 0x0f200090, 0x00200090, "und", "x" }, /* Before data processing */ |
154 | { 0x0e1000d0, 0x000000d0, "und", "x" }, /* Before data processing */ | | 167 | { 0x0e1000d0, 0x000000d0, "und", "x" }, /* Before data processing */ |
155 | { 0x0ff00ff0, 0x01000090, "swp", "dmo" }, | | 168 | { 0x0ff00ff0, 0x01000090, "swp", "dmo" }, |
156 | { 0x0ff00ff0, 0x01400090, "swpb", "dmo" }, | | 169 | { 0x0ff00ff0, 0x01400090, "swpb", "dmo" }, |
157 | { 0x0fbf0fff, 0x010f0000, "mrs", "dp" }, /* Before data processing */ | | 170 | { 0x0fbf0fff, 0x010f0000, "mrs", "dp" }, /* Before data processing */ |
158 | { 0x0fb0fff0, 0x0120f000, "msr", "pFm" },/* Before data processing */ | | 171 | { 0x0fb0fff0, 0x0120f000, "msr", "pFm" },/* Before data processing */ |
159 | { 0x0fe0f000, 0x0320f000, "msr", "pF2" },/* Before data processing */ | | 172 | { 0x0fe0f000, 0x0320f000, "msr", "pF2" },/* Before data processing */ |
| @@ -657,27 +670,28 @@ disasm_insn_ldrstr(const disasm_interfac | | | @@ -657,27 +670,28 @@ disasm_insn_ldrstr(const disasm_interfac |
657 | { | | 670 | { |
658 | int offset; | | 671 | int offset; |
659 | | | 672 | |
660 | offset = insn & 0xfff; | | 673 | offset = insn & 0xfff; |
661 | if ((insn & 0x032f0000) == 0x010f0000) { | | 674 | if ((insn & 0x032f0000) == 0x010f0000) { |
662 | /* rA = pc, immediate index */ | | 675 | /* rA = pc, immediate index */ |
663 | if (insn & 0x00800000) | | 676 | if (insn & 0x00800000) |
664 | loc += offset; | | 677 | loc += offset; |
665 | else | | 678 | else |
666 | loc -= offset; | | 679 | loc -= offset; |
667 | di->di_printaddr(loc + 8); | | 680 | di->di_printaddr(loc + 8); |
668 | } else { | | 681 | } else { |
669 | di->di_printf("[r%d", (insn >> 16) & 0x0f); | | 682 | di->di_printf("[r%d", (insn >> 16) & 0x0f); |
670 | if ((insn & 0x03000fff) != 0x01000000) { | | 683 | if ((insn & 0x03000fff) != 0x01000000 |
| | | 684 | && (insn & 0x0f800ff0) != 0x01800f90) { |
671 | di->di_printf("%s, ", (insn & (1 << 24)) ? "" : "]"); | | 685 | di->di_printf("%s, ", (insn & (1 << 24)) ? "" : "]"); |
672 | if (!(insn & 0x00800000)) | | 686 | if (!(insn & 0x00800000)) |
673 | di->di_printf("-"); | | 687 | di->di_printf("-"); |
674 | if (insn & (1 << 25)) | | 688 | if (insn & (1 << 25)) |
675 | disasm_register_shift(di, insn); | | 689 | disasm_register_shift(di, insn); |
676 | else | | 690 | else |
677 | di->di_printf("#0x%03x", offset); | | 691 | di->di_printf("#0x%03x", offset); |
678 | } | | 692 | } |
679 | if (insn & (1 << 24)) | | 693 | if (insn & (1 << 24)) |
680 | di->di_printf("]"); | | 694 | di->di_printf("]"); |
681 | } | | 695 | } |
682 | } | | 696 | } |
683 | | | 697 | |