fix gcc6 build error
[profile/mobile/platform/kernel/u-boot-tm1.git] / property / sysdump.h
1 /*
2  * Copyright (C) 2013 Spreadtrum Communications Inc.
3  *
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.
7  *
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.
12  */
13
14 #ifndef __SYSDUMP_H__
15 #define __SYSDUMP_H__
16
17 #include <config.h>
18 #include <linux/types.h>
19
20 #define SYSDUMP_CORE_NAME_FMT   "sysdump.core.%02d" /* time, number */
21 #define NR_KCORE_MEM            80
22 #define SYSDUMP_MAGIC           "SPRD_SYSDUMP_119"
23
24 #define CONFIG_PHYS_OFFSET 0x80000000
25 #define PAGE_OFFSET 0xC0000000
26
27 #ifndef REAL_SDRAM_SIZE
28 #define REAL_SDRAM_SIZE 0x40000000 /*dump 1G ram*/
29 #endif
30
31 #define PAGE_SHIFT 12
32 #ifndef PAGE_SIZE
33 #define PAGE_SIZE (1UL << PAGE_SHIFT)
34 #endif
35 #ifndef PAGE_ALIGN
36 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
37 #endif
38
39 struct sysdump_mem {
40         unsigned long paddr;
41         unsigned long vaddr;
42         unsigned long soff;
43         size_t size;
44         int type;
45 };
46
47 struct sysdump_info {
48         char magic[16];
49         char time[32];
50         char dump_path[128];
51         int elfhdr_size;
52         int mem_num;
53         unsigned long dump_mem_paddr;
54         int crash_key;
55 };
56
57
58 enum sysdump_type {
59         SYSDUMP_RAM,
60         SYSDUMP_MODEM,
61         SYSDUMP_IOMEM,
62 };
63
64 #define CORE_STR                "CORE"
65 #ifndef ELF_CORE_EFLAGS
66 #define ELF_CORE_EFLAGS 0
67 #endif
68
69
70 /* An ELF note in memory */
71 struct memelfnote
72 {
73         const char *name;
74         int type;
75         unsigned int datasz;
76         void *data;
77 };
78
79 #define SETUP_NOTE 0
80
81 #if SETUP_NOTE
82 struct task_struct;
83
84 typedef unsigned long elf_greg_t;
85 typedef unsigned long elf_freg_t[3];
86
87 #define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t))
88 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
89
90 struct timeval {
91         long tv_sec;     /* seconds */
92         long tv_usec;    /* microseconds */
93 };
94
95
96 struct elf_siginfo
97 {
98         int     si_signo;                       /* signal number */
99         int     si_code;                        /* extra code */
100         int     si_errno;                       /* errno */
101 };
102
103 struct elf_prstatus
104 {
105 #if 0
106         long    pr_flags;       /* XXX Process flags */
107         short   pr_why;         /* XXX Reason for process halt */
108         short   pr_what;        /* XXX More detailed reason */
109 #endif
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 */
114 #if 0
115         struct sigaltstack pr_altstack; /* Alternate stack info */
116         struct sigaction pr_action;     /* Signal action for current sig */
117 #endif
118         pid_t   pr_pid;
119         pid_t   pr_ppid;
120         pid_t   pr_pgrp;
121         pid_t   pr_sid;
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 */
126 #if 0
127         long    pr_instr;               /* Current instruction */
128 #endif
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.
136          */
137         unsigned long pr_exec_fdpic_loadmap;
138         unsigned long pr_interp_fdpic_loadmap;
139 #endif
140         int pr_fpvalid;         /* True if math co-processor being used.  */
141 };
142
143 #define ELF_PRARGSZ     (80)    /* Number of chars for args */
144
145 struct elf_prpsinfo
146 {
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;
155         /* Lots missing */
156         char    pr_fname[16];   /* filename of executable */
157         char    pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
158 };
159
160 #endif
161
162 /* from asm/elf.h */
163
164
165 #define EM_ARM  40
166
167 #define R_ARM_NONE              0
168 #define R_ARM_PC24              1
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
176
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
181
182 /*
183  * These are used to set parameters in the core dumps.
184  */
185 #define ELF_CLASS       ELFCLASS32
186 #ifdef __ARMEB__
187 #define ELF_DATA        ELFDATA2MSB
188 #else
189 #define ELF_DATA        ELFDATA2LSB
190 #endif
191 #define ELF_ARCH        EM_ARM
192
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;
200
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;
210
211 /* These constants are for the segment types stored in the image headers */
212 #define PT_NULL    0
213 #define PT_LOAD    1
214 #define PT_DYNAMIC 2
215 #define PT_INTERP  3
216 #define PT_NOTE    4
217 #define PT_SHLIB   5
218 #define PT_PHDR    6
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
225
226 #define PT_GNU_STACK    (PT_LOOS + 0x474e551)
227
228 /*
229  * Extended Numbering
230  *
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.
236  *
237  * Specifications are available in:
238  *
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
242  *
243  * - System V ABI AMD64 Architecture Processor Supplement
244  *   Draft Version 0.99.,
245  *   May 11, 2009.
246  *   URL: http://www.x86-64.org/
247  */
248 #define PN_XNUM 0xffff
249
250 /* These constants define the different elf file types */
251 #define ET_NONE   0
252 #define ET_REL    1
253 #define ET_EXEC   2
254 #define ET_DYN    3
255 #define ET_CORE   4
256 #define ET_LOPROC 0xff00
257 #define ET_HIPROC 0xffff
258
259 /* This is the info that is needed to parse the dynamic section of the file */
260 #define DT_NULL         0
261 #define DT_NEEDED       1
262 #define DT_PLTRELSZ     2
263 #define DT_PLTGOT       3
264 #define DT_HASH         4
265 #define DT_STRTAB       5
266 #define DT_SYMTAB       6
267 #define DT_RELA         7
268 #define DT_RELASZ       8
269 #define DT_RELAENT      9
270 #define DT_STRSZ        10
271 #define DT_SYMENT       11
272 #define DT_INIT         12
273 #define DT_FINI         13
274 #define DT_SONAME       14
275 #define DT_RPATH        15
276 #define DT_SYMBOLIC     16
277 #define DT_REL          17
278 #define DT_RELSZ        18
279 #define DT_RELENT       19
280 #define DT_PLTREL       20
281 #define DT_DEBUG        21
282 #define DT_TEXTREL      22
283 #define DT_JMPREL       23
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
303
304 /* This info is needed when parsing the symbol table */
305 #define STB_LOCAL  0
306 #define STB_GLOBAL 1
307 #define STB_WEAK   2
308
309 #define STT_NOTYPE  0
310 #define STT_OBJECT  1
311 #define STT_FUNC    2
312 #define STT_SECTION 3
313 #define STT_FILE    4
314 #define STT_COMMON  5
315 #define STT_TLS     6
316
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)
323
324 typedef struct dynamic{
325   Elf32_Sword d_tag;
326   union{
327     Elf32_Sword d_val;
328     Elf32_Addr  d_ptr;
329   } d_un;
330 } Elf32_Dyn;
331
332 typedef struct {
333   Elf64_Sxword d_tag;           /* entry tag value */
334   union {
335     Elf64_Xword d_val;
336     Elf64_Addr d_ptr;
337   } d_un;
338 } Elf64_Dyn;
339
340 /* The following are used with relocations */
341 #define ELF32_R_SYM(x) ((x) >> 8)
342 #define ELF32_R_TYPE(x) ((x) & 0xff)
343
344 #define ELF64_R_SYM(i)                  ((i) >> 32)
345 #define ELF64_R_TYPE(i)                 ((i) & 0xffffffff)
346
347 typedef struct elf32_rel {
348   Elf32_Addr    r_offset;
349   Elf32_Word    r_info;
350 } Elf32_Rel;
351
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 */
355 } Elf64_Rel;
356
357 typedef struct elf32_rela{
358   Elf32_Addr    r_offset;
359   Elf32_Word    r_info;
360   Elf32_Sword   r_addend;
361 } Elf32_Rela;
362
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 */
367 } Elf64_Rela;
368
369 typedef struct elf32_sym{
370   Elf32_Word    st_name;
371   Elf32_Addr    st_value;
372   Elf32_Word    st_size;
373   unsigned char st_info;
374   unsigned char st_other;
375   Elf32_Half    st_shndx;
376 } Elf32_Sym;
377
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 */
385 } Elf64_Sym;
386
387
388 #define EI_NIDENT       16
389
390 typedef struct elf32_hdr{
391   unsigned char e_ident[EI_NIDENT];
392   Elf32_Half    e_type;
393   Elf32_Half    e_machine;
394   Elf32_Word    e_version;
395   Elf32_Addr    e_entry;  /* Entry point */
396   Elf32_Off     e_phoff;
397   Elf32_Off     e_shoff;
398   Elf32_Word    e_flags;
399   Elf32_Half    e_ehsize;
400   Elf32_Half    e_phentsize;
401   Elf32_Half    e_phnum;
402   Elf32_Half    e_shentsize;
403   Elf32_Half    e_shnum;
404   Elf32_Half    e_shstrndx;
405 } Elf32_Ehdr;
406
407 typedef struct elf64_hdr {
408   unsigned char e_ident[EI_NIDENT];     /* ELF "magic number" */
409   Elf64_Half e_type;
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 */
415   Elf64_Word e_flags;
416   Elf64_Half e_ehsize;
417   Elf64_Half e_phentsize;
418   Elf64_Half e_phnum;
419   Elf64_Half e_shentsize;
420   Elf64_Half e_shnum;
421   Elf64_Half e_shstrndx;
422 } Elf64_Ehdr;
423
424 /* These constants define the permissions on sections in the program
425    header, p_flags. */
426 #define PF_R            0x4
427 #define PF_W            0x2
428 #define PF_X            0x1
429
430 typedef struct elf32_phdr{
431   Elf32_Word    p_type;
432   Elf32_Off     p_offset;
433   Elf32_Addr    p_vaddr;
434   Elf32_Addr    p_paddr;
435   Elf32_Word    p_filesz;
436   Elf32_Word    p_memsz;
437   Elf32_Word    p_flags;
438   Elf32_Word    p_align;
439 } Elf32_Phdr;
440
441 typedef struct elf64_phdr {
442   Elf64_Word p_type;
443   Elf64_Word p_flags;
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 */
450 } Elf64_Phdr;
451
452 /* sh_type */
453 #define SHT_NULL        0
454 #define SHT_PROGBITS    1
455 #define SHT_SYMTAB      2
456 #define SHT_STRTAB      3
457 #define SHT_RELA        4
458 #define SHT_HASH        5
459 #define SHT_DYNAMIC     6
460 #define SHT_NOTE        7
461 #define SHT_NOBITS      8
462 #define SHT_REL         9
463 #define SHT_SHLIB       10
464 #define SHT_DYNSYM      11
465 #define SHT_NUM         12
466 #define SHT_LOPROC      0x70000000
467 #define SHT_HIPROC      0x7fffffff
468 #define SHT_LOUSER      0x80000000
469 #define SHT_HIUSER      0xffffffff
470
471 /* sh_flags */
472 #define SHF_WRITE       0x1
473 #define SHF_ALLOC       0x2
474 #define SHF_EXECINSTR   0x4
475 #define SHF_MASKPROC    0xf0000000
476
477 /* special section indexes */
478 #define SHN_UNDEF       0
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
485  
486 typedef struct elf32_shdr {
487   Elf32_Word    sh_name;
488   Elf32_Word    sh_type;
489   Elf32_Word    sh_flags;
490   Elf32_Addr    sh_addr;
491   Elf32_Off     sh_offset;
492   Elf32_Word    sh_size;
493   Elf32_Word    sh_link;
494   Elf32_Word    sh_info;
495   Elf32_Word    sh_addralign;
496   Elf32_Word    sh_entsize;
497 } Elf32_Shdr;
498
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 */
510 } Elf64_Shdr;
511
512 #define EI_MAG0         0               /* e_ident[] indexes */
513 #define EI_MAG1         1
514 #define EI_MAG2         2
515 #define EI_MAG3         3
516 #define EI_CLASS        4
517 #define EI_DATA         5
518 #define EI_VERSION      6
519 #define EI_OSABI        7
520 #define EI_PAD          8
521
522 #define ELFMAG0         0x7f            /* EI_MAG */
523 #define ELFMAG1         'E'
524 #define ELFMAG2         'L'
525 #define ELFMAG3         'F'
526 #define ELFMAG          "\177ELF"
527 #define SELFMAG         4
528
529 #define ELFCLASSNONE    0               /* EI_CLASS */
530 #define ELFCLASS32      1
531 #define ELFCLASS64      2
532 #define ELFCLASSNUM     3
533
534 #define ELFDATANONE     0               /* e_ident[EI_DATA] */
535 #define ELFDATA2LSB     1
536 #define ELFDATA2MSB     2
537
538 #define EV_NONE         0               /* e_version, EI_VERSION */
539 #define EV_CURRENT      1
540 #define EV_NUM          2
541
542 #define ELFOSABI_NONE   0
543 #define ELFOSABI_LINUX  3
544
545 #ifndef ELF_OSABI
546 #define ELF_OSABI ELFOSABI_NONE
547 #endif
548
549 /*
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.
553  */
554 #define NT_PRSTATUS     1
555 #define NT_PRFPREG      2
556 #define NT_PRPSINFO     3
557 #define NT_TASKSTRUCT   4
558 #define NT_AUXV         6
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 */
575
576
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 */
582 } Elf32_Nhdr;
583
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 */
589 } Elf64_Nhdr;
590
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
596 #endif
597
598 #if ELF_CLASS == ELFCLASS32
599
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
607
608 #else
609
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
617
618 #endif
619
620 #endif //__SYSDUMP_H__