summaryrefslogtreecommitdiff
path: root/arch/cris/arch-v32/kernel/kgdb_asm.S
blob: 3e7fa9ef8510ce43b704147aeee728995f1b0136 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
/*
 *  Copyright (C) 2004 Axis Communications AB
 *
 * Code for handling break 8, hardware breakpoint, single step, and serial
 * port exceptions for kernel debugging purposes.
 */

#include <asm/arch/hwregs/intr_vect.h>

	;; Exported functions.
	.globl kgdb_handle_exception

kgdb_handle_exception:

;; Create a register image of the caller.
;;
;; First of all, save the ACR on the stack since we need it for address calculations.
;; We put it into the register struct later.

  subq     4, $sp
  move.d   $acr, [$sp]

;; Now we are free to use ACR all we want.
;; If we were running this handler with interrupts on, we would have to be careful
;; to save and restore CCS manually, but since we aren't we treat it like every other
;; register.

  move.d   reg,  $acr
  move.d   $r0,  [$acr]        ; Save R0 (start of register struct)
  addq     4,    $acr
  move.d   $r1,  [$acr]        ; Save R1
  addq     4,    $acr
  move.d   $r2,  [$acr]        ; Save R2
  addq     4,    $acr
  move.d   $r3,  [$acr]        ; Save R3
  addq     4,    $acr
  move.d   $r4,  [$acr]        ; Save R4
  addq     4,    $acr
  move.d   $r5,  [$acr]        ; Save R5
  addq     4,    $acr
  move.d   $r6,  [$acr]        ; Save R6
  addq     4,    $acr
  move.d   $r7,  [$acr]        ; Save R7
  addq     4,    $acr
  move.d   $r8,  [$acr]        ; Save R8
  addq     4,    $acr
  move.d   $r9,  [$acr]        ; Save R9
  addq     4,    $acr
  move.d   $r10, [$acr]        ; Save R10
  addq     4,    $acr
  move.d   $r11, [$acr]        ; Save R11
  addq     4,    $acr
  move.d   $r12, [$acr]        ; Save R12
  addq     4,    $acr
  move.d   $r13, [$acr]        ; Save R13
  addq     4,    $acr
  move.d   $sp,  [$acr]        ; Save SP (R14)
  addq     4,    $acr

  ;; The ACR register is already saved on the stack, so pop it from there.
  move.d   [$sp],$r0
  move.d   $r0,  [$acr]
  addq     4,    $acr

  move     $bz,  [$acr]
  addq     1,    $acr
  move     $vr,  [$acr]
  addq     1,    $acr
  move     $pid, [$acr]
  addq     4,    $acr
  move     $srs, [$acr]
  addq     1,    $acr
  move     $wz,  [$acr]
  addq     2,    $acr
  move     $exs, [$acr]
  addq     4,    $acr
  move     $eda, [$acr]
  addq     4,    $acr
  move     $mof, [$acr]
  addq     4,    $acr
  move     $dz,  [$acr]
  addq     4,    $acr
  move     $ebp, [$acr]
  addq     4,    $acr
  move     $erp, [$acr]
  addq     4,    $acr
  move     $srp, [$acr]
  addq     4,    $acr
  move     $nrp, [$acr]
  addq     4,    $acr
  move     $ccs, [$acr]
  addq     4,    $acr
  move     $usp, [$acr]
  addq     4,    $acr
  move     $spc, [$acr]
  addq     4,     $acr

;; Skip the pseudo-PC.
  addq     4,     $acr

;; Save the support registers in bank 0 - 3.
  clear.d $r1 ; Bank counter
  move.d  sreg, $acr

;; Bank 0
  move    $r1,  $srs
  nop
  nop
  nop
  move    $s0,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s1,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s2,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s3,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s4,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s5,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s6,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s7,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s8,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s9,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s10,  $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s11,  $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s12,  $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr

  ;; Nothing in S13 - S15, bank 0
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr

