Skip to content

Commit c4f719c

Browse files
author
Cyril Lugan
committed
NDS arm9 port
1 parent 8c61962 commit c4f719c

File tree

133 files changed

+4824
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+4824
-49
lines changed

Makefile

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11

22
PATH := $(DEVKITARM)/bin:$(PATH)
33

4-
GAME_TITLE := PrexDS
5-
GAME_SUBTITLE1 := cyril.lugan.info
6-
GAME_SUBTITLE2 := www.devkitpro.org
7-
GAME_ICON := $(DEVKITPRO)/libnds/icon.bmp
4+
GAME_TITLE := Prex
5+
GAME_SUBTITLE1 := www.devkitpro.org
6+
GAME_SUBTITLE2 := cyril.lugan.info
7+
GAME_ICON := ./icon.bmp
88

99
all : prex.nds
1010

1111
prex.nds : prex.arm9
12-
ndstool -c $@ -9 prex.arm9 -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)"
12+
@ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)"
1313

1414
.PHONY : prex.arm9 clean
1515

1616
prex.arm9 :
17-
@$(MAKE) --file=prex.mk prex.arm9
17+
./configure --target=arm-nds_arm9 --cross-prefix=arm-eabi-
18+
@$(MAKE) --file=prex.mk
19+
mv prexos prex.arm9
1820

1921
clean :
22+
rm prex.nds
2023
@$(MAKE) --file=prex.mk clean

README

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Building instructions (tested with devkitARM r27) :
33
###
44

5-
./configure --target=arm-nds --cross-prefix=arm-eabi-
65
make
76

87
###
@@ -16,7 +15,7 @@ file, then run the configure script and build.
1615
# DS related files
1716
###
1817

19-
/conf/arm/nds : Configuration file
20-
/bsp/boot/arm/nds : Bootloader
21-
/bsp/hal/arm/nds : Hardware Abstaction Layer
22-
/bsp/drv/arm/nds : Drivers
18+
/conf/arm/nds_arm9 : Configuration file
19+
/bsp/boot/arm/nds_arm9 : Bootloader
20+
/bsp/hal/arm/nds_arm9 : Hardware Abstaction Layer
21+
/bsp/drv/arm/nds_arm9 : Drivers

bsp/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include $(SRCDIR)/mk/own.mk
2+
3+
SUBDIR:= boot hal drv
4+
5+
include $(SRCDIR)/mk/subdir.mk

bsp/boot/Makefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Rules to compile boot loader
2+
3+
include $(SRCDIR)/mk/own.mk
4+
5+
TARGET:= bootldr
6+
7+
#MAP:= bootldr.map
8+
#DISASM:= bootldr.lst
9+
#SYMBOL:= bootldr.sym
10+
11+
_KERNEL_:= 1
12+
DEFS+= KERNEL
13+
14+
include $(CURDIR)/$(ARCH)/$(PLATFORM)/Makefile.inc
15+
include $(CURDIR)/$(ARCH)/arch/Makefile.inc
16+
include $(CURDIR)/common/Makefile.inc
17+
18+
LIBSDIR+= $(SRCDIR)/conf
19+
INCSDIR+= $(CURDIR)/include $(CURDIR)/$(ARCH)
20+
ifndef LDSCRIPT
21+
LDSCRIPT:= $(CURDIR)/$(ARCH)/arch/boot.ld
22+
endif
23+
24+
include $(SRCDIR)/mk/common.mk
25+
26+
$(TARGET): $(OBJS) $(LIBS) $(LDSCRIPT)
27+
$(call echo-file,LD ,$@)
28+
$(LD) $(LDFLAGS) $(OUTPUT_OPTION) $(OBJS) $(LIBS) $(PLATFORM_LIBS)
29+
$(ASMGEN)
30+
$(SYMGEN)
31+
$(OBJCOPY) -O binary -R .note -R .comment -S $@

bsp/boot/arm/arch/elf_reloc.c

+14
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ relocate_rel(Elf32_Rel *rel, Elf32_Addr sym_val, char *target_sect)
6060
ELFDBG(("R_ARM_PC24: %lx -> %lx\n",
6161
(long)where, (long)*where));
6262
break;
63+
/*
64+
* Added to support devkitARM
65+
* http://lists.openwall.net/linux-kernel/2009/03/29/72
66+
*/
67+
case R_ARM_V4BX:
68+
/* Preserve Rm and the condition code. Alter
69+
* other bits to re-code instruction as
70+
* MOV PC,Rm.
71+
*/
72+
*where &= 0xf000000f;
73+
*where |= 0x01a0f000;
74+
ELFDBG(("R_ARM_V4BX: %lx -> %lx\n",
75+
(long)where, (long)*where));
76+
break;
6377
default:
6478
ELFDBG(("Unkown relocation type=%d\n",
6579
ELF32_R_TYPE(rel->r_info)));

