genex.S 11.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle
 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8
 * Copyright (C) 2002, 2007  Maciej W. Rozycki
9
 * Copyright (C) 2001, 2012 MIPS Technologies, Inc.  All rights reserved.
L
Linus Torvalds 已提交
10 11 12 13
 */
#include <linux/init.h>

#include <asm/asm.h>
14
#include <asm/asmmacro.h>
L
Linus Torvalds 已提交
15
#include <asm/cacheops.h>
16
#include <asm/irqflags.h>
L
Linus Torvalds 已提交
17 18 19 20 21
#include <asm/regdef.h>
#include <asm/fpregdef.h>
#include <asm/mipsregs.h>
#include <asm/stackframe.h>
#include <asm/war.h>
22
#include <asm/thread_info.h>
L
Linus Torvalds 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

	__INIT

/*
 * General exception vector for all other CPUs.
 *
 * Be careful when changing this, it has to be at most 128 bytes
 * to fit into space reserved for the exception handler.
 */
NESTED(except_vec3_generic, 0, sp)
	.set	push
	.set	noat
#if R5432_CP0_INTERRUPT_WAR
	mfc0	k0, CP0_INDEX
#endif
	mfc0	k1, CP0_CAUSE
	andi	k1, k1, 0x7c
40
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
	dsll	k1, k1, 1
#endif
	PTR_L	k0, exception_handlers(k1)
	jr	k0
	.set	pop
	END(except_vec3_generic)

/*
 * General exception handler for CPUs with virtual coherency exception.
 *
 * Be careful when changing this, it has to be at most 256 (as a special
 * exception) bytes to fit into space reserved for the exception handler.
 */
NESTED(except_vec3_r4000, 0, sp)
	.set	push
56
	.set	arch=r4000
L
Linus Torvalds 已提交
57 58 59 60 61 62 63 64 65 66
	.set	noat
	mfc0	k1, CP0_CAUSE
	li	k0, 31<<2
	andi	k1, k1, 0x7c
	.set	push
	.set	noreorder
	.set	nomacro
	beq	k1, k0, handle_vced
	 li	k0, 14<<2
	beq	k1, k0, handle_vcei
67
#ifdef CONFIG_64BIT
T
Thiemo Seufer 已提交
68
	 dsll	k1, k1, 1
L
Linus Torvalds 已提交
69 70 71 72 73 74 75
#endif
	.set	pop
	PTR_L	k0, exception_handlers(k1)
	jr	k0

	/*
	 * Big shit, we now may have two dirty primary cache lines for the same
T
Thiemo Seufer 已提交
76
	 * physical address.  We can safely invalidate the line pointed to by
L
Linus Torvalds 已提交
77 78 79 80
	 * c0_badvaddr because after return from this exception handler the
	 * load / store will be re-executed.
	 */
handle_vced:
T
Thiemo Seufer 已提交
81
	MFC0	k0, CP0_BADVADDR
L
Linus Torvalds 已提交
82 83 84
	li	k1, -4					# Is this ...
	and	k0, k1					# ... really needed?
	mtc0	zero, CP0_TAGLO
T
Thiemo Seufer 已提交
85 86
	cache	Index_Store_Tag_D, (k0)
	cache	Hit_Writeback_Inv_SD, (k0)
L
Linus Torvalds 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
#ifdef CONFIG_PROC_FS
	PTR_LA	k0, vced_count
	lw	k1, (k0)
	addiu	k1, 1
	sw	k1, (k0)
#endif
	eret

handle_vcei:
	MFC0	k0, CP0_BADVADDR
	cache	Hit_Writeback_Inv_SD, (k0)		# also cleans pi
#ifdef CONFIG_PROC_FS
	PTR_LA	k0, vcei_count
	lw	k1, (k0)
	addiu	k1, 1
	sw	k1, (k0)
#endif
	eret
	.set	pop
	END(except_vec3_r4000)

108 109
	__FINIT

110
	.align	5	/* 32 byte rollback region */
