xref: /openbsd-src/sys/arch/arm64/arm64/db_disasm.c (revision 311b6aa824a006e2f436474d9ba54b31c6d40a20)
1 /* $OpenBSD: db_disasm.c,v 1.4 2020/09/11 09:27:10 mpi Exp $ */
2 /* $NetBSD: db_disasm.c,v 1.10 2020/07/09 23:43:41 ryo Exp $ */
3 
4 /*
5  * Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <machine/db_machdep.h>
33 #include <ddb/db_interface.h>
34 #include <ddb/db_sym.h>
35 #include <ddb/db_output.h>
36 #include <ddb/db_access.h>
37 
38 #include <arch/arm64/arm64/disasm.h>
39 
40 static db_expr_t
db_disasm_readword(db_expr_t address)41 db_disasm_readword(db_expr_t address)
42 {
43 	return db_get_value(address, sizeof(uint32_t), false);
44 }
45 
46 static void
db_disasm_printaddr(db_expr_t address)47 db_disasm_printaddr(db_expr_t address)
48 {
49 	db_printf("%lx <", address);
50 	db_printsym((vaddr_t)address, DB_STGY_ANY, db_printf);
51 	db_printf(">");
52 }
53 
54 static const disasm_interface_t db_disasm_interface = {
55 	.di_readword = db_disasm_readword,
56 	.di_printaddr = db_disasm_printaddr,
57 	.di_printf = db_printf
58 };
59 
60 vaddr_t
db_disasm(vaddr_t loc,int altfmt)61 db_disasm(vaddr_t loc, int altfmt)
62 {
63 	return disasm(&db_disasm_interface, loc);
64 }
65