1/*
2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#pragma once
8
9
10#include <types.h>
11
12/* minimal ELF structures needed for loading GRUB boot module */
13
14typedef struct Elf32_Header {
15    unsigned char e_ident[16];
16    uint16_t      e_type;      /* Relocatable=1, Executable=2 (+ some more ..) */
17    uint16_t      e_machine;   /* Target architecture: MIPS=8 */
18    uint32_t      e_version;   /* Elf version (should be 1) */
19    uint32_t      e_entry;     /* Code entry point */
20    uint32_t      e_phoff;     /* Program header table */
21    uint32_t      e_shoff;     /* Section header table */
22    uint32_t      e_flags;     /* Flags */
23    uint16_t      e_ehsize;    /* ELF header size */
24    uint16_t      e_phentsize; /* Size of one program segment header */
25    uint16_t      e_phnum;     /* Number of program segment headers */
26    uint16_t      e_shentsize; /* Size of one section header */
27    uint16_t      e_shnum;     /* Number of section headers */
28    uint16_t      e_shstrndx;  /* Section header index of the string table for section header names */
29} Elf32_Header_t, Elf_Header_t;
30
31/* 32-bit elf phdr */
32typedef struct Elf32_Phdr {
33    uint32_t      p_type;      /* Segment type: Loadable segment = 1 */
34    uint32_t      p_offset;    /* Offset of segment in file */
35    uint32_t      p_vaddr;     /* Reqd virtual address of segment when loading */
36    uint32_t      p_paddr;     /* Reqd physical address of segment (ignore) */
37    uint32_t      p_filesz;    /* How many bytes this segment occupies in file */
38    uint32_t      p_memsz;     /* How many bytes this segment should occupy in memory */
39    uint32_t      p_flags;     /* Flags: logical "or" of PF_ constants below */
40    uint32_t      p_align;     /* Reqd alignment of segment in memory */
41} Elf32_Phdr_t, Elf_Phdr_t;
42