;; Bank 1 and bank 2 have the same layout, hence the loop.
  addq    1, $r1
1:
  move    $r1,  $srs
  nop
  nop
  nop
  move    $s0,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s1,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s2,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s3,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s4,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s5,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s6,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr

  ;; Nothing in S7 - S15, bank 1 and 2
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr
  clear.d [$acr]
  addq    4,     $acr

  addq 1, $r1
  cmpq 3, $r1
  bne 1b
  nop

;; Bank 3
  move    $r1,  $srs
  nop
  nop
  nop
  move    $s0,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s1,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s2,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s3,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s4,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s5,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s6,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s7,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s8,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s9,   $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s10,  $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s11,  $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s12,  $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s13,  $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
  move    $s14,  $r0
  move.d  $r0,   [$acr]
  addq    4,     $acr
;; Nothing in S15, bank 3
  clear.d [$acr]
  addq    4,     $acr

;; Check what got us here: get IDX field of EXS.
  move $exs,    $r10
  and.d 0xff00, $r10
  lsrq 8,       $r10
#if defined(CONFIG_ETRAX_KGDB_PORT0)
  cmp.d SER0_INTR_VECT,   $r10 ; IRQ for serial port 0
  beq sigint
  nop
#elif defined(CONFIG_ETRAX_KGDB_PORT1)
  cmp.d SER1_INTR_VECT,   $r10 ; IRQ for serial port 1
  beq sigint
  nop
#elif defined(CONFIG_ETRAX_KGDB_PORT2)
  cmp.d SER2_INTR_VECT,   $r10 ; IRQ for serial port 2
  beq sigint
  nop
#elif defined(CONFIG_ETRAX_KGDB_PORT3)
  cmp.d SER3_INTR_VECT,   $r10 ; IRQ for serial port 3
  beq sigint
  nop
#endif
;; Multiple interrupt must be due to serial break.
  cmp.d 0x30,   $r10 ; Multiple interrupt
  beq sigint
  nop
;; Neither of those? Then it's a sigtrap.
  ba handle_comm
  moveq 5, $r10      ; Set SIGTRAP (delay slot)

sigint:
  ;; Serial interrupt; get character
  jsr getDebugChar
  nop                ; Delay slot
  cmp.b 3, $r10      ; \003 (Ctrl-C)?
  bne return         ; No, get out of here
  nop
  moveq 2, $r10      ; Set SIGINT

;;
;; Handle the communication
;;
handle_comm:
  move.d   internal_stack+1020, $sp ; Use the internal stack which grows upwards
  jsr      handle_exception         ; Interactive routine
  nop

;;
;; Return to the caller
;;
return:

;; First of all, write the support registers.
  clear.d $r1 ; Bank counter
  move.d  sreg, $acr

;; Bank 0
  move    $r1,  $srs
  nop
  nop
  nop
  move.d  [$acr], $r0
  move    $r0,    $s0
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s1
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s2
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s3
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s4
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s5
  addq    4,      $acr

;; Nothing in S6 - S7, bank 0.
  addq    4,      $acr
  addq    4,      $acr

  move.d  [$acr], $r0
  move    $r0,    $s8
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s9
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s10
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s11
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s12
  addq    4,      $acr

;; Nothing in S13 - S15, bank 0
  addq    4,      $acr
  addq    4,      $acr
  addq    4,      $acr

;; Bank 1 and bank 2 have the same layout, hence the loop.
  addq    1, $r1
2:
  move    $r1,  $srs
  nop
  nop
  nop
  move.d  [$acr], $r0
  move    $r0,    $s0
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s1
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s2
  addq    4,      $acr

;; S3 (MM_CAUSE) is read-only.
  addq    4,      $acr

  move.d  [$acr], $r0
  move    $r0,    $s4
  addq    4,      $acr

;; FIXME: Actually write S5/S6? (Affects MM_CAUSE.)
  addq    4,      $acr
  addq    4,      $acr

