Skip to content

Baremetal ARM library for the Nintendo 3DS, used by libctr9 and libctr11

License

Unknown and 2 other licenses found

Licenses found

Unknown
COPYING.txt
GPL-2.0
LICENSE-GPL2.txt
GPL-3.0
LICENSE-GPL3.txt
Notifications You must be signed in to change notification settings

gemarcano/libctr_core

________________________________________________________________________________

(Working title) libctr_core

Copyright 2016 Gabriel Marcano
________________________________________________________________________________


--------------------------------------------------------------------------------
Licensing
--------------------------------------------------------------------------------

This project is licensed under the GPL 2 or later licenses, at your choice.
Refer to COPYING for more licensing information and for the licensing for the
code borrowed from other sources.


--------------------------------------------------------------------------------
About
--------------------------------------------------------------------------------

This library is meant to be a collection of core routines used by libctr9 and
libctr11 for ARM 3DS development.

The library was meant to be linked with LTO, but due to technical limitations of
devKitARM with GCC 5.3, it is not. Instead, it is compiled with
-ffunction-section, so if the final executable uses the gc-section option for
the linker, the linker when linking the final executable will be able to throw
out parts of the library that are not in use, reducing executable size.

Note this library is still in active development and the API is not considered
stable. Breaking changes will be mentioned in commits at the very least.


--------------------------------------------------------------------------------
Dependencies
--------------------------------------------------------------------------------

 - FreeType2 - Used for font handling. Make sure it is installed somewhere that
    the compiler can pick it up, or use -L and -I to instruct the compiler where
    to find it. The build tools will attempt to find it within the prefix where
    libctr11 was configured to be installed in.

 - Autotools in general. These are used to create the build scripts.

 - autoconf-archive. Some of the macros provided by this packages are used by
    the bundled autoconf scripts.


--------------------------------------------------------------------------------
Compiling (TODO)
--------------------------------------------------------------------------------

Due to the differences between the devKitARM bundled libc between ARM9 and
ARM11, mostly having to do with hardware floating point support, libctr_core
must be compiled separately for libctr9 and libctr11.

The configure script supports the --with-gcc-arch option, which allows one to
specify an architecture or even CPU model to target. For reference, the ARM9
CPU in the 3DS is compatible with CPU model arm946e-s, and the ARM11 with
mpcore.

For convenience, the configure script has two --enable-* options that set up
some common compilation flags. --enable-thumb tells the project to compile the
library in Thumb mode, and --enable-3ds-arm11 enables some flags that make the
binary compatible with devKitARM's libc. Note that both cannot be enabled at the
same time (that is, it is not possible to compile an ARM11 application in thumb
mode that has hardware floating point support).

As a suggestion, it is recommended for one to set up a fixed prefix directory
and to store a share/config.site under the prefix. For example, if the variable
CTRARM11 holds the prefix path, then $CTRARM11/share/config.site is where this
file would be located. Any variables defined here will be picked up by configure
upon being run. At a minimum, if other libraries will be installed to the prefix
path, the config.site should have the following:

  CPPFLAGS="$CPPFLAGS -I$prefix/include -I$prefix/include/freetype2"
  LDFLAGS="-L$prefix/lib $LDFLAGS"

This example assumes that these directories exist, and in particular that
FreeType2's include path exists in the folder shown above. Refer to:
https://www.gnu.org/software/automake/manual/html_node/config_002esite.html
for more information and details about config.site files.

The Autotools setup assumes that devkitarm is already in the PATH.

 # this following line is if the 3ds compiler isn't in the path
 export PATH=${PATH}:${DEVKITPRO}/bin:${DEVKITARM}/bin
 autoreconf -if
 ./configure --host arm-none-eabi --with-gcc-arch=[architecture] \
   --prefix=[lib install path] --enable-[optional]
 make

Example for ARM11:
  export PATH=${PATH}:${DEVKITPRO}/bin:${DEVKITARM}/bin
  autoreconf -if
  ./configure --host arm-none-eabi --with-gcc-arch=mpcore \
    --prefix="$HOME/.local/usr/arm-none-eabi-11/" --enable-3ds-arm11
  make -j10

Example for ARM9:
  export PATH=${PATH}:${DEVKITPRO}/bin:${DEVKITARM}/bin
  autoreconf -if
  ./configure --host arm-none-eabi --with-gcc-arch=arm946e-s \
    --prefix="$HOME/.local/usr/arm-none-eabi-9/" --enable-thumb
  make -j10

