| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2015-02-21 15:09:32 +05:30
										 |  |  |  * Common Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC | 
					
						
							|  |  |  |  * (included from entry-<isa>.S | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-02-21 15:09:32 +05:30
										 |  |  |  * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  |  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify
 | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License version 2 as | 
					
						
							|  |  |  |  * published by the Free Software Foundation. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*------------------------------------------------------------------ | 
					
						
							|  |  |  |  *    Function                            ABI | 
					
						
							|  |  |  |  *------------------------------------------------------------------ | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Arguments                           r0 - r7 | 
					
						
							|  |  |  |  *  Caller Saved Registers              r0 - r12 | 
					
						
							|  |  |  |  *  Callee Saved Registers              r13- r25 | 
					
						
							|  |  |  |  *  Global Pointer (gp)                 r26 | 
					
						
							|  |  |  |  *  Frame Pointer (fp)                  r27 | 
					
						
							|  |  |  |  *  Stack Pointer (sp)                  r28 | 
					
						
							|  |  |  |  *  Branch link register (blink)        r31 | 
					
						
							|  |  |  |  *------------------------------------------------------------------ | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-10 19:13:07 +05:30
										 |  |  | ;################### Special Sys Call Wrappers ##########################
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ENTRY(sys_clone_wrapper) | 
					
						
							|  |  |  | 	SAVE_CALLEE_SAVED_USER | 
					
						
							|  |  |  | 	bl  @sys_clone
 | 
					
						
							|  |  |  | 	DISCARD_CALLEE_SAVED_USER | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	GET_CURR_THR_INFO_FLAGS   r10 | 
					
						
							|  |  |  | 	btst r10, TIF_SYSCALL_TRACE | 
					
						
							|  |  |  | 	bnz  tracesys_exit | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	b ret_from_system_call | 
					
						
							|  |  |  | END(sys_clone_wrapper) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ENTRY(ret_from_fork) | 
					
						
							|  |  |  | 	; when the forked child comes here from the __switch_to function
 | 
					
						
							|  |  |  | 	; r0 has the last task pointer.
 | 
					
						
							|  |  |  | 	; put last task in scheduler queue
 | 
					
						
							|  |  |  | 	bl   @schedule_tail
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ld   r9, [sp, PT_status32] | 
					
						
							|  |  |  | 	brne r9, 0, 1f | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	jl.d [r14]		; kernel thread entry point
 | 
					
						
							|  |  |  | 	mov  r0, r13		; (see PF_KTHREAD block in copy_thread)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 1: | 
					
						
							|  |  |  | 	; Return to user space
 | 
					
						
							|  |  |  | 	; 1. Any forked task (Reach here via BRne above)
 | 
					
						
							|  |  |  | 	; 2. First ever init task (Reach here via return from JL above)
 | 
					
						
							|  |  |  | 	;    This is the historic "kernel_execve" use-case, to return to init
 | 
					
						
							|  |  |  | 	;    user mode, in a round about way since that is always done from
 | 
					
						
							|  |  |  | 	;    a kernel thread which is executed via JL above but always returns
 | 
					
						
							|  |  |  | 	;    out whenever kernel_execve (now inline do_fork()) is involved
 | 
					
						
							|  |  |  | 	b    ret_from_exception | 
					
						
							|  |  |  | END(ret_from_fork) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_ARC_DW2_UNWIND | 
					
						
							|  |  |  | ; Workaround for bug 94179 (STAR ):
 | 
					
						
							|  |  |  | ; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
 | 
					
						
							|  |  |  | ; section (.debug_frame) as loadable. So we force it here.
 | 
					
						
							|  |  |  | ; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
 | 
					
						
							|  |  |  | ; would not work after a clean build due to kernel build system dependencies.
 | 
					
						
							|  |  |  | .section .debug_frame, "wa",@progbits
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ; Reset to .text as this file is included in entry-<isa>.S
 | 
					
						
							|  |  |  | .section .text, "ax",@progbits
 | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | ;################### Non TLB Exception Handling #############################
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | ; Instruction Error Exception Handler
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | ENTRY(instr_service) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 	EXCEPTION_PROLOGUE | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-12 15:13:40 +05:30
										 |  |  | 	lr  r0, [efa] | 
					
						
							|  |  |  | 	mov r1, sp | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:43:08 +05:30
										 |  |  | 	FAKE_RET_FROM_EXCPN | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	bl  do_insterror_or_kprobe | 
					
						
							|  |  |  | 	b   ret_from_exception | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | END(instr_service) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | ; Memory Error Exception Handler
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | ENTRY(mem_service) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 	EXCEPTION_PROLOGUE | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-12 15:13:40 +05:30
										 |  |  | 	lr  r0, [efa] | 
					
						
							|  |  |  | 	mov r1, sp | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:43:08 +05:30
										 |  |  | 	FAKE_RET_FROM_EXCPN | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	bl  do_memory_error | 
					
						
							|  |  |  | 	b   ret_from_exception | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | END(mem_service) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | ; Machine Check Exception Handler
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | ENTRY(EV_MachineCheck) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 	EXCEPTION_PROLOGUE | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-12 15:13:40 +05:30
										 |  |  | 	lr  r2, [ecr] | 
					
						
							|  |  |  | 	lr  r0, [efa] | 
					
						
							|  |  |  | 	mov r1, sp | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-12 15:13:40 +05:30
										 |  |  | 	lsr  	r3, r2, 8 | 
					
						
							| 
									
										
										
										
											2013-05-28 15:24:30 +05:30
										 |  |  | 	bmsk 	r3, r3, 7 | 
					
						
							|  |  |  | 	brne    r3, ECR_C_MCHK_DUP_TLB, 1f | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	bl      do_tlb_overlap_fault | 
					
						
							|  |  |  | 	b       ret_from_exception | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 1: | 
					
						
							|  |  |  | 	; DEAD END: can't do much, display Regs and HALT
 | 
					
						
							|  |  |  | 	SAVE_CALLEE_SAVED_USER | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10 | 
					
						
							|  |  |  | 	st  sp, [r10, THREAD_CALLEE_REG] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	j  do_machine_check_fault | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | END(EV_MachineCheck) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | ; Privilege Violation Exception Handler
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | ENTRY(EV_PrivilegeV) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 	EXCEPTION_PROLOGUE | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-12 15:13:40 +05:30
										 |  |  | 	lr  r0, [efa] | 
					
						
							|  |  |  | 	mov r1, sp | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:43:08 +05:30
										 |  |  | 	FAKE_RET_FROM_EXCPN | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	bl  do_privilege_fault | 
					
						
							|  |  |  | 	b   ret_from_exception | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | END(EV_PrivilegeV) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | ; Extension Instruction Exception Handler
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | ENTRY(EV_Extension) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 	EXCEPTION_PROLOGUE | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-12 15:13:40 +05:30
										 |  |  | 	lr  r0, [efa] | 
					
						
							|  |  |  | 	mov r1, sp | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:43:08 +05:30
										 |  |  | 	FAKE_RET_FROM_EXCPN | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	bl  do_extension_fault | 
					
						
							|  |  |  | 	b   ret_from_exception | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | END(EV_Extension) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | ;################ Trap Handling (Syscall, Breakpoint) ##################
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:22 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | ; syscall Tracing
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:22 +05:30
										 |  |  | tracesys: | 
					
						
							|  |  |  | 	; save EFA in case tracer wants the PC of traced task
 | 
					
						
							|  |  |  | 	; using ERET won't work since next-PC has already committed
 | 
					
						
							|  |  |  | 	lr  r12, [efa] | 
					
						
							|  |  |  | 	GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r11 | 
					
						
							| 
									
										
										
										
											2013-03-20 16:53:14 +05:30
										 |  |  | 	st  r12, [r11, THREAD_FAULT_ADDR]	; thread.fault_address
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:22 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	; PRE Sys Call Ptrace hook
 | 
					
						
							|  |  |  | 	mov r0, sp			; pt_regs needed
 | 
					
						
							|  |  |  | 	bl  @syscall_trace_entry
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; Tracing code now returns the syscall num (orig or modif)
 | 
					
						
							|  |  |  | 	mov r8, r0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; Do the Sys Call as we normally would.
 | 
					
						
							|  |  |  | 	; Validate the Sys Call number
 | 
					
						
							|  |  |  | 	cmp     r8,  NR_syscalls | 
					
						
							|  |  |  | 	mov.hi  r0, -ENOSYS | 
					
						
							|  |  |  | 	bhi     tracesys_exit | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; Restore the sys-call args. Mere invocation of the hook abv could have
 | 
					
						
							|  |  |  | 	; clobbered them (since they are in scratch regs). The tracer could also
 | 
					
						
							|  |  |  | 	; have deliberately changed the syscall args: r0-r7
 | 
					
						
							|  |  |  | 	ld  r0, [sp, PT_r0] | 
					
						
							|  |  |  | 	ld  r1, [sp, PT_r1] | 
					
						
							|  |  |  | 	ld  r2, [sp, PT_r2] | 
					
						
							|  |  |  | 	ld  r3, [sp, PT_r3] | 
					
						
							|  |  |  | 	ld  r4, [sp, PT_r4] | 
					
						
							|  |  |  | 	ld  r5, [sp, PT_r5] | 
					
						
							|  |  |  | 	ld  r6, [sp, PT_r6] | 
					
						
							|  |  |  | 	ld  r7, [sp, PT_r7] | 
					
						
							|  |  |  | 	ld.as   r9, [sys_call_table, r8] | 
					
						
							|  |  |  | 	jl      [r9]        ; Entry into Sys Call Handler
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tracesys_exit: | 
					
						
							|  |  |  | 	st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	;POST Sys Call Ptrace Hook
 | 
					
						
							|  |  |  | 	bl  @syscall_trace_exit
 | 
					
						
							|  |  |  | 	b   ret_from_exception ; NOT ret_from_system_call at is saves r0 which
 | 
					
						
							|  |  |  | 	; we'd done before calling post hook above
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | ; Breakpoint TRAP
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | trap_with_param: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-11 20:01:24 +05:30
										 |  |  | 	; stop_pc info by gdb needs this info
 | 
					
						
							| 
									
										
										
										
											2013-06-12 15:13:40 +05:30
										 |  |  | 	lr  r0, [efa] | 
					
						
							|  |  |  | 	mov r1, sp | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-20 13:33:48 +01:00
										 |  |  | 	; Now that we have read EFA, it is safe to do "fake" rtie
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	;   and get out of CPU exception mode
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:43:08 +05:30
										 |  |  | 	FAKE_RET_FROM_EXCPN | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	; Save callee regs in case gdb wants to have a look
 | 
					
						
							|  |  |  | 	; SP will grow up by size of CALLEE Reg-File
 | 
					
						
							|  |  |  | 	; NOTE: clobbers r12
 | 
					
						
							|  |  |  | 	SAVE_CALLEE_SAVED_USER | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; save location of saved Callee Regs @ thread_struct->pc
 | 
					
						
							|  |  |  | 	GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10 | 
					
						
							|  |  |  | 	st  sp, [r10, THREAD_CALLEE_REG] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; Call the trap handler
 | 
					
						
							|  |  |  | 	bl  do_non_swi_trap | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; unwind stack to discard Callee saved Regs
 | 
					
						
							|  |  |  | 	DISCARD_CALLEE_SAVED_USER | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	b   ret_from_exception | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | ; ---------------------------------------------
 | 
					
						
							|  |  |  | ; syscall TRAP
 | 
					
						
							|  |  |  | ; ABI: (r0-r7) upto 8 args, (r8) syscall number
 | 
					
						
							|  |  |  | ; ---------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | ENTRY(EV_Trap) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 15:07:13 +05:30
										 |  |  | 	EXCEPTION_PROLOGUE | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | 	;============ TRAP 1   :breakpoints
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:50:23 +05:30
										 |  |  | 	; Check ECR for trap with arg (PROLOGUE ensures r9 has ECR)
 | 
					
						
							|  |  |  | 	bmsk.f 0, r9, 7 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	bnz    trap_with_param | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | 	;============ TRAP  (no param): syscall top level
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | 	; First return from Exception to pure K mode (Exception/IRQs renabled)
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:43:08 +05:30
										 |  |  | 	FAKE_RET_FROM_EXCPN | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | 	; If syscall tracing ongoing, invoke pre-post-hooks
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:22 +05:30
										 |  |  | 	GET_CURR_THR_INFO_FLAGS   r10 | 
					
						
							|  |  |  | 	btst r10, TIF_SYSCALL_TRACE | 
					
						
							|  |  |  | 	bnz tracesys  ; this never comes back
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:45:08 +05:30
										 |  |  | 	;============ Normal syscall case
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; syscall num shd not exceed the total system calls avail
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	cmp     r8,  NR_syscalls | 
					
						
							|  |  |  | 	mov.hi  r0, -ENOSYS | 
					
						
							|  |  |  | 	bhi     ret_from_system_call | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; Offset into the syscall_table and call handler
 | 
					
						
							|  |  |  | 	ld.as   r9,[sys_call_table, r8] | 
					
						
							|  |  |  | 	jl      [r9]        ; Entry into Sys Call Handler
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; fall through to ret_from_system_call
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | END(EV_Trap) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | ENTRY(ret_from_system_call) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; fall through yet again to ret_from_exception
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
 | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | ; If ret to user mode do we need to handle signals, schedule() et al.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 13:47:43 +05:30
										 |  |  | ENTRY(ret_from_exception) | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
 | 
					
						
							|  |  |  | 	ld  r8, [sp, PT_status32]   ; returning to User/Kernel Mode
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bbit0  r8, STATUS_U_BIT, resume_kernel_mode | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; Before returning to User mode check-for-and-complete any pending work
 | 
					
						
							|  |  |  | 	; such as rescheduling/signal-delivery etc.
 | 
					
						
							|  |  |  | resume_user_mode_begin: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; Disable IRQs to ensures that chk for pending work itself is atomic
 | 
					
						
							|  |  |  | 	; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
 | 
					
						
							|  |  |  | 	; interim IRQ).
 | 
					
						
							|  |  |  | 	IRQ_DISABLE	r10 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; Fast Path return to user mode if no pending work
 | 
					
						
							|  |  |  | 	GET_CURR_THR_INFO_FLAGS   r9 | 
					
						
							|  |  |  | 	and.f  0,  r9, _TIF_WORK_MASK | 
					
						
							| 
									
										
										
										
											2014-10-13 19:49:00 +05:30
										 |  |  | 	bz     .Lrestore_regs | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	; --- (Slow Path #1) task preemption ---
 | 
					
						
							|  |  |  | 	bbit0  r9, TIF_NEED_RESCHED, .Lchk_pend_signals | 
					
						
							|  |  |  | 	mov    blink, resume_user_mode_begin  ; tail-call to U mode ret chks
 | 
					
						
							|  |  |  | 	b      @schedule 	; BTST+Bnz causes relo error in link
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .Lchk_pend_signals: | 
					
						
							|  |  |  | 	IRQ_ENABLE	r10 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; --- (Slow Path #2) pending signal  ---
 | 
					
						
							|  |  |  | 	mov r0, sp	; pt_regs for arg to do_signal()/do_notify_resume()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-06 14:18:17 +05:30
										 |  |  | 	GET_CURR_THR_INFO_FLAGS   r9 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	bbit0  r9, TIF_SIGPENDING, .Lchk_notify_resume | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:19 +05:30
										 |  |  | 	; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
 | 
					
						
							|  |  |  | 	; in pt_reg since the "C" ABI (kernel code) will automatically
 | 
					
						
							|  |  |  | 	; save/restore callee-saved regs.
 | 
					
						
							|  |  |  | 	;
 | 
					
						
							|  |  |  | 	; However, here we need to explicitly save callee regs because
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	; (i)  If this signal causes coredump - full regfile needed
 | 
					
						
							|  |  |  | 	; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
 | 
					
						
							|  |  |  | 	;      tracer might call PEEKUSR(CALLEE reg)
 | 
					
						
							|  |  |  | 	;
 | 
					
						
							|  |  |  | 	; NOTE: SP will grow up by size of CALLEE Reg-File
 | 
					
						
							|  |  |  | 	SAVE_CALLEE_SAVED_USER		; clobbers r12
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; save location of saved Callee Regs @ thread_struct->callee
 | 
					
						
							|  |  |  | 	GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10 | 
					
						
							|  |  |  | 	st  sp, [r10, THREAD_CALLEE_REG] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bl  @do_signal
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:19 +05:30
										 |  |  | 	; Ideally we want to discard the Callee reg above, however if this was
 | 
					
						
							|  |  |  | 	; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
 | 
					
						
							|  |  |  | 	RESTORE_CALLEE_SAVED_USER | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	b      resume_user_mode_begin	; loop back to start of U mode ret
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; --- (Slow Path #3) notify_resume ---
 | 
					
						
							|  |  |  | .Lchk_notify_resume: | 
					
						
							|  |  |  | 	btst   r9, TIF_NOTIFY_RESUME | 
					
						
							|  |  |  | 	blnz   @do_notify_resume
 | 
					
						
							|  |  |  | 	b      resume_user_mode_begin	; unconditionally back to U mode ret chks
 | 
					
						
							|  |  |  | 					; for single exit point from this block
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | resume_kernel_mode: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 15:26:45 +05:30
										 |  |  | 	; Disable Interrupts from this point on
 | 
					
						
							|  |  |  | 	; CONFIG_PREEMPT: This is a must for preempt_schedule_irq()
 | 
					
						
							|  |  |  | 	; !CONFIG_PREEMPT: To ensure restore_regs is intr safe
 | 
					
						
							| 
									
										
										
										
											2013-07-09 17:06:40 +05:30
										 |  |  | 	IRQ_DISABLE	r9 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 15:26:45 +05:30
										 |  |  | #ifdef CONFIG_PREEMPT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 	; Can't preempt if preemption disabled
 | 
					
						
							|  |  |  | 	GET_CURR_THR_INFO_FROM_SP   r10 | 
					
						
							|  |  |  | 	ld  r8, [r10, THREAD_INFO_PREEMPT_COUNT] | 
					
						
							| 
									
										
										
										
											2014-10-13 19:49:00 +05:30
										 |  |  | 	brne  r8, 0, .Lrestore_regs | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	; check if this task's NEED_RESCHED flag set
 | 
					
						
							|  |  |  | 	ld  r9, [r10, THREAD_INFO_FLAGS] | 
					
						
							| 
									
										
										
										
											2014-10-13 19:49:00 +05:30
										 |  |  | 	bbit0  r9, TIF_NEED_RESCHED, .Lrestore_regs | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	; Invoke PREEMPTION
 | 
					
						
							|  |  |  | 	bl      preempt_schedule_irq | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	; preempt_schedule_irq() always returns with IRQ disabled
 | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:09:32 +05:30
										 |  |  | 	b	.Lrestore_regs | 
					
						
							| 
									
										
										
										
											2013-01-18 15:12:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-10 19:13:07 +05:30
										 |  |  | ##### DONT ADD CODE HERE - .Lrestore_regs actually follows in entry-<isa>.S | 
					
						
							| 
									
										
										
										
											2015-02-21 15:09:32 +05:30
										 |  |  | 
 |