]> git.sur5r.net Git - cc65/blob - libsrc/common/longjmp.s
Merge remote-tracking branch 'irgendwer/AtariOS_Structure' into master
[cc65] / libsrc / common / longjmp.s
1 ;
2 ; 1998-06-06, Ullrich von Bassewitz
3 ; 2015-09-11, Greg King
4 ;
5 ; void __fastcall__ longjmp (jmp_buf buf, int retval);
6 ;
7
8         .export         _longjmp
9         .import         popptr1
10         .importzp       sp, ptr1, ptr2
11
12 _longjmp:
13         sta     ptr2            ; Save retval
14         stx     ptr2+1
15         ora     ptr2+1          ; Check for 0
16         bne     @L1
17         inc     ptr2            ; 0 is illegal, according to the standard ...
18                                 ; ... and, must be replaced by 1
19 @L1:    jsr     popptr1         ; get buf
20         ; ldy     #0            is guaranteed by popptr1
21
22 ; Get the old parameter stack
23
24         lda     (ptr1),y
25         iny
26         sta     sp
27         lda     (ptr1),y
28         iny
29         sta     sp+1
30
31 ; Get the old stack pointer
32
33         lda     (ptr1),y
34         iny
35         tax
36         txs
37
38 ; Get the return address and push it on the stack
39
40         lda     (ptr1),y
41         iny
42         pha
43         lda     (ptr1),y
44         pha
45
46 ; Load the return value and return to the caller
47
48         lda     ptr2
49         ldx     ptr2+1
50         rts