Merge branch 'dfsg-orig'
[debian/gnuradio] / usrp / firmware / src / common / _startup.a51.brittle
1 ;;; -*- asm -*-
2 ;;;
3 ;;; Copyright 2003 Free Software Foundation, Inc.
4 ;;; 
5 ;;; This file is part of GNU Radio
6 ;;; 
7 ;;; GNU Radio is free software; you can redistribute it and/or modify
8 ;;; it under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3, or (at your option)
10 ;;; any later version.
11 ;;; 
12 ;;; GNU Radio is distributed in the hope that it will be useful,
13 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;;; GNU General Public License for more details.
16 ;;; 
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Radio; see the file COPYING.  If not, write to
19 ;;; the Free Software Foundation, Inc., 51 Franklin Street,
20 ;;; Boston, MA 02110-1301, USA.
21
22     
23 ;;; The default external memory initialization provided by sdcc is not
24 ;;; appropriate to the FX2.  This is derived from the sdcc code, but uses 
25 ;;; the FX2 specific _MPAGE sfr.
26
27
28         .area XISEG   (XDATA)   ; the initialized external data area
29         .area XINIT   (CODE)    ; the code space consts to init XISEG
30         .area XSEG    (XDATA)   ; zero initialized xdata
31         .area USBDESCSEG (XDATA); usb descriptors
32
33         
34         ;; BIG TIME KLUDGE!
35         ;; Look at usrp_main.rst and count the bytes from our
36         ;; "normal return location" to the first instruction following
37         ;; the comment: "_mcs51_getRAMCLEAR () start"
38         
39         INSTRUCTION_BYTES_TO_SKIP = 0x29         ; valid for sdcc 2.4.0 
40         
41
42         .area CSEG    (CODE)
43
44         ;; sfr that sets upper address byte of MOVX using @r0 or @r1
45         _MPAGE  =       0x0092
46
47 __sdcc_external_startup::
48 ;       _mcs51_genXINIT() start
49         mov     r1,#l_XINIT
50         mov     a,r1
51         orl     a,#(l_XINIT >> 8)
52         jz      00003$
53         mov     r2,#((l_XINIT+255) >> 8)
54         mov     dptr,#s_XINIT
55         mov     r0,#s_XISEG
56         mov     _MPAGE,#(s_XISEG >> 8)
57 00001$: clr     a
58         movc    a,@a+dptr
59         movx    @r0,a
60         inc     dptr
61         inc     r0
62         cjne    r0,#0,00002$
63         inc     _MPAGE
64 00002$: djnz    r1,00001$
65         djnz    r2,00001$
66         mov     _MPAGE,#0xFF
67 00003$:
68
69         ;; Danger! Total KLUDGE!
70         ;; We pop the return address, add a magic number to it
71         ;; then jump to that address.  Believe it or not, this
72         ;; looks like the least kludgy way to handle this,
73         ;; short of patching the compiler...
74
75         pop     dph
76         pop     dpl
77         mov     a,#INSTRUCTION_BYTES_TO_SKIP
78         jmp     @a+dptr