From 57cda18641d16ba4e4fec52b5514e48db8ee4593 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 3 Feb 2022 22:38:16 +0100 Subject: Switch back to mkpsxiso master branch, update docs --- doc/dev_notes.md | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) (limited to 'doc/dev_notes.md') diff --git a/doc/dev_notes.md b/doc/dev_notes.md index 3aa2304..4873a59 100644 --- a/doc/dev_notes.md +++ b/doc/dev_notes.md @@ -14,20 +14,20 @@ _- spicyjpeg_ ## MIPS ABI / compiler -- When calling C functions (ie. BIOS functions) from assembly code you'll need - to allocate N words on the stack first when calling a function that has N - arguments (`addiu $sp, -(4*N)` where N = number of arguments of the function - being called) even if the arguments are on registers `a0` to `a3` and the C - functions don't always use the space allotted in stack. When calling a - function with a variable number of arguments (`printf`) always allocate 16 - bytes of stack. +- When calling C functions (including BIOS functions) from assembly code you'll + need to allocate one 32-bit word on the stack for each argument the function + takes (`addiu $sp, -(4*N)` where `N` = number of arguments of the function + being called), *even if the function takes its arguments from registers* + *`$a0`-`$a3` rather than from the stack*. When calling a variadic function + (i.e. one with a variable number of arguments, such as `printf`) always + allocate 16 bytes of stack. - For some reason `mipsel-unknown-elf-nm` and `mipsel-none-elf-nm` (symbol map generators) insist on outputting 64-bit addresses (with the top 32 bits set, - e.g. `FFFFFFFF80010000`) even when feeding it a regular 32-bit MIPS - executable, while the standard x86 nm tool that ships with most GCC packages - prints the proper 32-bit address. Unclear whether this is a bug, intended - behavior or the result of some ancient ELF ABI flag crap. + e.g. `FFFFFFFF80010000`) even when feeding them a regular 32-bit MIPS + executable, while the standard (x86) `nm` tool that ships with most GCC + packages prints the proper 32-bit address. Unclear whether this is a bug, + intended behavior or the result of some ancient ELF ABI flag crap. `DL_ParseSymbolMap()` will ignore the top 32 bits, so this should only bother you if you're implementing your own symbol map parser. @@ -162,7 +162,7 @@ _- spicyjpeg_ multiple times) and uses the same variable values as the main project, however CMake will *not* pass custom variables through by default. If your toolchain script has options that can be set via custom variables (like - `PSN00BSDK_TC` and `PSN00BSDK_PREFIX` in PSn00bSDK), you'll have to set + `PSN00BSDK_TC` and `PSN00BSDK_TARGET` in PSn00bSDK), you'll have to set `CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` to a list of variable names to be exported to generated dummy projects. @@ -220,20 +220,6 @@ _- spicyjpeg_ endforeach() ``` -- Depending on how you find external dependencies (`find_package()`, vcpkg, - pkg-config...), CMake may end up outputting an executable that relies on a - DLL installed system-wide. To correctly install the DLL alongside the - executable you have to specify a regex as follows: - - ```cmake - install( - TARGETS my_executable - RUNTIME_DEPENDENCIES - PRE_EXCLUDE_REGEXES ".*" - PRE_INCLUDE_REGEXES "tinyxml2" - ) - ``` - CMake will scan the executable at install time and copy all the required DLLs that match the second regex. If no regex is specified CMake will also copy OS DLLs like `libc` or `msvcrt`, which usually isn't the desired behavior. @@ -277,4 +263,4 @@ _- spicyjpeg_ space. ----------------------------------------- -_Last updated on 2021-11-28 by spicyjpeg_ +_Last updated on 2022-01-30 by spicyjpeg_ -- cgit v1.2.3 From 40b7d95e9b16252d1aebb0706f3bba885f6e67cf Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Mon, 7 Feb 2022 01:06:33 +0100 Subject: Add LIBPSN00B_GENERATOR option, fix .incbin alignment --- .github/workflows/build.yml | 20 ++++++--------- CMakeLists.txt | 33 +++++++++++++++++++++++-- CMakePresets.json | 11 ++++++--- doc/dev_notes.md | 21 ++++++++++++++-- doc/installation.md | 14 ++++++++--- examples/README.md | 4 +-- examples/demos/n00bdemo/data.s.template | 8 +++++- examples/graphics/billboard/tim.s.template | 1 + examples/graphics/render2tex/texture.s.template | 1 + examples/graphics/rgb24/tim.s.template | 1 + examples/graphics/tilesasm/data.s.template | 1 + examples/system/childexec/child_exe.s.template | 1 + libpsn00b/cmake/flags.cmake | 11 +++------ 13 files changed, 93 insertions(+), 34 deletions(-) (limited to 'doc/dev_notes.md') diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a72f5d3..a2a5510 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,9 +83,11 @@ jobs: # No surprises here either. The GitHub Actions VMs even come with most of the # dependencies required to build PSn00bSDK preinstalled. + # NOTE: the workaround to allow the toolchain cache to be loaded (see below) + # doesn't seem to work on Windows Server 2022 currently. build-sdk-windows: name: Build PSn00bSDK on Windows - runs-on: windows-latest + runs-on: windows-2019 needs: build-gcc steps: @@ -111,12 +113,8 @@ jobs: - name: Fetch repo contents uses: actions/checkout@v2 with: - path: sdk - - - name: Update repo submodules - run: | - cd sdk - git submodule update --init --recursive + path: sdk + submodules: recursive - name: Build and package PSn00bSDK run: | @@ -159,12 +157,8 @@ jobs: - name: Fetch repo contents uses: actions/checkout@v2 with: - path: sdk - - - name: Update repo submodules - run: | - cd sdk - git submodule update --init --recursive + path: sdk + submodules: recursive - name: Build and package PSn00bSDK run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 2079fd1..1eca26e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # PSn00bSDK main build script -# (C) 2021 spicyjpeg - MPL licensed +# (C) 2021-2022 spicyjpeg - MPL licensed # NOTE: CMake doesn't support using multiple toolchains in a single project, # so we can't use add_subdirectory() to build both the libraries and tools. A @@ -38,6 +38,10 @@ set( SKIP_EXAMPLES OFF CACHE BOOL "Skip building SDK examples (not required for installation)" ) +set( + LIBPSN00B_GENERATOR ${CMAKE_GENERATOR} + CACHE STRING "CMake generator to use for building libpsn00b and examples" +) set( PSN00BSDK_GIT_TAG "" CACHE STRING "Git tag or branch name (used by CI)" @@ -47,6 +51,24 @@ set( CACHE STRING "Git commit hash (used by CI)" ) +# Attempt to automatically select a suitable CMake generator to build libpsn00b +# and the examples. Only Ninja and makefile-based generators can be used, as +# other generators (VS and Xcode) do not allow custom toolchains to be used. +if(NOT LIBPSN00B_GENERATOR MATCHES ".*(Make|Makefiles|Ninja)( Multi-Config)?$") + find_program(_ninja ninja NO_CACHE) + + if(_ninja STREQUAL "_ninja-NOTFOUND") + message(FATAL_ERROR "LIBPSN00B_GENERATOR must be set to a CMake generator which supports custom toolchains (Ninja or make). The current default generator (${CMAKE_GENERATOR}) will be used to build tools.") + else() + set( + LIBPSN00B_GENERATOR Ninja + CACHE STRING "CMake generator to use for building libpsn00b and examples" + FORCE + ) + message(WARNING "The current default generator (${CMAKE_GENERATOR}) will be used to build tools but does not support custom toolchains. Ninja will be used instead for building libpsn00b and examples.") + endif() +endif() + string(TIMESTAMP PSN00BSDK_BUILD_DATE UTC) # Forward some important variables to mkpsxiso and to the subprojects (they are @@ -81,7 +103,8 @@ set( # Ensure PSn00bSDK isn't being built using the toolchain file from PSn00bSDK # itself (or from another version of it). if(CMAKE_TOOLCHAIN_FILE MATCHES ".*libpsn00b[/\\]cmake[/\\]sdk\.cmake$") - message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE is set to the toolchain file of an existing PSn00bSDK installation. It must be unset or overridden by passing '-DCMAKE_TOOLCHAIN_FILE=\"\"' to CMake.") + unset(CMAKE_TOOLCHAIN_FILE CACHE) + message(WARNING "CMAKE_TOOLCHAIN_FILE is currently set to the toolchain file of an existing PSn00bSDK installation. It will be ignored.") endif() ## Subprojects @@ -93,18 +116,22 @@ endif() ExternalProject_Add( tools SOURCE_DIR ${PROJECT_SOURCE_DIR}/tools + BINARY_DIR tools-build CMAKE_CACHE_ARGS ${_sdk_args} INSTALL_DIR install_tree ) ExternalProject_Add( mkpsxiso SOURCE_DIR ${PROJECT_SOURCE_DIR}/tools/mkpsxiso + BINARY_DIR mkpsxiso-build CMAKE_CACHE_ARGS ${_sdk_args} INSTALL_DIR install_tree ) ExternalProject_Add( libpsn00b SOURCE_DIR ${PROJECT_SOURCE_DIR}/libpsn00b + BINARY_DIR libpsn00b-build + CMAKE_GENERATOR ${LIBPSN00B_GENERATOR} CMAKE_CACHE_ARGS ${_sdk_args} INSTALL_DIR install_tree #DEPENDS tools @@ -112,6 +139,8 @@ ExternalProject_Add( ExternalProject_Add( examples SOURCE_DIR ${PROJECT_SOURCE_DIR}/examples + BINARY_DIR examples-build + CMAKE_GENERATOR ${LIBPSN00B_GENERATOR} CMAKE_CACHE_ARGS ${_examples_args} INSTALL_DIR examples DEPENDS libpsn00b tools mkpsxiso diff --git a/CMakePresets.json b/CMakePresets.json index d71c1ae..b103270 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -11,14 +11,16 @@ "displayName": "Default configuration", "description": "Use this preset when building the SDK for local installation.", "generator": "Ninja", - "binaryDir": "${sourceDir}/build" + "binaryDir": "${sourceDir}/build", + "warnings": { + "dev": false + } }, { "name": "package", "displayName": "Installer package", "description": "Use this preset to build installer packages via CPack.", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build", + "inherits": "default", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "SKIP_EXAMPLES": "ON", @@ -29,11 +31,12 @@ "name": "ci", "displayName": "CI build", "description": "This preset is used by GitHub Actions to build PSn00bSDK.", - "generator": "Ninja", + "inherits": "default", "binaryDir": "${sourceDir}/../build", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "BUNDLE_TOOLCHAIN": "ON", + "LIBPSN00B_GENERATOR": "Ninja", "PSN00BSDK_TARGET": "$env{GCC_TARGET}", "PSN00BSDK_GIT_TAG": "$env{GITHUB_REF_NAME}", "PSN00BSDK_GIT_COMMIT": "$env{GITHUB_SHA}" diff --git a/doc/dev_notes.md b/doc/dev_notes.md index 4873a59..a96d6ef 100644 --- a/doc/dev_notes.md +++ b/doc/dev_notes.md @@ -164,7 +164,24 @@ _- spicyjpeg_ toolchain script has options that can be set via custom variables (like `PSN00BSDK_TC` and `PSN00BSDK_TARGET` in PSn00bSDK), you'll have to set `CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` to a list of variable names to be - exported to generated dummy projects. + exported to generated dummy projects. Additionally you may need to set + `CMAKE_TRY_COMPILE_TARGET_TYPE` to `STATIC_LIBRARY` to prevent CMake from + invoking the linker. + +- When `project()` is called, CMake uses the value of `CMAKE_SYSTEM_NAME` to + determine default values for several variables and properties. Most of these + defaults are undocumented: e.g. setting the system name to `Generic` (as + suggested by the docs for bare metal targets) will result in CMake assuming + that the target platform does not support dynamic linking, so you'll have to + turn it back on by setting the `TARGET_SUPPORTS_SHARED_LIBS` global property + *after* invoking `project()`. + +- It is not possible to use custom toolchains (through toolchain files or by + setting `CMAKE_*_COMPILER` manually) with any of the Xcode or VS generators, + as their respective build systems handle compiler selection internally rather + than relying on variables passed by CMake. Ninja or `make` is thus always + required to build PSn00bSDK and any projects made with it, even if the + host-side tools are built using Xcode or MSVC. - There is no way to use multiple toolchains (PS1 + host) in a single project, even if you use `add_subdirectory()` to execute multiple project files @@ -263,4 +280,4 @@ _- spicyjpeg_ space. ----------------------------------------- -_Last updated on 2022-01-30 by spicyjpeg_ +_Last updated on 2022-02-06 by spicyjpeg_ diff --git a/doc/installation.md b/doc/installation.md index 1646653..c766fd9 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -1,6 +1,14 @@ # Getting started with PSn00bSDK +**IMPORTANT**: due to a bug in `libflac` (used by `mkpsxiso`), building using +MinGW on Windows is currently broken. You'll have to install Visual Studio and +pass `-G "Visual Studio "` to CMake when configuring PSn00bSDK to use +MSVC instead. Due to MSBuild limitations *you'll still need to install Ninja* +in order to build the SDK, as MSBuild is not compatible with custom toolchains. +This guide will be updated with detailed MSVC build instructions in the near +future. + ## Building and installing The instructions below are for Windows and Linux. Building on macOS hasn't been @@ -79,8 +87,8 @@ and installed properly. **NOTE**: Ninja is used by default to build the SDK. If you can't get it to work or don't have it installed, pass `-G "Unix Makefiles"` (or - `-G "MSYS Makefiles"` on Windows) to the first command to build using `make` - instead. + `-G "MinGW Makefiles"` on Windows) to the first command to build using + `make` instead. 6. Install the SDK to the path you chose (add `sudo` or run it from a command prompt with admin privileges if necessary): @@ -150,4 +158,4 @@ The toolchain script defines a few CMake macros to create PS1 executables, DLLs and CD images. See the [reference](cmake_reference.md) for details. ----------------------------------------- -_Last updated on 2021-12-29 by spicyjpeg_ +_Last updated on 2022-02-06 by spicyjpeg_ diff --git a/examples/README.md b/examples/README.md index 60ccd21..8b84e5e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -76,7 +76,7 @@ are for rebuilding the examples *after* the SDK has been installed. Add `-DPSN00BSDK_TARGET=mipsel-unknown-elf` to the first command if your toolchain targets `mipsel-unknown-elf` rather than `mipsel-none-elf`. If you can't get Ninja to work or don't have it installed, you can also replace - `-G "Ninja"` with `-G "Unix Makefiles"` (`-G "MSYS Makefiles"` on Windows) + `-G "Ninja"` with `-G "Unix Makefiles"` (`-G "MinGW Makefiles"` on Windows) to build using `make` instead. This should create a `build` directory whose structure mirrors the one of @@ -84,4 +84,4 @@ are for rebuilding the examples *after* the SDK has been installed. CD images for each example. ----------------------------------------- -_Last updated on 2022-01-21 by spicyjpeg_ +_Last updated on 2022-02-06 by spicyjpeg_ diff --git a/examples/demos/n00bdemo/data.s.template b/examples/demos/n00bdemo/data.s.template index 9fbef2e..f659163 100644 --- a/examples/demos/n00bdemo/data.s.template +++ b/examples/demos/n00bdemo/data.s.template @@ -3,29 +3,35 @@ .global _lz_resources .type _lz_resources, @object _lz_resources: + .balign 4 .incbin "${PROJECT_BINARY_DIR}/data.lzp" #.global smd_mtekdisk #.type smd_mtekdisk, @object #smd_mtekdisk: +# .balign 4 # .incbin "data/mtekdisk.smd" #.global smd_mtektext #.type smd_mtektext, @object #smd_mtektext: +# .balign 4 # .incbin "data/mtektext.smd" #.global smd_star #.type smd_star, @object #smd_star: +# .balign 4 # .incbin "data/star.smd" #.global smd_psn00b #.type smd_psn00b, @object #smd_psn00b: +# .balign 4 # .incbin "data/psn00blogo.smd" #.global smd_scarletlogo #.type smd_scarletlogo, @object #smd_scarletlogo: -# .incbin "data/scarletlogo.smd" \ No newline at end of file +# .balign 4 +# .incbin "data/scarletlogo.smd" diff --git a/examples/graphics/billboard/tim.s.template b/examples/graphics/billboard/tim.s.template index fbe7522..d9309bc 100644 --- a/examples/graphics/billboard/tim.s.template +++ b/examples/graphics/billboard/tim.s.template @@ -3,4 +3,5 @@ .global tim_image .type tim_image, @object tim_image: + .balign 4 # Required to correctly parse and load the image .incbin "${PROJECT_SOURCE_DIR}/texture64.tim" diff --git a/examples/graphics/render2tex/texture.s.template b/examples/graphics/render2tex/texture.s.template index 8b09ad8..48248b2 100644 --- a/examples/graphics/render2tex/texture.s.template +++ b/examples/graphics/render2tex/texture.s.template @@ -5,4 +5,5 @@ .global tim_blendpattern .type tim_blendpattern, @object tim_blendpattern: + .balign 4 # Required to correctly parse and load the image .incbin "${PROJECT_SOURCE_DIR}/blendpattern-16c.tim" diff --git a/examples/graphics/rgb24/tim.s.template b/examples/graphics/rgb24/tim.s.template index 9fb1fb6..205a081 100644 --- a/examples/graphics/rgb24/tim.s.template +++ b/examples/graphics/rgb24/tim.s.template @@ -3,4 +3,5 @@ .global tim_image .type tim_image, @object tim_image: + .balign 4 # Required to correctly parse and load the image .incbin "${PROJECT_SOURCE_DIR}/bunpattern.tim" diff --git a/examples/graphics/tilesasm/data.s.template b/examples/graphics/tilesasm/data.s.template index 1c4b01e..bec0b84 100644 --- a/examples/graphics/tilesasm/data.s.template +++ b/examples/graphics/tilesasm/data.s.template @@ -31,4 +31,5 @@ # declared in the C code # tim_tileset: + .balign 4 # Required to correctly parse and load the image .incbin "${PROJECT_SOURCE_DIR}/tiles_256.tim" diff --git a/examples/system/childexec/child_exe.s.template b/examples/system/childexec/child_exe.s.template index f76bb3d..31e7c49 100644 --- a/examples/system/childexec/child_exe.s.template +++ b/examples/system/childexec/child_exe.s.template @@ -3,4 +3,5 @@ .global child_exe # Insert spoopypasta .type child_exe, @object child_exe: + .balign 4 .incbin "${PROJECT_BINARY_DIR}/child.exe" diff --git a/libpsn00b/cmake/flags.cmake b/libpsn00b/cmake/flags.cmake index 249c5b4..e31773f 100644 --- a/libpsn00b/cmake/flags.cmake +++ b/libpsn00b/cmake/flags.cmake @@ -5,10 +5,10 @@ # directories and compiler flags when a target is linked against them. The # following targets are currently defined: # - psn00bsdk_common -# - psn00bsdk_object_lib (same as psn00bsdk_common) # - psn00bsdk_static_exe # - psn00bsdk_dynamic_exe # - psn00bsdk_static_lib +# - psn00bsdk_object_lib (same as psn00bsdk_static_lib) # - psn00bsdk_shared_lib # - psn00bsdk_module_lib (same as psn00bsdk_shared_lib) # @@ -21,12 +21,7 @@ add_library(psn00bsdk_common INTERFACE) foreach( _target IN ITEMS - object_lib - static_exe - dynamic_exe - static_lib - shared_lib - module_lib + static_exe dynamic_exe static_lib object_lib shared_lib module_lib ) add_library (psn00bsdk_${_target} INTERFACE) target_link_libraries(psn00bsdk_${_target} INTERFACE psn00bsdk_common) @@ -128,6 +123,8 @@ target_compile_options( -Wa,--strip-local-absolute ) +target_link_libraries(psn00bsdk_object_lib INTERFACE psn00bsdk_static_lib) + # Options for dynamically-loaded libraries: # - Position-independent code enabled # - GP-relative addressing disabled (incompatible with ABI calls) -- cgit v1.2.3