?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. /*-------------------------------------------------------------------------
  2.    setjmp.c - source file for ANSI routines setjmp & longjmp
  3.  
  4.    Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
  5.  
  6.    This library is free software; you can redistribute it and/or modify it
  7.    under the terms of the GNU General Public License as published by the
  8.    Free Software Foundation; either version 2, or (at your option) any
  9.    later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this library; see the file COPYING. If not, write to the
  18.    Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  19.    MA 02110-1301, USA.
  20.  
  21.    As a special exception, if you link this library with other files,
  22.    some of which are compiled with SDCC, to produce an executable,
  23.    this library does not by itself cause the resulting executable to
  24.    be covered by the GNU General Public License. This exception does
  25.    not however invalidate any other reasons why the executable file
  26.    might be covered by the GNU General Public License.
  27. -------------------------------------------------------------------------*/
  28.  
  29. #include <sdcc-lib.h>
  30. #define __SDCC_HIDE_LONGJMP
  31. #include <setjmp.h>
  32.  
  33. #if defined(__SDCC_ds390)
  34.  
  35. #include <ds80c390.h>
  36.  
  37. int __setjmp (jmp_buf buf)
  38. {
  39.     unsigned char sp, esp;
  40.     unsigned long lsp;
  41.  
  42.     /* registers would have been saved on the
  43.        stack anyway so we need to save SP
  44.        and the return address */
  45.     __critical {
  46.         sp = SP;
  47.         esp = ESP;
  48.     }
  49.     lsp = sp;
  50.     lsp |= (unsigned int)(esp << 8);
  51.     lsp |= 0x400000;
  52.     *buf++ = lsp;
  53.     *buf++ = lsp >> 8;
  54.     *buf++ = *((unsigned char __xdata *) lsp - 0);
  55.     *buf++ = *((unsigned char __xdata *) lsp - 1);
  56.     *buf++ = *((unsigned char __xdata *) lsp - 2);
  57.     return 0;
  58. }
  59.  
  60. int longjmp (jmp_buf buf, int rv)
  61. {
  62.     unsigned long lsp;
  63.  
  64.     lsp = *buf++;
  65.     lsp |= (unsigned int)(*buf++ << 8);
  66.     lsp |= 0x400000;
  67.     *((unsigned char __xdata *) lsp - 0) = *buf++;
  68.     *((unsigned char __xdata *) lsp - 1) = *buf++;
  69.     *((unsigned char __xdata *) lsp - 2) = *buf++;
  70.     __critical {
  71.         SP = lsp;
  72.         ESP = lsp >> 8;
  73.     }
  74.     return rv ? rv : 1;
  75. }
  76.  
  77. #elif defined(__SDCC_STACK_AUTO) && defined(__SDCC_USE_XSTACK)
  78.  
  79. static void dummy (void) __naked
  80. {
  81.         __asm
  82.  
  83. ;------------------------------------------------------------
  84. ;Allocation info for local variables in function 'setjmp'
  85. ;------------------------------------------------------------
  86. ;buf                       Allocated to registers dptr b
  87. ;------------------------------------------------------------
  88. ;../../device/lib/_setjmp.c:180:int setjmp (jmp_buf buf)
  89. ;       -----------------------------------------
  90. ;        function setjmp
  91. ;       -----------------------------------------
  92.         .globl ___setjmp
  93. ___setjmp:
  94.         ar2 = 0x02
  95.         ar3 = 0x03
  96.         ar4 = 0x04
  97.         ar5 = 0x05
  98.         ar6 = 0x06
  99.         ar7 = 0x07
  100.         ar0 = 0x00
  101.         ar1 = 0x01
  102. ;../../device/lib/_setjmp.c:183:*buf++ = bpx;
  103. ;     genPointerSet
  104. ;     genGenPointerSet
  105.         mov     a,_bpx
  106.         lcall   __gptrput
  107.         inc     dptr
  108. ;../../device/lib/_setjmp.c:184:*buf++ = spx;
  109. ;     genPointerSet
  110. ;     genGenPointerSet
  111.         mov     a,_spx
  112.         lcall   __gptrput
  113.         inc     dptr
  114. ;../../device/lib/_setjmp.c:185:*buf++ = bp;
  115. ;     genPointerSet
  116. ;     genGenPointerSet
  117.         mov     a,_bp
  118.         lcall   __gptrput
  119.         inc     dptr
  120. ;../../device/lib/_setjmp.c:186:*buf++ = SP;
  121. ;     genPointerSet
  122. ;     genGenPointerSet
  123.         mov     a,sp
  124.         lcall   __gptrput
  125.         inc     dptr
  126. ;../../device/lib/_setjmp.c:187:*buf++ = *((unsigned char __data *) SP  );
  127. ;     genCast
  128. ;     genPointerGet
  129. ;     genNearPointerGet
  130. ;     genPointerSet
  131. ;     genGenPointerSet
  132.         mov     r0,sp
  133.         mov     a,@r0
  134.         lcall   __gptrput
  135.         inc     dptr
  136. ;../../device/lib/_setjmp.c:188:*buf   = *((unsigned char __data *)SP - 1);
  137. ;     genCast
  138. ;     genMinus
  139. ;     genMinusDec
  140. ;       peephole 177.g  optimized mov sequence
  141.         dec     r0
  142. ;     genPointerGet
  143. ;     genNearPointerGet
  144.         mov     a,@r0
  145. ;     genPointerSet
  146. ;     genGenPointerSet
  147.         lcall   __gptrput
  148. #ifdef __SDCC_MODEL_HUGE
  149.         inc     dptr
  150. ;../../device/lib/_setjmp.c:189:*buf   = *((unsigned char __data *)SP - 2);
  151. ;     genCast
  152. ;     genMinus
  153. ;     genMinusDec
  154. ;       peephole 177.g  optimized mov sequence
  155.         dec     r0
  156. ;     genPointerGet
  157. ;     genNearPointerGet
  158.         mov     a,@r0
  159. ;     genPointerSet
  160. ;     genGenPointerSet
  161.         lcall   __gptrput
  162. #endif
  163. ;../../device/lib/_setjmp.c:190:return 0;
  164. ;     genRet
  165.         mov     dptr,#0x0000
  166.         _RETURN
  167.  
  168. ;------------------------------------------------------------
  169. ;Allocation info for local variables in function 'longjmp'
  170. ;------------------------------------------------------------
  171. ;rv                        Allocated to stack - offset -2
  172. ;buf                       Allocated to registers dptr b
  173. ;lsp                       Allocated to registers r5
  174. ;------------------------------------------------------------
  175. ;../../device/lib/_setjmp.c:192:int longjmp (jmp_buf buf, int rv)
  176. ;       -----------------------------------------
  177. ;        function longjmp
  178. ;       -----------------------------------------
  179.         .globl _longjmp
  180. _longjmp:
  181. ;     genReceive
  182.         mov     r0,_spx
  183.         dec     r0
  184.         movx    a,@r0
  185.         mov     r2,a
  186.         dec     r0
  187.         movx    a,@r0
  188.         mov     r3,a
  189. ;../../device/lib/_setjmp.c:193:bpx = *buf++;
  190. ;     genPointerGet
  191. ;     genGenPointerGet
  192.         lcall   __gptrget
  193.         mov     _bpx,a
  194.         inc     dptr
  195. ;../../device/lib/_setjmp.c:194:spx = *buf++;
  196. ;     genPointerGet
  197. ;     genGenPointerGet
  198.         lcall   __gptrget
  199.         mov     _spx,a
  200.         inc     dptr
  201. ;../../device/lib/_setjmp.c:195:bp = *buf++;
  202. ;     genPointerGet
  203. ;     genGenPointerGet
  204.         lcall   __gptrget
  205.         mov     _bp,a
  206.         inc     dptr
  207. ;../../device/lib/_setjmp.c:196:lsp = *buf++;
  208. ;     genPointerGet
  209. ;     genGenPointerGet
  210.         lcall   __gptrget
  211.         inc     dptr
  212. ;     genAssign
  213.         mov     r5,a
  214. ;../../device/lib/_setjmp.c:197:*((unsigned char __data *) lsp) = *buf++;
  215. ;     genCast
  216.         mov     r0,a
  217. ;     genPointerGet
  218. ;     genGenPointerGet
  219.         lcall   __gptrget
  220.         inc     dptr
  221. ;     genPointerSet
  222. ;     genNearPointerSet
  223.         mov     @r0,a
  224. ;../../device/lib/_setjmp.c:198:*((unsigned char __data *) lsp - 1) = *buf;
  225. ;     genMinus
  226. ;     genMinusDec
  227.         dec     r0
  228. ;     genPointerGet
  229. ;     genGenPointerGet
  230.         lcall   __gptrget
  231. ;     genPointerSet
  232. ;     genNearPointerSet
  233.         mov     @r0,a
  234. #ifdef __SDCC_MODEL_HUGE
  235.         inc     dptr
  236. ;../../device/lib/_setjmp.c:199:*((unsigned char __data *) lsp - 2) = *buf;
  237. ;     genMinus
  238. ;     genMinusDec
  239.         dec     r0
  240. ;     genPointerGet
  241. ;     genGenPointerGet
  242.         lcall   __gptrget
  243. ;     genPointerSet
  244. ;     genNearPointerSet
  245.         mov     @r0,a
  246. #endif
  247. ;../../device/lib/_setjmp.c:200:SP = lsp;
  248. ;     genAssign
  249.         mov     sp,r5
  250. ;../../device/lib/_setjmp.c:201:return rv ? rv : 1;
  251. ;     genAssign
  252.         mov     dph,r2
  253.         mov     dpl,r3
  254.         mov     a,r2
  255.         orl     a,r3
  256.         jnz     00001$
  257.         inc     dptr
  258. ;     genRet
  259. 00001$:
  260.         _RETURN
  261.  
  262.         __endasm;
  263. }
  264.  
  265. #elif defined(__SDCC_STACK_AUTO)
  266.  
  267. static void dummy (void) __naked
  268. {
  269.         __asm
  270.  
  271. ;------------------------------------------------------------
  272. ;Allocation info for local variables in function 'setjmp'
  273. ;------------------------------------------------------------
  274. ;buf                       Allocated to registers dptr b
  275. ;------------------------------------------------------------
  276. ;../../device/lib/_setjmp.c:122:int setjmp (unsigned char *buf)
  277. ;       -----------------------------------------
  278. ;        function setjmp
  279. ;       -----------------------------------------
  280.         .globl ___setjmp
  281. ___setjmp:
  282.         ar2 = 0x02
  283.         ar3 = 0x03
  284.         ar4 = 0x04
  285.         ar5 = 0x05
  286.         ar6 = 0x06
  287.         ar7 = 0x07
  288.         ar0 = 0x00
  289.         ar1 = 0x01
  290. ;     genReceive
  291. ;../../device/lib/_setjmp.c:125:*buf   = BP;
  292. ;     genPointerSet
  293. ;     genGenPointerSet
  294.         mov     a,_bp
  295.         lcall   __gptrput
  296.         inc     dptr
  297. ;../../device/lib/_setjmp.c:126:*buf   = SP;
  298. ;     genPointerSet
  299. ;     genGenPointerSet
  300.         mov     a,sp
  301.         lcall   __gptrput
  302.         inc     dptr
  303. ;../../device/lib/_setjmp.c:127:*buf++ = *((unsigned char __data *) SP  );
  304. ;     genCast
  305.         mov     r0,sp
  306. ;     genPointerGet
  307. ;     genNearPointerGet
  308.         mov     a,@r0
  309. ;     genPointerSet
  310. ;     genGenPointerSet
  311.         lcall   __gptrput
  312.         inc     dptr
  313. ;../../device/lib/_setjmp.c:128:*buf++ = *((unsigned char __data *)SP - 1);
  314. ;     genCast
  315. ;     genMinus
  316. ;     genMinusDec
  317.         dec     r0
  318. ;     genPointerGet
  319. ;     genNearPointerGet
  320.         mov     a,@r0
  321. ;     genPointerSet
  322. ;     genGenPointerSet
  323.         lcall   __gptrput
  324. #ifdef __SDCC_MODEL_HUGE
  325.         inc     dptr
  326. ;../../device/lib/_setjmp.c:129:*buf++ = *((unsigned char __data *)SP - 2);
  327. ;     genCast
  328. ;     genMinus
  329. ;     genMinusDec
  330.         dec     r0
  331. ;     genPointerGet
  332. ;     genNearPointerGet
  333.         mov     a,@r0
  334. ;     genPointerSet
  335. ;     genGenPointerSet
  336.         lcall   __gptrput
  337. #endif
  338. ;../../device/lib/_setjmp.c:130:return 0;
  339. ;     genRet
  340.         mov     dptr,#0x0000
  341.         _RETURN
  342.  
  343. ;------------------------------------------------------------
  344. ;Allocation info for local variables in function 'longjmp'
  345. ;------------------------------------------------------------
  346. ;rv                        Allocated to stack - offset -3
  347. ;buf                       Allocated to registers dptr b
  348. ;lsp                       Allocated to registers r5
  349. ;------------------------------------------------------------
  350. ;../../device/lib/_setjmp.c:28:int longjmp (jmp_buf buf, int rv)
  351. ;       -----------------------------------------
  352. ;        function longjmp
  353. ;       -----------------------------------------
  354.         .globl _longjmp
  355. _longjmp:
  356.         ar2 = 0x02
  357.         ar3 = 0x03
  358.         ar4 = 0x04
  359.         ar5 = 0x05
  360.         ar6 = 0x06
  361.         ar7 = 0x07
  362.         ar0 = 0x00
  363.         ar1 = 0x01
  364. ;     genReceive
  365.         mov     r0,sp
  366.         dec     r0
  367.         dec     r0
  368. #ifdef __SDCC_MODEL_HUGE
  369.         dec     r0
  370. #endif
  371.         mov     ar2,@r0
  372.         dec     r0
  373.         mov     ar3,@r0
  374. ;../../device/lib/_setjmp.c:30:bp = *buf++;
  375. ;     genPointerGet
  376. ;     genGenPointerGet
  377.         lcall   __gptrget
  378.         inc     dptr
  379. ;     genAssign
  380.         mov     _bp,a
  381. ;../../device/lib/_setjmp.c:31:lsp = *buf++;
  382. ;     genPointerGet
  383. ;     genGenPointerGet
  384.         lcall   __gptrget
  385.         inc     dptr
  386. ;     genAssign
  387.         mov     r5,a
  388. ;../../device/lib/_setjmp.c:32:*((unsigned char __data *) lsp) = *buf++;
  389. ;     genCast
  390.         mov     r0,a
  391. ;     genPointerGet
  392. ;     genGenPointerGet
  393.         lcall   __gptrget
  394.         inc     dptr
  395. ;     genPointerSet
  396. ;     genNearPointerSet
  397.         mov     @r0,a
  398. ;../../device/lib/_setjmp.c:33:*((unsigned char __data *) lsp - 1) = *buf;
  399. ;     genCast
  400. ;     genMinus
  401. ;     genMinusDec
  402.         dec     r0
  403. ;     genPointerGet
  404. ;     genGenPointerGet
  405.         lcall   __gptrget
  406. ;     genPointerSet
  407. ;     genNearPointerSet
  408.         mov     @r0,a
  409. #ifdef __SDCC_MODEL_HUGE
  410.         inc     dptr
  411. ;../../device/lib/_setjmp.c:34:*((unsigned char __data *) lsp - 2) = *buf;
  412. ;     genCast
  413. ;     genMinus
  414. ;     genMinusDec
  415.         dec     r0
  416. ;     genPointerGet
  417. ;     genGenPointerGet
  418.         lcall   __gptrget
  419. ;     genPointerSet
  420. ;     genNearPointerSet
  421.         mov     @r0,a
  422. #endif
  423. ;../../device/lib/_setjmp.c:35:SP = lsp;
  424. ;     genAssign
  425.         mov     sp,r5
  426. ;../../device/lib/_setjmp.c:36:return rv ? rv : 1;
  427. ;     genAssign
  428.         mov     dph,r2
  429.         mov     dpl,r3
  430.         mov     a,r2
  431.         orl     a,r3
  432.         jnz     00001$
  433.         inc     dptr
  434. ;     genRet
  435. 00001$:
  436.         _RETURN
  437.  
  438.         __endasm;
  439. }
  440.  
  441. #else
  442.  
  443. #include <8051.h>
  444.  
  445. extern unsigned char __data spx;
  446. extern unsigned char __data bpx;
  447.  
  448. int __setjmp (jmp_buf buf)
  449. {
  450.     /* registers would have been saved on the
  451.        stack anyway so we need to save SP
  452.        and the return address */
  453. #ifdef __SDCC_USE_XSTACK
  454.     *buf++ = spx;
  455.     *buf++ = bpx;
  456. #endif
  457.     *buf++ = SP;
  458.     *buf++ = *((unsigned char __data *) SP - 0);
  459.     *buf++ = *((unsigned char __data *) SP - 1);
  460. #ifdef __SDCC_MODEL_HUGE
  461.     *buf++ = *((unsigned char __data *) SP - 2);
  462. #endif
  463.     return 0;
  464. }
  465.  
  466. int longjmp (jmp_buf buf, int rv)
  467. {
  468.     unsigned char lsp;
  469.  
  470. #ifdef __SDCC_USE_XSTACK
  471.     spx = *buf++;
  472.     bpx = *buf++;
  473. #endif
  474.     lsp = *buf++;
  475.     *((unsigned char __data *) lsp - 0) = *buf++;
  476.     *((unsigned char __data *) lsp - 1) = *buf++;
  477. #ifdef __SDCC_MODEL_HUGE
  478.     *((unsigned char __data *) lsp - 2) = *buf++;
  479. #endif
  480.     SP = lsp;
  481.     return rv ? rv : 1;
  482. }
  483.  
  484. #endif
  485.