3ds: 3ds port sources. First set of two

This commit adds changes to the original rockbox sources.

Note: the port files, functions, folders, etc., will be referred
to as 'ctru' to avoid using the Nintendo name elsewhere.

Change-Id: I0e2d3d4d2a75bd45ea67dc3452eb8d5487cf1f5a
This commit is contained in:
Mauricio Garrido 2025-09-29 16:06:04 -06:00 committed by Solomon Peachy
parent 511a38763b
commit a4de1195cd
25 changed files with 227 additions and 23 deletions

View file

@ -305,4 +305,6 @@ keymaps/keymap-echor1.c
keymaps/keymap-surfansf28.c
#elif CONFIG_KEYPAD == RG_NANO_PAD
keymaps/keymap-rgnano.c
#elif CONFIG_KEYPAD == CTRU_PAD
keymaps/keymap-ctru.c
#endif

View file

@ -565,7 +565,11 @@ void resume_directory(const char *dir)
/* Returns the current working directory and also writes cwd to buf if
non-NULL. In case of error, returns NULL. */
#ifdef CTRU
char *__wrap_getcwd(char *buf, getcwd_size_t size)
#else
char *getcwd(char *buf, getcwd_size_t size)
#endif
{
if (!buf)
return tc.currdir;

View file

@ -128,7 +128,12 @@ void tree_unlock_cache(struct tree_context *t);
#else
#define getcwd_size_t size_t
#endif
#ifdef CTRU
/* devkitarm already defines getcwd */
char *__wrap_getcwd(char *buf, getcwd_size_t size);
#else
char *getcwd(char *buf, getcwd_size_t size);
#endif
void reload_directory(void);
bool check_rockboxdir(void);
struct tree_context* tree_get_context(void);

View file

@ -25,7 +25,7 @@ target/hosted/rtc.c
#if (CONFIG_PLATFORM & PLATFORM_ANDROID) == 0 && \
!defined(DX50) && !defined(DX90) && \
(defined(DEBUG) || defined(SIMULATOR)) /* sim should define DEBUG instead */
(defined(DEBUG) || defined(SIMULATOR) || defined(CTRU)) /* sim should define DEBUG instead */
target/hosted/debug-hosted.c
#endif
@ -94,12 +94,14 @@ target/hosted/sdl/app/button-application.c
#ifdef WIN32
target/hosted/filesystem-win32.c
#else /* !WIN32 */
#ifndef CTRU
target/hosted/filesystem-unix.c
#endif /* CTRU */
#endif /* WIN32 */
#endif /* APPLICATION */
#endif /* HAVE_SDL */
#ifdef APPLICATION
#if defined(APPLICATION) && !defined(CTRU)
target/hosted/filesystem-app.c
#endif /* APPLICATION */
@ -581,6 +583,8 @@ target/hosted/maemo/pcm-gstreamer.c
target/hosted/sdl/pcm-sdl.c
#endif /* (CONFIG_PLATFORM & PLATFORM_MAEMO) */
#elif defined(CTRU)
drivers/audio/ctru.c
#endif
#endif /* (CONFIG_PLATFORM & PLATFORM_NATIVE) */
@ -2071,6 +2075,28 @@ target/hosted/ibasso/dx90/button-dx90.c
#endif
#endif
#if (CONFIG_PLATFORM & PLATFORM_CTRU)
asm/arm/lcd-as-memframe.S
target/hosted/ctru/backlight-ctru.c
target/hosted/ctru/button-ctru.c
target/hosted/ctru/kernel-ctru.c
target/hosted/ctru/thread-ctru.c
target/hosted/ctru/lcd-bitmap.c
target/hosted/ctru/luminance-ctru.c
target/hosted/ctru/system-ctru.c
target/hosted/ctru/filesystem-ctru.c
target/hosted/ctru/lc-ctru.c
target/hosted/ctru/lc-program-resolver.c
target/hosted/ctru/powermgmt-ctru.c
target/hosted/ctru/timer-ctru.c
target/hosted/ctru/pcm-ctru.c
target/hosted/ctru/lib/sys_file.c
target/hosted/ctru/lib/sys_dir.c
target/hosted/ctru/lib/sys_thread.c
target/hosted/ctru/lib/sys_timer.c
target/hosted/ctru/lib/bfile/bfile.c
#endif
#else /* defined(SIMULATOR) */
#ifdef WIN32
@ -2119,9 +2145,9 @@ kernel/queue.c
#ifdef HAVE_SEMAPHORE_OBJECTS
kernel/semaphore.c
#endif
#if defined(HAVE_SDL_THREADS)
#ifdef HAVE_SDL_THREADS
target/hosted/sdl/thread-sdl.c
#else
#elif !defined(CTRU)
kernel/thread.c
#endif
kernel/thread-common.c

View file

@ -224,7 +224,7 @@ struct sound_settings_info
#elif defined(HAVE_ES9218)
#include "es9218.h"
#elif ((CONFIG_PLATFORM & (PLATFORM_ANDROID | PLATFORM_MAEMO \
| PLATFORM_PANDORA | PLATFORM_SDL )) | defined(RG_NANO))
| PLATFORM_PANDORA | PLATFORM_SDL | PLATFORM_CTRU)) | defined(RG_NANO))
#include "hosted_codec.h"
#elif defined(DX50)
#include "codec-dx50.h"

