mirror of
https://github.com/LumaTeam/Luma3DS.git
synced 2026-02-22 18:04:38 +00:00
Compare commits
No commits in common. "master" and "v8.1.1" have entirely different histories.
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,2 +0,0 @@
|
|||||||
*.xml text eol=lf
|
|
||||||
*.ini text eol=lf
|
|
||||||
88
.github/ISSUE_TEMPLATE.md
vendored
Normal file
88
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<!--
|
||||||
|
-- THIS IS NOT A SUPPORT FORUM! For support go here:
|
||||||
|
-- Nintendo Hacking: https://discord.gg/MjzatM8y
|
||||||
|
--
|
||||||
|
-- Also check the Wiki (https://github.com/AuroraWright/Luma3DS/wiki) before making an issue.
|
||||||
|
--
|
||||||
|
-- For GBA/DSiWare/DS/AGB_FIRM/TWL_FIRM problems: https://3ds.guide/troubleshooting
|
||||||
|
-- If you're using an emu/redNAND anything related to that must also be installed to sysNAND.
|
||||||
|
-- Please make sure to read "Enable game patching" https://github.com/AuroraWright/Luma3DS/wiki/Options-and-usage before posting any issues about the "Enable game patching" option(s).
|
||||||
|
--
|
||||||
|
-- Luma updaters that don't support Boot9Strap/Sighax won't work.
|
||||||
|
-- This is due to support for non-B9S/Sighax entrypoints being dropped.
|
||||||
|
--
|
||||||
|
-- Please fill in the placeholders.-->
|
||||||
|
**System model:**
|
||||||
|
|
||||||
|
[e.g. 2DS, New 3DS, Old 3DS]
|
||||||
|
|
||||||
|
**SysNAND version (+emu/redNAND version if applicable):**
|
||||||
|
|
||||||
|
[e.g. 11.4.0-37U SysNAND, 11.4.0-37J EmuNAND]
|
||||||
|
|
||||||
|
**Entrypoint (How/what you're using to boot Luma3DS):**
|
||||||
|
|
||||||
|
[e.g. Boot9Strap/Sighax, etc.]
|
||||||
|
|
||||||
|
**Luma3DS version:**
|
||||||
|
|
||||||
|
[e.g. 8.1 stable or if using nightly/hourly specify the commit like this https://github.com/AuroraWright/Luma3DS/commit/9570e6cbeca53128433abbf5e3473cb8a07fe69e]
|
||||||
|
<!--You can check which version you're on in System Settings. It will be on the bottom right of the top screen.-->
|
||||||
|
|
||||||
|
|
||||||
|
**Luma3DS configuration/options:**
|
||||||
|
|
||||||
|
Default EmuNAND: ( )
|
||||||
|
|
||||||
|
Screen brightness: ( )
|
||||||
|
|
||||||
|
Splash: ( )
|
||||||
|
|
||||||
|
PIN lock: ( )
|
||||||
|
|
||||||
|
New 3DS CPU: ( )
|
||||||
|
<!--This option is only available for New 3DS/2DS.-->
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Autoboot EmuNAND: ( )
|
||||||
|
|
||||||
|
Use EmuNAND FIRM if booting with R: ( )
|
||||||
|
|
||||||
|
Enable loading external FIRMs and modules: ( )
|
||||||
|
<!--Firmware (.bin) files are not required by Luma, or NTR CFW anymore.
|
||||||
|
-- If you're having issues with this option enabled try deleting them from the luma folder on the root of the SD card and disabling this option.-->
|
||||||
|
|
||||||
|
Enable game patching: ( )
|
||||||
|
|
||||||
|
Show NAND or user string in System Settings: ( )
|
||||||
|
|
||||||
|
Show GBA boot screen in patched AGB_FIRM: ( )
|
||||||
|
|
||||||
|
Patch ARM9 access: ( )
|
||||||
|
|
||||||
|
Set developer UNITINFO: ( )
|
||||||
|
|
||||||
|
Disable ARM11 exception handlers: ( )
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
|
||||||
|
**Explanation of the issue:**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Steps to reproduce:**
|
||||||
|
|
||||||
|
1.
|
||||||
|
|
||||||
|
2.
|
||||||
|
|
||||||
|
|
||||||
|
**Dump file:**
|
||||||
|
<!--If the issue leads to a crash you can generate a crash dump by checking the "Enable exception handlers" option.
|
||||||
|
-- The error message will tell you where the dump is.
|
||||||
|
-- Zip the dmp file and drag & drop it below.-->
|
||||||
96
.github/ISSUE_TEMPLATE/bug-report.md
vendored
96
.github/ISSUE_TEMPLATE/bug-report.md
vendored
@ -1,96 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Use this to report bugs you encounter with Luma3DS. Make sure you upload the crash dumps if Luma3DS crashes.
|
|
||||||
---
|
|
||||||
|
|
||||||
<!--
|
|
||||||
-- THIS IS NOT A SUPPORT FORUM! For support go here:
|
|
||||||
-- Nintendo Homebrew: https://discord.gg/MjzatM8
|
|
||||||
--
|
|
||||||
-- Rosalina feature requests go here: https://github.com/LumaTeam/Luma3DS/issues/752
|
|
||||||
--
|
|
||||||
-- Also check the Wiki (https://github.com/LumaTeam/Luma3DS/wiki) before making an issue.
|
|
||||||
--
|
|
||||||
-- For GBA/DSiWare/DS/AGB_FIRM/TWL_FIRM problems: use https://github.com/MechanicalDragon0687/TWLFix-CFW and update your system.
|
|
||||||
-- If you're using an emu/redNAND try installing anything on it to sysNAND.
|
|
||||||
-- Please make sure to read "Enable game patching" https://github.com/LumaTeam/Luma3DS/wiki/Options-and-usage before posting any issues about the "Enable game patching" option(s).
|
|
||||||
--
|
|
||||||
-- Luma updaters that don't support Boot9Strap/Sighax won't work.
|
|
||||||
-- This is due to support for non-B9S/Sighax entrypoints being dropped.
|
|
||||||
--
|
|
||||||
-- Please fill in the placeholders.-->
|
|
||||||
**System model:**
|
|
||||||
|
|
||||||
[New 2DS XL, New 3DS XL, New 3DS, Old 2DS, Old 3DS XL, Old 3DS]
|
|
||||||
|
|
||||||
**SysNAND version (+emu/redNAND version if applicable):**
|
|
||||||
|
|
||||||
[e.g. 11.17.0-50U SysNAND, 11.17.0-50E EmuNAND]
|
|
||||||
<!--You can check which version you're on in System Settings. It will be on the bottom right of the top screen.-->
|
|
||||||
|
|
||||||
**Entrypoint (How/what you're using to boot Luma3DS):**
|
|
||||||
|
|
||||||
[e.g. Boot9Strap/Sighax, etc.]
|
|
||||||
|
|
||||||
**Luma3DS version:**
|
|
||||||
|
|
||||||
[e.g. v13.2.1 stable or if using non-releases specify the commit like this https://github.com/LumaTeam/Luma3DS/commit/988ec17ebfce513fc4589f7b12e0d6e3894ae542]
|
|
||||||
|
|
||||||
**Luma3DS configuration/options:**
|
|
||||||
|
|
||||||
Default EmuNAND: ( )
|
|
||||||
<!--This option is only available if there's at least one EmuNAND.-->
|
|
||||||
|
|
||||||
Screen brightness: ( )
|
|
||||||
|
|
||||||
Splash: ( )
|
|
||||||
|
|
||||||
Splash duration: ( )
|
|
||||||
|
|
||||||
PIN lock: ( )
|
|
||||||
|
|
||||||
New 3DS CPU: ( )
|
|
||||||
<!--This option is only available on New 3DS (XL)/New 2DS XL.-->
|
|
||||||
|
|
||||||
Hbmenu autoboot: ( )
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
Autoboot EmuNAND: ( )
|
|
||||||
<!--This option is only available if there's at least one EmuNAND.-->
|
|
||||||
|
|
||||||
Enable loading external FIRMs and modules: ( )
|
|
||||||
<!--Firmware (.bin) files are not required by Luma, or NTR CFW anymore.
|
|
||||||
-- If you're having issues with this option enabled try deleting them from the luma folder on the root of the SD card or /rw/luma on CTRNAND and disabling this option.-->
|
|
||||||
|
|
||||||
Enable game patching: ( )
|
|
||||||
|
|
||||||
Redirect app. syscore threads to core2: ( )
|
|
||||||
<!--This option is only available on New 3DS (XL)/New 2DS XL.-->
|
|
||||||
|
|
||||||
Show NAND or user string in System Settings: ( )
|
|
||||||
|
|
||||||
Show GBA boot screen in patched AGB_FIRM: ( )
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
|
|
||||||
**Explanation of the issue:**
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**Steps to reproduce:**
|
|
||||||
|
|
||||||
1.
|
|
||||||
|
|
||||||
2.
|
|
||||||
|
|
||||||
|
|
||||||
**Dump file (if applicable):**
|
|
||||||
<!--If the issue leads to a crash you must ensure the "Disable Arm11 exception handlers"
|
|
||||||
-- option is not disabled in config.ini.
|
|
||||||
-- The error message will tell you where the dump is.
|
|
||||||
-- Zip the dmp file and drag & drop it below.-->
|
|
||||||
8
.gitignore
vendored
8
.gitignore
vendored
@ -13,12 +13,4 @@ exceptions/arm11/build
|
|||||||
*.d
|
*.d
|
||||||
*.elf
|
*.elf
|
||||||
*.cxi
|
*.cxi
|
||||||
*.3dsx
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.dmp
|
|
||||||
.project
|
|
||||||
.cproject
|
|
||||||
.settings
|
|
||||||
|
|
||||||
Luma3DS*.zip
|
|
||||||
hbmenu.zip
|
|
||||||
|
|||||||
174
Makefile
174
Makefile
@ -1,48 +1,162 @@
|
|||||||
|
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
||||||
|
|
||||||
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq ($(strip $(shell firmtool -v 2>&1 | grep usage)),)
|
ifneq ($(strip $(shell firmtool -v 2>&1 | grep usage)),)
|
||||||
$(error "Please install firmtool v1.1 or greater")
|
$(error "Please install firmtool v1.1 or greater")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Disable kext and firmlaunch patches, all custom sysmodules except Loader, enable PASLR.
|
include $(DEVKITARM)/base_tools
|
||||||
# Dangerous. Don't enable this unless you know what you're doing!
|
|
||||||
export BUILD_FOR_EXPLOIT_DEV ?= 0
|
|
||||||
|
|
||||||
# Build with O0 & frame pointer information for use with GDB
|
name := Luma3DS
|
||||||
export BUILD_FOR_GDB ?= 0
|
revision := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
|
||||||
|
version_major := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f1 -d.)
|
||||||
|
version_minor := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f2 -d.)
|
||||||
|
version_build := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f3 -d.)
|
||||||
|
commit := $(shell git rev-parse --short=8 HEAD)
|
||||||
|
is_release := 0
|
||||||
|
|
||||||
# Default 3DSX TitleID for hb:ldr
|
ifeq ($(strip $(revision)),)
|
||||||
export HBLDR_DEFAULT_3DSX_TID ?= 000400000D921E00
|
revision := v0.0.0-0
|
||||||
|
version_major := 0
|
||||||
|
version_minor := 0
|
||||||
|
version_build := 0
|
||||||
|
endif
|
||||||
|
|
||||||
# What to call the title corresponding to HBLDR_DEFAULT_3DSX_TID
|
ifeq ($(strip $(commit)),)
|
||||||
export HBLDR_DEFAULT_3DSX_TITLE_NAME ?= "hblauncher_loader"
|
commit := 0
|
||||||
|
endif
|
||||||
|
|
||||||
NAME := $(notdir $(CURDIR))
|
ifeq ($(strip $(version_build)),)
|
||||||
REVISION := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
|
version_build := 0
|
||||||
|
endif
|
||||||
|
|
||||||
SUBFOLDERS := sysmodules arm11 arm9 k11_extension
|
ifeq ($(strip $(shell git describe --tags --match v[0-9]* | grep -)),)
|
||||||
|
is_release := 1
|
||||||
|
endif
|
||||||
|
|
||||||
.PHONY: all release clean $(SUBFOLDERS)
|
dir_source := source
|
||||||
|
dir_patches := patches
|
||||||
|
dir_arm11 := arm11
|
||||||
|
dir_chainloader := chainloader
|
||||||
|
dir_exceptions := exceptions
|
||||||
|
dir_arm9_exceptions := $(dir_exceptions)/arm9
|
||||||
|
dir_k11_extension := k11_extension
|
||||||
|
dir_sysmodules := sysmodules
|
||||||
|
dir_loader := $(dir_sysmodules)/loader
|
||||||
|
dir_rosalina := $(dir_sysmodules)/rosalina
|
||||||
|
dir_build := build
|
||||||
|
dir_out := out
|
||||||
|
|
||||||
all: boot.firm
|
ASFLAGS := -mcpu=arm946e-s
|
||||||
|
CFLAGS := -Wall -Wextra $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math
|
||||||
|
LDFLAGS := -nostartfiles -Wl,--nmagic
|
||||||
|
|
||||||
release: $(NAME)$(REVISION).zip
|
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||||
|
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
||||||
|
$(call rwildcard, $(dir_source), *.s *.c)))
|
||||||
|
|
||||||
|
bundled = $(dir_build)/reboot.bin.o $(dir_build)/emunand.bin.o $(dir_build)/chainloader.bin.o $(dir_build)/arm9_exceptions.bin.o
|
||||||
|
|
||||||
|
modules = $(dir_build)/loader.cxi $(dir_build)/rosalina.cxi
|
||||||
|
|
||||||
|
define bin2o
|
||||||
|
bin2s $< | $(AS) -o $(@)
|
||||||
|
endef
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: firm
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release: $(dir_out)/$(name)$(revision).7z
|
||||||
|
|
||||||
|
.PHONY: firm
|
||||||
|
firm: $(dir_out)/boot.firm
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@$(foreach dir, $(SUBFOLDERS), $(MAKE) -C $(dir) clean &&) true
|
@$(MAKE) -C $(dir_arm11) clean
|
||||||
@rm -rf *.firm *.zip *.3dsx
|
@$(MAKE) -C $(dir_chainloader) clean
|
||||||
|
@$(MAKE) -C $(dir_arm9_exceptions) clean
|
||||||
|
@$(MAKE) -C $(dir_k11_extension) clean
|
||||||
|
@$(MAKE) -C $(dir_loader) clean
|
||||||
|
@$(MAKE) -C $(dir_rosalina) clean
|
||||||
|
@rm -rf $(dir_out) $(dir_build)
|
||||||
|
|
||||||
# boot.3dsx comes from https://github.com/fincs/new-hbmenu/releases
|
.PRECIOUS: $(dir_build)/%.bin
|
||||||
$(NAME)$(REVISION).zip: hbmenu.zip boot.firm
|
|
||||||
@cp $< $@
|
|
||||||
@zip $@ boot.firm -x "*.DS_Store*" "*__MACOSX*"
|
|
||||||
|
|
||||||
boot.firm: $(SUBFOLDERS)
|
.PHONY: $(dir_arm11)
|
||||||
@firmtool build $@ -D sysmodules/sysmodules.bin arm11/arm11.elf arm9/arm9.elf k11_extension/k11_extension.elf \
|
.PHONY: $(dir_chainloader)
|
||||||
-A 0x18180000 -C XDMA XDMA NDMA XDMA
|
.PHONY: $(dir_arm9_exceptions)
|
||||||
@echo built... $(notdir $@)
|
.PHONY: $(dir_k11_extension)
|
||||||
|
.PHONY: $(dir_loader)
|
||||||
|
.PHONY: $(dir_rosalina)
|
||||||
|
|
||||||
hbmenu.zip:
|
$(dir_out)/$(name)$(revision).7z: all
|
||||||
@curl -sSfL $(shell curl -s https://api.github.com/repos/devkitPro/3ds-hbmenu/releases/latest | grep 'browser_' | cut -d\" -f4) -o $@
|
@mkdir -p "$(@D)"
|
||||||
@echo downloaded... $(notdir $@)
|
@7z a -mx $@ ./$(@D)/* ./$(dir_exceptions)/exception_dump_parser.py
|
||||||
|
|
||||||
$(SUBFOLDERS):
|
$(dir_out)/boot.firm: $(dir_build)/modules.bin $(dir_build)/arm11.elf $(dir_build)/main.elf $(dir_build)/k11_extension.bin
|
||||||
@$(MAKE) -C $@ all
|
@mkdir -p "$(@D)"
|
||||||
|
@firmtool build $@ -D $^ -A 0x18180000 0x18000000 -C XDMA XDMA NDMA XDMA
|
||||||
|
|
||||||
|
$(dir_build)/modules.bin: $(modules)
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
cat $^ > $@
|
||||||
|
|
||||||
|
$(dir_build)/arm11.elf: $(dir_arm11)
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@$(MAKE) -C $<
|
||||||
|
|
||||||
|
$(dir_build)/main.elf: $(bundled) $(objects)
|
||||||
|
$(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^
|
||||||
|
|
||||||
|
$(dir_build)/k11_extension.bin: $(dir_k11_extension)
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@$(MAKE) -C $<
|
||||||
|
|
||||||
|
$(dir_build)/loader.cxi: $(dir_loader)
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@$(MAKE) -C $<
|
||||||
|
|
||||||
|
$(dir_build)/rosalina.cxi: $(dir_rosalina)
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@$(MAKE) -C $<
|
||||||
|
|
||||||
|
$(dir_build)/%.bin.o: $(dir_build)/%.bin
|
||||||
|
@$(bin2o)
|
||||||
|
|
||||||
|
$(dir_build)/chainloader.bin: $(dir_chainloader)
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@$(MAKE) -C $<
|
||||||
|
|
||||||
|
$(dir_build)/arm9_exceptions.bin: $(dir_arm9_exceptions)
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@$(MAKE) -C $<
|
||||||
|
|
||||||
|
$(dir_build)/%.bin: $(dir_patches)/%.s
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@armips $<
|
||||||
|
|
||||||
|
$(dir_build)/memory.o $(dir_build)/strings.o: CFLAGS += -O3
|
||||||
|
$(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(revision) configuration\""
|
||||||
|
$(dir_build)/patches.o: CFLAGS += -DVERSION_MAJOR="$(version_major)" -DVERSION_MINOR="$(version_minor)"\
|
||||||
|
-DVERSION_BUILD="$(version_build)" -DISRELEASE="$(is_release)" -DCOMMIT_HASH="0x$(commit)"
|
||||||
|
$(dir_build)/firm.o: $(dir_build)/modules.bin
|
||||||
|
$(dir_build)/firm.o: CFLAGS += -DLUMA_SECTION0_SIZE="$(shell wc -c $(dir_build)/modules.bin | tr -d [:space:][:alpha:][:punct:])"
|
||||||
|
|
||||||
|
$(dir_build)/bundled.h: $(bundled)
|
||||||
|
@$(foreach f, $(bundled),\
|
||||||
|
echo "extern const u8" `(echo $(basename $(notdir $(f))) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> $@;\
|
||||||
|
echo "extern const u32" `(echo $(basename $(notdir $(f)))| sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> $@;\
|
||||||
|
)
|
||||||
|
|
||||||
|
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/bundled.h
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||||
|
|
||||||
|
$(dir_build)/%.o: $(dir_source)/%.s
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||||
|
|||||||
122
README.md
122
README.md
@ -1,112 +1,40 @@
|
|||||||
# Luma3DS
|
# Luma3DS
|
||||||
|
*Noob-proof (N)3DS "Custom Firmware"*
|
||||||
|
|
||||||

|
## What it is
|
||||||

|
|
||||||
|
|
||||||
*Nintendo 3DS "Custom Firmware"*
|
**Luma3DS** is a program to patch the system software of (New) Nintendo 3DS handheld consoles "on the fly", adding features (such as per-game language settings and debugging capabilities for developers) and removing restrictions enforced by Nintendo (such as the region lock).
|
||||||
|
It also allows you to run unauthorized ("homebrew") content by removing signature checks.
|
||||||
|
To use it, you will need a console capable of running homebrew software on the ARM9 processor. We recommend [Plailect's guide](https://3ds.guide/) for details on how to get your system ready.
|
||||||
|
|
||||||

|
Since Luma3DS v8.0, Luma3DS has its own in-game menu, triggerable by `L+Down+Select` (see the [release notes](https://github.com/AuroraWright/Luma3DS/releases/tag/v8.0)).
|
||||||

|
|
||||||
|
|
||||||
## Description
|
---
|
||||||
**Luma3DS** patches and reimplements significant parts of the system software running on all models of the Nintendo 3DS family of consoles. It aims to greatly improve the user experience and support the 3DS far beyond its end-of-life. Features include:
|
|
||||||
|
|
||||||
* **First-class support for homebrew applications**
|
## Compiling
|
||||||
* **Rosalina**, an overlay menu (triggered by <kbd>L+Down+Select</kbd> by default), allowing things like:
|
|
||||||
* Taking screenshots while in game
|
|
||||||
* Blue light filters and other screen filters
|
|
||||||
* Input redirection to play with external devices, such as controllers
|
|
||||||
* Using cheat codes
|
|
||||||
* Setting time and date accurately from the network (NTP)
|
|
||||||
* ... and much more!
|
|
||||||
* **Many game modding features**, such as, but not limited to:
|
|
||||||
* Game plugins (in 3GX format)
|
|
||||||
* Per-game language overrides ("locale emulation")
|
|
||||||
* Asset content path redirection ("LayeredFS")
|
|
||||||
* **Support for user-provided patches and/or full "system modules" replacements**, an essential feature for Nintendo Network replacements (amongst other projects)
|
|
||||||
* A **fully-fledged GDB stub**, allowing homebrew developers and reverse-engineers alike to work much more efficiently
|
|
||||||
* Ability to chainload other firmware files, including other versions of itself
|
|
||||||
* ... and much more!
|
|
||||||
|
|
||||||
## Installation and upgrade
|
First you need to clone the repository with: `git clone https://github.com/AuroraWright/Luma3DS.git`
|
||||||
Luma3DS requires [boot9strap](https://github.com/SciresM/boot9strap) to run.
|
To compile, you'll need [armips](https://github.com/Kingcom/armips) and a build of a recent commit of [makerom](https://github.com/profi200/Project_CTR) added to your PATH. You'll also need to install [firmtool](https://github.com/TuxSH/firmtool), its README contains installation instructions.
|
||||||
|
For now, you'll also need to update your [libctru](https://github.com/smealum/ctrulib) install, building from the latest commit.
|
||||||
|
For your convenience, here are [Windows](http://www91.zippyshare.com/v/ePGpjk9r/file.html) and [Linux](https://mega.nz/#!uQ1T1IAD!Q91O0e12LXKiaXh_YjXD3D5m8_W3FuMI-hEa6KVMRDQ) builds of armips (thanks to who compiled them!) and [makerom](https://github.com/Steveice10/buildtools/tree/master/3ds) (thanks @Steveice10!).
|
||||||
|
Finally just run `make` and everything should work!
|
||||||
|
You can find the compiled files in the `out` folder.
|
||||||
|
|
||||||
Once boot9strap has been installed, simply download the [latest release archive](https://github.com/LumaTeam/Luma3DS/releases/latest) and extract the archive onto the root of your SD card to "install" or to upgrade Luma3DS alongside the [homebrew menu and certs bundle](https://github.com/devkitPro/3ds-hbmenu) shipped with it. Replace existing files and merge existing folders if necessary.
|
---
|
||||||
|
|
||||||
## Basic usage
|
## Setup / Usage / Features
|
||||||
**The main Luma3DS configuration menu** can be accessed by pressing <kbd>Select</kbd> at boot. The configuration file is stored in `/luma/config.ini` on the SD card (or `/rw/luma/config.ini` on the CTRNAND partition if Luma3DS has been launched from the CTRNAND partition, which happens when SD card is missing).
|
|
||||||
|
|
||||||
**The chainloader menu** is accessed by pressing <kbd>Start</kbd> at boot, or from the configuration menu. Payloads are expected to be located in `/luma/payloads` with the `.firm` extension; if there is only one such payload, the aforementionned selection menu will be skipped. Hotkeys can be assigned to payload, for example `x_test.firm` will be chainloaded when <kbd>X</kbd> is pressed at boot.
|
See https://github.com/AuroraWright/Luma3DS/wiki
|
||||||
|
|
||||||
**The overlay menu, Rosalina**, has a default button combination: <kbd>L+Down+Select</kbd>. For greater flexbility, most Rosalina menu settings aren't saved automatically, hence the "Save settings" option.
|
---
|
||||||
|
|
||||||
**GDB ports**, when enabled, are `4000-4002` for the normal ports. Use of `attach` in "extended-remote" mode, alongside `info os processes` is supported and encouraged (for reverse-engineering, also check out `monitor getmemregions`). The port for the break-on-start feature is `4003` without "extended-remote". Both devkitARM-patched GDB and IDA Pro (without "stepping support" enabled) are actively supported.
|
|
||||||
|
|
||||||
We have a wiki, however it is currently very outdated.
|
|
||||||
|
|
||||||
## Components
|
|
||||||
|
|
||||||
Luma3DS consists of multiple components. While the code style within each component is mostly consistent, these components have been written over many years and may not reflect how maintainers would write new code in new components/projects:
|
|
||||||
|
|
||||||
* **arm9**, **arm11**: baremetal main settings menu, chainloader and firmware loader. Aside from showing settings and chainloading to other homebrew firmware files on demand, it is responsible for patching the official firmware to modify `Process9` code and to inject all other custom components. This was the first component ever written for this project, in 2015
|
|
||||||
* **k11_extension**: code extending the Arm11 `NATIVE_FIRM` kernel (`Kernel11`). It is injected by the above mentioned baremetal loader into the kernel by hooking its startup code, then hooks itself into the rest of the kernel. Its features include hooking system calls (SVCs), introducing new SVCs and hooking into interprocess communications, to bypass limitations in Nintendo's system design. This is the component that allows Rosalina to pause other processes on overlay menu entry, for example. This was written at a time when we didn't fully reverse-engineer the kernel, and originally released in 2017 alongside Rosalina. Further hooks for "game plugin" support have been merged in 2023
|
|
||||||
* **sysmodules**: reimplementation of "system modules" (processes) of the 3DS's OS (except for Rosalina being custom), currently only initial processes loaded directly in-memory by the kernel ("kernel initial process", or KIP in short)
|
|
||||||
* **loader**: process that loads non-KIP processes from storage. Because this is the perfect place to patch/replace executable code, this is where all process patches are done, enabling in particular "game modding" features. This is also the sysmodule handling 3DSX homebrew loading. Introduced in 2016
|
|
||||||
* _**rosalina**_: the most important component of Luma3DS and custom KIP: overlay menu, GDB server, `err:f` (fatal error screen) reimplementation, and much more. Introduced in mid-2017, and has continuously undergone changes and received many external contributions ever since
|
|
||||||
* **pxi**: Arm11<>Arm9 communication KIP, reimplemented just for the sake of it. Introduced late 2017
|
|
||||||
* **sm**: service manager KIP, reimplemented to remove service access control restrictions. Introduced late 2017
|
|
||||||
* **pm**: process manager KIP reponsible of starting/terminating processes and instructing `loader` to load them. The reimplemention allows for break-on-start GDB feature in Rosalina, as well as lifting FS access control restrictions the proper way. Introduced in 2019
|
|
||||||
|
|
||||||
## Maintainers
|
|
||||||
|
|
||||||
* **[@TuxSH](https://github.com/TuxSH)**: lead developer, created and maintains most features of the project. Joined in 2016
|
|
||||||
* **[@AuroraWright](https://github.com/AuroraWright)**: author of the project, implemented the core features (most of the baremetal boot settings menu and firmware loading code) with successful design decisions that made the project popular. Created the project in 2015, currently inactive
|
|
||||||
* **[@PabloMK7](https://github.com/PabloMK7)**: maintainer of the plugin loader feature merged for the v13.0 release. Joined in 2023
|
|
||||||
|
|
||||||
## Roadmap
|
|
||||||
|
|
||||||
There are still a lot more features and consolidation planned for Luma3DS! Here is a list of what is currently in store:
|
|
||||||
|
|
||||||
* Full reimplementation of `TwlBg` and `AgbBg`. This will allow much better, and more configurable, upscaling for top screen in DS and GBA games (except on Old 2DS). This is currently being developed privately in C++23 (no ETA). While this is quite a difficult endeavor as this requires rewriting the entire driver stack in semi-bare-metal (limited kernel with no IPC), this is the most critical feature for Luma3DS to have and will make driver sysmodule reimpelementation trivial
|
|
||||||
* Reimplementation of `Process9` for `TWL_FIRM` and `AGB_FIRM` to allow for more features in DS and GBA compatibility mode (ones that require file access)
|
|
||||||
* Eventually, a full `Kernel11` reimplementation
|
|
||||||
|
|
||||||
## Known issues
|
|
||||||
|
|
||||||
* **Cheat engine crashes with some applications, in particular Pokémon games**: there is a race condition in Nintendo's `Kernel11` pertaining to attaching a new `KDebugThread` to a `KThread` on thread creation, and another thread null-dereferencing `thread->debugThread`. This causes the cheat engine to crashes games that create and destroy many threads all the time (like Pokémon).
|
|
||||||
* For these games, having a **dedicated "game plugin"** is the only alternative until `Kernel11` is reimplemented.
|
|
||||||
* **Applications reacting to Rosalina menu button combo**: Rosalina merely polls button input at an interval to know when to show the menu. This means that the Rosalina menu combo can sometimes be processed by the game/process that is going to be paused.
|
|
||||||
* You can **change the menu combo** in the "Miscellaneous options" submenu (then save it with "Save settings" in the main menu) to work around this.
|
|
||||||
|
|
||||||
## Building from source
|
|
||||||
|
|
||||||
To build Luma3DS, the following is needed:
|
|
||||||
* git
|
|
||||||
* [makerom](https://github.com/jakcron/Project_CTR) in `$PATH`
|
|
||||||
* [firmtool](https://github.com/TuxSH/firmtool) installed
|
|
||||||
* up-to-date devkitARM and libctru:
|
|
||||||
* install `dkp-pacman` (or, for distributions that already provide pacman, add repositories): https://devkitpro.org/wiki/devkitPro_pacman
|
|
||||||
* install packages from `3ds-dev` metapackage: `sudo dkp-pacman -S 3ds-dev --needed`
|
|
||||||
* while libctru and Luma3DS releases are kept in sync, you may have to build libctru from source for non-release Luma3DS commits
|
|
||||||
|
|
||||||
While Luma3DS releases are bundled with `3ds-hbmenu`, Luma3DS actually compiles into one single file: `boot.firm`. Just copy it over to the root of your SD card ([ftpd](https://github.com/mtheall/ftpd) is the easiest way to do so), and you're done.
|
|
||||||
|
|
||||||
## Licensing
|
|
||||||
This software is licensed under the terms of the GPLv3. You can find a copy of the license in the LICENSE.txt file.
|
|
||||||
|
|
||||||
Files in the GDB stub are instead triple-licensed as MIT or "GPLv2 or any later version", in which case it's specified in the file header. PM, SM, PXI reimplementations are also licensed under MIT.
|
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
Luma3DS would not be what it is without the contributions and constructive feedback of many. We would like to thanks in particular:
|
See https://github.com/AuroraWright/Luma3DS/wiki/Credits
|
||||||
|
|
||||||
* **[@devkitPro](https://github.com/devkitPro)** (especially **[@fincs](https://github.com/fincs)**, **[@WinterMute](https://github.com/WinterMute)** and **[@mtheall](https://github.com/mtheall)**) for providing quality and easy-to-use toolchains with bleeding-edge GCC, and for their continued technical advice
|
---
|
||||||
* **[@Nanquitas](https://github.com/Nanquitas)** for the initial version of the game plugin loader code as well as very useful contributions to the GDB stub
|
|
||||||
* **[@piepie62](https://github.com/piepie62)** for the current implementation of the Rosalina cheat engine, **Duckbill** for its original implementation
|
## Licensing
|
||||||
* **[@panicbit](https://github.com/panicbit)** for the original implementation of screen filters in Rosalina
|
|
||||||
* **[@jasondellaluce](https://github.com/jasondellaluce)** for LayeredFS
|
This software is licensed under the terms of the GPLv3.
|
||||||
* **[@LiquidFenrir](https://github.com/LiquidFenrir)** for the memory viewer inside Rosalina's "Process List"
|
You can find a copy of the license in the LICENSE.txt file.
|
||||||
* **ChaN** for [FatFs](http://elm-chan.org/fsw/ff/00index_e.html)
|
|
||||||
* Everyone who has contributed to the Luma3DS repository
|
|
||||||
* Everyone who has assisted with troubleshooting end-users
|
|
||||||
* Everyone who has provided constructive feedback to Luma3DS
|
|
||||||
|
|||||||
156
arm11/Makefile
156
arm11/Makefile
@ -1,147 +1,39 @@
|
|||||||
#---------------------------------------------------------------------------------
|
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
||||||
.SUFFIXES:
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ifeq ($(strip $(DEVKITARM)),)
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TOPDIR ?= $(CURDIR)
|
include $(DEVKITARM)/base_tools
|
||||||
include $(DEVKITARM)/base_rules
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
name := $(shell basename $(CURDIR))
|
||||||
# TARGET is the name of the output
|
|
||||||
# BUILD is the directory where object files & intermediate files will be placed
|
|
||||||
# SOURCES is a list of directories containing source code
|
|
||||||
# DATA is a list of directories containing data files
|
|
||||||
# INCLUDES is a list of directories containing header files
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
TARGET := $(notdir $(CURDIR))
|
|
||||||
BUILD := build
|
|
||||||
SOURCES := source source/svc
|
|
||||||
DATA := data
|
|
||||||
INCLUDES := include include/svc
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
dir_source := source
|
||||||
# options for code generation
|
dir_build := build
|
||||||
#---------------------------------------------------------------------------------
|
dir_out := ../$(dir_build)
|
||||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
|
||||||
DEFINES := -DARM11 -D__3DS__
|
|
||||||
|
|
||||||
CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -O2 -mword-relocations \
|
ASFLAGS := -mcpu=mpcore
|
||||||
-fomit-frame-pointer -ffunction-sections -fdata-sections \
|
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math
|
||||||
-Wno-main -fno-builtin $(ARCH) $(DEFINES)
|
LDFLAGS := -nostartfiles -Wl,--nmagic
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE)
|
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||||
|
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
||||||
|
$(call rwildcard, $(dir_source), *.s *.c)))
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
.PHONY: all
|
||||||
|
all: $(dir_out)/$(name).elf
|
||||||
|
|
||||||
ASFLAGS := -g $(ARCH)
|
.PHONY: clean
|
||||||
LDFLAGS = -specs=$(TOPDIR)/linker.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
|
||||||
|
|
||||||
LIBS :=
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# list of directories containing libraries, this must be the top level containing
|
|
||||||
# include and lib
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
LIBDIRS :=
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# no real need to edit anything past this point unless you need to add additional
|
|
||||||
# rules for different file extensions
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
|
||||||
export TOPDIR := $(CURDIR)
|
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
|
||||||
|
|
||||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
|
||||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifeq ($(strip $(CPPFILES)),)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CC)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
else
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CXX)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
|
||||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
|
||||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
|
||||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
|
||||||
|
|
||||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
|
||||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
|
||||||
-I$(CURDIR)/$(BUILD)
|
|
||||||
|
|
||||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
|
||||||
|
|
||||||
.PHONY: $(BUILD) clean all
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
all: $(BUILD)
|
|
||||||
|
|
||||||
$(BUILD):
|
|
||||||
@[ -d $@ ] || mkdir -p $@
|
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
clean:
|
clean:
|
||||||
@echo clean ...
|
@rm -rf $(dir_build)
|
||||||
@rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf
|
|
||||||
|
|
||||||
|
$(dir_out)/$(name).elf: $(objects)
|
||||||
|
$(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
$(dir_build)/%.o: $(dir_source)/%.c
|
||||||
else
|
@mkdir -p "$(@D)"
|
||||||
.PHONY: all
|
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||||
|
|
||||||
DEPENDS := $(OFILES:.o=.d)
|
$(dir_build)/%.o: $(dir_source)/%.s
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
#---------------------------------------------------------------------------------
|
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||||
# main targets
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
all : $(OUTPUT).bin
|
|
||||||
|
|
||||||
$(OUTPUT).bin : $(OUTPUT).elf
|
|
||||||
$(OBJCOPY) -S -O binary $< $@
|
|
||||||
@echo built ... $(notdir $@)
|
|
||||||
|
|
||||||
$(OUTPUT).elf : $(OFILES)
|
|
||||||
|
|
||||||
%.elf: $(OFILES)
|
|
||||||
@echo linking $(notdir $@)
|
|
||||||
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
|
||||||
@$(NM) -CSn $@ > $(notdir $*.lst)
|
|
||||||
|
|
||||||
$(OFILES_SRC) : $(HFILES_BIN)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# you need a rule like this for each extension you use as binary data
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
%.bin.o %_bin.h : %.bin
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(bin2o)
|
|
||||||
|
|
||||||
-include $(DEPENDS)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------------
|
|
||||||
|
|||||||
158
arm11/linker.ld
158
arm11/linker.ld
@ -1,158 +1,16 @@
|
|||||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||||
OUTPUT_ARCH(arm)
|
OUTPUT_ARCH(arm)
|
||||||
|
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
|
||||||
/* Mostly copied from https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/3dsx.ld */
|
|
||||||
|
|
||||||
PHDRS
|
|
||||||
{
|
|
||||||
main PT_LOAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
PROVIDE(__start__ = 0x1FF80000);
|
. = 0x1FF80000;
|
||||||
PROVIDE(__stack_top__ = 0x1FFFE000);
|
|
||||||
PROVIDE(__stack_bottom__ = 0x1FFFD000);
|
|
||||||
|
|
||||||
. = __start__;
|
.text : ALIGN(4) { *(.text.start) *(.text*); . = ALIGN(4); }
|
||||||
|
.rodata : ALIGN(4) { *(.rodata*); . = ALIGN(4); }
|
||||||
|
.data : ALIGN(4) { *(.data*); . = ALIGN(4); }
|
||||||
|
.bss : ALIGN(8) { __bss_start = .; *(.bss* COMMON); . = ALIGN(8); __bss_end = .; }
|
||||||
|
|
||||||
.text :
|
__stack_top__ = 0x1FFFF000;
|
||||||
{
|
. = ALIGN(4);
|
||||||
KEEP( *(.text.start) )
|
|
||||||
KEEP( *(.init) )
|
|
||||||
|
|
||||||
/* .text */
|
|
||||||
*(.text)
|
|
||||||
*(.text.*)
|
|
||||||
*(.glue_7)
|
|
||||||
*(.glue_7t)
|
|
||||||
*(.stub)
|
|
||||||
*(.gnu.warning)
|
|
||||||
*(.gnu.linkonce.t*)
|
|
||||||
|
|
||||||
/* .fini */
|
|
||||||
KEEP( *(.fini) )
|
|
||||||
. = ALIGN(32);
|
|
||||||
} :main
|
|
||||||
|
|
||||||
.rodata :
|
|
||||||
{
|
|
||||||
*(.rodata)
|
|
||||||
*(.roda)
|
|
||||||
*(.rodata.*)
|
|
||||||
*all.rodata*(*)
|
|
||||||
*(.gnu.linkonce.r*)
|
|
||||||
SORT(CONSTRUCTORS)
|
|
||||||
. = ALIGN(8);
|
|
||||||
}
|
|
||||||
|
|
||||||
.preinit_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__preinit_array_start = .);
|
|
||||||
KEEP (*(.preinit_array))
|
|
||||||
PROVIDE (__preinit_array_end = .);
|
|
||||||
}
|
|
||||||
|
|
||||||
.init_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__init_array_start = .);
|
|
||||||
KEEP (*(SORT(.init_array.*)))
|
|
||||||
KEEP (*(.init_array))
|
|
||||||
PROVIDE (__init_array_end = .);
|
|
||||||
}
|
|
||||||
|
|
||||||
.fini_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__fini_array_start = .);
|
|
||||||
KEEP (*(.fini_array))
|
|
||||||
KEEP (*(SORT(.fini_array.*)))
|
|
||||||
PROVIDE (__fini_array_end = .);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ctors :
|
|
||||||
{
|
|
||||||
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
|
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
|
||||||
KEEP (*(SORT(.ctors.*)))
|
|
||||||
KEEP (*(.ctors))
|
|
||||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
|
||||||
}
|
|
||||||
|
|
||||||
.dtors :
|
|
||||||
{
|
|
||||||
KEEP (*crtbegin.o(.dtors))
|
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
|
||||||
KEEP (*(SORT(.dtors.*)))
|
|
||||||
KEEP (*(.dtors))
|
|
||||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
|
||||||
}
|
|
||||||
|
|
||||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) __exidx_start = .;}
|
|
||||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) __exidx_end = .;}
|
|
||||||
|
|
||||||
.data :
|
|
||||||
{
|
|
||||||
*(.data)
|
|
||||||
*(.data.*)
|
|
||||||
KEEP (*(.large_patch*))
|
|
||||||
*(.gnu.linkonce.d*)
|
|
||||||
CONSTRUCTORS
|
|
||||||
. = ALIGN(32);
|
|
||||||
}
|
|
||||||
|
|
||||||
.bss (NOLOAD) :
|
|
||||||
{
|
|
||||||
. = ALIGN(32);
|
|
||||||
PROVIDE (__bss_start__ = ABSOLUTE(.));
|
|
||||||
*(.dynbss)
|
|
||||||
*(.bss)
|
|
||||||
*(.bss.*)
|
|
||||||
*(.gnu.linkonce.b*)
|
|
||||||
*(COMMON)
|
|
||||||
. = ALIGN(8);
|
|
||||||
PROVIDE (__bss_end__ = ABSOLUTE(.));
|
|
||||||
} :NONE
|
|
||||||
|
|
||||||
PROVIDE (__end__ = ABSOLUTE(.));
|
|
||||||
|
|
||||||
/* ==================
|
|
||||||
==== Metadata ====
|
|
||||||
================== */
|
|
||||||
|
|
||||||
/* Discard sections that difficult post-processing */
|
|
||||||
/DISCARD/ : { *(.group .comment .note) }
|
|
||||||
|
|
||||||
/* Stabs debugging sections. */
|
|
||||||
.stab 0 : { *(.stab) }
|
|
||||||
.stabstr 0 : { *(.stabstr) }
|
|
||||||
.stab.excl 0 : { *(.stab.excl) }
|
|
||||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
|
||||||
.stab.index 0 : { *(.stab.index) }
|
|
||||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
|
||||||
|
|
||||||
/* DWARF debug sections.
|
|
||||||
Symbols in the DWARF debugging sections are relative to the beginning
|
|
||||||
of the section so we begin them at 0. */
|
|
||||||
|
|
||||||
/* DWARF 1 */
|
|
||||||
.debug 0 : { *(.debug) }
|
|
||||||
.line 0 : { *(.line) }
|
|
||||||
|
|
||||||
/* GNU DWARF 1 extensions */
|
|
||||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
|
||||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
|
||||||
|
|
||||||
/* DWARF 1.1 and DWARF 2 */
|
|
||||||
.debug_aranges 0 : { *(.debug_aranges) }
|
|
||||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
|
||||||
|
|
||||||
/* DWARF 2 */
|
|
||||||
.debug_info 0 : { *(.debug_info) }
|
|
||||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
|
||||||
.debug_line 0 : { *(.debug_line) }
|
|
||||||
.debug_frame 0 : { *(.debug_frame) }
|
|
||||||
.debug_str 0 : { *(.debug_str) }
|
|
||||||
.debug_loc 0 : { *(.debug_loc) }
|
|
||||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
%rename link old_link
|
|
||||||
|
|
||||||
*link:
|
|
||||||
%(old_link) -T %:getenv(TOPDIR /linker.ld) --nmagic --gc-sections --no-warn-rwx-segments
|
|
||||||
|
|
||||||
*startfile:
|
|
||||||
crti%O%s crtbegin%O%s
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -37,13 +37,9 @@ extern u32 prepareForFirmlaunchSize;
|
|||||||
|
|
||||||
extern volatile Arm11Operation operation;
|
extern volatile Arm11Operation operation;
|
||||||
|
|
||||||
static void initScreens(u32 brightnessLevel, struct fb *fbs)
|
static void initScreens(u32 brightnessLevel)
|
||||||
{
|
{
|
||||||
*(vu32 *)0x10141200 = 0x1007F;
|
*(vu32 *)0x10141200 = 0x1007F;
|
||||||
|
|
||||||
*(vu32 *)0x10202204 = 0x01000000; //set LCD fill black to hide potential garbage -- NFIRM does it before firmlaunching
|
|
||||||
*(vu32 *)0x10202A04 = 0x01000000;
|
|
||||||
|
|
||||||
*(vu32 *)0x10202014 = 0x00000001;
|
*(vu32 *)0x10202014 = 0x00000001;
|
||||||
*(vu32 *)0x1020200C &= 0xFFFEFFFE;
|
*(vu32 *)0x1020200C &= 0xFFFEFFFE;
|
||||||
*(vu32 *)0x10202240 = brightnessLevel;
|
*(vu32 *)0x10202240 = brightnessLevel;
|
||||||
@ -74,18 +70,13 @@ static void initScreens(u32 brightnessLevel, struct fb *fbs)
|
|||||||
*(vu32 *)0x1040045C = 0x00f00190;
|
*(vu32 *)0x1040045C = 0x00f00190;
|
||||||
*(vu32 *)0x10400460 = 0x01c100d1;
|
*(vu32 *)0x10400460 = 0x01c100d1;
|
||||||
*(vu32 *)0x10400464 = 0x01920002;
|
*(vu32 *)0x10400464 = 0x01920002;
|
||||||
*(vu32 *)0x10400468 = (u32)fbs[0].top_left;
|
|
||||||
*(vu32 *)0x1040046C = (u32)fbs[1].top_left;
|
|
||||||
*(vu32 *)0x10400470 = 0x80341;
|
*(vu32 *)0x10400470 = 0x80341;
|
||||||
*(vu32 *)0x10400474 = 0x00010501;
|
*(vu32 *)0x10400474 = 0x00010501;
|
||||||
*(vu32 *)0x10400478 = 0;
|
*(vu32 *)0x10400478 = 0;
|
||||||
*(vu32 *)0x10400494 = (u32)fbs[0].top_right;
|
|
||||||
*(vu32 *)0x10400498 = (u32)fbs[1].top_right;
|
|
||||||
*(vu32 *)0x10400490 = 0x000002D0;
|
*(vu32 *)0x10400490 = 0x000002D0;
|
||||||
*(vu32 *)0x1040049C = 0x00000000;
|
*(vu32 *)0x1040049C = 0x00000000;
|
||||||
|
|
||||||
// Color LUT
|
//Disco register
|
||||||
*(vu32 *)0x10400480 = 0;
|
|
||||||
for(u32 i = 0; i < 256; i++)
|
for(u32 i = 0; i < 256; i++)
|
||||||
*(vu32 *)0x10400484 = 0x10101 * i;
|
*(vu32 *)0x10400484 = 0x10101 * i;
|
||||||
|
|
||||||
@ -112,45 +103,25 @@ static void initScreens(u32 brightnessLevel, struct fb *fbs)
|
|||||||
*(vu32 *)0x1040055C = 0x00f00140;
|
*(vu32 *)0x1040055C = 0x00f00140;
|
||||||
*(vu32 *)0x10400560 = 0x01c100d1;
|
*(vu32 *)0x10400560 = 0x01c100d1;
|
||||||
*(vu32 *)0x10400564 = 0x01920052;
|
*(vu32 *)0x10400564 = 0x01920052;
|
||||||
*(vu32 *)0x10400568 = (u32)fbs[0].bottom;
|
|
||||||
*(vu32 *)0x1040056C = (u32)fbs[1].bottom;
|
|
||||||
*(vu32 *)0x10400570 = 0x80301;
|
*(vu32 *)0x10400570 = 0x80301;
|
||||||
*(vu32 *)0x10400574 = 0x00010501;
|
*(vu32 *)0x10400574 = 0x00010501;
|
||||||
*(vu32 *)0x10400578 = 0;
|
*(vu32 *)0x10400578 = 0;
|
||||||
*(vu32 *)0x10400590 = 0x000002D0;
|
*(vu32 *)0x10400590 = 0x000002D0;
|
||||||
*(vu32 *)0x1040059C = 0x00000000;
|
*(vu32 *)0x1040059C = 0x00000000;
|
||||||
|
|
||||||
// Color LUT
|
//Disco register
|
||||||
*(vu32 *)0x10400580 = 0;
|
|
||||||
for(u32 i = 0; i < 256; i++)
|
for(u32 i = 0; i < 256; i++)
|
||||||
*(vu32 *)0x10400584 = 0x10101 * i;
|
*(vu32 *)0x10400584 = 0x10101 * i;
|
||||||
|
|
||||||
*(vu32 *)0x10202204 = 0x00000000; //unset LCD fill
|
|
||||||
*(vu32 *)0x10202A04 = 0x00000000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupFramebuffers(struct fb *fbs)
|
static void setupFramebuffers(struct fb *fbs)
|
||||||
{
|
{
|
||||||
*(vu32 *)0x10202204 = 0x01000000; //set LCD fill black to hide potential garbage -- NFIRM does it before firmlaunching
|
|
||||||
*(vu32 *)0x10202A04 = 0x01000000;
|
|
||||||
|
|
||||||
*(vu32 *)0x10400468 = (u32)fbs[0].top_left;
|
*(vu32 *)0x10400468 = (u32)fbs[0].top_left;
|
||||||
*(vu32 *)0x1040046c = (u32)fbs[1].top_left;
|
*(vu32 *)0x1040046c = (u32)fbs[1].top_left;
|
||||||
*(vu32 *)0x10400494 = (u32)fbs[0].top_right;
|
*(vu32 *)0x10400494 = (u32)fbs[0].top_right;
|
||||||
*(vu32 *)0x10400498 = (u32)fbs[1].top_right;
|
*(vu32 *)0x10400498 = (u32)fbs[1].top_right;
|
||||||
*(vu32 *)0x10400568 = (u32)fbs[0].bottom;
|
*(vu32 *)0x10400568 = (u32)fbs[0].bottom;
|
||||||
*(vu32 *)0x1040056c = (u32)fbs[1].bottom;
|
*(vu32 *)0x1040056c = (u32)fbs[1].bottom;
|
||||||
|
|
||||||
//Set framebuffer format, framebuffer select and stride
|
|
||||||
*(vu32 *)0x10400470 = 0x80341;
|
|
||||||
*(vu32 *)0x10400478 = 0;
|
|
||||||
*(vu32 *)0x10400490 = 0x2D0;
|
|
||||||
*(vu32 *)0x10400570 = 0x80301;
|
|
||||||
*(vu32 *)0x10400578 = 0;
|
|
||||||
*(vu32 *)0x10400590 = 0x2D0;
|
|
||||||
|
|
||||||
*(vu32 *)0x10202204 = 0x00000000; //unset LCD fill
|
|
||||||
*(vu32 *)0x10202A04 = 0x00000000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clearScreens(struct fb *fb)
|
static void clearScreens(struct fb *fb)
|
||||||
@ -177,7 +148,7 @@ static void swapFramebuffers(bool isAlternate)
|
|||||||
{
|
{
|
||||||
u32 isAlternateTmp = isAlternate ? 1 : 0;
|
u32 isAlternateTmp = isAlternate ? 1 : 0;
|
||||||
*(vu32 *)0x10400478 = (*(vu32 *)0x10400478 & 0xFFFFFFFE) | isAlternateTmp;
|
*(vu32 *)0x10400478 = (*(vu32 *)0x10400478 & 0xFFFFFFFE) | isAlternateTmp;
|
||||||
*(vu32 *)0x10400578 = (*(vu32 *)0x10400578 & 0xFFFFFFFE) | isAlternateTmp;
|
*(vu32 *)0x10400578 = (*(vu32 *)0x10400478 & 0xFFFFFFFE) | isAlternateTmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateBrightness(u32 brightnessLevel)
|
static void updateBrightness(u32 brightnessLevel)
|
||||||
@ -195,28 +166,6 @@ static void deinitScreens(void)
|
|||||||
*(vu32 *)0x10202014 = 0;
|
*(vu32 *)0x10202014 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zerofillN3dsAblRegisters(void)
|
|
||||||
{
|
|
||||||
// It should be fine to write to these regs even on O3DS as they
|
|
||||||
// are RAZ/WI
|
|
||||||
|
|
||||||
// TODO: read from calibration, but null values should do just
|
|
||||||
// fine. From testing, LUT explicitly ignores null values, and
|
|
||||||
// it is probably the case of reg @ 0x54 as well.
|
|
||||||
*(vu32 *)0x10202250 = 0; // unknown 24-bit value, seen: 0
|
|
||||||
*(vu32 *)0x10202254 = 0; // unknown 24-bit value, seen: nonzero
|
|
||||||
|
|
||||||
*(vu32 *)0x10202A50 = 0; // unknown 24-bit value, seen: 0
|
|
||||||
*(vu32 *)0x10202A54 = 0; // unknown 24-bit value, seen: nonzero
|
|
||||||
|
|
||||||
for (u32 i = 0; i < 64; i++) {
|
|
||||||
// Blend colors (w/ color multiplication) for each group
|
|
||||||
// of 4 relative-luminance Rs
|
|
||||||
*(vu32 *)(0x10202300 + 4*i) = 0;
|
|
||||||
*(vu32 *)(0x10202B00 + 4*i) = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
operation = ARM11_READY;
|
operation = ARM11_READY;
|
||||||
@ -228,7 +177,7 @@ void main(void)
|
|||||||
case ARM11_READY:
|
case ARM11_READY:
|
||||||
continue;
|
continue;
|
||||||
case INIT_SCREENS:
|
case INIT_SCREENS:
|
||||||
initScreens(*(vu32 *)ARM11_PARAMETERS_ADDRESS, (struct fb *)(ARM11_PARAMETERS_ADDRESS + 4));
|
initScreens(*(vu32 *)ARM11_PARAMETERS_ADDRESS);
|
||||||
break;
|
break;
|
||||||
case SETUP_FRAMEBUFFERS:
|
case SETUP_FRAMEBUFFERS:
|
||||||
setupFramebuffers((struct fb *)ARM11_PARAMETERS_ADDRESS);
|
setupFramebuffers((struct fb *)ARM11_PARAMETERS_ADDRESS);
|
||||||
@ -245,9 +194,6 @@ void main(void)
|
|||||||
case DEINIT_SCREENS:
|
case DEINIT_SCREENS:
|
||||||
deinitScreens();
|
deinitScreens();
|
||||||
break;
|
break;
|
||||||
case ZEROFILL_N3DS_ABL_REGISTERS:
|
|
||||||
zerofillN3dsAblRegisters();
|
|
||||||
break;
|
|
||||||
case PREPARE_ARM11_FOR_FIRMLAUNCH:
|
case PREPARE_ARM11_FOR_FIRMLAUNCH:
|
||||||
memcpy((void *)0x1FFFFC00, (void *)prepareForFirmlaunch, prepareForFirmlaunchSize);
|
memcpy((void *)0x1FFFFC00, (void *)prepareForFirmlaunch, prepareForFirmlaunchSize);
|
||||||
*(vu32 *)0x1FFFFFFC = 0;
|
*(vu32 *)0x1FFFFFFC = 0;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
@ This file is part of Luma3DS
|
@ This file is part of Luma3DS
|
||||||
@ Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
@
|
@
|
||||||
@ This program is free software: you can redistribute it and/or modify
|
@ This program is free software: you can redistribute it and/or modify
|
||||||
@ it under the terms of the GNU General Public License as published by
|
@ it under the terms of the GNU General Public License as published by
|
||||||
@ -22,7 +22,7 @@
|
|||||||
@ or requiring that modified versions of such material be marked in
|
@ or requiring that modified versions of such material be marked in
|
||||||
@ reasonable ways as different from the original version.
|
@ reasonable ways as different from the original version.
|
||||||
|
|
||||||
.section .text.start, "ax", %progbits
|
.section .text.start
|
||||||
.align 4
|
.align 4
|
||||||
.global _start
|
.global _start
|
||||||
.type _start, %function
|
.type _start, %function
|
||||||
@ -53,25 +53,20 @@ start:
|
|||||||
mcr p15, 0, r0, c7, c7, 0
|
mcr p15, 0, r0, c7, c7, 0
|
||||||
mcr p15, 0, r0, c7, c10, 4
|
mcr p15, 0, r0, c7, c10, 4
|
||||||
|
|
||||||
ldr sp, =__stack_top__
|
|
||||||
mov fp, #0
|
|
||||||
|
|
||||||
@ Clear BSS
|
@ Clear BSS
|
||||||
ldr r0, =__bss_start__
|
ldr r0, =__bss_start
|
||||||
mov r1, #0
|
mov r1, #0
|
||||||
ldr r2, =__bss_end__
|
ldr r2, =__bss_end
|
||||||
sub r2, r0
|
sub r2, r0
|
||||||
bl memset
|
bl memset32
|
||||||
|
|
||||||
@ Call the init array
|
|
||||||
bl __libc_init_array
|
|
||||||
|
|
||||||
|
ldr sp, =__stack_top__
|
||||||
b main
|
b main
|
||||||
|
|
||||||
.global prepareForFirmlaunch
|
.global prepareForFirmlaunch
|
||||||
.type prepareForFirmlaunch, %function
|
.type prepareForFirmlaunch, %function
|
||||||
prepareForFirmlaunch:
|
prepareForFirmlaunch:
|
||||||
str r0, [r1] @ tell Arm9 we're done
|
str r0, [r1] @ tell ARM9 we're done
|
||||||
mov r0, #0x20000000
|
mov r0, #0x20000000
|
||||||
|
|
||||||
_wait_for_core0_entrypoint_loop:
|
_wait_for_core0_entrypoint_loop:
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -50,7 +50,7 @@ struct fb {
|
|||||||
u8 *top_left;
|
u8 *top_left;
|
||||||
u8 *top_right;
|
u8 *top_right;
|
||||||
u8 *bottom;
|
u8 *bottom;
|
||||||
};
|
} __attribute__((packed));
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@ -60,7 +60,6 @@ typedef enum
|
|||||||
SWAP_FRAMEBUFFERS,
|
SWAP_FRAMEBUFFERS,
|
||||||
UPDATE_BRIGHTNESS,
|
UPDATE_BRIGHTNESS,
|
||||||
DEINIT_SCREENS,
|
DEINIT_SCREENS,
|
||||||
ZEROFILL_N3DS_ABL_REGISTERS,
|
|
||||||
PREPARE_ARM11_FOR_FIRMLAUNCH,
|
PREPARE_ARM11_FOR_FIRMLAUNCH,
|
||||||
ARM11_READY,
|
ARM11_READY,
|
||||||
} Arm11Operation;
|
} Arm11Operation;
|
||||||
|
|||||||
191
arm9/Makefile
191
arm9/Makefile
@ -1,191 +0,0 @@
|
|||||||
#---------------------------------------------------------------------------------
|
|
||||||
.SUFFIXES:
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ifeq ($(strip $(DEVKITARM)),)
|
|
||||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
|
||||||
endif
|
|
||||||
|
|
||||||
TOPDIR ?= $(CURDIR)
|
|
||||||
include $(DEVKITARM)/base_rules
|
|
||||||
|
|
||||||
export REVISION := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
|
|
||||||
export VERSION_MAJOR := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f1 -d.)
|
|
||||||
export VERSION_MINOR := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f2 -d.)
|
|
||||||
export VERSION_BUILD := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f3 -d.)
|
|
||||||
export COMMIT := $(shell git rev-parse --short=8 HEAD)
|
|
||||||
export IS_RELEASE := 0
|
|
||||||
|
|
||||||
ifeq ($(strip $(REVISION)),)
|
|
||||||
export REVISION := v0.0.0-0
|
|
||||||
export VERSION_MAJOR := 0
|
|
||||||
export VERSION_MINOR := 0
|
|
||||||
export VERSION_BUILD := 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(strip $(COMMIT)),)
|
|
||||||
export COMMIT := 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(strip $(VERSION_BUILD)),)
|
|
||||||
export VERSION_BUILD := 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(strip $(shell git describe --tags --match v[0-9]* | grep -)),)
|
|
||||||
export IS_RELEASE := 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Default 3DSX TitleID for hb:ldr (note: also defined in top-level Makefile)
|
|
||||||
export HBLDR_DEFAULT_3DSX_TID ?= 000400000D921E00
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# TARGET is the name of the output
|
|
||||||
# BUILD is the directory where object files & intermediate files will be placed
|
|
||||||
# SOURCES is a list of directories containing source code
|
|
||||||
# DATA is a list of directories containing data files
|
|
||||||
# INCLUDES is a list of directories containing header files
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
APP_TITLE := Luma3DS
|
|
||||||
TARGET := $(notdir $(CURDIR))
|
|
||||||
BUILD := build
|
|
||||||
SOURCES := source source/fatfs source/fatfs/sdmmc
|
|
||||||
DATA := data
|
|
||||||
INCLUDES := include
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# options for code generation
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ARCH := -marm -march=armv5te -mtune=arm946e-s
|
|
||||||
|
|
||||||
ifeq ($(BUILD_FOR_EXPLOIT_DEV),1)
|
|
||||||
DEFINES := -DARM9 -D__3DS__ -DHBLDR_DEFAULT_3DSX_TID="0x$(HBLDR_DEFAULT_3DSX_TID)ULL" -DBUILD_FOR_EXPLOIT_DEV=1
|
|
||||||
else
|
|
||||||
DEFINES := -DARM9 -D__3DS__ -DHBLDR_DEFAULT_3DSX_TID="0x$(HBLDR_DEFAULT_3DSX_TID)ULL"
|
|
||||||
endif
|
|
||||||
|
|
||||||
FALSEPOSITIVES := -Wno-array-bounds -Wno-stringop-overflow -Wno-stringop-overread
|
|
||||||
CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -O2 -mword-relocations \
|
|
||||||
-fomit-frame-pointer -ffunction-sections -fdata-sections \
|
|
||||||
-Wno-main $(FALSEPOSITIVES) $(ARCH) $(DEFINES)
|
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE)
|
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
|
||||||
|
|
||||||
ASFLAGS := -g $(ARCH)
|
|
||||||
LDFLAGS = -specs=$(TOPDIR)/linker.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
|
||||||
|
|
||||||
LIBS :=
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# list of directories containing libraries, this must be the top level containing
|
|
||||||
# include and lib
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
LIBDIRS :=
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# no real need to edit anything past this point unless you need to add additional
|
|
||||||
# rules for different file extensions
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
|
||||||
export TOPDIR := $(CURDIR)
|
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
|
||||||
|
|
||||||
export APP_TITLE := $(notdir $(TOPDIR)/..)
|
|
||||||
|
|
||||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
|
||||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifeq ($(strip $(CPPFILES)),)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CC)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
else
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CXX)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
|
||||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
|
||||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
|
||||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
|
||||||
|
|
||||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
|
||||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
|
||||||
-I$(CURDIR)/$(BUILD)
|
|
||||||
|
|
||||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
|
||||||
|
|
||||||
.PHONY: $(BUILD) clean all
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
all: $(BUILD)
|
|
||||||
|
|
||||||
$(BUILD):
|
|
||||||
@[ -d $@ ] || mkdir -p $@
|
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
clean:
|
|
||||||
@echo clean ...
|
|
||||||
@rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
else
|
|
||||||
.PHONY: all
|
|
||||||
|
|
||||||
DEPENDS := $(OFILES:.o=.d)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# main targets
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
all : $(OUTPUT).elf
|
|
||||||
|
|
||||||
$(OUTPUT).elf : $(OFILES)
|
|
||||||
|
|
||||||
%.elf: $(OFILES)
|
|
||||||
@echo linking $(notdir $@)
|
|
||||||
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
|
||||||
@$(NM) -CSn $@ > $(notdir $*.lst)
|
|
||||||
|
|
||||||
$(OFILES_SRC) : $(HFILES_BIN)
|
|
||||||
|
|
||||||
memory.o strings.o: CFLAGS += -O3
|
|
||||||
patches.o config.o: CFLAGS += -DCONFIG_TITLE="\"$(APP_TITLE) $(REVISION) configuration\""\
|
|
||||||
-DVERSION_MAJOR="$(VERSION_MAJOR)" -DVERSION_MINOR="$(VERSION_MINOR)"\
|
|
||||||
-DVERSION_BUILD="$(VERSION_BUILD)" -DISRELEASE="$(IS_RELEASE)" -DCOMMIT_HASH="0x$(COMMIT)"
|
|
||||||
config.o ini.o: CFLAGS += -DINI_HANDLER_LINENO=1 -DINI_STOP_ON_FIRST_ERROR=1
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# you need a rule like this for each extension you use as binary data
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
%.bin.o %_bin.h : %.bin
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(bin2o)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
%.ini.o %_ini.h: %.ini
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(bin2o)
|
|
||||||
|
|
||||||
-include $(DEPENDS)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------------
|
|
||||||
Binary file not shown.
210
arm9/linker.ld
210
arm9/linker.ld
@ -1,210 +0,0 @@
|
|||||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
|
||||||
OUTPUT_ARCH(arm)
|
|
||||||
ENTRY(_start)
|
|
||||||
|
|
||||||
PHDRS
|
|
||||||
{
|
|
||||||
crt0 PT_LOAD;
|
|
||||||
itcm PT_LOAD;
|
|
||||||
main PT_LOAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mostly copied from https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/3dsx.ld */
|
|
||||||
MEMORY
|
|
||||||
{
|
|
||||||
main : ORIGIN = 0x08006000, LENGTH = 0x080F0000 - 0x08006000
|
|
||||||
itcm : ORIGIN = 0x01FF8000, LENGTH = 0x01FFB800 - 0x01FF8000 /* Unused ITCM slice. */
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTIONS
|
|
||||||
{
|
|
||||||
PROVIDE(__start__ = 0x08006000);
|
|
||||||
PROVIDE(__stack_top__ = 0x08100000);
|
|
||||||
PROVIDE(__stack_bottom__ = 0x080F0000);
|
|
||||||
|
|
||||||
PROVIDE(__itcm_stack_top__ = 0x01FFB800);
|
|
||||||
PROVIDE(__itcm_stack_bottom__ = 0x01FFA800);
|
|
||||||
|
|
||||||
. = __start__;
|
|
||||||
|
|
||||||
.crt0 :
|
|
||||||
{
|
|
||||||
KEEP( *(.text.start) )
|
|
||||||
KEEP( *(.init) )
|
|
||||||
. = ALIGN(32);
|
|
||||||
} >main :crt0
|
|
||||||
|
|
||||||
.itcm_loadable :
|
|
||||||
{
|
|
||||||
PROVIDE (__itcm_start__ = ABSOLUTE(.));
|
|
||||||
PROVIDE (__itcm_lma__ = LOADADDR(.itcm_loadable));
|
|
||||||
|
|
||||||
KEEP(*(.arm9_exception_handlers.text))
|
|
||||||
*(.arm9_exception_handlers.text*)
|
|
||||||
KEEP(*(.chainloader.text.start))
|
|
||||||
|
|
||||||
chainloader.o(.text*)
|
|
||||||
i2c.o(.text*)
|
|
||||||
arm9_exception_handlers.o(.text*)
|
|
||||||
KEEP (*(.emunand_patch))
|
|
||||||
|
|
||||||
*(.arm9_exception_handlers.rodata*)
|
|
||||||
chainloader.o(.rodata*)
|
|
||||||
i2c.o(.rodata*)
|
|
||||||
arm9_exception_handlers.o(.rodata*)
|
|
||||||
|
|
||||||
*(.arm9_exception_handlers.data*)
|
|
||||||
chainloader.o(.data*)
|
|
||||||
i2c.o(.data*)
|
|
||||||
arm9_exception_handlers.o(.data*)
|
|
||||||
. = ALIGN(32);
|
|
||||||
} >itcm AT>main :itcm
|
|
||||||
|
|
||||||
.itcm_bss (NOLOAD) :
|
|
||||||
{
|
|
||||||
. = ALIGN(32);
|
|
||||||
PROVIDE (__itcm_bss_start__ = ABSOLUTE(.));
|
|
||||||
|
|
||||||
*(.arm9_exception_handlers.bss*)
|
|
||||||
chainloader.o(.bss* COMMON)
|
|
||||||
i2c.o(.bss* COMMON)
|
|
||||||
arm9_exception_handlers.o(.bss* COMMON)
|
|
||||||
. = ALIGN(32);
|
|
||||||
PROVIDE (__itcm_end__ = ABSOLUTE(.));
|
|
||||||
} >itcm :NONE
|
|
||||||
|
|
||||||
.text :
|
|
||||||
{
|
|
||||||
/* .text */
|
|
||||||
*(.text)
|
|
||||||
*(.text.*)
|
|
||||||
*(.glue_7)
|
|
||||||
*(.glue_7t)
|
|
||||||
*(.stub)
|
|
||||||
*(.gnu.warning)
|
|
||||||
*(.gnu.linkonce.t*)
|
|
||||||
|
|
||||||
/* .fini */
|
|
||||||
KEEP( *(.fini) )
|
|
||||||
. = ALIGN(8);
|
|
||||||
} >main :main
|
|
||||||
|
|
||||||
.rodata :
|
|
||||||
{
|
|
||||||
*(.rodata)
|
|
||||||
*(.roda)
|
|
||||||
*(.rodata.*)
|
|
||||||
*all.rodata*(*)
|
|
||||||
*(.gnu.linkonce.r*)
|
|
||||||
SORT(CONSTRUCTORS)
|
|
||||||
. = ALIGN(8);
|
|
||||||
} >main
|
|
||||||
|
|
||||||
.preinit_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__preinit_array_start = .);
|
|
||||||
KEEP (*(.preinit_array))
|
|
||||||
PROVIDE (__preinit_array_end = .);
|
|
||||||
} >main
|
|
||||||
|
|
||||||
.init_array ALIGN(4) :
|
|
||||||
{
|
|
||||||
PROVIDE (__init_array_start = .);
|
|
||||||
KEEP (*(SORT(.init_array.*)))
|
|
||||||
KEEP (*(.init_array))
|
|
||||||
PROVIDE (__init_array_end = .);
|
|
||||||
} >main
|
|
||||||
|
|
||||||
.fini_array ALIGN(4) :
|
|
||||||
{
|
|
||||||
PROVIDE (__fini_array_start = .);
|
|
||||||
KEEP (*(.fini_array))
|
|
||||||
KEEP (*(SORT(.fini_array.*)))
|
|
||||||
PROVIDE (__fini_array_end = .);
|
|
||||||
} >main
|
|
||||||
|
|
||||||
.ctors ALIGN(4) :
|
|
||||||
{
|
|
||||||
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
|
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
|
||||||
KEEP (*(SORT(.ctors.*)))
|
|
||||||
KEEP (*(.ctors))
|
|
||||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
|
||||||
} >main
|
|
||||||
|
|
||||||
.dtors ALIGN(4) :
|
|
||||||
{
|
|
||||||
KEEP (*crtbegin.o(.dtors))
|
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
|
||||||
KEEP (*(SORT(.dtors.*)))
|
|
||||||
KEEP (*(.dtors))
|
|
||||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
|
||||||
} >main
|
|
||||||
|
|
||||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) __exidx_start = ABSOLUTE(.);} >main
|
|
||||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) __exidx_end = ABSOLUTE(.);} >main
|
|
||||||
|
|
||||||
.data :
|
|
||||||
{
|
|
||||||
*(.data)
|
|
||||||
*(.data.*)
|
|
||||||
KEEP (*(.large_patch*))
|
|
||||||
*(.gnu.linkonce.d*)
|
|
||||||
CONSTRUCTORS
|
|
||||||
. = ALIGN(32);
|
|
||||||
} >main
|
|
||||||
|
|
||||||
.bss (NOLOAD) :
|
|
||||||
{
|
|
||||||
. = ALIGN(32);
|
|
||||||
PROVIDE (__bss_start__ = ABSOLUTE(.));
|
|
||||||
*(.dynbss)
|
|
||||||
*(.bss)
|
|
||||||
*(.bss.*)
|
|
||||||
*(.gnu.linkonce.b*)
|
|
||||||
*(COMMON)
|
|
||||||
. = ALIGN(8);
|
|
||||||
PROVIDE (__bss_end__ = ABSOLUTE(.));
|
|
||||||
} >main :NONE
|
|
||||||
__end__ = ABSOLUTE(.) ;
|
|
||||||
|
|
||||||
/* ==================
|
|
||||||
==== Metadata ====
|
|
||||||
================== */
|
|
||||||
|
|
||||||
/* Discard sections that difficult post-processing */
|
|
||||||
/DISCARD/ : { *(.group .comment .note) }
|
|
||||||
|
|
||||||
/* Stabs debugging sections. */
|
|
||||||
.stab 0 : { *(.stab) }
|
|
||||||
.stabstr 0 : { *(.stabstr) }
|
|
||||||
.stab.excl 0 : { *(.stab.excl) }
|
|
||||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
|
||||||
.stab.index 0 : { *(.stab.index) }
|
|
||||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
|
||||||
|
|
||||||
/* DWARF debug sections.
|
|
||||||
Symbols in the DWARF debugging sections are relative to the beginning
|
|
||||||
of the section so we begin them at 0. */
|
|
||||||
|
|
||||||
/* DWARF 1 */
|
|
||||||
.debug 0 : { *(.debug) }
|
|
||||||
.line 0 : { *(.line) }
|
|
||||||
|
|
||||||
/* GNU DWARF 1 extensions */
|
|
||||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
|
||||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
|
||||||
|
|
||||||
/* DWARF 1.1 and DWARF 2 */
|
|
||||||
.debug_aranges 0 : { *(.debug_aranges) }
|
|
||||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
|
||||||
|
|
||||||
/* DWARF 2 */
|
|
||||||
.debug_info 0 : { *(.debug_info) }
|
|
||||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
|
||||||
.debug_line 0 : { *(.debug_line) }
|
|
||||||
.debug_frame 0 : { *(.debug_frame) }
|
|
||||||
.debug_str 0 : { *(.debug_str) }
|
|
||||||
.debug_loc 0 : { *(.debug_loc) }
|
|
||||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
%rename link old_link
|
|
||||||
|
|
||||||
*link:
|
|
||||||
%(old_link) -T %:getenv(TOPDIR /linker.ld) --nmagic --gc-sections --no-warn-rwx-segments
|
|
||||||
|
|
||||||
*startfile:
|
|
||||||
crti%O%s crtbegin%O%s
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
void *alignedseqmemcpy(void *dst, const void *src, u32 len);
|
|
||||||
@ -1,168 +0,0 @@
|
|||||||
@ This file is part of Luma3DS
|
|
||||||
@ Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
|
||||||
@
|
|
||||||
@ This program is free software: you can redistribute it and/or modify
|
|
||||||
@ it under the terms of the GNU General Public License as published by
|
|
||||||
@ the Free Software Foundation, either version 3 of the License, or
|
|
||||||
@ (at your option) any later version.
|
|
||||||
@
|
|
||||||
@ This program is distributed in the hope that it will be useful,
|
|
||||||
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
@ GNU General Public License for more details.
|
|
||||||
@
|
|
||||||
@ You should have received a copy of the GNU General Public License
|
|
||||||
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
@
|
|
||||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
@ * Requiring preservation of specified reasonable legal notices or
|
|
||||||
@ author attributions in that material or in the Appropriate Legal
|
|
||||||
@ Notices displayed by works containing it.
|
|
||||||
@ * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
@ or requiring that modified versions of such material be marked in
|
|
||||||
@ reasonable ways as different from the original version.
|
|
||||||
|
|
||||||
.macro GEN_USUAL_HANDLER name, index
|
|
||||||
\name\()Handler:
|
|
||||||
ldr sp, =_regs
|
|
||||||
stmia sp, {r0-r7}
|
|
||||||
|
|
||||||
mov r0, #\index
|
|
||||||
b _arm9ExceptionHandlerCommon
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.section .arm9_exception_handlers.text, "ax", %progbits
|
|
||||||
.arm
|
|
||||||
.align 4
|
|
||||||
|
|
||||||
.global _arm9ExceptionHandlerCommon
|
|
||||||
.type _arm9ExceptionHandlerCommon, %function
|
|
||||||
_arm9ExceptionHandlerCommon:
|
|
||||||
mov r1, r0
|
|
||||||
mov r0, sp
|
|
||||||
mrs r2, spsr
|
|
||||||
mrs r3, cpsr
|
|
||||||
add r6, r0, #(8 * 4)
|
|
||||||
|
|
||||||
orr r3, #0xc0 @ mask interrupts
|
|
||||||
msr cpsr_cx, r3
|
|
||||||
|
|
||||||
ands r4, r2, #0xf @ get the mode that triggered the exception
|
|
||||||
moveq r4, #0xf @ usr => sys
|
|
||||||
bic r5, r3, #0xf
|
|
||||||
orr r5, r4
|
|
||||||
msr cpsr_c, r5 @ change processor mode
|
|
||||||
stmia r6!, {r8-lr}
|
|
||||||
msr cpsr_c, r3 @ restore processor mode
|
|
||||||
|
|
||||||
str lr, [r6], #4
|
|
||||||
str r2, [r6]
|
|
||||||
|
|
||||||
msr cpsr_cxsf, #0xdf @ finally, switch to system mode, mask interrupts and clear flags (in case of double faults)
|
|
||||||
ldr sp, =0x02000000
|
|
||||||
b arm9ExceptionHandlerMain
|
|
||||||
|
|
||||||
|
|
||||||
.global FIQHandler
|
|
||||||
.type FIQHandler, %function
|
|
||||||
GEN_USUAL_HANDLER FIQ, 0
|
|
||||||
|
|
||||||
.global undefinedInstructionHandler
|
|
||||||
.type undefinedInstructionHandler, %function
|
|
||||||
GEN_USUAL_HANDLER undefinedInstruction, 1
|
|
||||||
|
|
||||||
.global prefetchAbortHandler
|
|
||||||
.type prefetchAbortHandler, %function
|
|
||||||
prefetchAbortHandler:
|
|
||||||
msr cpsr_cx, #0xd7 @ mask interrupts (abort mode)
|
|
||||||
mrs sp, spsr
|
|
||||||
and sp, #0x3f
|
|
||||||
cmp sp, #0x13
|
|
||||||
bne _prefetchAbortNormalHandler
|
|
||||||
|
|
||||||
ldr sp, =arm9ExceptionHandlerSvcBreakAddress
|
|
||||||
ldr sp, [sp]
|
|
||||||
cmp sp, #0
|
|
||||||
beq _prefetchAbortNormalHandler
|
|
||||||
add sp, #(1*4 + 4)
|
|
||||||
cmp lr, sp
|
|
||||||
bne _prefetchAbortNormalHandler
|
|
||||||
|
|
||||||
mov sp, r8
|
|
||||||
pop {r8-r11}
|
|
||||||
ldr lr, [sp, #8]!
|
|
||||||
ldr sp, [sp, #4]
|
|
||||||
msr spsr_cxsf, sp
|
|
||||||
tst sp, #0x20
|
|
||||||
addne lr, #2 @ adjust address for later
|
|
||||||
|
|
||||||
GEN_USUAL_HANDLER _prefetchAbortNormal, 2
|
|
||||||
|
|
||||||
.global dataAbortHandler
|
|
||||||
.type dataAbortHandler, %function
|
|
||||||
dataAbortHandler:
|
|
||||||
msr cpsr_cx, #0xd7 @ mask interrupts (abort mode)
|
|
||||||
mrs sp, spsr
|
|
||||||
and sp, #0x3f
|
|
||||||
cmp sp, #0x1f
|
|
||||||
bne _dataAbortNormalHandler
|
|
||||||
|
|
||||||
sub lr, #8
|
|
||||||
adr sp, safecpy
|
|
||||||
cmp lr, sp
|
|
||||||
blo _j_dataAbortNormalHandler
|
|
||||||
adr sp, _safecpy_end
|
|
||||||
cmp lr, sp
|
|
||||||
bhs _j_dataAbortNormalHandler
|
|
||||||
|
|
||||||
msr spsr_f, #(1 << 30)
|
|
||||||
mov r12, #0
|
|
||||||
adds pc, lr, #4
|
|
||||||
|
|
||||||
_j_dataAbortNormalHandler:
|
|
||||||
add lr, #8
|
|
||||||
|
|
||||||
GEN_USUAL_HANDLER _dataAbortNormal, 3
|
|
||||||
|
|
||||||
|
|
||||||
.global safecpy
|
|
||||||
.type safecpy, %function
|
|
||||||
safecpy:
|
|
||||||
push {r4, lr}
|
|
||||||
mov r3, #0
|
|
||||||
movs r12, #1
|
|
||||||
|
|
||||||
_safecpy_loop:
|
|
||||||
ldrb r4, [r1, r3]
|
|
||||||
cmp r12, #0
|
|
||||||
beq _safecpy_loop_end
|
|
||||||
strb r4, [r0, r3]
|
|
||||||
add r3, #1
|
|
||||||
cmp r3, r2
|
|
||||||
blo _safecpy_loop
|
|
||||||
|
|
||||||
_safecpy_loop_end:
|
|
||||||
mov r0, r3
|
|
||||||
pop {r4, pc}
|
|
||||||
|
|
||||||
_safecpy_end:
|
|
||||||
|
|
||||||
.section .arm9_exception_handlers.rodata, "a", %progbits
|
|
||||||
.align 4
|
|
||||||
.global arm9ExceptionHandlerAddressTable
|
|
||||||
arm9ExceptionHandlerAddressTable:
|
|
||||||
.word 0 @ IRQ
|
|
||||||
.word FIQHandler @ FIQ
|
|
||||||
.word 0 @ SVC
|
|
||||||
.word undefinedInstructionHandler @ Undefined instruction
|
|
||||||
.word prefetchAbortHandler @ Prefetch abort
|
|
||||||
.word dataAbortHandler @ Data abort
|
|
||||||
|
|
||||||
.section .arm9_exception_handlers.bss, "aw", %nobits
|
|
||||||
.align 4
|
|
||||||
|
|
||||||
.global arm9ExceptionHandlerSvcBreakAddress
|
|
||||||
arm9ExceptionHandlerSvcBreakAddress:
|
|
||||||
.skip 4
|
|
||||||
|
|
||||||
_regs: .skip (4 * 17)
|
|
||||||
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "chainloader.h"
|
|
||||||
#include "screen.h"
|
|
||||||
|
|
||||||
void disableMpuAndJumpToEntrypoints(int argc, char **argv, void *arm11Entry, void *arm9Entry);
|
|
||||||
|
|
||||||
#pragma GCC optimize (3)
|
|
||||||
|
|
||||||
static void *xmemcpy(void *dst, const void *src, u32 len)
|
|
||||||
{
|
|
||||||
const u8 *src8 = (const u8 *)src;
|
|
||||||
u8 *dst8 = (u8 *)dst;
|
|
||||||
|
|
||||||
for (u32 i = 0; i < len; i++) {
|
|
||||||
dst8[i] = src8[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void doLaunchFirm(Firm *firm, int argc, char **argv)
|
|
||||||
{
|
|
||||||
//Copy FIRM sections to respective memory locations
|
|
||||||
for(u32 sectionNum = 0; sectionNum < 4; sectionNum++)
|
|
||||||
xmemcpy(firm->section[sectionNum].address, (u8 *)firm + firm->section[sectionNum].offset, firm->section[sectionNum].size);
|
|
||||||
|
|
||||||
disableMpuAndJumpToEntrypoints(argc, argv, firm->arm9Entry, firm->arm11Entry);
|
|
||||||
|
|
||||||
__builtin_unreachable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void chainloader_main(int argc, char **argv, Firm *firm)
|
|
||||||
{
|
|
||||||
char *argvPassed[2],
|
|
||||||
absPath[24 + 255];
|
|
||||||
struct fb fbs[2];
|
|
||||||
|
|
||||||
if(argc > 0)
|
|
||||||
{
|
|
||||||
u32 i;
|
|
||||||
for(i = 0; i < sizeof(absPath) - 1 && argv[0][i] != 0; i++)
|
|
||||||
absPath[i] = argv[0][i];
|
|
||||||
absPath[i] = 0;
|
|
||||||
|
|
||||||
argvPassed[0] = (char *)absPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(argc == 2)
|
|
||||||
{
|
|
||||||
struct fb *fbsrc = (struct fb *)argv[1];
|
|
||||||
|
|
||||||
fbs[0] = fbsrc[0];
|
|
||||||
fbs[1] = fbsrc[1];
|
|
||||||
|
|
||||||
argvPassed[1] = (char *)&fbs;
|
|
||||||
}
|
|
||||||
|
|
||||||
doLaunchFirm(firm, argc, argvPassed);
|
|
||||||
}
|
|
||||||
1209
arm9/source/config.c
1209
arm9/source/config.c
File diff suppressed because it is too large
Load Diff
@ -1,279 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2022 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "deliver_arg.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "memory.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "i2c.h"
|
|
||||||
#include "screen.h"
|
|
||||||
|
|
||||||
u8 *loadDeliverArg(void)
|
|
||||||
{
|
|
||||||
static __attribute__((aligned(8))) u8 deliverArg[0x1000] = {0};
|
|
||||||
static bool deliverArgLoaded = false;
|
|
||||||
|
|
||||||
if (!deliverArgLoaded)
|
|
||||||
{
|
|
||||||
u32 bootenv = CFG_BOOTENV; // this register is preserved across reboots
|
|
||||||
if ((bootenv & 1) == 0) // true coldboot
|
|
||||||
{
|
|
||||||
memset(deliverArg, 0, 0x1000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
u32 mode = bootenv >> 1;
|
|
||||||
if (mode == 0) // CTR mode
|
|
||||||
{
|
|
||||||
memcpy(deliverArg, (const void *)0x20000000, 0x1000);
|
|
||||||
|
|
||||||
// Validate deliver arg
|
|
||||||
u32 testPattern = *(u32 *)(deliverArg + 0x438);
|
|
||||||
u32 *crcPtr = (u32 *)(deliverArg + 0x43C);
|
|
||||||
u32 crc = *crcPtr;
|
|
||||||
*crcPtr = 0; // clear crc field before calculation
|
|
||||||
u32 expectedCrc = crc32(deliverArg + 0x400, 0x140, 0xFFFFFFFF);
|
|
||||||
*crcPtr = crc;
|
|
||||||
if (testPattern != 0xFFFF || crc != expectedCrc)
|
|
||||||
memset(deliverArg, 0, 0x1000);
|
|
||||||
}
|
|
||||||
else // Legacy modes
|
|
||||||
{
|
|
||||||
// Copy TWL deliver arg stuff as-is (0...0x300)
|
|
||||||
copyFromLegacyModeFcram(deliverArg, (const void *)0x20000000, 0x400);
|
|
||||||
|
|
||||||
// Validate TLNC (TWL launcher params) block
|
|
||||||
// Note: Nintendo doesn't do crcLen bound check
|
|
||||||
u8 *tlnc = deliverArg + 0x300;
|
|
||||||
bool hasMagic = memcmp(tlnc, "TLNC", 4) == 0;
|
|
||||||
u8 crcLen = tlnc[5];
|
|
||||||
u16 crc = *(u16 *)(tlnc + 6);
|
|
||||||
if (!hasMagic || (8 + crcLen) > 0x100 || crc != crc16(tlnc + 8, crcLen, 0xFFFF))
|
|
||||||
memset(tlnc, 0, 0x100);
|
|
||||||
|
|
||||||
memset(deliverArg + 0x400, 0, 0xC00);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deliverArgLoaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return deliverArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void commitDeliverArg(void)
|
|
||||||
{
|
|
||||||
u8 *deliverArg = loadDeliverArg();
|
|
||||||
u32 bootenv = CFG_BOOTENV;
|
|
||||||
|
|
||||||
if ((bootenv & 1) == 0) // if true coldboot, set bootenv to "CTR mode reboot"
|
|
||||||
{
|
|
||||||
bootenv = 1;
|
|
||||||
CFG_BOOTENV = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 mode = bootenv >> 1;
|
|
||||||
if (mode == 0) // CTR mode
|
|
||||||
{
|
|
||||||
*(u32 *)(deliverArg + 0x438) = 0xFFFF;
|
|
||||||
*(u32 *)(deliverArg + 0x43C) = 0; // clear CRC field before calculating it
|
|
||||||
*(u32 *)(deliverArg + 0x43C) = crc32(deliverArg + 0x400, 0x140, 0xFFFFFFFF);
|
|
||||||
memcpy((void *)0x20000000, deliverArg, 0x1000);
|
|
||||||
}
|
|
||||||
else // Legacy modes (just TWL mode, really)
|
|
||||||
{
|
|
||||||
copyToLegacyModeFcram((void *)0x20000000, deliverArg, 0x400);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasValidTlncAutobootParams(void)
|
|
||||||
{
|
|
||||||
u8 *tlnc = loadDeliverArg() + 0x300; // loadDeliverArg clears invalid TLNC blocks
|
|
||||||
return memcmp(tlnc, "TLNC", 4) == 0 && (*(u16 *)(tlnc + 0x18) & 1) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isTwlToCtrLaunch(void)
|
|
||||||
{
|
|
||||||
// assumes TLNC block is valid
|
|
||||||
u8 *tlnc = loadDeliverArg() + 0x300; // loadDeliverArg clears invalid TLNC blocks
|
|
||||||
u64 twlTid = *(u64 *)(tlnc + 0x10);
|
|
||||||
|
|
||||||
switch (twlTid & ~0xFFull)
|
|
||||||
{
|
|
||||||
case 0x0000000000000000ull: // TWL Launcher -> Home menu (note: NS checks full TID)
|
|
||||||
case 0x00030015484E4200ull: // TWL System Settings -> CTR System Settings (mset)
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool configureHomebrewAutobootCtr(u8 *deliverArg)
|
|
||||||
{
|
|
||||||
static const u8 appmemtypesO3ds[] = { 0, 2, 3, 4, 5 };
|
|
||||||
static const u8 appmemtypesN3ds[] = { 6, 7, 7, 7, 7 };
|
|
||||||
|
|
||||||
u64 hbldrTid = configData.hbldr3dsxTitleId;
|
|
||||||
hbldrTid = hbldrTid == 0 ? HBLDR_DEFAULT_3DSX_TID : hbldrTid; // replicate Loader's behavior
|
|
||||||
if ((hbldrTid >> 46) != 0x10) // Not a CTR titleId. Bail out
|
|
||||||
return false;
|
|
||||||
|
|
||||||
u8 memtype = configData.autobootCtrAppmemtype;
|
|
||||||
// autobootCtrAppmemtype already checked, but it doesn't hurt to check again
|
|
||||||
memtype = memtype >= 5 ? 0 : memtype;
|
|
||||||
deliverArg[0x400] = ISN3DS ? appmemtypesN3ds[memtype] : appmemtypesO3ds[memtype];
|
|
||||||
|
|
||||||
// Determine whether to load from the SD card or from NAND. We don't support gamecards for this
|
|
||||||
u32 category = (hbldrTid >> 32) & 0xFFFF;
|
|
||||||
bool isSdApp = (category & 0x10) == 0 && category != 1; // not a system app nor a DLP child
|
|
||||||
*(u64 *)(deliverArg + 0x440) = hbldrTid;
|
|
||||||
*(u64 *)(deliverArg + 0x448) = isSdApp ? 1 : 0;
|
|
||||||
|
|
||||||
// Tell NS to run the title, and that it's not a title jump from legacy mode
|
|
||||||
*(u32 *)(deliverArg + 0x460) = (0 << 1) | (1 << 0);
|
|
||||||
|
|
||||||
// Whenever power button is held long enough ("force shutdown"), mcu sysmodule
|
|
||||||
// stores a flag in free reg 0. It will clear it next boot.
|
|
||||||
|
|
||||||
// During that next boot, if that flag was set and if CFG_BOOTENV.bit0 is set
|
|
||||||
// (warmboot/firm chainload, i.e. not coldbooting), then main() will simulate
|
|
||||||
// a "power button held" interrupt (after upgrading mcu fw if necessary -- it
|
|
||||||
// will reboot console after if it has upgraded mcu fw, I guess that's one of
|
|
||||||
// the reasons the flag is there). This obviously cause other processes to initiate
|
|
||||||
// a shutdown, and it also sets that flag again.
|
|
||||||
|
|
||||||
// In the case of autoboot, ns will panic when this happens. This caused
|
|
||||||
// hb autoboot to keep failing over and over again.
|
|
||||||
|
|
||||||
// Select free reg 0, read it, select it again, write it (clearing force shutdown flag)
|
|
||||||
I2C_writeReg(I2C_DEV_MCU, 0x60, 0);
|
|
||||||
u8 flags = I2C_readReg(I2C_DEV_MCU, 0x61);
|
|
||||||
flags &= ~4;
|
|
||||||
I2C_writeReg(I2C_DEV_MCU, 0x60, 0);
|
|
||||||
I2C_writeReg(I2C_DEV_MCU, 0x61, flags);
|
|
||||||
|
|
||||||
CFG_BOOTENV = 1;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool configureHomebrewAutobootTwl(u8 *deliverArg)
|
|
||||||
{
|
|
||||||
// Here, we pretend to be a TWL app rebooting into another TWL app.
|
|
||||||
// We get NS to do all the heavy lifting (starting NWM and AM, etc.) this way.
|
|
||||||
|
|
||||||
memset(deliverArg + 0x000, 0, 0x300); // zero TWL deliver arg params
|
|
||||||
|
|
||||||
// Now onto TLNC (launcher params):
|
|
||||||
u8 *tlnc = deliverArg + 0x300;
|
|
||||||
memset(tlnc, 0, 0x100);
|
|
||||||
memcpy(tlnc, "TLNC", 4);
|
|
||||||
tlnc[4] = 1; // version
|
|
||||||
tlnc[5] = 0x18; // length of data to calculate CRC over
|
|
||||||
|
|
||||||
*(u64 *)(tlnc + 8) = 0; // old title ID
|
|
||||||
*(u64 *)(tlnc + 0x10) = configData.autobootTwlTitleId; // new title ID
|
|
||||||
// bit4: "skip logo" ; bits2:1: NAND boot ; bit0: valid
|
|
||||||
*(u16 *)(tlnc + 0x18) = (1 << 4) | (3 << 1) | (1 << 0);
|
|
||||||
|
|
||||||
*(u16 *)(tlnc + 6) = crc16(tlnc + 8, 0x18, 0xFFFF);
|
|
||||||
|
|
||||||
// Even though (when running TWL/AGB FIRM) the SoC is in O3DS mode, and the GPU also is,
|
|
||||||
// as well as most other components behaving as such (external RAM, L2C not usable, etc.),
|
|
||||||
// this is NOT the case for the LCD and adaptive backlight logic which retains FULL N3DS
|
|
||||||
// functionality, including a feature where the window is blended with a given color depending
|
|
||||||
// on the overall relative luminance of that window.
|
|
||||||
|
|
||||||
// However, Nintendo's own code mistakenly assumes the opposite, and clearly so ("if GPU in N3DS mode"
|
|
||||||
// checks, not passing N3DS extra adaptive backlight (ABL) to TWL/AGB_FIRM). This has implications:
|
|
||||||
|
|
||||||
// - Powersaving (ABL) settings in TWL/AGB_FIRM is inconsistent with *both* O3DS (because the new RGB blend LUT
|
|
||||||
// has been set to its current value by NATIVE_FIRM) and N3DS (because "pwn_cnt" and "inertia" are missing
|
|
||||||
// their N3DS-only bits)
|
|
||||||
// - "rave party" when booting into TWL/AGB_FIRM or O3DS NATIVE_FIRM without these regs (well, the LUT) initialized.
|
|
||||||
// Easiest way to do so is by leveraging the "DSi autooboot" feature Luma provides. It is worth noting at least
|
|
||||||
// the LUT survives hardware reboots (if Nintendo were using DSi software that was using TLNC-based reboots,
|
|
||||||
// they wouldn't have noticed).
|
|
||||||
|
|
||||||
// As such, zerofill these registers (from testing, hardware explicitly discards null values, so this
|
|
||||||
// should be fine). For now, only touch the Luma-initiated autoboot path
|
|
||||||
|
|
||||||
if (ISN3DS)
|
|
||||||
zerofillN3dsAblRegisters();
|
|
||||||
|
|
||||||
CFG_BOOTENV = 3;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool configureHomebrewAutoboot(void)
|
|
||||||
{
|
|
||||||
bool ret;
|
|
||||||
u8 *deliverArg = loadDeliverArg();
|
|
||||||
|
|
||||||
u32 bootenv = CFG_BOOTENV;
|
|
||||||
u32 mode = bootenv >> 1;
|
|
||||||
|
|
||||||
// NS always writes a valid deliver arg on reboot, no matter what.
|
|
||||||
// Check if it is empty, and, of course, bail out if we aren't rebooting from
|
|
||||||
// NATIVE_FIRM.
|
|
||||||
// Checking if it is empty is necessary to let us reboot from autobooted hbmenu
|
|
||||||
// to hbmenu.
|
|
||||||
|
|
||||||
if (mode != 0)
|
|
||||||
return false;
|
|
||||||
else if (bootenv == 1)
|
|
||||||
{
|
|
||||||
for (u32 i = 0; i < 0x410; i++)
|
|
||||||
{
|
|
||||||
if (deliverArg[i] != 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (u32 i = 0x440; i < 0x1000; i++)
|
|
||||||
{
|
|
||||||
if (deliverArg[i] != 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (MULTICONFIG(AUTOBOOTMODE))
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
ret = configureHomebrewAutobootCtr(deliverArg);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
ret = configureHomebrewAutobootTwl(deliverArg);
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
ret = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret)
|
|
||||||
commitDeliverArg();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
@ -1,338 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2021 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Code for locating the SDMMC struct by Normmatt
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "emunand.h"
|
|
||||||
#include "memory.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "fatfs/sdmmc/sdmmc.h"
|
|
||||||
#include "large_patches.h"
|
|
||||||
|
|
||||||
u32 emuOffset,
|
|
||||||
emuHeader;
|
|
||||||
|
|
||||||
void locateEmuNand(FirmwareSource *nandType, u32 *emunandIndex, bool configureCtrNandParams)
|
|
||||||
{
|
|
||||||
static u8 __attribute__((aligned(4))) temp[0x200];
|
|
||||||
static u32 nandSize = 0,
|
|
||||||
fatStart;
|
|
||||||
|
|
||||||
if(!nandSize)
|
|
||||||
{
|
|
||||||
nandSize = getMMCDevice(0)->total_size;
|
|
||||||
sdmmc_sdcard_readsectors(0, 1, temp);
|
|
||||||
fatStart = *(u32 *)(temp + 0x1C6); //First sector of the FAT partition
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if (*nandType == FIRMWARE_SYSNAND)
|
|
||||||
return;*/
|
|
||||||
|
|
||||||
for(u32 i = 0; i < 3; i++) // Test the different kinds of multi-EmuNAND there are, unless we are looking for the first one
|
|
||||||
{
|
|
||||||
static const u32 roundedMinsizes[] = {0x1D8000, 0x26E000};
|
|
||||||
|
|
||||||
u32 nandOffset;
|
|
||||||
switch(i)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
nandOffset = ROUND_TO_4MB(nandSize + 1); //"Default" layout
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
nandOffset = roundedMinsizes[ISN3DS ? 1 : 0]; //"Minsize" layout
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
nandOffset = nandSize > 0x200000 ? 0x400000 : 0x200000; //"Legacy" layout
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
nandOffset *= *emunandIndex; // always 0 for 1st EmuNAND
|
|
||||||
|
|
||||||
if(fatStart >= nandOffset + roundedMinsizes[ISN3DS ? 1 : 0])
|
|
||||||
{
|
|
||||||
//Check for RedNAND
|
|
||||||
if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && memcmp(temp + 0x100, "NCSD", 4) == 0)
|
|
||||||
{
|
|
||||||
if (configureCtrNandParams)
|
|
||||||
{
|
|
||||||
emuOffset = nandOffset + 1;
|
|
||||||
emuHeader = 0;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check for Gateway EmuNAND
|
|
||||||
else if(i != 2 && !sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && memcmp(temp + 0x100, "NCSD", 4) == 0)
|
|
||||||
{
|
|
||||||
if (configureCtrNandParams)
|
|
||||||
{
|
|
||||||
emuOffset = nandOffset;
|
|
||||||
emuHeader = nandSize;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(*emunandIndex == 0) break; // See above comments
|
|
||||||
}
|
|
||||||
|
|
||||||
//Fallback to the first EmuNAND if there's no second/third/fourth one, or to SysNAND if there isn't any
|
|
||||||
if(*emunandIndex != 0)
|
|
||||||
{
|
|
||||||
*emunandIndex = 0;
|
|
||||||
locateEmuNand(nandType, emunandIndex, configureCtrNandParams);
|
|
||||||
}
|
|
||||||
else *nandType = FIRMWARE_SYSNAND;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u32 getProtoSdmmc(u32 *sdmmc, u32 firmVersion)
|
|
||||||
{
|
|
||||||
switch(firmVersion)
|
|
||||||
{
|
|
||||||
case 243: // SDK 0.9.x (0.9.7?)
|
|
||||||
*sdmmc = (0x080AAA28 + 0x4e0);
|
|
||||||
break;
|
|
||||||
case 238: // SDK 0.10
|
|
||||||
*sdmmc = (0x080BEA70 + 0x690);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u32 getOldSdmmc(u32 *sdmmc, u32 firmVersion)
|
|
||||||
{
|
|
||||||
switch(firmVersion)
|
|
||||||
{
|
|
||||||
case 0x18:
|
|
||||||
*sdmmc = 0x080D91D8;
|
|
||||||
break;
|
|
||||||
case 0x1D:
|
|
||||||
case 0x1F:
|
|
||||||
*sdmmc = 0x080D8CD0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u32 getSdmmc(u8 *pos, u32 size, u32 *sdmmc)
|
|
||||||
{
|
|
||||||
//Look for struct code
|
|
||||||
static const u8 pattern[] = {0x21, 0x20, 0x18, 0x20};
|
|
||||||
|
|
||||||
const u8 *off = memsearch(pos, pattern, size, sizeof(pattern));
|
|
||||||
|
|
||||||
if(off == NULL) return 1;
|
|
||||||
|
|
||||||
*sdmmc = *(u32 *)(off + 9) + *(u32 *)(off + 0xD);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u32 patchNandRw(u8 *pos, u32 size, u32 hookAddr)
|
|
||||||
{
|
|
||||||
//Look for read/write code
|
|
||||||
static const u8 pattern[] = {0x1E, 0x00, 0xC8, 0x05};
|
|
||||||
|
|
||||||
u16 *readOffset = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
|
||||||
|
|
||||||
if(readOffset == NULL) return 1;
|
|
||||||
|
|
||||||
readOffset -= 3;
|
|
||||||
|
|
||||||
u16 *writeOffset = (u16 *)memsearch((u8 *)(readOffset + 5), pattern, 0x100, sizeof(pattern));
|
|
||||||
|
|
||||||
if(writeOffset == NULL) return 1;
|
|
||||||
|
|
||||||
writeOffset -= 3;
|
|
||||||
*readOffset = *writeOffset = 0x4C00;
|
|
||||||
readOffset[1] = writeOffset[1] = 0x47A0;
|
|
||||||
((u32 *)writeOffset)[1] = ((u32 *)readOffset)[1] = hookAddr;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u32 patchProtoNandRw(u8 *pos, u32 size, u32 hookAddr, u32 hookCidAddr)
|
|
||||||
{
|
|
||||||
//Look for read/write code
|
|
||||||
static const u8 pattern[] = {
|
|
||||||
0x03, 0x00, 0x51, 0xE3, // cmp r1, #3
|
|
||||||
0x02, 0xC0, 0xA0, 0xE1, // mov r12, r2
|
|
||||||
0x04, 0x00, 0x80, 0xE2, // add r0, r0, #4
|
|
||||||
};
|
|
||||||
|
|
||||||
u32 *writeOffset = (u32 *)memsearch(pos, pattern, size, sizeof(pattern));
|
|
||||||
|
|
||||||
if(writeOffset == NULL) return 1;
|
|
||||||
|
|
||||||
u32 *readOffset = (u32 *)memsearch((u8 *)(writeOffset + 3), pattern, 0x400, sizeof(pattern));
|
|
||||||
|
|
||||||
if(readOffset == NULL) return 1;
|
|
||||||
|
|
||||||
// Find the sdmmc mount/init(?) function
|
|
||||||
static const u8 mount_pattern[] = {
|
|
||||||
0x20, 0x00, 0x84, 0xE2, // add r0, r4, 0x20
|
|
||||||
0x01, 0x20, 0xA0, 0xE3, // mov r2, #1
|
|
||||||
0x00, 0x10, 0xA0, 0xE3, // mov r1, #0
|
|
||||||
};
|
|
||||||
u32* mountOffset = (u32*) memsearch(pos, mount_pattern, size, sizeof(mount_pattern));
|
|
||||||
if (mountOffset == NULL) return 1;
|
|
||||||
|
|
||||||
// Find the sdmmc read cid function.
|
|
||||||
static const u8 readcid_pattern[] = {
|
|
||||||
0x31, 0xFF, 0x2F, 0xE1, // blx r1
|
|
||||||
0x20, 0x60, 0x9F, 0xE5, // ldr r6, [pc, #0x20] // =failing_result
|
|
||||||
0x00, 0x00, 0x50, 0xE3, // cmp r0, #0
|
|
||||||
};
|
|
||||||
u32* readCidOffset = (u32*) memsearch(pos, readcid_pattern, size, sizeof(readcid_pattern));
|
|
||||||
if (readCidOffset == NULL) return 1;
|
|
||||||
readCidOffset -= 5;
|
|
||||||
|
|
||||||
mountOffset[1] = 0xe3a02000; // mov r2, #0 // sd-card
|
|
||||||
|
|
||||||
readOffset[0] = writeOffset[0] = 0xe52de004; // push {lr}
|
|
||||||
readOffset[1] = writeOffset[1] = 0xe59fc000; // ldr r12, [pc, #0]
|
|
||||||
readOffset[2] = writeOffset[2] = 0xe12fff3c; // blx r12
|
|
||||||
readOffset[3] = writeOffset[3] = hookAddr;
|
|
||||||
|
|
||||||
readCidOffset[0] = 0xe59fc000; // ldr r12, [pc, #0]
|
|
||||||
readCidOffset[1] = 0xe12fff3c; // blx r12
|
|
||||||
readCidOffset[2] = hookCidAddr;
|
|
||||||
|
|
||||||
// Read the emmc cid into the place hook will copy it from
|
|
||||||
sdmmc_get_cid(1, emunandPatchNandCid);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u32 patchProtoNandRw238(u8 *pos, u32 size, u32 hookAddr, u32 hookCidAddr)
|
|
||||||
{
|
|
||||||
//Look for read/write code
|
|
||||||
static const u8 pattern[] = {
|
|
||||||
0x03, 0x00, 0x50, 0xE3, // cmp r0, #3
|
|
||||||
0x00, 0x00, 0xA0, 0x13, // movne r0, #0
|
|
||||||
0x01, 0x00, 0xA0, 0x03, // moveq r0, #1
|
|
||||||
};
|
|
||||||
|
|
||||||
u32 *writeOffset = (u32 *)memsearch(pos, pattern, size, sizeof(pattern));
|
|
||||||
|
|
||||||
if(writeOffset == NULL) return 1;
|
|
||||||
|
|
||||||
u32 *readOffset = (u32 *)memsearch((u8 *)(writeOffset + 3), pattern, 0x400, sizeof(pattern));
|
|
||||||
|
|
||||||
if(readOffset == NULL) return 1;
|
|
||||||
|
|
||||||
// Find the mmc static ctor...
|
|
||||||
static const u8 mount_pattern[] = {
|
|
||||||
0x08, // last byte of some ptr to something in P9
|
|
||||||
0x01, 0x01, 0x00, 0x00, // emmc controller id
|
|
||||||
};
|
|
||||||
u8* mountOffset = (u8*) memsearch(pos, mount_pattern, size, sizeof(mount_pattern));
|
|
||||||
if (mountOffset == NULL) return 1;
|
|
||||||
mountOffset++;
|
|
||||||
|
|
||||||
// Find the sdmmc read cid function.
|
|
||||||
static const u8 readcid_pattern[] = {
|
|
||||||
0x31, 0xFF, 0x2F, 0xE1, // blx r1
|
|
||||||
0x20, 0x60, 0x9F, 0xE5, // ldr r6, [pc, #0x20] // =failing_result
|
|
||||||
0x00, 0x00, 0x50, 0xE3, // cmp r0, #0
|
|
||||||
};
|
|
||||||
u32* readCidOffset = (u32*) memsearch(pos, readcid_pattern, size, sizeof(readcid_pattern));
|
|
||||||
if (readCidOffset == NULL) return 1;
|
|
||||||
readCidOffset -= 5;
|
|
||||||
|
|
||||||
*(u32*)mountOffset = 0x300; // sd card
|
|
||||||
|
|
||||||
readOffset[0] = writeOffset[0] = 0xe59fc000; // ldr r12, [pc, #0]
|
|
||||||
readOffset[1] = writeOffset[1] = 0xe12fff3c; // blx r12
|
|
||||||
readOffset[2] = writeOffset[2] = hookAddr;
|
|
||||||
|
|
||||||
readCidOffset[0] = 0xe59fc000; // ldr r12, [pc, #0]
|
|
||||||
readCidOffset[1] = 0xe12fff3c; // blx r12
|
|
||||||
readCidOffset[2] = hookCidAddr;
|
|
||||||
|
|
||||||
// Read the emmc cid into the place hook will copy it from
|
|
||||||
sdmmc_get_cid(1, emunandPatchNandCid);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 patchEmuNand(u8 *process9Offset, u32 process9Size, u32 firmVersion)
|
|
||||||
{
|
|
||||||
u32 ret = 0;
|
|
||||||
|
|
||||||
//Add the data of the found EmuNAND
|
|
||||||
emunandPatchNandOffset = emuOffset;
|
|
||||||
emunandPatchNcsdHeaderOffset = emuHeader;
|
|
||||||
|
|
||||||
//Find and add the SDMMC struct
|
|
||||||
u32 sdmmc;
|
|
||||||
ret += !ISN3DS && firmVersion < 0x25 ? getOldSdmmc(&sdmmc, firmVersion) : getSdmmc(process9Offset, process9Size, &sdmmc);
|
|
||||||
if(!ret) emunandPatchSdmmcStructPtr = sdmmc;
|
|
||||||
|
|
||||||
//Add EmuNAND hooks
|
|
||||||
ret += patchNandRw(process9Offset, process9Size, (u32)emunandPatch);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 patchProtoEmuNand(u8 *process9Offset, u32 process9Size)
|
|
||||||
{
|
|
||||||
extern u32 firmProtoVersion;
|
|
||||||
u32 ret = 0;
|
|
||||||
|
|
||||||
// Add the data of the found EmuNAND
|
|
||||||
emunandPatchNandOffset = emuOffset;
|
|
||||||
emunandPatchNcsdHeaderOffset = emuHeader;
|
|
||||||
|
|
||||||
// Find and add the SDMMC struct
|
|
||||||
u32 sdmmc;
|
|
||||||
ret += getProtoSdmmc(&sdmmc, firmProtoVersion);
|
|
||||||
if(!ret) emunandPatchSdmmcStructPtr = sdmmc;
|
|
||||||
|
|
||||||
// Add EmuNAND hooks
|
|
||||||
switch (firmProtoVersion) {
|
|
||||||
case 243: // SDK 0.9.x (0.9.7?)
|
|
||||||
ret += patchProtoNandRw(process9Offset, process9Size, (u32)emunandProtoPatch, (u32)emunandProtoCidPatch);
|
|
||||||
break;
|
|
||||||
case 238: // SDK 0.10.x
|
|
||||||
ret += patchProtoNandRw238(process9Offset, process9Size, (u32)emunandProtoPatch238, (u32)emunandProtoCidPatch);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ret++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
@ -1,194 +0,0 @@
|
|||||||
.section .emunand_patch, "aw", %progbits
|
|
||||||
.arm
|
|
||||||
.align 4
|
|
||||||
|
|
||||||
@ Code originally by Normmatt
|
|
||||||
|
|
||||||
.global emunandPatch
|
|
||||||
emunandPatch:
|
|
||||||
@ Original code that still needs to be executed
|
|
||||||
mov r4, r0
|
|
||||||
mov r5, r1
|
|
||||||
mov r7, r2
|
|
||||||
mov r6, r3
|
|
||||||
@ End
|
|
||||||
|
|
||||||
@ If we're already trying to access the SD, return
|
|
||||||
ldr r2, [r0, #4]
|
|
||||||
ldr r1, emunandPatchSdmmcStructPtr
|
|
||||||
cmp r2, r1
|
|
||||||
beq out
|
|
||||||
|
|
||||||
str r1, [r0, #4] @ Set object to be SD
|
|
||||||
ldr r2, [r0, #8] @ Get sector to read
|
|
||||||
cmp r2, #0 @ For GW compatibility, see if we're trying to read the ncsd header (sector 0)
|
|
||||||
|
|
||||||
ldr r3, emunandPatchNandOffset
|
|
||||||
add r2, r3 @ Add the offset to the NAND in the SD
|
|
||||||
|
|
||||||
ldreq r3, emunandPatchNcsdHeaderOffset
|
|
||||||
addeq r2, r3 @ If we're reading the ncsd header, add the offset of that sector
|
|
||||||
|
|
||||||
str r2, [r0, #8] @ Store sector to read
|
|
||||||
|
|
||||||
out:
|
|
||||||
@ Restore registers.
|
|
||||||
mov r1, r5
|
|
||||||
mov r2, r7
|
|
||||||
mov r3, r6
|
|
||||||
|
|
||||||
@ Return 4 bytes behind where we got called,
|
|
||||||
@ due to the offset of this function being stored there
|
|
||||||
mov r0, lr
|
|
||||||
add r0, #4
|
|
||||||
bx r0
|
|
||||||
|
|
||||||
.pool
|
|
||||||
|
|
||||||
_emunandPatchEnd:
|
|
||||||
|
|
||||||
.global emunandProtoPatch
|
|
||||||
emunandProtoPatch:
|
|
||||||
@ Save registers
|
|
||||||
push {r0-r3}
|
|
||||||
|
|
||||||
@ If we're already trying to access the SD, return
|
|
||||||
ldr r2, [r0, #4]
|
|
||||||
ldr r1, emunandPatchSdmmcStructPtr
|
|
||||||
cmp r2, r1
|
|
||||||
beq _out
|
|
||||||
|
|
||||||
ldrb r2, [r1, #0xc] @ Get sdmc->m_isInitialised
|
|
||||||
cmp r2, #0 @ Is initialised?
|
|
||||||
beq _pastSdmc @ if not, use "NAND" object, patched elsewhere to access SD
|
|
||||||
str r1, [r0, #4] @ Set object to be SD
|
|
||||||
_pastSdmc:
|
|
||||||
ldr r2, [r0, #8] @ Get sector to read
|
|
||||||
cmp r2, #0 @ For GW compatibility, see if we're trying to read the ncsd header (sector 0)
|
|
||||||
|
|
||||||
ldr r3, emunandPatchNandOffset
|
|
||||||
add r2, r3 @ Add the offset to the NAND in the SD
|
|
||||||
|
|
||||||
ldreq r3, emunandPatchNcsdHeaderOffset
|
|
||||||
addeq r2, r3 @ If we're reading the ncsd header, add the offset of that sector
|
|
||||||
|
|
||||||
str r2, [r0, #8] @ Store sector to read
|
|
||||||
|
|
||||||
_out:
|
|
||||||
@ Restore registers
|
|
||||||
pop {r0-r3}
|
|
||||||
@ Execute original code that got patched.
|
|
||||||
cmp r1, #3
|
|
||||||
mov r12, r2
|
|
||||||
add r0, r0, #4
|
|
||||||
movne r1, #0
|
|
||||||
moveq r1, #1
|
|
||||||
@ r2 about to be overwritten, so it's free to use here.
|
|
||||||
@ Save off our return address and restore lr.
|
|
||||||
mov r2, lr
|
|
||||||
pop {lr}
|
|
||||||
@ r2+0 is return address (patched movne r1, #0)
|
|
||||||
@ r2+4 is moveq r1, #1
|
|
||||||
@ r2+8 is the following instruction (mov r2, r3)
|
|
||||||
add r2, #8
|
|
||||||
bx r2
|
|
||||||
|
|
||||||
.global emunandProtoCidPatch
|
|
||||||
emunandProtoCidPatch:
|
|
||||||
@ If we're already trying to access the SD, return
|
|
||||||
ldr r4, emunandPatchSdmmcStructPtr
|
|
||||||
cmp r0, r4
|
|
||||||
beq _cid_return
|
|
||||||
|
|
||||||
@ Trying to access nand, so copy the NAND cid into r1
|
|
||||||
adr r4, emunandPatchNandCid
|
|
||||||
ldr r2, [r4, #0]
|
|
||||||
ldr r3, [r4, #4]
|
|
||||||
ldr r5, [r4, #8]
|
|
||||||
ldr r6, [r4, #0xc]
|
|
||||||
str r2, [r1, #0]
|
|
||||||
str r3, [r1, #4]
|
|
||||||
str r5, [r1, #8]
|
|
||||||
str r6, [r1, #0xc]
|
|
||||||
@ And return from whence we came
|
|
||||||
mov r0, #0
|
|
||||||
pop {r4-r6, pc}
|
|
||||||
|
|
||||||
_cid_return:
|
|
||||||
@ Execute original code that got patched.
|
|
||||||
mov r4, r0
|
|
||||||
ldr r0, [r0]
|
|
||||||
mov r5, r1
|
|
||||||
@ lr+0 is return address (patched mov r5, r1)
|
|
||||||
@ lr+4 is following instruction (ldr r1, [r0,#8])
|
|
||||||
add lr, #4
|
|
||||||
bx lr
|
|
||||||
|
|
||||||
.global emunandProtoPatch238
|
|
||||||
emunandProtoPatch238:
|
|
||||||
@ Save registers
|
|
||||||
push {r0-r3}
|
|
||||||
|
|
||||||
@ If we're already trying to access the SD, return
|
|
||||||
ldr r2, [r4, #4]
|
|
||||||
ldr r1, emunandPatchSdmmcStructPtr
|
|
||||||
cmp r2, r1
|
|
||||||
beq _out238
|
|
||||||
|
|
||||||
ldr r2, [r1, #0x24] @ Get sdmc->m_someObjInitedLater
|
|
||||||
cmp r2, #0 @ Is initialised?
|
|
||||||
beq _pastSdmc238 @ if not, use "NAND" object, patched elsewhere to access SD
|
|
||||||
str r1, [r4, #4] @ Set object to be SD
|
|
||||||
_pastSdmc238:
|
|
||||||
|
|
||||||
ldr r2, [r4, #8] @ Get sector to read
|
|
||||||
cmp r2, #0 @ For GW compatibility, see if we're trying to read the ncsd header (sector 0)
|
|
||||||
|
|
||||||
ldr r3, emunandPatchNandOffset
|
|
||||||
add r2, r3 @ Add the offset to the NAND in the SD
|
|
||||||
|
|
||||||
ldreq r3, emunandPatchNcsdHeaderOffset
|
|
||||||
addeq r2, r3 @ If we're reading the ncsd header, add the offset of that sector
|
|
||||||
|
|
||||||
str r2, [r4, #8] @ Store sector to read
|
|
||||||
|
|
||||||
_out238:
|
|
||||||
@ Restore registers
|
|
||||||
pop {r0-r3}
|
|
||||||
@ Execute original code that got patched.
|
|
||||||
cmp r0, #3
|
|
||||||
movne r0, #0
|
|
||||||
moveq r0, #1
|
|
||||||
@ r1 about to be overwritten, so it's free to use here.
|
|
||||||
@ Save off our return address.
|
|
||||||
mov r1, lr
|
|
||||||
@ r1+0 is return address (patched moveq r1, #1)
|
|
||||||
@ r1+4 is tst r0, #0xff or sub sp, sp, #0xc
|
|
||||||
add r1, #4
|
|
||||||
bx r1
|
|
||||||
|
|
||||||
.pool
|
|
||||||
|
|
||||||
.global emunandPatchSdmmcStructPtr
|
|
||||||
.global emunandPatchNandOffset
|
|
||||||
.global emunandPatchNcsdHeaderOffset
|
|
||||||
.global emunandPatchNandCid
|
|
||||||
|
|
||||||
_emunandPatchBssStart:
|
|
||||||
emunandPatchSdmmcStructPtr: .word 0 @ Pointer to sdmmc struct
|
|
||||||
emunandPatchNandOffset: .word 0 @ For rednand this should be 1
|
|
||||||
emunandPatchNcsdHeaderOffset: .word 0 @ Depends on nand manufacturer + emunand type (GW/RED)
|
|
||||||
emunandPatchNandCid: @ Store emmc cid here, to override "sdmc's" when trying to read emmc's
|
|
||||||
.word 0,0,0,0
|
|
||||||
_emunandPatchBssEnd:
|
|
||||||
|
|
||||||
.pool
|
|
||||||
.balign 4
|
|
||||||
|
|
||||||
.global emunandPatchSize
|
|
||||||
emunandPatchSize:
|
|
||||||
.word _emunandPatchEnd - emunandPatch
|
|
||||||
|
|
||||||
.global emunandPatchBssSize
|
|
||||||
emunandPatchBssSize:
|
|
||||||
.word _emunandPatchBssEnd - _emunandPatchBssStart
|
|
||||||
@ -1,186 +0,0 @@
|
|||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* If a working storage control module is available, it should be */
|
|
||||||
/* attached to the FatFs via a glue function rather than modifying it. */
|
|
||||||
/* This is an example of glue functions to attach various exsisting */
|
|
||||||
/* storage control modules to the FatFs module with a defined API. */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#include "ff.h" /* Obtains integer types */
|
|
||||||
#include "diskio.h" /* Declarations of disk functions */
|
|
||||||
#include "sdmmc/sdmmc.h"
|
|
||||||
#include "../crypto.h"
|
|
||||||
#include "../i2c.h"
|
|
||||||
|
|
||||||
/* Definitions of physical drive number for each drive */
|
|
||||||
#define SDCARD 0
|
|
||||||
#define CTRNAND 1
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Get Drive Status */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
DSTATUS disk_status (
|
|
||||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(void)pdrv;
|
|
||||||
return RES_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Inidialize a Drive */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
DSTATUS disk_initialize (
|
|
||||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
static u32 sdmmcInitResult = 4;
|
|
||||||
DSTATUS res = 0;
|
|
||||||
|
|
||||||
if(sdmmcInitResult == 4)
|
|
||||||
sdmmcInitResult = sdmmc_sdcard_init();
|
|
||||||
|
|
||||||
// Check physical drive initialized status
|
|
||||||
switch (pdrv)
|
|
||||||
{
|
|
||||||
case SDCARD:
|
|
||||||
res = (sdmmcInitResult & 2) == 0 ? 0 : STA_NOINIT;
|
|
||||||
break;
|
|
||||||
case CTRNAND:
|
|
||||||
// Always update CTRNAND parameters when remounting
|
|
||||||
res = (sdmmcInitResult & 1) == 0 && ctrNandInit() == 0 ? 0 : STA_NOINIT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
res = STA_NODISK;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Read Sector(s) */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
DRESULT disk_read (
|
|
||||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
|
||||||
BYTE *buff, /* Data buffer to store read data */
|
|
||||||
LBA_t sector, /* Start sector in LBA */
|
|
||||||
UINT count /* Number of sectors to read */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
DRESULT res = RES_OK;
|
|
||||||
|
|
||||||
switch (pdrv)
|
|
||||||
{
|
|
||||||
case SDCARD:
|
|
||||||
res = sdmmc_sdcard_readsectors(sector, count, buff) == 0 ? RES_OK : RES_PARERR;
|
|
||||||
break;
|
|
||||||
case CTRNAND:
|
|
||||||
res = ctrNandRead(sector, count, buff) == 0 ? RES_OK : RES_PARERR;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
res = RES_NOTRDY;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Write Sector(s) */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if FF_FS_READONLY == 0
|
|
||||||
|
|
||||||
DRESULT disk_write (
|
|
||||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
|
||||||
const BYTE *buff, /* Data to be written */
|
|
||||||
LBA_t sector, /* Start sector in LBA */
|
|
||||||
UINT count /* Number of sectors to write */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
DRESULT res = RES_OK;
|
|
||||||
|
|
||||||
switch (pdrv)
|
|
||||||
{
|
|
||||||
case SDCARD:
|
|
||||||
{
|
|
||||||
if ((*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0) // why == 0?
|
|
||||||
res = RES_WRPRT;
|
|
||||||
else
|
|
||||||
res = sdmmc_sdcard_writesectors(sector, count, buff) == 0 ? RES_OK : RES_PARERR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CTRNAND:
|
|
||||||
res = ctrNandWrite(sector, count, buff) == 0 ? RES_OK : RES_PARERR;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
res = RES_NOTRDY;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Miscellaneous Functions */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
DRESULT disk_ioctl (
|
|
||||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
|
||||||
BYTE cmd, /* Control code */
|
|
||||||
void *buff /* Buffer to send/receive control data */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(void)pdrv;
|
|
||||||
(void)buff;
|
|
||||||
return cmd == CTRL_SYNC ? RES_OK : RES_PARERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// From GodMode9
|
|
||||||
#define BCDVALID(b) (((b)<=0x99)&&(((b)&0xF)<=0x9)&&((((b)>>4)&0xF)<=0x9))
|
|
||||||
#define BCD2NUM(b) (BCDVALID(b) ? (((b)&0xF)+((((b)>>4)&0xF)*10)) : 0xFF)
|
|
||||||
#define NUM2BCD(n) ((n<99) ? (((n/10)*0x10)|(n%10)) : 0x99)
|
|
||||||
#define DSTIMEGET(bcd,n) (BCD2NUM((bcd)->n))
|
|
||||||
|
|
||||||
// see: http://3dbrew.org/wiki/I2C_Registers#Device_3 (register 30)
|
|
||||||
typedef struct DsTime {
|
|
||||||
u8 bcd_s;
|
|
||||||
u8 bcd_m;
|
|
||||||
u8 bcd_h;
|
|
||||||
u8 weekday;
|
|
||||||
u8 bcd_D;
|
|
||||||
u8 bcd_M;
|
|
||||||
u8 bcd_Y;
|
|
||||||
u8 leap_count;
|
|
||||||
} DsTime;
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Get current FAT time */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
DWORD get_fattime( void ) {
|
|
||||||
DsTime dstime;
|
|
||||||
I2C_readRegBuf(I2C_DEV_MCU, 0x30, (u8 *)&dstime, sizeof(DsTime));
|
|
||||||
DWORD fattime =
|
|
||||||
((DSTIMEGET(&dstime, bcd_s)&0x3F) >> 1 ) |
|
|
||||||
((DSTIMEGET(&dstime, bcd_m)&0x3F) << 5 ) |
|
|
||||||
((DSTIMEGET(&dstime, bcd_h)&0x3F) << 11) |
|
|
||||||
((DSTIMEGET(&dstime, bcd_D)&0x1F) << 16) |
|
|
||||||
((DSTIMEGET(&dstime, bcd_M)&0x0F) << 21) |
|
|
||||||
(((DSTIMEGET(&dstime, bcd_Y)+(2000-1980))&0x7F) << 25);
|
|
||||||
|
|
||||||
return fattime;
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,296 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------/
|
|
||||||
/ Configurations of FatFs Module
|
|
||||||
/---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#define FFCONF_DEF 80286 /* Revision ID */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------/
|
|
||||||
/ Function Configurations
|
|
||||||
/---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#define FF_FS_READONLY 0
|
|
||||||
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
|
|
||||||
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
|
|
||||||
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
|
|
||||||
/ and optional writing functions as well. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_MINIMIZE 0
|
|
||||||
/* This option defines minimization level to remove some basic API functions.
|
|
||||||
/
|
|
||||||
/ 0: Basic functions are fully enabled.
|
|
||||||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
|
|
||||||
/ are removed.
|
|
||||||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
|
||||||
/ 3: f_lseek() function is removed in addition to 2. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_FIND 1
|
|
||||||
/* This option switches filtered directory read functions, f_findfirst() and
|
|
||||||
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_MKFS 0
|
|
||||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_FASTSEEK 0
|
|
||||||
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_EXPAND 0
|
|
||||||
/* This option switches f_expand function. (0:Disable or 1:Enable) */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_CHMOD 0
|
|
||||||
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
|
|
||||||
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_LABEL 0
|
|
||||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
|
||||||
/ (0:Disable or 1:Enable) */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_FORWARD 0
|
|
||||||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_STRFUNC 0
|
|
||||||
#define FF_PRINT_LLI 1
|
|
||||||
#define FF_PRINT_FLOAT 1
|
|
||||||
#define FF_STRF_ENCODE 3
|
|
||||||
/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
|
|
||||||
/ f_printf().
|
|
||||||
/
|
|
||||||
/ 0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
|
|
||||||
/ 1: Enable without LF-CRLF conversion.
|
|
||||||
/ 2: Enable with LF-CRLF conversion.
|
|
||||||
/
|
|
||||||
/ FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
|
|
||||||
/ makes f_printf() support floating point argument. These features want C99 or later.
|
|
||||||
/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
|
|
||||||
/ encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
|
|
||||||
/ to be read/written via those functions.
|
|
||||||
/
|
|
||||||
/ 0: ANSI/OEM in current CP
|
|
||||||
/ 1: Unicode in UTF-16LE
|
|
||||||
/ 2: Unicode in UTF-16BE
|
|
||||||
/ 3: Unicode in UTF-8
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------/
|
|
||||||
/ Locale and Namespace Configurations
|
|
||||||
/---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#define FF_CODE_PAGE 437
|
|
||||||
/* This option specifies the OEM code page to be used on the target system.
|
|
||||||
/ Incorrect code page setting can cause a file open failure.
|
|
||||||
/
|
|
||||||
/ 437 - U.S.
|
|
||||||
/ 720 - Arabic
|
|
||||||
/ 737 - Greek
|
|
||||||
/ 771 - KBL
|
|
||||||
/ 775 - Baltic
|
|
||||||
/ 850 - Latin 1
|
|
||||||
/ 852 - Latin 2
|
|
||||||
/ 855 - Cyrillic
|
|
||||||
/ 857 - Turkish
|
|
||||||
/ 860 - Portuguese
|
|
||||||
/ 861 - Icelandic
|
|
||||||
/ 862 - Hebrew
|
|
||||||
/ 863 - Canadian French
|
|
||||||
/ 864 - Arabic
|
|
||||||
/ 865 - Nordic
|
|
||||||
/ 866 - Russian
|
|
||||||
/ 869 - Greek 2
|
|
||||||
/ 932 - Japanese (DBCS)
|
|
||||||
/ 936 - Simplified Chinese (DBCS)
|
|
||||||
/ 949 - Korean (DBCS)
|
|
||||||
/ 950 - Traditional Chinese (DBCS)
|
|
||||||
/ 0 - Include all code pages above and configured by f_setcp()
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_LFN 2
|
|
||||||
#define FF_MAX_LFN 255
|
|
||||||
/* The FF_USE_LFN switches the support for LFN (long file name).
|
|
||||||
/
|
|
||||||
/ 0: Disable LFN. FF_MAX_LFN has no effect.
|
|
||||||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
|
||||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
|
||||||
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
|
||||||
/
|
|
||||||
/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
|
|
||||||
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
|
|
||||||
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
|
|
||||||
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
|
|
||||||
/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
|
|
||||||
/ specification.
|
|
||||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
|
||||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
|
||||||
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_LFN_UNICODE 2
|
|
||||||
/* This option switches the character encoding on the API when LFN is enabled.
|
|
||||||
/
|
|
||||||
/ 0: ANSI/OEM in current CP (TCHAR = char)
|
|
||||||
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
|
|
||||||
/ 2: Unicode in UTF-8 (TCHAR = char)
|
|
||||||
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
|
|
||||||
/
|
|
||||||
/ Also behavior of string I/O functions will be affected by this option.
|
|
||||||
/ When LFN is not enabled, this option has no effect. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_LFN_BUF 255
|
|
||||||
#define FF_SFN_BUF 12
|
|
||||||
/* This set of options defines size of file name members in the FILINFO structure
|
|
||||||
/ which is used to read out directory items. These values should be suffcient for
|
|
||||||
/ the file names to read. The maximum possible length of the read file name depends
|
|
||||||
/ on character encoding. When LFN is not enabled, these options have no effect. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_RPATH 1
|
|
||||||
/* This option configures support for relative path.
|
|
||||||
/
|
|
||||||
/ 0: Disable relative path and remove related functions.
|
|
||||||
/ 1: Enable relative path. f_chdir() and f_chdrive() are available.
|
|
||||||
/ 2: f_getcwd() function is available in addition to 1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------/
|
|
||||||
/ Drive/Volume Configurations
|
|
||||||
/---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#define FF_VOLUMES 2
|
|
||||||
/* Number of volumes (logical drives) to be used. (1-10) */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_STR_VOLUME_ID 1
|
|
||||||
#define FF_VOLUME_STRS "sdmc", "nand"
|
|
||||||
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
|
|
||||||
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
|
|
||||||
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
|
|
||||||
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid
|
|
||||||
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
|
|
||||||
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
|
|
||||||
/ not defined, a user defined volume string table is needed as:
|
|
||||||
/
|
|
||||||
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_MULTI_PARTITION 0
|
|
||||||
/* This option switches support for multiple volumes on the physical drive.
|
|
||||||
/ By default (0), each logical drive number is bound to the same physical drive
|
|
||||||
/ number and only an FAT volume found on the physical drive will be mounted.
|
|
||||||
/ When this function is enabled (1), each logical drive number can be bound to
|
|
||||||
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
|
|
||||||
/ function will be available. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_MIN_SS 512
|
|
||||||
#define FF_MAX_SS 512
|
|
||||||
/* This set of options configures the range of sector size to be supported. (512,
|
|
||||||
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
|
|
||||||
/ harddisk, but a larger value may be required for on-board flash memory and some
|
|
||||||
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
|
|
||||||
/ for variable sector size mode and disk_ioctl() function needs to implement
|
|
||||||
/ GET_SECTOR_SIZE command. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_LBA64 0
|
|
||||||
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
|
|
||||||
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_MIN_GPT 0x10000000
|
|
||||||
/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
|
|
||||||
/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_TRIM 0
|
|
||||||
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
|
|
||||||
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
|
||||||
/ disk_ioctl() function. */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------/
|
|
||||||
/ System Configurations
|
|
||||||
/---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#define FF_FS_TINY 0
|
|
||||||
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
|
|
||||||
/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
|
|
||||||
/ Instead of private sector buffer eliminated from the file object, common sector
|
|
||||||
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_EXFAT 0
|
|
||||||
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
|
|
||||||
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
|
|
||||||
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_NORTC 0
|
|
||||||
#define FF_NORTC_MON 1
|
|
||||||
#define FF_NORTC_MDAY 1
|
|
||||||
#define FF_NORTC_YEAR 2022
|
|
||||||
/* The option FF_FS_NORTC switches timestamp feature. If the system does not have
|
|
||||||
/ an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the
|
|
||||||
/ timestamp feature. Every object modified by FatFs will have a fixed timestamp
|
|
||||||
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
|
|
||||||
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
|
|
||||||
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
|
|
||||||
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
|
|
||||||
/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_NOFSINFO 0
|
|
||||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
|
||||||
/ option, and f_getfree() function at the first time after volume mount will force
|
|
||||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
|
||||||
/
|
|
||||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
|
||||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
|
||||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
|
||||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_LOCK 0
|
|
||||||
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
|
|
||||||
/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
|
|
||||||
/ is 1.
|
|
||||||
/
|
|
||||||
/ 0: Disable file lock function. To avoid volume corruption, application program
|
|
||||||
/ should avoid illegal open, remove and rename to the open objects.
|
|
||||||
/ >0: Enable file lock function. The value defines how many files/sub-directories
|
|
||||||
/ can be opened simultaneously under file lock control. Note that the file
|
|
||||||
/ lock control is independent of re-entrancy. */
|
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_REENTRANT 0
|
|
||||||
#define FF_FS_TIMEOUT 1000
|
|
||||||
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
|
|
||||||
/ module itself. Note that regardless of this option, file access to different
|
|
||||||
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
|
|
||||||
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
|
|
||||||
/ to the same volume is under control of this featuer.
|
|
||||||
/
|
|
||||||
/ 0: Disable re-entrancy. FF_FS_TIMEOUT have no effect.
|
|
||||||
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
|
||||||
/ ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give()
|
|
||||||
/ function, must be added to the project. Samples are available in ffsystem.c.
|
|
||||||
/
|
|
||||||
/ The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*--- End of configuration options ---*/
|
|
||||||
@ -1,208 +0,0 @@
|
|||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* A Sample Code of User Provided OS Dependent Functions for FatFs */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#include "ff.h"
|
|
||||||
|
|
||||||
|
|
||||||
#if FF_USE_LFN == 3 /* Use dynamic memory allocation */
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* Allocate/Free a Memory Block */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#include <stdlib.h> /* with POSIX API */
|
|
||||||
|
|
||||||
|
|
||||||
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
|
|
||||||
UINT msize /* Number of bytes to allocate */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return malloc((size_t)msize); /* Allocate a new memory block */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ff_memfree (
|
|
||||||
void* mblock /* Pointer to the memory block to free (no effect if null) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
free(mblock); /* Free the memory block */
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if FF_FS_REENTRANT /* Mutal exclusion */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* Definitions of Mutex */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#define OS_TYPE 0 /* 0:Win32, 1:uITRON4.0, 2:uC/OS-II, 3:FreeRTOS, 4:CMSIS-RTOS */
|
|
||||||
|
|
||||||
|
|
||||||
#if OS_TYPE == 0 /* Win32 */
|
|
||||||
#include <windows.h>
|
|
||||||
static HANDLE Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
|
|
||||||
|
|
||||||
#elif OS_TYPE == 1 /* uITRON */
|
|
||||||
#include "itron.h"
|
|
||||||
#include "kernel.h"
|
|
||||||
static mtxid Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
|
|
||||||
|
|
||||||
#elif OS_TYPE == 2 /* uc/OS-II */
|
|
||||||
#include "includes.h"
|
|
||||||
static OS_EVENT *Mutex[FF_VOLUMES + 1]; /* Table of mutex pinter */
|
|
||||||
|
|
||||||
#elif OS_TYPE == 3 /* FreeRTOS */
|
|
||||||
#include "FreeRTOS.h"
|
|
||||||
#include "semphr.h"
|
|
||||||
static SemaphoreHandle_t Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
|
|
||||||
|
|
||||||
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
static osMutexId Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* Create a Mutex */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* This function is called in f_mount function to create a new mutex
|
|
||||||
/ or semaphore for the volume. When a 0 is returned, the f_mount function
|
|
||||||
/ fails with FR_INT_ERR.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */
|
|
||||||
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
#if OS_TYPE == 0 /* Win32 */
|
|
||||||
Mutex[vol] = CreateMutex(NULL, FALSE, NULL);
|
|
||||||
return (int)(Mutex[vol] != INVALID_HANDLE_VALUE);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 1 /* uITRON */
|
|
||||||
T_CMTX cmtx = {TA_TPRI,1};
|
|
||||||
|
|
||||||
Mutex[vol] = acre_mtx(&cmtx);
|
|
||||||
return (int)(Mutex[vol] > 0);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 2 /* uC/OS-II */
|
|
||||||
OS_ERR err;
|
|
||||||
|
|
||||||
Mutex[vol] = OSMutexCreate(0, &err);
|
|
||||||
return (int)(err == OS_NO_ERR);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 3 /* FreeRTOS */
|
|
||||||
Mutex[vol] = xSemaphoreCreateMutex();
|
|
||||||
return (int)(Mutex[vol] != NULL);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
|
||||||
osMutexDef(cmsis_os_mutex);
|
|
||||||
|
|
||||||
Mutex[vol] = osMutexCreate(osMutex(cmsis_os_mutex));
|
|
||||||
return (int)(Mutex[vol] != NULL);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* Delete a Mutex */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* This function is called in f_mount function to delete a mutex or
|
|
||||||
/ semaphore of the volume created with ff_mutex_create function.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */
|
|
||||||
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
#if OS_TYPE == 0 /* Win32 */
|
|
||||||
CloseHandle(Mutex[vol]);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 1 /* uITRON */
|
|
||||||
del_mtx(Mutex[vol]);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 2 /* uC/OS-II */
|
|
||||||
OS_ERR err;
|
|
||||||
|
|
||||||
OSMutexDel(Mutex[vol], OS_DEL_ALWAYS, &err);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 3 /* FreeRTOS */
|
|
||||||
vSemaphoreDelete(Mutex[vol]);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
|
||||||
osMutexDelete(Mutex[vol]);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* Request a Grant to Access the Volume */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* This function is called on enter file functions to lock the volume.
|
|
||||||
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */
|
|
||||||
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
#if OS_TYPE == 0 /* Win32 */
|
|
||||||
return (int)(WaitForSingleObject(Mutex[vol], FF_FS_TIMEOUT) == WAIT_OBJECT_0);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 1 /* uITRON */
|
|
||||||
return (int)(tloc_mtx(Mutex[vol], FF_FS_TIMEOUT) == E_OK);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 2 /* uC/OS-II */
|
|
||||||
OS_ERR err;
|
|
||||||
|
|
||||||
OSMutexPend(Mutex[vol], FF_FS_TIMEOUT, &err));
|
|
||||||
return (int)(err == OS_NO_ERR);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 3 /* FreeRTOS */
|
|
||||||
return (int)(xSemaphoreTake(Mutex[vol], FF_FS_TIMEOUT) == pdTRUE);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
|
||||||
return (int)(osMutexWait(Mutex[vol], FF_FS_TIMEOUT) == osOK);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* Release a Grant to Access the Volume */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* This function is called on leave file functions to unlock the volume.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ff_mutex_give (
|
|
||||||
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
#if OS_TYPE == 0 /* Win32 */
|
|
||||||
ReleaseMutex(Mutex[vol]);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 1 /* uITRON */
|
|
||||||
unl_mtx(Mutex[vol]);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 2 /* uC/OS-II */
|
|
||||||
OSMutexPost(Mutex[vol]);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 3 /* FreeRTOS */
|
|
||||||
xSemaphoreGive(Mutex[vol]);
|
|
||||||
|
|
||||||
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
|
||||||
osMutexRelease(Mutex[vol]);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* FF_FS_REENTRANT */
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
529
arm9/source/fs.c
529
arm9/source/fs.c
@ -1,529 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2021 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "fs.h"
|
|
||||||
#include "memory.h"
|
|
||||||
#include "fmt.h"
|
|
||||||
#include "crypto.h"
|
|
||||||
#include "cache.h"
|
|
||||||
#include "screen.h"
|
|
||||||
#include "draw.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "fatfs/ff.h"
|
|
||||||
#include "buttons.h"
|
|
||||||
#include "firm.h"
|
|
||||||
#include "crypto.h"
|
|
||||||
#include "strings.h"
|
|
||||||
#include "alignedseqmemcpy.h"
|
|
||||||
#include "i2c.h"
|
|
||||||
|
|
||||||
static FATFS sdFs,
|
|
||||||
nandFs;
|
|
||||||
|
|
||||||
static bool switchToMainDir(bool isSd)
|
|
||||||
{
|
|
||||||
const char *mainDir = isSd ? "/luma" : "/rw/luma";
|
|
||||||
|
|
||||||
switch(f_chdir(mainDir))
|
|
||||||
{
|
|
||||||
case FR_OK:
|
|
||||||
return true;
|
|
||||||
case FR_NO_PATH:
|
|
||||||
{
|
|
||||||
if (f_mkdir(mainDir) != FR_OK)
|
|
||||||
{
|
|
||||||
error("Failed to create luma directory.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return switchToMainDir(isSd);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool mountSdCardPartition(bool switchMainDir)
|
|
||||||
{
|
|
||||||
static bool sdInitialized = false;
|
|
||||||
if (!sdInitialized)
|
|
||||||
sdInitialized = f_mount(&sdFs, "sdmc:", 1) == FR_OK;
|
|
||||||
|
|
||||||
if (sdInitialized && switchMainDir)
|
|
||||||
return f_chdrive("sdmc:") == FR_OK && switchToMainDir(true);
|
|
||||||
return sdInitialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool remountCtrNandPartition(bool switchMainDir)
|
|
||||||
{
|
|
||||||
static bool nandInitialized = false;
|
|
||||||
int res = FR_OK;
|
|
||||||
|
|
||||||
if (!nandInitialized)
|
|
||||||
{
|
|
||||||
res = f_mount(&nandFs, "nand:", 1);
|
|
||||||
nandInitialized = res == FR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nandInitialized && switchMainDir)
|
|
||||||
return f_chdrive("nand:") == FR_OK && switchToMainDir(false);
|
|
||||||
return nandInitialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
void unmountPartitions(void)
|
|
||||||
{
|
|
||||||
f_unmount("nand:");
|
|
||||||
f_unmount("sdmc:");
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 fileRead(void *dest, const char *path, u32 maxSize)
|
|
||||||
{
|
|
||||||
FIL file;
|
|
||||||
FRESULT result = FR_OK;
|
|
||||||
u32 ret = 0;
|
|
||||||
|
|
||||||
if(f_open(&file, path, FA_READ) != FR_OK) return ret;
|
|
||||||
|
|
||||||
u32 size = f_size(&file);
|
|
||||||
if(dest == NULL) ret = size;
|
|
||||||
else if(size <= maxSize)
|
|
||||||
result = f_read(&file, dest, size, (unsigned int *)&ret);
|
|
||||||
result |= f_close(&file);
|
|
||||||
|
|
||||||
return result == FR_OK ? ret : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 getFileSize(const char *path)
|
|
||||||
{
|
|
||||||
return fileRead(NULL, path, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fileWrite(const void *buffer, const char *path, u32 size)
|
|
||||||
{
|
|
||||||
FIL file;
|
|
||||||
FRESULT result = FR_OK;
|
|
||||||
|
|
||||||
switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS))
|
|
||||||
{
|
|
||||||
case FR_OK:
|
|
||||||
{
|
|
||||||
unsigned int written;
|
|
||||||
result = f_write(&file, buffer, size, &written);
|
|
||||||
if(result == FR_OK) result = f_truncate(&file);
|
|
||||||
result |= f_close(&file);
|
|
||||||
|
|
||||||
return result == FR_OK && (u32)written == size;
|
|
||||||
}
|
|
||||||
case FR_NO_PATH:
|
|
||||||
// Only create the last dir in the hierarchy
|
|
||||||
for(u32 i = 1; path[i] != 0; i++)
|
|
||||||
if(path[i] == '/')
|
|
||||||
{
|
|
||||||
char folder[i + 1];
|
|
||||||
memcpy(folder, path, i);
|
|
||||||
folder[i] = 0;
|
|
||||||
result = f_mkdir(folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result == FR_OK && fileWrite(buffer, path, size);
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fileDelete(const char *path)
|
|
||||||
{
|
|
||||||
return f_unlink(path) == FR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fileCopy(const char *pathSrc, const char *pathDst, bool replace, void *tmpBuffer, size_t bufferSize)
|
|
||||||
{
|
|
||||||
FIL fileSrc, fileDst;
|
|
||||||
FRESULT res;
|
|
||||||
|
|
||||||
res = f_open(&fileSrc, pathSrc, FA_READ);
|
|
||||||
if (res != FR_OK)
|
|
||||||
return true; // Succeed if the source file doesn't exist
|
|
||||||
|
|
||||||
size_t szSrc = f_size(&fileSrc), rem = szSrc;
|
|
||||||
|
|
||||||
res = f_open(&fileDst, pathDst, FA_WRITE | (replace ? FA_CREATE_ALWAYS : FA_CREATE_NEW));
|
|
||||||
|
|
||||||
if (res == FR_EXIST)
|
|
||||||
{
|
|
||||||
// We did not fail
|
|
||||||
f_close(&fileSrc);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (res == FR_NO_PATH)
|
|
||||||
{
|
|
||||||
// Only create the last dir in the hierarchy
|
|
||||||
const char *c;
|
|
||||||
for (c = pathDst + strlen(pathDst); *c != '/' && c >= pathDst; --c);
|
|
||||||
if (c >= pathDst && c - pathDst <= FF_MAX_LFN && *c != '\0')
|
|
||||||
{
|
|
||||||
char path[FF_MAX_LFN + 1];
|
|
||||||
strncpy(path, pathDst, c - pathDst);
|
|
||||||
path[c - pathDst] = '\0';
|
|
||||||
res = f_mkdir(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == FR_OK)
|
|
||||||
res = f_open(&fileDst, pathDst, FA_WRITE | (replace ? FA_CREATE_ALWAYS : FA_CREATE_NEW));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res != FR_OK)
|
|
||||||
{
|
|
||||||
f_close(&fileSrc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (rem > 0)
|
|
||||||
{
|
|
||||||
size_t sz = rem >= bufferSize ? bufferSize : rem;
|
|
||||||
UINT n = 0;
|
|
||||||
|
|
||||||
res = f_read(&fileSrc, tmpBuffer, sz, &n);
|
|
||||||
if (n != sz)
|
|
||||||
res = FR_INT_ERR; // should not happen
|
|
||||||
|
|
||||||
if (res == FR_OK)
|
|
||||||
{
|
|
||||||
res = f_write(&fileDst, tmpBuffer, sz, &n);
|
|
||||||
if (n != sz)
|
|
||||||
res = FR_DENIED; // disk full
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res != FR_OK)
|
|
||||||
{
|
|
||||||
f_close(&fileSrc);
|
|
||||||
f_close(&fileDst);
|
|
||||||
f_unlink(pathDst); // oops, failed
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
rem -= sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
f_close(&fileSrc);
|
|
||||||
f_close(&fileDst);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool createDir(const char *path)
|
|
||||||
{
|
|
||||||
FRESULT res = f_mkdir(path);
|
|
||||||
return res == FR_OK || res == FR_EXIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool findPayload(char *path, u32 pressed)
|
|
||||||
{
|
|
||||||
const char *pattern;
|
|
||||||
|
|
||||||
if(pressed & BUTTON_LEFT) pattern = PATTERN("left");
|
|
||||||
else if(pressed & BUTTON_RIGHT) pattern = PATTERN("right");
|
|
||||||
else if(pressed & BUTTON_UP) pattern = PATTERN("up");
|
|
||||||
else if(pressed & BUTTON_DOWN) pattern = PATTERN("down");
|
|
||||||
else if(pressed & BUTTON_START) pattern = PATTERN("start");
|
|
||||||
else if(pressed & BUTTON_B) pattern = PATTERN("b");
|
|
||||||
else if(pressed & BUTTON_X) pattern = PATTERN("x");
|
|
||||||
else if(pressed & BUTTON_Y) pattern = PATTERN("y");
|
|
||||||
else if(pressed & BUTTON_R1) pattern = PATTERN("r");
|
|
||||||
else if(pressed & BUTTON_A) pattern = PATTERN("a");
|
|
||||||
else pattern = PATTERN("select");
|
|
||||||
|
|
||||||
DIR dir;
|
|
||||||
FILINFO info;
|
|
||||||
FRESULT result;
|
|
||||||
|
|
||||||
result = f_findfirst(&dir, &info, "payloads", pattern);
|
|
||||||
|
|
||||||
if(result != FR_OK) return false;
|
|
||||||
|
|
||||||
f_closedir(&dir);
|
|
||||||
|
|
||||||
if(!info.fname[0]) return false;
|
|
||||||
|
|
||||||
sprintf(path, "payloads/%s", info.fname);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool payloadMenu(char *path, bool *hasDisplayedMenu)
|
|
||||||
{
|
|
||||||
DIR dir;
|
|
||||||
|
|
||||||
*hasDisplayedMenu = false;
|
|
||||||
if(f_opendir(&dir, "payloads") != FR_OK) return false;
|
|
||||||
|
|
||||||
FILINFO info;
|
|
||||||
u32 payloadNum = 0;
|
|
||||||
char payloadList[20][49];
|
|
||||||
|
|
||||||
while(f_readdir(&dir, &info) == FR_OK && info.fname[0] != 0 && payloadNum < 20)
|
|
||||||
{
|
|
||||||
if(info.fname[0] == '.') continue;
|
|
||||||
|
|
||||||
u32 nameLength = strlen(info.fname);
|
|
||||||
|
|
||||||
if(nameLength < 6 || nameLength > 52) continue;
|
|
||||||
|
|
||||||
nameLength -= 5;
|
|
||||||
|
|
||||||
if(memcmp(info.fname + nameLength, ".firm", 5) != 0) continue;
|
|
||||||
|
|
||||||
memcpy(payloadList[payloadNum], info.fname, nameLength);
|
|
||||||
payloadList[payloadNum][nameLength] = 0;
|
|
||||||
payloadNum++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(f_closedir(&dir) != FR_OK || !payloadNum) return false;
|
|
||||||
|
|
||||||
u32 pressed = 0,
|
|
||||||
selectedPayload = 0;
|
|
||||||
|
|
||||||
if(payloadNum != 1)
|
|
||||||
{
|
|
||||||
initScreens();
|
|
||||||
*hasDisplayedMenu = true;
|
|
||||||
|
|
||||||
drawString(true, 10, 10, COLOR_TITLE, "Luma3DS chainloader");
|
|
||||||
drawString(true, 10, 10 + SPACING_Y, COLOR_TITLE, "Press A to select, START to quit");
|
|
||||||
|
|
||||||
for(u32 i = 0, posY = 10 + 3 * SPACING_Y, color = COLOR_RED; i < payloadNum; i++, posY += SPACING_Y)
|
|
||||||
{
|
|
||||||
drawString(true, 10, posY, color, payloadList[i]);
|
|
||||||
if(color == COLOR_RED) color = COLOR_WHITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(pressed != BUTTON_A && pressed != BUTTON_START)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
pressed = waitInput(true) & MENU_BUTTONS;
|
|
||||||
}
|
|
||||||
while(!pressed);
|
|
||||||
|
|
||||||
u32 oldSelectedPayload = selectedPayload;
|
|
||||||
|
|
||||||
switch(pressed)
|
|
||||||
{
|
|
||||||
case BUTTON_UP:
|
|
||||||
selectedPayload = !selectedPayload ? payloadNum - 1 : selectedPayload - 1;
|
|
||||||
break;
|
|
||||||
case BUTTON_DOWN:
|
|
||||||
selectedPayload = selectedPayload == payloadNum - 1 ? 0 : selectedPayload + 1;
|
|
||||||
break;
|
|
||||||
case BUTTON_LEFT:
|
|
||||||
selectedPayload = 0;
|
|
||||||
break;
|
|
||||||
case BUTTON_RIGHT:
|
|
||||||
selectedPayload = payloadNum - 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(oldSelectedPayload == selectedPayload) continue;
|
|
||||||
|
|
||||||
drawString(true, 10, 10 + (3 + oldSelectedPayload) * SPACING_Y, COLOR_WHITE, payloadList[oldSelectedPayload]);
|
|
||||||
drawString(true, 10, 10 + (3 + selectedPayload) * SPACING_Y, COLOR_RED, payloadList[selectedPayload]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pressed != BUTTON_START)
|
|
||||||
{
|
|
||||||
sprintf(path, "payloads/%s.firm", payloadList[selectedPayload]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(HID_PAD & MENU_BUTTONS);
|
|
||||||
wait(2000ULL);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 firmRead(void *dest, u32 firmType)
|
|
||||||
{
|
|
||||||
static const char *firmFolders[][2] = {{"00000002", "20000002"},
|
|
||||||
{"00000102", "20000102"},
|
|
||||||
{"00000202", "20000202"},
|
|
||||||
{"00000003", "20000003"},
|
|
||||||
{"00000001", "20000001"}};
|
|
||||||
|
|
||||||
char folderPath[64],
|
|
||||||
path[128];
|
|
||||||
|
|
||||||
sprintf(folderPath, "nand:/title/00040138/%s/content", firmFolders[firmType][ISN3DS ? 1 : 0]);
|
|
||||||
|
|
||||||
DIR dir;
|
|
||||||
u32 firmVersion = 0xFFFFFFFF;
|
|
||||||
|
|
||||||
if(f_opendir(&dir, folderPath) != FR_OK) goto exit;
|
|
||||||
|
|
||||||
FILINFO info;
|
|
||||||
|
|
||||||
//Parse the target directory
|
|
||||||
while(f_readdir(&dir, &info) == FR_OK && info.fname[0] != 0)
|
|
||||||
{
|
|
||||||
//Not a cxi
|
|
||||||
if(info.fname[9] != 'a' || strlen(info.fname) != 12) continue;
|
|
||||||
|
|
||||||
u32 tempVersion = hexAtoi(info.altname, 8);
|
|
||||||
|
|
||||||
//Found an older cxi
|
|
||||||
if(tempVersion < firmVersion) firmVersion = tempVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(f_closedir(&dir) != FR_OK || firmVersion == 0xFFFFFFFF) goto exit;
|
|
||||||
|
|
||||||
//Complete the string with the .app name
|
|
||||||
sprintf(path, "%s/%08lx.app", folderPath, firmVersion);
|
|
||||||
|
|
||||||
if(fileRead(dest, path, 0x400000 + sizeof(Cxi) + 0x200) <= sizeof(Cxi) + 0x400) firmVersion = 0xFFFFFFFF;
|
|
||||||
|
|
||||||
exit:
|
|
||||||
return firmVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
void findDumpFile(const char *folderPath, char *fileName)
|
|
||||||
{
|
|
||||||
DIR dir;
|
|
||||||
FRESULT result;
|
|
||||||
|
|
||||||
for(u32 n = 0; n <= 99999999; n++)
|
|
||||||
{
|
|
||||||
FILINFO info;
|
|
||||||
|
|
||||||
sprintf(fileName, "crash_dump_%08lu.dmp", n);
|
|
||||||
result = f_findfirst(&dir, &info, folderPath, fileName);
|
|
||||||
|
|
||||||
if(result != FR_OK || !info.fname[0]) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result == FR_OK) f_closedir(&dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
static u8 fileCopyBuffer[0x10000];
|
|
||||||
|
|
||||||
static const u8 boot9Sha256[32] = {
|
|
||||||
0x2F, 0x88, 0x74, 0x4F, 0xEE, 0xD7, 0x17, 0x85, 0x63, 0x86, 0x40, 0x0A, 0x44, 0xBB, 0xA4, 0xB9,
|
|
||||||
0xCA, 0x62, 0xE7, 0x6A, 0x32, 0xC7, 0x15, 0xD4, 0xF3, 0x09, 0xC3, 0x99, 0xBF, 0x28, 0x16, 0x6F
|
|
||||||
};
|
|
||||||
|
|
||||||
static const u8 boot11Sha256[32] = {
|
|
||||||
0x74, 0xDA, 0xAC, 0xE1, 0xF8, 0x06, 0x7B, 0x66, 0xCC, 0x81, 0xFC, 0x30, 0x7A, 0x3F, 0xDB, 0x50,
|
|
||||||
0x9C, 0xBE, 0xDC, 0x32, 0xF9, 0x03, 0xAE, 0xBE, 0x90, 0x61, 0x44, 0xDE, 0xA7, 0xA0, 0x75, 0x12
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool backupEssentialFiles(void)
|
|
||||||
{
|
|
||||||
size_t sz = sizeof(fileCopyBuffer);
|
|
||||||
|
|
||||||
u32 deviceID = *(vu32*)0x01FFB804;
|
|
||||||
char pathStart[0x20];
|
|
||||||
sprintf(pathStart, "backups/%08lX/", deviceID);
|
|
||||||
char fullPath[0x80];
|
|
||||||
|
|
||||||
// Since the other funcs in this file don't create directories recursively (only the last one),
|
|
||||||
// and nor does f_mkdir, create the directories anyway and ignore the result
|
|
||||||
f_mkdir("backups");
|
|
||||||
f_mkdir(pathStart);
|
|
||||||
|
|
||||||
bool ok = true;
|
|
||||||
sprintf(fullPath, "%sHWCAL0.dat", pathStart);
|
|
||||||
ok = ok && fileCopy("nand:/ro/sys/HWCAL0.dat", fullPath, false, fileCopyBuffer, sz);
|
|
||||||
sprintf(fullPath, "%sHWCAL1.dat", pathStart);
|
|
||||||
ok = ok && fileCopy("nand:/ro/sys/HWCAL1.dat", fullPath, false, fileCopyBuffer, sz);
|
|
||||||
|
|
||||||
sprintf(fullPath, "%sLocalFriendCodeSeed_A", pathStart);
|
|
||||||
ok = ok && fileCopy("nand:/rw/sys/LocalFriendCodeSeed_A", fullPath, false, fileCopyBuffer, sz); // often doesn't exist
|
|
||||||
sprintf(fullPath, "%sLocalFriendCodeSeed_B", pathStart);
|
|
||||||
ok = ok && fileCopy("nand:/rw/sys/LocalFriendCodeSeed_B", fullPath, false, fileCopyBuffer, sz);
|
|
||||||
|
|
||||||
sprintf(fullPath, "%sSecureInfo_A", pathStart);
|
|
||||||
ok = ok && fileCopy("nand:/rw/sys/SecureInfo_A", fullPath, false, fileCopyBuffer, sz);
|
|
||||||
sprintf(fullPath, "%sSecureInfo_B", pathStart);
|
|
||||||
ok = ok && fileCopy("nand:/rw/sys/SecureInfo_B", fullPath, false, fileCopyBuffer, sz); // often doesn't exist
|
|
||||||
|
|
||||||
if (!ok) return false;
|
|
||||||
|
|
||||||
alignedseqmemcpy(fileCopyBuffer, (const void *)0x10012000, 0x100);
|
|
||||||
sprintf(fullPath, "%sotp.bin", pathStart);
|
|
||||||
if (getFileSize(fullPath) != 0x100)
|
|
||||||
ok = ok && fileWrite(fileCopyBuffer, fullPath, 0x100);
|
|
||||||
|
|
||||||
if (!ok) return false;
|
|
||||||
|
|
||||||
// On dev boards, but not O3DS IS_DEBUGGER, hwcal is on an EEPROM chip accessed via I2C
|
|
||||||
u8 c = mcuConsoleInfo[0];
|
|
||||||
if (c == 2 || c == 4 || (ISN3DS && c == 5) || c == 6)
|
|
||||||
{
|
|
||||||
sprintf(fullPath, "%sHWCAL_01_EEPROM.dat", pathStart);
|
|
||||||
I2C_readRegBuf(I2C_DEV_EEPROM, 0, fileCopyBuffer, 0x1000); // Up to two instances of hwcal, with the second one @0x800
|
|
||||||
if (getFileSize(fullPath) != 0x1000)
|
|
||||||
ok = ok && fileWrite(fileCopyBuffer, fullPath, 0x1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// B9S bootrom backups
|
|
||||||
u32 hash[32/4];
|
|
||||||
sha(hash, (const void *)0x08080000, 0x10000, SHA_256_MODE);
|
|
||||||
sprintf(fullPath, "%sboot9.bin", pathStart);
|
|
||||||
if (memcmp(hash, boot9Sha256, 32) == 0 && getFileSize(fullPath) != 0x10000)
|
|
||||||
ok = ok && fileWrite((const void *)0x08080000, fullPath, 0x10000);
|
|
||||||
sha(hash, (const void *)0x08090000, 0x10000, SHA_256_MODE);
|
|
||||||
sprintf(fullPath, "%sboot11.bin", pathStart);
|
|
||||||
if (memcmp(hash, boot11Sha256, 32) == 0 && getFileSize(fullPath) != 0x10000)
|
|
||||||
ok = ok && fileWrite((const void *)0x08090000, fullPath, 0x10000);
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool doLumaUpgradeProcess(void)
|
|
||||||
{
|
|
||||||
bool ok = true, ok2 = true;
|
|
||||||
|
|
||||||
// Ensure CTRNAND is mounted
|
|
||||||
remountCtrNandPartition(false);
|
|
||||||
|
|
||||||
// Try to boot.firm to CTRNAND, when applicable
|
|
||||||
#ifndef BUILD_FOR_EXPLOIT_DEV
|
|
||||||
if (isSdMode && memcmp(launchedPathForFatfs, "sdmc:", 5) == 0)
|
|
||||||
ok = fileCopy(launchedPathForFatfs, "nand:/boot.firm", true, fileCopyBuffer, sizeof(fileCopyBuffer));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Try to backup essential files
|
|
||||||
ok2 = backupEssentialFiles();
|
|
||||||
|
|
||||||
// Clean up some of the old files
|
|
||||||
fileDelete("sdmc:/luma/config.bin");
|
|
||||||
fileDelete("nand:/rw/luma/config.bin");
|
|
||||||
|
|
||||||
createDir("sdmc:/luma/payloads");
|
|
||||||
createDir("nand:/rw/luma/payloads");
|
|
||||||
|
|
||||||
return ok && ok2;
|
|
||||||
}
|
|
||||||
@ -1,225 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of fastboot 3DS
|
|
||||||
* Copyright (C) 2017 derrek, profi200
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "types.h"
|
|
||||||
#include "i2c.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#define I2C1_REGS_BASE (0x10161000)
|
|
||||||
|
|
||||||
#define I2C2_REGS_BASE (0x10144000)
|
|
||||||
|
|
||||||
#define I2C3_REGS_BASE (0x10148000)
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
vu8 REG_I2C_DATA;
|
|
||||||
vu8 REG_I2C_CNT;
|
|
||||||
vu16 REG_I2C_CNTEX;
|
|
||||||
vu16 REG_I2C_SCL;
|
|
||||||
} I2cRegs;
|
|
||||||
|
|
||||||
static const struct
|
|
||||||
{
|
|
||||||
u8 busId;
|
|
||||||
u8 devAddr;
|
|
||||||
} i2cDevTable[] =
|
|
||||||
{
|
|
||||||
{0, 0x4A},
|
|
||||||
{0, 0x7A},
|
|
||||||
{0, 0x78},
|
|
||||||
{1, 0x4A},
|
|
||||||
{1, 0x78},
|
|
||||||
{1, 0x2C},
|
|
||||||
{1, 0x2E},
|
|
||||||
{1, 0x40},
|
|
||||||
{1, 0x44},
|
|
||||||
{2, 0xA6}, // TODO: Find out if 0xA6 or 0xD6 is correct
|
|
||||||
{2, 0xD0},
|
|
||||||
{2, 0xD2},
|
|
||||||
{2, 0xA4},
|
|
||||||
{2, 0x9A},
|
|
||||||
{2, 0xA0},
|
|
||||||
{1, 0xEE},
|
|
||||||
{0, 0x40},
|
|
||||||
{2, 0x54}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void i2cWaitBusy(I2cRegs *const regs)
|
|
||||||
{
|
|
||||||
while(regs->REG_I2C_CNT & I2C_ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static I2cRegs* i2cGetBusRegsBase(u8 busId)
|
|
||||||
{
|
|
||||||
I2cRegs *base;
|
|
||||||
switch(busId)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
base = (I2cRegs*)I2C1_REGS_BASE;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
base = (I2cRegs*)I2C2_REGS_BASE;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
base = (I2cRegs*)I2C3_REGS_BASE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
base = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
|
|
||||||
void I2C_init(void)
|
|
||||||
{
|
|
||||||
I2cRegs *regs = i2cGetBusRegsBase(0); // Bus 1
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
regs->REG_I2C_CNTEX = 2; // ?
|
|
||||||
regs->REG_I2C_SCL = 1280; // ?
|
|
||||||
|
|
||||||
regs = i2cGetBusRegsBase(1); // Bus 2
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
regs->REG_I2C_CNTEX = 2; // ?
|
|
||||||
regs->REG_I2C_SCL = 1280; // ?
|
|
||||||
|
|
||||||
regs = i2cGetBusRegsBase(2); // Bus 3
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
regs->REG_I2C_CNTEX = 2; // ?
|
|
||||||
regs->REG_I2C_SCL = 1280; // ?
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool i2cStartTransfer(I2cDevice devId, u8 regAddr, bool read, I2cRegs *const regs)
|
|
||||||
{
|
|
||||||
const u8 devAddr = i2cDevTable[devId].devAddr;
|
|
||||||
|
|
||||||
|
|
||||||
u32 i = 0;
|
|
||||||
for(; i < 8; i++)
|
|
||||||
{
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
|
|
||||||
// Select device and start.
|
|
||||||
regs->REG_I2C_DATA = devAddr;
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_START;
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
|
||||||
{
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select register and change direction to write.
|
|
||||||
regs->REG_I2C_DATA = regAddr;
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
|
||||||
{
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select device in read mode for read transfer.
|
|
||||||
if(read)
|
|
||||||
{
|
|
||||||
regs->REG_I2C_DATA = devAddr | 1u; // Set bit 0 for read.
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_START;
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
|
||||||
{
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i < 8) return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size)
|
|
||||||
{
|
|
||||||
const u8 busId = i2cDevTable[devId].busId;
|
|
||||||
I2cRegs *const regs = i2cGetBusRegsBase(busId);
|
|
||||||
|
|
||||||
|
|
||||||
if(!i2cStartTransfer(devId, regAddr, true, regs)) return false;
|
|
||||||
|
|
||||||
while(--size)
|
|
||||||
{
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_ACK;
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
*out++ = regs->REG_I2C_DATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_STOP;
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
*out = regs->REG_I2C_DATA; // Last byte
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const u8 *in, u32 size)
|
|
||||||
{
|
|
||||||
const u8 busId = i2cDevTable[devId].busId;
|
|
||||||
I2cRegs *const regs = i2cGetBusRegsBase(busId);
|
|
||||||
|
|
||||||
|
|
||||||
if(!i2cStartTransfer(devId, regAddr, false, regs)) return false;
|
|
||||||
|
|
||||||
while(--size)
|
|
||||||
{
|
|
||||||
regs->REG_I2C_DATA = *in++;
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
|
||||||
{
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
regs->REG_I2C_DATA = *in;
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE | I2C_STOP;
|
|
||||||
i2cWaitBusy(regs);
|
|
||||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
|
||||||
{
|
|
||||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 I2C_readReg(I2cDevice devId, u8 regAddr)
|
|
||||||
{
|
|
||||||
u8 data;
|
|
||||||
if(!I2C_readRegBuf(devId, regAddr, &data, 1)) return 0xFF;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool I2C_writeReg(I2cDevice devId, u8 regAddr, u8 data)
|
|
||||||
{
|
|
||||||
return I2C_writeRegBuf(devId, regAddr, &data, 1);
|
|
||||||
}
|
|
||||||
@ -1,104 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of fastboot 3DS
|
|
||||||
* Copyright (C) 2017 derrek, profi200
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define I2C_STOP (1u)
|
|
||||||
#define I2C_START (1u<<1)
|
|
||||||
#define I2C_ERROR (1u<<2)
|
|
||||||
#define I2C_ACK (1u<<4)
|
|
||||||
#define I2C_DIRE_WRITE (0u)
|
|
||||||
#define I2C_DIRE_READ (1u<<5)
|
|
||||||
#define I2C_IRQ_ENABLE (1u<<6)
|
|
||||||
#define I2C_ENABLE (1u<<7)
|
|
||||||
|
|
||||||
#define I2C_GET_ACK(reg) ((bool)((reg)>>4 & 1u))
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
I2C_DEV_POWER = 0, // Unconfirmed
|
|
||||||
I2C_DEV_CAMERA = 1, // Unconfirmed
|
|
||||||
I2C_DEV_CAMERA2 = 2, // Unconfirmed
|
|
||||||
I2C_DEV_MCU = 3,
|
|
||||||
I2C_DEV_LCD_TOP = 5,
|
|
||||||
I2C_DEV_LCD_BOT = 6,
|
|
||||||
I2C_DEV_GYRO = 10,
|
|
||||||
I2C_DEV_DEBUG_PAD = 12,
|
|
||||||
I2C_DEV_IR = 13,
|
|
||||||
I2C_DEV_EEPROM = 14, // Unconfirmed
|
|
||||||
I2C_DEV_NFC = 15,
|
|
||||||
I2C_DEV_QTM = 16,
|
|
||||||
I2C_DEV_N3DS_HID = 17
|
|
||||||
} I2cDevice;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initializes the I2C buses. Call this only once.
|
|
||||||
*/
|
|
||||||
void I2C_init(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reads data from a I2C register to a buffer.
|
|
||||||
*
|
|
||||||
* @param[in] devId The device ID. Use the enum above.
|
|
||||||
* @param[in] regAddr The register address.
|
|
||||||
* @param out The output buffer pointer.
|
|
||||||
* @param[in] size The read size.
|
|
||||||
*
|
|
||||||
* @return Returns true on success and false on failure.
|
|
||||||
*/
|
|
||||||
bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Writes a buffer to a I2C register.
|
|
||||||
*
|
|
||||||
* @param[in] devId The device ID. Use the enum above.
|
|
||||||
* @param[in] regAddr The register address.
|
|
||||||
* @param[in] in The input buffer pointer.
|
|
||||||
* @param[in] size The write size.
|
|
||||||
*
|
|
||||||
* @return Returns true on success and false on failure.
|
|
||||||
*/
|
|
||||||
bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const u8 *in, u32 size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reads a byte from a I2C register.
|
|
||||||
*
|
|
||||||
* @param[in] devId The device ID. Use the enum above.
|
|
||||||
* @param[in] regAddr The register address.
|
|
||||||
*
|
|
||||||
* @return Returns the value read on success otherwise 0xFF.
|
|
||||||
*/
|
|
||||||
u8 I2C_readReg(I2cDevice devId, u8 regAddr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Writes a byte to a I2C register.
|
|
||||||
*
|
|
||||||
* @param[in] devId The device ID. Use the enum above.
|
|
||||||
* @param[in] regAddr The register address.
|
|
||||||
* @param[in] data The data to write.
|
|
||||||
*
|
|
||||||
* @return Returns true on success and false on failure.
|
|
||||||
*/
|
|
||||||
bool I2C_writeReg(I2cDevice devId, u8 regAddr, u8 data);
|
|
||||||
@ -1,298 +0,0 @@
|
|||||||
/* inih -- simple .INI file parser
|
|
||||||
|
|
||||||
SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
Copyright (C) 2009-2020, Ben Hoyt
|
|
||||||
|
|
||||||
inih is released under the New BSD license (see LICENSE.txt). Go to the project
|
|
||||||
home page for more info:
|
|
||||||
|
|
||||||
https://github.com/benhoyt/inih
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "ini.h"
|
|
||||||
|
|
||||||
#if !INI_USE_STACK
|
|
||||||
#if INI_CUSTOM_ALLOCATOR
|
|
||||||
#include <stddef.h>
|
|
||||||
void* ini_malloc(size_t size);
|
|
||||||
void ini_free(void* ptr);
|
|
||||||
void* ini_realloc(void* ptr, size_t size);
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#define ini_malloc malloc
|
|
||||||
#define ini_free free
|
|
||||||
#define ini_realloc realloc
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_SECTION 50
|
|
||||||
#define MAX_NAME 50
|
|
||||||
|
|
||||||
/* Used by ini_parse_string() to keep track of string parsing state. */
|
|
||||||
typedef struct {
|
|
||||||
const char* ptr;
|
|
||||||
size_t num_left;
|
|
||||||
} ini_parse_string_ctx;
|
|
||||||
|
|
||||||
/* Strip whitespace chars off end of given string, in place. Return s. */
|
|
||||||
static char* rstrip(char* s)
|
|
||||||
{
|
|
||||||
char* p = s + strlen(s);
|
|
||||||
while (p > s && isspace((unsigned char)(*--p)))
|
|
||||||
*p = '\0';
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return pointer to first non-whitespace char in given string. */
|
|
||||||
static char* lskip(const char* s)
|
|
||||||
{
|
|
||||||
while (*s && isspace((unsigned char)(*s)))
|
|
||||||
s++;
|
|
||||||
return (char*)s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return pointer to first char (of chars) or inline comment in given string,
|
|
||||||
or pointer to NUL at end of string if neither found. Inline comment must
|
|
||||||
be prefixed by a whitespace character to register as a comment. */
|
|
||||||
static char* find_chars_or_comment(const char* s, const char* chars)
|
|
||||||
{
|
|
||||||
#if INI_ALLOW_INLINE_COMMENTS
|
|
||||||
int was_space = 0;
|
|
||||||
while (*s && (!chars || !strchr(chars, *s)) &&
|
|
||||||
!(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
|
|
||||||
was_space = isspace((unsigned char)(*s));
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
while (*s && (!chars || !strchr(chars, *s))) {
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return (char*)s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Similar to strncpy, but ensures dest (size bytes) is
|
|
||||||
NUL-terminated, and doesn't pad with NULs. */
|
|
||||||
static char* strncpy0(char* dest, const char* src, size_t size)
|
|
||||||
{
|
|
||||||
/* Could use strncpy internally, but it causes gcc warnings (see issue #91) */
|
|
||||||
size_t i;
|
|
||||||
for (i = 0; i < size - 1 && src[i]; i++)
|
|
||||||
dest[i] = src[i];
|
|
||||||
dest[i] = '\0';
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See documentation in header file. */
|
|
||||||
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
|
||||||
void* user)
|
|
||||||
{
|
|
||||||
/* Uses a fair bit of stack (use heap instead if you need to) */
|
|
||||||
#if INI_USE_STACK
|
|
||||||
char line[INI_MAX_LINE];
|
|
||||||
int max_line = INI_MAX_LINE;
|
|
||||||
#else
|
|
||||||
char* line;
|
|
||||||
size_t max_line = INI_INITIAL_ALLOC;
|
|
||||||
#endif
|
|
||||||
#if INI_ALLOW_REALLOC && !INI_USE_STACK
|
|
||||||
char* new_line;
|
|
||||||
size_t offset;
|
|
||||||
#endif
|
|
||||||
char section[MAX_SECTION] = "";
|
|
||||||
char prev_name[MAX_NAME] = "";
|
|
||||||
|
|
||||||
char* start;
|
|
||||||
char* end;
|
|
||||||
char* name;
|
|
||||||
char* value;
|
|
||||||
int lineno = 0;
|
|
||||||
int error = 0;
|
|
||||||
|
|
||||||
#if !INI_USE_STACK
|
|
||||||
line = (char*)ini_malloc(INI_INITIAL_ALLOC);
|
|
||||||
if (!line) {
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if INI_HANDLER_LINENO
|
|
||||||
#define HANDLER(u, s, n, v) handler(u, s, n, v, lineno)
|
|
||||||
#else
|
|
||||||
#define HANDLER(u, s, n, v) handler(u, s, n, v)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Scan through stream line by line */
|
|
||||||
while (reader(line, (int)max_line, stream) != NULL) {
|
|
||||||
#if INI_ALLOW_REALLOC && !INI_USE_STACK
|
|
||||||
offset = strlen(line);
|
|
||||||
while (offset == max_line - 1 && line[offset - 1] != '\n') {
|
|
||||||
max_line *= 2;
|
|
||||||
if (max_line > INI_MAX_LINE)
|
|
||||||
max_line = INI_MAX_LINE;
|
|
||||||
new_line = ini_realloc(line, max_line);
|
|
||||||
if (!new_line) {
|
|
||||||
ini_free(line);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
line = new_line;
|
|
||||||
if (reader(line + offset, (int)(max_line - offset), stream) == NULL)
|
|
||||||
break;
|
|
||||||
if (max_line >= INI_MAX_LINE)
|
|
||||||
break;
|
|
||||||
offset += strlen(line + offset);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lineno++;
|
|
||||||
|
|
||||||
start = line;
|
|
||||||
#if INI_ALLOW_BOM
|
|
||||||
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
|
|
||||||
(unsigned char)start[1] == 0xBB &&
|
|
||||||
(unsigned char)start[2] == 0xBF) {
|
|
||||||
start += 3;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
start = lskip(rstrip(start));
|
|
||||||
|
|
||||||
if (strchr(INI_START_COMMENT_PREFIXES, *start)) {
|
|
||||||
/* Start-of-line comment */
|
|
||||||
}
|
|
||||||
#if INI_ALLOW_MULTILINE
|
|
||||||
else if (*prev_name && *start && start > line) {
|
|
||||||
/* Non-blank line with leading whitespace, treat as continuation
|
|
||||||
of previous name's value (as per Python configparser). */
|
|
||||||
if (!HANDLER(user, section, prev_name, start) && !error)
|
|
||||||
error = lineno;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
else if (*start == '[') {
|
|
||||||
/* A "[section]" line */
|
|
||||||
end = find_chars_or_comment(start + 1, "]");
|
|
||||||
if (*end == ']') {
|
|
||||||
*end = '\0';
|
|
||||||
strncpy0(section, start + 1, sizeof(section));
|
|
||||||
*prev_name = '\0';
|
|
||||||
#if INI_CALL_HANDLER_ON_NEW_SECTION
|
|
||||||
if (!HANDLER(user, section, NULL, NULL) && !error)
|
|
||||||
error = lineno;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else if (!error) {
|
|
||||||
/* No ']' found on section line */
|
|
||||||
error = lineno;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (*start) {
|
|
||||||
/* Not a comment, must be a name[=:]value pair */
|
|
||||||
end = find_chars_or_comment(start, "=:");
|
|
||||||
if (*end == '=' || *end == ':') {
|
|
||||||
*end = '\0';
|
|
||||||
name = rstrip(start);
|
|
||||||
value = end + 1;
|
|
||||||
#if INI_ALLOW_INLINE_COMMENTS
|
|
||||||
end = find_chars_or_comment(value, NULL);
|
|
||||||
if (*end)
|
|
||||||
*end = '\0';
|
|
||||||
#endif
|
|
||||||
value = lskip(value);
|
|
||||||
rstrip(value);
|
|
||||||
|
|
||||||
/* Valid name[=:]value pair found, call handler */
|
|
||||||
strncpy0(prev_name, name, sizeof(prev_name));
|
|
||||||
if (!HANDLER(user, section, name, value) && !error)
|
|
||||||
error = lineno;
|
|
||||||
}
|
|
||||||
else if (!error) {
|
|
||||||
/* No '=' or ':' found on name[=:]value line */
|
|
||||||
#if INI_ALLOW_NO_VALUE
|
|
||||||
*end = '\0';
|
|
||||||
name = rstrip(start);
|
|
||||||
if (!HANDLER(user, section, name, NULL) && !error)
|
|
||||||
error = lineno;
|
|
||||||
#else
|
|
||||||
error = lineno;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if INI_STOP_ON_FIRST_ERROR
|
|
||||||
if (error)
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !INI_USE_STACK
|
|
||||||
ini_free(line);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See documentation in header file. */
|
|
||||||
int ini_parse_file(FILE* file, ini_handler handler, void* user)
|
|
||||||
{
|
|
||||||
return ini_parse_stream((ini_reader)fgets, file, handler, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See documentation in header file. */
|
|
||||||
int ini_parse(const char* filename, ini_handler handler, void* user)
|
|
||||||
{
|
|
||||||
FILE* file;
|
|
||||||
int error;
|
|
||||||
|
|
||||||
file = fopen(filename, "r");
|
|
||||||
if (!file)
|
|
||||||
return -1;
|
|
||||||
error = ini_parse_file(file, handler, user);
|
|
||||||
fclose(file);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* An ini_reader function to read the next line from a string buffer. This
|
|
||||||
is the fgets() equivalent used by ini_parse_string(). */
|
|
||||||
static char* ini_reader_string(char* str, int num, void* stream) {
|
|
||||||
ini_parse_string_ctx* ctx = (ini_parse_string_ctx*)stream;
|
|
||||||
const char* ctx_ptr = ctx->ptr;
|
|
||||||
size_t ctx_num_left = ctx->num_left;
|
|
||||||
char* strp = str;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
if (ctx_num_left == 0 || num < 2)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
while (num > 1 && ctx_num_left != 0) {
|
|
||||||
c = *ctx_ptr++;
|
|
||||||
ctx_num_left--;
|
|
||||||
*strp++ = c;
|
|
||||||
if (c == '\n')
|
|
||||||
break;
|
|
||||||
num--;
|
|
||||||
}
|
|
||||||
|
|
||||||
*strp = '\0';
|
|
||||||
ctx->ptr = ctx_ptr;
|
|
||||||
ctx->num_left = ctx_num_left;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See documentation in header file. */
|
|
||||||
int ini_parse_string(const char* string, ini_handler handler, void* user) {
|
|
||||||
ini_parse_string_ctx ctx;
|
|
||||||
|
|
||||||
ctx.ptr = string;
|
|
||||||
ctx.num_left = strlen(string);
|
|
||||||
return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler,
|
|
||||||
user);
|
|
||||||
}
|
|
||||||
@ -1,157 +0,0 @@
|
|||||||
/* inih -- simple .INI file parser
|
|
||||||
|
|
||||||
SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
Copyright (C) 2009-2020, Ben Hoyt
|
|
||||||
|
|
||||||
inih is released under the New BSD license (see LICENSE.txt). Go to the project
|
|
||||||
home page for more info:
|
|
||||||
|
|
||||||
https://github.com/benhoyt/inih
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INI_H
|
|
||||||
#define INI_H
|
|
||||||
|
|
||||||
/* Make this header file easier to include in C++ code */
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
/* Nonzero if ini_handler callback should accept lineno parameter. */
|
|
||||||
#ifndef INI_HANDLER_LINENO
|
|
||||||
#define INI_HANDLER_LINENO 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Typedef for prototype of handler function. */
|
|
||||||
#if INI_HANDLER_LINENO
|
|
||||||
typedef int (*ini_handler)(void* user, const char* section,
|
|
||||||
const char* name, const char* value,
|
|
||||||
int lineno);
|
|
||||||
#else
|
|
||||||
typedef int (*ini_handler)(void* user, const char* section,
|
|
||||||
const char* name, const char* value);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Typedef for prototype of fgets-style reader function. */
|
|
||||||
typedef char* (*ini_reader)(char* str, int num, void* stream);
|
|
||||||
|
|
||||||
/* Parse given INI-style file. May have [section]s, name=value pairs
|
|
||||||
(whitespace stripped), and comments starting with ';' (semicolon). Section
|
|
||||||
is "" if name=value pair parsed before any section heading. name:value
|
|
||||||
pairs are also supported as a concession to Python's configparser.
|
|
||||||
|
|
||||||
For each name=value pair parsed, call handler function with given user
|
|
||||||
pointer as well as section, name, and value (data only valid for duration
|
|
||||||
of handler call). Handler should return nonzero on success, zero on error.
|
|
||||||
|
|
||||||
Returns 0 on success, line number of first error on parse error (doesn't
|
|
||||||
stop on first error), -1 on file open error, or -2 on memory allocation
|
|
||||||
error (only when INI_USE_STACK is zero).
|
|
||||||
*/
|
|
||||||
int ini_parse(const char* filename, ini_handler handler, void* user);
|
|
||||||
|
|
||||||
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
|
|
||||||
close the file when it's finished -- the caller must do that. */
|
|
||||||
int ini_parse_file(FILE* file, ini_handler handler, void* user);
|
|
||||||
|
|
||||||
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
|
|
||||||
filename. Used for implementing custom or string-based I/O (see also
|
|
||||||
ini_parse_string). */
|
|
||||||
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
|
||||||
void* user);
|
|
||||||
|
|
||||||
/* Same as ini_parse(), but takes a zero-terminated string with the INI data
|
|
||||||
instead of a file. Useful for parsing INI data from a network socket or
|
|
||||||
already in memory. */
|
|
||||||
int ini_parse_string(const char* string, ini_handler handler, void* user);
|
|
||||||
|
|
||||||
/* Nonzero to allow multi-line value parsing, in the style of Python's
|
|
||||||
configparser. If allowed, ini_parse() will call the handler with the same
|
|
||||||
name for each subsequent line parsed. */
|
|
||||||
#ifndef INI_ALLOW_MULTILINE
|
|
||||||
#define INI_ALLOW_MULTILINE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
|
|
||||||
the file. See https://github.com/benhoyt/inih/issues/21 */
|
|
||||||
#ifndef INI_ALLOW_BOM
|
|
||||||
#define INI_ALLOW_BOM 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Chars that begin a start-of-line comment. Per Python configparser, allow
|
|
||||||
both ; and # comments at the start of a line by default. */
|
|
||||||
#ifndef INI_START_COMMENT_PREFIXES
|
|
||||||
#define INI_START_COMMENT_PREFIXES ";#"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Nonzero to allow inline comments (with valid inline comment characters
|
|
||||||
specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
|
|
||||||
Python 3.2+ configparser behaviour. */
|
|
||||||
#ifndef INI_ALLOW_INLINE_COMMENTS
|
|
||||||
#define INI_ALLOW_INLINE_COMMENTS 1
|
|
||||||
#endif
|
|
||||||
#ifndef INI_INLINE_COMMENT_PREFIXES
|
|
||||||
#define INI_INLINE_COMMENT_PREFIXES ";"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */
|
|
||||||
#ifndef INI_USE_STACK
|
|
||||||
#define INI_USE_STACK 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Maximum line length for any line in INI file (stack or heap). Note that
|
|
||||||
this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */
|
|
||||||
#ifndef INI_MAX_LINE
|
|
||||||
#define INI_MAX_LINE 200
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Nonzero to allow heap line buffer to grow via realloc(), zero for a
|
|
||||||
fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is
|
|
||||||
zero. */
|
|
||||||
#ifndef INI_ALLOW_REALLOC
|
|
||||||
#define INI_ALLOW_REALLOC 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK
|
|
||||||
is zero. */
|
|
||||||
#ifndef INI_INITIAL_ALLOC
|
|
||||||
#define INI_INITIAL_ALLOC 200
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Stop parsing on first error (default is to keep parsing). */
|
|
||||||
#ifndef INI_STOP_ON_FIRST_ERROR
|
|
||||||
#define INI_STOP_ON_FIRST_ERROR 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Nonzero to call the handler at the start of each new section (with
|
|
||||||
name and value NULL). Default is to only call the handler on
|
|
||||||
each name=value pair. */
|
|
||||||
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
|
|
||||||
#define INI_CALL_HANDLER_ON_NEW_SECTION 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
|
|
||||||
call the handler with value NULL in this case. Default is to treat
|
|
||||||
no-value lines as an error. */
|
|
||||||
#ifndef INI_ALLOW_NO_VALUE
|
|
||||||
#define INI_ALLOW_NO_VALUE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory
|
|
||||||
allocation functions (INI_USE_STACK must also be 0). These functions must
|
|
||||||
have the same signatures as malloc/free/realloc and behave in a similar
|
|
||||||
way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */
|
|
||||||
#ifndef INI_CUSTOM_ALLOCATOR
|
|
||||||
#define INI_CUSTOM_ALLOCATOR 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* INI_H */
|
|
||||||
@ -1,399 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2023 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "emunand.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "firm.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "exceptions.h"
|
|
||||||
#include "draw.h"
|
|
||||||
#include "buttons.h"
|
|
||||||
#include "pin.h"
|
|
||||||
#include "crypto.h"
|
|
||||||
#include "memory.h"
|
|
||||||
#include "deliver_arg.h"
|
|
||||||
#include "screen.h"
|
|
||||||
#include "i2c.h"
|
|
||||||
#include "fmt.h"
|
|
||||||
#include "fatfs/sdmmc/sdmmc.h"
|
|
||||||
|
|
||||||
extern u8 __itcm_start__[], __itcm_lma__[], __itcm_bss_start__[], __itcm_end__[];
|
|
||||||
|
|
||||||
extern CfgData configData;
|
|
||||||
extern ConfigurationStatus needConfig;
|
|
||||||
|
|
||||||
bool isSdMode;
|
|
||||||
char launchedPathForFatfs[256];
|
|
||||||
u16 launchedPath[80+1];
|
|
||||||
BootType bootType;
|
|
||||||
|
|
||||||
u16 mcuFwVersion;
|
|
||||||
u8 mcuConsoleInfo[9];
|
|
||||||
|
|
||||||
void main(int argc, char **argv, u32 magicWord)
|
|
||||||
{
|
|
||||||
bool isFirmProtEnabled = true,
|
|
||||||
isSafeMode = false,
|
|
||||||
needToInitSd = false,
|
|
||||||
isNoForceFlagSet = false,
|
|
||||||
isInvalidLoader = false,
|
|
||||||
isNtrBoot = false;
|
|
||||||
FirmwareType firmType = NATIVE_FIRM;
|
|
||||||
FirmwareSource nandType = FIRMWARE_SYSNAND;
|
|
||||||
u32 emunandIndex = 0;
|
|
||||||
|
|
||||||
const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C;
|
|
||||||
const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010;
|
|
||||||
u32 firmlaunchTidLow = 0;
|
|
||||||
|
|
||||||
//Shell closed, no error booting NTRCARD, NAND paritions not even considered
|
|
||||||
isNtrBoot = bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1];
|
|
||||||
|
|
||||||
if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal (B9S) boot
|
|
||||||
{
|
|
||||||
bootType = isNtrBoot ? B9SNTR : B9S;
|
|
||||||
strncpy(launchedPathForFatfs, argv[0], sizeof(launchedPathForFatfs) - 1);
|
|
||||||
launchedPathForFatfs[sizeof(launchedPathForFatfs) - 1] = 0;
|
|
||||||
|
|
||||||
u32 i;
|
|
||||||
for(i = 0; i < sizeof(launchedPath)/2 - 1 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16
|
|
||||||
launchedPath[i] = argv[0][i];
|
|
||||||
launchedPath[i] = 0;
|
|
||||||
}
|
|
||||||
else if(magicWord == 0xBABE && argc == 2) //Firmlaunch
|
|
||||||
{
|
|
||||||
bootType = FIRMLAUNCH;
|
|
||||||
|
|
||||||
u32 i;
|
|
||||||
u16 *p = (u16 *)argv[0];
|
|
||||||
for(i = 0; i < sizeof(launchedPath)/2 - 1 && p[i] != 0; i++)
|
|
||||||
{
|
|
||||||
launchedPath[i] = p[i];
|
|
||||||
launchedPathForFatfs[i] = (u8)p[i]; // UCS-2 to ascii. Meh.
|
|
||||||
}
|
|
||||||
launchedPath[i] = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < 8; i++)
|
|
||||||
firmlaunchTidLow = (argv[1][2 * i] > '9' ? argv[1][2 * i] - 'a' + 10 : argv[1][2 * i] - '0') | (firmlaunchTidLow << 4);
|
|
||||||
}
|
|
||||||
else if(magicWord == 0xB002) //FIRM/NTRCARD boot
|
|
||||||
{
|
|
||||||
if(isNtrBoot) bootType = NTR;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const char *path;
|
|
||||||
if(!((vu8 *)bootPartitionsStatus)[2])
|
|
||||||
{
|
|
||||||
bootType = FIRM0;
|
|
||||||
path = "firm0:";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bootType = FIRM1;
|
|
||||||
path = "firm1:";
|
|
||||||
}
|
|
||||||
|
|
||||||
for(u32 i = 0; i < 7; i++) //Copy and convert the path to UTF-16
|
|
||||||
launchedPath[i] = path[i];
|
|
||||||
strcpy(launchedPathForFatfs, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
setupKeyslots();
|
|
||||||
}
|
|
||||||
else isInvalidLoader = true;
|
|
||||||
|
|
||||||
// Set up the additional sections, overwrites argc
|
|
||||||
memcpy(__itcm_start__, __itcm_lma__, __itcm_bss_start__ - __itcm_start__);
|
|
||||||
memset(__itcm_bss_start__, 0, __itcm_end__ - __itcm_bss_start__);
|
|
||||||
I2C_init();
|
|
||||||
|
|
||||||
u8 mcuFwVerHi = I2C_readReg(I2C_DEV_MCU, 0) - 0x10;
|
|
||||||
u8 mcuFwVerLo = I2C_readReg(I2C_DEV_MCU, 1);
|
|
||||||
mcuFwVersion = ((u16)mcuFwVerHi << 16) | mcuFwVerLo;
|
|
||||||
|
|
||||||
// Check if fw is older than factory. See https://www.3dbrew.org/wiki/MCU_Services#MCU_firmware_versions for a table
|
|
||||||
if (mcuFwVerHi < 1) error("Unsupported MCU FW version %d.%d.", (int)mcuFwVerHi, (int)mcuFwVerLo);
|
|
||||||
|
|
||||||
I2C_readRegBuf(I2C_DEV_MCU, 0x7F, mcuConsoleInfo, 9);
|
|
||||||
|
|
||||||
if(isInvalidLoader) error("Launched using an unsupported loader.");
|
|
||||||
|
|
||||||
installArm9Handlers();
|
|
||||||
|
|
||||||
if(memcmp(launchedPath, u"sdmc", 8) == 0)
|
|
||||||
{
|
|
||||||
if(!mountSdCardPartition(true)) error("Failed to mount SD.");
|
|
||||||
isSdMode = true;
|
|
||||||
}
|
|
||||||
else if(memcmp(launchedPath, u"nand", 8) == 0)
|
|
||||||
{
|
|
||||||
if(!remountCtrNandPartition(true)) error("Failed to mount CTRNAND.");
|
|
||||||
isSdMode = false;
|
|
||||||
}
|
|
||||||
else if(bootType == NTR || memcmp(launchedPath, u"firm", 8) == 0)
|
|
||||||
{
|
|
||||||
if(mountSdCardPartition(true)) isSdMode = true;
|
|
||||||
else if(remountCtrNandPartition(true)) isSdMode = false;
|
|
||||||
else error("Failed to mount SD and CTRNAND.");
|
|
||||||
|
|
||||||
if(bootType == NTR)
|
|
||||||
{
|
|
||||||
while(HID_PAD & NTRBOOT_BUTTONS);
|
|
||||||
loadHomebrewFirm(0);
|
|
||||||
mcuPowerOff();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char mountPoint[5];
|
|
||||||
|
|
||||||
u32 i;
|
|
||||||
for(i = 0; i < 4 && launchedPath[i] != u':'; i++)
|
|
||||||
mountPoint[i] = (char)launchedPath[i];
|
|
||||||
mountPoint[i] = 0;
|
|
||||||
|
|
||||||
error("Launched from an unsupported location: %s.", mountPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
detectAndProcessExceptionDumps();
|
|
||||||
|
|
||||||
//Attempt to read the configuration file
|
|
||||||
needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION;
|
|
||||||
|
|
||||||
//Determine if this is a firmlaunch boot
|
|
||||||
if(bootType == FIRMLAUNCH)
|
|
||||||
{
|
|
||||||
if(needConfig == CREATE_CONFIGURATION) mcuPowerOff();
|
|
||||||
|
|
||||||
switch(firmlaunchTidLow & 0xF)
|
|
||||||
{
|
|
||||||
case 2:
|
|
||||||
firmType = (FirmwareType)((firmlaunchTidLow >> 8) & 0xF);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
firmType = SAFE_FIRM;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
firmType = SYSUPDATER_FIRM;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
nandType = (FirmwareSource)BOOTCFG_NAND;
|
|
||||||
emunandIndex = BOOTCFG_EMUINDEX;
|
|
||||||
isFirmProtEnabled = !BOOTCFG_NTRCARDBOOT;
|
|
||||||
|
|
||||||
goto boot;
|
|
||||||
}
|
|
||||||
|
|
||||||
firmType = NATIVE_FIRM;
|
|
||||||
isFirmProtEnabled = bootType != NTR;
|
|
||||||
|
|
||||||
//Get pressed buttons
|
|
||||||
u32 pressed = HID_PAD;
|
|
||||||
|
|
||||||
//If it's a MCU reboot, try to force boot options
|
|
||||||
if(CFG_BOOTENV && needConfig != CREATE_CONFIGURATION)
|
|
||||||
{
|
|
||||||
u32 bootenv = CFG_BOOTENV;
|
|
||||||
bool validTlnc = bootenv == 3 && hasValidTlncAutobootParams();
|
|
||||||
|
|
||||||
if (validTlnc)
|
|
||||||
needToInitSd = true;
|
|
||||||
|
|
||||||
//Always force a SysNAND boot when quitting AGB_FIRM
|
|
||||||
if(bootenv == 7)
|
|
||||||
{
|
|
||||||
nandType = FIRMWARE_SYSNAND;
|
|
||||||
|
|
||||||
// Prevent multiple boot options-forcing
|
|
||||||
// This bit is a bit weird. Basically, as you return to Home Menu by pressing either
|
|
||||||
// the HOME or POWER button, nandType will be overridden to "SysNAND" (needed). But,
|
|
||||||
// if you reboot again (e.g. via Rosalina menu), it'll use your default settings.
|
|
||||||
if(nandType != BOOTCFG_NAND) isNoForceFlagSet = true;
|
|
||||||
|
|
||||||
goto boot;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure homebrew autoboot (if deliver arg ends up not containing anything)
|
|
||||||
if (bootenv == 1 && MULTICONFIG(AUTOBOOTMODE) != 0)
|
|
||||||
configureHomebrewAutoboot();
|
|
||||||
|
|
||||||
/* Force the last used boot options if doing autolaunch from TWL, or unless a button is pressed
|
|
||||||
or the no-forcing flag is set */
|
|
||||||
if(validTlnc || !(pressed || BOOTCFG_NOFORCEFLAG))
|
|
||||||
{
|
|
||||||
nandType = (FirmwareSource)BOOTCFG_NAND;
|
|
||||||
emunandIndex = BOOTCFG_EMUINDEX;
|
|
||||||
|
|
||||||
goto boot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 pinMode = MULTICONFIG(PIN);
|
|
||||||
bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT);
|
|
||||||
bool pinExists = pinMode != 0 && verifyPin(pinMode);
|
|
||||||
|
|
||||||
/* If the PIN has been verified, wait to make it easier to press the SAFE_MODE combo or the configuration menu button
|
|
||||||
(if not already pressed, for the latter) */
|
|
||||||
if(pinExists && !shouldLoadConfigMenu)
|
|
||||||
{
|
|
||||||
while(HID_PAD & PIN_BUTTONS);
|
|
||||||
wait(2000ULL);
|
|
||||||
|
|
||||||
//Update pressed buttons
|
|
||||||
pressed = HID_PAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT);
|
|
||||||
if(shouldLoadConfigMenu)
|
|
||||||
{
|
|
||||||
configMenu(pinExists, pinMode);
|
|
||||||
|
|
||||||
//Update pressed buttons
|
|
||||||
pressed = HID_PAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!CFG_BOOTENV && pressed == SAFE_MODE)
|
|
||||||
{
|
|
||||||
nandType = FIRMWARE_SYSNAND;
|
|
||||||
|
|
||||||
isSafeMode = true;
|
|
||||||
needToInitSd = true;
|
|
||||||
|
|
||||||
goto boot;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 splashMode = MULTICONFIG(SPLASH);
|
|
||||||
|
|
||||||
if(splashMode == 1 && loadSplash()) pressed = HID_PAD;
|
|
||||||
|
|
||||||
bool autoBootEmu = CONFIG(AUTOBOOTEMU);
|
|
||||||
|
|
||||||
if((pressed & (BUTTON_START | BUTTON_L1)) == BUTTON_START)
|
|
||||||
{
|
|
||||||
loadHomebrewFirm(0);
|
|
||||||
pressed = HID_PAD;
|
|
||||||
}
|
|
||||||
else if((((pressed & SINGLE_PAYLOAD_BUTTONS) || (!autoBootEmu && (pressed & DPAD_BUTTONS))) && !(pressed & (BUTTON_L1 | BUTTON_R1))) ||
|
|
||||||
(((pressed & L_PAYLOAD_BUTTONS) || (autoBootEmu && (pressed & DPAD_BUTTONS))) && (pressed & BUTTON_L1))) loadHomebrewFirm(pressed);
|
|
||||||
|
|
||||||
if(splashMode == 2 && loadSplash()) pressed = HID_PAD;
|
|
||||||
|
|
||||||
//Check SAFE_MODE combo again
|
|
||||||
if(!CFG_BOOTENV && pressed == SAFE_MODE)
|
|
||||||
{
|
|
||||||
nandType = FIRMWARE_SYSNAND;
|
|
||||||
|
|
||||||
isSafeMode = true;
|
|
||||||
needToInitSd = true;
|
|
||||||
|
|
||||||
goto boot;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set-up autoboot
|
|
||||||
if (MULTICONFIG(AUTOBOOTMODE) != 0)
|
|
||||||
configureHomebrewAutoboot();
|
|
||||||
|
|
||||||
//If booting from CTRNAND, always use SysNAND
|
|
||||||
if(!isSdMode) nandType = FIRMWARE_SYSNAND;
|
|
||||||
else nandType = (autoBootEmu == ((pressed & BUTTON_L1) == BUTTON_L1)) ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND;
|
|
||||||
|
|
||||||
//If we're booting EmuNAND or using EmuNAND FIRM, determine which one from the directional pad buttons, or otherwise from the config
|
|
||||||
if(nandType == FIRMWARE_EMUNAND)
|
|
||||||
{
|
|
||||||
switch(pressed & DPAD_BUTTONS)
|
|
||||||
{
|
|
||||||
case BUTTON_UP:
|
|
||||||
emunandIndex = 0;
|
|
||||||
break;
|
|
||||||
case BUTTON_RIGHT:
|
|
||||||
emunandIndex = 1;
|
|
||||||
break;
|
|
||||||
case BUTTON_DOWN:
|
|
||||||
emunandIndex = 2;
|
|
||||||
break;
|
|
||||||
case BUTTON_LEFT:
|
|
||||||
emunandIndex = 3;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
emunandIndex = MULTICONFIG(DEFAULTEMU);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boot:
|
|
||||||
|
|
||||||
//If we need to boot EmuNAND, make sure it exists
|
|
||||||
if(nandType != FIRMWARE_SYSNAND)
|
|
||||||
{
|
|
||||||
locateEmuNand(&nandType, &emunandIndex, true);
|
|
||||||
if(nandType == FIRMWARE_EMUNAND && (*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0) //Make sure the SD card isn't write protected
|
|
||||||
error("The SD card is locked, EmuNAND can not be used.\nPlease turn the write protection switch off.");
|
|
||||||
}
|
|
||||||
|
|
||||||
ctrNandLocation = nandType; // for CTRNAND partition
|
|
||||||
|
|
||||||
if(bootType != FIRMLAUNCH)
|
|
||||||
{
|
|
||||||
configData.bootConfig = ((bootType == NTR ? 1 : 0) << 4) | ((u32)isNoForceFlagSet << 3) | ((u32)emunandIndex << 1) | (u32)nandType;
|
|
||||||
writeConfig(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool loadFromStorage = CONFIG(LOADEXTFIRMSANDMODULES);
|
|
||||||
u32 firmVersion = loadNintendoFirm(&firmType, nandType, loadFromStorage, isSafeMode);
|
|
||||||
|
|
||||||
bool doUnitinfoPatch = CONFIG(PATCHUNITINFO);
|
|
||||||
u32 res = 0;
|
|
||||||
switch(firmType)
|
|
||||||
{
|
|
||||||
case NATIVE_FIRM:
|
|
||||||
{
|
|
||||||
res = patchNativeFirm(firmVersion, nandType, loadFromStorage, isFirmProtEnabled, needToInitSd, doUnitinfoPatch);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TWL_FIRM:
|
|
||||||
res = patchTwlFirm(firmVersion, loadFromStorage, doUnitinfoPatch);
|
|
||||||
break;
|
|
||||||
case AGB_FIRM:
|
|
||||||
res = patchAgbFirm(loadFromStorage, doUnitinfoPatch);
|
|
||||||
break;
|
|
||||||
case SAFE_FIRM:
|
|
||||||
case SYSUPDATER_FIRM:
|
|
||||||
case NATIVE_FIRM1X2X:
|
|
||||||
res = patch1x2xNativeAndSafeFirm();
|
|
||||||
break;
|
|
||||||
case NATIVE_PROTOTYPE:
|
|
||||||
res = patchPrototypeNative(nandType);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(res != 0) error("Failed to apply %u FIRM patch(es).", res);
|
|
||||||
|
|
||||||
unmountPartitions();
|
|
||||||
if(bootType != FIRMLAUNCH) deinitScreens();
|
|
||||||
launchFirm(0, NULL);
|
|
||||||
}
|
|
||||||
@ -1,251 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2022 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* waitInput function based on code by d0k3 https://github.com/d0k3/Decrypt9WIP/blob/master/source/hid.c
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include "i2c.h"
|
|
||||||
#include "buttons.h"
|
|
||||||
#include "screen.h"
|
|
||||||
#include "draw.h"
|
|
||||||
#include "cache.h"
|
|
||||||
#include "fmt.h"
|
|
||||||
#include "memory.h"
|
|
||||||
#include "fs.h"
|
|
||||||
|
|
||||||
void startChrono(void)
|
|
||||||
{
|
|
||||||
static bool isChronoStarted = false;
|
|
||||||
|
|
||||||
if(isChronoStarted) return;
|
|
||||||
|
|
||||||
REG_TIMER_CNT(0) = 0; //67MHz
|
|
||||||
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 4; //Count-up
|
|
||||||
|
|
||||||
for(u32 i = 0; i < 4; i++) REG_TIMER_VAL(i) = 0;
|
|
||||||
|
|
||||||
REG_TIMER_CNT(0) = 0x80; //67MHz; enabled
|
|
||||||
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 0x84; //Count-up; enabled
|
|
||||||
|
|
||||||
isChronoStarted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 chrono(void)
|
|
||||||
{
|
|
||||||
u64 res = 0;
|
|
||||||
for(u32 i = 0; i < 4; i++) res |= REG_TIMER_VAL(i) << (16 * i);
|
|
||||||
|
|
||||||
res /= (TICKS_PER_SEC / 1000);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 waitInput(bool isMenu)
|
|
||||||
{
|
|
||||||
static u64 dPadDelay = 0ULL;
|
|
||||||
u64 initialValue = 0ULL;
|
|
||||||
u32 key,
|
|
||||||
oldKey = HID_PAD;
|
|
||||||
bool shouldShellShutdown = bootType != B9SNTR && bootType != NTR;
|
|
||||||
|
|
||||||
if(isMenu)
|
|
||||||
{
|
|
||||||
dPadDelay = dPadDelay > 0ULL ? 87ULL : 143ULL;
|
|
||||||
startChrono();
|
|
||||||
initialValue = chrono();
|
|
||||||
}
|
|
||||||
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
key = HID_PAD;
|
|
||||||
|
|
||||||
if(!key)
|
|
||||||
{
|
|
||||||
if(shouldShellShutdown)
|
|
||||||
{
|
|
||||||
u8 shellState = I2C_readReg(I2C_DEV_MCU, 0xF);
|
|
||||||
wait(5);
|
|
||||||
if(!(shellState & 2)) mcuPowerOff();
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 intStatus = I2C_readReg(I2C_DEV_MCU, 0x10);
|
|
||||||
wait(5);
|
|
||||||
if(intStatus & 1) mcuPowerOff(); //Power button pressed
|
|
||||||
|
|
||||||
oldKey = 0;
|
|
||||||
dPadDelay = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(key == oldKey && (!isMenu || (!(key & DPAD_BUTTONS) || chrono() - initialValue < dPadDelay))) continue;
|
|
||||||
|
|
||||||
//Make sure the key is pressed
|
|
||||||
u32 i;
|
|
||||||
for(i = 0; i < 0x13000 && key == HID_PAD; i++);
|
|
||||||
if(i == 0x13000) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((noreturn)) void mcuPowerOff(void)
|
|
||||||
{
|
|
||||||
// Unmount partitions
|
|
||||||
unmountPartitions();
|
|
||||||
|
|
||||||
if(!needToSetupScreens) clearScreens(false);
|
|
||||||
|
|
||||||
//Shutdown LCD
|
|
||||||
if(ARESCREENSINITIALIZED) I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0);
|
|
||||||
|
|
||||||
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
|
||||||
flushEntireDCache();
|
|
||||||
|
|
||||||
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 0);
|
|
||||||
while(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wait(u64 amount)
|
|
||||||
{
|
|
||||||
startChrono();
|
|
||||||
|
|
||||||
u64 initialValue = chrono();
|
|
||||||
|
|
||||||
while(chrono() - initialValue < amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
void error(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
char buf[DRAW_MAX_FORMATTED_STRING_SIZE + 1];
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
vsprintf(buf, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
initScreens();
|
|
||||||
drawString(true, 10, 10, COLOR_RED, "An error has occurred:");
|
|
||||||
u32 posY = drawString(true, 10, 30, COLOR_WHITE, buf);
|
|
||||||
drawString(true, 10, posY + 2 * SPACING_Y, COLOR_WHITE, "Press any button to shutdown");
|
|
||||||
|
|
||||||
waitInput(false);
|
|
||||||
|
|
||||||
mcuPowerOff();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// CRC-16/MODBUS
|
|
||||||
u16 crc16(const void *data, size_t size, u16 initialValue)
|
|
||||||
{
|
|
||||||
static const u16 lut[256] = {
|
|
||||||
0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241,
|
|
||||||
0xC601,0x06C0,0x0780,0xC741,0x0500,0xC5C1,0xC481,0x0440,
|
|
||||||
0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40,
|
|
||||||
0x0A00,0xCAC1,0xCB81,0x0B40,0xC901,0x09C0,0x0880,0xC841,
|
|
||||||
0xD801,0x18C0,0x1980,0xD941,0x1B00,0xDBC1,0xDA81,0x1A40,
|
|
||||||
0x1E00,0xDEC1,0xDF81,0x1F40,0xDD01,0x1DC0,0x1C80,0xDC41,
|
|
||||||
0x1400,0xD4C1,0xD581,0x1540,0xD701,0x17C0,0x1680,0xD641,
|
|
||||||
0xD201,0x12C0,0x1380,0xD341,0x1100,0xD1C1,0xD081,0x1040,
|
|
||||||
0xF001,0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240,
|
|
||||||
0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,0x3480,0xF441,
|
|
||||||
0x3C00,0xFCC1,0xFD81,0x3D40,0xFF01,0x3FC0,0x3E80,0xFE41,
|
|
||||||
0xFA01,0x3AC0,0x3B80,0xFB41,0x3900,0xF9C1,0xF881,0x3840,
|
|
||||||
0x2800,0xE8C1,0xE981,0x2940,0xEB01,0x2BC0,0x2A80,0xEA41,
|
|
||||||
0xEE01,0x2EC0,0x2F80,0xEF41,0x2D00,0xEDC1,0xEC81,0x2C40,
|
|
||||||
0xE401,0x24C0,0x2580,0xE541,0x2700,0xE7C1,0xE681,0x2640,
|
|
||||||
0x2200,0xE2C1,0xE381,0x2340,0xE101,0x21C0,0x2080,0xE041,
|
|
||||||
0xA001,0x60C0,0x6180,0xA141,0x6300,0xA3C1,0xA281,0x6240,
|
|
||||||
0x6600,0xA6C1,0xA781,0x6740,0xA501,0x65C0,0x6480,0xA441,
|
|
||||||
0x6C00,0xACC1,0xAD81,0x6D40,0xAF01,0x6FC0,0x6E80,0xAE41,
|
|
||||||
0xAA01,0x6AC0,0x6B80,0xAB41,0x6900,0xA9C1,0xA881,0x6840,
|
|
||||||
0x7800,0xB8C1,0xB981,0x7940,0xBB01,0x7BC0,0x7A80,0xBA41,
|
|
||||||
0xBE01,0x7EC0,0x7F80,0xBF41,0x7D00,0xBDC1,0xBC81,0x7C40,
|
|
||||||
0xB401,0x74C0,0x7580,0xB541,0x7700,0xB7C1,0xB681,0x7640,
|
|
||||||
0x7200,0xB2C1,0xB381,0x7340,0xB101,0x71C0,0x7080,0xB041,
|
|
||||||
0x5000,0x90C1,0x9181,0x5140,0x9301,0x53C0,0x5280,0x9241,
|
|
||||||
0x9601,0x56C0,0x5780,0x9741,0x5500,0x95C1,0x9481,0x5440,
|
|
||||||
0x9C01,0x5CC0,0x5D80,0x9D41,0x5F00,0x9FC1,0x9E81,0x5E40,
|
|
||||||
0x5A00,0x9AC1,0x9B81,0x5B40,0x9901,0x59C0,0x5880,0x9841,
|
|
||||||
0x8801,0x48C0,0x4980,0x8941,0x4B00,0x8BC1,0x8A81,0x4A40,
|
|
||||||
0x4E00,0x8EC1,0x8F81,0x4F40,0x8D01,0x4DC0,0x4C80,0x8C41,
|
|
||||||
0x4400,0x84C1,0x8581,0x4540,0x8701,0x47C0,0x4680,0x8641,
|
|
||||||
0x8201,0x42C0,0x4380,0x8341,0x4100,0x81C1,0x8081,0x4040,
|
|
||||||
};
|
|
||||||
|
|
||||||
u16 r = initialValue;
|
|
||||||
const u8 *data8 = (const u8 *)data;
|
|
||||||
for (size_t i = 0; i < size; i++)
|
|
||||||
r = (r >> 8) ^ lut[(r ^ data8[i]) & 0xFF];
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 crc32(const void *data, size_t size, u32 initialValue)
|
|
||||||
{
|
|
||||||
static const u32 lut[256] = {
|
|
||||||
0x00000000,0x77073096,0xEE0E612C,0x990951BA,0x076DC419,0x706AF48F,0xE963A535,0x9E6495A3,
|
|
||||||
0x0EDB8832,0x79DCB8A4,0xE0D5E91E,0x97D2D988,0x09B64C2B,0x7EB17CBD,0xE7B82D07,0x90BF1D91,
|
|
||||||
0x1DB71064,0x6AB020F2,0xF3B97148,0x84BE41DE,0x1ADAD47D,0x6DDDE4EB,0xF4D4B551,0x83D385C7,
|
|
||||||
0x136C9856,0x646BA8C0,0xFD62F97A,0x8A65C9EC,0x14015C4F,0x63066CD9,0xFA0F3D63,0x8D080DF5,
|
|
||||||
0x3B6E20C8,0x4C69105E,0xD56041E4,0xA2677172,0x3C03E4D1,0x4B04D447,0xD20D85FD,0xA50AB56B,
|
|
||||||
0x35B5A8FA,0x42B2986C,0xDBBBC9D6,0xACBCF940,0x32D86CE3,0x45DF5C75,0xDCD60DCF,0xABD13D59,
|
|
||||||
0x26D930AC,0x51DE003A,0xC8D75180,0xBFD06116,0x21B4F4B5,0x56B3C423,0xCFBA9599,0xB8BDA50F,
|
|
||||||
0x2802B89E,0x5F058808,0xC60CD9B2,0xB10BE924,0x2F6F7C87,0x58684C11,0xC1611DAB,0xB6662D3D,
|
|
||||||
0x76DC4190,0x01DB7106,0x98D220BC,0xEFD5102A,0x71B18589,0x06B6B51F,0x9FBFE4A5,0xE8B8D433,
|
|
||||||
0x7807C9A2,0x0F00F934,0x9609A88E,0xE10E9818,0x7F6A0DBB,0x086D3D2D,0x91646C97,0xE6635C01,
|
|
||||||
0x6B6B51F4,0x1C6C6162,0x856530D8,0xF262004E,0x6C0695ED,0x1B01A57B,0x8208F4C1,0xF50FC457,
|
|
||||||
0x65B0D9C6,0x12B7E950,0x8BBEB8EA,0xFCB9887C,0x62DD1DDF,0x15DA2D49,0x8CD37CF3,0xFBD44C65,
|
|
||||||
0x4DB26158,0x3AB551CE,0xA3BC0074,0xD4BB30E2,0x4ADFA541,0x3DD895D7,0xA4D1C46D,0xD3D6F4FB,
|
|
||||||
0x4369E96A,0x346ED9FC,0xAD678846,0xDA60B8D0,0x44042D73,0x33031DE5,0xAA0A4C5F,0xDD0D7CC9,
|
|
||||||
0x5005713C,0x270241AA,0xBE0B1010,0xC90C2086,0x5768B525,0x206F85B3,0xB966D409,0xCE61E49F,
|
|
||||||
0x5EDEF90E,0x29D9C998,0xB0D09822,0xC7D7A8B4,0x59B33D17,0x2EB40D81,0xB7BD5C3B,0xC0BA6CAD,
|
|
||||||
0xEDB88320,0x9ABFB3B6,0x03B6E20C,0x74B1D29A,0xEAD54739,0x9DD277AF,0x04DB2615,0x73DC1683,
|
|
||||||
0xE3630B12,0x94643B84,0x0D6D6A3E,0x7A6A5AA8,0xE40ECF0B,0x9309FF9D,0x0A00AE27,0x7D079EB1,
|
|
||||||
0xF00F9344,0x8708A3D2,0x1E01F268,0x6906C2FE,0xF762575D,0x806567CB,0x196C3671,0x6E6B06E7,
|
|
||||||
0xFED41B76,0x89D32BE0,0x10DA7A5A,0x67DD4ACC,0xF9B9DF6F,0x8EBEEFF9,0x17B7BE43,0x60B08ED5,
|
|
||||||
0xD6D6A3E8,0xA1D1937E,0x38D8C2C4,0x4FDFF252,0xD1BB67F1,0xA6BC5767,0x3FB506DD,0x48B2364B,
|
|
||||||
0xD80D2BDA,0xAF0A1B4C,0x36034AF6,0x41047A60,0xDF60EFC3,0xA867DF55,0x316E8EEF,0x4669BE79,
|
|
||||||
0xCB61B38C,0xBC66831A,0x256FD2A0,0x5268E236,0xCC0C7795,0xBB0B4703,0x220216B9,0x5505262F,
|
|
||||||
0xC5BA3BBE,0xB2BD0B28,0x2BB45A92,0x5CB36A04,0xC2D7FFA7,0xB5D0CF31,0x2CD99E8B,0x5BDEAE1D,
|
|
||||||
0x9B64C2B0,0xEC63F226,0x756AA39C,0x026D930A,0x9C0906A9,0xEB0E363F,0x72076785,0x05005713,
|
|
||||||
0x95BF4A82,0xE2B87A14,0x7BB12BAE,0x0CB61B38,0x92D28E9B,0xE5D5BE0D,0x7CDCEFB7,0x0BDBDF21,
|
|
||||||
0x86D3D2D4,0xF1D4E242,0x68DDB3F8,0x1FDA836E,0x81BE16CD,0xF6B9265B,0x6FB077E1,0x18B74777,
|
|
||||||
0x88085AE6,0xFF0F6A70,0x66063BCA,0x11010B5C,0x8F659EFF,0xF862AE69,0x616BFFD3,0x166CCF45,
|
|
||||||
0xA00AE278,0xD70DD2EE,0x4E048354,0x3903B3C2,0xA7672661,0xD06016F7,0x4969474D,0x3E6E77DB,
|
|
||||||
0xAED16A4A,0xD9D65ADC,0x40DF0B66,0x37D83BF0,0xA9BCAE53,0xDEBB9EC5,0x47B2CF7F,0x30B5FFE9,
|
|
||||||
0xBDBDF21C,0xCABAC28A,0x53B39330,0x24B4A3A6,0xBAD03605,0xCDD70693,0x54DE5729,0x23D967BF,
|
|
||||||
0xB3667A2E,0xC4614AB8,0x5D681B02,0x2A6F2B94,0xB40BBE37,0xC30C8EA1,0x5A05DF1B,0x2D02EF8D,
|
|
||||||
};
|
|
||||||
|
|
||||||
u32 r = initialValue;
|
|
||||||
const u8 *data8 = (const u8 *)data;
|
|
||||||
for (size_t i = 0; i < size; i++)
|
|
||||||
r = (r >> 8) ^ lut[(r ^ data8[i]) & 0xFF];
|
|
||||||
|
|
||||||
return ~r;
|
|
||||||
}
|
|
||||||
44
chainloader/Makefile
Normal file
44
chainloader/Makefile
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
||||||
|
|
||||||
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(DEVKITARM)/base_tools
|
||||||
|
|
||||||
|
name := $(shell basename $(CURDIR))
|
||||||
|
|
||||||
|
dir_source := source
|
||||||
|
dir_build := build
|
||||||
|
dir_out := ../$(dir_build)
|
||||||
|
|
||||||
|
ASFLAGS := -mcpu=arm946e-s
|
||||||
|
CFLAGS := -Wall -Wextra -marm $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math
|
||||||
|
LDFLAGS := -nostartfiles -Wl,--nmagic
|
||||||
|
|
||||||
|
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||||
|
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
||||||
|
$(call rwildcard, $(dir_source), *.s *.c)))
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(dir_out)/$(name).bin
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
@rm -rf $(dir_build)
|
||||||
|
|
||||||
|
$(dir_out)/$(name).bin: $(dir_build)/$(name).elf
|
||||||
|
$(OBJCOPY) -S -O binary $< $@
|
||||||
|
|
||||||
|
$(dir_build)/$(name).elf: $(objects)
|
||||||
|
$(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^
|
||||||
|
|
||||||
|
$(dir_build)/memory.o: CFLAGS += -O3
|
||||||
|
|
||||||
|
$(dir_build)/%.o: $(dir_source)/%.c
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||||
|
|
||||||
|
$(dir_build)/%.o: $(dir_source)/%.s
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||||
21
chainloader/linker.ld
Normal file
21
chainloader/linker.ld
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||||
|
OUTPUT_ARCH(arm)
|
||||||
|
|
||||||
|
ENTRY(_start)
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
. = 0x01FF9000;
|
||||||
|
|
||||||
|
__start__ = ABSOLUTE(.);
|
||||||
|
|
||||||
|
.text : ALIGN(4) { *(.text.start) *(.text*); . = ALIGN(4); }
|
||||||
|
.rodata : ALIGN(4) { *(.rodata*); . = ALIGN(4); }
|
||||||
|
.data : ALIGN(4) { *(.data*); . = ALIGN(8); *(.bss* COMMON); . = ALIGN(8); }
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
|
||||||
|
__end__ = ABSOLUTE(.);
|
||||||
|
|
||||||
|
__stack_top__ = 0x01FFB800;
|
||||||
|
__stack_bottom__ = 0x01FFA800;
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2022 TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "MyThread.h"
|
|
||||||
|
|
||||||
MyThread *bootdiagCreateThread(void);
|
#include "types.h"
|
||||||
|
|
||||||
|
void flushCaches(void);
|
||||||
60
chainloader/source/cache.s
Normal file
60
chainloader/source/cache.s
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
@ This file is part of Luma3DS
|
||||||
|
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
@
|
||||||
|
@ This program is free software: you can redistribute it and/or modify
|
||||||
|
@ it under the terms of the GNU General Public License as published by
|
||||||
|
@ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
@ (at your option) any later version.
|
||||||
|
@
|
||||||
|
@ This program is distributed in the hope that it will be useful,
|
||||||
|
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
@ GNU General Public License for more details.
|
||||||
|
@
|
||||||
|
@ You should have received a copy of the GNU General Public License
|
||||||
|
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
@
|
||||||
|
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
@ * Requiring preservation of specified reasonable legal notices or
|
||||||
|
@ author attributions in that material or in the Appropriate Legal
|
||||||
|
@ Notices displayed by works containing it.
|
||||||
|
@ * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
@ or requiring that modified versions of such material be marked in
|
||||||
|
@ reasonable ways as different from the original version.
|
||||||
|
|
||||||
|
.text
|
||||||
|
.arm
|
||||||
|
.align 4
|
||||||
|
|
||||||
|
.global flushCaches
|
||||||
|
.type flushCaches, %function
|
||||||
|
flushCaches:
|
||||||
|
@ Clean and flush both the data cache and instruction caches
|
||||||
|
|
||||||
|
@ Adpated from http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0155a/ch03s03s05.html ,
|
||||||
|
@ and https://github.com/gemarcano/libctr9_io/blob/master/src/ctr_system_ARM.c#L39 as well
|
||||||
|
@ Note: ARM's example is actually for a 8KB DCache (which is what the 3DS has)
|
||||||
|
|
||||||
|
@ Implemented in bootROM at addresses 0xffff0830 (DCache) and 0xffff0ab4 (ICache)
|
||||||
|
|
||||||
|
mov r1, #0 @ segment counter
|
||||||
|
outer_loop:
|
||||||
|
mov r0, #0 @ line counter
|
||||||
|
|
||||||
|
inner_loop:
|
||||||
|
orr r2, r1, r0 @ generate segment and line address
|
||||||
|
mcr p15, 0, r2, c7, c14, 2 @ clean and flush the line
|
||||||
|
add r0, #0x20 @ increment to next line
|
||||||
|
cmp r0, #0x400
|
||||||
|
bne inner_loop
|
||||||
|
|
||||||
|
add r1, #0x40000000
|
||||||
|
cmp r1, #0
|
||||||
|
bne outer_loop
|
||||||
|
|
||||||
|
mcr p15, 0, r1, c7, c10, 4 @ drain write buffer
|
||||||
|
|
||||||
|
@ Flush instruction cache
|
||||||
|
mcr p15, 0, r1, c7, c5, 0
|
||||||
|
|
||||||
|
bx lr
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2022 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -24,21 +24,19 @@
|
|||||||
* reasonable ways as different from the original version.
|
* reasonable ways as different from the original version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#include "firm.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "cache.h"
|
||||||
|
|
||||||
#include <3ds.h>
|
void disableMpuAndJumpToEntrypoints(int argc, char **argv, void *arm11Entry, void *arm9Entry);
|
||||||
#include "luma_shared_config.h"
|
|
||||||
|
|
||||||
Result hbldrLoadProcess(Handle *outProcessHandle, const ExHeader_Info *exhi);
|
void launchFirm(Firm *firm, int argc, char **argv)
|
||||||
void hbldrPatchExHeaderInfo(ExHeader_Info *exhi);
|
|
||||||
void hbldrHandleCommands(void *ctx);
|
|
||||||
|
|
||||||
static inline bool hbldrIs3dsxTitle(u64 tid)
|
|
||||||
{
|
{
|
||||||
if (!Luma_SharedConfig->use_hbldr)
|
//Copy FIRM sections to respective memory locations
|
||||||
return false;
|
for(u32 sectionNum = 0; sectionNum < 4; sectionNum++)
|
||||||
u64 hbldrTid = Luma_SharedConfig->hbldr_3dsx_tid;
|
memcpy(firm->section[sectionNum].address, (u8 *)firm + firm->section[sectionNum].offset, firm->section[sectionNum].size);
|
||||||
|
|
||||||
// Just like p9 clears them, ignore platform/N3DS bits
|
disableMpuAndJumpToEntrypoints(argc, argv, firm->arm9Entry, firm->arm11Entry);
|
||||||
return ((tid ^ hbldrTid) & ~0xF0000000ull) == 0;
|
|
||||||
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
50
chainloader/source/firm.h
Normal file
50
chainloader/source/firm.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed))
|
||||||
|
{
|
||||||
|
u32 offset;
|
||||||
|
u8 *address;
|
||||||
|
u32 size;
|
||||||
|
u32 procType;
|
||||||
|
u8 hash[0x20];
|
||||||
|
} FirmSection;
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed))
|
||||||
|
{
|
||||||
|
char magic[4];
|
||||||
|
u32 reserved1;
|
||||||
|
u8 *arm11Entry;
|
||||||
|
u8 *arm9Entry;
|
||||||
|
u8 reserved2[0x30];
|
||||||
|
FirmSection section[4];
|
||||||
|
} Firm;
|
||||||
|
|
||||||
|
void launchFirm(Firm *firm, int argc, char **argv);
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2023 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -24,14 +24,35 @@
|
|||||||
* reasonable ways as different from the original version.
|
* reasonable ways as different from the original version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "svc/CreateThread.h"
|
#include "memory.h"
|
||||||
|
#include "cache.h"
|
||||||
|
#include "firm.h"
|
||||||
|
|
||||||
Result CreateThreadHook(Handle *outThreadHandle, u32 ep, u32 arg, u32 stackTop, s32 priority, s32 processorId)
|
void main(int argc, char **argv, Firm *firm)
|
||||||
{
|
{
|
||||||
u32 flags = flagsOfProcess(currentCoreContext->objectContext.currentProcess);
|
char *argvPassed[2],
|
||||||
if (isN3DS && CONFIG(REDIRECTAPPTHREADS) && !disableThreadRedirection && processorId == 1 && (flags & 0xF00) == 0x100)
|
absPath[24 + 255];
|
||||||
processorId = 2;
|
struct fb fbs[2];
|
||||||
|
|
||||||
return CreateThread(outThreadHandle, ep, arg, stackTop, priority, processorId);
|
if(argc > 0)
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
for(i = 0; i < sizeof(absPath) - 1 && argv[0][i] != 0; i++)
|
||||||
|
absPath[i] = argv[0][i];
|
||||||
|
absPath[i] = 0;
|
||||||
|
|
||||||
|
argvPassed[0] = (char *)absPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(argc == 2)
|
||||||
|
{
|
||||||
|
struct fb *fbsrc = (struct fb *)argv[1];
|
||||||
|
|
||||||
|
fbs[0] = fbsrc[0];
|
||||||
|
fbs[1] = fbsrc[1];
|
||||||
|
|
||||||
|
argvPassed[1] = (char *)&fbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
launchFirm(firm, argc, argvPassed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -24,9 +24,17 @@
|
|||||||
* reasonable ways as different from the original version.
|
* reasonable ways as different from the original version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "types.h"
|
/*
|
||||||
|
* memcpy adapted from https://github.com/mid-kid/CakesForeveryWan/blob/557a8e8605ab3ee173af6497486e8f22c261d0e2/source/memfuncs.c
|
||||||
|
*/
|
||||||
|
|
||||||
extern const u32 arm9ExceptionHandlerAddressTable[6];
|
#include "memory.h"
|
||||||
extern u32 arm9ExceptionHandlerSvcBreakAddress;
|
|
||||||
|
|
||||||
u32 safecpy(void *dst, const void *src, u32 len);
|
void memcpy(void *dest, const void *src, u32 size)
|
||||||
|
{
|
||||||
|
u8 *destc = (u8 *)dest;
|
||||||
|
const u8 *srcc = (const u8 *)src;
|
||||||
|
|
||||||
|
for(u32 i = 0; i < size; i++)
|
||||||
|
destc[i] = srcc[i];
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2022 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -24,14 +24,12 @@
|
|||||||
* reasonable ways as different from the original version.
|
* reasonable ways as different from the original version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* memcpy adapted from https://github.com/mid-kid/CakesForeveryWan/blob/557a8e8605ab3ee173af6497486e8f22c261d0e2/source/memfuncs.c
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
u8 *loadDeliverArg(void);
|
void memcpy(void *dest, const void *src, u32 size);
|
||||||
void commitDeliverArg(void);
|
|
||||||
|
|
||||||
bool hasValidTlncAutobootParams(void);
|
|
||||||
bool isTwlToCtrLaunch(void); // assumes TLNC block is valid
|
|
||||||
|
|
||||||
bool configureHomebrewAutoboot(void);
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
@ This file is part of Luma3DS
|
@ This file is part of Luma3DS
|
||||||
@ Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
@
|
@
|
||||||
@ This program is free software: you can redistribute it and/or modify
|
@ This program is free software: you can redistribute it and/or modify
|
||||||
@ it under the terms of the GNU General Public License as published by
|
@ it under the terms of the GNU General Public License as published by
|
||||||
@ -21,45 +21,40 @@
|
|||||||
@ * Prohibiting misrepresentation of the origin of that material,
|
@ * Prohibiting misrepresentation of the origin of that material,
|
||||||
@ or requiring that modified versions of such material be marked in
|
@ or requiring that modified versions of such material be marked in
|
||||||
@ reasonable ways as different from the original version.
|
@ reasonable ways as different from the original version.
|
||||||
|
|
||||||
.section .text.alignedseqmemcpy, "ax", %progbits
|
|
||||||
.arm
|
.arm
|
||||||
@ Align on cache line boundaries & make sure the loops don't cross them.
|
|
||||||
.align 5
|
|
||||||
.global alignedseqmemcpy
|
|
||||||
.type alignedseqmemcpy, %function
|
|
||||||
alignedseqmemcpy:
|
|
||||||
@ src=r1 and dst=r0 are expected to be 4-byte-aligned
|
|
||||||
push {r4-r10, lr}
|
|
||||||
|
|
||||||
lsrs r12, r2, #5
|
.section .text.start
|
||||||
sub r2, r2, r12, lsl #5
|
.align 4
|
||||||
beq 2f
|
.global _start
|
||||||
|
_start:
|
||||||
|
ldr sp, =__stack_top__
|
||||||
|
b main
|
||||||
|
|
||||||
1:
|
.text
|
||||||
ldmia r1!, {r3-r10}
|
.balign 4
|
||||||
stmia r0!, {r3-r10}
|
.global disableMpuAndJumpToEntrypoints
|
||||||
subs r12, #1
|
.type disableMpuAndJumpToEntrypoints, %function
|
||||||
bne 1b
|
disableMpuAndJumpToEntrypoints:
|
||||||
|
mov r4, r0
|
||||||
|
mov r5, r1
|
||||||
|
mov r6, r2
|
||||||
|
mov r7, r3
|
||||||
|
|
||||||
2:
|
bl flushCaches
|
||||||
lsrs r12, r2, #2
|
|
||||||
sub r2, r2, r12, lsl #2
|
|
||||||
beq 4f
|
|
||||||
|
|
||||||
3:
|
@ Disable caches / MPU
|
||||||
ldr r3, [r1], #4
|
mrc p15, 0, r0, c1, c0, 0 @ read control register
|
||||||
str r3, [r0], #4
|
bic r0, #(1<<12) @ - instruction cache disable
|
||||||
subs r12, #1
|
bic r0, #(1<<2) @ - data cache disable
|
||||||
bne 3b
|
bic r0, #(1<<0) @ - MPU disable
|
||||||
|
mcr p15, 0, r0, c1, c0, 0 @ write control register
|
||||||
|
|
||||||
4:
|
@ Set the ARM11 entrypoint
|
||||||
tst r2, #2
|
mov r0, #0x20000000
|
||||||
ldrneh r3, [r1], #2
|
str r7, [r0, #-4]
|
||||||
strneh r3, [r0], #2
|
|
||||||
|
|
||||||
tst r2, #1
|
@ Jump to the ARM9 entrypoint
|
||||||
ldrneb r3, [r1], #1
|
mov r0, r4
|
||||||
strneb r3, [r0], #1
|
mov r1, r5
|
||||||
|
ldr r2, =0x2BEEF
|
||||||
pop {r4-r10, pc}
|
bx r6
|
||||||
45
chainloader/source/types.h
Normal file
45
chainloader/source/types.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
//Common data types
|
||||||
|
typedef uint8_t u8;
|
||||||
|
typedef uint16_t u16;
|
||||||
|
typedef uint32_t u32;
|
||||||
|
typedef uint64_t u64;
|
||||||
|
typedef volatile u8 vu8;
|
||||||
|
typedef volatile u16 vu16;
|
||||||
|
typedef volatile u32 vu32;
|
||||||
|
typedef volatile u64 vu64;
|
||||||
|
|
||||||
|
struct fb {
|
||||||
|
u8 *top_left;
|
||||||
|
u8 *top_right;
|
||||||
|
u8 *bottom;
|
||||||
|
} __attribute__((packed));
|
||||||
42
exceptions/arm9/Makefile
Normal file
42
exceptions/arm9/Makefile
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
||||||
|
|
||||||
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(DEVKITARM)/base_tools
|
||||||
|
|
||||||
|
name := arm9_exceptions
|
||||||
|
|
||||||
|
dir_source := source
|
||||||
|
dir_build := build
|
||||||
|
dir_out := ../../$(dir_build)
|
||||||
|
|
||||||
|
ASFLAGS := -mcpu=arm946e-s
|
||||||
|
CFLAGS := -Wall -Wextra -mthumb $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math
|
||||||
|
LDFLAGS := -nostdlib
|
||||||
|
|
||||||
|
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||||
|
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
||||||
|
$(call rwildcard, $(dir_source), *.s *.c)))
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(dir_out)/$(name).bin
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
@rm -rf $(dir_build)
|
||||||
|
|
||||||
|
$(dir_out)/$(name).bin: $(dir_build)/$(name).elf
|
||||||
|
$(OBJCOPY) -S -O binary $< $@
|
||||||
|
|
||||||
|
$(dir_build)/$(name).elf: $(objects)
|
||||||
|
$(CC) $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
||||||
|
|
||||||
|
$(dir_build)/%.o: $(dir_source)/%.c
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||||
|
|
||||||
|
$(dir_build)/%.o: $(dir_source)/%.s
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||||
14
exceptions/arm9/linker.ld
Normal file
14
exceptions/arm9/linker.ld
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||||
|
OUTPUT_ARCH(arm)
|
||||||
|
|
||||||
|
ENTRY(_start)
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
. = 0x01FF7FE0;
|
||||||
|
|
||||||
|
.text : ALIGN(4) { *(.text.start) *(.text*); . = ALIGN(4); }
|
||||||
|
.rodata : ALIGN(4) { *(.rodata*); . = ALIGN(4); }
|
||||||
|
.data : ALIGN(4) { *(.data*); . = ALIGN(8); *(.bss* COMMON); . = ALIGN(8); }
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
}
|
||||||
50
exceptions/arm9/source/handlers.h
Normal file
50
exceptions/arm9/source/handlers.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed))
|
||||||
|
{
|
||||||
|
u32 magic[2];
|
||||||
|
u16 versionMinor, versionMajor;
|
||||||
|
|
||||||
|
u16 processor, core;
|
||||||
|
u32 type;
|
||||||
|
|
||||||
|
u32 totalSize;
|
||||||
|
u32 registerDumpSize;
|
||||||
|
u32 codeDumpSize;
|
||||||
|
u32 stackDumpSize;
|
||||||
|
u32 additionalDataSize;
|
||||||
|
} ExceptionDumpHeader;
|
||||||
|
|
||||||
|
u32 readMPUConfig(u32 *regionSettings);
|
||||||
|
void FIQHandler(void);
|
||||||
|
void undefinedInstructionHandler(void);
|
||||||
|
void dataAbortHandler(void);
|
||||||
|
void prefetchAbortHandler(void);
|
||||||
113
exceptions/arm9/source/handlers.s
Normal file
113
exceptions/arm9/source/handlers.s
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
@ This file is part of Luma3DS
|
||||||
|
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
@
|
||||||
|
@ This program is free software: you can redistribute it and/or modify
|
||||||
|
@ it under the terms of the GNU General Public License as published by
|
||||||
|
@ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
@ (at your option) any later version.
|
||||||
|
@
|
||||||
|
@ This program is distributed in the hope that it will be useful,
|
||||||
|
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
@ GNU General Public License for more details.
|
||||||
|
@
|
||||||
|
@ You should have received a copy of the GNU General Public License
|
||||||
|
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
@
|
||||||
|
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
@ * Requiring preservation of specified reasonable legal notices or
|
||||||
|
@ author attributions in that material or in the Appropriate Legal
|
||||||
|
@ Notices displayed by works containing it.
|
||||||
|
@ * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
@ or requiring that modified versions of such material be marked in
|
||||||
|
@ reasonable ways as different from the original version.
|
||||||
|
|
||||||
|
.macro GEN_HANDLER name
|
||||||
|
.global \name
|
||||||
|
.type \name, %function
|
||||||
|
\name:
|
||||||
|
ldr sp, =#0x02000000 @ We make the (full descending) stack point to the end of ITCM for our exception handlers.
|
||||||
|
@ It doesn't matter if we're overwriting stuff here, since we're going to reboot.
|
||||||
|
|
||||||
|
stmfd sp!, {r0-r7} @ FIQ has its own r8-r14 regs
|
||||||
|
ldr r1, =\@ @ macro expansion counter
|
||||||
|
b _commonHandler
|
||||||
|
|
||||||
|
.size \name, . - \name
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.text
|
||||||
|
.arm
|
||||||
|
.align 4
|
||||||
|
|
||||||
|
.global _commonHandler
|
||||||
|
.type _commonHandler, %function
|
||||||
|
_commonHandler:
|
||||||
|
mrs r2, spsr
|
||||||
|
mov r6, sp
|
||||||
|
mrs r3, cpsr
|
||||||
|
|
||||||
|
orr r3, #0x1c0 @ disable Imprecise Aborts, IRQ and FIQ (equivalent to "cpsid aif" on arm11)
|
||||||
|
msr cpsr_cx, r3
|
||||||
|
|
||||||
|
tst r2, #0x20
|
||||||
|
bne noSvcBreak
|
||||||
|
cmp r1, #2
|
||||||
|
bne noSvcBreak
|
||||||
|
|
||||||
|
sub r0, lr, #4 @ calling cannotAccessAddress cause more problems that it actually solves... (I've to save a lot of regs and that's a pain tbh)
|
||||||
|
lsr r0, #20 @ we'll just do some address checks (to see if it's in ARM9 internal memory)
|
||||||
|
cmp r0, #0x80
|
||||||
|
bne noSvcBreak
|
||||||
|
ldr r4, [lr, #-4]
|
||||||
|
ldr r5, =#0xe12fff7f
|
||||||
|
cmp r4, r5
|
||||||
|
bne noSvcBreak
|
||||||
|
bic r5, r3, #0xf
|
||||||
|
orr r5, #0x3
|
||||||
|
msr cpsr_c, r5 @ switch to supervisor mode
|
||||||
|
ldmfd sp, {r8-r11}^
|
||||||
|
ldr r2, [sp, #0x1c] @ implementation details of the official svc handler
|
||||||
|
ldr r4, [sp, #0x18]
|
||||||
|
msr cpsr_c, r3 @ restore processor mode
|
||||||
|
tst r2, #0x20
|
||||||
|
addne lr, r4, #2 @ adjust address for later
|
||||||
|
moveq lr, r4
|
||||||
|
|
||||||
|
noSvcBreak:
|
||||||
|
ands r4, r2, #0xf @ get the mode that triggered the exception
|
||||||
|
moveq r4, #0xf @ usr => sys
|
||||||
|
bic r5, r3, #0xf
|
||||||
|
orr r5, r4
|
||||||
|
msr cpsr_c, r5 @ change processor mode
|
||||||
|
stmfd r6!, {r8-lr}
|
||||||
|
msr cpsr_c, r3 @ restore processor mode
|
||||||
|
mov sp, r6
|
||||||
|
|
||||||
|
stmfd sp!, {r2,lr} @ it's a bit of a mess, but we will fix that later
|
||||||
|
@ order of saved regs now: cpsr, pc + (2/4/8), r8-r14, r0-r7
|
||||||
|
|
||||||
|
mov r0, sp
|
||||||
|
|
||||||
|
b mainHandler
|
||||||
|
|
||||||
|
GEN_HANDLER FIQHandler
|
||||||
|
GEN_HANDLER undefinedInstructionHandler
|
||||||
|
GEN_HANDLER prefetchAbortHandler
|
||||||
|
GEN_HANDLER dataAbortHandler
|
||||||
|
|
||||||
|
.global readMPUConfig
|
||||||
|
.type readMPUConfig, %function
|
||||||
|
readMPUConfig:
|
||||||
|
stmfd sp!, {r4-r8, lr}
|
||||||
|
mrc p15,0,r1,c6,c0,0
|
||||||
|
mrc p15,0,r2,c6,c1,0
|
||||||
|
mrc p15,0,r3,c6,c2,0
|
||||||
|
mrc p15,0,r4,c6,c3,0
|
||||||
|
mrc p15,0,r5,c6,c4,0
|
||||||
|
mrc p15,0,r6,c6,c5,0
|
||||||
|
mrc p15,0,r7,c6,c6,0
|
||||||
|
mrc p15,0,r8,c6,c7,0
|
||||||
|
stmia r0, {r1-r8}
|
||||||
|
mrc p15,0,r0,c5,c0,2 @ read data access permission bits
|
||||||
|
ldmfd sp!, {r4-r8, pc}
|
||||||
143
exceptions/arm9/source/i2c.c
Normal file
143
exceptions/arm9/source/i2c.c
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Thanks to whoever contributed in the development of this file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "i2c.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static const struct { u8 bus_id, reg_addr; } dev_data[] = {
|
||||||
|
{0, 0x4A}, {0, 0x7A}, {0, 0x78},
|
||||||
|
{1, 0x4A}, {1, 0x78}, {1, 0x2C},
|
||||||
|
{1, 0x2E}, {1, 0x40}, {1, 0x44},
|
||||||
|
{2, 0xD6}, {2, 0xD0}, {2, 0xD2},
|
||||||
|
{2, 0xA4}, {2, 0x9A}, {2, 0xA0},
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline u8 i2cGetDeviceBusId(u8 device_id)
|
||||||
|
{
|
||||||
|
return dev_data[device_id].bus_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u8 i2cGetDeviceRegAddr(u8 device_id)
|
||||||
|
{
|
||||||
|
return dev_data[device_id].reg_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static vu8 *reg_data_addrs[] = {
|
||||||
|
(vu8 *)(I2C1_REG_OFF + I2C_REG_DATA),
|
||||||
|
(vu8 *)(I2C2_REG_OFF + I2C_REG_DATA),
|
||||||
|
(vu8 *)(I2C3_REG_OFF + I2C_REG_DATA),
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline vu8 *i2cGetDataReg(u8 bus_id)
|
||||||
|
{
|
||||||
|
return reg_data_addrs[bus_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static vu8 *reg_cnt_addrs[] = {
|
||||||
|
(vu8 *)(I2C1_REG_OFF + I2C_REG_CNT),
|
||||||
|
(vu8 *)(I2C2_REG_OFF + I2C_REG_CNT),
|
||||||
|
(vu8 *)(I2C3_REG_OFF + I2C_REG_CNT),
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline vu8 *i2cGetCntReg(u8 bus_id)
|
||||||
|
{
|
||||||
|
return reg_cnt_addrs[bus_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static inline void i2cWaitBusy(u8 bus_id)
|
||||||
|
{
|
||||||
|
while (*i2cGetCntReg(bus_id) & 0x80);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool i2cGetResult(u8 bus_id)
|
||||||
|
{
|
||||||
|
i2cWaitBusy(bus_id);
|
||||||
|
|
||||||
|
return (*i2cGetCntReg(bus_id) >> 4) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void i2cStop(u8 bus_id, u8 arg0)
|
||||||
|
{
|
||||||
|
*i2cGetCntReg(bus_id) = (arg0 << 5) | 0xC0;
|
||||||
|
i2cWaitBusy(bus_id);
|
||||||
|
*i2cGetCntReg(bus_id) = 0xC5;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static bool i2cSelectDevice(u8 bus_id, u8 dev_reg)
|
||||||
|
{
|
||||||
|
i2cWaitBusy(bus_id);
|
||||||
|
*i2cGetDataReg(bus_id) = dev_reg;
|
||||||
|
*i2cGetCntReg(bus_id) = 0xC2;
|
||||||
|
|
||||||
|
return i2cGetResult(bus_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool i2cSelectRegister(u8 bus_id, u8 reg)
|
||||||
|
{
|
||||||
|
i2cWaitBusy(bus_id);
|
||||||
|
*i2cGetDataReg(bus_id) = reg;
|
||||||
|
*i2cGetCntReg(bus_id) = 0xC0;
|
||||||
|
|
||||||
|
return i2cGetResult(bus_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data)
|
||||||
|
{
|
||||||
|
u8 bus_id = i2cGetDeviceBusId(dev_id);
|
||||||
|
u8 dev_addr = i2cGetDeviceRegAddr(dev_id);
|
||||||
|
|
||||||
|
for(u32 i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if(i2cSelectDevice(bus_id, dev_addr) && i2cSelectRegister(bus_id, reg))
|
||||||
|
{
|
||||||
|
i2cWaitBusy(bus_id);
|
||||||
|
*i2cGetDataReg(bus_id) = data;
|
||||||
|
*i2cGetCntReg(bus_id) = 0xC1;
|
||||||
|
i2cStop(bus_id, 0);
|
||||||
|
|
||||||
|
if(i2cGetResult(bus_id)) return true;
|
||||||
|
}
|
||||||
|
*i2cGetCntReg(bus_id) = 0xC5;
|
||||||
|
i2cWaitBusy(bus_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
48
exceptions/arm9/source/i2c.h
Normal file
48
exceptions/arm9/source/i2c.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Thanks to whoever contributed in the development of this file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#define I2C1_REG_OFF 0x10161000
|
||||||
|
#define I2C2_REG_OFF 0x10144000
|
||||||
|
#define I2C3_REG_OFF 0x10148000
|
||||||
|
|
||||||
|
#define I2C_REG_DATA 0
|
||||||
|
#define I2C_REG_CNT 1
|
||||||
|
#define I2C_REG_CNTEX 2
|
||||||
|
#define I2C_REG_SCL 4
|
||||||
|
|
||||||
|
#define I2C_DEV_MCU 3
|
||||||
|
#define I2C_DEV_GYRO 10
|
||||||
|
#define I2C_DEV_IR 13
|
||||||
|
|
||||||
|
bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data);
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -24,35 +24,62 @@
|
|||||||
* reasonable ways as different from the original version.
|
* reasonable ways as different from the original version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "arm9_exception_handlers.h"
|
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "screen.h"
|
#include "handlers.h"
|
||||||
|
|
||||||
#define FINAL_BUFFER 0x25000000
|
#define FINAL_BUFFER 0x25000000
|
||||||
|
|
||||||
#define REG_DUMP_SIZE 4 * 17
|
#define REG_DUMP_SIZE 4 * 17
|
||||||
#define CODE_DUMP_SIZE 48
|
#define CODE_DUMP_SIZE 48
|
||||||
|
|
||||||
static inline void dumpArm9Memory(ExceptionDumpHeader *dumpHeader, u8 *buf)
|
bool cannotAccessAddress(const void *address)
|
||||||
{
|
{
|
||||||
// Check if n3ds extra arm9 mem is enabled (if it's possible to read CFG9_EXTMEMCNT9)
|
u32 regionSettings[8];
|
||||||
u8 extmemcnt9 = 0;
|
u32 addr = (u32)address;
|
||||||
safecpy(&extmemcnt9, (const void *)0x10000200, 1);
|
|
||||||
|
|
||||||
u32 size = (extmemcnt9 & 1) ? 0x180000 : 0x100000;
|
u32 dataAccessPermissions = readMPUConfig(regionSettings);
|
||||||
dumpHeader->additionalDataSize += safecpy(buf, (const void *)0x08000000, size);
|
for(u32 i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if((dataAccessPermissions & 0xF) == 0 || (regionSettings[i] & 1) == 0)
|
||||||
|
continue; //No access / region not enabled
|
||||||
|
|
||||||
|
u32 regionAddrBase = regionSettings[i] & ~0xFFF;
|
||||||
|
u32 regionSize = 1 << (((regionSettings[i] >> 1) & 0x1F) + 1);
|
||||||
|
|
||||||
|
if(addr >= regionAddrBase && addr < regionAddrBase + regionSize)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dataAccessPermissions >>= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__((noreturn)) arm9ExceptionHandlerMain(u32 *registerDump, u32 type)
|
static u32 __attribute__((noinline)) copyMemory(void *dst, const void *src, u32 size, u32 alignment)
|
||||||
|
{
|
||||||
|
u8 *out = (u8 *)dst;
|
||||||
|
const u8 *in = (const u8 *)src;
|
||||||
|
|
||||||
|
if(((u32)src & (alignment - 1)) != 0 || cannotAccessAddress(src) || (size != 0 && cannotAccessAddress((u8 *)src + size - 1)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for(u32 i = 0; i < size; i++)
|
||||||
|
*out++ = *in++;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noreturn)) mainHandler(u32 *regs, u32 type)
|
||||||
{
|
{
|
||||||
ExceptionDumpHeader dumpHeader;
|
ExceptionDumpHeader dumpHeader;
|
||||||
|
|
||||||
|
u32 registerDump[REG_DUMP_SIZE / 4];
|
||||||
u8 codeDump[CODE_DUMP_SIZE];
|
u8 codeDump[CODE_DUMP_SIZE];
|
||||||
|
|
||||||
dumpHeader.magic[0] = 0xDEADC0DE;
|
dumpHeader.magic[0] = 0xDEADC0DE;
|
||||||
dumpHeader.magic[1] = 0xDEADCAFE;
|
dumpHeader.magic[1] = 0xDEADCAFE;
|
||||||
dumpHeader.versionMajor = 1;
|
dumpHeader.versionMajor = 1;
|
||||||
dumpHeader.versionMinor = 3;
|
dumpHeader.versionMinor = 2;
|
||||||
|
|
||||||
dumpHeader.processor = 9;
|
dumpHeader.processor = 9;
|
||||||
dumpHeader.core = 0;
|
dumpHeader.core = 0;
|
||||||
@ -62,51 +89,34 @@ void __attribute__((noreturn)) arm9ExceptionHandlerMain(u32 *registerDump, u32 t
|
|||||||
dumpHeader.codeDumpSize = CODE_DUMP_SIZE;
|
dumpHeader.codeDumpSize = CODE_DUMP_SIZE;
|
||||||
dumpHeader.additionalDataSize = 0;
|
dumpHeader.additionalDataSize = 0;
|
||||||
|
|
||||||
u32 cpsr = registerDump[16];
|
//Dump registers
|
||||||
u32 pc = registerDump[15] - (type < 3 ? (((cpsr & 0x20) != 0 && type == 1) ? 2 : 4) : 8);
|
//Current order of saved regs: cpsr, pc, r8-r14, r0-r7
|
||||||
|
u32 cpsr = regs[0];
|
||||||
|
u32 pc = regs[1] - (type < 3 ? (((cpsr & 0x20) != 0 && type == 1) ? 2 : 4) : 8);
|
||||||
|
|
||||||
registerDump[15] = pc;
|
registerDump[15] = pc;
|
||||||
|
registerDump[16] = cpsr;
|
||||||
|
for(u32 i = 0; i < 7; i++) registerDump[8 + i] = regs[2 + i];
|
||||||
|
for(u32 i = 0; i < 8; i++) registerDump[i] = regs[9 + i];
|
||||||
|
|
||||||
//Dump code
|
//Dump code
|
||||||
u8 *instr = (u8 *)pc + ((cpsr & 0x20) ? 2 : 4) - dumpHeader.codeDumpSize; //wouldn't work well on 32-bit Thumb instructions, but it isn't much of a problem
|
u8 *instr = (u8 *)pc + ((cpsr & 0x20) ? 2 : 4) - dumpHeader.codeDumpSize; //Doesn't work well on 32-bit Thumb instructions, but it isn't much of a problem
|
||||||
dumpHeader.codeDumpSize = ((u32)instr & (((cpsr & 0x20) != 0) ? 1 : 3)) != 0 ? 0 : safecpy(codeDump, instr, dumpHeader.codeDumpSize);
|
dumpHeader.codeDumpSize = copyMemory(codeDump, instr, dumpHeader.codeDumpSize, ((cpsr & 0x20) != 0) ? 2 : 4);
|
||||||
|
|
||||||
//Copy register dump and code dump
|
//Copy register dump and code dump
|
||||||
u8 *final = (u8 *)(FINAL_BUFFER + sizeof(ExceptionDumpHeader));
|
u8 *final = (u8 *)(FINAL_BUFFER + sizeof(ExceptionDumpHeader));
|
||||||
final += safecpy(final, registerDump, dumpHeader.registerDumpSize);
|
final += copyMemory(final, registerDump, dumpHeader.registerDumpSize, 1);
|
||||||
final += safecpy(final, codeDump, dumpHeader.codeDumpSize);
|
final += copyMemory(final, codeDump, dumpHeader.codeDumpSize, 1);
|
||||||
|
|
||||||
//Dump stack in place
|
//Dump stack in place
|
||||||
dumpHeader.stackDumpSize = safecpy(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF));
|
dumpHeader.stackDumpSize = copyMemory(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF), 1);
|
||||||
final += dumpHeader.stackDumpSize;
|
|
||||||
|
|
||||||
// See if we need to copy Arm9 memory (check for bkpt 0xFFFD / bkpt 0xFD)
|
|
||||||
if(dumpHeader.codeDumpSize > 0)
|
|
||||||
{
|
|
||||||
if(cpsr & 0x20)
|
|
||||||
{
|
|
||||||
// Thumb
|
|
||||||
u16 instr;
|
|
||||||
safecpy(&instr, codeDump + dumpHeader.codeDumpSize - 2, 2);
|
|
||||||
if(instr == 0xBEFD) dumpArm9Memory(&dumpHeader, final);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
u32 instr;
|
|
||||||
safecpy(&instr, codeDump + dumpHeader.codeDumpSize - 4, 4);
|
|
||||||
if(instr == 0xE12FFF7D) dumpArm9Memory(&dumpHeader, final);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize;
|
dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize;
|
||||||
|
|
||||||
//Copy header (actually optimized by the compiler)
|
//Copy header (actually optimized by the compiler)
|
||||||
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
|
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
|
||||||
|
|
||||||
if(ARESCREENSINITIALIZED) I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); //Shutdown LCD
|
|
||||||
|
|
||||||
((void (*)())0xFFFF0830)(); //Ensure that all memory transfers have completed and that the data cache has been flushed
|
((void (*)())0xFFFF0830)(); //Ensure that all memory transfers have completed and that the data cache has been flushed
|
||||||
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot
|
||||||
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot
|
|
||||||
while(true);
|
while(true);
|
||||||
}
|
}
|
||||||
35
exceptions/arm9/source/start.s
Normal file
35
exceptions/arm9/source/start.s
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
@ This file is part of Luma3DS
|
||||||
|
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
@
|
||||||
|
@ This program is free software: you can redistribute it and/or modify
|
||||||
|
@ it under the terms of the GNU General Public License as published by
|
||||||
|
@ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
@ (at your option) any later version.
|
||||||
|
@
|
||||||
|
@ This program is distributed in the hope that it will be useful,
|
||||||
|
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
@ GNU General Public License for more details.
|
||||||
|
@
|
||||||
|
@ You should have received a copy of the GNU General Public License
|
||||||
|
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
@
|
||||||
|
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
@ * Requiring preservation of specified reasonable legal notices or
|
||||||
|
@ author attributions in that material or in the Appropriate Legal
|
||||||
|
@ Notices displayed by works containing it.
|
||||||
|
@ * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
@ or requiring that modified versions of such material be marked in
|
||||||
|
@ reasonable ways as different from the original version.
|
||||||
|
|
||||||
|
.section .text.start
|
||||||
|
.align 4
|
||||||
|
.global _start
|
||||||
|
_start:
|
||||||
|
add pc, r0, #(handlers - .) @ Dummy instruction to prevent compiler optimizations
|
||||||
|
|
||||||
|
handlers:
|
||||||
|
.word FIQHandler
|
||||||
|
.word undefinedInstructionHandler
|
||||||
|
.word prefetchAbortHandler
|
||||||
|
.word dataAbortHandler
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2018 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -26,9 +26,16 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "utils.h"
|
#include <stdint.h>
|
||||||
#include "kernel.h"
|
#include <stdlib.h>
|
||||||
#include "svc.h"
|
#include <stdbool.h>
|
||||||
|
|
||||||
Result ControlMemoryUnsafe(u32 *out, u32 addr0, u32 size, MemOp op, MemPerm perm);
|
//Common data types
|
||||||
Result ControlMemoryUnsafeWrapper(u32 *out, u32 addr0, u32 size, MemOp op, MemPerm perm);
|
typedef uint8_t u8;
|
||||||
|
typedef uint16_t u16;
|
||||||
|
typedef uint32_t u32;
|
||||||
|
typedef uint64_t u64;
|
||||||
|
typedef volatile u8 vu8;
|
||||||
|
typedef volatile u16 vu16;
|
||||||
|
typedef volatile u32 vu32;
|
||||||
|
typedef volatile u64 vu64;
|
||||||
169
exceptions/exception_dump_parser.py
Normal file
169
exceptions/exception_dump_parser.py
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# Requires Python >= 3.2 or >= 2.7
|
||||||
|
|
||||||
|
# This file is part of Luma3DS
|
||||||
|
# Copyright (C) 2016 Aurora Wright, TuxSH
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified
|
||||||
|
# reasonable legal notices or author attributions in that material or in the Appropriate Legal
|
||||||
|
# Notices displayed by works containing it.
|
||||||
|
|
||||||
|
__author__ = "TuxSH"
|
||||||
|
__copyright__ = "Copyright (c) 2016 TuxSH"
|
||||||
|
__license__ = "GPLv3"
|
||||||
|
__version__ = "v1.2"
|
||||||
|
|
||||||
|
"""
|
||||||
|
Parses Luma3DS exception dumps
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from struct import unpack_from
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
# Source of hexdump: https://gist.github.com/ImmortalPC/c340564823f283fe530b
|
||||||
|
# Credits for hexdump go to the original authors
|
||||||
|
# Slightly edited by TuxSH
|
||||||
|
|
||||||
|
def hexdump(addr, src, length=16, sep='.' ):
|
||||||
|
'''
|
||||||
|
@brief Return {src} in hex dump.
|
||||||
|
@param[in] length {Int} Nb Bytes by row.
|
||||||
|
@param[in] sep {Char} For the text part, {sep} will be used for non ASCII char.
|
||||||
|
@return {Str} The hexdump
|
||||||
|
@note Full support for python2 and python3 !
|
||||||
|
'''
|
||||||
|
result = []
|
||||||
|
|
||||||
|
# Python3 support
|
||||||
|
try:
|
||||||
|
xrange(0,1)
|
||||||
|
except NameError:
|
||||||
|
xrange = range
|
||||||
|
|
||||||
|
for i in xrange(0, len(src), length):
|
||||||
|
subSrc = src[i:i+length]
|
||||||
|
hexa = ''
|
||||||
|
isMiddle = False
|
||||||
|
for h in xrange(0,len(subSrc)):
|
||||||
|
if h == length/2:
|
||||||
|
hexa += ' '
|
||||||
|
h = subSrc[h]
|
||||||
|
if not isinstance(h, int):
|
||||||
|
h = ord(h)
|
||||||
|
h = hex(h).replace('0x','')
|
||||||
|
if len(h) == 1:
|
||||||
|
h = '0'+h
|
||||||
|
hexa += h+' '
|
||||||
|
hexa = hexa.strip(' ')
|
||||||
|
text = ''
|
||||||
|
for c in subSrc:
|
||||||
|
if not isinstance(c, int):
|
||||||
|
c = ord(c)
|
||||||
|
if 0x20 <= c < 0x7F:
|
||||||
|
text += chr(c)
|
||||||
|
else:
|
||||||
|
text += sep
|
||||||
|
result.append(('%08x: %-'+str(length*(2+1)+1)+'s |%s|') % (addr + i, hexa, text))
|
||||||
|
|
||||||
|
return '\n'.join(result)
|
||||||
|
|
||||||
|
|
||||||
|
def makeRegisterLine(A, rA, B, rB):
|
||||||
|
return "{0:<15}{1:<20}{2:<15}{3:<20}".format(A, "{0:08x}".format(rA), B, "{0:08x}".format(rB))
|
||||||
|
|
||||||
|
handledExceptionNames = ("FIQ", "undefined instruction", "prefetch abort", "data abort")
|
||||||
|
registerNames = tuple("r{0}".format(i) for i in range(13)) + ("sp", "lr", "pc", "cpsr") + ("dfsr", "ifsr", "far") + ("fpexc", "fpinst", "fpinst2")
|
||||||
|
svcBreakReasons = ("(svcBreak: panic)", "(svcBreak: assertion failed)", "(svcBreak: user-related)")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Parse Luma3DS exception dumps")
|
||||||
|
parser.add_argument("filename")
|
||||||
|
args = parser.parse_args()
|
||||||
|
data = b""
|
||||||
|
with open(args.filename, "rb") as f: data = f.read()
|
||||||
|
if unpack_from("<2I", data) != (0xdeadc0de, 0xdeadcafe):
|
||||||
|
raise SystemExit("Invalid file format")
|
||||||
|
|
||||||
|
version, processor, exceptionType, _, nbRegisters, codeDumpSize, stackDumpSize, additionalDataSize = unpack_from("<8I", data, 8)
|
||||||
|
nbRegisters //= 4
|
||||||
|
|
||||||
|
if version < (1 << 16) | 2:
|
||||||
|
raise SystemExit("Incompatible format version, please use the appropriate parser.")
|
||||||
|
|
||||||
|
registers = unpack_from("<{0}I".format(nbRegisters), data, 40)
|
||||||
|
codeOffset = 40 + 4 * nbRegisters
|
||||||
|
codeDump = data[codeOffset : codeOffset + codeDumpSize]
|
||||||
|
stackOffset = codeOffset + codeDumpSize
|
||||||
|
stackDump = data[stackOffset : stackOffset + stackDumpSize]
|
||||||
|
addtionalDataOffset = stackOffset + stackDumpSize
|
||||||
|
additionalData = data[addtionalDataOffset : addtionalDataOffset + additionalDataSize]
|
||||||
|
|
||||||
|
if processor == 9: print("Processor: ARM9")
|
||||||
|
else: print("Processor: ARM11 (core {0})".format(processor >> 16))
|
||||||
|
|
||||||
|
typeDetailsStr = ""
|
||||||
|
if exceptionType == 2:
|
||||||
|
if (registers[16] & 0x20) == 0 and codeDumpSize >= 4:
|
||||||
|
instr = unpack_from("<I", codeDump[-4:])[0]
|
||||||
|
if instr == 0xe12fff7e:
|
||||||
|
typeDetailsStr = " (kernel panic)"
|
||||||
|
elif instr == 0xef00003c:
|
||||||
|
typeDetailsStr = " " + (svcBreakReasons[registers[0]] if registers[0] < 3 else "(svcBreak)")
|
||||||
|
elif (registers[16] & 0x20) == 1 and codeDumpSize >= 2:
|
||||||
|
instr = unpack_from("<I", codeDump[-4:])[0]
|
||||||
|
if instr == 0xdf3c:
|
||||||
|
typeDetailsStr = " " + (svcBreakReasons[registers[0]] if registers[0] < 3 else "(svcBreak)")
|
||||||
|
|
||||||
|
elif processor != 9 and (registers[20] & 0x80000000) != 0:
|
||||||
|
typeDetailsStr = " (VFP exception)"
|
||||||
|
|
||||||
|
print("Exception type: {0}{1}".format("unknown" if exceptionType >= len(handledExceptionNames) else handledExceptionNames[exceptionType], typeDetailsStr))
|
||||||
|
if additionalDataSize != 0:
|
||||||
|
print("Current process: {0} ({1:016x})".format(additionalData[:8].decode("ascii"), unpack_from("<Q", additionalData, 8)[0]))
|
||||||
|
|
||||||
|
print("\nRegister dump:\n")
|
||||||
|
for i in range(0, nbRegisters - (nbRegisters % 2), 2):
|
||||||
|
if i == 16: print("")
|
||||||
|
print(makeRegisterLine(registerNames[i], registers[i], registerNames[i+1], registers[i+1]))
|
||||||
|
if nbRegisters % 2 == 1: print("{0:<15}{1:<20}".format(registerNames[nbRegisters - 1], "{0:08x}".format(registers[nbRegisters - 1])))
|
||||||
|
|
||||||
|
thumb = registers[16] & 0x20 != 0
|
||||||
|
addr = registers[15] - codeDumpSize + (2 if thumb else 4)
|
||||||
|
|
||||||
|
print("\nCode dump:\n")
|
||||||
|
|
||||||
|
objdump_res = ""
|
||||||
|
try:
|
||||||
|
path = os.path.join(os.environ["DEVKITARM"], "bin", "arm-none-eabi-objdump")
|
||||||
|
if os.name == "nt":
|
||||||
|
path = ''.join((path[1], ':', path[2:])).replace('/', '\\')
|
||||||
|
|
||||||
|
objdump_res = subprocess.check_output((
|
||||||
|
path, "-marm", "-b", "binary",
|
||||||
|
"--adjust-vma="+hex(addr - codeOffset), "--start-address="+hex(addr),
|
||||||
|
"--stop-address="+hex(addr + codeDumpSize), "-D", "-z", "-M",
|
||||||
|
"reg-names-std" + (",force-thumb" if thumb else ""), args.filename
|
||||||
|
)).decode("utf-8")
|
||||||
|
objdump_res = '\n'.join(objdump_res[objdump_res.find('<.data+'):].split('\n')[1:])
|
||||||
|
except: objdump_res = ""
|
||||||
|
|
||||||
|
print(objdump_res if objdump_res != "" else hexdump(addr, codeDump))
|
||||||
|
|
||||||
|
print("\nStack dump:\n")
|
||||||
|
print(hexdump(registers[13], stackDump))
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB |
@ -1,145 +1,47 @@
|
|||||||
#---------------------------------------------------------------------------------
|
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
||||||
.SUFFIXES:
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ifeq ($(strip $(DEVKITARM)),)
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TOPDIR ?= $(CURDIR)
|
include $(DEVKITARM)/base_tools
|
||||||
include $(DEVKITARM)/base_rules
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
name := k11_extension
|
||||||
# TARGET is the name of the output
|
|
||||||
# BUILD is the directory where object files & intermediate files will be placed
|
|
||||||
# SOURCES is a list of directories containing source code
|
|
||||||
# DATA is a list of directories containing data files
|
|
||||||
# INCLUDES is a list of directories containing header files
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
TARGET := $(notdir $(CURDIR))
|
|
||||||
BUILD := build
|
|
||||||
SOURCES := source source/svc
|
|
||||||
DATA := data
|
|
||||||
INCLUDES := include include/svc
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
dir_source := source
|
||||||
# options for code generation
|
dir_include := include
|
||||||
#---------------------------------------------------------------------------------
|
dir_build := build
|
||||||
# -mgeneral-regs-only so that the C code is guaranteed not to use FPU regs
|
|
||||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -mgeneral-regs-only
|
|
||||||
DEFINES := -DARM11 -D__3DS__
|
|
||||||
|
|
||||||
FALSEPOSITIVES := -Wno-array-bounds -Wno-stringop-overflow -Wno-stringop-overread
|
ARCH := -mcpu=mpcore -mfpu=vfp
|
||||||
CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -O2 -mword-relocations \
|
ASFLAGS := $(ARCH)
|
||||||
-fomit-frame-pointer -ffunction-sections -fdata-sections \
|
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -I$(dir_include) -fno-builtin -std=c11 -Wno-main -g -flto -O2 -ffast-math \
|
||||||
-Wno-main $(FALSEPOSITIVES) $(ARCH) $(DEFINES)
|
-mword-relocations -ffunction-sections -fdata-sections
|
||||||
|
LDFLAGS := -nostdlib -Wl,--gc-sections,--nmagic $(ARCH)
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE)
|
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||||
|
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
||||||
|
$(call rwildcard, $(dir_source), *.s *.c)))
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
.PHONY: all
|
||||||
|
all: ../$(dir_build)/$(name).bin
|
||||||
|
|
||||||
ASFLAGS := -g $(ARCH)
|
.PHONY: clean
|
||||||
LDFLAGS = -specs=$(TOPDIR)/linker.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
|
||||||
|
|
||||||
LIBS :=
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# list of directories containing libraries, this must be the top level containing
|
|
||||||
# include and lib
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
LIBDIRS :=
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# no real need to edit anything past this point unless you need to add additional
|
|
||||||
# rules for different file extensions
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
|
||||||
export TOPDIR := $(CURDIR)
|
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
|
||||||
|
|
||||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
|
||||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifeq ($(strip $(CPPFILES)),)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CC)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
else
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CXX)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
|
||||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
|
||||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
|
||||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
|
||||||
|
|
||||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
|
||||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
|
||||||
-I$(CURDIR)/$(BUILD)
|
|
||||||
|
|
||||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
|
||||||
|
|
||||||
.PHONY: $(BUILD) clean all
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
all: $(BUILD)
|
|
||||||
|
|
||||||
$(BUILD):
|
|
||||||
@[ -d $@ ] || mkdir -p $@
|
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
clean:
|
clean:
|
||||||
@echo clean ...
|
@rm -rf $(dir_build)
|
||||||
@rm -fr $(BUILD) $(TARGET).elf
|
|
||||||
|
|
||||||
|
../$(dir_build)/$(name).bin: $(dir_build)/$(name).elf
|
||||||
|
$(OBJCOPY) -S -O binary $< $@
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
$(dir_build)/$(name).elf: $(objects)
|
||||||
else
|
$(CC) $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
||||||
.PHONY: all
|
|
||||||
|
|
||||||
DEPENDS := $(OFILES:.o=.d)
|
$(dir_build)/memory.o : CFLAGS += -O3 -marm
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
$(dir_build)/%.o: $(dir_source)/%.c
|
||||||
# main targets
|
@mkdir -p "$(@D)"
|
||||||
#---------------------------------------------------------------------------------
|
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||||
all : $(OUTPUT).elf
|
|
||||||
|
|
||||||
$(OUTPUT).elf : $(OFILES)
|
$(dir_build)/%.o: $(dir_source)/%.s
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
%.elf: $(OFILES)
|
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||||
@echo linking $(notdir $@)
|
include $(call rwildcard, $(dir_build), *.d)
|
||||||
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
|
||||||
@$(NM) -CSn $@ > $(notdir $*.lst)
|
|
||||||
|
|
||||||
$(OFILES_SRC) : $(HFILES_BIN)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# you need a rule like this for each extension you use as binary data
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
%.bin.o %_bin.h : %.bin
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(bin2o)
|
|
||||||
|
|
||||||
-include $(DEPENDS)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------------
|
|
||||||
|
|||||||
@ -9,10 +9,9 @@
|
|||||||
#define MULTICONFIG(a) ((cfwInfo.multiConfig >> (2 * (a))) & 3)
|
#define MULTICONFIG(a) ((cfwInfo.multiConfig >> (2 * (a))) & 3)
|
||||||
#define BOOTCONFIG(a, b) ((cfwInfo.bootConfig >> (a)) & (b))
|
#define BOOTCONFIG(a, b) ((cfwInfo.bootConfig >> (a)) & (b))
|
||||||
|
|
||||||
#define BOOTCFG_NAND BOOTCONFIG(0, 1)
|
#define BOOTCFG_NAND BOOTCONFIG(0, 7)
|
||||||
#define BOOTCFG_EMUINDEX BOOTCONFIG(1, 3)
|
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)
|
||||||
#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(3, 1)
|
#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1)
|
||||||
#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(4, 1)
|
|
||||||
|
|
||||||
enum multiOptions
|
enum multiOptions
|
||||||
{
|
{
|
||||||
@ -20,21 +19,18 @@ enum multiOptions
|
|||||||
BRIGHTNESS,
|
BRIGHTNESS,
|
||||||
SPLASH,
|
SPLASH,
|
||||||
PIN,
|
PIN,
|
||||||
NEWCPU,
|
NEWCPU
|
||||||
AUTOBOOTMODE,
|
|
||||||
FORCEAUDIOOUTPUT,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum singleOptions
|
enum singleOptions
|
||||||
{
|
{
|
||||||
AUTOBOOTEMU = 0,
|
AUTOBOOTEMU = 0,
|
||||||
|
USEEMUFIRM,
|
||||||
LOADEXTFIRMSANDMODULES,
|
LOADEXTFIRMSANDMODULES,
|
||||||
PATCHGAMES,
|
PATCHGAMES,
|
||||||
REDIRECTAPPTHREADS,
|
|
||||||
PATCHVERSTRING,
|
PATCHVERSTRING,
|
||||||
SHOWGBABOOT,
|
SHOWGBABOOT,
|
||||||
|
PATCHACCESS,
|
||||||
PATCHUNITINFO,
|
PATCHUNITINFO,
|
||||||
ENABLEDSIEXTFILTER,
|
DISABLEARM11EXCHANDLERS
|
||||||
DISABLEARM11EXCHANDLERS,
|
|
||||||
ENABLESAFEFIRMROSALINA,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "globals.h"
|
|
||||||
#include "kernel.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
extern KRecursiveLock dbgParamsLock;
|
|
||||||
extern u32 dbgParamWatchpointId, dbgParamDVA, dbgParamWCR, dbgParamContextId;
|
|
||||||
|
|
||||||
KSchedulableInterruptEvent *enableMonitorModeDebugging(KBaseInterruptEvent *this, u32 interruptID);
|
|
||||||
KSchedulableInterruptEvent *disableWatchpoint(KBaseInterruptEvent *this, u32 interruptID);
|
|
||||||
KSchedulableInterruptEvent *setWatchpointWithContextId(KBaseInterruptEvent *this, u32 interruptID);
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -36,7 +36,7 @@ void undefinedInstructionHandler(void);
|
|||||||
void prefetchAbortHandler(void);
|
void prefetchAbortHandler(void);
|
||||||
void dataAbortHandler(void);
|
void dataAbortHandler(void);
|
||||||
|
|
||||||
typedef struct
|
typedef struct __attribute__((packed))
|
||||||
{
|
{
|
||||||
u32 magic[2];
|
u32 magic[2];
|
||||||
u16 versionMinor, versionMajor;
|
u16 versionMinor, versionMajor;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
extern KRecursiveLock *criticalSectionLock;
|
extern KRecursiveLock *criticalSectionLock;
|
||||||
extern KObjectList *threadList;
|
extern KObjectList *threadList;
|
||||||
extern KObjectList *resourceLimitList;
|
|
||||||
extern KObjectMutex *synchronizationMutex;
|
extern KObjectMutex *synchronizationMutex;
|
||||||
|
|
||||||
extern void (*KRecursiveLock__Lock)(KRecursiveLock *this);
|
extern void (*KRecursiveLock__Lock)(KRecursiveLock *this);
|
||||||
@ -45,27 +44,17 @@ extern KAutoObject * (*KProcessHandleTable__ToKAutoObject)(KProcessHandleTable *
|
|||||||
extern void (*KSynchronizationObject__Signal)(KSynchronizationObject *this, bool isPulse);
|
extern void (*KSynchronizationObject__Signal)(KSynchronizationObject *this, bool isPulse);
|
||||||
extern Result (*WaitSynchronization1)(void *this_unused, KThread *thread, KSynchronizationObject *syncObject, s64 timeout);
|
extern Result (*WaitSynchronization1)(void *this_unused, KThread *thread, KSynchronizationObject *syncObject, s64 timeout);
|
||||||
extern Result (*KProcessHandleTable__CreateHandle)(KProcessHandleTable *this, Handle *out, KAutoObject *obj, u8 token);
|
extern Result (*KProcessHandleTable__CreateHandle)(KProcessHandleTable *this, Handle *out, KAutoObject *obj, u8 token);
|
||||||
extern Result (*KProcessHwInfo__QueryMemory)(KProcessHwInfo *this, MemoryInfo *memoryInfo, PageInfo *pageInfo, void *address);
|
|
||||||
extern Result (*KProcessHwInfo__MapProcessMemory)(KProcessHwInfo *this, KProcessHwInfo *other, void *dst, void *src, u32 nbPages);
|
extern Result (*KProcessHwInfo__MapProcessMemory)(KProcessHwInfo *this, KProcessHwInfo *other, void *dst, void *src, u32 nbPages);
|
||||||
extern Result (*KProcessHwInfo__UnmapProcessMemory)(KProcessHwInfo *this, void *addr, u32 nbPages);
|
extern Result (*KProcessHwInfo__UnmapProcessMemory)(KProcessHwInfo *this, void *addr, u32 nbPages);
|
||||||
extern Result (*KProcessHwInfo__CheckVaState)(KProcessHwInfo *hwInfo, u32 va, u32 size, u32 state, u32 perm);
|
|
||||||
extern Result (*KProcessHwInfo__GetListOfKBlockInfoForVA)(KProcessHwInfo *hwInfo, KLinkedList *list, u32 va, u32 sizeInPage);
|
|
||||||
extern Result (*KProcessHwInfo__MapListOfKBlockInfo)(KProcessHwInfo *this, u32 va, KLinkedList *list, u32 state, u32 perm, u32 sbz);
|
|
||||||
extern Result (*KEvent__Clear)(KEvent *this);
|
extern Result (*KEvent__Clear)(KEvent *this);
|
||||||
extern Result (*KEvent__Signal)(KEvent *this);
|
|
||||||
extern void (*KObjectMutex__WaitAndAcquire)(KObjectMutex *this);
|
extern void (*KObjectMutex__WaitAndAcquire)(KObjectMutex *this);
|
||||||
extern void (*KObjectMutex__ErrorOccured)(void);
|
extern void (*KObjectMutex__ErrorOccured)(void);
|
||||||
|
|
||||||
extern void (*KScheduler__AdjustThread)(KScheduler *this, KThread *thread, u32 oldSchedulingMask);
|
extern void (*KScheduler__AdjustThread)(KScheduler *this, KThread *thread, u32 oldSchedulingMask);
|
||||||
extern void (*KScheduler__AttemptSwitchingThreadContext)(KScheduler *this);
|
extern void (*KScheduler__AttemptSwitchingThreadContext)(KScheduler *this);
|
||||||
|
|
||||||
extern void (*KLinkedList_KBlockInfo__Clear)(KLinkedList *list);
|
|
||||||
|
|
||||||
extern Result (*ControlMemory)(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
|
extern Result (*ControlMemory)(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
|
||||||
extern Result (*doControlMemory)(KProcessHwInfo *this, u32 addr, u32 requestedNbPages, u32 pa, u32 state, u32 perm, u32 a7, u32 region);
|
|
||||||
extern Result (*CreateThread)(Handle *outThreadHandle, u32 ep, u32 arg, u32 stackTop, s32 priority, s32 processorId);
|
|
||||||
extern void (*SleepThread)(s64 ns);
|
extern void (*SleepThread)(s64 ns);
|
||||||
extern Result (*CreateEvent)(Handle *out, ResetType resetType);
|
|
||||||
extern Result (*CloseHandle)(Handle handle);
|
extern Result (*CloseHandle)(Handle handle);
|
||||||
extern Result (*GetHandleInfo)(s64 *out, Handle handle, u32 type);
|
extern Result (*GetHandleInfo)(s64 *out, Handle handle, u32 type);
|
||||||
extern Result (*GetSystemInfo)(s64 *out, s32 type, s32 param);
|
extern Result (*GetSystemInfo)(s64 *out, s32 type, s32 param);
|
||||||
@ -76,7 +65,6 @@ extern Result (*SendSyncRequest)(Handle handle);
|
|||||||
extern Result (*OpenProcess)(Handle *out, u32 processId);
|
extern Result (*OpenProcess)(Handle *out, u32 processId);
|
||||||
extern Result (*GetProcessId)(u32 *out, Handle process);
|
extern Result (*GetProcessId)(u32 *out, Handle process);
|
||||||
extern Result (*DebugActiveProcess)(Handle *out, u32 processId);
|
extern Result (*DebugActiveProcess)(Handle *out, u32 processId);
|
||||||
extern Result (*SignalEvent)(Handle event);
|
|
||||||
extern Result (*UnmapProcessMemory)(Handle processHandle, void *dst, u32 size);
|
extern Result (*UnmapProcessMemory)(Handle processHandle, void *dst, u32 size);
|
||||||
extern Result (*KernelSetState)(u32 type, u32 varg1, u32 varg2, u32 varg3);
|
extern Result (*KernelSetState)(u32 type, u32 varg1, u32 varg2, u32 varg3);
|
||||||
|
|
||||||
@ -109,7 +97,6 @@ extern bool *isDevUnit;
|
|||||||
extern vu8 *configPage;
|
extern vu8 *configPage;
|
||||||
extern u32 kernelVersion;
|
extern u32 kernelVersion;
|
||||||
extern FcramLayout fcramLayout;
|
extern FcramLayout fcramLayout;
|
||||||
extern FcramDescriptor *fcramDescriptor;
|
|
||||||
|
|
||||||
extern KCoreContext *coreCtxs;
|
extern KCoreContext *coreCtxs;
|
||||||
|
|
||||||
@ -123,19 +110,9 @@ extern Result (*InterruptManager__MapInterrupt)(InterruptManager *manager, KBase
|
|||||||
extern InterruptManager *interruptManager;
|
extern InterruptManager *interruptManager;
|
||||||
extern KBaseInterruptEvent *customInterruptEvent;
|
extern KBaseInterruptEvent *customInterruptEvent;
|
||||||
|
|
||||||
extern void (*initFPU)(void);
|
extern void (*initFPU)(void);
|
||||||
extern void (*mcuReboot)(void);
|
extern void (*mcuReboot)(void);
|
||||||
extern void (*coreBarrier)(void);
|
extern void (*coreBarrier)(void);
|
||||||
extern void* (*kAlloc)(FcramDescriptor *fcramDesc, u32 nbPages, u32 alignment, u32 region);
|
|
||||||
|
|
||||||
typedef struct ScreenFiltersCfgData {
|
|
||||||
u16 cct;
|
|
||||||
bool invert;
|
|
||||||
u8 colorCurveCorrection;
|
|
||||||
s64 gammaEnc;
|
|
||||||
s64 contrastEnc;
|
|
||||||
s64 brightnessEnc;
|
|
||||||
} ScreenFiltersCfgData;
|
|
||||||
|
|
||||||
typedef struct CfwInfo
|
typedef struct CfwInfo
|
||||||
{
|
{
|
||||||
@ -150,43 +127,11 @@ typedef struct CfwInfo
|
|||||||
|
|
||||||
u16 configFormatVersionMajor, configFormatVersionMinor;
|
u16 configFormatVersionMajor, configFormatVersionMinor;
|
||||||
u32 config, multiConfig, bootConfig;
|
u32 config, multiConfig, bootConfig;
|
||||||
u32 splashDurationMsec;
|
|
||||||
s8 volumeSliderOverride;
|
|
||||||
u64 hbldr3dsxTitleId;
|
u64 hbldr3dsxTitleId;
|
||||||
u32 rosalinaMenuCombo;
|
u32 rosalinaMenuCombo;
|
||||||
u32 pluginLoaderFlags;
|
|
||||||
s16 ntpTzOffetMinutes;
|
|
||||||
|
|
||||||
ScreenFiltersCfgData topScreenFilter;
|
|
||||||
ScreenFiltersCfgData bottomScreenFilter;
|
|
||||||
|
|
||||||
u64 autobootTwlTitleId;
|
|
||||||
u8 autobootCtrAppmemtype;
|
|
||||||
|
|
||||||
u16 launchedPath[80+1];
|
|
||||||
} CfwInfo;
|
} CfwInfo;
|
||||||
|
|
||||||
extern CfwInfo cfwInfo;
|
extern CfwInfo cfwInfo;
|
||||||
extern u32 kextBasePa;
|
|
||||||
extern u32 stolenSystemMemRegionSize;
|
|
||||||
extern bool disableThreadRedirection;
|
|
||||||
|
|
||||||
extern vu32 rosalinaState;
|
extern vu32 rosalinaState;
|
||||||
extern bool hasStartedRosalinaNetworkFuncsOnce;
|
extern bool hasStartedRosalinaNetworkFuncsOnce;
|
||||||
extern KEvent* signalPluginEvent;
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
PLG_CFG_NONE = 0,
|
|
||||||
PLG_CFG_RUNNING = 1,
|
|
||||||
PLG_CFG_INHOME = 2,
|
|
||||||
PLG_CFG_EXITING = 3,
|
|
||||||
|
|
||||||
PLG_CFG_HOME_EVENT = 1 << 16,
|
|
||||||
PLG_CFG_EXIT_EVENT = 2 << 16
|
|
||||||
} PLG_CFG_STATUS;
|
|
||||||
|
|
||||||
void PLG_SignalEvent(u32 event);
|
|
||||||
void PLG__WakeAppThread(void);
|
|
||||||
u32 PLG_GetStatus(void);
|
|
||||||
KLinkedList* KLinkedList__Initialize(KLinkedList *list);
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -57,4 +57,5 @@ void SessionInfo_Add(KSession *session, const char *name);
|
|||||||
void SessionInfo_Remove(KSession *session);
|
void SessionInfo_Remove(KSession *session);
|
||||||
|
|
||||||
bool doLangEmu(Result *res, u32 *cmdbuf);
|
bool doLangEmu(Result *res, u32 *cmdbuf);
|
||||||
|
Result doPublishToProcessHook(Handle handle, u32 *cmdbuf);
|
||||||
bool doErrfThrowHook(u32 *cmdbuf);
|
bool doErrfThrowHook(u32 *cmdbuf);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -27,7 +27,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
extern u32 kernelVersion;
|
extern u32 kernelVersion;
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ struct KMutexLinkedList;
|
|||||||
struct KPreemptionTimer;
|
struct KPreemptionTimer;
|
||||||
|
|
||||||
/* 12 */
|
/* 12 */
|
||||||
typedef struct CTR_ALIGN(4) KAutoObject
|
typedef struct ALIGN(4) KAutoObject
|
||||||
{
|
{
|
||||||
struct Vtable__KAutoObject *vtable;
|
struct Vtable__KAutoObject *vtable;
|
||||||
u32 refCount;
|
u32 refCount;
|
||||||
@ -96,7 +95,7 @@ typedef struct KMutexLinkedListNode
|
|||||||
} KMutexLinkedListNode;
|
} KMutexLinkedListNode;
|
||||||
|
|
||||||
/* 1 */
|
/* 1 */
|
||||||
typedef struct CTR_ALIGN(4) KMutex
|
typedef struct ALIGN(4) KMutex
|
||||||
{
|
{
|
||||||
KSynchronizationObject syncObject;
|
KSynchronizationObject syncObject;
|
||||||
KMutexLinkedListNode mutexListNode;
|
KMutexLinkedListNode mutexListNode;
|
||||||
@ -106,14 +105,6 @@ typedef struct CTR_ALIGN(4) KMutex
|
|||||||
union KProcess *owner;
|
union KProcess *owner;
|
||||||
} KMutex;
|
} KMutex;
|
||||||
|
|
||||||
typedef struct KAddressArbiter
|
|
||||||
{
|
|
||||||
KAutoObject autoObject;
|
|
||||||
struct KThread *first;
|
|
||||||
struct KThread *last;
|
|
||||||
union KProcess *owner;
|
|
||||||
} KAddressArbiter;
|
|
||||||
|
|
||||||
/* 92 */
|
/* 92 */
|
||||||
typedef struct KMutexLinkedList
|
typedef struct KMutexLinkedList
|
||||||
{
|
{
|
||||||
@ -121,30 +112,6 @@ typedef struct KMutexLinkedList
|
|||||||
KMutex *last;
|
KMutex *last;
|
||||||
} KMutexLinkedList;
|
} KMutexLinkedList;
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
TOKEN_KAUTOOBJECT = 0,
|
|
||||||
TOKEN_KSYNCHRONIZATIONOBJECT = 1,
|
|
||||||
TOKEN_KEVENT = 0x1F,
|
|
||||||
TOKEN_KSEMAPHORE = 0x2F,
|
|
||||||
TOKEN_KTIMER = 0x35,
|
|
||||||
TOKEN_KMUTEX = 0x39,
|
|
||||||
TOKEN_KDEBUG = 0x4D,
|
|
||||||
TOKEN_KSERVERPORT = 0x55,
|
|
||||||
TOKEN_KDMAOBJECT = 0x59,
|
|
||||||
TOKEN_KCLIENTPORT = 0x65,
|
|
||||||
TOKEN_KCODESET = 0x68,
|
|
||||||
TOKEN_KSESSION = 0x70,
|
|
||||||
TOKEN_KTHREAD = 0x8D,
|
|
||||||
TOKEN_KSERVERSESSION = 0x95,
|
|
||||||
TOKEN_KADDRESSARBITER = 0x98,
|
|
||||||
TOKEN_KCLIENTSESSION = 0xA5,
|
|
||||||
TOKEN_KPORT = 0xA8,
|
|
||||||
TOKEN_KSHAREDMEMORY = 0xB0,
|
|
||||||
TOKEN_KPROCESS = 0xC5,
|
|
||||||
TOKEN_KRESOURCELIMIT = 0xC8
|
|
||||||
};
|
|
||||||
|
|
||||||
/* 45 */
|
/* 45 */
|
||||||
typedef struct KClassToken
|
typedef struct KClassToken
|
||||||
{
|
{
|
||||||
@ -153,7 +120,7 @@ typedef struct KClassToken
|
|||||||
} KClassToken;
|
} KClassToken;
|
||||||
|
|
||||||
/* 44 */
|
/* 44 */
|
||||||
typedef struct CTR_ALIGN(4) Vtable__KAutoObject
|
typedef struct ALIGN(4) Vtable__KAutoObject
|
||||||
{
|
{
|
||||||
void *field_0;
|
void *field_0;
|
||||||
void *field_4;
|
void *field_4;
|
||||||
@ -174,7 +141,7 @@ typedef struct KBaseInterruptEvent
|
|||||||
} KBaseInterruptEvent;
|
} KBaseInterruptEvent;
|
||||||
|
|
||||||
/* 55 */
|
/* 55 */
|
||||||
typedef struct CTR_ALIGN(4) Vtable__KBaseInterruptEvent
|
typedef struct ALIGN(4) Vtable__KBaseInterruptEvent
|
||||||
{
|
{
|
||||||
struct KSchedulableInterruptEvent *(*handleInterruptEvent)(KBaseInterruptEvent *, u32);
|
struct KSchedulableInterruptEvent *(*handleInterruptEvent)(KBaseInterruptEvent *, u32);
|
||||||
} Vtable__KBaseInterruptEvent;
|
} Vtable__KBaseInterruptEvent;
|
||||||
@ -210,7 +177,7 @@ typedef struct KThreadLinkedListNode
|
|||||||
|
|
||||||
|
|
||||||
/* 93 */
|
/* 93 */
|
||||||
typedef struct CTR_ALIGN(4) KPreemptionTimer
|
typedef struct ALIGN(4) KPreemptionTimer
|
||||||
{
|
{
|
||||||
u32 nLimitedTicks;
|
u32 nLimitedTicks;
|
||||||
u32 timer;
|
u32 timer;
|
||||||
@ -219,7 +186,7 @@ typedef struct CTR_ALIGN(4) KPreemptionTimer
|
|||||||
} KPreemptionTimer;
|
} KPreemptionTimer;
|
||||||
|
|
||||||
/* 15 */
|
/* 15 */
|
||||||
typedef struct CTR_PACKED CTR_ALIGN(4) KThread
|
typedef struct PACKED ALIGN(4) KThread
|
||||||
{
|
{
|
||||||
KSynchronizationObject syncObject;
|
KSynchronizationObject syncObject;
|
||||||
KTimeableInterruptEvent timeableInterruptEvent;
|
KTimeableInterruptEvent timeableInterruptEvent;
|
||||||
@ -277,7 +244,7 @@ typedef enum ProcessStatus
|
|||||||
} ProcessStatus;
|
} ProcessStatus;
|
||||||
|
|
||||||
/* 3 */
|
/* 3 */
|
||||||
typedef struct CTR_ALIGN(4) HandleDescriptor
|
typedef struct ALIGN(4) HandleDescriptor
|
||||||
{
|
{
|
||||||
u32 info;
|
u32 info;
|
||||||
KAutoObject *pointer;
|
KAutoObject *pointer;
|
||||||
@ -297,7 +264,7 @@ typedef struct KProcessHandleTable
|
|||||||
} KProcessHandleTable;
|
} KProcessHandleTable;
|
||||||
|
|
||||||
/* 4 */
|
/* 4 */
|
||||||
typedef struct CTR_ALIGN(4) KDebugThread
|
typedef struct ALIGN(4) KDebugThread
|
||||||
{
|
{
|
||||||
KThread *linkedThread;
|
KThread *linkedThread;
|
||||||
bool usedSvcBreak;
|
bool usedSvcBreak;
|
||||||
@ -355,7 +322,7 @@ typedef enum {
|
|||||||
} ExceptionEventType;
|
} ExceptionEventType;
|
||||||
|
|
||||||
/* 6 */
|
/* 6 */
|
||||||
typedef struct CTR_ALIGN(4) KDebug
|
typedef struct ALIGN(4) KDebug
|
||||||
{
|
{
|
||||||
KSynchronizationObject syncObject;
|
KSynchronizationObject syncObject;
|
||||||
KSendableInterruptEvent sendableInterruptEvent;
|
KSendableInterruptEvent sendableInterruptEvent;
|
||||||
@ -422,7 +389,7 @@ typedef struct KCodeSetMemDescriptor
|
|||||||
} KCodeSetMemDescriptor;
|
} KCodeSetMemDescriptor;
|
||||||
|
|
||||||
/* 5 */
|
/* 5 */
|
||||||
typedef struct CTR_PACKED CTR_ALIGN(4) KCodeSet
|
typedef struct PACKED ALIGN(4) KCodeSet
|
||||||
{
|
{
|
||||||
KAutoObject autoObject;
|
KAutoObject autoObject;
|
||||||
KCodeSetMemDescriptor textSection;
|
KCodeSetMemDescriptor textSection;
|
||||||
@ -497,7 +464,7 @@ typedef struct KUserBindableInterruptEvent
|
|||||||
} KUserBindableInterruptEvent;
|
} KUserBindableInterruptEvent;
|
||||||
|
|
||||||
/* 14 */
|
/* 14 */
|
||||||
typedef struct CTR_ALIGN(4) KEvent
|
typedef struct ALIGN(4) KEvent
|
||||||
{
|
{
|
||||||
KSynchronizationObject syncObject;
|
KSynchronizationObject syncObject;
|
||||||
KUserBindableInterruptEvent userBindableInterruptEvent;
|
KUserBindableInterruptEvent userBindableInterruptEvent;
|
||||||
@ -521,9 +488,6 @@ typedef enum MemOp
|
|||||||
MEMOP_REGION_SYSTEM = 0x200,
|
MEMOP_REGION_SYSTEM = 0x200,
|
||||||
MEMOP_REGION_BASE = 0x300,
|
MEMOP_REGION_BASE = 0x300,
|
||||||
MEMOP_LINEAR = 0x10000,
|
MEMOP_LINEAR = 0x10000,
|
||||||
|
|
||||||
MEMOP_OP_MASK = 0xFF,
|
|
||||||
MEMOP_REGION_MASK = 0xF00,
|
|
||||||
} MemOp;
|
} MemOp;
|
||||||
|
|
||||||
/* 17 */
|
/* 17 */
|
||||||
@ -576,20 +540,6 @@ typedef struct KBlockInfo
|
|||||||
u32 pageCount;
|
u32 pageCount;
|
||||||
} KBlockInfo;
|
} KBlockInfo;
|
||||||
|
|
||||||
typedef struct KSharedMemory
|
|
||||||
{
|
|
||||||
KAutoObject autoObject;
|
|
||||||
KLinkedList ownedKBlockInfo;
|
|
||||||
union KProcess *owner;
|
|
||||||
u32 ownerPermissions;
|
|
||||||
u32 otherPermissions;
|
|
||||||
u8 isBlockInfoGenerated;
|
|
||||||
s8 allBlockInfoGenerated;
|
|
||||||
u8 unknown_1;
|
|
||||||
u8 unknown_2;
|
|
||||||
u32 address;
|
|
||||||
} KSharedMemory;
|
|
||||||
|
|
||||||
/* 25 */
|
/* 25 */
|
||||||
typedef struct KMemoryBlock
|
typedef struct KMemoryBlock
|
||||||
{
|
{
|
||||||
@ -601,7 +551,7 @@ typedef struct KMemoryBlock
|
|||||||
} KMemoryBlock;
|
} KMemoryBlock;
|
||||||
|
|
||||||
/* 28 */
|
/* 28 */
|
||||||
typedef struct CTR_ALIGN(4) KScheduler
|
typedef struct ALIGN(4) KScheduler
|
||||||
{
|
{
|
||||||
KSchedulableInterruptEvent interruptEvent;
|
KSchedulableInterruptEvent interruptEvent;
|
||||||
u32 threadSwitchAttempts;
|
u32 threadSwitchAttempts;
|
||||||
@ -619,7 +569,7 @@ typedef struct CTR_ALIGN(4) KScheduler
|
|||||||
} KScheduler;
|
} KScheduler;
|
||||||
|
|
||||||
/* 46 */
|
/* 46 */
|
||||||
typedef struct CTR_PACKED CodeSetInfo
|
typedef struct PACKED CodeSetInfo
|
||||||
{
|
{
|
||||||
char name[8];
|
char name[8];
|
||||||
u16 unknown_1;
|
u16 unknown_1;
|
||||||
@ -639,7 +589,7 @@ typedef struct CTR_PACKED CodeSetInfo
|
|||||||
} CodeSetInfo;
|
} CodeSetInfo;
|
||||||
|
|
||||||
/* 53 */
|
/* 53 */
|
||||||
typedef struct CTR_ALIGN(4) InterruptData
|
typedef struct ALIGN(4) InterruptData
|
||||||
{
|
{
|
||||||
KBaseInterruptEvent *interruptEvent;
|
KBaseInterruptEvent *interruptEvent;
|
||||||
bool disableUponReceipt;
|
bool disableUponReceipt;
|
||||||
@ -740,7 +690,7 @@ typedef enum ResetType
|
|||||||
} ResetType;
|
} ResetType;
|
||||||
|
|
||||||
/* 81 */
|
/* 81 */
|
||||||
typedef struct CTR_PACKED CTR_ALIGN(4) KTimer
|
typedef struct PACKED ALIGN(4) KTimer
|
||||||
{
|
{
|
||||||
KSynchronizationObject syncObject;
|
KSynchronizationObject syncObject;
|
||||||
KTimeableInterruptEvent timeableInterruptEvent;
|
KTimeableInterruptEvent timeableInterruptEvent;
|
||||||
@ -768,7 +718,7 @@ typedef KSchedulableInterruptEvent KThreadTerminationInterruptEvent;
|
|||||||
typedef KSchedulableInterruptEvent KThreadExitInterruptEvent;
|
typedef KSchedulableInterruptEvent KThreadExitInterruptEvent;
|
||||||
|
|
||||||
/* 89 */
|
/* 89 */
|
||||||
typedef struct CTR_ALIGN(4) KInterruptEventMailbox
|
typedef struct ALIGN(4) KInterruptEventMailbox
|
||||||
{
|
{
|
||||||
u32 mailboxID;
|
u32 mailboxID;
|
||||||
KSendableInterruptEvent *first;
|
KSendableInterruptEvent *first;
|
||||||
@ -795,7 +745,7 @@ typedef enum LimitableResource
|
|||||||
} LimitableResource;
|
} LimitableResource;
|
||||||
|
|
||||||
/* 99 */
|
/* 99 */
|
||||||
typedef struct CTR_ALIGN(4) CpuRegisters
|
typedef struct ALIGN(4) CpuRegisters
|
||||||
{
|
{
|
||||||
u32 r[13];
|
u32 r[13];
|
||||||
u32 sp;
|
u32 sp;
|
||||||
@ -809,7 +759,7 @@ typedef struct FpuRegisters
|
|||||||
{
|
{
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
struct CTR_PACKED { double d[16]; };
|
struct PACKED { double d[16]; };
|
||||||
float s[32];
|
float s[32];
|
||||||
};
|
};
|
||||||
u32 fpscr;
|
u32 fpscr;
|
||||||
@ -974,7 +924,7 @@ typedef struct KEventInfo
|
|||||||
};
|
};
|
||||||
} KEventInfo;
|
} KEventInfo;
|
||||||
|
|
||||||
typedef struct CTR_ALIGN(0x1000) KCoreObjectContext
|
typedef struct ALIGN(0x1000) KCoreObjectContext
|
||||||
{
|
{
|
||||||
KThread *volatile currentThread;
|
KThread *volatile currentThread;
|
||||||
union KProcess *volatile currentProcess;
|
union KProcess *volatile currentProcess;
|
||||||
@ -1004,7 +954,7 @@ extern KCoreContext *coreCtxs;
|
|||||||
|
|
||||||
#define DEFINE_CONSOLE_SPECIFIC_STRUCTS(console, nbCores)
|
#define DEFINE_CONSOLE_SPECIFIC_STRUCTS(console, nbCores)
|
||||||
/* 60 */
|
/* 60 */
|
||||||
typedef struct CTR_ALIGN(4) KProcessHwInfoN3DS
|
typedef struct ALIGN(4) KProcessHwInfoN3DS
|
||||||
{
|
{
|
||||||
KObjectMutex mutex;
|
KObjectMutex mutex;
|
||||||
u32 processTLBEntriesNeedToBeFlushedOnCore[4];
|
u32 processTLBEntriesNeedToBeFlushedOnCore[4];
|
||||||
@ -1023,7 +973,7 @@ typedef struct CTR_ALIGN(4) KProcessHwInfoN3DS
|
|||||||
u32 *mmuTableVA;
|
u32 *mmuTableVA;
|
||||||
} KProcessHwInfoN3DS;
|
} KProcessHwInfoN3DS;
|
||||||
|
|
||||||
typedef struct CTR_ALIGN(4) KProcessHwInfoO3DS8x
|
typedef struct ALIGN(4) KProcessHwInfoO3DS8x
|
||||||
{
|
{
|
||||||
KObjectMutex mutex;
|
KObjectMutex mutex;
|
||||||
u32 processTLBEntriesNeedToBeFlushedOnCore[2];
|
u32 processTLBEntriesNeedToBeFlushedOnCore[2];
|
||||||
@ -1042,7 +992,7 @@ typedef struct CTR_ALIGN(4) KProcessHwInfoO3DS8x
|
|||||||
u32 *mmuTableVA;
|
u32 *mmuTableVA;
|
||||||
} KProcessHwInfoO3DS8x;
|
} KProcessHwInfoO3DS8x;
|
||||||
|
|
||||||
typedef struct CTR_ALIGN(4) KProcessHwInfoO3DSPre8x
|
typedef struct ALIGN(4) KProcessHwInfoO3DSPre8x
|
||||||
{
|
{
|
||||||
KObjectMutex mutex;
|
KObjectMutex mutex;
|
||||||
u32 processTLBEntriesNeedToBeFlushedOnCore[2];
|
u32 processTLBEntriesNeedToBeFlushedOnCore[2];
|
||||||
@ -1087,24 +1037,10 @@ typedef struct KProcess##sys\
|
|||||||
KThread *mainThread;\
|
KThread *mainThread;\
|
||||||
u32 interruptEnabledFlags[4];\
|
u32 interruptEnabledFlags[4];\
|
||||||
KProcessHandleTable handleTable;\
|
KProcessHandleTable handleTable;\
|
||||||
/* Custom fields for plugin system */ \
|
u8 gap234[52];\
|
||||||
/* { */ \
|
|
||||||
u32 customFlags; /* see KProcess_CustomFlags enum below */ \
|
|
||||||
Handle onMemoryLayoutChangeEvent;\
|
|
||||||
/* } */ \
|
|
||||||
u8 gap234[44];\
|
|
||||||
u64 unused;\
|
u64 unused;\
|
||||||
} KProcess##sys;
|
} KProcess##sys;
|
||||||
|
|
||||||
enum KProcess_CustomFlags
|
|
||||||
{
|
|
||||||
ForceRWXPages = 1 << 0,
|
|
||||||
SignalOnMemLayoutChanges = 1 << 1,
|
|
||||||
SignalOnExit = 1 << 2,
|
|
||||||
|
|
||||||
MemLayoutChanged = 1 << 16
|
|
||||||
};
|
|
||||||
|
|
||||||
INSTANCIATE_KPROCESS(N3DS);
|
INSTANCIATE_KPROCESS(N3DS);
|
||||||
INSTANCIATE_KPROCESS(O3DS8x);
|
INSTANCIATE_KPROCESS(O3DS8x);
|
||||||
INSTANCIATE_KPROCESS(O3DSPre8x);
|
INSTANCIATE_KPROCESS(O3DSPre8x);
|
||||||
@ -1190,49 +1126,27 @@ typedef union KCacheMaintenanceInterruptEvent
|
|||||||
|
|
||||||
typedef struct FcramLayout
|
typedef struct FcramLayout
|
||||||
{
|
{
|
||||||
u32 applicationAddr;
|
void *applicationAddr;
|
||||||
u32 applicationSize;
|
u32 applicationSize;
|
||||||
u32 systemAddr;
|
void *systemAddr;
|
||||||
u32 systemSize;
|
u32 systemSize;
|
||||||
u32 baseAddr;
|
void *baseAddr;
|
||||||
u32 baseSize;
|
u32 baseSize;
|
||||||
} FcramLayout;
|
} FcramLayout;
|
||||||
|
|
||||||
typedef struct RegionDescriptor
|
|
||||||
{
|
|
||||||
void *firstMemoryBlock;
|
|
||||||
void *lastMemoryBlock;
|
|
||||||
void *regionStart;
|
|
||||||
u32 regionSizeInBytes;
|
|
||||||
} RegionDescriptor;
|
|
||||||
|
|
||||||
typedef struct FcramDescriptor
|
|
||||||
{
|
|
||||||
RegionDescriptor appRegion;
|
|
||||||
RegionDescriptor sysRegion;
|
|
||||||
RegionDescriptor baseRegion;
|
|
||||||
RegionDescriptor * regionDescsPtr;
|
|
||||||
u32 fcramStart;
|
|
||||||
u32 fcramSizeInPages;
|
|
||||||
u32 baseMemoryStart;
|
|
||||||
u32 kernelUsageInBytes;
|
|
||||||
u32 unknown;
|
|
||||||
KObjectMutex mutex;
|
|
||||||
} FcramDescriptor;
|
|
||||||
|
|
||||||
extern bool isN3DS;
|
extern bool isN3DS;
|
||||||
extern void *officialSVCs[0x7E];
|
extern void *officialSVCs[0x7E];
|
||||||
|
|
||||||
#define KPROCESSRELATED_OFFSETOFF(classname, field) (isN3DS ? offsetof(classname##N3DS, field) :\
|
#define KPROCESSRELATED_OFFSETOFF(classname, field) (isN3DS ? offsetof(classname##N3DS, field) :\
|
||||||
((GET_VERSION_MINOR(kernelVersion) >= 44) ? offsetof(classname##O3DS8x, field) :\
|
((kernelVersion >= SYSTEM_VERSION(2, 44, 6)) ? offsetof(classname##O3DS8x, field) :\
|
||||||
offsetof(classname##O3DSPre8x, field)))
|
offsetof(classname##O3DSPre8x, field)))
|
||||||
|
|
||||||
#define KPROCESSRELATED_GET_PTR(obj, field) (isN3DS ? &(obj)->N3DS.field :\
|
#define KPROCESSRELATED_GET_PTR(obj, field) (isN3DS ? &(obj)->N3DS.field :\
|
||||||
((GET_VERSION_MINOR(kernelVersion) >= 44) ? &(obj)->O3DS8x.field :\
|
((kernelVersion >= SYSTEM_VERSION(2, 44, 6)) ? &(obj)->O3DS8x.field :\
|
||||||
&(obj)->O3DSPre8x.field))
|
&(obj)->O3DSPre8x.field))
|
||||||
|
|
||||||
#define KPROCESSRELATED_GET_PTR_TYPE(type, obj, field) (isN3DS ? (type *)(&(obj)->N3DS.field) :\
|
#define KPROCESSRELATED_GET_PTR_TYPE(type, obj, field) (isN3DS ? (type *)(&(obj)->N3DS.field) :\
|
||||||
((GET_VERSION_MINOR(kernelVersion) >= 44) ? (type *)(&(obj)->O3DS8x.field) :\
|
((kernelVersion >= SYSTEM_VERSION(2, 44, 6)) ? (type *)(&(obj)->O3DS8x.field) :\
|
||||||
(type *)(&(obj)->O3DSPre8x.field)))
|
(type *)(&(obj)->O3DSPre8x.field)))
|
||||||
|
|
||||||
#define KPROCESS_OFFSETOF(field) KPROCESSRELATED_OFFSETOFF(KProcess, field)
|
#define KPROCESS_OFFSETOF(field) KPROCESSRELATED_OFFSETOFF(KProcess, field)
|
||||||
@ -1247,50 +1161,35 @@ offsetof(classname##O3DSPre8x, field)))
|
|||||||
#define KPROCESSHWINFO_GET_RVALUE(obj, field) *(KPROCESSHWINFO_GET_PTR(obj, field))
|
#define KPROCESSHWINFO_GET_RVALUE(obj, field) *(KPROCESSHWINFO_GET_PTR(obj, field))
|
||||||
#define KPROCESSHWINFO_GET_RVALUE_TYPE(type, obj, field) *(KPROCESSHWINFO_GET_PTR_TYPE(type, obj, field))
|
#define KPROCESSHWINFO_GET_RVALUE_TYPE(type, obj, field) *(KPROCESSHWINFO_GET_PTR_TYPE(type, obj, field))
|
||||||
|
|
||||||
extern u32 pidOffsetKProcess, hwInfoOffsetKProcess, codeSetOffsetKProcess, handleTableOffsetKProcess, debugOffsetKProcess, flagsKProcess;
|
|
||||||
|
|
||||||
static inline u32 idOfProcess(KProcess *process)
|
static inline u32 idOfProcess(KProcess *process)
|
||||||
{
|
{
|
||||||
u32 id;
|
return KPROCESS_GET_RVALUE(process, processId);
|
||||||
memcpy(&id, (const u8 *)process + pidOffsetKProcess, 4);
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline KProcessHwInfo *hwInfoOfProcess(KProcess *process)
|
static inline KProcessHwInfo *hwInfoOfProcess(KProcess *process)
|
||||||
{
|
{
|
||||||
return (KProcessHwInfo *)((uintptr_t)process + hwInfoOffsetKProcess);
|
return KPROCESS_GET_PTR_TYPE(KProcessHwInfo, process, hwInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline KCodeSet *codeSetOfProcess(KProcess *process)
|
static inline KCodeSet *codeSetOfProcess(KProcess *process)
|
||||||
{
|
{
|
||||||
KCodeSet *cs;
|
return KPROCESS_GET_RVALUE(process, codeSet);
|
||||||
memcpy(&cs, (const u8 *)process + codeSetOffsetKProcess, 4);
|
|
||||||
return cs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline KProcessHandleTable *handleTableOfProcess(KProcess *process)
|
static inline KProcessHandleTable *handleTableOfProcess(KProcess *process)
|
||||||
{
|
{
|
||||||
return (KProcessHandleTable *)((uintptr_t)process + handleTableOffsetKProcess);
|
return KPROCESS_GET_PTR(process, handleTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline KDebug *debugOfProcess(KProcess *process)
|
static inline KDebug *debugOfProcess(KProcess *process)
|
||||||
{
|
{
|
||||||
KDebug *debug;
|
return KPROCESS_GET_RVALUE(process, debug);
|
||||||
memcpy(&debug, (const u8 *)process + debugOffsetKProcess, 4);
|
|
||||||
return debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u32 flagsOfProcess(KProcess *process)
|
|
||||||
{
|
|
||||||
u32 flags;
|
|
||||||
memcpy(&flags, (const u8 *)process + flagsKProcess, 4);
|
|
||||||
return flags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline const char *classNameOfAutoObject(KAutoObject *object)
|
static inline const char *classNameOfAutoObject(KAutoObject *object)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
if(GET_VERSION_MINOR(kernelVersion) >= 46)
|
if(kernelVersion >= SYSTEM_VERSION(2, 46, 0))
|
||||||
{
|
{
|
||||||
KClassToken tok;
|
KClassToken tok;
|
||||||
object->vtable->GetClassToken(&tok, object);
|
object->vtable->GetClassToken(&tok, object);
|
||||||
@ -1306,7 +1205,7 @@ extern Result (*KProcessHandleTable__CreateHandle)(KProcessHandleTable *this, Ha
|
|||||||
static inline Result createHandleForProcess(Handle *out, KProcess *process, KAutoObject *obj)
|
static inline Result createHandleForProcess(Handle *out, KProcess *process, KAutoObject *obj)
|
||||||
{
|
{
|
||||||
u8 token;
|
u8 token;
|
||||||
if(GET_VERSION_MINOR(kernelVersion) >= 46)
|
if(kernelVersion >= SYSTEM_VERSION(2, 46, 0))
|
||||||
{
|
{
|
||||||
KClassToken tok;
|
KClassToken tok;
|
||||||
obj->vtable->GetClassToken(&tok, obj);
|
obj->vtable->GetClassToken(&tok, obj);
|
||||||
|
|||||||
42
k11_extension/include/memory.h
Normal file
42
k11_extension/include/memory.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
void *memcpy(void *dest, const void *src, u32 size) USED;
|
||||||
|
int memcmp(const void *buf1, const void *buf2, u32 size) USED;
|
||||||
|
void *memset(void *dest, u32 value, u32 size) USED; // thanks binutils for the nice bug involving memset.
|
||||||
|
void *memset32(void *dest, u32 value, u32 size);
|
||||||
|
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize);
|
||||||
|
char *strcpy(char *dest, const char *src);
|
||||||
|
char *strncpy(char *dest, const char *src, u32 size);
|
||||||
|
s32 strnlen(const char *string, s32 maxlen);
|
||||||
|
s32 strlen(const char *string);
|
||||||
|
s32 strcmp(const char *str1, const char *str2);
|
||||||
|
s32 strncmp(const char *str1, const char *str2, u32 size);
|
||||||
|
void hexItoa(u64 number, char *out, u32 digits, bool uppercase);
|
||||||
@ -1,129 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "kernel.h"
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32 bits1_0 : 2; ///< 0b00
|
|
||||||
} Desc_TranslationFault;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32 bits1_0 : 2; ///< 0b01
|
|
||||||
u32 sbz : 3;
|
|
||||||
u32 domain : 4;
|
|
||||||
u32 p : 1;
|
|
||||||
u32 addr : 21;
|
|
||||||
} Desc_CoarsePageTable;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32 bits1_0 : 2; ///< 0b10
|
|
||||||
u32 b : 1;
|
|
||||||
u32 c : 1;
|
|
||||||
u32 xn : 1;
|
|
||||||
u32 domain : 4;
|
|
||||||
u32 p : 1;
|
|
||||||
u32 ap : 2;
|
|
||||||
u32 tex : 3;
|
|
||||||
u32 apx : 1;
|
|
||||||
u32 s : 1;
|
|
||||||
u32 ng : 1;
|
|
||||||
u32 bit18 : 1; ///< 0
|
|
||||||
u32 sbz : 1;
|
|
||||||
u32 addr : 12;
|
|
||||||
} Desc_Section;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32 bits1_0 : 2; ///< 0b10
|
|
||||||
u32 b : 1;
|
|
||||||
u32 c : 1;
|
|
||||||
u32 xn : 1;
|
|
||||||
u32 domain : 4;
|
|
||||||
u32 p : 1;
|
|
||||||
u32 ap : 2;
|
|
||||||
u32 tex : 3;
|
|
||||||
u32 sbz : 3;
|
|
||||||
u32 bit18 : 1; ///< 1
|
|
||||||
u32 sbz2 : 5;
|
|
||||||
u32 addr : 8;
|
|
||||||
} Desc_Supersection;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32 bits1_0 : 2; ///< 0b11
|
|
||||||
} Desc_Reserved;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32 bits1_0 : 2; ///< 0b01
|
|
||||||
u32 b : 1;
|
|
||||||
u32 c : 1;
|
|
||||||
u32 ap : 2;
|
|
||||||
u32 sbz : 3;
|
|
||||||
u32 apx : 1;
|
|
||||||
u32 s : 1;
|
|
||||||
u32 ng : 1;
|
|
||||||
u32 tex : 3;
|
|
||||||
u32 xn : 1;
|
|
||||||
u32 addr : 16;
|
|
||||||
} Desc_LargePage;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32 xn : 1;
|
|
||||||
u32 bit1 : 1; ///< 1
|
|
||||||
u32 b : 1;
|
|
||||||
u32 c : 1;
|
|
||||||
u32 ap : 2;
|
|
||||||
u32 tex : 3;
|
|
||||||
u32 apx : 1;
|
|
||||||
u32 s : 1;
|
|
||||||
u32 ng : 1;
|
|
||||||
u32 addr : 20;
|
|
||||||
} Desc_SmallPage;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
u32 raw;
|
|
||||||
|
|
||||||
Desc_TranslationFault translationFault;
|
|
||||||
Desc_CoarsePageTable coarsePageTable;
|
|
||||||
Desc_Section section;
|
|
||||||
Desc_Supersection supersection;
|
|
||||||
Desc_Reserved reserved;
|
|
||||||
|
|
||||||
} L1Descriptor;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
u32 raw;
|
|
||||||
|
|
||||||
Desc_TranslationFault translationFault;
|
|
||||||
Desc_LargePage largePage;
|
|
||||||
Desc_SmallPage smallPage;
|
|
||||||
} L2Descriptor;
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
Descriptor_TranslationFault,
|
|
||||||
Descriptor_CoarsePageTable,
|
|
||||||
Descriptor_Section,
|
|
||||||
Descriptor_Supersection,
|
|
||||||
Descriptor_Reserved,
|
|
||||||
Descriptor_LargePage,
|
|
||||||
Descriptor_SmallPage
|
|
||||||
} DescType;
|
|
||||||
|
|
||||||
void L1MMUTable__RWXForAll(u32 *table);
|
|
||||||
void L2MMUTable__RWXForAll(u32 *table);
|
|
||||||
u32 L1MMUTable__GetPAFromVA(u32 *table, u32 va);
|
|
||||||
u32 L2MMUTable__GetPAFromVA(u32 *table, u32 va);
|
|
||||||
u32 L1MMUTable__GetAddressUserPerm(u32 *table, u32 va);
|
|
||||||
u32 L2MMUTable__GetAddressUserPerm(u32 *table, u32 va);
|
|
||||||
|
|
||||||
void KProcessHwInfo__SetMMUTableToRWX(KProcessHwInfo *hwInfo);
|
|
||||||
u32 KProcessHwInfo__GetPAFromVA(KProcessHwInfo *hwInfo, u32 va);
|
|
||||||
u32 KProcessHwInfo__GetAddressUserPerm(KProcessHwInfo *hwInfo, u32 va);
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -32,9 +32,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
extern void *officialSVCs[0x7E];
|
extern void *officialSVCs[0x7E];
|
||||||
extern void *alteredSvcTable[0x100];
|
|
||||||
|
|
||||||
void buildAlteredSvcTable(void);
|
|
||||||
|
|
||||||
void postprocessSvc(void);
|
void postprocessSvc(void);
|
||||||
void svcDefaultHandler(u8 svcId);
|
void svcDefaultHandler(u8 svcId);
|
||||||
|
void *svcHook(u8 *pageEnd);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include "kernel.h"
|
|
||||||
#include "svc.h"
|
|
||||||
|
|
||||||
/// Operations for svcControlProcess
|
|
||||||
typedef enum ProcessOp
|
|
||||||
{
|
|
||||||
PROCESSOP_GET_ALL_HANDLES, ///< List all handles of the process, varg3 can be either 0 to fetch all handles, or token of the type to fetch
|
|
||||||
///< svcControlProcess(handle, PROCESSOP_GET_ALL_HANDLES, (u32)&outBuf, 0)
|
|
||||||
PROCESSOP_SET_MMU_TO_RWX, ///< Set the whole memory of the process with rwx access
|
|
||||||
///< svcControlProcess(handle, PROCESSOP_SET_MMU_TO_RWX, 0, 0)
|
|
||||||
PROCESSOP_GET_ON_MEMORY_CHANGE_EVENT,
|
|
||||||
PROCESSOP_SIGNAL_ON_EXIT,
|
|
||||||
PROCESSOP_GET_PA_FROM_VA, ///< Get the physical address of the va within the process
|
|
||||||
///< svcControlProcess(handle, PROCESSOP_GET_PA_FROM_VA, (u32)&outPa, va)
|
|
||||||
PROCESSOP_SCHEDULE_THREADS,
|
|
||||||
} ProcessOp;
|
|
||||||
|
|
||||||
Result ControlProcess(Handle process, ProcessOp op, u32 varg2, u32 varg3);
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2023 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include "kernel.h"
|
|
||||||
#include "svc.h"
|
|
||||||
|
|
||||||
Result CreateThreadHookWrapper(Handle *outThreadHandle, u32 ep, u32 arg, u32 stackTop, s32 priority, s32 processorId);
|
|
||||||
Result CreateThreadHook(Handle *outThreadHandle, u32 ep, u32 arg, u32 stackTop, s32 priority, s32 processorId);
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
#include "utils.h"
|
|
||||||
#include "kernel.h"
|
|
||||||
#include "svc.h"
|
|
||||||
|
|
||||||
void ExitProcessHook(void);
|
|
||||||
void ExitProcessHookWrapper(void);
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -26,7 +26,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include "utils.h"
|
||||||
#include "firm.h"
|
#include "kernel.h"
|
||||||
|
#include "svc.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
void chainload(int argc, char **argv, Firm *firm);
|
// DEPRECATED
|
||||||
|
Result GetCFWInfo(CfwInfo *out);
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -30,7 +30,5 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "svc.h"
|
#include "svc.h"
|
||||||
|
|
||||||
extern u8 svcSignalingEnabled;
|
|
||||||
|
|
||||||
bool shouldSignalSyscallDebugEvent(KProcess *process, u8 svcId);
|
bool shouldSignalSyscallDebugEvent(KProcess *process, u8 svcId);
|
||||||
Result KernelSetStateHook(u32 type, u32 varg1, u32 varg2, u32 varg3);
|
Result KernelSetStateHook(u32 type, u32 varg1, u32 varg2, u32 varg3);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -30,11 +30,4 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "svc.h"
|
#include "svc.h"
|
||||||
|
|
||||||
/// Flags for svcMapProcessMemoryEx
|
Result MapProcessMemoryEx(Handle processHandle, void *dst, void *src, u32 size);
|
||||||
typedef enum MapExFlags
|
|
||||||
{
|
|
||||||
MAPEXFLAGS_PRIVATE = BIT(0), ///< Maps the memory as PRIVATE (0xBB05) instead of SHARED (0x5806)
|
|
||||||
} MapExFlags;
|
|
||||||
|
|
||||||
Result MapProcessMemoryEx(Handle dstProcessHandle, u32 vaDst, Handle srcProcessHandle, u32 vaSrc, u32 size, MapExFlags flags);
|
|
||||||
Result MapProcessMemoryExWrapper(Handle dstProcessHandle, u32 vaDst, Handle srcProcessHandle, u32 vaSrc, u32 size, MapExFlags flags);
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -36,12 +36,11 @@ void executeFunctionOnCores(SGI0Handler_t func, u8 targetList, u8 targetListFilt
|
|||||||
|
|
||||||
void KScheduler__TriggerCrossCoreInterrupt(KScheduler *this);
|
void KScheduler__TriggerCrossCoreInterrupt(KScheduler *this);
|
||||||
void KThread__DebugReschedule(KThread *this, bool lock);
|
void KThread__DebugReschedule(KThread *this, bool lock);
|
||||||
|
bool rosalinaThreadLockPredicate(KThread *thread);
|
||||||
bool rosalinaThreadLockPredicate(KThread *thread, u32 mask);
|
|
||||||
void rosalinaRescheduleThread(KThread *thread, bool lock);
|
void rosalinaRescheduleThread(KThread *thread, bool lock);
|
||||||
|
void rosalinaLockThread(KThread *thread);
|
||||||
void rosalinaLockThreads(u32 mask);
|
void rosalinaLockAllThreads(void);
|
||||||
void rosalinaUnlockThreads(u32 mask);
|
void rosalinaUnlockAllThreads(void);
|
||||||
|
|
||||||
// Taken from ctrulib:
|
// Taken from ctrulib:
|
||||||
|
|
||||||
@ -50,11 +49,6 @@ static inline void __dsb(void)
|
|||||||
__asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 4" :: [val] "r" (0) : "memory");
|
__asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 4" :: [val] "r" (0) : "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __dmb(void)
|
|
||||||
{
|
|
||||||
__asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 5" :: [val] "r" (0) : "memory");
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void __clrex(void)
|
static inline void __clrex(void)
|
||||||
{
|
{
|
||||||
__asm__ __volatile__("clrex" ::: "memory");
|
__asm__ __volatile__("clrex" ::: "memory");
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -69,24 +69,15 @@ typedef s32 Result; ///< Function result.
|
|||||||
#define BIT(n) (1U<<(n))
|
#define BIT(n) (1U<<(n))
|
||||||
|
|
||||||
/// Aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m.
|
/// Aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m.
|
||||||
#define CTR_ALIGN(m) __attribute__((aligned(m)))
|
#define ALIGN(m) __attribute__((aligned(m)))
|
||||||
/// Packs a struct (and other types?) so it won't include padding bytes.
|
/// Packs a struct (and other types?) so it won't include padding bytes.
|
||||||
#define CTR_PACKED __attribute__((packed))
|
#define PACKED __attribute__((packed))
|
||||||
#define CTR_USED __attribute__((used))
|
#define USED __attribute__((used))
|
||||||
#define CTR_UNUSED __attribute__((unused))
|
#define UNUSED __attribute__((unused))
|
||||||
/// Packs a system version from its components.
|
/// Packs a system version from its components.
|
||||||
#define SYSTEM_VERSION(major, minor, revision) \
|
#define SYSTEM_VERSION(major, minor, revision) \
|
||||||
(((major)<<24)|((minor)<<16)|((revision)<<8))
|
(((major)<<24)|((minor)<<16)|((revision)<<8))
|
||||||
|
|
||||||
/// Retrieves the major version from a packed system version.
|
|
||||||
#define GET_VERSION_MAJOR(version) ((version) >>24)
|
|
||||||
|
|
||||||
/// Retrieves the minor version from a packed system version.
|
|
||||||
#define GET_VERSION_MINOR(version) (((version)>>16)&0xFF)
|
|
||||||
|
|
||||||
/// Retrieves the revision version from a packed system version.
|
|
||||||
#define GET_VERSION_REVISION(version) (((version)>> 8)&0xFF)
|
|
||||||
|
|
||||||
#define CUR_THREAD_HANDLE 0xFFFF8000
|
#define CUR_THREAD_HANDLE 0xFFFF8000
|
||||||
#define CUR_PROCESS_HANDLE 0xFFFF8001
|
#define CUR_PROCESS_HANDLE 0xFFFF8001
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Luma3DS
|
* This file is part of Luma3DS
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -33,7 +33,7 @@
|
|||||||
#define PA_PTR(addr) (void *)((u32)(addr) | 1u << 31)
|
#define PA_PTR(addr) (void *)((u32)(addr) | 1u << 31)
|
||||||
#define PA_FROM_VA_PTR(addr) PA_PTR(convertVAToPA(addr, false))
|
#define PA_FROM_VA_PTR(addr) PA_PTR(convertVAToPA(addr, false))
|
||||||
|
|
||||||
static inline u32 makeArmBranch(const void *src, const void *dst, bool link) // the macros for those are ugly and buggy
|
static inline u32 makeARMBranch(const void *src, const void *dst, bool link) // the macros for those are ugly and buggy
|
||||||
{
|
{
|
||||||
u32 instrBase = link ? 0xEB000000 : 0xEA000000;
|
u32 instrBase = link ? 0xEB000000 : 0xEA000000;
|
||||||
u32 off = (u32)((const u8 *)dst - ((const u8 *)src + 8)); // the PC is always two instructions ahead of the one being executed
|
u32 off = (u32)((const u8 *)dst - ((const u8 *)src + 8)); // the PC is always two instructions ahead of the one being executed
|
||||||
@ -41,7 +41,7 @@ static inline u32 makeArmBranch(const void *src, const void *dst, bool link) //
|
|||||||
return instrBase | ((off >> 2) & 0xFFFFFF);
|
return instrBase | ((off >> 2) & 0xFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void *decodeArmBranch(const void *src)
|
static inline void *decodeARMBranch(const void *src)
|
||||||
{
|
{
|
||||||
u32 instr = *(const u32 *)src;
|
u32 instr = *(const u32 *)src;
|
||||||
s32 off = (instr & 0xFFFFFF) << 2;
|
s32 off = (instr & 0xFFFFFF) << 2;
|
||||||
@ -50,8 +50,8 @@ static inline void *decodeArmBranch(const void *src)
|
|||||||
return (void *)((const u8 *)src + 8 + off);
|
return (void *)((const u8 *)src + 8 + off);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Arm prologs in the form of: push {regs} ... sub sp, #off (this obviously doesn't intend to cover all cases)
|
// For ARM prologs in the form of: push {regs} ... sub sp, #off (this obviously doesn't intend to cover all cases)
|
||||||
static inline u32 computeArmFrameSize(const u32 *prolog)
|
static inline u32 computeARMFrameSize(const u32 *prolog)
|
||||||
{
|
{
|
||||||
const u32 *off;
|
const u32 *off;
|
||||||
|
|
||||||
|
|||||||
@ -1,157 +1,19 @@
|
|||||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||||
OUTPUT_ARCH(arm)
|
OUTPUT_ARCH(arm)
|
||||||
|
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
|
||||||
MEMORY
|
|
||||||
{
|
|
||||||
vram : ORIGIN = 0x18000000, LENGTH = 0x18180000 - 0x18000000 /* Up to the kernel builtins. */
|
|
||||||
main : ORIGIN = 0x70000000, LENGTH = 1M
|
|
||||||
}
|
|
||||||
|
|
||||||
PHDRS
|
|
||||||
{
|
|
||||||
main PT_LOAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
PROVIDE(__start__ = ORIGIN(main));
|
. = 0x40000000;
|
||||||
. = ABSOLUTE(__start__);
|
|
||||||
|
|
||||||
.text :
|
__start__ = .;
|
||||||
{
|
|
||||||
KEEP( *(.text.start) )
|
|
||||||
KEEP( *(.init) )
|
|
||||||
|
|
||||||
/* .text */
|
.text : ALIGN(4) { *(.text.start) *(.text*); . = ALIGN(4); }
|
||||||
*(.text)
|
.rodata : ALIGN(4) { *(.rodata*); . = ALIGN(4); }
|
||||||
*(.text.*)
|
.data : ALIGN(4) { *(.data*); . = ALIGN(4); }
|
||||||
*(.glue_7)
|
.bss : ALIGN(8) { __bss_start__ = .; *(.bss* COMMON); . = ALIGN(8); __bss_end__ = .; }
|
||||||
*(.glue_7t)
|
|
||||||
*(.stub)
|
|
||||||
*(.gnu.warning)
|
|
||||||
*(.gnu.linkonce.t*)
|
|
||||||
|
|
||||||
/* .fini */
|
. = ALIGN(0x1000);
|
||||||
KEEP( *(.fini) )
|
|
||||||
. = ALIGN(32);
|
|
||||||
} >main AT>vram :main
|
|
||||||
|
|
||||||
.rodata :
|
__end__ = .;
|
||||||
{
|
|
||||||
*(.rodata)
|
|
||||||
*(.roda)
|
|
||||||
*(.rodata.*)
|
|
||||||
*all.rodata*(*)
|
|
||||||
*(.gnu.linkonce.r*)
|
|
||||||
SORT(CONSTRUCTORS)
|
|
||||||
. = ALIGN(8);
|
|
||||||
} >main AT>vram
|
|
||||||
|
|
||||||
.preinit_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__preinit_array_start = .);
|
|
||||||
KEEP (*(.preinit_array))
|
|
||||||
PROVIDE (__preinit_array_end = .);
|
|
||||||
} >main AT>vram
|
|
||||||
|
|
||||||
.init_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__init_array_start = .);
|
|
||||||
KEEP (*(SORT(.init_array.*)))
|
|
||||||
KEEP (*(.init_array))
|
|
||||||
PROVIDE (__init_array_end = .);
|
|
||||||
} >main AT>vram
|
|
||||||
|
|
||||||
.fini_array :
|
|
||||||
{
|
|
||||||
PROVIDE (__fini_array_start = .);
|
|
||||||
KEEP (*(.fini_array))
|
|
||||||
KEEP (*(SORT(.fini_array.*)))
|
|
||||||
PROVIDE (__fini_array_end = .);
|
|
||||||
} >main AT>vram
|
|
||||||
|
|
||||||
.ctors :
|
|
||||||
{
|
|
||||||
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
|
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
|
||||||
KEEP (*(SORT(.ctors.*)))
|
|
||||||
KEEP (*(.ctors))
|
|
||||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
|
||||||
} >main AT>vram
|
|
||||||
|
|
||||||
.dtors :
|
|
||||||
{
|
|
||||||
KEEP (*crtbegin.o(.dtors))
|
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
|
||||||
KEEP (*(SORT(.dtors.*)))
|
|
||||||
KEEP (*(.dtors))
|
|
||||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
|
||||||
} >main AT>vram
|
|
||||||
|
|
||||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) __exidx_start = ABSOLUTE(.);} >main AT>vram
|
|
||||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) __exidx_end = ABSOLUTE(.);} >main AT>vram
|
|
||||||
|
|
||||||
.data :
|
|
||||||
{
|
|
||||||
*(.data)
|
|
||||||
*(.data.*)
|
|
||||||
*(.gnu.linkonce.d*)
|
|
||||||
CONSTRUCTORS
|
|
||||||
. = ALIGN(32);
|
|
||||||
} >main AT>vram
|
|
||||||
|
|
||||||
.bss (NOLOAD) :
|
|
||||||
{
|
|
||||||
. = ALIGN(32);
|
|
||||||
PROVIDE (__bss_start__ = ABSOLUTE(.));
|
|
||||||
*(.dynbss)
|
|
||||||
*(.bss)
|
|
||||||
*(.bss.*)
|
|
||||||
*(.gnu.linkonce.b*)
|
|
||||||
*(COMMON)
|
|
||||||
. = ALIGN(0x1000);
|
|
||||||
PROVIDE (__bss_end__ = ABSOLUTE(.));
|
|
||||||
PROVIDE (__end__ = ABSOLUTE(.));
|
|
||||||
} >main :NONE
|
|
||||||
|
|
||||||
/* ==================
|
|
||||||
==== Metadata ====
|
|
||||||
================== */
|
|
||||||
|
|
||||||
/* Discard sections that difficult post-processing */
|
|
||||||
/DISCARD/ : { *(.group .comment .note) }
|
|
||||||
|
|
||||||
/* Stabs debugging sections. */
|
|
||||||
.stab 0 : { *(.stab) }
|
|
||||||
.stabstr 0 : { *(.stabstr) }
|
|
||||||
.stab.excl 0 : { *(.stab.excl) }
|
|
||||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
|
||||||
.stab.index 0 : { *(.stab.index) }
|
|
||||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
|
||||||
|
|
||||||
/* DWARF debug sections.
|
|
||||||
Symbols in the DWARF debugging sections are relative to the beginning
|
|
||||||
of the section so we begin them at 0. */
|
|
||||||
|
|
||||||
/* DWARF 1 */
|
|
||||||
.debug 0 : { *(.debug) }
|
|
||||||
.line 0 : { *(.line) }
|
|
||||||
|
|
||||||
/* GNU DWARF 1 extensions */
|
|
||||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
|
||||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
|
||||||
|
|
||||||
/* DWARF 1.1 and DWARF 2 */
|
|
||||||
.debug_aranges 0 : { *(.debug_aranges) }
|
|
||||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
|
||||||
|
|
||||||
/* DWARF 2 */
|
|
||||||
.debug_info 0 : { *(.debug_info) }
|
|
||||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
|
||||||
.debug_line 0 : { *(.debug_line) }
|
|
||||||
.debug_frame 0 : { *(.debug_frame) }
|
|
||||||
.debug_str 0 : { *(.debug_str) }
|
|
||||||
.debug_loc 0 : { *(.debug_loc) }
|
|
||||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
%rename link old_link
|
|
||||||
|
|
||||||
*link:
|
|
||||||
%(old_link) -T %:getenv(TOPDIR /linker.ld) --nmagic --gc-sections --no-warn-rwx-segments
|
|
||||||
|
|
||||||
*startfile:
|
|
||||||
crti%O%s crtbegin%O%s
|
|
||||||
@ -1,147 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "debug.h"
|
|
||||||
#include "synchronization.h"
|
|
||||||
|
|
||||||
KRecursiveLock dbgParamsLock = { NULL };
|
|
||||||
u32 dbgParamWatchpointId, dbgParamDVA, dbgParamWCR, dbgParamContextId;
|
|
||||||
|
|
||||||
KSchedulableInterruptEvent *enableMonitorModeDebugging(KBaseInterruptEvent *this CTR_UNUSED, u32 interruptID CTR_UNUSED)
|
|
||||||
{
|
|
||||||
coreBarrier();
|
|
||||||
|
|
||||||
u32 DSCR;
|
|
||||||
__asm__ __volatile__("mrc p14, 0, %[val], c0, c1, 0" : [val] "=r" (DSCR));
|
|
||||||
DSCR |= 0x8000;
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c1, 0" :: [val] "r" (DSCR));
|
|
||||||
|
|
||||||
__dsb();
|
|
||||||
coreBarrier();
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void disableWatchpoint0(void)
|
|
||||||
{
|
|
||||||
u32 control;
|
|
||||||
|
|
||||||
// WCR0
|
|
||||||
__asm__ __volatile__("mrc p14, 0, %[val], c0, c0, 7" : [val] "=r" (control));
|
|
||||||
control &= ~1;
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c0, 7" :: [val] "r" (control));
|
|
||||||
|
|
||||||
// BCR4
|
|
||||||
__asm__ __volatile__("mrc p14, 0, %[val], c0, c4, 5" : [val] "=r" (control));
|
|
||||||
control &= ~1;
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c4, 5" :: [val] "r" (control));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void disableWatchpoint1(void)
|
|
||||||
{
|
|
||||||
u32 control;
|
|
||||||
|
|
||||||
// WCR1
|
|
||||||
__asm__ __volatile__("mrc p14, 0, %[val], c0, c1, 7" : [val] "=r" (control));
|
|
||||||
control &= ~1;
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c1, 7" :: [val] "r" (control));
|
|
||||||
|
|
||||||
// BCR5
|
|
||||||
__asm__ __volatile__("mrc p14, 0, %[val], c0, c5, 5" : [val] "=r" (control));
|
|
||||||
control &= ~1;
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c5, 5" :: [val] "r" (control));
|
|
||||||
}
|
|
||||||
|
|
||||||
KSchedulableInterruptEvent *disableWatchpoint(KBaseInterruptEvent *this CTR_UNUSED, u32 interruptID CTR_UNUSED)
|
|
||||||
{
|
|
||||||
coreBarrier();
|
|
||||||
|
|
||||||
if(dbgParamWatchpointId == 0)
|
|
||||||
disableWatchpoint0();
|
|
||||||
else
|
|
||||||
disableWatchpoint1();
|
|
||||||
|
|
||||||
__dsb();
|
|
||||||
coreBarrier();
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setWatchpoint0WithContextId(u32 DVA, u32 WCR, u32 contextId)
|
|
||||||
{
|
|
||||||
// http://infocenter.arm.com/help/topic/com.arm.doc.ddi0360f/CEGCFFDF.html
|
|
||||||
u32 BCR =
|
|
||||||
(1 << 21) | /* compare with context ID */
|
|
||||||
(1 << 20) | /* linked (with a WRP in our case) */
|
|
||||||
(0xf << 5) | /* byte address select, +0 to +3 as mandated when linking with a WRP */
|
|
||||||
(3 << 1) | /* either privileged modes or user mode, as mandated when linking with a WRP */
|
|
||||||
(1 << 0) ; /* enabled */
|
|
||||||
|
|
||||||
disableWatchpoint0();
|
|
||||||
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c0, 6" :: [val] "r" (DVA));
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c4, 4" :: [val] "r" (contextId));
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c0, 7" :: [val] "r" (WCR));
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c4, 5" :: [val] "r" (BCR));
|
|
||||||
|
|
||||||
__asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 5" :: [val] "r" (0) : "memory"); // DMB
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setWatchpoint1WithContextId(u32 DVA, u32 WCR, u32 contextId)
|
|
||||||
{
|
|
||||||
// http://infocenter.arm.com/help/topic/com.arm.doc.ddi0360f/CEGCFFDF.html
|
|
||||||
u32 BCR =
|
|
||||||
(1 << 21) | /* compare with context ID */
|
|
||||||
(1 << 20) | /* linked (with a WRP in our case) */
|
|
||||||
(0xf << 5) | /* byte address select, +0 to +3 as mandated when linking with a WRP */
|
|
||||||
(3 << 1) | /* either privileged modes or user mode, as mandated when linking with a WRP */
|
|
||||||
(1 << 0) ; /* enabled */
|
|
||||||
|
|
||||||
disableWatchpoint1();
|
|
||||||
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c1, 6" :: [val] "r" (DVA));
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c5, 4" :: [val] "r" (contextId));
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c1, 7" :: [val] "r" (WCR));
|
|
||||||
__asm__ __volatile__("mcr p14, 0, %[val], c0, c5, 5" :: [val] "r" (BCR));
|
|
||||||
|
|
||||||
__asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 5" :: [val] "r" (0) : "memory"); // DMB
|
|
||||||
}
|
|
||||||
|
|
||||||
KSchedulableInterruptEvent *setWatchpointWithContextId(KBaseInterruptEvent *this CTR_UNUSED, u32 interruptID CTR_UNUSED)
|
|
||||||
{
|
|
||||||
coreBarrier();
|
|
||||||
|
|
||||||
if(dbgParamWatchpointId == 0)
|
|
||||||
setWatchpoint0WithContextId(dbgParamDVA, dbgParamWCR, dbgParamContextId);
|
|
||||||
else
|
|
||||||
setWatchpoint1WithContextId(dbgParamDVA, dbgParamWCR, dbgParamContextId);
|
|
||||||
|
|
||||||
__dsb();
|
|
||||||
coreBarrier();
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user