Skip to content

Commit 7e604ae

Browse files
authored
Read DSi MBK settings from the GBARunner3 .nds file
- Replaces bootloader with custom version
1 parent 6e50ee2 commit 7e604ae

File tree

17 files changed

+2338
-5
lines changed

17 files changed

+2338
-5
lines changed

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[submodule "bootloader"]
2-
path = bootloader
3-
url = https://github.com/devkitPro/nds-bootloader.git
4-
branch = master
51
[submodule "nds-exception-stub"]
62
path = nds-exception-stub
73
url = https://github.com/devkitPro/nds-exception-stub.git

bootloader

Lines changed: 0 additions & 1 deletion
This file was deleted.

bootloader/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*build
2+
load.bin
3+
load.elf

bootloader/Makefile

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#---------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#---------------------------------------------------------------------------------
4+
ifeq ($(strip $(DEVKITARM)),)
5+
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
6+
endif
7+
8+
-include $(DEVKITARM)/ds_rules
9+
10+
#---------------------------------------------------------------------------------
11+
# BUILD is the directory where object files & intermediate files will be placed
12+
# SOURCES is a list of directories containing source code
13+
# INCLUDES is a list of directories containing extra header files
14+
#---------------------------------------------------------------------------------
15+
TARGET := load
16+
BUILD ?= build
17+
SOURCES := source source/patches
18+
INCLUDES := build
19+
SPECS := specs
20+
21+
22+
#---------------------------------------------------------------------------------
23+
# options for code generation
24+
#---------------------------------------------------------------------------------
25+
ARCH := -mthumb -mthumb-interwork -march=armv4t -mtune=arm7tdmi
26+
27+
CFLAGS := -g -Wall -Os \
28+
-ffunction-sections -fdata-sections \
29+
$(ARCH)
30+
31+
CFLAGS += $(INCLUDE) $(EXTRA_CFLAGS) -DARM7
32+
33+
ASFLAGS := -g $(ARCH) $(EXTRA_CFLAGS) $(INCLUDE)
34+
LDFLAGS = -nostartfiles -T $(TOPDIR)/load.ld -Wl,--no-warn-rwx-segments,--nmagic,--gc-sections -g $(ARCH) -Wl,-Map,$(TARGET).map
35+
36+
LIBS := -lnds7 -lcalico_ds7
37+
38+
#---------------------------------------------------------------------------------
39+
# list of directories containing libraries, this must be the top level containing
40+
# include and lib
41+
#---------------------------------------------------------------------------------
42+
LIBDIRS := $(LIBNDS)
43+
44+
45+
#---------------------------------------------------------------------------------
46+
# no real need to edit anything past this point unless you need to add additional
47+
# rules for different file extensions
48+
#---------------------------------------------------------------------------------
49+
ifneq ($(BUILD),$(notdir $(CURDIR)))
50+
#---------------------------------------------------------------------------------
51+
52+
export TOPDIR := $(CURDIR)
53+
export LOADBIN ?= $(CURDIR)/$(TARGET).bin
54+
export LOADELF := $(CURDIR)/$(TARGET).elf
55+
export DEPSDIR := $(CURDIR)/$(BUILD)
56+
57+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
58+
59+
export CC := $(PREFIX)gcc
60+
export CXX := $(PREFIX)g++
61+
export AR := $(PREFIX)ar
62+
export OBJCOPY := $(PREFIX)objcopy
63+
64+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
65+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
66+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
67+
68+
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
69+
70+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
71+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
72+
-I$(CURDIR)/$(BUILD)
73+
74+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
75+
76+
#---------------------------------------------------------------------------------
77+
# use CC for linking standard C
78+
#---------------------------------------------------------------------------------
79+
export LD := $(CC)
80+
#---------------------------------------------------------------------------------
81+
82+
.PHONY: $(BUILD) clean
83+
84+
#---------------------------------------------------------------------------------
85+
$(BUILD):
86+
@[ -d $@ ] || mkdir -p $@
87+
@$(MAKE) -C $(BUILD) -f $(CURDIR)/Makefile
88+
89+
#---------------------------------------------------------------------------------
90+
clean:
91+
@echo clean ...
92+
@rm -fr $(BUILD) *.elf *.bin
93+
94+
95+
#---------------------------------------------------------------------------------
96+
else
97+
98+
DEPENDS := $(OFILES:.o=.d)
99+
100+
#---------------------------------------------------------------------------------
101+
# main targets
102+
#---------------------------------------------------------------------------------
103+
$(LOADBIN) : $(LOADELF)
104+
@$(OBJCOPY) -O binary $< $@
105+
@echo built ... $(notdir $@)
106+
107+
108+
$(LOADELF) : $(OFILES)
109+
@echo linking $(notdir $@)
110+
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
111+
112+
arm9mpu_reset.o: mpu_reset.bin
113+
114+
mpu_reset.bin: mpu_reset.elf
115+
$(OBJCOPY) -O binary $< $@
116+
117+
mpu_reset.elf: $(TOPDIR)/arm9code/mpu_reset.s
118+
$(CC) $(ASFLAGS) -Ttext=0 -x assembler-with-cpp -nostartfiles -nostdlib $< -o $@
119+
120+
-include $(DEPENDS)
121+
#---------------------------------------------------------------------------------------
122+
endif
123+
#---------------------------------------------------------------------------------------