;; Nothing in S7 - S15, bank 1 and 2
  addq    4,      $acr
  addq    4,      $acr
  addq    4,      $acr
  addq    4,      $acr
  addq    4,      $acr
  addq    4,      $acr
  addq    4,      $acr
  addq    4,      $acr
  addq    4,      $acr

  addq 1, $r1
  cmpq 3, $r1
  bne 2b
  nop

;; Bank 3
  move    $r1,  $srs
  nop
  nop
  nop
  move.d  [$acr], $r0
  move    $r0,    $s0
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s1
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s2
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s3
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s4
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s5
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s6
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s7
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s8
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s9
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s10
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s11
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s12
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s13
  addq    4,      $acr
  move.d  [$acr], $r0
  move    $r0,    $s14
  addq    4,      $acr

;; Nothing in S15, bank 3
  addq    4,      $acr

;; Now, move on to the regular register restoration process.

   move.d  reg,    $acr   ; Reset ACR to point at the beginning of the register image
   move.d  [$acr], $r0    ; Restore R0
   addq    4,      $acr
   move.d  [$acr], $r1    ; Restore R1
   addq    4,      $acr
   move.d  [$acr], $r2    ; Restore R2
   addq    4,      $acr
   move.d  [$acr], $r3    ; Restore R3
   addq    4,      $acr
   move.d  [$acr], $r4    ; Restore R4
   addq    4,      $acr
   move.d  [$acr], $r5    ; Restore R5
   addq    4,      $acr
   move.d  [$acr], $r6    ; Restore R6
   addq    4,      $acr
   move.d  [$acr], $r7    ; Restore R7
   addq    4,      $acr
   move.d  [$acr], $r8    ; Restore R8
   addq    4,      $acr
   move.d  [$acr], $r9    ; Restore R9
   addq    4,      $acr
   move.d  [$acr], $r10   ; Restore R10
   addq    4,      $acr
   move.d  [$acr], $r11   ; Restore R11
   addq    4,      $acr
   move.d  [$acr], $r12   ; Restore R12
   addq    4,      $acr
   move.d  [$acr], $r13   ; Restore R13

;;
;; We restore all registers, even though some of them probably haven't changed.
;;

   addq    4,      $acr
   move.d  [$acr], $sp    ; Restore SP (R14)

   ;; ACR cannot be restored just yet.
   addq    8,      $acr

   ;; Skip BZ, VR.
   addq    2,      $acr

   move    [$acr], $pid   ; Restore PID
   addq    4,      $acr
   move    [$acr], $srs   ; Restore SRS
   nop
   nop
   nop
   addq    1,      $acr

   ;; Skip WZ.
   addq    2,      $acr

   move    [$acr], $exs    ; Restore EXS.
   addq    4,      $acr
   move    [$acr], $eda    ; Restore EDA.
   addq    4,      $acr
   move    [$acr], $mof    ; Restore MOF.

   ;; Skip DZ.
   addq    8,      $acr

   move    [$acr], $ebp    ; Restore EBP.
   addq    4,      $acr
   move    [$acr], $erp    ; Restore ERP.
   addq    4,      $acr
   move    [$acr], $srp    ; Restore SRP.
   addq    4,      $acr
   move    [$acr], $nrp    ; Restore NRP.
   addq    4,      $acr
   move    [$acr], $ccs    ; Restore CCS like an ordinary register.
   addq    4,      $acr
   move    [$acr], $usp    ; Restore USP
   addq    4,      $acr
   move    [$acr], $spc    ; Restore SPC
                           ; No restoration of pseudo-PC of course.

   move.d  reg,    $acr    ; Reset ACR to point at the beginning of the register image
   add.d   15*4,   $acr
   move.d  [$acr], $acr    ; Finally, restore ACR.
   rete                    ; Same as jump ERP
   rfe                     ; Shifts CCS