Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ include_directories (SYSTEM "${D_PS5SDK}/include")
add_subdirectory("crt")

add_subdirectory("examples/hello_socket")
add_subdirectory("examples/klog_server")
add_subdirectory("examples/pipe_pirate")

if (DEFINED V_FW AND ${V_FW} STREQUAL "0x403")
add_subdirectory("examples/klog_server")
endif()

MACRO(SUBDIRLIST result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
Expand Down
2 changes: 2 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_TOOLCHAIN_FILE=%PS5SDK%/cmake/toolchain-ps5.cmake .
ninja
6 changes: 3 additions & 3 deletions cmake/toolchain-ps5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Search for programs in the build
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # For libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(CMAKE_C_FLAGS "--target=x86_64-freebsd-pc-elf -O0 -DPPR -DPS5 -DPS5_FW_VERSION=${V_FW} ")
set(CMAKE_C_FLAGS "--target=x86_64-freebsd-pc-elf -march=znver2 -O0 -DPPR -DPS5 -DPS5_FW_VERSION=${V_FW} ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200112 -D__BSD_VISIBLE=1 -D__XSI_VISIBLE=500")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin -nostdlib -Wall -m64") # -nostartfiles
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fPIC -fPIE -pie -Wl,-z,norelro")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fPIC -fPIE")

set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -nostdinc++ ") #

set(CMAKE_ASM_FLAGS "--target=x86_64-pc-freebsd11-elf -nostdlib -fPIC -fPIE")

#-DCMAKE_LINKER=/path/to/linker -DCMAKE_CXX_LINK_EXECUTABLE="<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld -Xlinker -T ${CMAKE_CURRENT_SOURCE_DIR}/linker.x -Wl,--build-id=none -Wl,-z,norelro")
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld -Xlinker -pie -Xlinker -T ${CMAKE_CURRENT_SOURCE_DIR}/linker.x -Wl,--build-id=none -Wl,-z,norelro")
19 changes: 4 additions & 15 deletions crt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,39 @@
cmake_minimum_required (VERSION 3.20)

set(basename "ps5sdk_crt")
project(${basename} C CXX ASM)
project(${basename} C)

# Language Standard Defaults
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if ("${CMAKE_CXX_STANDARD}" STREQUAL "")
set(CMAKE_CXX_STANDARD 23)
endif()

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${D_CWD}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${D_CWD}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${D_CWD}/lib) # static libs are archive

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "[Cc]lang")
if ("${CMAKE_C_COMPILER_ID}" MATCHES "[Cc]lang")
set(IS_CLANG 1)
else()
message(FATAL_ERROR "${PROJECT_NAME} is meant to be built with clang! CompilerID: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "${PROJECT_NAME} is meant to be built with clang! CompilerID: ${CMAKE_C_COMPILER_ID}")
endif()

if (NOT DEFINED D_PS5SDK)
set(D_PS5SDK ".")
endif()

message(" C_FLAGS: ${CMAKE_C_FLAGS} ")
message("CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message("ASM_FLAGS: ${CMAKE_ASM_FLAGS}")

########## finalize main target sources ##########

set(D_CRT_SRC ${D_CWD}/crt)

file(GLOB SrcFiles ${D_CRT_SRC}/*.c ${D_CRT_SRC}/*.s)
file(GLOB SrcFiles ${D_CRT_SRC}/*.c)

add_library(${PROJECT_NAME} STATIC ${SrcFiles})

target_compile_options(${PROJECT_NAME} PUBLIC
$<$<COMPILE_LANGUAGE:C>:${C_DEFS} ${C_FLAGS}>
$<$<COMPILE_LANGUAGE:CXX>:${CXX_DEFS} ${CXX_FLAGS}>
$<$<COMPILE_LANGUAGE:ASM>:$<IF:${IS_CLANG},-Xclang,-x> assembler-with-cpp ${ASM_FLAGS}>
)
6 changes: 5 additions & 1 deletion crt/crt.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ void __ps5sdk_crt_start(struct payload_args *args)

out:
*(int *)args->payloadout = rv;
}
}

void __attribute__((naked)) _start(void) {
asm volatile("jmp __ps5sdk_crt_start\n");
}
9 changes: 0 additions & 9 deletions crt/crt0.s

This file was deleted.

Empty file removed examples/hello_socket/bin/.gitkeep
Empty file.
Empty file removed examples/klog_server/bin/.gitkeep
Empty file.
Empty file removed examples/pipe_pirate/bin/.gitkeep
Empty file.