View file

@ -85,6 +85,7 @@
#define RK27XX 2700
#define X1000 1000
#define STM32H743 32743
#define N10480H 10480
/* platforms
* bit fields to allow PLATFORM_HOSTED to be OR'ed e.g. with a
@ -98,6 +99,7 @@
#define PLATFORM_MAEMO5 (1<<5)
#define PLATFORM_MAEMO (PLATFORM_MAEMO4|PLATFORM_MAEMO5)
#define PLATFORM_PANDORA (1<<6)
#define PLATFORM_CTRU (1<<7)
/* CONFIG_KEYPAD */
#define IRIVER_H100_PAD 4
@ -167,6 +169,7 @@
#define ECHO_R1_PAD 75
#define SURFANS_F28_PAD 76
#define RG_NANO_PAD 77
#define CTRU_PAD 78
/* CONFIG_REMOTE_KEYPAD */
#define H100_REMOTE 1
@ -623,6 +626,8 @@ Lyre prototype 1 */
#include "config/surfansf28.h"
#elif defined(RG_NANO)
#include "config/rgnano.h"
#elif defined(CTRU)
#include "config/ctru.h"
#else
#error "unknown hardware platform!"
#endif
@ -650,7 +655,7 @@ Lyre prototype 1 */
# define CONFIG_BUFLIB_BACKEND BUFLIB_BACKEND_MEMPOOL
#endif
#ifdef APPLICATION
#if defined(APPLICATION)
#ifndef CONFIG_CPU
#define CONFIG_CPU 0
#endif
@ -1033,7 +1038,8 @@ Lyre prototype 1 */
#if defined(ASSEMBLER_THREADS) \
|| defined(HAVE_WIN32_FIBER_THREADS) \
|| defined(HAVE_SIGALTSTACK_THREADS)
|| defined(HAVE_SIGALTSTACK_THREADS) \
|| defined(CTRU)
#define HAVE_PRIORITY_SCHEDULING
#endif
@ -1104,7 +1110,7 @@ Lyre prototype 1 */
* Older versions of GCC emit assembly in divided syntax with no option
* to enable unified syntax.
*/
#if (__GNUC__ < 8) && defined(CPU_ARM_CLASSIC)
#if (__GNUC__ < 8) && defined(CPU_ARM_CLASSIC) || defined(CTRU)
#define BEGIN_ARM_ASM_SYNTAX_UNIFIED ".syntax unified\n"
#define END_ARM_ASM_SYNTAX_UNIFIED ".syntax divided\n"
#else

View file

@ -35,6 +35,10 @@ extern void ldebugf(const char* file, int line, const char *fmt, ...)
|| (defined(APPLICATION) && defined(DEBUG))
#define DEBUGF debugf
#define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__)
#elif (CONFIG_PLATFORM & PLATFORM_CTRU)
/* let's use second display for debug output */
#define DEBUGF debugf
#define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__)
#elif defined(DEBUG) /* DEBUG on native targets */
#ifdef HAVE_GDB_API

View file

@ -21,8 +21,9 @@
#ifndef HOSTED_CODEC_H
#define HOSTED_CODEC_H
#if defined(HAVE_SDL_AUDIO) \
&& !(CONFIG_PLATFORM & PLATFORM_MAEMO5)
#if (defined(HAVE_SDL_AUDIO) \
&& !(CONFIG_PLATFORM & PLATFORM_MAEMO5)) \
|| (CONFIG_PLATFORM & PLATFORM_CTRU)
AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -80, 0, 0)
#else
#define AUDIOHW_CAPS (MONO_VOL_CAP)

View file

