Implemented runtime files and tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
project(photon)
|
project(photon C ASM-ATT)
|
||||||
|
|
||||||
macro(subdirlist result curdir)
|
macro(subdirlist result curdir)
|
||||||
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
||||||
@@ -36,18 +36,37 @@ endif ()
|
|||||||
|
|
||||||
message(STATUS "Target platform: ${PLATFORM}")
|
message(STATUS "Target platform: ${PLATFORM}")
|
||||||
|
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS
|
||||||
|
"${CMAKE_EXE_LINKER_FLAGS} -ffreestanding -nostdlib -lgcc")
|
||||||
|
|
||||||
set(photon_libc_sources "")
|
set(photon_libc_sources "")
|
||||||
set(generic_dirs string include)
|
set(generic_dirs string)
|
||||||
|
|
||||||
foreach (dir ${generic_dirs})
|
foreach (dir ${generic_dirs})
|
||||||
file(GLOB_RECURSE dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/${dir}/*.c)
|
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/${dir}/*.c)
|
||||||
set(photon_libc_sources ${photon_libc_sources} ${dir_sources})
|
set(photon_libc_sources ${photon_libc_sources} ${dir_sources})
|
||||||
endforeach (dir)
|
endforeach (dir)
|
||||||
|
|
||||||
file(GLOB_RECURSE platform_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM})
|
file(GLOB_RECURSE photon_libc_includes ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include/*.h)
|
||||||
|
|
||||||
|
file(GLOB photon_libc_crt
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM}/machine/${MACHINE}/crt*.s)
|
||||||
|
|
||||||
|
add_library(crt OBJECT ${photon_libc_crt})
|
||||||
|
message(STATUS "CRT sources: ${photon_libc_crt}")
|
||||||
|
|
||||||
|
file(GLOB platform_sources
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/*.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/*.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.s)
|
||||||
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
|
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
|
||||||
|
|
||||||
add_library(c STATIC ${photon_libc_sources})
|
add_library(c STATIC ${photon_libc_sources} ${photon_libc_includes})
|
||||||
target_compile_options(c PRIVATE -ffreestanding -nostdlib -nostdinc)
|
target_compile_options(c PRIVATE -ffreestanding -nostdlib -nostdinc)
|
||||||
|
target_link_libraries(c crt)
|
||||||
|
|
||||||
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include)
|
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include)
|
||||||
|
|
||||||
|
add_subdirectory(tests)
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
#define __have_long32 1
|
#define __have_long32 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif /* defined(__cplusplus) */
|
||||||
|
|
||||||
#ifdef __INT8_TYPE__
|
#ifdef __INT8_TYPE__
|
||||||
typedef __INT8_TYPE__ __int8_t;
|
typedef __INT8_TYPE__ __int8_t;
|
||||||
@@ -236,8 +236,8 @@ typedef __uint64_t __uint_fast64_t;
|
|||||||
|
|
||||||
#undef __EXP
|
#undef __EXP
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* defined(__cplusplus) */
|
||||||
|
|
||||||
#endif /* _MACHINE__STDINT_H */
|
#endif /* _MACHINE__STDINT_H */
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif /* defined(__cplusplus) */
|
||||||
|
|
||||||
typedef __intptr_t ptrdiff_t;
|
typedef __intptr_t ptrdiff_t;
|
||||||
typedef __uintptr_t size_t;
|
typedef __uintptr_t size_t;
|
||||||
@@ -16,6 +16,6 @@ typedef int wchar_t;
|
|||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* defined(__cplusplus) */
|
||||||
|
|
||||||
#endif
|
#endif /* STDDEF_H_ */
|
||||||
|
|||||||
@@ -50,4 +50,4 @@ typedef __uintptr_t uintptr_t;
|
|||||||
|
|
||||||
typedef
|
typedef
|
||||||
|
|
||||||
#endif
|
#endif /* STDINT_H_ */
|
||||||
|
|||||||
15
photon/libc/sys/linux/machine/x86_64/crt0.s
Normal file
15
photon/libc/sys/linux/machine/x86_64/crt0.s
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
.global _start
|
||||||
|
.type _start, @function
|
||||||
|
|
||||||
|
.extern main
|
||||||
|
.type main, @function
|
||||||
|
|
||||||
|
_start:
|
||||||
|
pop %rbp
|
||||||
|
pop %rdi
|
||||||
|
mov %rsp, %rsi
|
||||||
|
andq $-16, %rsp
|
||||||
|
call main
|
||||||
|
movq %rax, %rdi
|
||||||
|
movq $60, %rax
|
||||||
|
syscall
|
||||||
8
tests/CMakeLists.txt
Normal file
8
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
file(GLOB test_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
|
||||||
|
|
||||||
|
foreach (test ${test_sources})
|
||||||
|
get_filename_component(test_name ${test} NAME_WE)
|
||||||
|
add_executable(${test_name} ${test} $<TARGET_OBJECTS:crt>)
|
||||||
|
target_compile_options(${test_name} PRIVATE -ffreestanding -nostdlib -nostdinc)
|
||||||
|
target_link_libraries(${test_name} c)
|
||||||
|
endforeach (test)
|
||||||
4
tests/start.c
Normal file
4
tests/start.c
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user