Posix compat work

This commit is contained in:
Ali Mashtizadeh 2014-10-14 12:39:26 -07:00
parent 4e76a9a922
commit 7c0d1cae67
11 changed files with 135 additions and 17 deletions

21
include/assert.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef __ASSERT_H__
#define __ASSERT_H__
#ifndef NDEBUG
#define assert(_expr)
#else
#define assert(_expr) \
if (e) { \
__assert(__func__, __FILE__, __LINE__, #e); \
}
#endif
void __assert(const char *func, const char *file, int line, const char *expr);
#endif /* __ASSERT_H__ */

View File

@ -2,23 +2,7 @@
#ifndef _STDINT_H_
#define _STDINT_H_
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef int64_t intptr_t;
typedef uint64_t uintptr_t;
typedef uint64_t size_t;
typedef int64_t ssize_t;
typedef int64_t off_t;
#include <sys/types.h>
#endif /* _STDINT_H_ */

6
include/stdio.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __STDIO_H__
#define __STDIO_H__
#endif /* __STDIO_H__ */

View File

@ -8,6 +8,7 @@
int atexit(void (*function)(void));
void exit(int status);
void abort(void);
#endif /* __STDLIB_H__ */

6
include/time.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __TIME_H__
#define __TIME_H__
#endif /* __TIME_H__ */

View File

@ -7,8 +7,10 @@ libc_env = env.Clone()
src = [ ]
src_common = [
"assert.c",
"exit.c",
"syscall.c",
"posix/mman.c",
]
src_amd64 = [

11
lib/libc/assert.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
void
__assert(const char *func, const char *file, int line, const char *expr)
{
//fprintf(stderr, "Assert (%s): %s %s:%d\n", expr, func, file, line);
abort();
}

40
lib/libc/posix/mman.c Normal file
View File

@ -0,0 +1,40 @@
#include <sys/types.h>
#include <sys/mman.h>
#if defined(__x86_64__)
#include <sys/cdefs.h>
#include <machine/amd64.h>
#else
#error "Unsupported Architecture!"
#endif
int
getpagesizes(size_t *pagesize, int nelem)
{
#if defined(__x86_64__)
if (pagesize) {
if (nelem >= 1)
pagesize[0] = PGSIZE;
if (nelem >= 2)
pagesize[1] = LARGE_PGSIZE;
if (nelem >= 3)
pagesize[2] = HUGE_PGSIZE;
return (nelem > 3 ? 3 : nelem);
}
return 3;
#else
#error "Unsupported Architecture!"
#endif
}
void*
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
{
}
int
munmap(void *addr, size_t len)
{
}

View File

@ -62,6 +62,7 @@ if (env["ARCH"] == "amd64"):
src.append(src_common)
kern_env.Append(LINKFLAGS = ['-T', ldscript[1:], '-N', '-nostdlib'])
kern_env.Append(CPPFLAGS = ['-D_KERNEL'])
kern_env.Append(CPPFLAGS = ['-ffreestanding', '-fno-builtin', '-nostdinc',
'-mno-red-zone', '-mno-mmx', '-mno-sse',
'-mcmodel=large'])

23
sys/include/mman.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef __SYS_MMAN_H__
#define __SYS_MMAN_H__
#define PROT_NONE 0x00
#define PROT_READ 0x01
#define PROT_WRITE 0x02
#define PROT_EXEC 0x04
#define MAP_FILE 0x0010
#define MAP_ANON 0x0020
#define MAP_FIXED 0x0040
#ifdef _KERNEL
#else /* _KERNEL */
int getpagesizes(size_t *pagesize, int nlem);
void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
int munmap(void *addr, size_t len);
#endif /* _KERNEL */
#endif /* __SYS_MMAN_H__ */

23
sys/include/types.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef __SYS_TYPES_H__
#define __SYS_TYPES_H__
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef int64_t intptr_t;
typedef uint64_t uintptr_t;
typedef uint64_t size_t;
typedef int64_t ssize_t;
typedef int64_t off_t;
#endif /* __SYS_TYPES_H__ */