1 /***************************************************************************
2 * Copyright (C) 2006 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
28 @ send word to debugger
29 .macro m_send_to_debugger reg
31 mrc p14, 0, r15, c14, c0, 0
33 mcr p14, 0, \reg, c8, c0, 0
36 @ receive word from debugger
37 .macro m_receive_from_debugger reg
39 mrc p14, 0, r15, c14, c0, 0
41 mrc p14, 0, \reg, c9, c0, 0
44 @ save register on debugger, small
45 .macro m_small_save_reg reg
50 @ save status register on debugger, small
51 .macro m_small_save_psr
56 @ wait for all outstanding coprocessor accesses to complete
58 mrc p15, 0, r0, c2, c0, 0
66 .global prefetch_abort_handler
67 .global data_abort_handler
71 .section .part1 , "ax"
75 mrc p14, 0, r13, c10, c0
76 @ check if global enable bit (GE) is set
77 ands r13, r13, #0x80000000
81 @ set global enable bit (GE)
83 mcr p14, 0, r13, c10, c0
87 @ save r0 without modifying other registers
90 @ save lr (program PC) without branching (use macro)
91 m_send_to_debugger r14
93 @ save non-banked registers and spsr (program CPSR)
105 @ prepare program PSR for debug use (clear Thumb, set I/F to disable interrupts)
107 orr r0, r0, #(PSR_I | PSR_F)
110 and r1, r0, #MODE_MASK
115 @ replace USR mode with SYS
116 bic r0, r0, #MODE_MASK
117 orr r0, r0, #MODE_SYS
121 b save_banked_registers
124 @ wait for command from debugger, than execute desired function
126 bl receive_from_debugger
128 @ 0x0n - register access
130 beq get_banked_registers
133 beq set_banked_registers
145 @ 0x2n - write memory
155 @ 0x3n - program execution
162 @ 0x4n - coprocessor access
169 @ 0x5n - cache and mmu functions
174 beq invalidate_d_cache
177 beq invalidate_i_cache
182 @ 0x6n - misc functions
187 beq read_trace_buffer
190 beq clean_trace_buffer
192 @ return (back to get_command)
197 @ resume program execution
199 @ restore CPSR (SPSR_dbg)
200 bl receive_from_debugger
203 @ restore registers (r7 - r0)
204 bl receive_from_debugger @ r7
206 bl receive_from_debugger @ r6
208 bl receive_from_debugger @ r5
210 bl receive_from_debugger @ r4
212 bl receive_from_debugger @ r3
214 bl receive_from_debugger @ r2
216 bl receive_from_debugger @ r1
218 bl receive_from_debugger @ r0
221 m_receive_from_debugger lr
223 @ branch back to application code, restoring CPSR
226 @ get banked registers
227 @ receive mode bits from host, then run into save_banked_registers to
229 get_banked_registers:
230 bl receive_from_debugger
232 @ save banked registers
233 @ r0[4:0]: desired mode bits
234 save_banked_registers:
240 @ keep current mode bits in r1 for later use
241 and r1, r0, #MODE_MASK
243 @ backup banked registers
244 m_send_to_debugger r8
245 m_send_to_debugger r9
246 m_send_to_debugger r10
247 m_send_to_debugger r11
248 m_send_to_debugger r12
249 m_send_to_debugger r13
250 m_send_to_debugger r14
252 @ if not in SYS mode (or USR, which we replaced with SYS before)
259 m_send_to_debugger r0
263 @ restore CPSR for SDS
273 @ set banked registers
274 @ receive mode bits from host, then run into save_banked_registers to
276 set_banked_registers:
277 bl receive_from_debugger
279 @ restore banked registers
280 @ r0[4:0]: desired mode bits
281 restore_banked_registers:
287 @ keep current mode bits in r1 for later use
288 and r1, r0, #MODE_MASK
290 @ set banked registers
291 m_receive_from_debugger r8
292 m_receive_from_debugger r9
293 m_receive_from_debugger r10
294 m_receive_from_debugger r11
295 m_receive_from_debugger r12
296 m_receive_from_debugger r13
297 m_receive_from_debugger r14
299 @ if not in SYS mode (or USR, which we replaced with SYS before)
302 beq no_spsr_to_restore
305 m_receive_from_debugger r0
310 @ restore CPSR for SDS
321 bl receive_from_debugger
325 bl receive_from_debugger
331 @ drain write- (and fill-) buffer to work around XScale errata
332 mcr p15, 0, r8, c7, c10, 4
346 bl receive_from_debugger
350 bl receive_from_debugger
356 @ drain write- (and fill-) buffer to work around XScale errata
357 mcr p15, 0, r8, c7, c10, 4
371 bl receive_from_debugger
375 bl receive_from_debugger
381 @ drain write- (and fill-) buffer to work around XScale errata
382 mcr p15, 0, r8, c7, c10, 4
396 bl receive_from_debugger
400 bl receive_from_debugger
404 bl receive_from_debugger
407 @ drain write- (and fill-) buffer to work around XScale errata
408 mcr p15, 0, r8, c7, c10, 4
420 bl receive_from_debugger
424 bl receive_from_debugger
428 bl receive_from_debugger
431 @ drain write- (and fill-) buffer to work around XScale errata
432 mcr p15, 0, r8, c7, c10, 4
444 bl receive_from_debugger
448 bl receive_from_debugger
452 bl receive_from_debugger
455 @ drain write- (and fill-) buffer to work around XScale errata
456 mcr p15, 0, r8, c7, c10, 4
468 mrc p14, 0, r0, c10, c0
474 mcr p14, 0, r0, c10, c0
482 @ r0: cache clean area
483 bl receive_from_debugger
487 mcr p15, 0, r0, c7, c2, 5
498 mcr p15, 0, r0, c7, c6, 0
506 mcr p15, 0, r0, c7, c5, 0
521 .section .part2 , "ax"
524 @ requested cp register
525 bl receive_from_debugger
527 adr r1, read_cp_table
528 add pc, r1, r0, lsl #3
531 mrc p15, 0, r0, c0, c0, 0 @ XSCALE_MAINID
533 mrc p15, 0, r0, c0, c0, 1 @ XSCALE_CACHETYPE
535 mrc p15, 0, r0, c1, c0, 0 @ XSCALE_CTRL
537 mrc p15, 0, r0, c1, c0, 1 @ XSCALE_AUXCTRL
539 mrc p15, 0, r0, c2, c0, 0 @ XSCALE_TTB
541 mrc p15, 0, r0, c3, c0, 0 @ XSCALE_DAC
543 mrc p15, 0, r0, c5, c0, 0 @ XSCALE_FSR
545 mrc p15, 0, r0, c6, c0, 0 @ XSCALE_FAR
547 mrc p15, 0, r0, c13, c0, 0 @ XSCALE_PID
549 mrc p15, 0, r0, c15, c0, 0 @ XSCALE_CP_ACCESS
551 mrc p15, 0, r0, c14, c8, 0 @ XSCALE_IBCR0
553 mrc p15, 0, r0, c14, c9, 0 @ XSCALE_IBCR1
555 mrc p15, 0, r0, c14, c0, 0 @ XSCALE_DBR0
557 mrc p15, 0, r0, c14, c3, 0 @ XSCALE_DBR1
559 mrc p15, 0, r0, c14, c4, 0 @ XSCALE_DBCON
561 mrc p14, 0, r0, c11, c0, 0 @ XSCALE_TBREG
563 mrc p14, 0, r0, c12, c0, 0 @ XSCALE_CHKPT0
565 mrc p14, 0, r0, c13, c0, 0 @ XSCALE_CHKPT1
567 mrc p14, 0, r0, c10, c0, 0 @ XSCALE_DCSR
579 @ requested cp register
580 bl receive_from_debugger
583 @ value to be written
584 bl receive_from_debugger
586 adr r2, write_cp_table
587 add pc, r2, r1, lsl #3
590 mcr p15, 0, r0, c0, c0, 0 @ XSCALE_MAINID (0x0)
592 mcr p15, 0, r0, c0, c0, 1 @ XSCALE_CACHETYPE (0x1)
594 mcr p15, 0, r0, c1, c0, 0 @ XSCALE_CTRL (0x2)
596 mcr p15, 0, r0, c1, c0, 1 @ XSCALE_AUXCTRL (0x3)
598 mcr p15, 0, r0, c2, c0, 0 @ XSCALE_TTB (0x4)
600 mcr p15, 0, r0, c3, c0, 0 @ XSCALE_DAC (0x5)
602 mcr p15, 0, r0, c5, c0, 0 @ XSCALE_FSR (0x6)
604 mcr p15, 0, r0, c6, c0, 0 @ XSCALE_FAR (0x7)
606 mcr p15, 0, r0, c13, c0, 0 @ XSCALE_PID (0x8)
608 mcr p15, 0, r0, c15, c0, 0 @ XSCALE_CP_ACCESS (0x9)
610 mcr p15, 0, r0, c14, c8, 0 @ XSCALE_IBCR0 (0xa)
612 mcr p15, 0, r0, c14, c9, 0 @ XSCALE_IBCR1 (0xb)
614 mcr p15, 0, r0, c14, c0, 0 @ XSCALE_DBR0 (0xc)
616 mcr p15, 0, r0, c14, c3, 0 @ XSCALE_DBR1 (0xd)
618 mcr p15, 0, r0, c14, c4, 0 @ XSCALE_DBCON (0xe)
620 mcr p14, 0, r0, c11, c0, 0 @ XSCALE_TBREG (0xf)
622 mcr p14, 0, r0, c12, c0, 0 @ XSCALE_CHKPT0 (0x10)
624 mcr p14, 0, r0, c13, c0, 0 @ XSCALE_CHKPT1 (0x11)
626 mcr p14, 0, r0, c10, c0, 0 @ XSCALE_DCSR (0x12)
633 @ dump 256 entries from trace buffer
636 mrc p14, 0, r0, c11, c0, 0 @ XSCALE_TBREG
641 @ dump checkpoint register 0
642 mrc p14, 0, r0, c12, c0, 0 @ XSCALE_CHKPT0 (0x10)
645 @ dump checkpoint register 1
646 mrc p14, 0, r0, c13, c0, 0 @ XSCALE_CHKPT1 (0x11)
656 @ clean 256 entries from trace buffer
659 mrc p14, 0, r0, c11, c0, 0 @ XSCALE_TBREG
669 @ resume program execution with trace buffer enabled
671 @ restore CPSR (SPSR_dbg)
672 bl receive_from_debugger
675 @ restore registers (r7 - r0)
676 bl receive_from_debugger @ r7
678 bl receive_from_debugger @ r6
680 bl receive_from_debugger @ r5
682 bl receive_from_debugger @ r4
684 bl receive_from_debugger @ r3
686 bl receive_from_debugger @ r2
688 bl receive_from_debugger @ r1
690 bl receive_from_debugger @ r0
693 m_receive_from_debugger lr
695 mrc p14, 0, r13, c10, c0, 0 @ XSCALE_DCSR
697 mcr p14, 0, r13, c10, c0, 0 @ XSCALE_DCSR
699 @ branch back to application code, restoring CPSR
704 prefetch_abort_handler:
712 m_send_to_debugger r0
715 receive_from_debugger:
716 m_receive_from_debugger r0