111
LEAF(__r4k_wait)
112 113 114 115 116 117 118 119 120 121
	.set	push
	.set	noreorder
	/* start of rollback region */
	LONG_L	t0, TI_FLAGS($28)
	nop
	andi	t0, _TIF_NEED_RESCHED
	bnez	t0, 1f
	 nop
	nop
	nop
122 123 124 125 126 127
#ifdef CONFIG_CPU_MICROMIPS
	nop
	nop
	nop
	nop
#endif
128
	.set	MIPS_ISA_ARCH_LEVEL_RAW
129 130 131 132
	wait
	/* end of rollback region (the region size must be power of two) */
1:
	jr	ra
133 134
	nop
	.set	pop
135
	END(__r4k_wait)
136 137 138 139 140 141

	.macro	BUILD_ROLLBACK_PROLOGUE handler
	FEXPORT(rollback_\handler)
	.set	push
	.set	noat
	MFC0	k0, CP0_EPC
142
	PTR_LA	k1, __r4k_wait
143 144 145 146 147 148 149 150
	ori	k0, 0x1f	/* 32 byte rollback region */
	xori	k0, 0x1f
	bne	k0, k1, 9f
	MTC0	k0, CP0_EPC
9:
	.set pop
	.endm

R
Ralf Baechle 已提交
151
	.align	5
152
BUILD_ROLLBACK_PROLOGUE handle_int
153
NESTED(handle_int, PT_SIZE, sp)
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
#ifdef CONFIG_TRACE_IRQFLAGS
	/*
	 * Check to see if the interrupted code has just disabled
	 * interrupts and ignore this interrupt for now if so.
	 *
	 * local_irq_disable() disables interrupts and then calls
	 * trace_hardirqs_off() to track the state. If an interrupt is taken
	 * after interrupts are disabled but before the state is updated
	 * it will appear to restore_all that it is incorrectly returning with
	 * interrupts disabled
	 */
	.set	push
	.set	noat
	mfc0	k0, CP0_STATUS
#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
	and	k0, ST0_IEP
	bnez	k0, 1f

172
	mfc0	k0, CP0_EPC
173 174 175 176 177 178 179 180 181 182 183 184
	.set	noreorder
	j	k0
	rfe
#else
	and	k0, ST0_IE
	bnez	k0, 1f

	eret
#endif
1:
	.set pop
#endif
185 186
	SAVE_ALL
	CLI
187
	TRACE_IRQS_OFF
188

189 190
	LONG_L	s0, TI_REGS($28)
	LONG_S	sp, TI_REGS($28)
A
Atsushi Nemoto 已提交
191
	PTR_LA	ra, ret_from_irq
192 193 194 195 196
	PTR_LA  v0, plat_irq_dispatch
	jr	v0
#ifdef CONFIG_CPU_MICROMIPS
	nop
#endif
197 198 199 200
	END(handle_int)

	__INIT

L
Linus Torvalds 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
/*
 * Special interrupt vector for MIPS64 ISA & embedded MIPS processors.
 * This is a dedicated interrupt exception vector which reduces the
 * interrupt processing overhead.  The jump instruction will be replaced
 * at the initialization time.
 *
 * Be careful when changing this, it has to be at most 128 bytes
 * to fit into space reserved for the exception handler.
 */
NESTED(except_vec4, 0, sp)
1:	j	1b			/* Dummy, will be replaced */
	END(except_vec4)

/*
 * EJTAG debug exception handler.
 * The EJTAG debug exception entry point is 0xbfc00480, which
217
 * normally is in the boot PROM, so the boot PROM must do an
L
Linus Torvalds 已提交
218 219 220 221
 * unconditional jump to this vector.
 */
NESTED(except_vec_ejtag_debug, 0, sp)
	j	ejtag_debug_handler
222 223 224
#ifdef CONFIG_CPU_MICROMIPS
	 nop
#endif
L
Linus Torvalds 已提交
225 226 227 228
	END(except_vec_ejtag_debug)

	__FINIT

229 230 231 232 233
/*
 * Vectored interrupt handler.
 * This prototype is copied to ebase + n*IntCtl.VS and patched
 * to invoke the handler
 */
