/*-1* Copyright (c) 2015-2016 Ruslan Bukin <[email protected]>2* All rights reserved.3*4* Portions of this software were developed by SRI International and the5* University of Cambridge Computer Laboratory under DARPA/AFRL contract6* FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.7*8* Portions of this software were developed by the University of Cambridge9* Computer Laboratory as part of the CTSRD Project, with support from the10* UK Higher Education Innovation Fund (HEIF).11*12* Redistribution and use in source and binary forms, with or without13* modification, are permitted provided that the following conditions14* are met:15* 1. Redistributions of source code must retain the above copyright16* notice, this list of conditions and the following disclaimer.17* 2. Redistributions in binary form must reproduce the above copyright18* notice, this list of conditions and the following disclaimer in the19* documentation and/or other materials provided with the distribution.20*21* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#include <machine/asm.h>35#include <machine/setjmp.h>3637ENTRY(_setjmp)38/* Store the magic value and stack pointer */39ld t0, .Lmagic40sd t0, (0 * 8)(a0)41sd sp, (1 * 8)(a0)42addi a0, a0, (2 * 8)4344/* Store the general purpose registers and ra */45sd s0, (0 * 8)(a0)46sd s1, (1 * 8)(a0)47sd s2, (2 * 8)(a0)48sd s3, (3 * 8)(a0)49sd s4, (4 * 8)(a0)50sd s5, (5 * 8)(a0)51sd s6, (6 * 8)(a0)52sd s7, (7 * 8)(a0)53sd s8, (8 * 8)(a0)54sd s9, (9 * 8)(a0)55sd s10, (10 * 8)(a0)56sd s11, (11 * 8)(a0)57sd ra, (12 * 8)(a0)58addi a0, a0, (13 * 8)5960#if !defined(_STANDALONE) && defined(__riscv_float_abi_double)61/* Store the fpe registers */62fsd fs0, (0 * 8)(a0)63fsd fs1, (1 * 8)(a0)64fsd fs2, (2 * 8)(a0)65fsd fs3, (3 * 8)(a0)66fsd fs4, (4 * 8)(a0)67fsd fs5, (5 * 8)(a0)68fsd fs6, (6 * 8)(a0)69fsd fs7, (7 * 8)(a0)70fsd fs8, (8 * 8)(a0)71fsd fs9, (9 * 8)(a0)72fsd fs10, (10 * 8)(a0)73fsd fs11, (11 * 8)(a0)74addi a0, a0, (12 * 8)75#endif7677/* Return value */78li a0, 079ret80.align 381.Lmagic:82.quad _JB_MAGIC__SETJMP83END(_setjmp)8485ENTRY(_longjmp)86/* Check the magic value */87ld t0, 0(a0)88ld t1, .Lmagic89bne t0, t1, botch9091/* Restore the stack pointer */92ld t0, 8(a0)93mv sp, t094addi a0, a0, (2 * 8)9596/* Restore the general purpose registers and ra */97ld s0, (0 * 8)(a0)98ld s1, (1 * 8)(a0)99ld s2, (2 * 8)(a0)100ld s3, (3 * 8)(a0)101ld s4, (4 * 8)(a0)102ld s5, (5 * 8)(a0)103ld s6, (6 * 8)(a0)104ld s7, (7 * 8)(a0)105ld s8, (8 * 8)(a0)106ld s9, (9 * 8)(a0)107ld s10, (10 * 8)(a0)108ld s11, (11 * 8)(a0)109ld ra, (12 * 8)(a0)110addi a0, a0, (13 * 8)111112#if !defined(_STANDALONE) && defined(__riscv_float_abi_double)113/* Restore the fpe registers */114fld fs0, (0 * 8)(a0)115fld fs1, (1 * 8)(a0)116fld fs2, (2 * 8)(a0)117fld fs3, (3 * 8)(a0)118fld fs4, (4 * 8)(a0)119fld fs5, (5 * 8)(a0)120fld fs6, (6 * 8)(a0)121fld fs7, (7 * 8)(a0)122fld fs8, (8 * 8)(a0)123fld fs9, (9 * 8)(a0)124fld fs10, (10 * 8)(a0)125fld fs11, (11 * 8)(a0)126addi a0, a0, (12 * 8)127#endif128129/* Load the return value */130mv a0, a1131bnez a1, 1f132li a0, 11331:134ret135136botch:137#ifdef _STANDALONE138j botch139#else140call _C_LABEL(longjmperror)141call _C_LABEL(abort)142#endif143END(_longjmp)144145146