#ifndef _HEADER_H\r
#define _HEADER_H\r
\r
-#define NULL ((void*)0)\r
-\r
#define Print(str) do{char*s=(str);write(_stdout,strlen(s)+1,s);}while(0)\r
\r
extern int _stdout;\r
* See file COPYING for \r
*/\r
#include "header.h"\r
+#include <stddef.h>\r
\r
// === CODE ===\r
/**\r
include $(dir $(lastword $(MAKEFILE_LIST)))../Makefile.cfg
ASFLAGS = -felf
-CPPFLAGS = -I$(ACESSUSERDIR)/include/
+CPPFLAGS = -I$(ACESSUSERDIR)/include/ -DARCHDIR_is_$(ARCHDIR)
CFLAGS = -fno-stack-protector $(CPPFLAGS)
LDFLAGS = -T $(OUTPUTDIR)Libs/acess.ld -rpath-link $(OUTPUTDIR)Libs -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc
//#include "common.h"
// === CONSTANTS ===
-#define NULL ((void*)0)
#define NUM_TERMS 4
#define DEFAULT_TERMINAL "/Devices/VTerm/0"
#define DEFAULT_SHELL "/Acess/SBin/login"
MAKEDEP = $(CC) -M
ASFLAGS += -D ARCHDIR=$(ARCHDIR)
-CPPFLAGS := -I$(ACESSDIR)/Usermode/include/ -D ARCHDIR=$(ARCHDIR) -D ARCHDIR_IS_$(ARCHDIR)=1
+CPPFLAGS := -I$(ACESSDIR)/Usermode/include/ -DARCHDIR=$(ARCHDIR) -DARCHDIR_is_$(ARCHDIR)=1
CFLAGS := -g -Wall -fPIC -fno-builtin -fno-stack-protector $(CPPFLAGS)
LDFLAGS := -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -e SoMain -x -L$(OUTPUTDIR)Libs/
#ifndef _COMMON_H
#define _COMMON_H
-#define NULL ((void*)0)
-
+#include <stddef.h>
#include <stdarg.h>
// HACK: Replace with underscored
for( i = 0; i < hdr->e_phnum; i ++ )
{
if(phtab[i].p_type == PT_DYNAMIC)
- dyntab = (void *)phtab[i].p_vaddr;
+ dyntab = (void *)(intptr_t)phtab[i].p_vaddr;
if(phtab[i].p_type == PT_LOAD && compiledBase > phtab[i].p_vaddr)
compiledBase = phtab[i].p_vaddr;
}
By thePowersGang
*/
#include "common.h"
+#include <stdint.h>
// === CODE ===
char *strcpy(char *dest, const char *src)
close(fd);
return 1;
}
+
+uint64_t __udivdi3(uint64_t Num, uint64_t Den)
+{
+ uint64_t ret = 0, add = 1;
+
+ // Find what power of two times Den is > Num
+ while( Num >= Den )
+ {
+ Den <<= 1;
+ add <<= 1;
+ }
+
+ // Search backwards
+ while( add > 1 )
+ {
+ add >>= 1;
+ Den >>= 1;
+ // If the numerator is > Den, subtract and add to return value
+ if( Num > Den )
+ {
+ ret += add;
+ Num -= Den;
+ }
+ }
+// if(Rem) *Rem = Num;
+ return ret;
+}
+
By thePowersGang\r
*/\r
#include <stdint.h>\r
+#include <stddef.h>\r
#include "common.h"\r
\r
// === PROTOTYPES ===\r
ASFLAGS +=\r
LDFLAGS += -soname libc.so -Map map.txt -lgcc\r
\r
-OBJ = stub.o heap.o stdlib.o env.o fileIO.o string.o\r
+OBJ = stub.o heap.o stdlib.o env.o fileIO.o string.o select.o\r
DEPFILES := $(OBJ:%.o=%.d)\r
# signals.o\r
BIN = libc.so\r
#define _stdout 1\r
\r
// === PROTOTYPES ===\r
-EXPORT void itoa(char *buf, uint64_t num, uint base, int minLength, char pad, int bSigned);\r
+EXPORT void itoa(char *buf, uint64_t num, size_t base, int minLength, char pad, int bSigned);\r
struct sFILE *get_file_struct();\r
\r
// === GLOBALS ===\r
///\todo Implement\r
}\r
\r
-EXPORT long int ftell(FILE *fp)\r
+EXPORT off_t ftell(FILE *fp)\r
{\r
if(!fp || !fp->FD) return -1;\r
\r
+++ /dev/null
-/*
- * AcessOS LibC
- * stddef.h
- */
-#ifndef _STDDEF_H
-#define _STDDEF_H
-
-// === CONSTANTS ===
-#ifndef NULL
-# define NULL ((void*)0)
-#endif
-
-// === TYPES ===
-#ifndef size_t
-typedef unsigned int size_t;
-#endif
-
-// === MACROS ===
-#define offsetof(st, m) ((size_t)((uintptr_t)((char *)&((st *)(0))->m - (char *)0 )))
-
-#endif
/*
*/
-#ifndef _STDTYPES_H_
-#define _STDTYPES_H_
+#ifndef _STDINT_H_
+#define _STDINT_H_
-//typedef unsigned int uint;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef signed int int32_t;
typedef signed long long int64_t;
-#ifdef __LP64__
+#if ARCHDIR_is_x86
+typedef uint32_t intptr_t;
+typedef uint32_t uintptr_t;
+#elif ARCHDIR_is_x86_64
typedef uint64_t intptr_t;
typedef uint64_t uintptr_t;
-typedef int64_t ptrdiff_t;
#else
-typedef uint32_t intptr_t;
-typedef uint32_t uintptr_t;
-typedef int32_t ptrdiff_t;
-#endif
-#if 0
# error "Unknown pointer size"
#endif
#include <stdlib.h>
#include <stdarg.h>
-// === Types ===
+/* === Types === */
typedef struct sFILE FILE;
-// === CONSTANTS ===
+/* === CONSTANTS === */
#define EOF (-1)
-// --- Standard IO ---
+/* --- Standard IO --- */
extern int printf(const char *format, ...);
extern int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list args);
extern int vsprintf(char *buf, const char *format, va_list args);
extern FILE *fdopen(int fd, const char *modes);
extern int fclose(FILE *fp);
extern void fflush(FILE *fp);
-extern long int ftell(FILE *fp);
+extern off_t ftell(FILE *fp);
extern int fseek(FILE *fp, long int amt, int whence);
extern size_t fread(void *buf, size_t size, size_t n, FILE *fp);
#define EXIT_FAILURE 1\r
#define EXIT_SUCCESS 0\r
\r
-// --- Spinlock Macros ---\r
+/* --- Spinlock Macros --- */\r
+/* TODO: Support non-x86 architectures */\r
#define DEFLOCK(_name) static int _spinlock_##_name=0;\r
-//#define LOCK(_name) __asm__ __volatile__("jmp ._tst;\n\t._lp:call yield;\n\t._tst:lock btsl $1,(%0);\n\tjc ._lp"::"D"(&_spinlock_##_name))\r
-#define LOCK(_name) do{int v=1;while(v){__asm__ __volatile__("lock cmpxchgl %%eax, (%1)":"=a"(v):"D"((&_spinlock_##_name)),"a"(1));yield();}}while(0)\r
+#define LOCK(_name) do{int v=1;while(v){__asm__ __volatile__("lock cmpxchgl %0, (%1)":"=a"(v):"D"((&_spinlock_##_name)),"a"(1));yield();}}while(0)\r
#define UNLOCK(_name) __asm__ __volatile__("lock andl $0, (%0)"::"D"(&_spinlock_##_name))\r
\r
-// --- StdLib ---\r
-extern void _exit(int code) __attribute__((noreturn)); //NOTE: Also defined in acess/sys.h\r
+/* --- StdLib --- */\r
+extern void _exit(int code) __attribute__((noreturn)); /* NOTE: Also defined in acess/sys.h */\r
extern int atoi(const char *ptr);\r
extern void exit(int status) __attribute__((noreturn));\r
extern void atexit(void (*__func)(void));\r
-extern void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));\r
+extern void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));\r
\r
-// --- Environment ---\r
+/* --- Environment --- */\r
extern char *getenv(const char *name);\r
\r
-// --- Heap ---\r
-extern void free(void *mem);\r
-extern void *malloc(size_t bytes);\r
-extern void *calloc(size_t __nmemb, size_t __size);\r
-extern void *realloc(void *__ptr, size_t __size);\r
+/* --- Heap --- */\r
+extern void free(void *mem);\r
+extern void *malloc(size_t bytes);\r
+extern void *calloc(size_t __nmemb, size_t __size);\r
+extern void *realloc(void *__ptr, size_t __size);\r
extern int IsHeap(void *ptr);\r
\r
#ifndef SEEK_CUR\r
#include <stddef.h>
-// Strings
+/* Strings */
extern size_t strlen(const char *string);
extern size_t strnlen(const char *string, size_t maxlen);
extern int strcmp(const char *str1, const char *str2);
extern size_t strcspn(const char *haystack, const char *reject);
extern size_t strspn(const char *haystack, const char *accept);
-// Memory
+/* Memory */
extern void *memset(void *dest, int val, size_t count);
extern void *memcpy(void *dest, const void *src, size_t count);
extern void *memmove(void *dest, const void *src, size_t count);
#ifndef _SYS_STAT_H_
#define _SYS_STAT_H_
-#include <stdint.h> //EVIL!
+#include <stdint.h> /* Evil */
+#include <stddef.h>
-typedef uintptr_t dev_t; // TODO: How to identify a device with Acess
+typedef void *dev_t; /* TODO: How to identify a device with Acess */
typedef uint64_t ino_t;
typedef unsigned int blksize_t;
typedef uint64_t blkcnt_t;
*/
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H
-//#include <stdint.h>
typedef struct stat t_fstat;
} fd_set;
struct s_sysACL {
- unsigned long object; //!< Group or user (bit 31 determines)
- unsigned long perms; //!< Inverted by bit 31
+ unsigned long object; /*!< Group or user (bit 31 determines) */
+ unsigned long perms; /*!< Inverted by bit 31 */
};
struct s_sysFInfo {
unsigned int mount;
typedef struct s_sysFInfo t_sysFInfo;
typedef struct s_sysACL t_sysACL;
-static inline void FD_ZERO(fd_set *fdsetp) {int i=FD_SETSIZE/16;while(i--)fdsetp->flags[i]=0; }
-static inline void FD_CLR(int fd, fd_set *fdsetp) {
- if(fd < 0 || fd > FD_SETSIZE) return;
- fdsetp->flags[fd/16] &= (fd_set_ent_t) ((~1 << (fd%16))) & 0xFFFF;
-}
-static inline void FD_SET(int fd, fd_set *fdsetp) {
- if(fd < 0 || fd > FD_SETSIZE) return;
- fdsetp->flags[fd/16] |= (fd_set_ent_t) (1 << (fd%16));
-}
-static inline int FD_ISSET(int fd, fd_set *fdsetp) {
- if(fd < 0 || fd > FD_SETSIZE) return 0;
- return !!( fdsetp->flags[fd/16] & (1<<(fd%16)) );
-}
+extern void FD_ZERO(fd_set *fdsetp);
+extern void FD_CLR(int fd, fd_set *fdsetp);
+extern void FD_SET(int fd, fd_set *fdsetp);
+extern int FD_ISSET(int fd, fd_set *fdsetp);
#include <sys/stat.h>