1 /*---------------------------------------------------------------------------*
2   Project:  Cafe
3   File:     ppc_disasm.h
4 
5   Copyright 2011 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13  *---------------------------------------------------------------------------*/
14 
15 #ifndef __PPCDISASM_H__
16 #define __PPCDISASM_H__
17 
18 #define PPC_DISASM_MIN_BUFFER      32
19 #define PPC_DISASM_MAX_BUFFER      64
20 #define PPC_DISASM_MAX_FUNC_BUFFER 256
21 
22 /* PPC Disassembly Options */
23 #define PPC_DISASM_DEFAULT     0x00000000  // use defaults
24 #define PPC_DISASM_SIMPLIFY    0x00000001  // use simplified mnemonics
25 #define PPC_DISASM_REG_SPACES  0x00000020  // emit spaces between registers
26 #define PPC_DISASM_EMIT_DISASM 0x00000040  // emit only disassembly
27 #define PPC_DISASM_EMIT_ADDR   0x00000080  // emit only addresses + disassembly
28 #define PPC_DISASM_EMIT_FUNCS  0x00000100  // emit function names before and during disassembly
29 
30 #include <types.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* DisasmReport is a callback for disasm use to print */
37 /* sprintf can be substituted to print into a buffer  */
38 typedef void (*DisasmReport)(char* outputBuffer, ...);
39 
40 /* DisasmGetSym is a callback for disasm to use to fetch the closest symbol names */
41 /* returns address of symbol-name or NULL                                         */
42 typedef void* (*DisasmGetSym) (unsigned long addr,
43                                unsigned char *symbolName,
44                                unsigned long nameBufSize);
45 
46 /* DisasmGetFuncSym is a callback for disasm to use to fetch the closest symbol names */
47 /* for specific functions so that we can print the nearest function name while        */
48 /* disassembling. Returns address of symbol-name or NULL                              */
49 typedef void* (*DisasmGetFuncSym) (unsigned long addr,
50                                    unsigned char *symbolName,
51                                    unsigned long nameBufSize);
52 
53 BOOL
54 DisassemblePPCOpcode(u32          *opcode,
55                      char         *outputBuffer,
56                      u32          bufferSize,
57                      DisasmGetSym disasmGetSym,
58                      u32          disasmOptions);
59 
60 void
61 DisassemblePPCRange(void            *rangeStart,
62                     void            *rangeEnd,
63                     DisasmReport     disasmReport,
64                     DisasmGetSym     disasmGetSym,
65                     u32              disasmOptions);
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif  // __PPCDISASM_H__
72 
73