2 * Kernel Debugger Architecture Dependent Instruction Disassembly
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/ctype.h>
15 #include <linux/string.h>
16 #include <linux/kdb.h>
17 #include <linux/kdbprivate.h>
22 * Get a symbol for the disassembler.
25 * addr Address for which to get symbol
26 * dip Pointer to disassemble_info
36 kdba_dis_getsym(bfd_vma addr, disassemble_info *dip)
45 * Print (symbolically) an address.
48 * addr Address for which to get symbol
49 * dip Pointer to disassemble_info
50 * flag True if a ":<tab>" sequence should follow the address
60 kdba_printaddress(kdb_machreg_t addr, disassemble_info *dip, int flag)
67 * Print a symbol name or address as necessary.
69 kdbnearsym(addr, &symtab);
70 if (symtab.sym_name) {
71 /* Do not use kdb_symbol_print here, it always does
72 * kdb_printf but we want dip->fprintf_func.
74 dip->fprintf_func(dip->stream,
76 2*sizeof(addr), addr, symtab.sym_name);
77 if ((offset = addr - symtab.sym_start) == 0) {
81 unsigned int o = offset;
84 dip->fprintf_func(dip->stream, "+0x%x", offset);
88 dip->fprintf_func(dip->stream, "0x%x", addr);
95 dip->fprintf_func(dip->stream, ":%*s", spaces, " ");
102 * Print (symbolically) an address. Called by GNU disassembly
103 * code via disassemble_info structure.
106 * addr Address for which to get symbol
107 * dip Pointer to disassemble_info
112 * This function will never append ":<tab>" to the printed
117 kdba_dis_printaddr(bfd_vma addr, disassemble_info *dip)
119 kdba_printaddress(addr, dip, 0);
125 * Fetch 'length' bytes from 'addr' into 'buf'.
128 * addr Address for which to get symbol
129 * buf Address of buffer to fill with bytes from 'addr'
130 * length Number of bytes to fetch
131 * dip Pointer to disassemble_info
133 * 0 if data is available, otherwise error.
141 kdba_dis_getmem(bfd_vma addr, bfd_byte *buf, unsigned int length, disassemble_info *dip)
143 return kdb_getarea_size(buf, addr, length);
149 * Parse IDMODE environment variable string and
150 * set appropriate value into "disassemble_info" structure.
154 * dip Disassemble_info structure pointer
158 * We handle the values 'x86' and '8086' to enable either
159 * 32-bit instruction set or 16-bit legacy instruction set.
163 kdba_id_parsemode(const char *mode, disassemble_info *dip)
167 if (strcmp(mode, "x86") == 0) {
168 dip->mach = bfd_mach_i386_i386;
169 } else if (strcmp(mode, "8086") == 0) {
170 dip->mach = bfd_mach_i386_i8086;
182 * Check that the pc is satisfactory.
185 * pc Program Counter Value.
195 kdba_check_pc(kdb_machreg_t *pc)
203 * Format and print a single instruction at 'pc'. Return the
204 * length of the instruction.
207 * pc Program Counter Value.
208 * dip Disassemble_info structure pointer
210 * Length of instruction, -1 for error.
214 * Depends on 'IDMODE' environment variable.
218 kdba_id_printinsn(kdb_machreg_t pc, disassemble_info *dip)
220 kdba_printaddress(pc, dip, 1);
221 return print_insn_i386_att(pc, dip);
227 * Initialize the architecture dependent elements of
228 * the disassembly information structure
229 * for the GNU disassembler.
243 kdba_id_init(disassemble_info *dip)
245 dip->read_memory_func = kdba_dis_getmem;
246 dip->print_address_func = kdba_dis_printaddr;
247 dip->symbol_at_address_func = kdba_dis_getsym;
249 dip->flavour = bfd_target_elf_flavour;
250 dip->arch = bfd_arch_i386;
251 dip->mach = bfd_mach_i386_i386;
252 dip->endian = BFD_ENDIAN_LITTLE;
254 dip->display_endian = BFD_ENDIAN_LITTLE;