?login_element?

Subversion Repositories NedoOS

Rev

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

  1. /*-------------------------------------------------------------------------
  2.    _gptrget.c - get 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. /* the  return value is expected to be in acc, and not in the standard
  41.  * location dpl. Therefore we choose return type void here: */
  42. #if defined DSDCC_MODEL_HUGE
  43. void
  44. _gptrget (char *gptr) __naked
  45. {
  46. /* This is the banked version with pointers up to 23 bits.
  47.    B cannot be trashed */
  48.  
  49.     gptr; /* hush the compiler */
  50.  
  51.     __asm
  52.     ;
  53.     ;   depending on the pointer type acc. to SDCCsymt.h
  54.     ;
  55.         jb      _B_7,codeptr$        ; >0x80 code       ; 3
  56.         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
  57.  
  58.         mov     dph,r0 ; save r0 independant of regbank ; 2
  59.         mov     r0,dpl ; use only low order address     ; 2
  60.  
  61.         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
  62.     ;
  63.     ;   Pointer to data space
  64.     ;
  65.         mov     a,@r0                                   ; 1
  66.  dataptrrestore$:
  67.         mov     r0,dph ; restore r0                     ; 2
  68.         mov     dph,#0 ; restore dph                    ; 2
  69.         ret                                             ; 1
  70.     ;
  71.     ;   pointer to external stack or pdata
  72.     ;
  73.  pdataptr$:
  74.         movx    a,@r0                                   ; 1
  75.         sjmp    dataptrrestore$                         ; 2
  76.     ;
  77.     ;   pointer to code area
  78.     ;
  79.  codeptr$:
  80.     ; implementation for SiLabs C8051F12x
  81.         mov     a,b                                     ; 2
  82.         anl     a,#0x03                                 ; 2
  83.         swap    a                                       ; 1
  84.         push    _PSBANK                                 ; 2
  85.         anl     _PSBANK,#0x0F                           ; 3
  86.         orl     _PSBANK,a                               ; 2
  87.  
  88.         clr     a                                       ; 1
  89.         movc    a,@a+dptr                               ; 1
  90.         pop     _PSBANK                                 ; 2
  91.         ret                                             ; 1
  92.     ;
  93.     ;   pointer to xternal data
  94.     ;
  95.  xdataptr$:
  96.     ; implementation for xram a16-a21 tied to P3
  97.         mov     _P3,b                                   ; 3
  98.  
  99.         movx    a,@dptr                                 ; 1
  100.         ret                                             ; 1
  101.                                                         ;===
  102.                                                         ;44 bytes
  103.      __endasm;
  104. }
  105.  
  106. #elif defined DSDCC_MODEL_MEDIUM
  107.  
  108. void
  109. _gptrget (char *gptr) __naked
  110. {
  111. /* This is the non-banked version with pointers up to 15 bits.
  112.    Assumes B is free to be used */
  113.  
  114.     gptr; /* hush the compiler */
  115.  
  116.     __asm
  117.     ;
  118.     ;   depending on the pointer type acc. to SDCCsymt.h
  119.     ;
  120.         mov     b,dph                                   ; 3
  121.         jb      _B_7,codeptr$        ; >0x80 code       ; 3
  122.         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
  123.  
  124.         mov     b,r0   ; save r0 independant of regbank ; 2
  125.         mov     r0,dpl ; use only low order address     ; 2
  126.  
  127.         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
  128.     ;
  129.     ;   Pointer to data space
  130.     ;
  131.         mov     a,@r0                                   ; 1
  132.         mov     r0,b   ; restore r0                     ; 2
  133.         ret                                             ; 1
  134.     ;
  135.     ;   pointer to xternal stack or pdata
  136.     ;
  137.  pdataptr$:
  138.         movx    a,@r0                                   ; 1
  139.         mov     r0,b   ; restore r0                     ; 2
  140.         ret                                             ; 1
  141.     ;
  142.     ;   pointer to code area, max 15 bits
  143.     ;
  144.  codeptr$:
  145.     ; 0x8000 <= dptr <= 0xFFFF
  146.     ; no need to AND dph and restore from B if hardware wraps code memory
  147.         anl     dph,#0x7F                               ; 3
  148.         clr     a                                       ; 1
  149.         movc    a,@a+dptr                               ; 1
  150.         mov     dph,b                                   ; 3
  151.         ret                                             ; 1
  152.     ;
  153.     ;   pointer to xternal data, max 14 bits
  154.     ;
  155.  xdataptr$:
  156.     ; 0 <= dptr <= 0x3FFF
  157.         movx    a,@dptr                                 ; 1
  158.         ret                                             ; 1
  159.                                                         ;===
  160.                                                         ;35 bytes
  161.      __endasm;
  162. }
  163.  
  164. #else
  165.  
  166. void
  167. _gptrget (char *gptr) __naked
  168. {
  169. /* This is the new version with pointers up to 16 bits.
  170.    B cannot be trashed */
  171.  
  172.     gptr; /* hush the compiler */
  173.  
  174.     __asm
  175.     ;
  176.     ;   depending on the pointer type acc. to SDCCsymt.h
  177.     ;
  178.         jb      _B_7,codeptr$        ; >0x80 code       ; 3
  179.         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
  180.  
  181.         mov     dph,r0 ; save r0 independant of regbank ; 2
  182.         mov     r0,dpl ; use only low order address     ; 2
  183.  
  184.         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
  185.     ;
  186.     ;   Pointer to data space
  187.     ;
  188.         mov     a,@r0                                   ; 1
  189.  dataptrrestore$:
  190.         mov     r0,dph ; restore r0                     ; 2
  191.         mov     dph,#0 ; restore dph                    ; 2
  192.         ret                                             ; 1
  193.     ;
  194.     ;   pointer to xternal stack or pdata
  195.     ;
  196.  pdataptr$:
  197.         movx    a,@r0                                   ; 1
  198.         sjmp    dataptrrestore$                         ; 2
  199.     ;
  200.     ;   pointer to code area, max 16 bits
  201.     ;
  202.  codeptr$:
  203.         clr     a                                       ; 1
  204.         movc    a,@a+dptr                               ; 1
  205.         ret                                             ; 1
  206.     ;
  207.     ;   pointer to xternal data, max 16 bits
  208.     ;
  209.  xdataptr$:
  210.         movx    a,@dptr                                 ; 1
  211.         ret                                             ; 1
  212.                                                         ;===
  213.                                                         ;27 bytes
  214.      __endasm;
  215. }
  216.  
  217. #endif
  218.  
  219. #ifdef __SDCC_ds390
  220. /* the  return value is expected to be in acc/acc1, and not in the standard
  221.  * location dpl/dph. Therefore we choose return type void here: */
  222.  
  223. void
  224. _gptrgetWord (unsigned *gptr)
  225. {
  226.     gptr; /* hush the compiler */
  227.  
  228.     __asm
  229.     ;
  230.     ;   depending on the pointer type acc. to SDCCsymt.h
  231.     ;
  232.         jb      _B_7,00003$           ; >0x80 code
  233.         jnb     _B_6,00002$           ; <0x40 far
  234.  
  235.         mov     dph,r0 ; save r0 independant of regbank
  236.         mov     r0,dpl ; use only low order address
  237.  
  238.         jb      _B_5,00004$           ; >0x60 pdata
  239.     ;
  240.     ;   Pointer to data space
  241.     ;
  242.         mov     acc1,@r0
  243.         inc     r0
  244.         mov     a,@r0
  245.         inc     dpl
  246.         sjmp    00005$
  247.     ;
  248.     ;   pointer to xternal data
  249.     ;
  250.  00002$:
  251.         movx    a,@dptr
  252.         mov     acc1,a
  253.         inc     dptr
  254.         movx    a,@dptr
  255.         sjmp    00006$
  256. ;
  257. ;   pointer to code area
  258. ;
  259.  00003$:
  260.         clr     a
  261.         movc    a,@a+dptr
  262.         mov     acc1,a
  263.         clr     a
  264.         inc     dptr
  265.         movc    a,@a+dptr
  266.         sjmp    00006$
  267. ;
  268. ;   pointer to xternal stack
  269. ;
  270.  00004$:
  271.         movx    a,@r0
  272.         mov     acc1,a
  273.         inc     r0
  274.         movx    a,@r0
  275.         inc     dpl
  276. ;
  277. ;   restore and return
  278. ;
  279.  00005$:
  280.         mov     r0,dph ; restore r0
  281.         mov     dph,#0 ; restore dph
  282.  00006$:
  283.         xch     a,acc1
  284.     __endasm;
  285.  
  286. }
  287.  
  288. #endif
  289.