bootloader/arm9code/mpu_reset.s

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Copyright 2006 - 2015 Dave Murphy (WinterMute)
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
*/
18+
19+
#include <nds/arm9/cache_asm.h>
20+
21+
.text
22+
.align 4
23+
24+
.arm
25+
26+
.arch armv5te
27+
.cpu arm946e-s
28+
29+
@---------------------------------------------------------------------------------
30+
.global _start
31+
.type _start STT_FUNC
32+
@---------------------------------------------------------------------------------
33+
_start:
34+
@---------------------------------------------------------------------------------
35+
@ Switch off MPU
36+
mrc p15, 0, r0, c1, c0, 0
37+
bic r0, r0, #PROTECT_ENABLE
38+
mcr p15, 0, r0, c1, c0, 0
39+
40+
41+
adr r12, mpu_initial_data
42+
ldmia r12, {r0-r10}
43+
44+
mcr p15, 0, r0, c2, c0, 0
45+
mcr p15, 0, r0, c2, c0, 1
46+
mcr p15, 0, r1, c3, c0, 0
47+
mcr p15, 0, r2, c5, c0, 2
48+
mcr p15, 0, r3, c5, c0, 3
49+
mcr p15, 0, r4, c6, c0, 0
50+
mcr p15, 0, r5, c6, c1, 0
51+
mcr p15, 0, r6, c6, c3, 0
52+
mcr p15, 0, r7, c6, c4, 0
53+
mcr p15, 0, r8, c6, c6, 0
54+
mcr p15, 0, r9, c6, c7, 0
55+
mcr p15, 0, r10, c9, c1, 0
56+
57+
mov r0, #0
58+
mcr p15, 0, r0, c6, c2, 0 @ PU Protection Unit Data/Unified Region 2
59+
mcr p15, 0, r0, c6, c5, 0 @ PU Protection Unit Data/Unified Region 5
60+
61+
mrc p15, 0, r0, c9, c1, 0 @ DTCM
62+
mov r0, r0, lsr #12 @ base
63+
mov r0, r0, lsl #12 @ size
64+
add r0, r0, #0x4000 @ dtcm top
65+
66+
sub r0, r0, #4 @ irq vector
67+
mov r1, #0
68+
str r1, [r0]
69+
sub r0, r0, #4 @ IRQ1 Check Bits
70+
str r1, [r0]
71+
72+
sub r0, r0, #128
73+
bic r0, r0, #7
74+
75+
msr cpsr_c, #0xd3 @ svc mode
76+
mov sp, r0
77+
sub r0, r0, #128
78+
msr cpsr_c, #0xd2 @ irq mode
79+
mov sp, r0
80+
sub r0, r0, #128
81+
msr cpsr_c, #0xdf @ system mode
82+
mov sp, r0
83+
84+
@ enable cache & tcm
85+
mrc p15, 0, r0, c1, c0, 0
86+
ldr r1,= ITCM_ENABLE | DTCM_ENABLE | ICACHE_ENABLE | DCACHE_ENABLE
87+
orr r0,r0,r1
88+
mcr p15, 0, r0, c1, c0, 0
89+
90+
ldr r10, =0x2FFFE04
91+
ldr r0, =0xE59FF018
92+
str r0, [r10]
93+
add r1, r10, #0x20
94+
str r10, [r1]
95+
bx r10
96+
97+
.pool
98+
99+
mpu_initial_data:
100+
.word 0x00000042 @ p15,0,c2,c0,0..1,r0 ;PU Cachability Bits for Data/Unified+Instruction Protection Region
101+
.word 0x00000002 @ p15,0,c3,c0,0,r1 ;PU Write-Bufferability Bits for Data Protection Regions
102+
.word 0x15111011 @ p15,0,c5,c0,2,r2 ;PU Extended Access Permission Data/Unified Protection Region
103+
.word 0x05100011 @ p15,0,c5,c0,3,r3 ;PU Extended Access Permission Instruction Protection Region
104+
.word 0x04000033 @ p15,0,c6,c0,0,r4 ;PU Protection Unit Data/Unified Region 0
105+
.word 0x0200002b @ p15,0,c6,c1,0,r5 ;PU Protection Unit Data/Unified Region 1 4MB
106+
.word 0x08000035 @ p15,0,c6,c3,0,r6 ;PU Protection Unit Data/Unified Region 3
107+
.word 0x0300001b @ p15,0,c6,c4,0,r7 ;PU Protection Unit Data/Unified Region 4
108+
.word 0xffff001d @ p15,0,c6,c6,0,r8 ;PU Protection Unit Data/Unified Region 6
109+
.word 0x02fff017 @ p15,0,c6,c7,0,r9 ;PU Protection Unit Data/Unified Region 7 4KB
110+
.word 0x0300000a @ p15,0,c9,c1,0,r10 ;TCM Data TCM Base and Virtual Size

0 commit comments

Comments
 (0)