234
BUILD_ROLLBACK_PROLOGUE except_vec_vi
235 236 237 238 239
NESTED(except_vec_vi, 0, sp)
	SAVE_SOME
	SAVE_AT
	.set	push
	.set	noreorder
240
	PTR_LA	v1, except_vec_vi_handler
241
FEXPORT(except_vec_vi_lui)
242
	lui	v0, 0		/* Patched */
243
	jr	v1
244
FEXPORT(except_vec_vi_ori)
245 246 247 248 249 250 251 252 253 254 255 256 257
	 ori	v0, 0		/* Patched */
	.set	pop
	END(except_vec_vi)
EXPORT(except_vec_vi_end)

/*
 * Common Vectored Interrupt code
 * Complete the register saves and invoke the handler which is passed in $v0
 */
NESTED(except_vec_vi_handler, 0, sp)
	SAVE_TEMP
	SAVE_STATIC
	CLI
258 259
#ifdef CONFIG_TRACE_IRQFLAGS
	move	s0, v0
260
	TRACE_IRQS_OFF
261 262
	move	v0, s0
#endif
263 264 265

	LONG_L	s0, TI_REGS($28)
	LONG_S	sp, TI_REGS($28)
266
	PTR_LA	ra, ret_from_irq
A
Atsushi Nemoto 已提交
267
	jr	v0
268 269
	END(except_vec_vi_handler)

L
Linus Torvalds 已提交
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
/*
 * EJTAG debug exception handler.
 */
NESTED(ejtag_debug_handler, PT_SIZE, sp)
	.set	push
	.set	noat
	MTC0	k0, CP0_DESAVE
	mfc0	k0, CP0_DEBUG

	sll	k0, k0, 30	# Check for SDBBP.
	bgez	k0, ejtag_return

	PTR_LA	k0, ejtag_debug_buffer
	LONG_S	k1, 0(k0)
	SAVE_ALL
	move	a0, sp
	jal	ejtag_exception_handler
	RESTORE_ALL
	PTR_LA	k0, ejtag_debug_buffer
	LONG_L	k1, 0(k0)

ejtag_return:
	MFC0	k0, CP0_DESAVE
	.set	mips32
	deret
	.set pop
	END(ejtag_debug_handler)

/*
 * This buffer is reserved for the use of the EJTAG debug
 * handler.
 */
	.data
EXPORT(ejtag_debug_buffer)
	.fill	LONGSIZE
	.previous

	__INIT

/*
 * NMI debug exception handler for MIPS reference boards.
 * The NMI debug exception entry point is 0xbfc00000, which
 * normally is in the boot PROM, so the boot PROM must do a
 * unconditional jump to this vector.
 */
NESTED(except_vec_nmi, 0, sp)
	j	nmi_handler
317 318 319
#ifdef CONFIG_CPU_MICROMIPS
	 nop
#endif
L
Linus Torvalds 已提交
320 321 322 323 324 325 326
	END(except_vec_nmi)

	__FINIT

NESTED(nmi_handler, PT_SIZE, sp)
	.set	push
	.set	noat
327 328 329 330 331 332 333 334 335 336
	/*
	 * Clear ERL - restore segment mapping
	 * Clear BEV - required for page fault exception handler to work
	 */
	mfc0	k0, CP0_STATUS
	ori     k0, k0, ST0_EXL
	li	k1, ~(ST0_BEV | ST0_ERL)
	and     k0, k0, k1
	mtc0    k0, CP0_STATUS
	_ehb
L
Linus Torvalds 已提交
337
	SAVE_ALL
R
Ralf Baechle 已提交
338
	move	a0, sp
L
Linus Torvalds 已提交
339
	jal	nmi_exception_handler
340
	/* nmi_exception_handler never returns */
L
Linus Torvalds 已提交
341 342 343 344 345 346 347
	.set	pop
	END(nmi_handler)

	.macro	__build_clear_none
	.endm

	.macro	__build_clear_sti
348
	TRACE_IRQS_ON
L
Linus Torvalds 已提交
349 350 351 352 353
	STI
	.endm

	.macro	__build_clear_cli
	CLI
