maintenance on gdb stub (should work again); don't crash when receiving invalid parameters for swi 0x1A-0x1C (and add a crude test case for that)

This commit is contained in:
zeromus 2010-05-15 23:23:10 +00:00
parent 0bb50b5372
commit ed7b6cd6f6
10 changed files with 615 additions and 177 deletions

View File

@ -1895,7 +1895,7 @@ void NDS_exec(s32 nb)
//trap the debug-stalled condition
#ifdef DEVELOPER
singleStep = false;
//(gbd stub doesnt yet know how to trigger these immediately by calling reschedule)
//(gdb stub doesnt yet know how to trigger these immediately by calling reschedule)
while((NDS_ARM9.stalled || NDS_ARM7.stalled) && execute)
{
driver->EMU_DebugIdleUpdate();
@ -1989,11 +1989,11 @@ void execHardware_interrupts()
if((MMU.reg_IF[0]&MMU.reg_IE[0]) && (MMU.reg_IME[0]))
{
//TODO - remove GDB specific code
#ifdef GDB_STUB
if ( armcpu_flagIrq( &NDS_ARM9))
#else
//#ifdef GDB_STUB
// if ( armcpu_flagIrq( &NDS_ARM9))
//#else
if ( armcpu_irqException(&NDS_ARM9))
#endif
//#endif
{
//printf("ARM9 interrupt! flags: %08X ; mask: %08X ; result: %08X\n",MMU.reg_IF[0],MMU.reg_IE[0],MMU.reg_IF[0]&MMU.reg_IE[0]);
//nds.ARM9Cycle = nds.cycles;
@ -2002,11 +2002,11 @@ void execHardware_interrupts()
//TODO - remove GDB specific code
if((MMU.reg_IF[1]&MMU.reg_IE[1]) && (MMU.reg_IME[1]))
{
#ifdef GDB_STUB
if ( armcpu_flagIrq( &NDS_ARM7))
#else
//#ifdef GDB_STUB
// if ( armcpu_flagIrq( &NDS_ARM7))
//#else
if ( armcpu_irqException(&NDS_ARM7))
#endif
//#endif
{
//nds.ARM7Cycle = nds.cycles;
}

View File

@ -254,8 +254,7 @@
TEMPLATE static u32 FASTCALL OP_UND(const u32 i)
{
INFO("ARM%c: Undefined instruction: 0x%08X (%s) PC=0x%08X. Stopped!!!\n", PROCNUM?'7':'9', cpu->instruction, decodeIntruction(false, cpu->instruction), cpu->instruct_adr);
emu_halt();
TRAPUNDEF(cpu);
return 1;
}

View File

@ -111,14 +111,14 @@ armcpu_t NDS_ARM9;
static void
stall_cpu( void *instance) {
armcpu_t *armcpu = (armcpu_t *)instance;
//printf("UNSTALL\n");
printf("UNSTALL\n");
armcpu->stalled = 1;
}
static void
unstall_cpu( void *instance) {
armcpu_t *armcpu = (armcpu_t *)instance;
//printf("UNSTALL\n");
printf("UNSTALL\n");
armcpu->stalled = 0;
}
@ -141,23 +141,20 @@ remove_post_exec_fn( void *instance) {
#endif
#ifdef GDB_STUB
static u32
read_cpu_reg( void *instance, u32 reg_num) {
armcpu_t *armcpu = (armcpu_t *)instance;
u32 reg_value = 0;
static u32 read_cpu_reg( void *instance, u32 reg_num)
{
armcpu_t *armcpu = (armcpu_t *)instance;
if ( reg_num <= 14) {
reg_value = armcpu->R[reg_num];
}
else if ( reg_num == 15) {
reg_value = armcpu->next_instruction;
}
else if ( reg_num == 16) {
/* CPSR */
reg_value = armcpu->CPSR.val;
}
return reg_value;
if ( reg_num <= 14) {
return armcpu->R[reg_num];
}
else if ( reg_num == 15) {
return armcpu->instruct_adr;
}
else if ( reg_num == 16) {
//CPSR
return armcpu->CPSR.val;
}
}
static void
@ -226,9 +223,9 @@ void armcpu_init(armcpu_t *armcpu, u32 adr)
armcpu->waitIRQ = FALSE;
armcpu->wirq = FALSE;
#ifdef GDB_STUB
armcpu->irq_flag = 0;
#endif
//#ifdef GDB_STUB
// armcpu->irq_flag = 0;
//#endif
for(i = 0; i < 15; ++i)
{
@ -248,12 +245,12 @@ void armcpu_init(armcpu_t *armcpu, u32 adr)
armcpu->SPSR_svc.val = armcpu->SPSR_abt.val = armcpu->SPSR_und.val = armcpu->SPSR_irq.val = armcpu->SPSR_fiq.val = 0;
#ifdef GDB_STUB
armcpu->instruct_adr = adr;
armcpu->R[15] = adr + 8;
#else
armcpu->R[15] = adr;
#endif
//#ifdef GDB_STUB
// armcpu->instruct_adr = adr;
// armcpu->R[15] = adr + 8;
//#else
//armcpu->R[15] = adr;
//#endif
armcpu->next_instruction = adr;
@ -261,9 +258,9 @@ void armcpu_init(armcpu_t *armcpu, u32 adr)
if (armcpu->proc_ID==0)
armcpu->coproc[15] = (armcp_t*)armcp15_new(armcpu);
#ifndef GDB_STUB
//#ifndef GDB_STUB
armcpu_prefetch(armcpu);
#endif
//#endif
}
u32 armcpu_switchMode(armcpu_t *armcpu, u8 mode)
@ -378,53 +375,53 @@ template<u32 PROCNUM>
FORCEINLINE static u32 armcpu_prefetch()
{
armcpu_t* const armcpu = &ARMPROC;
#ifdef GDB_STUB
u32 temp_instruction;
#endif
//#ifdef GDB_STUB
// u32 temp_instruction;
//#endif
u32 curInstruction = armcpu->next_instruction;
if(armcpu->CPSR.bits.T == 0)
{
#ifdef GDB_STUB
temp_instruction =
armcpu->mem_if->prefetch32( armcpu->mem_if->data,
armcpu->next_instruction);
if ( !armcpu->stalled) {
armcpu->instruction = temp_instruction;
armcpu->instruct_adr = armcpu->next_instruction;
armcpu->next_instruction += 4;
armcpu->R[15] = armcpu->next_instruction + 4;
}
#else
//#ifdef GDB_STUB
// temp_instruction =
// armcpu->mem_if->prefetch32( armcpu->mem_if->data,
// armcpu->next_instruction);
//
// if ( !armcpu->stalled) {
// armcpu->instruction = temp_instruction;
// armcpu->instruct_adr = armcpu->next_instruction;
// armcpu->next_instruction += 4;
// armcpu->R[15] = armcpu->next_instruction + 4;
// }
//#else
curInstruction &= 0xFFFFFFFC; //please don't change this to 0x0FFFFFFC -- the NDS will happily run on 0xF******* addresses all day long
armcpu->instruction = _MMU_read32<PROCNUM, MMU_AT_CODE>(curInstruction);
armcpu->instruct_adr = curInstruction;
armcpu->next_instruction = curInstruction + 4;
armcpu->R[15] = curInstruction + 8;
#endif
//#endif
return MMU_codeFetchCycles<PROCNUM,32>(curInstruction);
}
#ifdef GDB_STUB
temp_instruction =
armcpu->mem_if->prefetch16( armcpu->mem_if->data,
armcpu->next_instruction);
if ( !armcpu->stalled) {
armcpu->instruction = temp_instruction;
armcpu->instruct_adr = armcpu->next_instruction;
armcpu->next_instruction = armcpu->next_instruction + 2;
armcpu->R[15] = armcpu->next_instruction + 2;
}
#else
//#ifdef GDB_STUB
// temp_instruction =
// armcpu->mem_if->prefetch16( armcpu->mem_if->data,
// armcpu->next_instruction);
//
// if ( !armcpu->stalled) {
// armcpu->instruction = temp_instruction;
// armcpu->instruct_adr = armcpu->next_instruction;
// armcpu->next_instruction = armcpu->next_instruction + 2;
// armcpu->R[15] = armcpu->next_instruction + 2;
// }
//#else
curInstruction &= 0xFFFFFFFE; //please don't change this to 0x0FFFFFFE -- the NDS will happily run on 0xF******* addresses all day long
armcpu->instruction = _MMU_read16<PROCNUM, MMU_AT_CODE>(curInstruction);
armcpu->instruct_adr = curInstruction;
armcpu->next_instruction = curInstruction + 2;
armcpu->R[15] = curInstruction + 4;
#endif
//#endif
if(PROCNUM==0)
{
@ -499,6 +496,9 @@ void armcpu_exception(armcpu_t *cpu, u32 number)
printf("armcpu_exception!\n");
//extern bool dolog;
//dolog=true;
//HOW DOES THIS WORTK WITHOUT A PREFETCH, LIKE IRQ BELOW?
//I REALLY WISH WE DIDNT PREFETCH BEFORE EXECUTING
}
BOOL armcpu_irqException(armcpu_t *armcpu)
@ -508,47 +508,45 @@ BOOL armcpu_irqException(armcpu_t *armcpu)
if(armcpu->CPSR.bits.I) return FALSE;
//TODO - remove GDB specific code
#ifdef GDB_STUB
armcpu->irq_flag = 0;
#endif
//#ifdef GDB_STUB
// armcpu->irq_flag = 0;
//#endif
tmp = armcpu->CPSR;
armcpu_switchMode(armcpu, IRQ);
//TODO - remove GDB specific code
#ifdef GDB_STUB
armcpu->R[14] = armcpu->next_instruction + 4;
#else
//#ifdef GDB_STUB
// armcpu->R[14] = armcpu->next_instruction + 4;
//#else
armcpu->R[14] = armcpu->instruct_adr + 4;
#endif
//#endif
armcpu->SPSR = tmp;
armcpu->CPSR.bits.T = 0;
armcpu->CPSR.bits.I = 1;
armcpu->next_instruction = armcpu->intVector + 0x18;
armcpu->waitIRQ = 0;
//TODO - remove GDB specific code
#ifndef GDB_STUB
armcpu->R[15] = armcpu->next_instruction + 8;
//must retain invariant of having next instruction to be executed prefetched
//(yucky)
armcpu_prefetch(armcpu);
#endif
return TRUE;
}
//TODO - remove GDB specific code
BOOL
armcpu_flagIrq( armcpu_t *armcpu) {
if(armcpu->CPSR.bits.I) return FALSE;
armcpu->waitIRQ = 0;
#ifdef GDB_STUB
armcpu->irq_flag = 1;
#endif
return TRUE;
}
//BOOL
//armcpu_flagIrq( armcpu_t *armcpu) {
// if(armcpu->CPSR.bits.I) return FALSE;
//
// armcpu->waitIRQ = 0;
//
//#ifdef GDB_STUB
// armcpu->irq_flag = 1;
//#endif
//
// return TRUE;
//}
u32 TRAPUNDEF(armcpu_t* cpu)
{
@ -589,60 +587,64 @@ u32 armcpu_exec()
//this assert is annoying. but sometimes it is handy.
//assert(ARMPROC.instruct_adr!=0x00000000);
#ifdef DEVELOPER
if ((((ARMPROC.instruct_adr & 0x0F000000) == 0x0F000000) && (PROCNUM == 0)) ||
(((ARMPROC.instruct_adr & 0x0F000000) == 0x00000000) && (PROCNUM == 1)))
{
switch (ARMPROC.instruct_adr & 0xFFFF)
{
case 0x00000000:
printf("BIOS%c: Reset!!!\n", PROCNUM?'7':'9');
emu_halt();
break;
case 0x00000004:
printf("BIOS%c: Undefined instruction\n", PROCNUM?'7':'9');
//emu_halt();
break;
case 0x00000008:
//printf("BIOS%c: SWI\n", PROCNUM?'7':'9');
break;
case 0x0000000C:
printf("BIOS%c: Prefetch Abort!!!\n", PROCNUM?'7':'9');
//emu_halt();
break;
case 0x00000010:
//printf("BIOS%c: Data Abort!!!\n", PROCNUM?'7':'9');
//emu_halt();
break;
case 0x00000014:
printf("BIOS%c: Reserved!!!\n", PROCNUM?'7':'9');
break;
case 0x00000018:
//printf("BIOS%c: IRQ\n", PROCNUM?'7':'9');
break;
case 0x0000001C:
printf("BIOS%c: Fast IRQ\n", PROCNUM?'7':'9');
break;
}
}
#endif
//#ifdef DEVELOPER
// if ((((ARMPROC.instruct_adr & 0x0F000000) == 0x0F000000) && (PROCNUM == 0)) ||
// (((ARMPROC.instruct_adr & 0x0F000000) == 0x00000000) && (PROCNUM == 1)))
// {
// switch (ARMPROC.instruct_adr & 0xFFFF)
// {
// case 0x00000000:
// printf("BIOS%c: Reset!!!\n", PROCNUM?'7':'9');
// emu_halt();
// break;
// case 0x00000004:
// printf("BIOS%c: Undefined instruction\n", PROCNUM?'7':'9');
// //emu_halt();
// break;
// case 0x00000008:
// //printf("BIOS%c: SWI\n", PROCNUM?'7':'9');
// break;
// case 0x0000000C:
// printf("BIOS%c: Prefetch Abort!!!\n", PROCNUM?'7':'9');
// //emu_halt();
// break;
// case 0x00000010:
// //printf("BIOS%c: Data Abort!!!\n", PROCNUM?'7':'9');
// //emu_halt();
// break;
// case 0x00000014:
// printf("BIOS%c: Reserved!!!\n", PROCNUM?'7':'9');
// break;
// case 0x00000018:
// //printf("BIOS%c: IRQ\n", PROCNUM?'7':'9');
// break;
// case 0x0000001C:
// printf("BIOS%c: Fast IRQ\n", PROCNUM?'7':'9');
// break;
// }
// }
//#endif
//
//#ifdef GDB_STUB
// if (ARMPROC.stalled) {
// return STALLED_CYCLE_COUNT;
// }
//
// /* check for interrupts */
// if (ARMPROC.irq_flag) {
// armcpu_irqException(&ARMPROC);
// }
//
// cFetch = armcpu_prefetch(&ARMPROC);
//
// if (ARMPROC.stalled) {
// return MMU_fetchExecuteCycles<PROCNUM>(cExecute, cFetch);
// }
//#endif
#ifdef GDB_STUB
if (ARMPROC.stalled) {
return STALLED_CYCLE_COUNT;
}
//cFetch = armcpu_prefetch(&ARMPROC);
/* check for interrupts */
if (ARMPROC.irq_flag) {
armcpu_irqException(&ARMPROC);
}
cFetch = armcpu_prefetch(&ARMPROC);
if (ARMPROC.stalled) {
return MMU_fetchExecuteCycles<PROCNUM>(cExecute, cFetch);
}
#endif
//printf("%d: %08X\n",PROCNUM,ARMPROC.instruct_adr);
if(ARMPROC.CPSR.bits.T == 0)
{
@ -674,9 +676,9 @@ u32 armcpu_exec()
/* call the external post execute function */
ARMPROC.post_ex_fn(ARMPROC.post_ex_fn_data, ARMPROC.instruct_adr, 0);
}
#else
cFetch = armcpu_prefetch<PROCNUM>();
ARMPROC.mem_if->prefetch32( ARMPROC.mem_if->data, ARMPROC.next_instruction);
#endif
cFetch = armcpu_prefetch<PROCNUM>();
return MMU_fetchExecuteCycles<PROCNUM>(cExecute, cFetch);
}
@ -702,9 +704,9 @@ u32 armcpu_exec()
/* call the external post execute function */
ARMPROC.post_ex_fn( ARMPROC.post_ex_fn_data, ARMPROC.instruct_adr, 1);
}
#else
cFetch = armcpu_prefetch<PROCNUM>();
ARMPROC.mem_if->prefetch32( ARMPROC.mem_if->data, ARMPROC.next_instruction);
#endif
cFetch = armcpu_prefetch<PROCNUM>();
return MMU_fetchExecuteCycles<PROCNUM>(cExecute, cFetch);
}

View File

@ -978,21 +978,44 @@ TEMPLATE static u32 setHaltCR()
}
TEMPLATE static u32 getSineTab()
{
cpu->R[0] = getsinetbl[cpu->R[0]];
return 1;
{
//ds returns garbage according to gbatek, but we must protect ourselves
if(cpu->R[0] >= ARRAY_SIZE(getsinetbl))
{
printf("Invalid SWI getSineTab: %08X\n",cpu->R[0]);
return 1;
}
cpu->R[0] = getsinetbl[cpu->R[0]];
return 1;
}
TEMPLATE static u32 getPitchTab()
{
cpu->R[0] = getpitchtbl[cpu->R[0]];
return 1;
//ds returns garbage according to gbatek, but we must protect ourselves
if(cpu->R[0] >= ARRAY_SIZE(getpitchtbl))
{
printf("Invalid SWI getPitchTab: %08X\n",cpu->R[0]);
return 1;
}
cpu->R[0] = getpitchtbl[cpu->R[0]];
return 1;
}
TEMPLATE static u32 getVolumeTab()
{
cpu->R[0] = getvoltbl[cpu->R[0]];
return 1;
//ds returns garbage according to gbatek, but we must protect ourselves
if(cpu->R[0] >= ARRAY_SIZE(getvoltbl))
{
printf("Invalid SWI getVolumeTab: %08X\n",cpu->R[0]);
return 1;
}
cpu->R[0] = getvoltbl[cpu->R[0]];
return 1;
}

View File

@ -16,6 +16,9 @@
#include <fcntl.h>
#include "types.h"
#include "NDSSystem.h"
#ifdef WIN32
#include <winsock2.h>
#else
@ -41,7 +44,7 @@
#define UNUSED_PARM( parm) parm
#endif
#if 0
#if 1
#define DEBUG_LOG( fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
#else
#define DEBUG_LOG( fmt, ...)
@ -174,6 +177,7 @@ break_execution( void *data, UNUSED_PARM(uint32_t addr), UNUSED_PARM(int thunmb)
/* stall the processor */
stub->cpu_ctrl->stall( stub->cpu_ctrl->data);
NDS_debug_break();
/* remove the post execution function */
stub->cpu_ctrl->remove_post_ex_fn( stub->cpu_ctrl->data);
@ -202,6 +206,8 @@ step_instruction_watch( void *data, uint32_t addr, UNUSED_PARM(int thunmb)) {
/* indicate the halt */
stub->stop_type = STOP_STEP_BREAK;
indicateCPUStop_gdb( stub);
NDS_debug_break();
}
}
@ -551,6 +557,7 @@ processPacket_gdb( SOCKET_TYPE sock, const uint8_t *packet,
send_reply = 0;
/* remove the cpu stall */
stub->cpu_ctrl->unstall( stub->cpu_ctrl->data);
NDS_debug_continue();
break;
case 's': {
@ -566,7 +573,6 @@ processPacket_gdb( SOCKET_TYPE sock, const uint8_t *packet,
step_instruction_watch,
stub);
stub->emu_stub_state = gdb_stub_state::RUNNING_EMU_GDB_STATE;
stub->ctl_stub_state = gdb_stub_state::START_RUN_GDB_STATE;
stub->main_stop_flag = 0;
@ -574,6 +580,8 @@ processPacket_gdb( SOCKET_TYPE sock, const uint8_t *packet,
/* remove the cpu stall */
stub->cpu_ctrl->unstall( stub->cpu_ctrl->data);
//NDS_debug_step();
NDS_debug_continue();
break;
}
@ -984,6 +992,8 @@ check_breaks_gdb( struct gdb_stub_state *gdb_state,
/* stall the processor */
gdb_state->cpu_ctrl->stall( gdb_state->cpu_ctrl->data);
NDS_debug_break();
/* indicate the break to the GDB stub thread */
gdb_state->stop_type = stop_type;
@ -1247,39 +1257,26 @@ WINAPI listenerThread_gdb( void *data) {
* The memory interface
*
*/
static uint32_t FASTCALL
gdb_prefetch32( void *data, uint32_t adr) {
static uint32_t FASTCALL gdb_prefetch32( void *data, uint32_t adr) {
struct gdb_stub_state *stub = (struct gdb_stub_state *)data;
uint32_t value = 0;
int breakpoint;
breakpoint = check_breaks_gdb( stub, stub->instr_breakpoints, adr, 4,
STOP_BREAKPOINT);
if ( !breakpoint) {
/* pass down to the real memory interace */
value = stub->real_cpu_memio->prefetch32( stub->real_cpu_memio->data,
adr);
}
return value;
//return stub->real_cpu_memio->prefetch32( stub->real_cpu_memio->data, adr);
return 0;
}
static uint16_t FASTCALL
gdb_prefetch16( void *data, uint32_t adr) {
static uint16_t FASTCALL gdb_prefetch16( void *data, uint32_t adr) {
struct gdb_stub_state *stub = (struct gdb_stub_state *)data;
uint16_t value = 0;
int breakpoint;
breakpoint = check_breaks_gdb( stub, stub->instr_breakpoints, adr, 2,
STOP_BREAKPOINT);
if ( !breakpoint) {
/* pass down to the real memory interace */
value = stub->real_cpu_memio->prefetch16( stub->real_cpu_memio->data,
adr);
}
return value;
//return stub->real_cpu_memio->prefetch16( stub->real_cpu_memio->data, adr);
return 0;
}
/** read 8 bit data value */

View File

@ -0,0 +1,41 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
export TARGET := $(shell basename $(CURDIR))
export TOPDIR := $(CURDIR)
.PHONY: $(TARGET).arm7 $(TARGET).arm9
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all: $(TARGET).nds
#---------------------------------------------------------------------------------
$(TARGET).nds : $(TARGET).arm7 $(TARGET).arm9
ndstool -c $(TARGET).nds -7 $(TARGET).arm7 -9 $(TARGET).arm9
#---------------------------------------------------------------------------------
$(TARGET).arm7 : arm7/$(TARGET).elf
$(TARGET).arm9 : arm9/$(TARGET).elf
#---------------------------------------------------------------------------------
arm7/$(TARGET).elf:
$(MAKE) -C arm7
#---------------------------------------------------------------------------------
arm9/$(TARGET).elf:
$(MAKE) -C arm9
#---------------------------------------------------------------------------------
clean:
$(MAKE) -C arm9 clean
$(MAKE) -C arm7 clean
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9

View File

@ -0,0 +1,132 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include build
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb-interwork
CFLAGS := -g -Wall -O2\
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM7
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,-Map,$(notdir $*).map
LIBS := -ldswifi7 -lmm7 -lnds7
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# 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 ARM7BIN := $(TOPDIR)/$(TARGET).arm7
export ARM7ELF := $(CURDIR)/$(TARGET).arm7.elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
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)/*.*)))
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
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)
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM7BIN) : $(ARM7ELF)
@$(OBJCOPY) -O binary $< $@
@echo built ... $(notdir $@)
$(ARM7ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------------
default ARM7 core
Copyright (C) 2005
Michael Noland (joat)
Jason Rogers (dovoto)
Dave Murphy (WinterMute)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <dswifi7.h>
#include <maxmod7.h>
//---------------------------------------------------------------------------------
void VcountHandler() {
//---------------------------------------------------------------------------------
inputGetAndSend();
}
//---------------------------------------------------------------------------------
void VblankHandler(void) {
//---------------------------------------------------------------------------------
Wifi_Update();
}
//---------------------------------------------------------------------------------
int main() {
//---------------------------------------------------------------------------------
irqInit();
fifoInit();
// read User Settings from firmware
readUserSettings();
// Start the RTC tracking IRQ
initClockIRQ();
SetYtrigger(80);
installWifiFIFO();
installSoundFIFO();
mmInstall(FIFO_MAXMOD);
installSystemFIFO();
irqSet(IRQ_VCOUNT, VcountHandler);
irqSet(IRQ_VBLANK, VblankHandler);
irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
//try to crash the emulator by using invalid parameters for these SWI
asm volatile ("mov r0, #0xFF0000\n");
asm volatile ("swi 0x1A0000\n");
asm volatile ("swi 0x1B0000\n");
asm volatile ("swi 0x1C0000\n");
// Keep the ARM7 mostly idle
while (1) swiWaitForVBlank();
}

View File

@ -0,0 +1,132 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O2\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lnds9
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# 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 ARM9BIN := $(TOPDIR)/$(TARGET).arm9
export ARM9ELF := $(CURDIR)/$(TARGET).arm9.elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
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 := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
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
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf *.nds* *.bin
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM9BIN) : $(ARM9ELF)
@$(OBJCOPY) -O binary $< $@
@echo built ... $(notdir $@)
$(ARM9ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -0,0 +1,31 @@
/*---------------------------------------------------------------------------------
Simple console print demo
-- dovoto
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <stdio.h>
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
touchPosition touch;
consoleDemoInit(); //setup the sub screen for printing
iprintf("\n\n\tHello DS dev'rs\n");
iprintf("\twww.drunkencoders.com\n");
iprintf("\twww.devkitpro.org");
while(1) {
touchRead(&touch);
iprintf("\x1b[10;0HTouch x = %04i, %04i\n", touch.rawx, touch.px);
iprintf("Touch y = %04i, %04i\n", touch.rawy, touch.py);
swiWaitForVBlank();
}
return 0;
}