1/* $NetBSD: _setjmp.S,v 1.3 2000/06/14 06:49:01 cgd Exp $ */ 2 3/* 4 * Copyright (c) 1994, 1995 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 30#include <machine/asm.h> 31 32/* 33 * C library -- _setjmp, _longjmp 34 * 35 * _longjmp(a,v) 36 * will generate a "return(v)" from 37 * the last call to 38 * _setjmp(a) 39 * by restoring registers from the stack, 40 * The previous signal state is NOT restored. 41 */ 42 43 .set noreorder 44 45LEAF(_setjmp, 1) 46 LDGP(pv) 47 stq ra, (2 * 8)(a0) /* sc_pc = return address */ 48 stq s0, (( 9 + 4) * 8)(a0) /* saved bits of sc_regs */ 49 stq s1, ((10 + 4) * 8)(a0) 50 stq s2, ((11 + 4) * 8)(a0) 51 stq s3, ((12 + 4) * 8)(a0) 52 stq s4, ((13 + 4) * 8)(a0) 53 stq s5, ((14 + 4) * 8)(a0) 54 stq s6, ((15 + 4) * 8)(a0) 55 stq ra, ((26 + 4) * 8)(a0) 56 stq sp, ((30 + 4) * 8)(a0) 57 ldiq t0, 0xacedbadd /* sigcontext magic number */ 58 stq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ 59 /* Too bad we can't check if we actually used FP */ 60 ldiq t0, 1 61 stq t0, (36 * 8)(a0) /* say we've used FP. */ 62 stt fs0, ((2 + 37) * 8)(a0) /* saved bits of sc_fpregs */ 63 stt fs1, ((3 + 37) * 8)(a0) 64 stt fs2, ((4 + 37) * 8)(a0) 65 stt fs3, ((5 + 37) * 8)(a0) 66 stt fs4, ((6 + 37) * 8)(a0) 67 stt fs5, ((7 + 37) * 8)(a0) 68 stt fs6, ((8 + 37) * 8)(a0) 69 stt fs7, ((9 + 37) * 8)(a0) 70 mf_fpcr ft0 /* get FP control reg */ 71 stt ft0, (69 * 8)(a0) /* and store it in sc_fpcr */ 72 stq zero, (70 * 8)(a0) /* FP software control XXX */ 73 stq zero, (71 * 8)(a0) /* sc_reserved[0] */ 74 stq zero, (72 * 8)(a0) /* sc_reserved[1] */ 75 stq zero, (73 * 8)(a0) /* sc_xxx[0] */ 76 stq zero, (74 * 8)(a0) /* sc_xxx[1] */ 77 stq zero, (75 * 8)(a0) /* sc_xxx[2] */ 78 stq zero, (76 * 8)(a0) /* sc_xxx[3] */ 79 stq zero, (77 * 8)(a0) /* sc_xxx[4] */ 80 stq zero, (78 * 8)(a0) /* sc_xxx[5] */ 81 stq zero, (79 * 8)(a0) /* sc_xxx[6] */ 82 stq zero, (80 * 8)(a0) /* sc_xxx[7] */ 83 84 mov zero, v0 /* return zero */ 85 RET 86END(_setjmp) 87 88LEAF(_longjmp, 2) 89 LDGP(pv) 90 ldq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ 91 ldiq t1, 0xacedbadd 92 cmpeq t0, t1, t0 93 beq t0, botch /* If the magic was bad, punt */ 94 95 ldq ra, (2 * 8)(a0) /* sc_pc = return address */ 96 ldq s0, (( 9 + 4) * 8)(a0) /* saved bits of sc_regs */ 97 ldq s1, ((10 + 4) * 8)(a0) 98 ldq s2, ((11 + 4) * 8)(a0) 99 ldq s3, ((12 + 4) * 8)(a0) 100 ldq s4, ((13 + 4) * 8)(a0) 101 ldq s5, ((14 + 4) * 8)(a0) 102 ldq s6, ((15 + 4) * 8)(a0) 103 /* ldq ra, ((26 + 4) * 8)(a0) set above */ 104 ldq sp, ((30 + 4) * 8)(a0) 105 ldt fs0, ((2 + 37) * 8)(a0) /* saved bits of sc_fpregs */ 106 ldt fs1, ((3 + 37) * 8)(a0) 107 ldt fs2, ((4 + 37) * 8)(a0) 108 ldt fs3, ((5 + 37) * 8)(a0) 109 ldt fs4, ((6 + 37) * 8)(a0) 110 ldt fs5, ((7 + 37) * 8)(a0) 111 ldt fs6, ((8 + 37) * 8)(a0) 112 ldt fs7, ((9 + 37) * 8)(a0) 113 ldt ft0, (69 * 8)(a0) /* get sc_fpcr */ 114 mt_fpcr ft0 /* and restore it. */ 115 116 mov a1, v0 /* return second arg */ 117 RET 118 119botch: 120 CALL(longjmperror) 121 CALL(abort) 122 RET /* "can't" get here... */ 123END(_longjmp) 124