bsp/boot/arm/nds_arm9/Makefile.inc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
SRCS:= arm/nds_arm9/head.S \
3+
arm/nds_arm9/cp15.S \
4+
arm/nds_arm9/diag_desmume.S \
5+
arm/nds_arm9/startup.c \
6+
arm/nds_arm9/debug.c
7+

bsp/boot/arm/nds_arm9/cp15.S

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include "cp15.h"
2+
3+
.text
4+
.align 2
5+
6+
.global cp15_setup
7+
8+
cp15_setup:
9+
10+
/* Protection, DCache, ICache, TCM, Alternate vectors disabled */
11+
mov r0, #0
12+
mcr p15, 0, r0, c1, c0
13+
14+
/* Drain write buffer : makes sure the prevous write has completed */
15+
mcr p15, 0, r0, c7, c10, 4
16+
17+
/* DTCM base = 0x0b000000, size = 16 KB */
18+
mov r0, #0x0b000000
19+
orr r0, r0, # 0b00101 << 1
20+
mcr p15, 0, r0, c9, c1,0
21+
22+
/* ITCM base = 0x01000000, size = 32 MB */
23+
mov r0, #0x01000000
24+
orr r0, r0, # 0b10000 << 1
25+
mcr p15, 0, r0, c9, c1,1
26+
27+
/*--------------------------------------------------------------------------
28+
* Setup memory regions similar to Release Version (from libnds)
29+
*------------------------------------------------------------------------*/
30+
31+
/* Region 0 - IO registers */
32+
ldr r0,=( CP15_REGION_64M | 0x04000000 | 1)
33+
mcr p15, 0, r0, c6, c0, 0
34+
35+
/* Region 1 - Main Memory */
36+
ldr r0,=( CP15_REGION_4M | 0x02000000 | 1)
37+
mcr p15, 0, r0, c6, c1, 0
38+
39+
/* Region 2 - alternate vector base */
40+
ldr r0,=( CP15_REGION_4K | 0x00000000 | 1)
41+
mcr p15, 0, r0, c6, c2, 0
42+
43+
/* Region 3 - DS Accessory (GBA Cart) */
44+
ldr r0,=( CP15_REGION_128M | 0x08000000 | 1)
45+
mcr p15, 0, r0, c6, c3, 0
46+
47+
/* Region 4 - DTCM */
48+
ldr r0,=0x0b000000
49+
orr r0,r0,#(CP15_REGION_16K | 1)
50+
mcr p15, 0, r0, c6, c4, 0
51+
52+
/* Region 5 - ITCM */
53+
ldr r0,=0x01000000
54+
55+
mov r0,r0,lsr #15 @--> align to 32k boundary
56+
mov r0,r0,lsl #15 @/
57+
58+
orr r0,r0,#(CP15_REGION_32K | 1)
59+
mcr p15, 0, r0, c6, c5, 0
60+
61+
/* Region 6 - System ROM */
62+
ldr r0,=( CP15_REGION_32K | 0xFFFF0000 | 1)
63+
mcr p15, 0, r0, c6, c6, 0
64+
65+
/* Region 7 - non cacheable main ram */
66+
ldr r0,=( CP15_REGION_4M | 0x02400000 | 1)
67+
mcr p15, 0, r0, c6, c7, 0
68+
69+
/*--------------------------------------------------------------------------
70+
* Activating TCM and caches
71+
*------------------------------------------------------------------------*/
72+
73+
/* Write buffer enable */
74+
ldr r0,=0b00000010
75+
mcr p15, 0, r0, c3, c0, 0
76+
77+
/* DCache & ICache enable */
78+
ldr r0,=0b01000010
79+
mcr p15, 0, r0, c2, c0, 0
80+
mcr p15, 0, r0, c2, c0, 1
81+
82+
/* IAccess */
83+
ldr r0,=0x36636633
84+
mcr p15, 0, r0, c5, c0, 3
85+
86+
/* DAccess */
87+
ldr r0,=0x36333633
88+
mcr p15, 0, r0, c5, c0, 2
89+
90+
/* Enable ICache, DCache, ITCM & DTCM */
91+
mrc p15, 0, r0, c1, c0, 0
92+
ldr r1,= CP15_ITCM_ENABLE | CP15_DTCM_ENABLE | CP15_ICACHE_ENABLE | CP15_DCACHE_ENABLE | CP15_PROTECT_ENABLE
93+
orr r0,r0,r1
94+
mcr p15, 0, r0, c1, c0, 0
95+
96+
mov pc, lr

