Added preliminary support for execve(). Updates to clone, fork, exit, task handling.

It turned out we used one version of kmalloc for malloc() and another for kfree()!
Now fixed.
Added parent-child relationship to tasks. Need to polish handling CLONE_PARENT and THREAD.
This commit is contained in:
Bahadir Balban
2008-11-19 12:59:52 +02:00
parent d182b5b35a
commit 46937eab88
39 changed files with 502 additions and 1192 deletions

View File

@@ -0,0 +1,61 @@
/*
* Definitions for Executable Linking Format
* Based on Portable Formats Specification v1.1
*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __ELF_H__
#define __ELF_H__
#include <l4/types.h>
/* ELF identification indices */
#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_PAD 7
/* Size of ELF identification field */
#define EI_NIDENT 16
/* Values for ELF identification fields */
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
/* Values for the ELF Class field */
#define ELFCLASSNONE 0
#define ELFCLASS32 1
#define ELFCLASS64 2
/* Values for the ELF Data field */
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
struct elf_header {
u8 e_ident[EI_NIDENT]; /* ELF identification */
u16 e_type; /* Object file type */
u16 e_machine; /* Machine architecture */
u32 e_version; /* Object file version */
u32 e_entry; /* Virtual entry address */
u32 e_phoff; /* Program header offset */
u32 e_shoff; /* Section header offset */
u32 e_flags; /* Processor specific flags */
u16 e_ehsize; /* ELF header size */
u16 e_phentsize; /* Program header entry size */
u16 e_phnum; /* Number of program headers */
u16 e_shentsize; /* Section header entry size */
u16 e_shnum; /* Number of section headers */
u16 e_shstrndx; /* Shtable index for strings */
} __attribute__((__packed__));
#endif /* __ELF_H__ */

View File

@@ -0,0 +1,35 @@
/*
* Definitions for ELF program headers
* Based on Portable Formats Specification v1.1
*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __ELFPRG_H__
#define __ELFPRG_H__
#include <l4/types.h>
struct elf_program_header {
u32 p_type; /* Type of segment */
u32 p_offset; /* Segment file offset */
u32 p_vaddr; /* Virtual start address */
u32 p_paddr; /* Physical start address */
u32 p_filesz; /* Size in stored file */
u32 p_memsz; /* Size in memory image */
u32 p_flags; /* Segment attributes */
u32 p_align; /* Alignment requirement */
} __attribute__((__packed__));
/* Program segment type definitions */
#define PT_NULL 0
#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7FFFFFFF
#endif /* __ELFPRG_H__ */

View File

@@ -0,0 +1,60 @@
/*
* Definitions for ELF Sections
* Based on Portable Formats Specification v1.1
*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __ELFSECT_H__
#define __ELFSECT_H__
#include <l4/types.h>
/* Special section indices */
#define SHN_UNDEF 0
#define SHN_LORESERVE 0xFF00
#define SHN_LOPROC 0xFF00
#define SHN_HIPROC 0xFF1F
#define SHN_ABS 0xFFF1
#define SHN_COMMON 0xFFF2
#define SHN_HIRESERVE 0xFFFF
struct elf_section_header {
u32 sh_name; /* Index to section header str table for name */
u32 sh_type; /* Categorises section's semantics */
u32 sh_flags; /* Flags that define various attributes */
u32 sh_addr; /* Virtual address for section */
u32 sh_offset; /* Offset to contents from file beginning */
u32 sh_size; /* Size of section (note SHT_NOBITS) */
u32 sh_link;
u32 sh_info; /* Extra section info */
u32 sh_addralign; /* Section alignment in power of 2 */
u32 sh_entsize; /* Size of each entry if fixed */
} __attribute__((__packed__));
/* Section type codes */
#define SHT_NULL 0 /* Inactive */
#define SHT_PROGBITS 1 /* Program contents */
#define SHT_SYMTAB 2 /* Symbol table */
#define SHT_STRTAB 3 /* String table */
#define SHT_RELA 4 /* Relocation entries */
#define SHT_HASH 5 /* Symbol hash table */
#define SHT_DYNAMIC 6 /* Dynamic linking info */
#define SHT_NOTE 7 /* Optional, additional info */
#define SHT_NOBITS 8 /* Does not occupy file space */
#define SHT_REL 9 /* Relocation entries */
#define SHT_SHLIB 10 /* Reserved */
#define SHT_DYNSYM 11 /* Symbols for dynamic linking */
#define SHT_LOPROC 0x70000000 /* Reserved for processors */
#define SHT_HIPROC 0x7FFFFFFF /* Reserved for processors */
#define SHT_LOUSER 0x80000000 /* Reserved for user progs */
#define SHT_HIUSER 0xFFFFFFFF /* Reserved for user progs */
/* Section attribute flags */
#define SHF_WRITE (1 << 0) /* Writeable */
#define SHF_ALLOC (1 << 1) /* Occupies actual memory */
#define SHF_EXECINSTR (1 << 2) /* Executable */
#define SHF_MASCPROC 0xF0000000 /* Reserved for processors */
#endif /* __ELFSECT_H__ */

View File

@@ -0,0 +1,59 @@
/*
* Definitions for ELF Symbol tables, symbols
* Based on Portable Formats Specification v1.1
*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __ELFSYM_H__
#define __ELFSYM_H__
#include <l4/types.h>
struct elf_symbol_entry {
u32 st_name; /* Index into string table */
u32 st_value; /* Symbol value; address, aboslute etc. */
u32 st_size; /* Number of bytes contained in object */
u8 st_info; /* Type and binding attributes */
u8 st_other; /* Unused, 0 */
u16 st_shndx; /* Section header index associated with entry */
} __attribute__((__packed__));
/* To manipulate binding and type attributes on st_info field */
#define ELF32_ST_BIND(i) ((i) >> 4)
#define ELF32_ST_TYPE(i) ((i) & 0xF)
#define ELF32_ST_INFO(b, t) (((b) << 4) + ((t) & 0xF))
/* Symbol binding codes */
#define STB_LOCAL 0
#define STB_GLOBAL 1
#define STB_WEAK 2
#define STB_LOPROC 13
#define STB_HIPROC 15
/* Symbol types */
#define STT_NOTYPE 0
#define STT_OBJECT 1
#define STT_FUNC 2
#define STT_SECTION 3
#define STT_FILE 4
#define STT_LOPROC 13
#define STT_HIPROC 15
/* Relocation structures */
struct elf_rel {
u32 r_offset;
u32 r_info;
} __attribute__((__packed__));
struct elf_rela {
u32 r_offset;
u32 r_info;
s32 r_addend;
} __attribute__((__packed__));
/* Macros to manipulate r_info field */
#define ELF32_R_SYM(i) ((i) >> 8)
#define ELF32_R_TYPE(i) ((u8)(i))
#define ELF32_R_INFO(s,t) (((s) << 8) + (u8)(t))
#endif /* __ELFSYM_H__ */