File: setjmp.c

package info (click to toggle)
brickos 0.9.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,700 kB
  • ctags: 1,727
  • sloc: ansic: 9,139; cpp: 860; makefile: 717; asm: 693; sh: 123; perl: 61
file content (69 lines) | stat: -rw-r--r-- 2,109 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*! \file   setjmp.c
    \brief  Implementation: Non-local goto as described in ANSI C.
    \author Torsten Landschoff <tla@informatik.uni-kiel.de>
*/
    
/*
 *  The contents of this file are subject to the Mozilla Public License
 *  Version 1.0 (the "License"); you may not use this file except in
 *  compliance with the License. You may obtain a copy of the License at
 *  http://www.mozilla.org/MPL/
 *
 *  Software distributed under the License is distributed on an "AS IS"
 *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 *  License for the specific language governing rights and limitations
 *  under the License.
 *
 *  Contributor(s): Torsten Landschoff <tla@informatik.uni-kiel.de>
 */

#include <setjmp.h>

#ifdef CONF_SETJMP

int     setjmp(jmp_buf env);

#ifndef DOXYGEN_SHOULD_SKIP_THIS
__asm__("\n\
.text\n\
.align 2\n\
.globl _setjmp\n\
_setjmp:\n\
    stc     ccr,r1h         ; remember flags\n\
    mov.w   #12,r2          ; move r0 'behind' jump buffer\n\
    add	    r2,r0           ; for storing with pre-decrement\n\
\n\
    pop     r2              ; get return address\n\
    mov.w   r2,@-r0         ; store return address\n\
    mov.w   r1,@-r0         ; store flags\n\
    mov.w   r7,@-r0         ; store registers r4-r7\n\
    mov.w   r6,@-r0\n\
    mov.w   r5,@-r0\n\
    mov.w   r4,@-r0\n\
    sub.w   r0,r0           ; return value: 0\n\
    jmp     @r2             ; jump to caller\n\
	");
#endif // DOXYGEN_SHOULD_SKIP_THIS


void    longjmp(jmp_buf env, int val);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
__asm__("\n\
.text\n\
.align 2\n\
.globl _longjmp\n\
_longjmp:\n\
    mov.w   @r0+,r4         ; restore registers r4-r7\n\
    mov.w   @r0+,r5\n\
    mov.w   @r0+,r6\n\
    mov.w   @r0+,r7\n\
    mov.w   @r0+,r2         ; get flags\n\
    mov.w   @r0+,r0         ; get return address\n\
    push    r0              ; set up for rts\n\
    mov.w   r1,r0           ; return specified value\n\
    ldc     r2h,ccr         ; restore flags\n\
    rts                     ; return to caller\n\
	");
#endif // DOXYGEN_SHOULD_SKIP_THIS

#endif // CONF_SETJMP