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#include <picolibc.h> 16 17# setjmp/longjmp for msp430. The jmpbuf looks like this: 18# 19# Register Jmpbuf offset 20# small large 21# r0 (pc) 0x00 0x00 22# r1 (sp) 0x02 0x04 23# r4 0x04 0x08 24# r5 0x06 0x0c 25# r6 0x08 0x10 26# r7 0x0a 0x14 27# r8 0x0c 0x18 28# r9 0x0e 0x1c 29# r10 0x10 0x20 30 31 .text 32 .global setjmp 33setjmp: 34 ; Upon entry r12 points to the jump buffer. 35 ; Returns 0 to caller. 36 37#if defined __MSP430X_LARGE__ 38 mova @r1, r13 39 mova r13, 0(r12) 40 mova r1, 4(r12) 41 mova r4, 8(r12) 42 mova r5, 12(r12) 43 mova r6, 16(r12) 44 mova r7, 20(r12) 45 mova r8, 24(r12) 46 mova r9, 28(r12) 47 mova r10, 32(r12) 48 clr r12 49 reta 50#else 51 ;; Get the return address off the stack 52 mov.w @r1, r13 53 mov.w r13, 0(r12) 54 mov.w r1, 2(r12) 55 mov.w r4, 4(r12) 56 mov.w r5, 6(r12) 57 mov.w r6, 8(r12) 58 mov.w r7, 10(r12) 59 mov.w r8, 12(r12) 60 mov.w r9, 14(r12) 61 mov.w r10, 16(r12) 62 clr r12 63 ret 64#endif 65 .size setjmp , . - setjmp 66 67 68 .global longjmp 69longjmp: 70 ; Upon entry r12 points to the jump buffer and 71 ; r13 contains the value to be returned by setjmp. 72 73#if defined __MSP430X_LARGE__ 74 mova @r12+, r14 75 mova @r12+, r1 76 mova @r12+, r4 77 mova @r12+, r5 78 mova @r12+, r6 79 mova @r12+, r7 80 mova @r12+, r8 81 mova @r12+, r9 82 mova @r12+, r10 83#else 84 mov.w @r12+, r14 85 mov.w @r12+, r1 86 mov.w @r12+, r4 87 mov.w @r12+, r5 88 mov.w @r12+, r6 89 mov.w @r12+, r7 90 mov.w @r12+, r8 91 mov.w @r12+, r9 92 mov.w @r12+, r10 93#endif 94 ; If caller attempts to return 0, return 1 instead. 95 cmp.w #0, r13 96 jne .Lnot_zero 97 mov.w #1, r13 98.Lnot_zero: 99 mov.w r13, r12 100 101#if defined __MSP430X_LARGE__ 102 adda #4, r1 103 mova r14, r0 104#else 105 add.w #2, r1 106 mov.w r14, r0 107#endif 108 .size longjmp , . - longjmp 109 110