354
	TRACE_IRQS_OFF
L
Linus Torvalds 已提交
355 356 357
	.endm

	.macro	__build_clear_fpe
358 359 360
	.set	push
	/* gas fails to assemble cfc1 for some archs (octeon).*/ \
	.set	mips1
361
	SET_HARDFLOAT
L
Linus Torvalds 已提交
362 363 364 365
	cfc1	a1, fcr31
	li	a2, ~(0x3f << 12)
	and	a2, a1
	ctc1	a2, fcr31
366
	.set	pop
367
	TRACE_IRQS_ON
L
Linus Torvalds 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
	STI
	.endm

	.macro	__build_clear_ade
	MFC0	t0, CP0_BADVADDR
	PTR_S	t0, PT_BVADDR(sp)
	KMODE
	.endm

	.macro	__BUILD_silent exception
	.endm

	/* Gas tries to parse the PRINT argument as a string containing
	   string escapes and emits bogus warnings if it believes to
	   recognize an unknown escape code.  So make the arguments
	   start with an n and gas will believe \n is ok ...  */
R
Ralf Baechle 已提交
384
	.macro	__BUILD_verbose nexception
L
Linus Torvalds 已提交
385
	LONG_L	a1, PT_EPC(sp)
Y
Yoichi Yuasa 已提交
386
#ifdef CONFIG_32BIT
L
Linus Torvalds 已提交
387
	PRINT("Got \nexception at %08lx\012")
388
#endif
Y
Yoichi Yuasa 已提交
389
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
390
	PRINT("Got \nexception at %016lx\012")
391
#endif
L
Linus Torvalds 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
	.endm

	.macro	__BUILD_count exception
	LONG_L	t0,exception_count_\exception
	LONG_ADDIU t0, 1
	LONG_S	t0,exception_count_\exception
	.comm	exception_count\exception, 8, 8
	.endm

	.macro	__BUILD_HANDLER exception handler clear verbose ext
	.align	5
	NESTED(handle_\exception, PT_SIZE, sp)
	.set	noat
	SAVE_ALL
	FEXPORT(handle_\exception\ext)
	__BUILD_clear_\clear
	.set	at
	__BUILD_\verbose \exception
	move	a0, sp
411 412
	PTR_LA	ra, ret_from_exception
	j	do_\handler
L
Linus Torvalds 已提交
413 414 415 416
	END(handle_\exception)
	.endm

	.macro	BUILD_HANDLER exception handler clear verbose
R
Ralf Baechle 已提交
417
	__BUILD_HANDLER \exception \handler \clear \verbose _int
L
Linus Torvalds 已提交
418 419 420 421 422 423 424 425 426 427 428
	.endm

	BUILD_HANDLER adel ade ade silent		/* #4  */
	BUILD_HANDLER ades ade ade silent		/* #5  */
	BUILD_HANDLER ibe be cli silent			/* #6  */
	BUILD_HANDLER dbe be cli silent			/* #7  */
	BUILD_HANDLER bp bp sti silent			/* #9  */
	BUILD_HANDLER ri ri sti silent			/* #10 */
	BUILD_HANDLER cpu cpu sti silent		/* #11 */
	BUILD_HANDLER ov ov sti silent			/* #12 */
	BUILD_HANDLER tr tr sti silent			/* #13 */
429
	BUILD_HANDLER msa_fpe msa_fpe sti silent	/* #14 */
L
Linus Torvalds 已提交
430
	BUILD_HANDLER fpe fpe fpe silent		/* #15 */
L
Leonid Yegoshin 已提交
431
	BUILD_HANDLER ftlb ftlb none silent		/* #16 */
432
	BUILD_HANDLER msa msa sti silent		/* #21 */
L
Linus Torvalds 已提交
433
	BUILD_HANDLER mdmx mdmx sti silent		/* #22 */
R
Ralf Baechle 已提交
434
#ifdef	CONFIG_HARDWARE_WATCHPOINTS
435 436 437 438 439
	/*
	 * For watch, interrupts will be enabled after the watch
	 * registers are read.
	 */
	BUILD_HANDLER watch watch cli silent		/* #23 */
