2 * Copyright (C) 2013 Spreadtrum Communications Inc.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
18 #include <linux/types.h>
20 #define SYSDUMP_CORE_NAME_FMT "sysdump.core.%02d" /* time, number */
21 #define NR_KCORE_MEM 80
22 #define SYSDUMP_MAGIC "SPRD_SYSDUMP_119"
24 #define CONFIG_PHYS_OFFSET 0x80000000
25 #define PAGE_OFFSET 0xC0000000
27 #ifndef REAL_SDRAM_SIZE
28 #define REAL_SDRAM_SIZE 0x40000000 /*dump 1G ram*/
33 #define PAGE_SIZE (1UL << PAGE_SHIFT)
36 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
53 unsigned long dump_mem_paddr;
64 #define CORE_STR "CORE"
65 #ifndef ELF_CORE_EFLAGS
66 #define ELF_CORE_EFLAGS 0
70 /* An ELF note in memory */
84 typedef unsigned long elf_greg_t;
85 typedef unsigned long elf_freg_t[3];
87 #define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t))
88 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
91 long tv_sec; /* seconds */
92 long tv_usec; /* microseconds */
98 int si_signo; /* signal number */
99 int si_code; /* extra code */
100 int si_errno; /* errno */
106 long pr_flags; /* XXX Process flags */
107 short pr_why; /* XXX Reason for process halt */
108 short pr_what; /* XXX More detailed reason */
110 struct elf_siginfo pr_info; /* Info associated with signal */
111 short pr_cursig; /* Current signal */
112 unsigned long pr_sigpend; /* Set of pending signals */
113 unsigned long pr_sighold; /* Set of held signals */
115 struct sigaltstack pr_altstack; /* Alternate stack info */
116 struct sigaction pr_action; /* Signal action for current sig */
122 struct timeval pr_utime; /* User time */
123 struct timeval pr_stime; /* System time */
124 struct timeval pr_cutime; /* Cumulative user time */
125 struct timeval pr_cstime; /* Cumulative system time */
127 long pr_instr; /* Current instruction */
129 elf_gregset_t pr_reg; /* GP registers */
130 #ifdef CONFIG_BINFMT_ELF_FDPIC
131 /* When using FDPIC, the loadmap addresses need to be communicated
132 * to GDB in order for GDB to do the necessary relocations. The
133 * fields (below) used to communicate this information are placed
134 * immediately after ``pr_reg'', so that the loadmap addresses may
135 * be viewed as part of the register set if so desired.
137 unsigned long pr_exec_fdpic_loadmap;
138 unsigned long pr_interp_fdpic_loadmap;
140 int pr_fpvalid; /* True if math co-processor being used. */
143 #define ELF_PRARGSZ (80) /* Number of chars for args */
147 char pr_state; /* numeric process state */
148 char pr_sname; /* char for pr_state */
149 char pr_zomb; /* zombie */
150 char pr_nice; /* nice val */
151 unsigned long pr_flag; /* flags */
152 __kernel_uid_t pr_uid;
153 __kernel_gid_t pr_gid;
154 pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;
156 char pr_fname[16]; /* filename of executable */
157 char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
169 #define R_ARM_ABS32 2
170 #define R_ARM_CALL 28
171 #define R_ARM_JUMP24 29
172 #define R_ARM_V4BX 40
173 #define R_ARM_PREL31 42
174 #define R_ARM_MOVW_ABS_NC 43
175 #define R_ARM_MOVT_ABS 44
177 #define R_ARM_THM_CALL 10
178 #define R_ARM_THM_JUMP24 30
179 #define R_ARM_THM_MOVW_ABS_NC 47
180 #define R_ARM_THM_MOVT_ABS 48
183 * These are used to set parameters in the core dumps.
185 #define ELF_CLASS ELFCLASS32
187 #define ELF_DATA ELFDATA2MSB
189 #define ELF_DATA ELFDATA2LSB
191 #define ELF_ARCH EM_ARM
193 /* from linux/elf.h */
194 /* 32-bit ELF base types. */
195 typedef __u32 Elf32_Addr;
196 typedef __u16 Elf32_Half;
197 typedef __u32 Elf32_Off;
198 typedef __s32 Elf32_Sword;
199 typedef __u32 Elf32_Word;
201 /* 64-bit ELF base types. */
202 typedef __u64 Elf64_Addr;
203 typedef __u16 Elf64_Half;
204 typedef __s16 Elf64_SHalf;
205 typedef __u64 Elf64_Off;
206 typedef __s32 Elf64_Sword;
207 typedef __u32 Elf64_Word;
208 typedef __u64 Elf64_Xword;
209 typedef __s64 Elf64_Sxword;
211 /* These constants are for the segment types stored in the image headers */
219 #define PT_TLS 7 /* Thread local storage segment */
220 #define PT_LOOS 0x60000000 /* OS-specific */
221 #define PT_HIOS 0x6fffffff /* OS-specific */
222 #define PT_LOPROC 0x70000000
223 #define PT_HIPROC 0x7fffffff
224 #define PT_GNU_EH_FRAME 0x6474e550
226 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
231 * If the real number of program header table entries is larger than
232 * or equal to PN_XNUM(0xffff), it is set to sh_info field of the
233 * section header at index 0, and PN_XNUM is set to e_phnum
234 * field. Otherwise, the section header at index 0 is zero
235 * initialized, if it exists.
237 * Specifications are available in:
239 * - Sun microsystems: Linker and Libraries.
240 * Part No: 817-1984-17, September 2008.
241 * URL: http://docs.sun.com/app/docs/doc/817-1984
243 * - System V ABI AMD64 Architecture Processor Supplement
244 * Draft Version 0.99.,
246 * URL: http://www.x86-64.org/
248 #define PN_XNUM 0xffff
250 /* These constants define the different elf file types */
256 #define ET_LOPROC 0xff00
257 #define ET_HIPROC 0xffff
259 /* This is the info that is needed to parse the dynamic section of the file */
262 #define DT_PLTRELSZ 2
276 #define DT_SYMBOLIC 16
282 #define DT_TEXTREL 22
284 #define DT_ENCODING 32
285 #define OLD_DT_LOOS 0x60000000
286 #define DT_LOOS 0x6000000d
287 #define DT_HIOS 0x6ffff000
288 #define DT_VALRNGLO 0x6ffffd00
289 #define DT_VALRNGHI 0x6ffffdff
290 #define DT_ADDRRNGLO 0x6ffffe00
291 #define DT_ADDRRNGHI 0x6ffffeff
292 #define DT_VERSYM 0x6ffffff0
293 #define DT_RELACOUNT 0x6ffffff9
294 #define DT_RELCOUNT 0x6ffffffa
295 #define DT_FLAGS_1 0x6ffffffb
296 #define DT_VERDEF 0x6ffffffc
297 #define DT_VERDEFNUM 0x6ffffffd
298 #define DT_VERNEED 0x6ffffffe
299 #define DT_VERNEEDNUM 0x6fffffff
300 #define OLD_DT_HIOS 0x6fffffff
301 #define DT_LOPROC 0x70000000
302 #define DT_HIPROC 0x7fffffff
304 /* This info is needed when parsing the symbol table */
312 #define STT_SECTION 3
317 #define ELF_ST_BIND(x) ((x) >> 4)
318 #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
319 #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
320 #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
321 #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
322 #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
324 typedef struct dynamic{
333 Elf64_Sxword d_tag; /* entry tag value */
340 /* The following are used with relocations */
341 #define ELF32_R_SYM(x) ((x) >> 8)
342 #define ELF32_R_TYPE(x) ((x) & 0xff)
344 #define ELF64_R_SYM(i) ((i) >> 32)
345 #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
347 typedef struct elf32_rel {
352 typedef struct elf64_rel {
353 Elf64_Addr r_offset; /* Location at which to apply the action */
354 Elf64_Xword r_info; /* index and type of relocation */
357 typedef struct elf32_rela{
360 Elf32_Sword r_addend;
363 typedef struct elf64_rela {
364 Elf64_Addr r_offset; /* Location at which to apply the action */
365 Elf64_Xword r_info; /* index and type of relocation */
366 Elf64_Sxword r_addend; /* Constant addend used to compute value */
369 typedef struct elf32_sym{
373 unsigned char st_info;
374 unsigned char st_other;
378 typedef struct elf64_sym {
379 Elf64_Word st_name; /* Symbol name, index in string tbl */
380 unsigned char st_info; /* Type and binding attributes */
381 unsigned char st_other; /* No defined meaning, 0 */
382 Elf64_Half st_shndx; /* Associated section index */
383 Elf64_Addr st_value; /* Value of the symbol */
384 Elf64_Xword st_size; /* Associated symbol size */
390 typedef struct elf32_hdr{
391 unsigned char e_ident[EI_NIDENT];
393 Elf32_Half e_machine;
394 Elf32_Word e_version;
395 Elf32_Addr e_entry; /* Entry point */
400 Elf32_Half e_phentsize;
402 Elf32_Half e_shentsize;
404 Elf32_Half e_shstrndx;
407 typedef struct elf64_hdr {
408 unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */
410 Elf64_Half e_machine;
411 Elf64_Word e_version;
412 Elf64_Addr e_entry; /* Entry point virtual address */
413 Elf64_Off e_phoff; /* Program header table file offset */
414 Elf64_Off e_shoff; /* Section header table file offset */
417 Elf64_Half e_phentsize;
419 Elf64_Half e_shentsize;
421 Elf64_Half e_shstrndx;
424 /* These constants define the permissions on sections in the program
430 typedef struct elf32_phdr{
441 typedef struct elf64_phdr {
444 Elf64_Off p_offset; /* Segment file offset */
445 Elf64_Addr p_vaddr; /* Segment virtual address */
446 Elf64_Addr p_paddr; /* Segment physical address */
447 Elf64_Xword p_filesz; /* Segment size in file */
448 Elf64_Xword p_memsz; /* Segment size in memory */
449 Elf64_Xword p_align; /* Segment alignment, file & memory */
454 #define SHT_PROGBITS 1
459 #define SHT_DYNAMIC 6
464 #define SHT_DYNSYM 11
466 #define SHT_LOPROC 0x70000000
467 #define SHT_HIPROC 0x7fffffff
468 #define SHT_LOUSER 0x80000000
469 #define SHT_HIUSER 0xffffffff
472 #define SHF_WRITE 0x1
473 #define SHF_ALLOC 0x2
474 #define SHF_EXECINSTR 0x4
475 #define SHF_MASKPROC 0xf0000000
477 /* special section indexes */
479 #define SHN_LORESERVE 0xff00
480 #define SHN_LOPROC 0xff00
481 #define SHN_HIPROC 0xff1f
482 #define SHN_ABS 0xfff1
483 #define SHN_COMMON 0xfff2
484 #define SHN_HIRESERVE 0xffff
486 typedef struct elf32_shdr {
495 Elf32_Word sh_addralign;
496 Elf32_Word sh_entsize;
499 typedef struct elf64_shdr {
500 Elf64_Word sh_name; /* Section name, index in string tbl */
501 Elf64_Word sh_type; /* Type of section */
502 Elf64_Xword sh_flags; /* Miscellaneous section attributes */
503 Elf64_Addr sh_addr; /* Section virtual addr at execution */
504 Elf64_Off sh_offset; /* Section file offset */
505 Elf64_Xword sh_size; /* Size of section in bytes */
506 Elf64_Word sh_link; /* Index of another section */
507 Elf64_Word sh_info; /* Additional section information */
508 Elf64_Xword sh_addralign; /* Section alignment */
509 Elf64_Xword sh_entsize; /* Entry size if section holds table */
512 #define EI_MAG0 0 /* e_ident[] indexes */
522 #define ELFMAG0 0x7f /* EI_MAG */
526 #define ELFMAG "\177ELF"
529 #define ELFCLASSNONE 0 /* EI_CLASS */
532 #define ELFCLASSNUM 3
534 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
535 #define ELFDATA2LSB 1
536 #define ELFDATA2MSB 2
538 #define EV_NONE 0 /* e_version, EI_VERSION */
542 #define ELFOSABI_NONE 0
543 #define ELFOSABI_LINUX 3
546 #define ELF_OSABI ELFOSABI_NONE
550 * Notes used in ET_CORE. Architectures export some of the arch register sets
551 * using the corresponding note types via the PTRACE_GETREGSET and
552 * PTRACE_SETREGSET requests.
554 #define NT_PRSTATUS 1
556 #define NT_PRPSINFO 3
557 #define NT_TASKSTRUCT 4
559 #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
560 #define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
561 #define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
562 #define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
563 #define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
564 #define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
565 #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
566 #define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
567 #define NT_S390_TIMER 0x301 /* s390 timer register */
568 #define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
569 #define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
570 #define NT_S390_CTRS 0x304 /* s390 control registers */
571 #define NT_S390_PREFIX 0x305 /* s390 prefix register */
572 #define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
573 #define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
574 #define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
577 /* Note header in a PT_NOTE section */
578 typedef struct elf32_note {
579 Elf32_Word n_namesz; /* Name size */
580 Elf32_Word n_descsz; /* Content size */
581 Elf32_Word n_type; /* Content type */
584 /* Note header in a PT_NOTE section */
585 typedef struct elf64_note {
586 Elf64_Word n_namesz; /* Name size */
587 Elf64_Word n_descsz; /* Content size */
588 Elf64_Word n_type; /* Content type */
591 #ifndef elf_read_implies_exec
592 /* Executables for which elf_read_implies_exec() returns TRUE will
593 have the READ_IMPLIES_EXEC personality flag set automatically.
594 Override in asm/elf.h as needed. */
595 # define elf_read_implies_exec(ex, have_pt_gnu_stack) 0
598 #if ELF_CLASS == ELFCLASS32
600 extern Elf32_Dyn _DYNAMIC [];
601 #define elfhdr elf32_hdr
602 #define elf_phdr elf32_phdr
603 #define elf_shdr elf32_shdr
604 #define elf_note elf32_note
605 #define elf_addr_t Elf32_Off
606 #define Elf_Half Elf32_Half
610 extern Elf64_Dyn _DYNAMIC [];
611 #define elfhdr elf64_hdr
612 #define elf_phdr elf64_phdr
613 #define elf_shdr elf64_shdr
614 #define elf_note elf64_note
615 #define elf_addr_t Elf64_Off
616 #define Elf_Half Elf64_Half
620 #endif //__SYSDUMP_H__