From: Tormod Volden Date: Sat, 23 May 2015 18:07:30 +0000 (+0200) Subject: 6809: Implement setjmp/longjmp X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b6adf3ac59b1536c82ba29029631d657150353c9;p=FUZIX.git 6809: Implement setjmp/longjmp Signed-off-by: Tormod Volden --- diff --git a/Library/include/setjmp.h b/Library/include/setjmp.h index d240a752..a9fd7e10 100644 --- a/Library/include/setjmp.h +++ b/Library/include/setjmp.h @@ -7,9 +7,12 @@ /* FIXME: need to add alt registers */ typedef int jmp_buf[7]; -int __setjmp __P((jmp_buf env)); void longjmp __P((jmp_buf env, int rv)); - +#if defined(__SDCC_z80) || defined(__SDCC_z180) +int __setjmp __P((jmp_buf env)); #define setjmp(x) __setjmp(x) +#else +int setjmp __P((jmp_buf env)); +#endif #endif diff --git a/Library/libs/Makefile.6809 b/Library/libs/Makefile.6809 index b7cc75c3..a721a770 100644 --- a/Library/libs/Makefile.6809 +++ b/Library/libs/Makefile.6809 @@ -9,7 +9,7 @@ CC_NOOPT = $(CC_OPT) ASM_OPT = -o SRC_CRT0 = crt0_$(PLATFORM).s OBJ_CRT0 = $(SRC_CRT0:.s=.o) -SRC_ASM = +SRC_ASM = setjmp_6809.s OBJ_ASM = $(SRC_ASM:.s=.o) SRC_C = __argv.c abort.c asctime.c assert.c atexit.c SRC_C += bcmp.c bcopy.c bsearch.c bzero.c calloc.c cfree.c clock.c closedir.c @@ -27,7 +27,7 @@ SRC_C += localtim.c localtim_r.c lseek.c lsearch.c lstat.c ltoa.c ltostr.c SRC_C += malloc.c mkfifo.c mkstemps.c nanosleep.c opendir.c pause.c perror.c SRC_C += popen.c printf.c putenv.c putchar_wrapper.c putpwent.c pwent.c qsort.c SRC_C += raise.c rand.c readdir.c readlink.c realloc.c regerror.c -SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c setjmp.c +SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c SRC_C += stat.c stdio0.c stime.c SRC_C += strcasecmp.c strcasestr.c strdup.c stricmp.c strlcpy.c strncasecmp.c diff --git a/Library/libs/setjmp_6809.s b/Library/libs/setjmp_6809.s new file mode 100644 index 00000000..a0a53252 --- /dev/null +++ b/Library/libs/setjmp_6809.s @@ -0,0 +1,34 @@ +; setjmp / longjmp for 6809 FUZIX +; Copyright 2015 Tormod Volden + + ; exported + .globl _setjmp + .globl _longjmp + + .area .text + +; int setjmp(jmp_buf) +_setjmp: + ldd ,s ; return address + sty ,x++ + stu ,x++ + sts ,x++ + std ,x + ldx #0 + rts + +; void longjmp(jmp_buf, int) +_longjmp: + ; read back Y,U,S and return address + ldd 2,s ; second argument + bne @nz ; must not be 0 + incb +@nz ldy ,x++ + ldu ,x++ + lds ,x++ ; points to clobbered return address + ldx ,x + stx ,s ; restore return address + ; return given argument to setjmp caller + tfr d,x + rts +