home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s270 / 1.ddi / PCKDD51B.EXE / A_CSTART.S03 < prev    next >
Encoding:
Text File  |  1991-01-15  |  3.9 KB  |  142 lines

  1. ;-----------------------------------------------------;
  2. ;                              ;
  3. ;            CSTARTUP.S03              ;
  4. ;                              ;
  5. ; This module contains the 8051 C startup-routine and ;
  6. ; must usually be tailored to suit customer hardware. ;
  7. ; Version: 2.00 [A.R. 10/Jun/87]              ;
  8. ;-----------------------------------------------------;
  9.     NAME    CSTARTUP
  10.  
  11.     LSTWID+            ; XXX -- to see INCLUDE files more easily
  12.  
  13. ;$DEFMM.INC        ; define memory model
  14. $\C51V2\DEFEM.INC    ; define memory model -- XXX Extended Memory Model
  15.  
  16.     PUBLIC    exit
  17.     EXTERN    _R    ; Register bank (0, 8, 16 or 24)
  18.     EXTERN    main
  19.  
  20. ;--------------------------------------------------------------;
  21. ; Virtual stack segment. It should be mapped into external RAM ;
  22. ;--------------------------------------------------------------;
  23.     IF    single_chip = 0
  24.  
  25.     RSEG    XSTACK
  26.     DS    512        ; Change if needed
  27. xstack_end:
  28.     ENDIF
  29.  
  30. ;--------------------------------------------------------------;
  31. ; Internal stack used for LCALL's and temporary storage for    ;
  32. ; code generator help-routines (math etc).  Stack can be loca- ;
  33. ; ted anywhere in the internal RAM with the exception of       ;
  34. ; _R - _R+7 that are reserved for R0-R7. Note that C interrupt ;
  35. ; routines require that you increase stack by 25 bytes to      ;
  36. ; assure that no overflows occur.                       ;
  37. ;--------------------------------------------------------------;
  38.     RSEG    ISTACK
  39. stack_begin:
  40.     IF    single_chip
  41.     DS    150
  42.     ELSE
  43.     DS    20
  44.     ENDIF
  45.  
  46.     RSEG    CSTART
  47. startup:            ; Should be at location zero
  48. ;    SJMP    init_C
  49.     LJMP    init_C        ; XXX -- I guess because increased size for
  50.                 ;        interrupt vectors
  51. ;    DS    20        ; Space for 8051 vectors
  52.     DS    256        ; Space for MCS-51 vectors -- XXX
  53.                 ; Note that highest interrupt vector address
  54.                 ; for 83C152 is 0x53 (83 decimal).  The value
  55.                 ; specified here should be chosen to allow for
  56.                 ; the processor with the highest interrupt
  57.                 ; vector address.
  58.                 ; 100 decimal == 0x064
  59.                 ; 128 decimal == 0x080
  60.                 ; 256 decimal == 0x100
  61. ;--------------------------------------------------------------;
  62. ; This is the place to insert interrupt vectors/handlers in.   ;
  63. ; For locations consult the Intel Microcontroller Handbook.    ;
  64. ;--------------------------------------------------------------;
  65.  
  66. init_C:
  67. ;---------------------------------------------------------------;
  68. ; Ativate the (at link-time) selected register bank.        ;
  69. ;---------------------------------------------------------------;
  70.  
  71.     MOV    A,#_R
  72.     MOV    C,ACC.3
  73.     MOV    PSW.3,C
  74.     MOV    C,ACC.4
  75.     MOV    PSW.4,C
  76.  
  77.     MOV    SP,#stack_begin    ; From low to high addresses
  78. ;--------------------------------------------------------------;
  79. ; If you don't want global/static C variables to be initial-   ;
  80. ; ized at startup you can just remove the next two lines.      ;
  81. ; NOTE: Never remove the call in the large models (-m0 or -m1) ;
  82. ;--------------------------------------------------------------;
  83.  
  84.     EXTERN    ?SEG_INIT_L17
  85.     LCALL    ?SEG_INIT_L17    ; Initialize segments
  86.  
  87. ;--------------------------------------------------------------;
  88. ; If hardware must be initiated from assembly or if interrupts ;
  89. ; should be on when reaching main, this is the place to insert ;
  90. ; such code.                               ;
  91. ;--------------------------------------------------------------;
  92.  
  93.     IF    single_chip
  94.  
  95.     MOV    R1,#0
  96.     LCALL    main        ; main()
  97. exit:                ; someone called exit()
  98.  
  99.     ELSE
  100.  
  101.     MOV    R6,#HIGH(xstack_end)
  102.     MOV    R7,#LOW(xstack_end)
  103.  
  104.     IF    banked_mode
  105.  
  106.     EXTERN    ?X_CALL_L18
  107.  
  108.     MOV    DPTR,#main
  109.     LCALL    ?X_CALL_L18        ; main()
  110.     DW    0            ; No parameter space
  111. local_exit:                ; someone called exit()
  112.  
  113.     ELSE
  114.  
  115.     MOV    DPTR,#0        ; No parameters
  116.  
  117.     LCALL    main        ; main()
  118. exit:                ; someone called exit()
  119.  
  120.     ENDIF
  121.  
  122.     ENDIF
  123.  
  124. ;--------------------------------------------------------------;
  125. ; Now when we are ready with our C program (usually 8051 C     ;
  126. ; programs are continouous) we must perform a system-dependent ;
  127. ; action.  In this simple case we just stop.               ;
  128. ;--------------------------------------------------------------;
  129.  
  130.     SJMP    $        ; Forever...
  131.  
  132.     IF    banked_mode
  133.  
  134.     RSEG    FLIST
  135. exit:
  136.     DD    local_exit
  137.  
  138.     ENDIF
  139.  
  140.     END    startup
  141.  
  142.