Re-organisation + stdint.h and stddef.h
This commit is contained in:
@@ -1,14 +1,53 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(photon)
|
||||
|
||||
file(GLOB_RECURSE photon_sources
|
||||
${CMAKE_SOURCE_DIR}/photon/*.c
|
||||
${CMAKE_SOURCE_DIR}/photon/*.h)
|
||||
message(STATUS "Sources: " ${photon_sources})
|
||||
macro(subdirlist result curdir)
|
||||
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
||||
set(dirlist "")
|
||||
foreach (child ${children})
|
||||
if (IS_DIRECTORY ${curdir}/${child})
|
||||
list(APPEND dirlist ${child})
|
||||
endif()
|
||||
endforeach()
|
||||
set(${result} ${dirlist})
|
||||
endmacro()
|
||||
|
||||
add_library(photon_obj OBJECT ${photon_sources})
|
||||
subdirlist(machine_dirs ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/machine)
|
||||
|
||||
add_library(photon SHARED $<TARGET_OBJECTS:photon_obj>)
|
||||
add_library(photon_s STATIC $<TARGET_OBJECTS:photon_obj>)
|
||||
if (NOT PLATFORM)
|
||||
set(PLATFORM "linux")
|
||||
endif ()
|
||||
|
||||
set_property(TARGET photon_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
if (NOT MACHINE)
|
||||
set(supported_machines "")
|
||||
foreach (dir ${machine_dirs})
|
||||
set(supported_machines "${supported_machines}${dir} ")
|
||||
endforeach (dir)
|
||||
|
||||
message(FATAL_ERROR "No machine architecture specified.\n"
|
||||
" Supported machines: ${supported_machines}\n"
|
||||
" Ex. `cmake -DMACHINE=x86_64 <dir>`")
|
||||
endif ()
|
||||
|
||||
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM})
|
||||
message(FATAL_ERROR "Unsupported platform: ${PLATFORM}")
|
||||
endif ()
|
||||
|
||||
|
||||
message(STATUS "Target platform: ${PLATFORM}")
|
||||
|
||||
set(photon_libc_sources "")
|
||||
set(generic_dirs string include)
|
||||
|
||||
foreach (dir ${generic_dirs})
|
||||
file(GLOB_RECURSE dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/${dir}/*.c)
|
||||
set(photon_libc_sources ${photon_libc_sources} ${dir_sources})
|
||||
endforeach (dir)
|
||||
|
||||
file(GLOB_RECURSE platform_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM})
|
||||
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
|
||||
|
||||
add_library(c STATIC ${photon_libc_sources})
|
||||
target_compile_options(c PRIVATE -ffreestanding -nostdlib -nostdinc)
|
||||
|
||||
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include)
|
||||
|
||||
243
photon/libc/include/machine/_stdint.h
Normal file
243
photon/libc/include/machine/_stdint.h
Normal file
@@ -0,0 +1,243 @@
|
||||
#ifndef MACHINE__STDINT_H
|
||||
#define MACHINE__STDINT_H
|
||||
|
||||
#define __EXP(x) __##x##__
|
||||
|
||||
#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \
|
||||
|| ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
|
||||
#define __have_longlong64 1
|
||||
#endif
|
||||
|
||||
#if __EXP(LONG_MAX) > 0x7fffffff
|
||||
#define __have_long64 1
|
||||
#elif __EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
|
||||
#define __have_long32 1
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __INT8_TYPE__
|
||||
typedef __INT8_TYPE__ __int8_t;
|
||||
#ifdef __UINT8_TYPE__
|
||||
typedef __UINT8_TYPE__ __uint8_t;
|
||||
#else
|
||||
typedef unsigned __INT8_TYPE__ __uint8_t;
|
||||
#endif
|
||||
#define ___int8_t_defined 1
|
||||
#elif __EXP(SCHAR_MAX) == 0x7f
|
||||
typedef signed char __int8_t ;
|
||||
typedef unsigned char __uint8_t ;
|
||||
#define ___int8_t_defined 1
|
||||
#endif
|
||||
|
||||
#ifdef __INT16_TYPE__
|
||||
typedef __INT16_TYPE__ __int16_t;
|
||||
#ifdef __UINT16_TYPE__
|
||||
typedef __UINT16_TYPE__ __uint16_t;
|
||||
#else
|
||||
typedef unsigned __INT16_TYPE__ __uint16_t;
|
||||
#endif
|
||||
#define ___int16_t_defined 1
|
||||
#elif __EXP(INT_MAX) == 0x7fff
|
||||
typedef signed int __int16_t;
|
||||
typedef unsigned int __uint16_t;
|
||||
#define ___int16_t_defined 1
|
||||
#elif __EXP(SHRT_MAX) == 0x7fff
|
||||
typedef signed short __int16_t;
|
||||
typedef unsigned short __uint16_t;
|
||||
#define ___int16_t_defined 1
|
||||
#elif __EXP(SCHAR_MAX) == 0x7fff
|
||||
typedef signed char __int16_t;
|
||||
typedef unsigned char __uint16_t;
|
||||
#define ___int16_t_defined 1
|
||||
#endif
|
||||
|
||||
#ifdef __INT32_TYPE__
|
||||
typedef __INT32_TYPE__ __int32_t;
|
||||
#ifdef __UINT32_TYPE__
|
||||
typedef __UINT32_TYPE__ __uint32_t;
|
||||
#else
|
||||
typedef unsigned __INT32_TYPE__ __uint32_t;
|
||||
#endif
|
||||
#define ___int32_t_defined 1
|
||||
#elif __EXP(INT_MAX) == 0x7fffffffL
|
||||
typedef signed int __int32_t;
|
||||
typedef unsigned int __uint32_t;
|
||||
#define ___int32_t_defined 1
|
||||
#elif __EXP(LONG_MAX) == 0x7fffffffL
|
||||
typedef signed long __int32_t;
|
||||
typedef unsigned long __uint32_t;
|
||||
#define ___int32_t_defined 1
|
||||
#elif __EXP(SHRT_MAX) == 0x7fffffffL
|
||||
typedef signed short __int32_t;
|
||||
typedef unsigned short __uint32_t;
|
||||
#define ___int32_t_defined 1
|
||||
#elif __EXP(SCHAR_MAX) == 0x7fffffffL
|
||||
typedef signed char __int32_t;
|
||||
typedef unsigned char __uint32_t;
|
||||
#define ___int32_t_defined 1
|
||||
#endif
|
||||
|
||||
#ifdef __INT64_TYPE__
|
||||
typedef __INT64_TYPE__ __int64_t;
|
||||
#ifdef __UINT64_TYPE__
|
||||
typedef __UINT64_TYPE__ __uint64_t;
|
||||
#else
|
||||
typedef unsigned __INT64_TYPE__ __uint64_t;
|
||||
#endif
|
||||
#define ___int64_t_defined 1
|
||||
#elif __EXP(LONG_MAX) > 0x7fffffff
|
||||
typedef signed long __int64_t;
|
||||
typedef unsigned long __uint64_t;
|
||||
#define ___int64_t_defined 1
|
||||
|
||||
/* GCC has __LONG_LONG_MAX__ */
|
||||
#elif defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff)
|
||||
typedef signed long long __int64_t;
|
||||
typedef unsigned long long __uint64_t;
|
||||
#define ___int64_t_defined 1
|
||||
|
||||
/* POSIX mandates LLONG_MAX in <limits.h> */
|
||||
#elif defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff)
|
||||
typedef signed long long __int64_t;
|
||||
typedef unsigned long long __uint64_t;
|
||||
#define ___int64_t_defined 1
|
||||
|
||||
#elif __EXP(INT_MAX) > 0x7fffffff
|
||||
typedef signed int __int64_t;
|
||||
typedef unsigned int __uint64_t;
|
||||
#define ___int64_t_defined 1
|
||||
#endif
|
||||
|
||||
#ifdef __INT_LEAST8_TYPE__
|
||||
typedef __INT_LEAST8_TYPE__ __int_least8_t;
|
||||
#ifdef __UINT_LEAST8_TYPE__
|
||||
typedef __UINT_LEAST8_TYPE__ __uint_least8_t;
|
||||
#else
|
||||
typedef unsigned __INT_LEAST8_TYPE__ __uint_least8_t;
|
||||
#endif
|
||||
#define ___int_least8_t_defined 1
|
||||
#elif defined(___int8_t_defined)
|
||||
typedef __int8_t __int_least8_t;
|
||||
typedef __uint8_t __uint_least8_t;
|
||||
#define ___int_least8_t_defined 1
|
||||
#elif defined(___int16_t_defined)
|
||||
typedef __int16_t __int_least8_t;
|
||||
typedef __uint16_t __uint_least8_t;
|
||||
#define ___int_least8_t_defined 1
|
||||
#elif defined(___int32_t_defined)
|
||||
typedef __int32_t __int_least8_t;
|
||||
typedef __uint32_t __uint_least8_t;
|
||||
#define ___int_least8_t_defined 1
|
||||
#elif defined(___int64_t_defined)
|
||||
typedef __int64_t __int_least8_t;
|
||||
typedef __uint64_t __uint_least8_t;
|
||||
#define ___int_least8_t_defined 1
|
||||
#endif
|
||||
|
||||
#ifdef __INT_LEAST16_TYPE__
|
||||
typedef __INT_LEAST16_TYPE__ __int_least16_t;
|
||||
#ifdef __UINT_LEAST16_TYPE__
|
||||
typedef __UINT_LEAST16_TYPE__ __uint_least16_t;
|
||||
#else
|
||||
typedef unsigned __INT_LEAST16_TYPE__ __uint_least16_t;
|
||||
#endif
|
||||
#define ___int_least16_t_defined 1
|
||||
#elif defined(___int16_t_defined)
|
||||
typedef __int16_t __int_least16_t;
|
||||
typedef __uint16_t __uint_least16_t;
|
||||
#define ___int_least16_t_defined 1
|
||||
#elif defined(___int32_t_defined)
|
||||
typedef __int32_t __int_least16_t;
|
||||
typedef __uint32_t __uint_least16_t;
|
||||
#define ___int_least16_t_defined 1
|
||||
#elif defined(___int64_t_defined)
|
||||
typedef __int64_t __int_least16_t;
|
||||
typedef __uint64_t __uint_least16_t;
|
||||
#define ___int_least16_t_defined 1
|
||||
#endif
|
||||
|
||||
#ifdef __INT_LEAST32_TYPE__
|
||||
typedef __INT_LEAST32_TYPE__ __int_least32_t;
|
||||
#ifdef __UINT_LEAST32_TYPE__
|
||||
typedef __UINT_LEAST32_TYPE__ __uint_least32_t;
|
||||
#else
|
||||
typedef unsigned __INT_LEAST32_TYPE__ __uint_least32_t;
|
||||
#endif
|
||||
#define ___int_least32_t_defined 1
|
||||
#elif defined(___int32_t_defined)
|
||||
typedef __int32_t __int_least32_t;
|
||||
typedef __uint32_t __uint_least32_t;
|
||||
#define ___int_least32_t_defined 1
|
||||
#elif defined(___int64_t_defined)
|
||||
typedef __int64_t __int_least32_t;
|
||||
typedef __uint64_t __uint_least32_t;
|
||||
#define ___int_least32_t_defined 1
|
||||
#endif
|
||||
|
||||
#ifdef __INT_LEAST64_TYPE__
|
||||
typedef __INT_LEAST64_TYPE__ __int_least64_t;
|
||||
#ifdef __UINT_LEAST64_TYPE__
|
||||
typedef __UINT_LEAST64_TYPE__ __uint_least64_t;
|
||||
#else
|
||||
typedef unsigned __INT_LEAST64_TYPE__ __uint_least64_t;
|
||||
#endif
|
||||
#define ___int_least64_t_defined 1
|
||||
#elif defined(___int64_t_defined)
|
||||
typedef __int64_t __int_least64_t;
|
||||
typedef __uint64_t __uint_least64_t;
|
||||
#define ___int_least64_t_defined 1
|
||||
#endif
|
||||
|
||||
#if defined(__INTMAX_TYPE__)
|
||||
typedef __INTMAX_TYPE__ __intmax_t;
|
||||
#elif __have_longlong64
|
||||
typedef signed long long __intmax_t;
|
||||
#else
|
||||
typedef signed long __intmax_t;
|
||||
#endif
|
||||
|
||||
#if defined(__UINTMAX_TYPE__)
|
||||
typedef __UINTMAX_TYPE__ __uintmax_t;
|
||||
#elif __have_longlong64
|
||||
typedef unsigned long long __uintmax_t;
|
||||
#else
|
||||
typedef unsigned long __uintmax_t;
|
||||
#endif
|
||||
|
||||
#ifdef __INTPTR_TYPE__
|
||||
typedef __INTPTR_TYPE__ __intptr_t;
|
||||
#ifdef __UINTPTR_TYPE__
|
||||
typedef __UINTPTR_TYPE__ __uintptr_t;
|
||||
#else
|
||||
typedef unsigned __INTPTR_TYPE__ __uintptr_t;
|
||||
#endif
|
||||
#elif defined(__PTRDIFF_TYPE__)
|
||||
typedef __PTRDIFF_TYPE__ __intptr_t;
|
||||
typedef unsigned __PTRDIFF_TYPE__ __uintptr_t;
|
||||
#else
|
||||
typedef long __intptr_t;
|
||||
typedef unsigned long __uintptr_t;
|
||||
#endif
|
||||
|
||||
typedef __int8_t __int_fast8_t;
|
||||
typedef __uint8_t __uint_fast8_t;
|
||||
|
||||
typedef __int16_t __int_fast16_t;
|
||||
typedef __uint16_t __uint_fast16_t;
|
||||
|
||||
typedef __int32_t __int_fast32_t;
|
||||
typedef __uint32_t __uint_fast32_t;
|
||||
|
||||
typedef __int64_t __int_fast64_t;
|
||||
typedef __uint64_t __uint_fast64_t;
|
||||
|
||||
#undef __EXP
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _MACHINE__STDINT_H */
|
||||
21
photon/libc/include/stddef.h
Normal file
21
photon/libc/include/stddef.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef STDDEF_H_
|
||||
#define STDDEF_H_
|
||||
|
||||
#include <machine/_stdint.h>
|
||||
|
||||
#define NULL ((void *)0)
|
||||
#define offsetof(t, m) ((size_t)(&(t *)0)->m)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef __intptr_t ptrdiff_t;
|
||||
typedef __uintptr_t size_t;
|
||||
typedef int wchar_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
53
photon/libc/include/stdint.h
Normal file
53
photon/libc/include/stdint.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef STDINT_H_
|
||||
#define STDINT_H_
|
||||
|
||||
#include <machine/_stdint.h>
|
||||
|
||||
typedef __int8_t int8_t;
|
||||
typedef __uint8_t uint8_t;
|
||||
|
||||
typedef __int16_t int16_t;
|
||||
typedef __uint16_t uint16_t;
|
||||
|
||||
typedef __int32_t int32_t;
|
||||
typedef __uint32_t uint32_t;
|
||||
|
||||
typedef __int64_t int64_t;
|
||||
typedef __uint64_t uint64_t;
|
||||
|
||||
typedef __intptr_t intptr_t;
|
||||
typedef __uintptr_t uintptr_t;
|
||||
|
||||
typedef __int_least8_t int_least8_t;
|
||||
typedef __uint_least8_t uint_least8_t;
|
||||
|
||||
typedef __int_least16_t int_least16_t;
|
||||
typedef __uint_least16_t uint_least16_t;
|
||||
|
||||
typedef __int_least32_t int_least32_t;
|
||||
typedef __uint_least32_t uint_least32_t;
|
||||
|
||||
typedef __int_least64_t int_least64_t;
|
||||
typedef __uint_least64_t uint_least64_t;
|
||||
|
||||
typedef __int_fast8_t int_fast8_t;
|
||||
typedef __uint_fast8_t uint_fast8_t;
|
||||
|
||||
typedef __int_fast16_t int_fast16_t;
|
||||
typedef __uint_fast16_t uint_fast16_t;
|
||||
|
||||
typedef __int_fast32_t int_fast32_t;
|
||||
typedef __uint_fast32_t uint_fast32_t;
|
||||
|
||||
typedef __int_fast64_t int_fast64_t;
|
||||
typedef __uint_fast64_t uint_fast64_t;
|
||||
|
||||
typedef __intmax_t intmax_t;
|
||||
typedef __uintmax_t uintmax_t;
|
||||
|
||||
typedef __intptr_t intptr_t;
|
||||
typedef __uintptr_t uintptr_t;
|
||||
|
||||
typedef
|
||||
|
||||
#endif
|
||||
16
photon/libc/include/string.h
Normal file
16
photon/libc/include/string.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef STRING_H_
|
||||
#define STRING_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern size_t strlen(const char *str);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
0
photon/libc/machine/i386/types.h
Normal file
0
photon/libc/machine/i386/types.h
Normal file
0
photon/libc/machine/x86_64/types.h
Normal file
0
photon/libc/machine/x86_64/types.h
Normal file
11
photon/libc/string/strlen.c
Normal file
11
photon/libc/string/strlen.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen(const char *str)
|
||||
{
|
||||
const char *start = str;
|
||||
while (*str) {
|
||||
str++;
|
||||
}
|
||||
|
||||
return str - start;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
int temp_2() {
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user