1*0a6a1f1dSLionel Sambuc/* $NetBSD: compat_setjmp.S,v 1.2 2014/01/23 03:08:50 christos Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras/* 42fe8fb19SBen Gras * Copyright (c) 1994, 1995 Carnegie-Mellon University. 52fe8fb19SBen Gras * All rights reserved. 62fe8fb19SBen Gras * 72fe8fb19SBen Gras * Author: Chris G. Demetriou 82fe8fb19SBen Gras * 92fe8fb19SBen Gras * Permission to use, copy, modify and distribute this software and 102fe8fb19SBen Gras * its documentation is hereby granted, provided that both the copyright 112fe8fb19SBen Gras * notice and this permission notice appear in all copies of the 122fe8fb19SBen Gras * software, derivative works or modified versions, and any portions 132fe8fb19SBen Gras * thereof, and that both notices appear in supporting documentation. 142fe8fb19SBen Gras * 152fe8fb19SBen Gras * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 162fe8fb19SBen Gras * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 172fe8fb19SBen Gras * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 182fe8fb19SBen Gras * 192fe8fb19SBen Gras * Carnegie Mellon requests users of this software to return to 202fe8fb19SBen Gras * 212fe8fb19SBen Gras * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 222fe8fb19SBen Gras * School of Computer Science 232fe8fb19SBen Gras * Carnegie Mellon University 242fe8fb19SBen Gras * Pittsburgh PA 15213-3890 252fe8fb19SBen Gras * 262fe8fb19SBen Gras * any improvements or extensions that they make and grant Carnegie the 272fe8fb19SBen Gras * rights to redistribute these changes. 282fe8fb19SBen Gras */ 292fe8fb19SBen Gras 302fe8fb19SBen Gras#include <machine/asm.h> 312fe8fb19SBen Gras 322fe8fb19SBen Gras/* 332fe8fb19SBen Gras * C library -- setjmp, longjmp 342fe8fb19SBen Gras * 352fe8fb19SBen Gras * longjmp(a,v) 362fe8fb19SBen Gras * will generate a "return(v)" from 372fe8fb19SBen Gras * the last call to 382fe8fb19SBen Gras * setjmp(a) 392fe8fb19SBen Gras * by restoring registers from the stack, 402fe8fb19SBen Gras * and the previous signal state. 412fe8fb19SBen Gras */ 422fe8fb19SBen Gras 432fe8fb19SBen Gras .set noreorder 442fe8fb19SBen Gras 452fe8fb19SBen GrasLEAF(setjmp, 1) 462fe8fb19SBen Gras LDGP(pv) 472fe8fb19SBen Gras stq ra, (2 * 8)(a0) /* sc_pc = return address */ 482fe8fb19SBen Gras stq s0, (( 9 + 4) * 8)(a0) /* saved bits of sc_regs */ 492fe8fb19SBen Gras stq s1, ((10 + 4) * 8)(a0) 502fe8fb19SBen Gras stq s2, ((11 + 4) * 8)(a0) 512fe8fb19SBen Gras stq s3, ((12 + 4) * 8)(a0) 522fe8fb19SBen Gras stq s4, ((13 + 4) * 8)(a0) 532fe8fb19SBen Gras stq s5, ((14 + 4) * 8)(a0) 542fe8fb19SBen Gras stq s6, ((15 + 4) * 8)(a0) 552fe8fb19SBen Gras stq ra, ((26 + 4) * 8)(a0) 562fe8fb19SBen Gras stq sp, ((30 + 4) * 8)(a0) 572fe8fb19SBen Gras 582fe8fb19SBen Gras /* 592fe8fb19SBen Gras * get signal information 602fe8fb19SBen Gras */ 612fe8fb19SBen Gras mov a0, s0 /* squirrel away ptr to sc */ 622fe8fb19SBen Gras 632fe8fb19SBen Gras /* see what's blocked */ 642fe8fb19SBen Gras mov zero, a0 652fe8fb19SBen Gras CALL(sigblock) /* see what's blocked */ 662fe8fb19SBen Gras stq v0, (1 * 8)(s0) /* and remember it in sc_mask */ 672fe8fb19SBen Gras 682fe8fb19SBen Gras lda sp, -24(sp) /* sizeof struct sigaltstack */ 692fe8fb19SBen Gras mov zero, a0 702fe8fb19SBen Gras mov sp, a1 712fe8fb19SBen Gras CALL(__sigaltstack14) 722fe8fb19SBen Gras ldl t0, 16(sp) /* offset of ss_flags */ 732fe8fb19SBen Gras lda sp, 24(sp) /* sizeof struct sigaltstack */ 742fe8fb19SBen Gras ldq ra, ((26 + 4) * 8)(s0) /* restore return address */ 752fe8fb19SBen Gras blt v0, botch /* check for error */ 762fe8fb19SBen Gras and t0, 0x1, t0 /* get SA_ONSTACK flag */ 772fe8fb19SBen Gras stq t0, (0 * 8)(s0) /* and save it in sc_onstack */ 782fe8fb19SBen Gras /* 792fe8fb19SBen Gras * Restore old s0 and a0, and continue saving registers 802fe8fb19SBen Gras */ 812fe8fb19SBen Gras mov s0, a0 822fe8fb19SBen Gras ldq s0, (( 9 + 4) * 8)(a0) 832fe8fb19SBen Gras 84*0a6a1f1dSLionel Sambuc ldq t0, magic /* sigcontext magic number */ 852fe8fb19SBen Gras stq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ 862fe8fb19SBen Gras /* Too bad we can't check if we actually used FP */ 872fe8fb19SBen Gras ldiq t0, 1 882fe8fb19SBen Gras stq t0, (36 * 8)(a0) /* say we've used FP. */ 892fe8fb19SBen Gras stt fs0, ((2 + 37) * 8)(a0) /* saved bits of sc_fpregs */ 902fe8fb19SBen Gras stt fs1, ((3 + 37) * 8)(a0) 912fe8fb19SBen Gras stt fs2, ((4 + 37) * 8)(a0) 922fe8fb19SBen Gras stt fs3, ((5 + 37) * 8)(a0) 932fe8fb19SBen Gras stt fs4, ((6 + 37) * 8)(a0) 942fe8fb19SBen Gras stt fs5, ((7 + 37) * 8)(a0) 952fe8fb19SBen Gras stt fs6, ((8 + 37) * 8)(a0) 962fe8fb19SBen Gras stt fs7, ((9 + 37) * 8)(a0) 972fe8fb19SBen Gras mf_fpcr ft0 /* get FP control reg */ 982fe8fb19SBen Gras stt ft0, (69 * 8)(a0) /* and store it in sc_fpcr */ 992fe8fb19SBen Gras stq zero, (70 * 8)(a0) /* FP software control XXX */ 1002fe8fb19SBen Gras stq zero, (71 * 8)(a0) /* sc_reserved[0] */ 1012fe8fb19SBen Gras stq zero, (72 * 8)(a0) /* sc_reserved[1] */ 1022fe8fb19SBen Gras stq zero, (73 * 8)(a0) /* sc_xxx[0] */ 1032fe8fb19SBen Gras stq zero, (74 * 8)(a0) /* sc_xxx[1] */ 1042fe8fb19SBen Gras stq zero, (75 * 8)(a0) /* sc_xxx[2] */ 1052fe8fb19SBen Gras stq zero, (76 * 8)(a0) /* sc_xxx[3] */ 1062fe8fb19SBen Gras stq zero, (77 * 8)(a0) /* sc_xxx[4] */ 1072fe8fb19SBen Gras stq zero, (78 * 8)(a0) /* sc_xxx[5] */ 1082fe8fb19SBen Gras stq zero, (79 * 8)(a0) /* sc_xxx[6] */ 1092fe8fb19SBen Gras stq zero, (80 * 8)(a0) /* sc_xxx[7] */ 1102fe8fb19SBen Gras 1112fe8fb19SBen Gras mov zero, v0 /* return zero */ 1122fe8fb19SBen Gras RET 1132fe8fb19SBen GrasEND(setjmp) 1142fe8fb19SBen Gras 1152fe8fb19SBen GrasLEAF(longjmp, 2) 1162fe8fb19SBen Gras LDGP(pv) 1172fe8fb19SBen Gras stq a1, (( 0 + 4) * 8)(a0) /* save return value */ 1182fe8fb19SBen Gras CALL(sigreturn) /* use sigreturn to return */ 1192fe8fb19SBen Gras 1202fe8fb19SBen Grasbotch: 1212fe8fb19SBen Gras CALL(longjmperror) 1222fe8fb19SBen Gras CALL(abort) 1232fe8fb19SBen Gras RET /* "can't" get here... */ 124*0a6a1f1dSLionel Sambucmagic: 125*0a6a1f1dSLionel Sambuc .quad 0xacedbade /* sigcontext magic number */ 1262fe8fb19SBen GrasEND(longjmp) 127