1*0a6a1f1dSLionel Sambuc/* $NetBSD: compat__setjmp.S,v 1.4 2014/01/24 10:19:18 skrll 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 * The previous signal state is NOT restored. 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) 57*0a6a1f1dSLionel Sambuc ldq t0, magic /* sigcontext magic number */ 582fe8fb19SBen Gras stq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ 592fe8fb19SBen Gras /* Too bad we can't check if we actually used FP */ 602fe8fb19SBen Gras ldiq t0, 1 612fe8fb19SBen Gras stq t0, (36 * 8)(a0) /* say we've used FP. */ 622fe8fb19SBen Gras stt fs0, ((2 + 37) * 8)(a0) /* saved bits of sc_fpregs */ 632fe8fb19SBen Gras stt fs1, ((3 + 37) * 8)(a0) 642fe8fb19SBen Gras stt fs2, ((4 + 37) * 8)(a0) 652fe8fb19SBen Gras stt fs3, ((5 + 37) * 8)(a0) 662fe8fb19SBen Gras stt fs4, ((6 + 37) * 8)(a0) 672fe8fb19SBen Gras stt fs5, ((7 + 37) * 8)(a0) 682fe8fb19SBen Gras stt fs6, ((8 + 37) * 8)(a0) 692fe8fb19SBen Gras stt fs7, ((9 + 37) * 8)(a0) 702fe8fb19SBen Gras mf_fpcr ft0 /* get FP control reg */ 712fe8fb19SBen Gras stt ft0, (69 * 8)(a0) /* and store it in sc_fpcr */ 722fe8fb19SBen Gras stq zero, (70 * 8)(a0) /* FP software control XXX */ 732fe8fb19SBen Gras stq zero, (71 * 8)(a0) /* sc_reserved[0] */ 742fe8fb19SBen Gras stq zero, (72 * 8)(a0) /* sc_reserved[1] */ 752fe8fb19SBen Gras stq zero, (73 * 8)(a0) /* sc_xxx[0] */ 762fe8fb19SBen Gras stq zero, (74 * 8)(a0) /* sc_xxx[1] */ 772fe8fb19SBen Gras stq zero, (75 * 8)(a0) /* sc_xxx[2] */ 782fe8fb19SBen Gras stq zero, (76 * 8)(a0) /* sc_xxx[3] */ 792fe8fb19SBen Gras stq zero, (77 * 8)(a0) /* sc_xxx[4] */ 802fe8fb19SBen Gras stq zero, (78 * 8)(a0) /* sc_xxx[5] */ 812fe8fb19SBen Gras stq zero, (79 * 8)(a0) /* sc_xxx[6] */ 822fe8fb19SBen Gras stq zero, (80 * 8)(a0) /* sc_xxx[7] */ 832fe8fb19SBen Gras 842fe8fb19SBen Gras mov zero, v0 /* return zero */ 852fe8fb19SBen Gras RET 86*0a6a1f1dSLionel Sambucmagic: 87*0a6a1f1dSLionel Sambuc .quad 0xacedbadd 882fe8fb19SBen GrasEND(_setjmp) 892fe8fb19SBen Gras 902fe8fb19SBen GrasLEAF(_longjmp, 2) 912fe8fb19SBen Gras LDGP(pv) 922fe8fb19SBen Gras ldq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ 93*0a6a1f1dSLionel Sambuc ldq t1, magic /* sigcontext magic number */ 942fe8fb19SBen Gras cmpeq t0, t1, t0 952fe8fb19SBen Gras beq t0, botch /* If the magic was bad, punt */ 962fe8fb19SBen Gras 972fe8fb19SBen Gras ldq ra, (2 * 8)(a0) /* sc_pc = return address */ 982fe8fb19SBen Gras ldq s0, (( 9 + 4) * 8)(a0) /* saved bits of sc_regs */ 992fe8fb19SBen Gras ldq s1, ((10 + 4) * 8)(a0) 1002fe8fb19SBen Gras ldq s2, ((11 + 4) * 8)(a0) 1012fe8fb19SBen Gras ldq s3, ((12 + 4) * 8)(a0) 1022fe8fb19SBen Gras ldq s4, ((13 + 4) * 8)(a0) 1032fe8fb19SBen Gras ldq s5, ((14 + 4) * 8)(a0) 1042fe8fb19SBen Gras ldq s6, ((15 + 4) * 8)(a0) 1052fe8fb19SBen Gras /* ldq ra, ((26 + 4) * 8)(a0) set above */ 1062fe8fb19SBen Gras ldq sp, ((30 + 4) * 8)(a0) 1072fe8fb19SBen Gras ldt fs0, ((2 + 37) * 8)(a0) /* saved bits of sc_fpregs */ 1082fe8fb19SBen Gras ldt fs1, ((3 + 37) * 8)(a0) 1092fe8fb19SBen Gras ldt fs2, ((4 + 37) * 8)(a0) 1102fe8fb19SBen Gras ldt fs3, ((5 + 37) * 8)(a0) 1112fe8fb19SBen Gras ldt fs4, ((6 + 37) * 8)(a0) 1122fe8fb19SBen Gras ldt fs5, ((7 + 37) * 8)(a0) 1132fe8fb19SBen Gras ldt fs6, ((8 + 37) * 8)(a0) 1142fe8fb19SBen Gras ldt fs7, ((9 + 37) * 8)(a0) 1152fe8fb19SBen Gras ldt ft0, (69 * 8)(a0) /* get sc_fpcr */ 1162fe8fb19SBen Gras mt_fpcr ft0 /* and restore it. */ 1172fe8fb19SBen Gras 1182fe8fb19SBen Gras mov a1, v0 /* return second arg */ 1192fe8fb19SBen Gras RET 1202fe8fb19SBen Gras 1212fe8fb19SBen Grasbotch: 1222fe8fb19SBen Gras CALL(longjmperror) 1232fe8fb19SBen Gras CALL(abort) 1242fe8fb19SBen Gras RET /* "can't" get here... */ 1252fe8fb19SBen GrasEND(_longjmp) 126