@ -41,7 +41,7 @@
/* NOTE: target-specific hosted HOME_DIR resides in filesystem-app.c */
#if !defined(APPLICATION) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \
defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX)
defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) || defined(CTRU)
#define HOME_DIR "/"
@ -87,7 +87,7 @@
#if defined(APPLICATION) && \
!(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX))
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) || defined(CTRU))
#define PLUGIN_DATA_DIR ROCKBOX_DIR "/rocks.data"
#define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR

View file

@ -9,8 +9,8 @@
"comment out" the non-ANSI parts of the ANSI header files (non-ANSI header
files aren't affected). */
#ifndef _ANSIDECL_H_
#define _ANSIDECL_H_
#ifndef __ANSIDECL_H__
#define __ANSIDECL_H__
/* First try to figure out whether we really are in an ANSI C environment. */
/* FIXME: This probably needs some work. Perhaps sys/config.h can be
@ -64,4 +64,4 @@
#endif
#endif
#endif /* _ANSIDECL_H_ */
#endif /* __ANSIDECL_H__ */

View file

@ -28,7 +28,9 @@
#include "fs_attr.h"
#include "fs_defines.h"
#if defined (APPLICATION) || defined(CHECKWPS)
#if defined(CTRU) && !defined(SIMULATOR)
#include "filesystem-ctru.h"
#elif defined (APPLICATION) || defined(CHECKWPS)
#include "filesystem-app.h"
#elif defined(SIMULATOR) || defined(DBTOOL)
#include "../../uisimulator/common/filesystem-sim.h"

View file

@ -40,7 +40,9 @@ enum relate_result
RELATE_PREFIX, /* the path2 contains path1 as a prefix */
};
#if defined(APPLICATION) || defined(CHECKWPS)
#if defined(CTRU) && !defined(SIMULATOR)
#include "filesystem-ctru.h"
#elif defined(APPLICATION) || defined(CHECKWPS)
#include "filesystem-app.h"
#elif defined(SIMULATOR) || defined(DBTOOL)
#include "../../uisimulator/common/filesystem-sim.h"

View file

@ -28,7 +28,7 @@
#endif
#ifndef __MINGW32__
#ifdef __APPLE__
#if defined(__APPLE__) || defined(CTRU)
#include <sys/types.h>
#else
#include <endian.h>

View file

@ -89,7 +89,7 @@ struct thread_entry;
*
* simulator (possibly) doesn't simulate stack usage anyway but well ... */
#if defined(HAVE_SDL_THREADS) || defined(__PCTOOL__)
#if defined(HAVE_SDL_THREADS) || defined(__PCTOOL__) || defined(CTRU)
#define DEFAULT_STACK_SIZE 0x100 /* tiny, ignored anyway */
#else
#include "asm/thread.h"

View file