bsp/boot/arm/nds_arm9/cp15.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef CP15_H_
2+
#define CP15_H_
3+
4+
#define CP15_ITCM_ENABLE (1 << 18)
5+
#define CP15_DTCM_ENABLE (1 << 16)
6+
#define CP15_ICACHE_ENABLE (1 << 12)
7+
#define CP15_DCACHE_ENABLE (1 << 2)
8+
#define CP15_PROTECT_ENABLE (1 << 0)
9+
10+
#define CP15_REGION_4K (0b01011 << 1)
11+
#define CP15_REGION_8K (0b01100 << 1)
12+
#define CP15_REGION_16K (0b01101 << 1)
13+
#define CP15_REGION_32K (0b01110 << 1)
14+
#define CP15_REGION_64K (0b01111 << 1)
15+
#define CP15_REGION_128K (0b10000 << 1)
16+
#define CP15_REGION_256K (0b10001 << 1)
17+
#define CP15_REGION_512K (0b10010 << 1)
18+
#define CP15_REGION_1M (0b10011 << 1)
19+
#define CP15_REGION_2M (0b10100 << 1)
20+
#define CP15_REGION_4M (0b10101 << 1)
21+
#define CP15_REGION_8M (0b10110 << 1)
22+
#define CP15_REGION_16M (0b10111 << 1)
23+
#define CP15_REGION_32M (0b11000 << 1)
24+
#define CP15_REGION_64M (0b11001 << 1)
25+
#define CP15_REGION_128M (0b11010 << 1)
26+
#define CP15_REGION_256M (0b11011 << 1)
27+
#define CP15_REGION_512M (0b11100 << 1)
28+
#define CP15_REGION_1G (0b11101 << 1)
29+
#define CP15_REGION_2G (0b11110 << 1)
30+
#define CP15_REGION_4G (0b11111 << 1)
31+
32+
#endif /* CP15_H_ */

bsp/boot/arm/nds_arm9/debug.c

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*-
2+
* Copyright (c) 2008-2009, Kohsuke Ohtani
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. Neither the name of the author nor the names of any co-contributors
14+
* may be used to endorse or promote products derived from this software
15+
* without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27+
* SUCH DAMAGE.
28+
*/
29+
30+
#include <sys/param.h>
31+
#include <boot.h>
32+
33+
/* Implemented in diag_desmume.S */
34+
void diag_desmume_puts(const char * s);
35+
36+
/*
37+
* Print one chracter
38+
* (buffer sent when it's full or when printing a \n)
39+
*/
40+
void
41+
debug_putc(int c)
42+
{
43+
#if defined(DEBUG) && defined(CONFIG_DIAG_DESMUME)
44+
45+
static char buf[81];
46+
static int i = 0;
47+
48+
buf[i] = c;
49+
50+
if(c == '\n' || i == 80) {
51+
buf[i] = '\0';
52+
diag_desmume_puts(buf);
53+
i = 0;
54+
} else {
55+
i += 1;
56+
}
57+
58+
#endif
59+
}
60+
61+
/*
62+
* Initialize debug port.
63+
*/
64+
void
65+
debug_init(void)
66+
{
67+
68+
}

bsp/boot/arm/nds_arm9/diag_desmume.S

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Print a string to DeSmuME emulator console.
3+
*
4+
* Important:
5+
* This BIOS call is not supported by actual NDS BIOS. So, you must
6+
* disable this function when you run it on actual NDS H/W.
7+
* (by commenting DIAG_DESMUME in the config file)
8+
*
9+
*/
10+
11+
.text
12+
.align 2
13+
14+
.global diag_desmume_puts
15+
16+
diag_desmume_puts:
17+
18+
swi 0xfcfcfc
19+
mov pc, lr

bsp/boot/arm/nds_arm9/head.S

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*-
2+
* Copyright (c) 2008, Kohsuke Ohtani
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. Neither the name of the author nor the names of any co-contributors
14+
* may be used to endorse or promote products derived from this software
15+
* without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27+
* SUCH DAMAGE.
28+
*/
29+
30+
/*
31+
* head.S - startup code.
32+
*/
33+
34+
#include <conf/config.h>
35+
#include <machine/memory.h>
36+
#include <machine/syspage.h>
37+
38+
.text
39+
.align 2
40+
41+
boot_entry:
42+
43+
/* Disable interrupts (IME = 0) */
44+
mov r0, #0x04000000
45+
str r0, [r0, #0x208]
46+
47+
bl cp15_setup
48+
49+
mov r0, #0xd3 /* Enter SVC mode, Disable IRQ,FIQ */
50+
msr cpsr_c, r0
51+
ldr sp, =BOOTSTKTOP
52+
53+
b main
54+
55+
/* to make the bootloader size 0x1FFF (see boot/arm/arch/boot.ld) */
56+
.section .tail,"ax"
57+
dummy:
58+
.byte 0xff
59+
60+
.end

0 commit comments

Comments
 (0)