As a heads up, if one does not set up a config.site in $prefix/share with the
freetype paths as shown above, one will need to add a -I gcc include directory
option to either CFLAGS or CPPFLAGS when invoking ./configure, so that it can
properly find the freetype header it is looking for. For example:

  ./configure --host arm-none-eabi --with-gcc-arch=arm946e-s \
    --prefix="$HOME/.local/usr/arm-none-eabi-9/" --enable-thumb \
	CPPFLAGS="-I"$HOME/.local/usr/arm-none-eabi-9/include/freetype2"


--------------------------------------------------------------------------------
Installation
--------------------------------------------------------------------------------

TBD. This library is built using Autotools, so it supports the 'make install'
and 'make uninstall' targets. Be sure to set --prefix when calling configure
if either of the preceeding targets will be used, else by default the generated
Makefile will install to /usr/local/ (most likely)) !

Example (after having compiled):
  #this will install to the directory specified in prefix, or /usr/local/ if
  #prefix isn't defined (most likely)!
  make install


--------------------------------------------------------------------------------
Usage
--------------------------------------------------------------------------------

Depending on where the library is installed, one may need to use -L in one's
projects to point the compiler to find the library, then use -lctr_core to cause
the linker to link in the static library.

Example:
  arm-none-eabi-gcc -I$HOME/.local/usr/arm-none-eabi-11/include \
    -L$HOME/.local/usr/arm-none-eabi-11/lib -Os -Wall -Wextra -Wpedantic \
	hello.c -lctr11 -lctr_core -lfreetype2

One setup that is recommended is to export a variable such as, CTRARM11 or
CTRARM9, to point to the root of the prefix where libctr_core is installed. This
way, it is easier to point to the lib and include directories (such as by using
$CTRARM11/include and $CTRARM9/lib, as examples).

This library may be useful for others, but it is meant to be a place where
shared code used by libctr9 and libctr11 can be placed and maintained. The
developer recommends using one of those libraries instead of libctr_core. Those
libraries do depend on libctr_core.


--------------------------------------------------------------------------------
Documentation
--------------------------------------------------------------------------------

This project uses Doxygen markup in order to facilitate the generation of
documentation, which should be found when generated in the doc/ folder. Each
header in the include/ directory should also be well documented and can be used
as reference for programming.

In addition, some documentation is hosted in GitHub pages:
    https://gemarcano.github.io/libctr_core/


--------------------------------------------------------------------------------
Testing - FIXME not there yet
--------------------------------------------------------------------------------

This project does include a homegrown unit testing framework and some unit tests
for this library. See the test/ directory for more information. Note that the
unit testing payload WILL write to NAND (in theory writes to areas that are
unused) as a part of unit testing.

To compile it, change directory to test/, then execute `make test`. The
generated test.bin is an A9LH compatible binary.


--------------------------------------------------------------------------------
Issues/Bugs
--------------------------------------------------------------------------------

Please report these to the issue tracker at the repository, and these will be
addressed as soon as possible, if not at least acknowledged. The more detailed
the reports, the more likely they are to be addressed quickly. In particular,
the following information can be quite useful when debugging bugs:

 - Type of 2/3DS system
 - Operating system being used to compile
 - Release/commit of library in use
 - Steps to reproduce issue
 - Expected behavior
 - Actual behavior
 - ARM9 entry point
 - How the ARM payload was launched and set up
 - Any modifications to the library, or extensions


--------------------------------------------------------------------------------
Contributing
--------------------------------------------------------------------------------

Pull requests are welcome. All requests will be looked at in detail, and must be
documented in a similar fashion as the rest of the code for this project. In
particular, it is unlikely (but not impossible) that code that emmits warnings
with the warnings in use by this library would be merged without first fixing/
addressing what is causing the warnings to be emitted.


--------------------------------------------------------------------------------
Credits
--------------------------------------------------------------------------------

 - #3dshacks @ Rizon for starting me on my path to 3DS homebrew development
 - #Cakey @ Freenode for the continued development support
 - #3dsdev @ EFNet for the occasional help answering questions
 - d0k3 for some code use in this library and for suggestions
 - dark_samus for helping to develop A9LH stuff in Cakey, which drove for the
    development of this library
 - Delebile for publishing the public arm9loaderhax implementation, making using
    and testing this library possible (or less of a pain)
 - Aurora, et. al (you know who you are, I hope) for for general development
    help and brainstorming
 - Normmatt for yelling at me for screwing up his sdmmc code :) Also a lot of
    other general 3DS development stuff
 - bilis for his ctr library (a small amount of code from that is used) and for
    his QEMU implementation of the 3DS ARM9 environment.

 - See COPYING for details about code usage from other sources

About

Baremetal ARM library for the Nintendo 3DS, used by libctr9 and libctr11

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
COPYING.txt
GPL-2.0
LICENSE-GPL2.txt
GPL-3.0
LICENSE-GPL3.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published