Added posix code

This commit is contained in:
Bahadir Balban
2009-09-29 21:55:59 +03:00
parent 54272ccb63
commit f0bb0a4657
478 changed files with 63161 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
/*
* Address allocation pool
*
* Copyright (C) 2007 Bahadir Balban
*/
#ifndef __ADDR_H__
#define __ADDR_H__
#include <lib/idpool.h>
/* Address pool to allocate from a range of addresses */
struct address_pool {
struct id_pool *idpool;
unsigned long start;
unsigned long end;
};
int address_pool_init_with_idpool(struct address_pool *pool,
struct id_pool *idpool,
unsigned long start, unsigned long end);
int address_pool_init(struct address_pool *pool, unsigned long start,
unsigned long end);
void *address_new(struct address_pool *pool, int npages);
int address_del(struct address_pool *, void *addr, int npages);
#endif /* __ADDR_H__ */

View File

@@ -0,0 +1,44 @@
#ifndef __LIB_BIT_H__
#define __LIB_BIT_H__
#include <l4lib/types.h>
unsigned int __clz(unsigned int bitvector);
int find_and_set_first_free_bit(u32 *word, unsigned int lastbit);
int find_and_set_first_free_contig_bits(u32 *word, unsigned int limit,
int nbits);
int check_and_clear_bit(u32 *word, int bit);
int check_and_clear_contig_bits(u32 *word, int first, int nbits);
int check_and_set_bit(u32 *word, int bit);
/* Set */
static inline void setbit(unsigned int *w, unsigned int flags)
{
*w |= flags;
}
/* Clear */
static inline void clrbit(unsigned int *w, unsigned int flags)
{
*w &= ~flags;
}
/* Test */
static inline int tstbit(unsigned int *w, unsigned int flags)
{
return *w & flags;
}
/* Test and clear */
static inline int tstclr(unsigned int *w, unsigned int flags)
{
int res = tstbit(w, flags);
clrbit(w, flags);
return res;
}
#endif /* __LIB_BIT_H__ */

View File

@@ -0,0 +1,64 @@
/*
* 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__));
int elf_parse_executable(struct tcb *task, struct vm_file *file,
struct exec_file_desc *efd);
#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__ */

View File

@@ -0,0 +1,21 @@
#ifndef __MM0_IDPOOL_H__
#define __MM0_IDPOOL_H__
#include <lib/bit.h>
#include <lib/spinlock.h>
struct id_pool {
int nwords;
int bitlimit;
u32 bitmap[];
};
struct id_pool *id_pool_new_init(int mapsize);
int id_new(struct id_pool *pool);
int id_del(struct id_pool *pool, int id);
int id_get(struct id_pool *pool, int id);
int id_is_empty(struct id_pool *pool);
int ids_new_contiguous(struct id_pool *pool, int numids);
int ids_del_contiguous(struct id_pool *pool, int first, int numids);
#endif /* __MM0_IDPOOL_H__ */

View File

@@ -0,0 +1,20 @@
#ifndef __PRIVATE_MALLOC_H__
#define __PRIVATE_MALLOC_H__
#include <stddef.h>
#include <string.h>
#include <stdio.h>
void *kmalloc(size_t size);
void kfree(void *blk);
static inline void *kzalloc(size_t size)
{
void *buf = kmalloc(size);
memset(buf, 0, size);
return buf;
}
#endif /*__PRIVATE_MALLOC_H__ */

View File

@@ -0,0 +1,17 @@
/*
* Fake spinlock for future multi-threaded mm0
*/
#ifndef __MM0_SPINLOCK_H__
#define __MM0_SPINLOCK_H__
struct spinlock {
int lock;
};
static inline void spin_lock_init(struct spinlock *s) { }
static inline void spin_lock(struct spinlock *s) { }
static inline void spin_unlock(struct spinlock *s) { }
#endif /* __MM0_SPINLOCK_H__ */