1/* A setjmp.c for Moxie
2   Copyright (C) 2009, 2019  Anthony Green
3
4   The authors hereby grant permission to use, copy, modify, distribute,
5   and license this software and its documentation for any purpose, provided
6   that existing copyright notices are retained in all copies and that this
7   notice is included verbatim in any distributions. No written agreement,
8   license, or royalty fee is required for any of the authorized uses.
9   Modifications to this software may be copyrighted by their authors
10   and need not follow the licensing terms described here, provided that
11   the new terms are clearly indicated on the first page of each file where
12   they apply.  */
13
14# setjmp/longjmp for moxie.  The jmpbuf looks like this:
15#
16# Register        jmpbuf offset
17#   $r6             0x00
18#   $r7             0x04
19#   $r8             0x08
20#   $r9             0x0c
21#   $r10            0x10
22#   $fp             0x14
23#   $sp             0x18
24#   stack frame fp  0x1c
25#   stack frame ra  0x20
26#   stack frame sc  0x25
27
28        .text
29        .global setjmp
30        .type   setjmp,@function
31setjmp:
32	st.l	($r0),     $r6
33	sto.l	0x04($r0), $r7
34	sto.l	0x08($r0), $r8
35	sto.l	0x0c($r0), $r9
36	sto.l	0x10($r0), $r10
37	sto.l	0x14($r0), $sp
38	sto.l	0x18($r0), $fp
39	ldo.l   $r1,       0x00($fp)
40	sto.l   0x1c($r0), $r1
41	ldo.l   $r1,       0x04($fp)
42	sto.l   0x20($r0), $r1
43	ldo.l   $r1,       0x08($fp)
44	sto.l   0x24($r0), $r1
45	xor	$r0, $r0
46	ret
47.Lend1:
48	.size	setjmp,.Lend1-setjmp
49
50	.global	longjmp
51	.type	longjmp,@function
52longjmp:
53	ldo.l	$r6, 0x00($r0)
54	ldo.l	$r7, 0x04($r0)
55	ldo.l	$r8, 0x08($r0)
56	ldo.l	$r9, 0x0c($r0)
57	ldo.l	$r10, 0x10($r0)
58	ldo.l	$sp, 0x14($r0)
59	ldo.l	$fp, 0x18($r0)
60	ldo.l   $r2, 0x1c($r0)
61	sto.l   0x0($fp), $r2
62	ldo.l   $r2, 0x20($r0)
63	sto.l   0x4($fp), $r2
64	ldo.l   $r2, 0x24($r0)
65	sto.l   0x8($fp), $r2
66	ldo.l	$r2, 0x08($r0)
67	mov	$r0, $r1
68	xor	$r2, $r2
69	cmp	$r0, $r2
70	beq	.Lreturn1
71	ret
72.Lreturn1:
73	inc     $r0, 1
74	ret
75.Lend2:
76	.size	longjmp,.Lend2-longjmp
77