12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565 |
- #include <linux/linkage.h>
- #include <linux/errno.h>
- #include <linux/unistd.h>
- #include <linux/init.h>
- #include <asm/ptrace.h>
- #include <asm/thread_info.h>
- #include <asm/irqflags.h>
- #include <asm/asm-offsets.h>
- #include <asm/types.h>
- #include <asm/traps.h>
- #include <asm/signal.h>
- #include <hv/hypervisor.h>
- #include <arch/abi.h>
- #include <arch/interrupts.h>
- #include <arch/spr_def.h>
- #define PTREGS_PTR(reg, ptreg) addli reg, sp, C_ABI_SAVE_AREA_SIZE + (ptreg)
- #define PTREGS_OFFSET_SYSCALL PTREGS_OFFSET_REG(TREG_SYSCALL_NR)
- #if CONFIG_KERNEL_PL == 1 || CONFIG_KERNEL_PL == 2
- # define IS_KERNEL_EX1(result, ex1) andi result, ex1, CONFIG_KERNEL_PL
- #else
- # error Recode IS_KERNEL_EX1 for CONFIG_KERNEL_PL
- #endif
- .macro push_reg reg, ptr=sp, delta=-8
- {
- st \ptr, \reg
- addli \ptr, \ptr, \delta
- }
- .endm
- .macro pop_reg reg, ptr=sp, delta=8
- {
- ld \reg, \ptr
- addli \ptr, \ptr, \delta
- }
- .endm
- .macro pop_reg_zero reg, zreg, ptr=sp, delta=8
- {
- move \zreg, zero
- ld \reg, \ptr
- addi \ptr, \ptr, \delta
- }
- .endm
- .macro push_extra_callee_saves reg
- PTREGS_PTR(\reg, PTREGS_OFFSET_REG(51))
- push_reg r51, \reg
- push_reg r50, \reg
- push_reg r49, \reg
- push_reg r48, \reg
- push_reg r47, \reg
- push_reg r46, \reg
- push_reg r45, \reg
- push_reg r44, \reg
- push_reg r43, \reg
- push_reg r42, \reg
- push_reg r41, \reg
- push_reg r40, \reg
- push_reg r39, \reg
- push_reg r38, \reg
- push_reg r37, \reg
- push_reg r36, \reg
- push_reg r35, \reg
- push_reg r34, \reg, PTREGS_OFFSET_BASE - PTREGS_OFFSET_REG(34)
- .endm
- .macro panic str
- .pushsection .rodata, "a"
- 1:
- .asciz "\str"
- .popsection
- {
- moveli r0, hw2_last(1b)
- }
- {
- shl16insli r0, r0, hw1(1b)
- }
- {
- shl16insli r0, r0, hw0(1b)
- jal panic
- }
- .endm
-
- .macro int_hand_unalign_fast vecnum, vecname
- .org (\vecnum << 8)
- intvec_\vecname:
-
- mtspr SPR_SYSTEM_SAVE_K_1, r3
- mfspr r3, SPR_EX_CONTEXT_K_1
-
- bnez r3, hand_unalign_slow_nonuser
- mfspr r3, SPR_SYSTEM_SAVE_K_0
-
- bfexts r3, r3, 0, CPU_SHIFT-1
- mm r3, zero, LOG2_THREAD_SIZE, 63
- addli r3, r3, THREAD_INFO_UNALIGN_JIT_TMP_OFFSET
-
- st_add r3, r0, 8
- st_add r3, r1, 8
- {
- st_add r3, r2, 8
- andi r2, sp, 7
- }
-
- mfspr r1, SPR_SYSTEM_SAVE_K_1
- st r3, r1
- {
-
- bnez r2, hand_unalign_slow_badsp
- }
-
- {
- ori sp, sp, 1
- mfspr r1, SPR_EX_CONTEXT_K_0
- }
-
- {
- addli r0, r3, THREAD_INFO_UNALIGN_JIT_BASE_OFFSET - \
- (THREAD_INFO_UNALIGN_JIT_TMP_OFFSET + (3 * 8))
- bfextu r2, r1, 3, (2 + PAGE_SHIFT - UNALIGN_JIT_SHIFT)
- }
-
- {
- ld r0, r0
- shli r2, r2, UNALIGN_JIT_SHIFT
- }
-
- {
- beqz r0, hand_unalign_slow
- add r2, r0, r2
- }
-
- ENTRY(__start_unalign_asm_code)
-
- ld_add r0, r2, 8
-
- {
- cmpeq r0, r0, r1
- ld r1, r1
- }
-
- beqz r0, hand_unalign_slow
-
- ld_add r0, r2, 8
-
- ENTRY(__end_unalign_asm_code)
-
- {
- cmpeq r0, r1, r0
- mtspr SPR_EX_CONTEXT_0_1, zero
- }
-
- beqz r0, hand_unalign_slow
-
- {
- mfspr r0, SPR_EX_CONTEXT_K_0
- andi sp, sp, ~1
- }
-
- {
- mtspr SPR_EX_CONTEXT_K_0, r2
- addi r0, r0, 8
- }
-
- {
- movei r1, PL_ICS_EX1(USER_PL, 1)
- mtspr SPR_EX_CONTEXT_0_0, r0
- }
- {
- mtspr SPR_EX_CONTEXT_K_1, r1
- addi r3, r3, -(3 * 8)
- }
-
- ld_add r0, r3, 8
- ld_add r1, r3, 8
- ld_add r2, r3, 8
- ld r3, r3
- iret
- ENDPROC(intvec_\vecname)
- .endm
- #ifdef __COLLECT_LINKER_FEEDBACK__
- .pushsection .text.intvec_feedback,"ax"
- intvec_feedback:
- .popsection
- #endif
-
- .macro __int_hand vecnum, vecname, c_routine,processing=handle_interrupt
- intvec_\vecname:
-
- mtspr SPR_SYSTEM_SAVE_K_1, r0
- mfspr r0, SPR_EX_CONTEXT_K_1
-
- {
- blbs sp, 2f
- IS_KERNEL_EX1(r0, r0)
- }
- .ifc \vecnum, INT_DOUBLE_FAULT
-
- beqz r0, 1f
- j _kernel_double_fault
- 1:
- .else
-
- {
- bnez r0, 0f
- move r0, sp
- }
- .endif
- .ifc \c_routine, do_page_fault
-
- mfspr r0, SPR_SYSTEM_SAVE_K_2
- {
- bltz r0, 0f
- move r0, sp
- }
- .endif
- 2:
-
- mfspr r0, SPR_SYSTEM_SAVE_K_0
- bfexts r0, r0, 0, CPU_SHIFT-1
- 0:
-
- #if STACK_TOP_DELTA != 64
- #error STACK_TOP_DELTA must be 64 for assumptions here and in task_pt_regs()
- #endif
- andi r0, r0, -64
-
- addli r0, r0, PTREGS_OFFSET_LR - (PTREGS_SIZE + KSTK_PTREGS_GAP)
- wh64 r0
- {
- st r0, lr
- addli r0, r0, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
- }
- {
- st r0, sp
- addli sp, r0, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_SP
- }
- wh64 sp
- {
- st sp, r52
- addli sp, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(52)
- }
- wh64 sp
- {
- st sp, r1
- addli sp, sp, PTREGS_OFFSET_REG(2) - PTREGS_OFFSET_REG(1)
- }
- {
- st sp, r2
- addli sp, sp, PTREGS_OFFSET_REG(3) - PTREGS_OFFSET_REG(2)
- }
- {
- st sp, r3
- addli sp, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_REG(3)
- }
- mfspr r0, SPR_EX_CONTEXT_K_0
- .ifc \processing,handle_syscall
-
- addi r0, r0, 8
- .endif
- {
- st sp, r0
- addli sp, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_PC
- }
- mfspr r0, SPR_EX_CONTEXT_K_1
- {
- st sp, r0
- addi sp, sp, PTREGS_OFFSET_FAULTNUM - PTREGS_OFFSET_EX1
-
- .ifc \processing,handle_syscall
- movei r0, \vecnum
- }
- {
- st sp, r0
- .else
- movei r1, \vecnum
- }
- {
- st sp, r1
- .endif
- addli sp, sp, PTREGS_OFFSET_REG(0) - PTREGS_OFFSET_FAULTNUM
- }
- mfspr r0, SPR_SYSTEM_SAVE_K_1
- {
- st sp, r0
- addi sp, sp, -PTREGS_OFFSET_REG(0) - 8
- }
- {
- st sp, zero
- addi sp, sp, -8
- }
- .ifc \processing,handle_syscall
- j handle_syscall
- .else
-
- .ifc \c_routine, do_page_fault
- mfspr r2, SPR_SYSTEM_SAVE_K_3
- mfspr r3, SPR_SYSTEM_SAVE_K_2
- .else
- .ifc \vecnum, INT_ILL_TRANS
- mfspr r2, ILL_VA_PC
- .else
- .ifc \vecnum, INT_DOUBLE_FAULT
- mfspr r2, SPR_SYSTEM_SAVE_K_2
- .else
- .ifc \c_routine, do_trap
- mfspr r2, GPV_REASON
- .else
- .ifc \c_routine, handle_perf_interrupt
- mfspr r2, PERF_COUNT_STS
- .else
- .ifc \c_routine, handle_perf_interrupt
- mfspr r2, AUX_PERF_COUNT_STS
- .endif
- .ifc \c_routine, do_nmi
- mfspr r2, SPR_SYSTEM_SAVE_K_2
- .else
- .endif
- .endif
- .endif
- .endif
- .endif
- .endif
-
- moveli r0, hw2_last(\c_routine)
- shl16insli r0, r0, hw1(\c_routine)
- {
- shl16insli r0, r0, hw0(\c_routine)
- j \processing
- }
- .endif
- ENDPROC(intvec_\vecname)
- #ifdef __COLLECT_LINKER_FEEDBACK__
- .pushsection .text.intvec_feedback,"ax"
- .org (\vecnum << 5)
- FEEDBACK_ENTER_EXPLICIT(intvec_\vecname, .intrpt, 1 << 8)
- jrp lr
- .popsection
- #endif
- .endm
-
- .macro finish_interrupt_save, function
-
- PTREGS_PTR(r52, PTREGS_OFFSET_ORIG_R0)
- {
- .ifc \function,handle_syscall
- st r52, r0
- .else
- st r52, zero
- .endif
- PTREGS_PTR(r52, PTREGS_OFFSET_TP)
- }
- st r52, tp
- {
- mfspr tp, CMPEXCH_VALUE
- PTREGS_PTR(r52, PTREGS_OFFSET_CMPEXCH)
- }
-
- {
- st r52, tp
- PTREGS_PTR(r52, PTREGS_OFFSET_REG(33))
- }
- wh64 r52
- push_reg r33, r52
- push_reg r32, r52
- push_reg r31, r52
- .ifc \function,handle_syscall
- push_reg r30, r52, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(30)
- push_reg TREG_SYSCALL_NR_NAME, r52, \
- PTREGS_OFFSET_REG(5) - PTREGS_OFFSET_SYSCALL
- .else
- push_reg r30, r52, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(30)
- wh64 r52
- push_reg r29, r52
- push_reg r28, r52
- push_reg r27, r52
- push_reg r26, r52
- push_reg r25, r52
- push_reg r24, r52
- push_reg r23, r52
- push_reg r22, r52
- wh64 r52
- push_reg r21, r52
- push_reg r20, r52
- push_reg r19, r52
- push_reg r18, r52
- push_reg r17, r52
- push_reg r16, r52
- push_reg r15, r52
- push_reg r14, r52
- wh64 r52
- push_reg r13, r52
- push_reg r12, r52
- push_reg r11, r52
- push_reg r10, r52
- push_reg r9, r52
- push_reg r8, r52
- push_reg r7, r52
- push_reg r6, r52
- .endif
- push_reg r5, r52
- st r52, r4
-
- mfspr r32, SPR_EX_CONTEXT_K_1
- {
- IS_KERNEL_EX1(r32, r32)
- PTREGS_PTR(r21, PTREGS_OFFSET_FLAGS)
- }
- beqzt r32, 1f
- IRQS_DISABLED(r32)
- #if PT_FLAGS_DISABLE_IRQ != 1
- # error Value of IRQS_DISABLED used to set PT_FLAGS_DISABLE_IRQ
- #endif
- 1:
- .ifnc \function,handle_syscall
-
- ori r32, r32, PT_FLAGS_CALLER_SAVES
- .endif
- st r21, r32
-
- .ifc \function,handle_nmi
- IRQ_DISABLE_ALL(r20)
- .else
- IRQ_DISABLE(r20, r21)
- .endif
- mtspr INTERRUPT_CRITICAL_SECTION, zero
-
- #ifdef CONFIG_SMP
- {
- mfspr r20, SPR_SYSTEM_SAVE_K_0
- moveli r21, hw2_last(__per_cpu_offset)
- }
- {
- shl16insli r21, r21, hw1(__per_cpu_offset)
- bfextu r20, r20, CPU_SHIFT, 63
- }
- shl16insli r21, r21, hw0(__per_cpu_offset)
- shl3add r20, r20, r21
- ld tp, r20
- #else
- move tp, zero
- #endif
- #ifdef __COLLECT_LINKER_FEEDBACK__
-
- .ifnc \function,handle_syscall
- shli r20, r1, 5
- .else
- moveli r20, INT_SWINT_1 << 5
- .endif
- moveli r21, hw2_last(intvec_feedback)
- shl16insli r21, r21, hw1(intvec_feedback)
- shl16insli r21, r21, hw0(intvec_feedback)
- add r20, r20, r21
- jalr r20
-
- FEEDBACK_ENTER(\function)
- #endif
-
- addi r52, sp, -64
- {
- wh64 r52
- addi r52, r52, -64
- }
- {
- wh64 r52
- addi r52, r52, -64
- }
- {
- wh64 r52
- addi r52, r52, -64
- }
- wh64 r52
- #if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
- .ifnc \function,handle_nmi
-
- .ifnc \function,handle_syscall
- { move r30, r0
- { move r32, r2
- .endif
- TRACE_IRQS_OFF
- #ifdef CONFIG_CONTEXT_TRACKING
- jal context_tracking_user_exit
- #endif
- .ifnc \function,handle_syscall
- { move r0, r30
- { move r2, r32
- .endif
- .endif
- #endif
- .endm
-
- .macro dc_dispatch vecnum, vecname
- .org (\vecnum << 8)
- intvec_\vecname:
- j _hv_downcall_dispatch
- ENDPROC(intvec_\vecname)
- .endm
-
- .pushsection .text.handle_interrupt,"ax"
- handle_interrupt:
- finish_interrupt_save handle_interrupt
-
- {
- jalr r0
- PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
- }
- FEEDBACK_REENTER(handle_interrupt)
- {
- movei r30, 0
- j interrupt_return
- }
- STD_ENDPROC(handle_interrupt)
- STD_ENTRY(interrupt_return)
-
- {
- bnez r30, .Lrestore_all
- PTREGS_PTR(r29, PTREGS_OFFSET_EX1)
- }
- ld r29, r29
- IS_KERNEL_EX1(r29, r29)
- {
- beqzt r29, .Lresume_userspace
- move r29, sp
- }
- #ifdef CONFIG_PREEMPT
-
- EXTRACT_THREAD_INFO(r29)
- addli r28, r29, THREAD_INFO_FLAGS_OFFSET
- {
- ld r28, r28
- addli r29, r29, THREAD_INFO_PREEMPT_COUNT_OFFSET
- }
- {
- andi r28, r28, _TIF_NEED_RESCHED
- ld4s r29, r29
- }
- beqzt r28, 1f
- bnez r29, 1f
-
- IRQ_DISABLE(r20,r21)
- TRACE_IRQS_OFF
- jal preempt_schedule_irq
- FEEDBACK_REENTER(interrupt_return)
- 1:
- #endif
-
- {
- moveli r27, hw2_last(_cpu_idle_nap)
- PTREGS_PTR(r29, PTREGS_OFFSET_PC)
- }
- {
- ld r28, r29
- shl16insli r27, r27, hw1(_cpu_idle_nap)
- }
- {
- shl16insli r27, r27, hw0(_cpu_idle_nap)
- }
- {
- cmpeq r27, r27, r28
- }
- {
- blbc r27, .Lrestore_all
- addi r28, r28, 8
- }
- st r29, r28
- j .Lrestore_all
- .Lresume_userspace:
- FEEDBACK_REENTER(interrupt_return)
-
- IRQ_DISABLE(r20, r21)
- TRACE_IRQS_OFF
-
- move r21, sp
- EXTRACT_THREAD_INFO(r21)
- {
- addi r22, r21, THREAD_INFO_FLAGS_OFFSET
- moveli r20, hw1_last(_TIF_ALLWORK_MASK)
- }
- {
- ld r22, r22
- shl16insli r20, r20, hw0(_TIF_ALLWORK_MASK)
- }
- and r1, r22, r20
- {
- PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
- beqzt r1, .Lrestore_all
- }
- push_extra_callee_saves r0
- jal prepare_exit_to_usermode
-
- .Lrestore_all:
- PTREGS_PTR(r0, PTREGS_OFFSET_EX1)
- {
- ld r0, r0
- PTREGS_PTR(r32, PTREGS_OFFSET_FLAGS)
- }
- {
- IS_KERNEL_EX1(r0, r0)
- ld r32, r32
- }
- bnez r0, 1f
- j 2f
- #if PT_FLAGS_DISABLE_IRQ != 1
- # error Assuming PT_FLAGS_DISABLE_IRQ == 1 so we can use blbct below
- #endif
- 1: blbct r32, 2f
- IRQ_DISABLE(r20,r21)
- TRACE_IRQS_OFF
- movei r0, 1
- mtspr INTERRUPT_CRITICAL_SECTION, r0
- beqzt r30, .Lrestore_regs
- j 3f
- 2: TRACE_IRQS_ON
- IRQ_ENABLE_LOAD(r20, r21)
- movei r0, 1
- mtspr INTERRUPT_CRITICAL_SECTION, r0
- IRQ_ENABLE_APPLY(r20, r21)
- beqzt r30, .Lrestore_regs
- 3:
- #if INT_PERF_COUNT + 1 != INT_AUX_PERF_COUNT
- # error Bad interrupt assumption
- #endif
- {
- movei r0, 3
- beqz r31, .Lrestore_regs
- }
- shli r0, r0, INT_PERF_COUNT
- mtspr SPR_INTERRUPT_MASK_RESET_K, r0
-
- .Lrestore_regs:
-
- #if PT_FLAGS_CALLER_SAVES != 2 || PT_FLAGS_RESTORE_REGS != 4
- # error Rotate trick does not work :-)
- #endif
- {
- rotli r20, r32, 62
- PTREGS_PTR(sp, PTREGS_OFFSET_REG(0))
- }
-
- pop_reg r0, sp, PTREGS_OFFSET_REG(30) - PTREGS_OFFSET_REG(0)
- pop_reg r30, sp, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_REG(30)
- pop_reg_zero r52, r3, sp, PTREGS_OFFSET_CMPEXCH - PTREGS_OFFSET_REG(52)
- pop_reg_zero r21, r27, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_CMPEXCH
- pop_reg_zero lr, r2, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_EX1
- {
- mtspr CMPEXCH_VALUE, r21
- move r4, zero
- }
- pop_reg r21, sp, PTREGS_OFFSET_REG(31) - PTREGS_OFFSET_PC
- {
- mtspr SPR_EX_CONTEXT_K_1, lr
- IS_KERNEL_EX1(lr, lr)
- }
- {
- mtspr SPR_EX_CONTEXT_K_0, r21
- move r5, zero
- }
-
- pop_reg_zero r31, r6
- pop_reg_zero r32, r7
- pop_reg_zero r33, r8, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(33)
-
- {
- move r9, zero
- blbs r20, .Lrestore_callees
- }
- .Lcontinue_restore_regs:
-
- {
- move r10, zero
- bltzt r20, 1f
- }
-
- {
- addli sp, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(29)
- bnez lr, .Lkernel_return
- }
-
- pop_reg_zero lr, r11, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
- pop_reg_zero tp, r12, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
- {
- ld sp, sp
- move r13, zero
- move r14, zero
- }
- { move r15, zero
- { move r17, zero
- { move r19, zero
- { move r21, zero
- { move r23, zero
- { move r25, zero
-
- {
- moveli r29, 4096
- sub r1, zero, r0
- }
- {
- move r28, zero
- cmpltu r29, r1, r29
- }
- {
- mnz r1, r29, r1
- move r29, zero
- }
- iret
-
- .align 64
- 1: pop_reg r29, sp, PTREGS_OFFSET_REG(21) - PTREGS_OFFSET_REG(29)
- pop_reg r21, sp, PTREGS_OFFSET_REG(13) - PTREGS_OFFSET_REG(21)
- pop_reg r13, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(13)
- pop_reg r1
- pop_reg r2
- pop_reg r3
- pop_reg r4
- pop_reg r5
- pop_reg r6
- pop_reg r7
- pop_reg r8
- pop_reg r9
- pop_reg r10
- pop_reg r11
- pop_reg r12, sp, 16
-
- pop_reg r14
- pop_reg r15
- pop_reg r16
- pop_reg r17
- pop_reg r18
- pop_reg r19
- pop_reg r20, sp, 16
-
- pop_reg r22
- pop_reg r23
- pop_reg r24
- pop_reg r25
- pop_reg r26
- pop_reg r27
- pop_reg r28, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(28)
-
- bnez lr, .Lkernel_return
- pop_reg lr, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
- pop_reg tp, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
- ld sp, sp
- iret
-
- .Lkernel_return:
- pop_reg lr, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
- ld sp, sp
- iret
-
- .Lrestore_callees:
- addli sp, sp, PTREGS_OFFSET_REG(34) - PTREGS_OFFSET_REG(29)
- pop_reg r34
- pop_reg r35
- pop_reg r36
- pop_reg r37
- pop_reg r38
- pop_reg r39
- pop_reg r40
- pop_reg r41
- pop_reg r42
- pop_reg r43
- pop_reg r44
- pop_reg r45
- pop_reg r46
- pop_reg r47
- pop_reg r48
- pop_reg r49
- pop_reg r50
- pop_reg r51, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(51)
- j .Lcontinue_restore_regs
- STD_ENDPROC(interrupt_return)
-
- .pushsection .text.handle_nmi,"ax"
- handle_nmi:
- finish_interrupt_save handle_nmi
- {
- jalr r0
- PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
- }
- FEEDBACK_REENTER(handle_nmi)
- {
- movei r30, 1
- cmpeq r31, r0, zero
- }
- j interrupt_return
- STD_ENDPROC(handle_nmi)
-
- .pushsection .text.handle_syscall,"ax"
- handle_syscall:
- finish_interrupt_save handle_syscall
-
- TRACE_IRQS_ON
- IRQ_ENABLE(r20, r21)
-
- moveli r20, hw2_last(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
- shl16insli r20, r20, hw1(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
- shl16insli r20, r20, hw0(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
- add r20, r20, tp
- ld4s r21, r20
- {
- addi r21, r21, 1
- move r31, sp
- }
- {
- st4 r20, r21
- EXTRACT_THREAD_INFO(r31)
- }
-
- addi r31, r31, THREAD_INFO_FLAGS_OFFSET
- {
- ld r30, r31
- moveli r32, _TIF_SYSCALL_ENTRY_WORK
- }
- and r30, r30, r32
- {
- addi r30, r31, THREAD_INFO_STATUS_OFFSET - THREAD_INFO_FLAGS_OFFSET
- beqzt r30, .Lrestore_syscall_regs
- }
- {
- PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
- jal do_syscall_trace_enter
- }
- FEEDBACK_REENTER(handle_syscall)
- bltz r0, .Lsyscall_sigreturn_skip
-
- .Lrestore_syscall_regs:
- {
- ld r30, r30
- PTREGS_PTR(r11, PTREGS_OFFSET_REG(0))
- }
- pop_reg r0, r11
- pop_reg r1, r11
- pop_reg r2, r11
- pop_reg r3, r11
- pop_reg r4, r11
- pop_reg r5, r11, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(5)
- {
- ld TREG_SYSCALL_NR_NAME, r11
- moveli r21, __NR_syscalls
- }
-
- {
- moveli r20, hw2(sys_call_table)
- #ifdef CONFIG_COMPAT
- blbs r30, .Lcompat_syscall
- #endif
- }
- {
- cmpltu r21, TREG_SYSCALL_NR_NAME, r21
- shl16insli r20, r20, hw1(sys_call_table)
- }
- {
- blbc r21, .Linvalid_syscall
- shl16insli r20, r20, hw0(sys_call_table)
- }
- .Lload_syscall_pointer:
- shl3add r20, TREG_SYSCALL_NR_NAME, r20
- ld r20, r20
-
- jalr r20
- .Lhandle_syscall_link:
-
- {
- PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
- blbct r30, 1f
- }
- addxi r0, r0, 0
- 1: st r29, r0
- .Lsyscall_sigreturn_skip:
- FEEDBACK_REENTER(handle_syscall)
-
- {
- ld r30, r31
- moveli r32, _TIF_SYSCALL_EXIT_WORK
- }
- and r0, r30, r32
- {
- andi r0, r30, _TIF_SINGLESTEP
- beqzt r0, 1f
- }
- {
- PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
- jal do_syscall_trace_exit
- }
- FEEDBACK_REENTER(handle_syscall)
- andi r0, r30, _TIF_SINGLESTEP
- 1: beqzt r0, 2f
-
- {
- movei r0, SIGTRAP
- jal ptrace_notify
- }
- FEEDBACK_REENTER(handle_syscall)
- 2: {
- movei r30, 0
- j .Lresume_userspace
- }
- #ifdef CONFIG_COMPAT
- .Lcompat_syscall:
-
- moveli r20, hw2(compat_sys_call_table)
- {
- cmpltu r21, TREG_SYSCALL_NR_NAME, r21
- shl16insli r20, r20, hw1(compat_sys_call_table)
- }
- {
- blbc r21, .Linvalid_syscall
- shl16insli r20, r20, hw0(compat_sys_call_table)
- }
- { move r11, r0
- { move r12, r1
- { move r13, r2
- { move r14, r3
- { move r15, r4
- { move r16, r5
- j .Lload_syscall_pointer
- #endif
- .Linvalid_syscall:
-
- {
- PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
- movei r28, -ENOSYS
- }
- st r29, r28
- {
- movei r30, 0
- j .Lresume_userspace
- }
- STD_ENDPROC(handle_syscall)
-
- STD_ENTRY_SECTION(handle_syscall_link_address, .text.handle_syscall)
- lnk r0
- {
- addli r0, r0, .Lhandle_syscall_link - .
- jrp lr
- }
- STD_ENDPROC(handle_syscall_link_address)
- STD_ENTRY(ret_from_fork)
- jal sim_notify_fork
- jal schedule_tail
- FEEDBACK_REENTER(ret_from_fork)
- {
- movei r30, 0
- j .Lresume_userspace
- }
- STD_ENDPROC(ret_from_fork)
- STD_ENTRY(ret_from_kernel_thread)
- jal sim_notify_fork
- jal schedule_tail
- FEEDBACK_REENTER(ret_from_fork)
- {
- move r0, r31
- jalr r30
- }
- FEEDBACK_REENTER(ret_from_kernel_thread)
- {
- movei r30, 0
- j interrupt_return
- }
- STD_ENDPROC(ret_from_kernel_thread)
- STD_ENTRY_LOCAL(_kernel_double_fault)
- mfspr r1, SPR_EX_CONTEXT_K_0
- move r2, lr
- move r3, sp
- move r4, r52
- addi sp, sp, -C_ABI_SAVE_AREA_SIZE
- j kernel_double_fault
- STD_ENDPROC(_kernel_double_fault)
- STD_ENTRY_LOCAL(bad_intr)
- mfspr r2, SPR_EX_CONTEXT_K_0
- panic "Unhandled interrupt %#x: PC %#lx"
- STD_ENDPROC(bad_intr)
- #define PTREGS_SYSCALL_SIGRETURN(x, reg) \
- STD_ENTRY(_##x)
- addli lr, lr, .Lsyscall_sigreturn_skip - .Lhandle_syscall_link
- { \
- PTREGS_PTR(reg, PTREGS_OFFSET_BASE)
- j x \
- }
- STD_ENDPROC(_##x)
- PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0)
- #ifdef CONFIG_COMPAT
- PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0)
- #endif
- STD_ENTRY(_sys_clone)
- push_extra_callee_saves r4
- j sys_clone
- STD_ENDPROC(_sys_clone)
-
- __HEAD
- hand_unalign_slow:
- andi sp, sp, ~1
- hand_unalign_slow_badsp:
- addi r3, r3, -(3 * 8)
- ld_add r0, r3, 8
- ld_add r1, r3, 8
- ld r2, r3
- hand_unalign_slow_nonuser:
- mfspr r3, SPR_SYSTEM_SAVE_K_1
- __int_hand INT_UNALIGN_DATA, UNALIGN_DATA_SLOW, int_unalign
- int_unalign:
- push_extra_callee_saves r0
- j do_unaligned
- ENDPROC(hand_unalign_slow)
- STD_ENTRY(fill_ra_stack)
- {
- move r0, lr
- jal 1f
- }
- 1: jal 2f
- 2: jal 3f
- 3: jal 4f
- 4: jrp r0
- STD_ENDPROC(fill_ra_stack)
- .macro int_hand vecnum, vecname, c_routine, processing=handle_interrupt
- .org (\vecnum << 8)
- __int_hand \vecnum, \vecname, \c_routine, \processing
- .endm
- .section ".intrpt", "ax"
- .global intrpt_start
- intrpt_start:
- #ifndef CONFIG_USE_PMC
- #define handle_perf_interrupt bad_intr
- #endif
- #ifndef CONFIG_HARDWALL
- #define do_hardwall_trap bad_intr
- #endif
- int_hand INT_MEM_ERROR, MEM_ERROR, do_trap
- int_hand INT_SINGLE_STEP_3, SINGLE_STEP_3, bad_intr
- #if CONFIG_KERNEL_PL == 2
- int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, gx_singlestep_handle
- int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, bad_intr
- #else
- int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, bad_intr
- int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, gx_singlestep_handle
- #endif
- int_hand INT_SINGLE_STEP_0, SINGLE_STEP_0, bad_intr
- int_hand INT_IDN_COMPLETE, IDN_COMPLETE, bad_intr
- int_hand INT_UDN_COMPLETE, UDN_COMPLETE, bad_intr
- int_hand INT_ITLB_MISS, ITLB_MISS, do_page_fault
- int_hand INT_ILL, ILL, do_trap
- int_hand INT_GPV, GPV, do_trap
- int_hand INT_IDN_ACCESS, IDN_ACCESS, do_trap
- int_hand INT_UDN_ACCESS, UDN_ACCESS, do_trap
- int_hand INT_SWINT_3, SWINT_3, do_trap
- int_hand INT_SWINT_2, SWINT_2, do_trap
- int_hand INT_SWINT_1, SWINT_1, SYSCALL, handle_syscall
- int_hand INT_SWINT_0, SWINT_0, do_trap
- int_hand INT_ILL_TRANS, ILL_TRANS, do_trap
- int_hand_unalign_fast INT_UNALIGN_DATA, UNALIGN_DATA
- int_hand INT_DTLB_MISS, DTLB_MISS, do_page_fault
- int_hand INT_DTLB_ACCESS, DTLB_ACCESS, do_page_fault
- int_hand INT_IDN_FIREWALL, IDN_FIREWALL, do_hardwall_trap
- int_hand INT_UDN_FIREWALL, UDN_FIREWALL, do_hardwall_trap
- int_hand INT_TILE_TIMER, TILE_TIMER, do_timer_interrupt
- int_hand INT_IDN_TIMER, IDN_TIMER, bad_intr
- int_hand INT_UDN_TIMER, UDN_TIMER, bad_intr
- int_hand INT_IDN_AVAIL, IDN_AVAIL, bad_intr
- int_hand INT_UDN_AVAIL, UDN_AVAIL, bad_intr
- int_hand INT_IPI_3, IPI_3, bad_intr
- #if CONFIG_KERNEL_PL == 2
- int_hand INT_IPI_2, IPI_2, tile_dev_intr
- int_hand INT_IPI_1, IPI_1, bad_intr
- #else
- int_hand INT_IPI_2, IPI_2, bad_intr
- int_hand INT_IPI_1, IPI_1, tile_dev_intr
- #endif
- int_hand INT_IPI_0, IPI_0, bad_intr
- int_hand INT_PERF_COUNT, PERF_COUNT, \
- handle_perf_interrupt, handle_nmi
- int_hand INT_AUX_PERF_COUNT, AUX_PERF_COUNT, \
- handle_perf_interrupt, handle_nmi
- int_hand INT_INTCTRL_3, INTCTRL_3, bad_intr
- #if CONFIG_KERNEL_PL == 2
- dc_dispatch INT_INTCTRL_2, INTCTRL_2
- int_hand INT_INTCTRL_1, INTCTRL_1, bad_intr
- #else
- int_hand INT_INTCTRL_2, INTCTRL_2, bad_intr
- dc_dispatch INT_INTCTRL_1, INTCTRL_1
- #endif
- int_hand INT_INTCTRL_0, INTCTRL_0, bad_intr
- int_hand INT_MESSAGE_RCV_DWNCL, MESSAGE_RCV_DWNCL, \
- hv_message_intr
- int_hand INT_DEV_INTR_DWNCL, DEV_INTR_DWNCL, bad_intr
- int_hand INT_I_ASID, I_ASID, bad_intr
- int_hand INT_D_ASID, D_ASID, bad_intr
- int_hand INT_DOUBLE_FAULT, DOUBLE_FAULT, do_trap
-
- int_hand INT_BREAKPOINT, BREAKPOINT, do_breakpoint
-
- int_hand INT_NMI_DWNCL, NMI_DWNCL, do_nmi, handle_nmi
|