xref: /freebsd/usr.bin/gcore/elf32core.c (revision 3cbb4cc200f8a0ad7ed08233425ea54524a21f1c)
1 /* $FreeBSD$ */
2 #ifndef __LP64__
3 #error "this file must be compiled for LP64."
4 #endif
5 
6 #define __ELF_WORD_SIZE 32
7 #define _MACHINE_ELF_WANT_32BIT
8 #define	_WANT_LWPINFO32
9 
10 #include <sys/procfs.h>
11 
12 #define	ELFCORE_COMPAT_32	1
13 #include "elfcore.c"
14 
15 static void
16 elf_convert_gregset(elfcore_gregset_t *rd, struct reg *rs)
17 {
18 #ifdef __amd64__
19 	rd->r_gs = rs->r_gs;
20 	rd->r_fs = rs->r_fs;
21 	rd->r_es = rs->r_es;
22 	rd->r_ds = rs->r_ds;
23 	rd->r_edi = rs->r_rdi;
24 	rd->r_esi = rs->r_rsi;
25 	rd->r_ebp = rs->r_rbp;
26 	rd->r_ebx = rs->r_rbx;
27 	rd->r_edx = rs->r_rdx;
28 	rd->r_ecx = rs->r_rcx;
29 	rd->r_eax = rs->r_rax;
30 	rd->r_eip = rs->r_rip;
31 	rd->r_cs = rs->r_cs;
32 	rd->r_eflags = rs->r_rflags;
33 	rd->r_esp = rs->r_rsp;
34 	rd->r_ss = rs->r_ss;
35 #elif defined(__aarch64__)
36 	int i;
37 
38 	for (i = 0; i < 13; i++)
39 		rd->r[i] = rs->x[i];
40 	rd->r_sp = rs->x[13];
41 	rd->r_lr = rs->x[14];
42 	rd->r_pc = rs->elr;
43 	rd->r_cpsr = rs->spsr;
44 #elif defined(__powerpc64__)
45 	int i;
46 
47 	for (i = 0; i < 32; i++)
48 		rd->fixreg[i] = rs->fixreg[i];
49 	rd->lr = rs->lr;
50 	rd->cr = rs->cr;
51 	rd->xer = rs->xer;
52 	rd->ctr = rs->ctr;
53 	rd->pc = rs->pc;
54 #else
55 #error Unsupported architecture
56 #endif
57 }
58 
59 static void
60 elf_convert_fpregset(elfcore_fpregset_t *rd, struct fpreg *rs)
61 {
62 #ifdef __amd64__
63 	/* XXX this is wrong... */
64 	memcpy(rd, rs, sizeof(*rd));
65 #elif defined(__aarch64__)
66 	/* ARM64TODO */
67 #elif defined(__powerpc64__)
68 	memcpy(rd, rs, sizeof(*rd));
69 #else
70 #error Unsupported architecture
71 #endif
72 }
73 
74 static void
75 elf_convert_siginfo(struct siginfo32 *sid, siginfo_t *sis)
76 {
77 
78 	bzero(sid, sizeof(*sid));
79 	sid->si_signo = sis->si_signo;
80 	sid->si_errno = sis->si_errno;
81 	sid->si_code = sis->si_code;
82 	sid->si_pid = sis->si_pid;
83 	sid->si_uid = sis->si_uid;
84 	sid->si_status = sis->si_status;
85 	sid->si_addr = (uintptr_t)sis->si_addr;
86 #if _BYTE_ORDER == _BIG_ENDIAN
87 	if (sis->si_value.sival_int == 0)
88 		sid->si_value.sival_ptr = (uintptr_t)sis->si_value.sival_ptr;
89 	else
90 #endif
91 		sid->si_value.sival_int = sis->si_value.sival_int;
92 	sid->si_timerid = sis->si_timerid;
93 	sid->si_overrun = sis->si_overrun;
94 }
95 
96 static void
97 elf_convert_lwpinfo(struct ptrace_lwpinfo32 *pld, struct ptrace_lwpinfo *pls)
98 {
99 
100 	pld->pl_lwpid = pls->pl_lwpid;
101 	pld->pl_event = pls->pl_event;
102 	pld->pl_flags = pls->pl_flags;
103 	pld->pl_sigmask = pls->pl_sigmask;
104 	pld->pl_siglist = pls->pl_siglist;
105 	elf_convert_siginfo(&pld->pl_siginfo, &pls->pl_siginfo);
106 	memcpy(pld->pl_tdname, pls->pl_tdname, sizeof(pld->pl_tdname));
107 	pld->pl_child_pid = pls->pl_child_pid;
108 	pld->pl_syscall_code = pls->pl_syscall_code;
109 	pld->pl_syscall_narg = pls->pl_syscall_narg;
110 }
111 
112