Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / mcs51 / crtbank.asm
1 ; /*-------------------------------------------------------------------------
2 ;
3 ;   crtbank.asm :- C run-time: bank switching
4 ;
5 ;    This library is free software; you can redistribute it and/or modify it
6 ;    under the terms of the GNU Library General Public License as published by the
7 ;    Free Software Foundation; either version 2, or (at your option) any
8 ;    later version.
9 ;
10 ;    This library is distributed in the hope that it will be useful,
11 ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ;    GNU Library General Public License for more details.
14 ;
15 ;    You should have received a copy of the GNU Library General Public License
16 ;    along with this program; if not, write to the Free Software
17 ;    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 ;
19 ;    In other words, you are welcome to use, share and improve this program.
20 ;    You are forbidden to forbid anyone else to use, share and improve
21 ;    what you give them.   Help stamp out software-hoarding!
22 ; -------------------------------------------------------------------------*/
23
24         .area HOME    (CODE)
25         .area GSINIT0 (CODE)
26         .area GSINIT1 (CODE)
27         .area GSINIT2 (CODE)
28         .area GSINIT3 (CODE)
29         .area GSINIT4 (CODE)
30         .area GSINIT5 (CODE)
31         .area GSINIT  (CODE)
32         .area GSFINAL (CODE)
33         .area CSEG    (CODE)
34
35 ; /*-------------------------------------------------------------------------
36 ;   Example for SiLabs C8051F12x / C8051F13x with 128kB code memory
37 ;   divided into 4 banks of 32kB
38 ;   These devices have an sfr called PSBANK containing two parts:
39 ;   COBANK (bit 5:4): Constant Operations Bank
40 ;   IFBANK (bit 1:0): Instruction Fetch Bank
41 ;   From 0x0000 to 0x7FFF bank 0 is always accessed
42 ;   From 0x8000 to 0xFFFF bank COBANK is accessed for reading with movc
43 ;   From 0x8000 to 0xFFFF bank IFBANK is accessed for executing instructions
44 ;
45 ;   Make your own copy of this file,
46 ;   adapt it to your situation,
47 ;   and compile/link it in your project
48 ; -------------------------------------------------------------------------*/
49
50         .globl _PSBANK
51
52         .area HOME    (CODE)
53
54 __sdcc_banked_call::
55         push    _PSBANK         ;save return bank
56         xch     a,r0            ;save Acc in r0, do not assume any register bank
57         push    acc             ;push LSB address
58         mov     a,r1
59         push    acc             ;push MSB address
60         mov     a,r2            ;get new bank
61         anl     a,#0x0F         ;remove storage class indicator
62         anl     _PSBANK,#0xF0
63         orl     _PSBANK,a       ;select bank
64         xch     a,r0            ;restore Acc
65         ret                     ;make the call
66
67 __sdcc_banked_ret::
68         pop     _PSBANK         ;restore bank
69         ret                     ;return to caller