1/*
2Copyright (c) 1990 The Regents of the University of California.
3All rights reserved.
4
5Redistribution and use in source and binary forms are permitted
6provided that the above copyright notice and this paragraph are
7duplicated in all such forms and that any documentation,
8and/or other materials related to such
9distribution and use acknowledge that the software was developed
10by the University of California, Berkeley.  The name of the
11University may not be used to endorse or promote products derived
12from this software without specific prior written permission.
13THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17#include <picolibc.h>
18
19# setjmp/longjmp for m32r.  The jmpbuf looks like this:
20#
21# Register	jmpbuf offset
22# reserved	0x00
23# R8		0x04
24# R9		0x08
25# R10		0x0c
26# R11		0x10
27# R12		0x14
28# R13 (FP)	0x18
29# R14 (LR)	0x1c
30# R15 (SP)	0x20
31# reserved	0x24
32
33	.text
34	.global	setjmp
35setjmp:
36	;addi	r0, #-4		; commented out as first word is reserved
37	;st	r1, @+r0
38	st	r8, @+r0
39	st	r9, @+r0
40	st	r10, @+r0
41	st	r11, @+r0
42	st	r12, @+r0
43	st	r13, @+r0
44	st	r14, @+r0
45	st	r15, @+r0
46
47# Return 0 to caller.
48	ldi	r0, #0
49	jmp	lr
50
51	.global	longjmp
52longjmp:
53	addi	r0, #4		; first word is reserved
54	;ld	r1, @r0+
55	ld	r8, @r0+
56	ld	r9, @r0+
57	ld	r10, @r0+
58	ld	r11, @r0+
59	ld	r12, @r0+
60	ld	r13, @r0+
61	ld	r2, @r0+	; return address
62	ld	r15, @r0+
63
64# If caller attempted to return 0, return 1 instead.
65
66	mv	r0, r1
67	bnez	r0, .Lnonzero
68	ldi	r0, #1
69.Lnonzero:
70	jmp	r2
71