Thread: [Lapetus-cvs] lapetus debug.c, NONE, 1.1 debug.h, NONE, 1.1 dmascu.c, NONE, 1.1 dmash2.c, NONE, 1.1
Status: Inactive
Brought to you by:
cyberwarriorx
From: Theo B. <cyb...@us...> - 2009-06-03 02:16:49
|
Update of /cvsroot/lapetus/lapetus In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30906 Added Files: debug.c debug.h dmascu.c dmash2.c install.bat localex.s remoteex.s ubc.s Log Message: -Added dma stuff -Added exception handler code(local is finish, remote still needs work) -Added early ubc code -Other stuff --- NEW FILE: ubc.s --- ! Copyright 2007 Theo Berkau ! ! This file is part of Lapetus. ! ! Lapetus 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 2 of the License, or ! (at your option) any later version. ! ! Lapetus 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 Lapetus; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA .section .text ! UbcSetCodeBreakpoint !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .global _UbcSetCodeBreakpoint ! R4 = slot, R5 = address, returns LAPETUS_ERR_OK if no problems _UbcSetCodeBreakpoint: mov.l r1, @-r15 cmp/eq r4, #0 ! 0 = Breakpoint A, 1 = Breakpoint B bf bpb ! Breakpoint A !set break address mov.l BARA, r1 mov.l r5, @r1 !set address mask mov.l BAMRA, r1 mov #0, r0 mov.l r0, @r1 !set break conditions mov.l BBRA, r1 mov.w COND, r0 ! Break on CPU cycles, Break only on instruction fetch cycles, break only on read cycles mov.w r0, @r1 !set break control mov.l BRCR, r1 mov.w CTRLA, r0 ! SH7604 mode, break before instruction execution mov.w r0, @r1 mov #0, r0 bra done nop bpb: ! Breakpoint B !set break address mov.l BARB, r1 mov.l r5, @r1 !set address mask mov.l BAMRA, r1 mov #0, r0 mov.l r0, @r1 !set break conditions mov.l BBRB, r1 mov.w COND, r0 ! Break on CPU cycles, Break only on instruction fetch cycles, break only on read cycles mov.w r0, @r1 !set break control mov.l BRCR, r1 ! mov.w CTRLB, r0 ! FIXME mov.w r0, @r1 mov #0, r0 done: mov.l @r15+, r1 rts nop COND: .word 0x0054 CTRLA: .word 0x1000 CTRLB: .word 0x1000 .align 4 BARA: .long 0xFFFFFF40 BAMRA: .long 0xFFFFFF44 BBRA: .long 0xFFFFFF48 BARB: .long 0xFFFFFF60 BAMRB: .long 0xFFFFFF64 BBRB: .long 0xFFFFFF68 BRCR: .long 0xFFFFFF78 ! UbcSetMemoryBreakpoint !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .global _UbcSetMemoryBreakpoint ! R4 = slot, R5 = address, R6 = type, returns LAPETUS_ERR_OK if no problems _UbcSetMemoryBreakpoint: rts nop ! BreakpointHandler !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .global _UBCIntHandler _UBCIntHandler: ! Save all registers to stack stc.l SR, @-r15 stc.l GBR, @-r15 stc.l VBR, @-r15 sts.l MACH, @-r15 sts.l MACL, @-r15 sts.l PR, @-r15 mov.l r0, @-r15 mov.l r1, @-r15 mov.l r2, @-r15 mov.l r3, @-r15 mov.l r4, @-r15 mov.l r5, @-r15 mov.l r6, @-r15 mov.l r7, @-r15 mov.l r8, @-r15 mov.l r9, @-r15 mov.l r10, @-r15 mov.l r11, @-r15 mov.l r12, @-r15 mov.l r13, @-r15 mov.l r14, @-r15 mov.l r15, @-r15 ! Copy all registers to work buffer mov.l WORKBUFADDR, r0 add #4, r0 mov.l r15, r1 add #?, r1 ! I need to calculate how much this needs to be adjusted by copylp: mov.l @r1+, r2 mov.l r2, @r0 add #4, r0 ! cmp/ge r15, r1 !double check to make sure this is right bf copylp ! Let PC know we're ready to transfer data mov.l WORKBUFADDR, r0 mov.l READY, r1 mov.l r1, @r0 ! Go into endless loop waiting for PC's response mov.l DONE, r1 waitlp: !trapa ! this needs work(the idea is it's supposed to latch onto the ar's commlink functions mov.l @r0, r2 cmp/eq r2, r1 bf waitlp ! Restore registers back to their original state mov.l @r15+, r15 mov.l @r15+, r14 mov.l @r15+, r13 mov.l @r15+, r12 mov.l @r15+, r11 mov.l @r15+, r10 mov.l @r15+, r9 mov.l @r15+, r8 mov.l @r15+, r7 mov.l @r15+, r6 mov.l @r15+, r5 mov.l @r15+, r4 mov.l @r15+, r3 mov.l @r15+, r2 mov.l @r15+, r1 mov.l @r15+, r0 lds.l @r15+, PR lds.l @r15+, MACL lds.l @r15+, MACH ldc.l @r15+, VBR ldc.l @r15+, GBR ldc.l @r15+, SR rte nop .align 4 DONE: .long 0x5A5A5A5A READY: .long 0xA5A5A5A5 WORKBUFADDR: .long 0x00000000 --- NEW FILE: debug.h --- /* Copyright 2009 Theo Berkau This file is part of Lapetus. Lapetus 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 2 of the License, or (at your option) any later version. Lapetus 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 Lapetus; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DEBUG_H #define DEBUG_H int RemoteDebuggerStart(void *addr); int RemoteDebuggerStop(void); int DebuggerStart(void); void DebuggerSetCodeBreakpoint(u32 addr); void DebuggerClearCodeBreakpoint(); void DebuggerSetMemoryBreakpoint(u32 addr, u32 val, u32 valmask, int rw, int size); void DebuggerClearMemoryBreakpoint(u32 addr); int DebuggerStop(void); #endif --- NEW FILE: install.bat --- copy liblapetus.a C:\PROGRA~3\KPITCU~1\GNUSHV~1\sh-coff\sh-coff\lib copy *.h C:\PROGRA~3\KPITCU~1\GNUSHV~1\sh-coff\sh-coff\include --- NEW FILE: dmash2.c --- /* Copyright 2007 Theo Berkau This file is part of Lapetus. Lapetus 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 2 of the License, or (at your option) any later version. Lapetus 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 Lapetus; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "lapetus.h" #define SAR0 (*(volatile u32 *)0xFFFFFF80) #define DAR0 (*(volatile u32 *)0xFFFFFF84) #define TCR0 (*(volatile u32 *)0xFFFFFF88) #define CHCR0 (*(volatile u32 *)0xFFFFFF8C) #define VCRDMA0 (*(volatile u32 *)0xFFFFFFA0) #define DRCR0 (*(volatile u8 *)0xFFFFFE71) #define SAR1 (*(volatile u32 *)0xFFFFFF90) #define DAR1 (*(volatile u32 *)0xFFFFFF94) #define TCR1 (*(volatile u32 *)0xFFFFFF98) #define CHCR1 (*(volatile u32 *)0xFFFFFF9C) #define VCRDMA1 (*(volatile u32 *)0xFFFFFFA8) #define DRCR1 (*(volatile u8 *)0xFFFFFE72) #define DMAOR (*(volatile u32 *)0xFFFFFFB0) ////////////////////////////////////////////////////////////////////////////// int Sh2DMAInit(void) { Sh2DMAStopAll(); CHCR0 = 0; CHCR1 = 0; return LAPETUS_ERR_OK; } ////////////////////////////////////////////////////////////////////////////// int Sh2DMAStart(int chan, void *src, void *dst, u32 size, u32 mode) { if (chan == 0) { // Set Source SAR0 = (u32)src; // Set Destination DAR0 = (u32)dst; // Set Transfer Count TCR0 = size; // Use external request DRCR0 = 0; // Set the Mode and Enable DMA CHCR0 = (CHCR0 & 0x0) | mode | 0x1; return LAPETUS_ERR_OK; } else if (chan == 1) { // Set Source SAR1 = (u32)src; // Set Destination DAR1 = (u32)dst; // Set Transfer Count TCR1 = size; // Use external request DRCR1 = 0; // Set the Mode and Enable DMA CHCR1 = (CHCR1 & 0x0) | mode | 0x1; return LAPETUS_ERR_OK; } return LAPETUS_ERR_INVALIDARG; } ////////////////////////////////////////////////////////////////////////////// BOOL IsSh2DMARunning(int chan) { // if (DMAOR & 0x1) { // Check if transfer end flag is set if (chan == 0 && !(CHCR0 & 0x2)) return TRUE; else if (chan == 1 && !(CHCR1 & 0x2)) return TRUE; } return FALSE; } ////////////////////////////////////////////////////////////////////////////// void Sh2DMAStopAll(void) { DMAOR = DMAOR & 0xE; } ////////////////////////////////////////////////////////////////////////////// --- NEW FILE: dmascu.c --- /* Copyright 2007 Theo Berkau This file is part of Lapetus. Lapetus 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 2 of the License, or (at your option) any later version. Lapetus 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 Lapetus; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "lapetus.h" #define SCUREG_D0R (*(volatile u32 *)0x25FE0000) #define SCUREG_D0W (*(volatile u32 *)0x25FE0004) #define SCUREG_D0C (*(volatile u32 *)0x25FE0008) #define SCUREG_D0AD (*(volatile u32 *)0x25FE000C) #define SCUREG_D0EN (*(volatile u32 *)0x25FE0010) #define SCUREG_D0MD (*(volatile u32 *)0x25FE0014) #define SCUREG_D1R (*(volatile u32 *)0x25FE0020) #define SCUREG_D1W (*(volatile u32 *)0x25FE0024) #define SCUREG_D1C (*(volatile u32 *)0x25FE0028) #define SCUREG_D1AD (*(volatile u32 *)0x25FE002C) #define SCUREG_D1EN (*(volatile u32 *)0x25FE0030) #define SCUREG_D1MD (*(volatile u32 *)0x25FE0034) #define SCUREG_D2R (*(volatile u32 *)0x25FE0040) #define SCUREG_D2W (*(volatile u32 *)0x25FE0044) #define SCUREG_D2C (*(volatile u32 *)0x25FE0048) #define SCUREG_D2AD (*(volatile u32 *)0x25FE004C) #define SCUREG_D2EN (*(volatile u32 *)0x25FE0050) #define SCUREG_D2MD (*(volatile u32 *)0x25FE0054) #define SCUREG_T0C (*(volatile u32 *)0x25FE0090) #define SCUREG_T1S (*(volatile u32 *)0x25FE0094) #define SCUREG_T1MD (*(volatile u32 *)0x25FE0098) #define SCUREG_IMS (*(volatile u32 *)0x25FE00A0) #define SCUREG_IST (*(volatile u32 *)0x25FE00A4) #define SCUREG_AIACK (*(volatile u32 *)0x25FE00A8) #define SCUREG_ASR0 (*(volatile u32 *)0x25FE00B0) #define SCUREG_ASR1 (*(volatile u32 *)0x25FE00B4) #define SCUREG_RSEL (*(volatile u32 *)0x25FE00C4) #define SCUREG_VER (*(volatile u32 *)0x25FE00C8) ////////////////////////////////////////////////////////////////////////////// int ScuDMAInit(void) { ScuDMAStopAll(); SCUREG_D0EN = 0; SCUREG_D1EN = 0; SCUREG_D2EN = 0; return LAPETUS_ERR_OK; } ////////////////////////////////////////////////////////////////////////////// int ScuDMAStart(int chan, void *src, void *dst, u32 size, u32 add, u32 mode) { // Check first to make sure the channel has no pending DMA operation going switch (chan) { case 0: // Make sure everything is disabled SCUREG_D0EN = 0; // Write the read address SCUREG_D0R = (u32)src; // Write the write address SCUREG_D0W = (u32)dst; // Write the transfer number SCUREG_D0C = size; SCUREG_D0AD = add; SCUREG_D0MD = mode; if ((mode & 0x7) == 0x7) SCUREG_D0EN = 0x101; else SCUREG_D0EN = 0x100; break; case 1: // Make sure everything is disabled SCUREG_D1EN = 0; // Write the read address SCUREG_D1R = (u32)src; // Write the write address SCUREG_D1W = (u32)dst; // Write the transfer number SCUREG_D1C = size; SCUREG_D1AD = add; SCUREG_D1MD = mode; if ((mode & 0x7) == 0x7) SCUREG_D1EN = 0x101; else SCUREG_D1EN = 0x100; break; case 2: // Make sure everything is disabled SCUREG_D2EN = 0; // Write the read address SCUREG_D2R = (u32)src; // Write the write address SCUREG_D2W = (u32)dst; // Write the transfer number SCUREG_D2C = size; SCUREG_D2AD = add; SCUREG_D2MD = mode; if ((mode & 0x7) == 0x7) SCUREG_D2EN = 0x101; else SCUREG_D2EN = 0x100; break; default: return LAPETUS_ERR_INVALIDARG; } return LAPETUS_ERR_OK; } ////////////////////////////////////////////////////////////////////////////// BOOL IsScuDMARunning(int chan) { switch (chan) { case 0: // if (SCUREG_DSTA & ?) // return LAPETUS_ERR_BUSY; case 1: case 2: default: return FALSE; } } ////////////////////////////////////////////////////////////////////////////// void ScuDMAStopAll(void) { SCUREG_DSTP = 1; } ////////////////////////////////////////////////////////////////////////////// --- NEW FILE: remoteex.s --- ! Copyright 2007 Theo Berkau ! ! This file is part of Lapetus. ! ! Lapetus 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 2 of the License, or ! (at your option) any later version. ! ! Lapetus 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 Lapetus; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA .section .text _RemoteDebugStart: .long ExchangeByte _RemoteDebugSize: .long endofcode-ExchangeByte _RemoteExGeneralIllegalInstruction: .long RemoteExGeneralIllegalInstruction-ExchangeByte _RemoteExSlotIllegalInstruction: .long RemoteExSlotIllegalInstruction-ExchangeByte _RemoteExCPUAddressError: .long RemoteExCPUAddressError-ExchangeByte _RemoteExDMAAddressError: .long RemoteExDMAAddressError-ExchangeByte _RemoteUBCHandler: .long RemoteUBCHandler-ExchangeByte !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ExchangeByte: mov.l R1, @-R15 mov.l STATPORT, r1 ! Keep reading the status port until there's data ready statloop: mov.b @R1, R0 cmp/eq #1, R0 bf statloop ! Alright, there's finally data ready. Let's do a byte exchange mov.l INPORT, R0 ! retrieve from inport mov.b @R0, R0 extu.b R0, R0 mov.l OUTPORT, R1 ! Write to outport mov.b R4, @R1 ! Ok, we're done, time to cleanup rts mov.l @r15+, r1 .align 4 OUTPORT: .long 0x22080001 STATPORT: .long 0x22100001 INPORT: .long 0x22180001 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SendLong: sts.l pr, @-R15 mov.l R1, @-R15 mov R4, R1 ! Send highest byte shlr16 R4 bsr ExchangeByte shlr8 R4 ! Send second-highest byte mov R1, R4 bsr ExchangeByte shlr16 R4 ! Send second-lowest byte mov R1, R4 bsr ExchangeByte shlr8 R4 ! Send lowest byte bsr ExchangeByte mov R1, R4 ! Alright, we're done mov.l @r15+, r1 rts lds.l @r15+, pr .align 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! saveregisters: stc.l SR, @-r15 stc.l GBR, @-r15 stc.l VBR, @-r15 sts.l MACH, @-r15 sts.l MACL, @-r15 mov.l r0, @-r15 mov.l r1, @-r15 mov.l r2, @-r15 mov.l r3, @-r15 mov.l r4, @-r15 mov.l r5, @-r15 mov.l r6, @-r15 mov.l r7, @-r15 mov.l r8, @-r15 mov.l r9, @-r15 mov.l r10, @-r15 mov.l r11, @-r15 mov.l r12, @-r15 mov.l r13, @-r15 mov.l r14, @-r15 rts mov.l r15, @-r15 ! this can't be right .align 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SendExceptionData: sts PR, R8 mov R4, R0 ! Send the data back to computer(use 0x01 return command) bsr ExchangeByte mov #1, R4 ! exception type bsr ExchangeByte mov R0, R4 ! Send all Registers to computer mov #21, r1 genregloop: bsr SendLong mov.l @r15+, r4 cmp/pl r1 bf/s genregloop add #-1, R1 lds R8, PR rts nop .align 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RemoteExGeneralIllegalInstruction: ! Save all registers to stack sts.l PR, @-r15 bsr saveregisters nop ! Now that we've insured that we have the previous program's state at crash ! Let's start doing our own thing ! Send the initial exception data bsr SendExceptionData mov #0, R4 ! Wait in a loop until the computer tells us what to do giloop: bra giloop nop !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RemoteExSlotIllegalInstruction: ! Save all registers to stack sts.l PR, @-r15 bsr saveregisters nop ! Now that we've insured that we have the previous program's state at crash ! Let's start doing our own thing ! Send the initial exception data bsr SendExceptionData mov #1, R4 ! Wait in a loop until the computer tells us what to do siloop: bra siloop nop .align 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RemoteExCPUAddressError: ! Save all registers to stack sts.l PR, @-r15 bsr saveregisters nop ! Now that we've insured that we have the previous program's state at crash ! Let's start doing our own thing ! Send the initial exception data bsr SendExceptionData mov #1, R4 ! Wait in a loop until the computer tells us what to do caloop: bra caloop nop .align 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RemoteExDMAAddressError: ! Save all registers to stack sts.l PR, @-r15 bsr saveregisters nop ! Now that we've insured that we have the previous program's state at crash ! Let's start doing our own thing ! Send the initial exception data bsr SendExceptionData mov #1, R4 ! Wait in a loop until the computer tells us what to do daloop: bra daloop nop .align 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RemoteUBCHandler: ! Save all registers to stack sts.l PR, @-r15 bsr saveregisters nop ! Now that we've insured that we have the previous program's state at crash ! Let's start doing our own thing ubcloop: bra ubcloop nop .align 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! endofcode: --- NEW FILE: debug.c --- // Almost everything is done here. I just need to finish the AR polling code // which should use the UBC. Also the UBC handler needs to be implemented // (in remoteex.s). I think I may remove the Local debugger altogether // I may also consider adding some profiler code #include <lapetus.h> #define BARA (*(volatile u32 *)0xFFFFFF40) #define BAMRA (*(volatile u32 *)0xFFFFFF44) #define BBRA (*(volatile u16 *)0xFFFFFF48) #define BARB (*(volatile u32 *)0xFFFFFF60) #define BAMRB (*(volatile u32 *)0xFFFFFF64) #define BBRB (*(volatile u16 *)0xFFFFFF68) #define BDRB (*(volatile u32 *)0xFFFFFF70) #define BDMRB (*(volatile u32 *)0xFFFFFF74) #define BRCR (*(volatile u16 *)0xFFFFFF78) #if 0 extern u32 RemoteDebugStart; extern u32 RemoteDebugSize; extern u32 RemoteExGeneralIllegalInstruction; extern u32 RemoteExSlotIllegalInstruction; extern u32 RemoteExCPUAddressError; extern u32 RemoteExDMAAddressError; extern u32 RemoteUBCHandler; //void RemoteUBCHandler(void) __attribute__ ((interrupt_handler)); #endif void ExGeneralIllegalInstruction(void); void ExSlotIllegalInstruction(void); void ExCPUAddressError(void); void ExDMAAddressError(void); void UBCHandler(void) __attribute__ ((interrupt_handler)); #if 0 /* ////////////////////////////////////////////////////////////////////////////// // This will be move to asm void RemoteUBCHandler(void) { // Let's establish which interrupt was triggered if (BRCR & 0x8000) { // Channel A(Code Breakpoint) // Send data back to computer notifying it that we're in a breakpoint(use 0x02 return command) } else if (BRCR & 0x80) { // Channel B(Memory Breakpoint) // Send data back to computer notifying it that we're in a breakpoint(use 0x02 return command) } // Clear A and B condition matches BRCR = BRCR & 0x3F3F; } */ ////////////////////////////////////////////////////////////////////////////// int RemoteDebuggerStart(void *addr) { u32 *outbuf=(u32 *)addr; u32 *buf=(u32 *)RemoteDebugStart; u32 i; // Copy over code for (i = 0; i < RemoteDebugSize; i++) outbuf[i] = buf[i]; // Setup exception functions BIOS_SetSH2Interrupt(0x4, addr+RemoteExGeneralIllegalInstruction); BIOS_SetSH2Interrupt(0x6, addr+RemoteExSlotIllegalInstruction); BIOS_SetSH2Interrupt(0x9, addr+RemoteExCPUAddressError); BIOS_SetSH2Interrupt(0xA, addr+RemoteExDMAAddressError); BIOS_SetSH2Interrupt(0xC, addr+RemoteUBCHandler); // Hijack interrupt handling function here // if (so and so word == ?) // replace word with bra instruction return LAPETUS_ERR_OK; } ////////////////////////////////////////////////////////////////////////////// int RemoteDebuggerStop(void) { BIOS_SetSH2Interrupt(0x4, 0); BIOS_SetSH2Interrupt(0x6, 0); BIOS_SetSH2Interrupt(0x9, 0); BIOS_SetSH2Interrupt(0xA, 0); BIOS_SetSH2Interrupt(0xC, 0); // Give interrupt handling function control back here return LAPETUS_ERR_OK; } ////////////////////////////////////////////////////////////////////////////// #endif void UBCHandler(void) { // if (BRCR & ?) } ////////////////////////////////////////////////////////////////////////////// int DebuggerStart(void) { // This function basically sets up exception handlers, disables remote // debugging, and sets things up to allows for breakpoints int ret; if ((ret = DebuggerStop()) != LAPETUS_ERR_OK) return ret; BIOS_SetSH2Interrupt(0x4, ExGeneralIllegalInstruction); BIOS_SetSH2Interrupt(0x6, ExSlotIllegalInstruction); BIOS_SetSH2Interrupt(0x9, ExCPUAddressError); BIOS_SetSH2Interrupt(0xA, ExDMAAddressError); // Clear the UBC registers BBRA = 0; BBRB = 0; BDRB = 0; BRCR = 0; BIOS_SetSH2Interrupt(0xC, UBCHandler); // Adjust level mask if (InterruptGetLevelMask() > 0xE) InterruptSetLevelMask(0xE); return LAPETUS_ERR_OK; } ////////////////////////////////////////////////////////////////////////////// void DebuggerSetCodeBreakpoint(u32 addr) { BARA = addr; BAMRA = 0; // break on cpu cycles, instruction fetch cycles, read/write cycles BBRA = (0x1 << 6) | (0x1 << 4) | (0x3 << 2) | 0; // Clear the condition match flags, break before instruction execution BRCR = (BRCR & 0x3BFF); } ////////////////////////////////////////////////////////////////////////////// void DebuggerClearCodeBreakpoint() { BBRA = 0; } ////////////////////////////////////////////////////////////////////////////// void DebuggerSetMemoryBreakpoint(u32 addr, u32 val, u32 valmask, int rw, int size) { BARB = addr; BAMRB = 0; BDRB = val; BDMRB = valmask; // break on cpu cycles, data access cycles, etc. BBRB = (0x1 << 6) | (0x2 << 4) | ((rw & 0x3) << 2) | (size & 0x3); // Clear the condition match flags, break before instruction execution BRCR = (BRCR & 0xFF33); } ////////////////////////////////////////////////////////////////////////////// void DebuggerClearMemoryBreakpoint(u32 addr) { BBRB = 0; } ////////////////////////////////////////////////////////////////////////////// int DebuggerStop(void) { BIOS_SetSH2Interrupt(0x4, 0); BIOS_SetSH2Interrupt(0x6, 0); BIOS_SetSH2Interrupt(0x9, 0); BIOS_SetSH2Interrupt(0xA, 0); BIOS_SetSH2Interrupt(0xC, 0); return LAPETUS_ERR_OK; } ////////////////////////////////////////////////////////////////////////////// --- NEW FILE: localex.s --- .section .text ! Things to finish: ! -Replace remaining old code to new .macro SaveRegisters sts.l PR, @-r15 stc.l GBR, @-r15 stc.l VBR, @-r15 sts.l MACH, @-r15 sts.l MACL, @-r15 mov.l r0, @-r15 mov.l r1, @-r15 mov.l r2, @-r15 mov.l r3, @-r15 mov.l r4, @-r15 mov.l r5, @-r15 mov.l r6, @-r15 mov.l r7, @-r15 mov.l r8, @-r15 mov.l r9, @-r15 mov.l r10, @-r15 mov.l r11, @-r15 mov.l r12, @-r15 mov.l r13, @-r15 mov.l r14, @-r15 mov r15, r0 add #0x58, r0 mov.l r0, @-r15 .endm ! Global Data !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .align 4 debugdispsettings: ! bitmap specific disp_bitmapsize: .byte 0 ! BG_BITMAP512x256 ! tile specific disp_charsize: .byte 0 disp_patternnamesize: .byte 0 disp_planesize: .byte 0 disp_map: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 disp_flipfunction: .byte 0 disp_extracharnum: .byte 0 ! used by both bitmap and tile disp_transparentbit: .byte 0 disp_color: .byte 1 ! BG_256COLOR disp_isbitmap: .byte 1 disp_specialpriority: .byte 0 disp_specialcolorcalc: .byte 0 disp_extrapalettenum: .byte 0 disp_mapoffset: .byte 0 ! rotation specific disp_rotationmode: .byte 0 disp_padding: .byte 0, 0 disp_parameteraddr: .long 0x25E60000 .align 4 debugfont: font_width: .byte 8 font_height: .byte 8 font_bpp: .byte 1 font_padding: .byte 1 font_data: .long _font8x8 font_charsize: .long 0 font_lineinc: .long 0 out: .long 0x25E00000 font_drawchar: .long 0 font_screen: .long 0 font_transparent: .long 0 ! ExGeneralIllegalInstruction !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .global _ExGeneralIllegalInstruction _ExGeneralIllegalInstruction: ! Save all registers to stack SaveRegisters mov.l aGeneralInst_ptr, r10 ! message ! Let's display everything mov.l dispstuff_ptr,r1 jmp @r1 nop .align 4 dispstuff_ptr: .long dispstuff aGeneralInst_ptr: .long aGeneralInst aGeneralInst: .ascii "General Illegal Instruction" ! ExSlotIllegalInstruction !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .align 4 .global _ExSlotIllegalInstruction _ExSlotIllegalInstruction: ! Save all registers to stack SaveRegisters mov.l aSlotInst_ptr, r10 ! message ! Let's display everything mov.l dispstuff_ptr_2,r1 jmp @r1 nop .align 4 dispstuff_ptr_2: .long dispstuff aSlotInst_ptr: .long aSlotInst aSlotInst: .ascii "Slot Illegal Instruction" ! ExCPUAddressError !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .align 4 .global _ExCPUAddressError _ExCPUAddressError: ! Save all registers to stack SaveRegisters mov.l aCPUAddr_ptr, r10 ! message ! Let's display everything mov.l dispstuff_ptr_3,r1 jmp @r1 nop .align 4 dispstuff_ptr_3: .long dispstuff aCPUAddr_ptr: .long aCPUAddr aCPUAddr: .ascii "CPU Address Error" ! ExDMAAddressError !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .align 4 .global _ExDMAAddressError _ExDMAAddressError: ! Save all registers to stack SaveRegisters mov.l aDMAAddr_ptr, r10 ! message mov.l dispstuff_ptr_4,r1 jmp @r1 nop .align 4 dispstuff_ptr_4: .long dispstuff aDMAAddr_ptr: .long aDMAAddr aDMAAddr: .ascii "DMA Address Error" ! dispstuff !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .align 4 dispstuff: ! Init Lapetus mov.l InitLapetus_ptr, r1 jsr @r1 mov #0, r4 ! RES_320x224 ! Setup RBG0 Screen mov.l debugdispsettings_ptr, r4 mov.l VdpRBG0Init_ptr, r1 jsr @r1 nop ! Use the default palette mov.l VdpSetDefaultPalette_ptr, r1 jsr @r1 nop ! Setup an 8x8 1BPP font mov #0, r6 ! Non-transparent text mov.l debugfont_ptr, r5 mov.l VdpSetFont_ptr, r1 jsr @r1 mov #4, r4 ! SCREEN_RBG0 ! Render Error Text ! void VdpPrintText(font_struct *font, int x, int y, int color, const char *text) add #-4, r15 mov.l r10, @r15 ! text mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov #0x8, r6 ! y mov.l VdpPrintText_ptr,r1 jsr @r1 mov #0x10, r5 ! x add #4, r15 ! Render Registers R0-R15 mov #0x10 r8 mov #0x90, r9 extu.b r9, r9 mov r15, r11 regdisploop1: add #-0x1, r8 ! Display Register Name and Value add #-0xC, r15 ! For Reg 0-9 we want an extra space mov #0xA, r0 cmp/ge r0, r8 bf useregname2 mov.l aRegName1_ptr, r0 bra regname1_done nop useregname2: mov.l aRegName2_ptr, r0 regname1_done: mov.l r0, @r15 !aRegName1_ptr/aRegName2_ptr mov.l r8, @(4, r15) ! Register Number mov.l @r11+, r0 mov.l r0, @(8, r15) ! Register Value mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov r9, r6 ! y mov.l VdpPrintf_ptr,r1 jsr @r1 mov #0, r5 ! x add #0xC, r15 add #-0x8, r9 cmp/pl r8 bt regdisploop1 ! Render MACL Register add #-0x8, r15 mov.l aMACLName_ptr, r0 mov.l r0, @r15 ! aMACLName_ptr mov.l @r11+, r0 mov.l r0, @(4, r15) ! Register Value mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov #0xB8, r6 ! y extu.b r6,r6 mov.l VdpPrintf_ptr,r1 jsr @r1 mov #0, r5 ! x add #0x8, r15 ! Render MACH Register add #-0x8, r15 mov.l aMACHName_ptr, r0 mov.l r0, @r15 ! aMACHName_ptr mov.l @r11+, r0 mov.l r0, @(4, r15) ! Register Value mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov #0xB0, r6 ! y extu.b r6,r6 mov.l VdpPrintf_ptr,r1 jsr @r1 mov #0, r5 ! x add #0x8, r15 ! Render VBR Register add #-0x8, r15 mov.l aVBRName_ptr, r0 mov.l r0, @r15 ! aVBRName_ptr mov.l @r11+, r0 mov.l r0, @(4, r15) ! Register Value mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov #0xA8, r6 ! y extu.b r6,r6 mov.l VdpPrintf_ptr,r1 jsr @r1 mov #0, r5 ! x add #0x8, r15 ! Render GBR Register add #-0x8, r15 mov.l aGBRName_ptr, r0 mov.l r0, @r15 ! aGBRName_ptr mov.l @r11+, r0 mov.l r0, @(4, r15) ! Register Value mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov #0xA0, r6 ! y extu.b r6,r6 mov.l VdpPrintf_ptr,r1 jsr @r1 mov #0, r5 ! x add #0x8, r15 ! Render PR Register add #-0x8, r15 mov.l aPRName_ptr, r0 mov.l r0, @r15 ! aPRName_ptr mov.l @r11+, r0 mov.l r0, @(4, r15) ! Register Value mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov #0xC0, r6 ! y extu.b r6,r6 mov.l VdpPrintf_ptr,r1 jsr @r1 mov #0, r5 ! x add #0x8, r15 ! Render PC Register add #-0x8, r15 mov.l aPCName_ptr, r0 mov.l r0, @r15 ! aPCName_ptr mov.l @r11+, r0 add #-2, r0 mov.l r0, @(4, r15) ! Register Value mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov #0xC8, r6 ! y extu.b r6,r6 mov.l VdpPrintf_ptr,r1 jsr @r1 mov #0, r5 ! x add #0x8, r15 ! Render SR Register add #-0x8, r15 mov.l aSRName_ptr, r0 mov.l r0, @r15 ! aSRName_ptr mov.l @r11+, r0 mov.l r0, @(4, r15) ! Register Value mov.l debugfont_ptr, r4 mov #0xF, r7 ! color mov #0x98, r6 ! y extu.b r6,r6 mov.l VdpPrintf_ptr,r1 jsr @r1 mov #0, r5 ! x add #0x8, r15 ! Display On mov.l VdpDispOn_ptr,r1 jsr @r1 nop mov.l CommlinkStartService_ptr, r1 jsr @r1 nop endlessloop: mov.l VdpVsync_ptr, r1 jsr @r1 nop mov.l per_ptr, r1 add #2, r1 mov.w @r1, r1 extu.w r1, r1 shlr8 r1 shlr2 r1 mov r1, r0 and #1, r0 extu.b r0, r1 tst r1, r1 bf reset bra endlessloop nop reset: mov.l SmpcCommand_ptr, r1 jsr @r1 mov #0xD, r4 ! SMPC_CMD_SYSRES colorf0_5: .word 0x00F0 .align 4 InitLapetus_ptr: .long _InitLapetus debugdispsettings_ptr: .long debugdispsettings VdpRBG0Init_ptr: .long _VdpRBG0Init VdpSetDefaultPalette_ptr: .long _VdpSetDefaultPalette debugfont_ptr: .long debugfont VdpSetFont_ptr: .long _VdpSetFont VdpPrintf_ptr: .long _VdpPrintf VdpPrintText_ptr: .long _VdpPrintText VdpVsync_ptr: .long _VdpVsync per_ptr: .long _per SmpcCommand_ptr: .long _SmpcCommand aRegName1_ptr: .long aRegName1 aRegName2_ptr: .long aRegName2 aMACLName_ptr: .long aMACLName aMACHName_ptr: .long aMACHName aVBRName_ptr: .long aVBRName aGBRName_ptr: .long aGBRName aPRName_ptr: .long aPRName aPCName_ptr: .long aPCName aSRName_ptr: .long aSRName aRegName1: .ascii "R%d: %08X" .align 4 aRegName2: .ascii "R%d: %08X" .align 4 aMACLName: .ascii "MACL: %08X" .align 4 aMACHName: .ascii "MACH: %08X" .align 4 aVBRName: .ascii "VBR: %08X" .align 4 aGBRName: .ascii "GBR: %08X" .align 4 aPRName: .ascii "PR: %08X" .align 4 aPCName: .ascii "PC: %08X" .align 4 aSRName: .ascii "SR: %08X" .align 4 VdpDispOn_ptr: .long _VdpDispOn CommlinkStartService_ptr: .long _CommlinkStartService |