xref: /netbsd-src/usr.sbin/crash/arch/mips.c (revision d914a3c1b942947a8b1fa87645678df29ac8e6ab)
1*d914a3c1Smrg /*	$NetBSD: mips.c,v 1.2 2021/12/11 19:24:22 mrg Exp $	*/
24d62e245Smrg 
34d62e245Smrg /*
44d62e245Smrg  * Copyright (c) 2020 Matthew R. Green
54d62e245Smrg  * All rights reserved.
64d62e245Smrg  *
74d62e245Smrg  * Redistribution and use in source and binary forms, with or without
84d62e245Smrg  * modification, are permitted provided that the following conditions
94d62e245Smrg  * are met:
104d62e245Smrg  * 1. Redistributions of source code must retain the above copyright
114d62e245Smrg  *    notice, this list of conditions and the following disclaimer.
124d62e245Smrg  * 2. Redistributions in binary form must reproduce the above copyright
134d62e245Smrg  *    notice, this list of conditions and the following disclaimer in the
144d62e245Smrg  *    documentation and/or other materials provided with the distribution.
154d62e245Smrg  *
164d62e245Smrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
174d62e245Smrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
184d62e245Smrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
194d62e245Smrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
204d62e245Smrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
214d62e245Smrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
224d62e245Smrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
234d62e245Smrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
244d62e245Smrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254d62e245Smrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264d62e245Smrg  * SUCH DAMAGE.
274d62e245Smrg  */
284d62e245Smrg 
294d62e245Smrg #include <sys/cdefs.h>
304d62e245Smrg #ifndef lint
31*d914a3c1Smrg __RCSID("$NetBSD: mips.c,v 1.2 2021/12/11 19:24:22 mrg Exp $");
324d62e245Smrg #endif /* not lint */
334d62e245Smrg 
344d62e245Smrg #include <ddb/ddb.h>
354d62e245Smrg 
364d62e245Smrg #include <kvm.h>
374d62e245Smrg #include <nlist.h>
384d62e245Smrg #include <err.h>
394d62e245Smrg #include <stdlib.h>
404d62e245Smrg 
414d62e245Smrg #include <machine/pcb.h>
424d62e245Smrg 
434d62e245Smrg #include "extern.h"
444d62e245Smrg 
454d62e245Smrg static struct nlist nl[] = {
464d62e245Smrg 	{ .n_name = "dumppcb" },
474d62e245Smrg 	{ .n_name = "cpu_switchto" },
484d62e245Smrg 	{ .n_name = NULL },
494d62e245Smrg };
504d62e245Smrg 
514d62e245Smrg struct pcb	pcb;
524d62e245Smrg 
534d62e245Smrg void
db_mach_init(kvm_t * kd)544d62e245Smrg db_mach_init(kvm_t *kd)
554d62e245Smrg {
564d62e245Smrg 
574d62e245Smrg 	if (kvm_nlist(kd, nl) == -1) {
584d62e245Smrg 		errx(EXIT_FAILURE, "kvm_nlist: %s", kvm_geterr(kd));
594d62e245Smrg 	}
604d62e245Smrg 	if ((size_t)kvm_read(kd, nl[0].n_value, &pcb, sizeof(pcb)) !=
614d62e245Smrg 	    sizeof(pcb)) {
624d62e245Smrg 		warnx("cannot read dumppcb: %s", kvm_geterr(kd));
634d62e245Smrg 	}
644d62e245Smrg }
654d62e245Smrg 
664d62e245Smrg /* Provided for db_trace.c. */
674d62e245Smrg vaddr_t
db_mach_addr_cpuswitch(void)684d62e245Smrg db_mach_addr_cpuswitch(void)
694d62e245Smrg {
704d62e245Smrg 	return (vaddr_t)nl[1].n_value;
714d62e245Smrg }
72