Saturn builds
This commit is contained in:
@@ -85,22 +85,100 @@ target_link_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
)
|
||||
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
# --start-group/--end-group allow circular archive references
|
||||
# (e.g. libyaul allocator symbols referenced by libzip / yyjson objects).
|
||||
-Wl,--start-group
|
||||
"${_YAUL_SYSROOT}/lib/libyaul.a"
|
||||
"${_YAUL_SYSROOT}/lib/libzip.a"
|
||||
"${_YAUL_SYSROOT}/lib/libz.a"
|
||||
m
|
||||
# GCC soft-float / soft-divide runtime (SH-2 has no FPU or hw divider).
|
||||
# -lgcc is resolved by the compiler driver even with -nodefaultlibs.
|
||||
-lgcc
|
||||
-Wl,--end-group
|
||||
)
|
||||
|
||||
# Yaul linker script (Saturn SH-2 memory map) and startup objects.
|
||||
# Startup objects must precede all other objects so use target_link_options
|
||||
# (those flags appear before the object-file list in cmake's link command).
|
||||
target_link_options(${DUSK_BINARY_TARGET_NAME} PRIVATE
|
||||
"-T${_YAUL_SYSROOT}/lib/ldscripts/yaul.x"
|
||||
"${_YAUL_SYSROOT}/lib/crt0.o"
|
||||
"${_YAUL_SYSROOT}/lib/init.o"
|
||||
# Provide SH-2 stack top addresses required by crt0.o/cpu_dual_entries.o.
|
||||
# RAM region: 0x06004000 .. 0x06100000 (~1 MB).
|
||||
# Master stack grows down from the very top; slave CPU gets 4 KB below.
|
||||
"-Wl,--defsym=___master_stack=0x06100000"
|
||||
"-Wl,--defsym=___slave_stack=0x060FF000"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Post-build: ELF → binary image
|
||||
# sh2eb-elf-objcopy converts the ELF to a flat binary that IP.BIN loads
|
||||
# into Saturn Work RAM.
|
||||
# Post-build: ELF → binary → Saturn disc image (ISO + CUE)
|
||||
# ---------------------------------------------------------------------------
|
||||
set(DUSK_SAT_BIN "${CMAKE_BINARY_DIR}/Dusk.bin")
|
||||
set(DUSK_SAT_BIN "${CMAKE_BINARY_DIR}/Dusk.bin")
|
||||
set(DUSK_SAT_IP_BIN "${CMAKE_BINARY_DIR}/IP.BIN")
|
||||
set(DUSK_SAT_CD_DIR "${CMAKE_BINARY_DIR}/cd")
|
||||
set(DUSK_SAT_AUDIO_DIR "${CMAKE_BINARY_DIR}/audio-tracks")
|
||||
set(DUSK_SAT_ISO "${CMAKE_BINARY_DIR}/Dusk.iso")
|
||||
set(DUSK_SAT_CUE "${CMAKE_BINARY_DIR}/Dusk.cue")
|
||||
|
||||
# Step 1: ELF → flat binary (loaded into Work RAM by IP.BIN)
|
||||
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
||||
COMMAND "${_YAUL_BIN}/sh2eb-elf-objcopy"
|
||||
-O binary
|
||||
"$<TARGET_FILE:${DUSK_BINARY_TARGET_NAME}>"
|
||||
"${DUSK_SAT_BIN}"
|
||||
COMMENT "Converting ${DUSK_BINARY_TARGET_NAME} ELF → ${DUSK_SAT_BIN}"
|
||||
COMMENT "Converting ELF → ${DUSK_SAT_BIN}"
|
||||
)
|
||||
|
||||
# Step 2: flat binary → IP.BIN (boot header with region security blobs)
|
||||
# make-ip writes IP.BIN into dirname(arg1), so it lands at ${CMAKE_BINARY_DIR}/IP.BIN.
|
||||
# Pass -1 for 1st-read-size so make-ip uses the actual file size.
|
||||
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E env
|
||||
"YAUL_INSTALL_ROOT=${YAUL_INSTALL_ROOT}"
|
||||
"YAUL_ARCH_SH_PREFIX=sh2eb-elf"
|
||||
"${_YAUL_BIN}/make-ip"
|
||||
"${DUSK_SAT_BIN}"
|
||||
"V1.000"
|
||||
"20260101"
|
||||
"JTUE"
|
||||
"J"
|
||||
"DUSK"
|
||||
"0x06100000"
|
||||
"0x060FF000"
|
||||
"0x06004000"
|
||||
"-1"
|
||||
COMMENT "Generating IP.BIN"
|
||||
)
|
||||
|
||||
# Step 3: build CD filesystem tree and create ISO 9660 image
|
||||
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_SAT_CD_DIR}"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_SAT_AUDIO_DIR}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${DUSK_SAT_BIN}" "${DUSK_SAT_CD_DIR}/A.BIN"
|
||||
# ISO 9660 requires these auxiliary text files
|
||||
COMMAND ${CMAKE_COMMAND} -E touch "${DUSK_SAT_CD_DIR}/ABS.TXT"
|
||||
COMMAND ${CMAKE_COMMAND} -E touch "${DUSK_SAT_CD_DIR}/BIB.TXT"
|
||||
COMMAND ${CMAKE_COMMAND} -E touch "${DUSK_SAT_CD_DIR}/CPY.TXT"
|
||||
COMMAND ${CMAKE_COMMAND} -E env
|
||||
"YAUL_INSTALL_ROOT=${YAUL_INSTALL_ROOT}"
|
||||
"MAKE_ISO_XORRISOFS=/usr/bin/xorrisofs"
|
||||
"${_YAUL_BIN}/make-iso"
|
||||
"${DUSK_SAT_CD_DIR}"
|
||||
"${DUSK_SAT_IP_BIN}"
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"Dusk"
|
||||
COMMENT "Generating ${DUSK_SAT_ISO}"
|
||||
)
|
||||
|
||||
# Step 4: ISO → CUE sheet (rename .iso → .bin for a classic BIN/CUE pair
|
||||
# if desired; emulators accept .iso+.cue as-is)
|
||||
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E env
|
||||
"YAUL_INSTALL_ROOT=${YAUL_INSTALL_ROOT}"
|
||||
"${_YAUL_BIN}/make-cue"
|
||||
"${DUSK_SAT_AUDIO_DIR}"
|
||||
"${DUSK_SAT_ISO}"
|
||||
COMMENT "Generating ${DUSK_SAT_CUE}"
|
||||
)
|
||||
|
||||
@@ -48,13 +48,16 @@ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
# SH-2 core flags: big-endian (-mb), SH-2 ISA (-m2), no FPU
|
||||
set(_SAT_C_FLAGS "-m2 -mb -fno-builtin -fomit-frame-pointer")
|
||||
# SH-2 core flags: big-endian (-mb), SH-2 ISA (-m2), no FPU.
|
||||
# -ffunction-sections/-fdata-sections enable --gc-sections to eliminate
|
||||
# unreachable code at the function level (e.g. yyjson FILE* API paths).
|
||||
set(_SAT_C_FLAGS "-m2 -mb -fno-builtin -fomit-frame-pointer -ffunction-sections -fdata-sections -Os")
|
||||
set(CMAKE_C_FLAGS_INIT "${_SAT_C_FLAGS}")
|
||||
|
||||
# Yaul installs yaul.specs to ${YAUL_INSTALL_ROOT}/sh2eb-elf/lib/ and
|
||||
# ldscripts/yaul.x to ${YAUL_INSTALL_ROOT}/sh2eb-elf/lib/ldscripts/.
|
||||
# GCC searches ${prefix}/${target}/lib/ for specs, so -specs=yaul.specs works
|
||||
# without an absolute path once the SDK is installed.
|
||||
# Linker flags: gc-sections, no startup/default libs (Yaul provides crt0/init;
|
||||
# we supply all needed libraries explicitly). -nodefaultlibs prevents cmake/gcc
|
||||
# from injecting -lc (which does not exist in the Yaul sysroot).
|
||||
# --start-group/--end-group are placed in target_link_libraries in
|
||||
# targets/saturn.cmake so they actually wrap the archive list.
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT
|
||||
"-specs=yaul.specs -Wl,--gc-sections -nostartfiles -Wl,--start-group -Wl,--end-group")
|
||||
"-Wl,--gc-sections -nostartfiles -nodefaultlibs")
|
||||
|
||||
Reference in New Issue
Block a user