1/* Copyright (c) 2013  Red Hat, Inc. All rights reserved.
2
3   This copyrighted material is made available to anyone wishing to use,
4   modify, copy, or redistribute it subject to the terms and conditions
5   of the BSD License.   This program is distributed in the hope that
6   it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7   including the implied warranties of MERCHANTABILITY or FITNESS FOR
8   A PARTICULAR PURPOSE.  A copy of this license is available at
9   http://www.opensource.org/licenses. Any Red Hat trademarks that are
10   incorporated in the source code or documentation are not subject to
11   the BSD License and may only be used or replicated with the express
12   permission of Red Hat, Inc.
13*/
14
15# setjmp/longjmp for msp430.  The jmpbuf looks like this:
16#
17# Register	Jmpbuf offset
18#               small   large
19# r0 (pc)	0x00     0x00
20# r1 (sp)	0x02	 0x04
21# r4		0x04	 0x08
22# r5		0x06	 0x0c
23# r6		0x08	 0x10
24# r7		0x0a	 0x14
25# r8		0x0c	 0x18
26# r9		0x0e	 0x1c
27# r10		0x10	 0x20
28
29	.text
30	.global	setjmp
31setjmp:
32	; Upon entry r12 points to the jump buffer.
33	; Returns 0 to caller.
34
35#if   defined __MSP430X_LARGE__
36	mova   @r1, r13
37	mova    r13, 0(r12)
38	mova	r1,  4(r12)
39	mova	r4,  8(r12)
40	mova	r5,  12(r12)
41	mova	r6,  16(r12)
42	mova	r7,  20(r12)
43	mova	r8,  24(r12)
44	mova	r9,  28(r12)
45	mova	r10, 32(r12)
46	clr   	r12
47	reta
48#else
49	;; Get the return address off the stack
50	mov.w  @r1,  r13
51	mov.w   r13, 0(r12)
52	mov.w	r1,  2(r12)
53	mov.w	r4,  4(r12)
54	mov.w	r5,  6(r12)
55	mov.w	r6,  8(r12)
56	mov.w	r7,  10(r12)
57	mov.w	r8,  12(r12)
58	mov.w	r9,  14(r12)
59	mov.w	r10, 16(r12)
60	clr   	r12
61	ret
62#endif
63	.size setjmp , . - setjmp
64
65
66	.global	longjmp
67longjmp:
68	; Upon entry r12 points to the jump buffer and
69        ; r13 contains the value to be returned by setjmp.
70
71#if   defined __MSP430X_LARGE__
72	mova	@r12+, r14
73	mova	@r12+, r1
74	mova	@r12+, r4
75	mova	@r12+, r5
76	mova	@r12+, r6
77	mova	@r12+, r7
78	mova	@r12+, r8
79	mova	@r12+, r9
80	mova	@r12+, r10
81#else
82	mov.w	@r12+, r14
83	mov.w	@r12+, r1
84	mov.w	@r12+, r4
85	mov.w	@r12+, r5
86	mov.w	@r12+, r6
87	mov.w	@r12+, r7
88	mov.w	@r12+, r8
89	mov.w	@r12+, r9
90	mov.w	@r12+, r10
91#endif
92	; If caller attempts to return 0, return 1 instead.
93	cmp.w   #0, r13
94	jne	.Lnot_zero
95	mov.w	#1, r13
96.Lnot_zero:
97	mov.w	r13, r12
98
99#if   defined __MSP430X_LARGE__
100	adda     #4, r1
101	mova	r14, r0
102#else
103	add.w    #2, r1
104	mov.w	r14, r0
105#endif
106	.size longjmp , . - longjmp
107
108