Home | History | Annotate | Line # | Download | only in gen
_setjmp.S revision 1.1
      1  1.1  matt /* $NetBSD: _setjmp.S,v 1.1 2014/08/10 05:47:36 matt Exp $ */
      2  1.1  matt 
      3  1.1  matt /*-
      4  1.1  matt  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  1.1  matt  * All rights reserved.
      6  1.1  matt  *
      7  1.1  matt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  matt  * by Matt Thomas of 3am Software Foundry.
      9  1.1  matt  *
     10  1.1  matt  * Redistribution and use in source and binary forms, with or without
     11  1.1  matt  * modification, are permitted provided that the following conditions
     12  1.1  matt  * are met:
     13  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     14  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     15  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  matt  *    documentation and/or other materials provided with the distribution.
     18  1.1  matt  *
     19  1.1  matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  matt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  matt  */
     31  1.1  matt 
     32  1.1  matt #include <machine/asm.h>
     33  1.1  matt #include "assym.h"
     34  1.1  matt 
     35  1.1  matt /*
     36  1.1  matt  * C library -- _setjmp, _longjmp
     37  1.1  matt  *
     38  1.1  matt  *	_longjmp(a, v)
     39  1.1  matt  * will generate a "return v;" from the last call to
     40  1.1  matt  *	_setjmp(a)
     41  1.1  matt  * by restoring registers from the stack.
     42  1.1  matt  * The previous signal state is NOT restored.
     43  1.1  matt  *
     44  1.1  matt  * Note: x0 is the return value
     45  1.1  matt  */
     46  1.1  matt 	.section	.rodata.cst8,"aM",@progbits,8
     47  1.1  matt 	.align	3
     48  1.1  matt .L_MAGIC:
     49  1.1  matt 	.xword	_JB_MAGIC_AARCH64__SETJMP
     50  1.1  matt 
     51  1.1  matt ENTRY(_setjmp)
     52  1.1  matt 	adrp	x7, .L_MAGIC
     53  1.1  matt 	ldr	x7, [x7, #:lo12:.L_MAGIC]
     54  1.1  matt 
     55  1.1  matt 	mov	x3, sp
     56  1.1  matt 
     57  1.1  matt 	stp	x7, x3, [x0, #_JB_MAGIC]
     58  1.1  matt 
     59  1.1  matt 	stp	x19, x20, [x0, #_JB_X19]
     60  1.1  matt 	stp	x21, x22, [x0, #_JB_X21]
     61  1.1  matt 	stp	x23, x24, [x0, #_JB_X23]
     62  1.1  matt 	stp	x25, x26, [x0, #_JB_X25]
     63  1.1  matt 	stp	x27, x28, [x0, #_JB_X27]
     64  1.1  matt 	stp	x29, x30, [x0, #_JB_X29]
     65  1.1  matt 
     66  1.1  matt 	mrs	x5, tpidr_el0
     67  1.1  matt 	str	x5, [x0, #_JB_TPIDR]
     68  1.1  matt 
     69  1.1  matt 	stp	d8,  d9,  [x0, #_JB_D8]
     70  1.1  matt 	stp	d10, d11, [x0, #_JB_D10]
     71  1.1  matt 	stp	d12, d13, [x0, #_JB_D12]
     72  1.1  matt 	stp	d14, d15, [x0, #_JB_D14]
     73  1.1  matt 
     74  1.1  matt         mov	x0, xzr
     75  1.1  matt         ret
     76  1.1  matt END(_setjmp)
     77  1.1  matt 
     78  1.1  matt ENTRY(_longjmp)
     79  1.1  matt 	adrp	x7, .L_MAGIC
     80  1.1  matt 	ldr	x7, [x7, #:lo12:.L_MAGIC]
     81  1.1  matt 
     82  1.1  matt 	ldp	x2, x3, [x0, #_JB_MAGIC]
     83  1.1  matt 	ldp	x4, x5, [x0, #_JB_X29]
     84  1.1  matt 
     85  1.1  matt 	cbz	x3, .Lbotch
     86  1.1  matt 	cbz	x4, .Lbotch
     87  1.1  matt 	cbz	x5, .Lbotch
     88  1.1  matt 	cmp	x2, x7
     89  1.1  matt 	b.ne	.Lbotch
     90  1.1  matt 
     91  1.1  matt 	ldp	x19, x20, [x0, #_JB_X19]
     92  1.1  matt 	ldp	x21, x22, [x0, #_JB_X21]
     93  1.1  matt 	ldp	x23, x24, [x0, #_JB_X23]
     94  1.1  matt 	ldp	x25, x26, [x0, #_JB_X25]
     95  1.1  matt 	ldp	x27, x28, [x0, #_JB_X27]
     96  1.1  matt 
     97  1.1  matt 	ldr	x5, [x0, #_JB_TPIDR]
     98  1.1  matt 	msr	tpidr_el0, x5
     99  1.1  matt 
    100  1.1  matt 	ldp	d8,  d9,  [x0, #_JB_D8]
    101  1.1  matt 	ldp	d10, d11, [x0, #_JB_D10]
    102  1.1  matt 	ldp	d12, d13, [x0, #_JB_D12]
    103  1.1  matt 	ldp	d14, d15, [x0, #_JB_D14]
    104  1.1  matt 
    105  1.1  matt 	mov	sp, x3
    106  1.1  matt 	mov	x29, x4
    107  1.1  matt 	mov	x30, x5
    108  1.1  matt 
    109  1.1  matt         mov	x0, x1
    110  1.1  matt         ret
    111  1.1  matt 
    112  1.1  matt 	/* validation failed, die die die. */
    113  1.1  matt .Lbotch:
    114  1.1  matt 	bl	_C_LABEL(longjmperror)
    115  1.1  matt 	bl	_C_LABEL(abort)
    116  1.1  matt 1:	b	1b		/* Cannot get here */
    117  1.1  matt END(_longjmp)
    118