Skip to content

Commit

Permalink
process/load: Add 32bit interpreter support
Browse files Browse the repository at this point in the history
JIRA: RTOS-664
  • Loading branch information
badochov committed Oct 6, 2024
1 parent a57a022 commit 361a096
Show file tree
Hide file tree
Showing 3 changed files with 340 additions and 62 deletions.
41 changes: 41 additions & 0 deletions include/auxv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Phoenix-RTOS
*
* Operating system kernel
*
* Auxiliary vector definitions
*
* Copyright 2024 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#ifndef _PHOENIX_AUXV_H_
#define _PHOENIX_AUXV_H_


#include "types.h"


struct auxInfo {
__u32 a_type; /* Type of element. */
__u64 a_v; /* Value of element. */
};


#define AT_NULL 0 /* End of auxiliary vector. */
#define AT_PAGESZ 1 /* Page size. */
#define AT_BASE 2 /* Base address of interpreter. */
#define AT_ENTRY 3 /* Entry point address. */
#define AT_PHDR 4 /* Location of program header table. */
#define AT_PHENT 5 /* Size of one entry in program header table. */
#define AT_PHNUM 6 /* Number of entries in program header table. */


#define AUXV_TYPE_COUNT 7 /* Number of auxiliary vector element types. */


#endif
115 changes: 65 additions & 50 deletions proc/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@


typedef unsigned short Elf32_Half;
typedef unsigned int Elf32_Word;
typedef unsigned int Elf32_Addr;
typedef unsigned int Elf32_Off;
typedef int Elf32_Sword;
typedef unsigned int Elf32_Word;
typedef unsigned int Elf32_Addr;
typedef unsigned int Elf32_Off;
typedef int Elf32_Sword;


typedef u16 Elf64_Half;
Expand All @@ -33,31 +33,47 @@ typedef s64 Elf64_Sword;
typedef u64 Elf64_Xword;


#define EI_NIDENT 16

#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_DYNSYM 11
#define SHT_LOPROC 0x70000000
#define SHT_HIPROC 0x7fffffff
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xffffffff

#define STT_LOPROC 13
#define STT_HIPROC 15

#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_GNU_STACK 0x6474e551
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff

#define PF_X 0x1
#define PF_W 0x2
#define PF_R 0x4
#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4

#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'

#define ELFCLASSNONE 0
#define ELFCLASS32 1
#define ELFCLASS64 2

#define EI_NIDENT 16

#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_DYNSYM 11
#define SHT_LOPROC 0x70000000
#define SHT_HIPROC 0x7fffffff
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xffffffff

#define STT_LOPROC 13
#define STT_HIPROC 15

#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_PHDR 6
#define PT_GNU_STACK 0x6474e551
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff

#define PF_X 0x1
#define PF_W 0x2
#define PF_R 0x4

#pragma pack(push, 1)

Expand All @@ -67,8 +83,8 @@ typedef struct {
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_hsize;
Elf32_Half e_phentsize;
Expand All @@ -84,7 +100,7 @@ typedef struct {
Elf32_Word sh_type;
Elf32_Word sh_flags;
Elf32_Addr sh_addr;
Elf32_Off sh_offset;
Elf32_Off sh_offset;
Elf32_Word sh_size;
Elf32_Word sh_link;
Elf32_Word sh_info;
Expand All @@ -95,7 +111,7 @@ typedef struct {

typedef struct {
Elf32_Word p_type;
Elf32_Off p_offset;
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Expand All @@ -106,18 +122,18 @@ typedef struct {


typedef struct {
u32 st_name;
Elf32_Addr st_value;
u32 st_size;
u32 st_name;
Elf32_Addr st_value;
u32 st_size;
unsigned char st_info;
unsigned char st_other;
u16 st_shndx;
u16 st_shndx;
} Elf32_Sym;


typedef struct {
Elf32_Addr r_offset;
u32 r_info;
u32 r_info;
} Elf32_Rel;


Expand All @@ -129,13 +145,13 @@ typedef struct {


typedef struct {
unsigned char e_ident [EI_NIDENT];
unsigned char e_ident[EI_NIDENT];
Elf64_Half e_type;
Elf64_Half e_machine;
Elf64_Word e_version;
Elf64_Addr e_entry;
Elf64_Off e_phoff;
Elf64_Off e_shoff;
Elf64_Off e_phoff;
Elf64_Off e_shoff;
Elf64_Word e_flags;
Elf64_Half e_ehsize;
Elf64_Half e_phentsize;
Expand All @@ -147,11 +163,11 @@ typedef struct {


typedef struct {
Elf64_Word p_type;
Elf64_Word p_flags;
Elf64_Off p_offset;
Elf64_Addr p_vaddr;
Elf64_Addr p_paddr;
Elf64_Word p_type;
Elf64_Word p_flags;
Elf64_Off p_offset;
Elf64_Addr p_vaddr;
Elf64_Addr p_paddr;
Elf64_Xword p_filesz;
Elf64_Xword p_memsz;
Elf64_Xword p_align;
Expand All @@ -174,10 +190,9 @@ typedef struct {

#pragma pack(pop)


#define ELF32_R_SYM(info) ((info)>>8)
#define ELF32_R_TYPE(info) ((unsigned char)(info))
#define ELF32_R_INFO(sym, type) (((sym)<<8)+(unsigned char)(type))
#define ELF32_R_SYM(info) ((info) >> 8)
#define ELF32_R_TYPE(info) ((unsigned char)(info))
#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))


#define R_ARM_ABS32 2
Expand Down
Loading

0 comments on commit 361a096

Please sign in to comment.