440
#else
L
Linus Torvalds 已提交
441
	BUILD_HANDLER watch watch sti verbose		/* #23 */
442
#endif
L
Linus Torvalds 已提交
443
	BUILD_HANDLER mcheck mcheck cli verbose		/* #24 */
444
	BUILD_HANDLER mt mt sti silent			/* #25 */
445
	BUILD_HANDLER dsp dsp sti silent		/* #26 */
L
Linus Torvalds 已提交
446 447
	BUILD_HANDLER reserved reserved sti verbose	/* others */

448 449 450 451 452 453 454
	.align	5
	LEAF(handle_ri_rdhwr_vivt)
	.set	push
	.set	noat
	.set	noreorder
	/* check if TLB contains a entry for EPC */
	MFC0	k1, CP0_ENTRYHI
455
	andi	k1, 0xff	/* ASID_MASK */
456
	MFC0	k0, CP0_EPC
R
Ralf Baechle 已提交
457 458
	PTR_SRL k0, _PAGE_SHIFT + 1
	PTR_SLL k0, _PAGE_SHIFT + 1
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
	or	k1, k0
	MTC0	k1, CP0_ENTRYHI
	mtc0_tlbw_hazard
	tlbp
	tlb_probe_hazard
	mfc0	k1, CP0_INDEX
	.set	pop
	bltz	k1, handle_ri	/* slow path */
	/* fall thru */
	END(handle_ri_rdhwr_vivt)

	LEAF(handle_ri_rdhwr)
	.set	push
	.set	noat
	.set	noreorder
474 475
	/* MIPS32:    0x7c03e83b: rdhwr v1,$29 */
	/* microMIPS: 0x007d6b3c: rdhwr v1,$29 */
476
	MFC0	k1, CP0_EPC
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
#if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_MIPS32_R2) || defined(CONFIG_CPU_MIPS64_R2)
	and     k0, k1, 1
	beqz    k0, 1f
	xor     k1, k0
	lhu     k0, (k1)
	lhu     k1, 2(k1)
	ins     k1, k0, 16, 16
	lui     k0, 0x007d
	b       docheck
	ori     k0, 0x6b3c
1:
	lui     k0, 0x7c03
	lw      k1, (k1)
	ori     k0, 0xe83b
#else
	andi    k0, k1, 1
	bnez    k0, handle_ri
	lui     k0, 0x7c03
	lw      k1, (k1)
	ori     k0, 0xe83b
#endif
	.set    reorder
docheck:
500
	bne	k0, k1, handle_ri	/* if not ours */
501 502

isrdhwr:
503 504 505 506 507 508 509 510 511 512 513 514
	/* The insn is rdhwr.  No need to check CAUSE.BD here. */
	get_saved_sp	/* k1 := current_thread_info */
	.set	noreorder
	MFC0	k0, CP0_EPC
#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
	ori	k1, _THREAD_MASK
	xori	k1, _THREAD_MASK
	LONG_L	v1, TI_TP_VALUE(k1)
	LONG_ADDIU	k0, 4
	jr	k0
	 rfe
#else
515
#ifndef CONFIG_CPU_DADDI_WORKAROUNDS
516
	LONG_ADDIU	k0, 4		/* stall on $k0 */
517 518 519 520 521
#else
	.set	at=v1
	LONG_ADDIU	k0, 4
	.set	noat
#endif
522 523 524 525 526
	MTC0	k0, CP0_EPC
	/* I hope three instructions between MTC0 and ERET are enough... */
	ori	k1, _THREAD_MASK
	xori	k1, _THREAD_MASK
	LONG_L	v1, TI_TP_VALUE(k1)
527
	.set	arch=r4000
528 529 530 531 532 533
	eret
	.set	mips0
#endif
	.set	pop
	END(handle_ri_rdhwr)

534
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
535 536 537 538 539 540
/* A temporary overflow handler used by check_daddi(). */

	__INIT

	BUILD_HANDLER  daddi_ov daddi_ov none silent	/* #12 */
#endif