?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*-------------------------------------------------------------------------
  2.    _gptrput.c - put value for a generic pointer
  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. /* not all devices use P2 to page pdata memory, therefore __XPAGE was
  30.    introduced. On some targets __XPAGE itself is a paged SFR so it is
  31.    not safe for all platforms to set this. Furthermore some targets
  32.    can be configured to behave differently for movx @dptr vs. movx @Ri
  33.    (don't drive high byte of address bus for movx @Ri only) */
  34. #define USE_PDATA_PAGING_REGISTER 0
  35.  
  36. __sbit __at (0xF7) B_7;
  37. __sbit __at (0xF6) B_6;
  38. __sbit __at (0xF5) B_5;
  39.  
  40. #if defined DSDCC_MODEL_HUGE
  41. void
  42. _gptrput (char *gptr, char c) __naked
  43. {
  44. /* This is the banked version with pointers up to 22 bits.
  45.    B cannot be trashed */
  46.  
  47.     gptr; c; /* hush the compiler */
  48.  
  49.     __asm
  50.     ;
  51.     ;   depending on the pointer type according to SDCCsymt.h
  52.     ;
  53.         jb      _B_7,codeptr$        ; >0x80 code       ; 3
  54.         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
  55.  
  56.         mov     dph,r0 ; save r0 independant of regbank ; 2
  57.         mov     r0,dpl ; use only low order address     ; 2
  58.  
  59.         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
  60.     ;
  61.     ;   store into near/idata space
  62.     ;
  63.         mov     @r0,a                                   ; 1
  64.  dataptrrestore$:
  65.         mov     r0,dph ; restore r0                     ; 2
  66.         mov     dph,#0 ; restore dph                    ; 2
  67.         ret                                             ; 1
  68.     ;
  69.     ;   cannot store into code space, lock up
  70.     ;
  71.  codeptr$:
  72.         sjmp    .                                       ; 2
  73.     ;
  74.     ;   store into external stack/pdata space
  75.     ;
  76.  pdataptr$:
  77.         movx    @r0,a                                   ; 1
  78.         sjmp    dataptrrestore$                         ; 2
  79.     ;
  80.     ;   store into far space
  81.     ;
  82.  xdataptr$:
  83.         mov     _P3,b                                   ; 3
  84.  
  85.         movx    @dptr,a                                 ; 1
  86.         ret                                             ; 1
  87.  
  88.                                                         ;===
  89.                                                         ;29 bytes
  90.     __endasm;
  91. }
  92.  
  93. #elif defined DSDCC_MODEL_MEDIUM
  94.  
  95. void
  96. _gptrput (char *gptr, char c) __naked
  97. {
  98. /* This is the non-banked version with pointers up to 14 bits.
  99.    Assumes B is free to be used */
  100.  
  101.     gptr; c; /* hush the compiler */
  102.  
  103.     __asm
  104.     ;
  105.     ;   depending on the pointer type according to SDCCsymt.h
  106.     ;
  107.         mov     b,dph                                   ; 3
  108.         jb      _B_7,codeptr$        ; >0x80 code       ; 3
  109.         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
  110.  
  111.         mov     b,r0   ; save r0 independant of regbank ; 2
  112.         mov     r0,dpl ; use only low order address     ; 2
  113.  
  114.         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
  115.     ;
  116.     ;   store into near/idata space
  117.     ;
  118.         mov     @r0,a                                   ; 1
  119.  dataptrrestore$:
  120.         mov     r0,b   ; restore r0                     ; 2
  121.         ret                                             ; 1
  122.     ;
  123.     ;   cannot store into code space, lock up
  124.     ;
  125.  codeptr$:
  126.         sjmp    .                                       ; 2
  127.     ;
  128.     ;   store into external stack/pdata space
  129.     ;
  130.  pdataptr$:
  131.         movx    @r0,a                                   ; 1
  132.         sjmp    dataptrrestore$                         ; 2
  133.     ;
  134.     ;   store into far space, max 14 bits
  135.     ;
  136.  xdataptr$:
  137.     ; 0 <= dptr <= 0x3FFF
  138.         movx    @dptr,a                                 ; 1
  139.         ret                                             ; 1
  140.                                                         ;===
  141.                                                         ;27 bytes
  142.     __endasm;
  143. }
  144.  
  145. #else
  146.  
  147. void
  148. _gptrput (char *gptr, char c) __naked
  149. {
  150. /* This is the new version with pointers up to 16 bits.
  151.    B cannot be trashed */
  152.  
  153.     gptr; c; /* hush the compiler */
  154.  
  155.     __asm
  156.     ;
  157.     ;   depending on the pointer type according to SDCCsymt.h
  158.     ;
  159.         jb      _B_7,codeptr$        ; >0x80 code       ; 3
  160.         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
  161.  
  162.         mov     dph,r0 ; save r0 independant of regbank ; 2
  163.         mov     r0,dpl ; use only low order address     ; 2
  164.  
  165.         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
  166.     ;
  167.     ;   store into near/idata space
  168.     ;
  169.         mov     @r0,a                                   ; 1
  170.  dataptrrestore$:
  171.         mov     r0,dph ; restore r0                     ; 2
  172.         mov     dph,#0 ; restore dph                    ; 2
  173.         ret                                             ; 1
  174.     ;
  175.     ;   cannot store into code space, lock up
  176.     ;
  177.  codeptr$:
  178.         sjmp    .                                       ; 2
  179.     ;
  180.     ;   store into external stack/pdata space
  181.     ;
  182.  pdataptr$:
  183.         movx    @r0,a                                   ; 1
  184.         sjmp    dataptrrestore$                         ; 2
  185.     ;
  186.     ;   store into far space
  187.     ;
  188.  xdataptr$:
  189.         movx    @dptr,a                                 ; 1
  190.         ret                                             ; 1
  191.  
  192.                                                         ;===
  193.                                                         ;26 bytes
  194.     __endasm;
  195. }
  196.  
  197. #endif
  198.  
  199. #ifdef __SDCC_ds390
  200.  
  201. void
  202. _gptrputWord (int *gptr, int w) __naked
  203. {
  204. /* The ds390 can write two bytes in one go.
  205.    B cannot be trashed */
  206.  
  207.     gptr; w; /* hush the compiler */
  208.  
  209.     __asm
  210.     ;
  211.     ;   depending on the pointer type acc. to SDCCsymt.h
  212.     ;
  213.         jb      _B_7,codeptr_w$       ; >0x80 code
  214.         jnb     _B_6,xdataptr_w$      ; <0x40 far
  215.  
  216.         mov     dph,r0 ; save r0 independant of regbank
  217.         mov     r0,dpl ; use only low order address
  218.  
  219.         jb      _B_5,pdataptr_w$      ; >0x60 pdata
  220. ;
  221. ;       store into near space
  222. ;
  223.         mov     @r0,acc1
  224.         inc     r0
  225.         mov     @r0,a
  226.  dataptrrestore_w$:
  227.         mov     dpl,r0
  228.         mov     r0,dph ; restore r0
  229.         mov     dph,#0 ; restore dph
  230.         ret
  231.     ;
  232.     ;   cannot store into code space, lock up
  233.     ;
  234.  codeptr_w$:
  235.         sjmp    .
  236. ;
  237. ;       store into xstack space
  238. ;
  239.  pdataptr_w$:
  240.         xch     a,acc1
  241.         movx    @r0,a
  242.         inc     r0
  243.         xch     a,acc1
  244.         movx    @r0, a
  245.         sjmp    dataptrrestore_w$
  246. ;
  247. ;       store into far space
  248. ;
  249.  xdataptr_w$:
  250.         xch     a,acc1
  251.         movx    @dptr,a
  252.         inc     dptr
  253.         xch     a,acc1
  254.         movx    @dptr,a
  255.         ret
  256.     __endasm;
  257. }
  258.  
  259. #endif
  260.