@ -75,11 +75,15 @@ void mutex_lock(struct mutex *m)
/* Release ownership of a mutex object - only owning thread must call this */
void mutex_unlock(struct mutex *m)
{
#ifndef CTRU
/* FIXME: synchronization primitives does not behave
correctly between different cores */
/* unlocker not being the owner is an unlocking violation */
KERNEL_ASSERT(m->blocker.thread == __running_self_entry(),
"mutex_unlock->wrong thread (%s != %s)\n",
m->blocker.thread->name,
__running_self_entry()->name);
#endif
if(m->recursion > 0)
{

View file

@ -304,7 +304,7 @@ int thread_get_debug_info(unsigned int thread_id,
#ifdef HAVE_SCHEDULER_BOOSTCTRL
cpu_boost = thread->cpu_boost;
#endif
#ifndef HAVE_SDL_THREADS
#if !defined(HAVE_SDL_THREADS) && !defined(CTRU)
infop->stack_usage = stack_usage(thread->stack, thread->stack_size);
size_t stack_used_current =

View file

@ -32,7 +32,7 @@
*
* simulator (possibly) doesn't simulate stack usage anyway but well ... */
#if defined(HAVE_SDL_THREADS) || defined(__PCTOOL__)
#if defined(HAVE_SDL_THREADS) || defined(__PCTOOL__) || defined(CTRU)
struct regs
{
void *t; /* OS thread */

View file

@ -58,7 +58,11 @@ const char * handle_special_dirs(const char *dir, unsigned flags,
#ifdef WIN32
#include "filesystem-win32.h"
#else /* !WIN32 */
#if defined(CTRU) && !defined(SIMULATOR)
#include "filesystem-ctru.h"
#else
#include "filesystem-unix.h"
#endif
#endif /* WIN32 */
#include "filesystem-hosted.h"

View file

@ -24,7 +24,7 @@
#include <sys/time.h>
#if !defined(WIN32)
#include <sys/ioctl.h>
#if !defined(__APPLE__)
#if !defined(__APPLE__) && !defined(CTRU)
#include <linux/rtc.h>
#endif
#include <fcntl.h>
@ -49,7 +49,7 @@ int rtc_read_datetime(struct tm *tm)
int rtc_write_datetime(const struct tm *tm)
{
#if !defined(WIN32) && !defined(__APPLE__)
#if !defined(WIN32) && !defined(__APPLE__) && !defined(CTRU)
struct timeval tv;
struct tm *tm_time;

View file

@ -31,6 +31,12 @@ extern unsigned char plugin_end_addr[];
* avoid warning with certain compilers */
int _start(void) {return 0;}
#ifdef CTRU
/* dummy undefined symbols */
void __aeabi_unwind_cpp_pr0(void) {}
struct _reent * _EXFUN(__getreent, (void)) {}
#endif
enum codec_status codec_start(enum codec_entry_call_reason reason)
{
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)

View file

@ -137,6 +137,10 @@ ifeq ($(ARCH),arch_arm)
$(SGCLIB) : CODECFLAGS += -O1
$(VGMLIB) : CODECFLAGS += -O1
$(WAVPACKLIB) : CODECFLAGS += -O3
ifneq (,$(findstring ctru, $(MODELNAME)))
# segfault with -O1
$(SPCLIB) : CODECFLAGS += -O2
endif
else ifeq ($(ARCH),arch_m68k)
$(CODECLIB) : CODECFLAGS += -O2
$(A52LIB) : CODECFLAGS += -O2

View file

@ -424,6 +424,11 @@ sub buildzip {
glob_mkdir("$temp_dir/libertas");
glob_copy("$ROOT/firmware/drivers/libertas/firmware/*", "$temp_dir/libertas/");
}
# add hbmenu shortcut's icon and 3dsx executable
if ($modelname =~ /ctru/) {
glob_copy("icon.icn", "$temp_dir/");
glob_copy("rockbox.3dsx", "$temp_dir/");
}
glob_mkdir("$temp_dir/langs");
glob_mkdir("$temp_dir/rocks");
@ -740,6 +745,18 @@ sub runone {
move(".rockbox", $rbdir);
print "mv .rockbox $rbdir\n" if $verbose;
}
# add hbmenu shortcut and cia file to zip file
if ($modelname =~ /ctru/) {
move("rockbox.cia", "3ds");
copy("$ROOT/packaging/ctru/rockbox.xml", "3ds");
system("$ziptool -u $output 3ds/rockbox.xml $target >/dev/null");
print "$ziptool $output $ROOT/packaging/ctru/rockbox.xml $target >/dev/null\n" if $verbose;
system("$ziptool -u $output 3ds/rockbox.cia $target >/dev/null");
print "$ziptool $output rockbox.cia $target >/dev/null\n" if $verbose;
}
system("$ziptool $output $rbdir $target >/dev/null");
print "$ziptool $output $rbdir $target >/dev/null\n" if $verbose;
rmtree("$rbdir");

112
tools/configure vendored
View file

@ -1009,6 +1009,90 @@ rgnanocc () {
rbdir="/FunKey/.rockbox"
}
devkitarmcc () {
if [ -z "$DEVKITPRO" ]; then
echo "ERROR: You need a devkitPro toolchain and libraries installed"
echo "and have the DEVKITPRO environment variable point to the root"
echo "of the devkitPro installation."
echo "More info at https://devkitpro.org/wiki/Getting_Started"
exit
fi
if [ -z "$DEVKITARM" ]; then
echo "ERROR: You need devkitARM toolchain installed and have the DEVKITARM"
echo "environment variable point to the root directory of the sdk."
exit
fi
# check for additional dependencies
if [ ! -e "$DEVKITPRO/portlibs/3ds/lib/libCTRL.a" ]; then
echo "ERROR: You need to install libCTRL utility library."
echo "https://github.com/kynex7510/CTRL"
exit
fi
if [ ! -e "$DEVKITPRO/portlibs/3ds/lib/libdl.a" ]; then
echo "ERROR: You need to install libdl implementation for 3ds (CTRDL)"
echo "https://github.com/kynex7510/CTRDL"
exit
fi
if [ ! -n "`findtool makerom`" ]; then
echo "ERROR: makerom not found, please install and run configure again."
echo "https://github.com/3DSGuy/Project_CTR"
exit
fi
if [ ! -n "`findtool bannertool`" ]; then
echo "ERROR: bannertool not found, please install and run configure again."
echo "https://github.com/carstene1ns/3ds-bannertool"
exit
fi
arch="arm"
arch_version="6"
arch_profile="classic"
CC=$DEVKITARM/bin/arm-none-eabi-gcc
CPP=$DEVKITARM/bin/arm-none-eabi-cpp
LD=$DEVKITARM/bin/arm-none-eabi-ld
AR=$DEVKITARM/bin/arm-none-eabi-gcc-ar
AS=$DEVKITARM/bin/arm-none-eabi-as
OC=$DEVKITARM/bin/arm-none-eabi-objcopy
WINDRES=windres
DLLTOOL=dlltool
DLLWRAP=dllwrap
RANLIB=$DEVKITARM/bin/arm-none-eabi-gcc-ranlib
if [ "yes" = "$use_debug" ]; then
GCCOPTS=`echo $GCCOPTS | sed -e s/\ -Os/\ -Og/`
fi
GCCOPTS="$GCCOPTS -fno-builtin -g -Wno-unused-result"
GCCOPTS="$GCCOPTS -I$DEVKITPRO/libctru/include -I$DEVKITPRO/portlibs/3ds/include"
GCCOPTS="$GCCOPTS -mword-relocations -ffunction-sections -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft"
GCCOPTS="$GCCOPTS -D_GNU_SOURCE=1 -D_REENTRANT -masm-syntax-unified"
SHARED_LDFLAGS="-shared"
SHARED_CFLAGS="-fPIC -fvisibility=hidden"
LDOPTS="-specs=3dsx.specs -L$DEVKITPRO/libctru/lib -L$DEVKITPRO/portlibs/3ds/lib -ldl -lCTRL -lctru -lm"
GLOBAL_LDOPTS="$GLOBAL_LDOPTS -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft"
# let's allow building shared libraries even if unresolved symbols are found,
# CTRDL (libdl) implementation will use a custom resolver for resolve symbols at runtime.
# TODO: use ResGen command to automatically detect unresolved symbols.
GLOBAL_LDOPTS=`echo $GLOBAL_LDOPTS | sed -e s/\-Wl,-z,defs//`
# devkitarm already defines getcwd
GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-wrap,getcwd"
ARG_PREFIX="romfs"
extradefines="-D__3DS__"
rbdir="/3ds/.rockbox"
}
do_bootloader() {
appsdir='$(ROOTDIR)/bootloader'
@ -1779,6 +1863,9 @@ cat <<EOF
(hw4 bl only)
==Echo project== ==Surfans==
270) Echo R1 (WIP) 280) F28 (WIP)
==Nintendo==
290) Nintendo 3DS (WIP)
EOF
buildfor=`input`;
@ -4471,6 +4558,28 @@ fi
sysfontbl="16-Terminus"
;;
290|ctru)
target_id=122
application="yes"
modelname="ctru"
app_type="ctru-app"
target="CTRU"
memory=16
uname=`uname`
devkitarmcc
tool="cp "
boottool="cp "
bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
output="rockbox"
bootoutput="rockbox"
appextra="recorder:gui"
plugins="no"
t_cpu="hosted"
t_manufacturer="ctru"
t_model="app"
;;
*)
echo "Please select a supported target platform!"
exit 7
@ -5024,6 +5133,9 @@ if test -n "$t_cpu"; then
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted"
elif [ "$t_manufacturer" = "ibasso" ]; then
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/ibasso/tinyalsa/include"
elif [ "$application" = "yes" ] && [ "$t_manufacturer" = "ctru" ]; then
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/ctru/lib"
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/ctru/lib/bfile"
fi
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer"

View file

@ -40,6 +40,8 @@ ifndef APP_TYPE
objcopy = $(OC) $(if $(filter yes, $(USE_ELF)), -S -x, -O binary) $(1) $(2) # objcopy native
else ifneq (,$(findstring sdl-sim,$(APP_TYPE)))
objcopy = cp $(1) $(1).tmp;mv -f $(1).tmp $(2) # objcopy simulator
else ifneq (,$(findstring ctru,$(MODELNAME))) # 3dsxtool requires symbols
objcopy = cp $(1) $(1).tmp;mv -f $(1).tmp $(2)
else
ifdef DEBUG
objcopy = cp $(1) $(1).tmp;mv -f $(1).tmp $(2) # objcopy hosted (DEBUG)

View file

@ -171,6 +171,9 @@ else # core
ifneq (,$(findstring rgnano, $(MODELNAME)))
include $(ROOTDIR)/packaging/rgnano/rgnano.make
endif
ifneq (,$(findstring ctru, $(APP_TYPE)))
include $(ROOTDIR)/packaging/ctru/ctru.make
endif
endif # bootloader