📄 cstart.asm
字号:
;*
;* $Id: cstart.asm,v 1.11 2007/09/11 05:18:25 sunny Exp $
;*
; Copyright (C) NEC Electronics Corporation 1990,2005
; NEC ELECTRONICS CONFIDENTIAL AND PROPRIETARY
; All rights reserved by NEC Electronics Corporation.
; This program must be used solely for the purpose for which
; it was furnished by NEC Electronics Corporation. No part of this
; program may be reproduced or disclosed to others, in any
; form, without the prior written permission of NEC Electronics
; Corporation. Use of copyright notice does not evidence
; publication of the program.
;-------------------------------------
; W-1 cstart
;
; Version 3.70 07 Feb 2005
;-------------------------------------
NAME @cstart
$INCLUDE (def.inc)
$INCLUDE (macro.inc)
;-----------------------------------------------------------------------------
; declaration of symbol
;
; attention): change to EQU value 1 -> 0 if necessary
;-----------------------------------------------------------------------------
;
BRKSW EQU 1 ;brk,sbrk,calloc,free,malloc,realloc function use
EXITSW EQU 1 ;exit,atexit function use
$_IF(_STATIC)
RANDSW EQU 0 ;rand,srand function use
DIVSW EQU 0 ;div function use
LDIVSW EQU 0 ;ldiv function use
FLOATSW EQU 0 ;floating point variables use
$ELSE
RANDSW EQU 1 ;rand,srand function use
DIVSW EQU 1 ;div function use
LDIVSW EQU 1 ;ldiv function use
FLOATSW EQU 1 ;floating point variables use
$ENDIF
STRTOKSW EQU 1 ;strtok function use
PUBLIC _@cstart,_@cend
$_IF(BRKSW)
PUBLIC _@BRKADR,_@MEMTOP,_@MEMBTM
$ENDIF
$_IF(EXITSW)
PUBLIC _@FNCTBL,_@FNCENT
$ENDIF
$_IF(RANDSW)
PUBLIC _@SEED
$ENDIF
$_IF(DIVSW)
PUBLIC _@DIVR
$ENDIF
$_IF(LDIVSW)
PUBLIC _@LDIVR
$ENDIF
$_IF(STRTOKSW)
PUBLIC _@TOKPTR
$ENDIF
$_IF(BRKSW OR FLOATSW)
PUBLIC _errno
$ENDIF
;-----------------------------------------------------------------------------
; external declaration of symbol for stack area
;
; _@STBEG has value of the end address +1 of compiler's stack area.
; _@STBEG is created by linker with -S option.
; Accordingly, specify the -S option when linking.
;-----------------------------------------------------------------------------
EXTRN _main,_@STBEG,_hdwinit
$_IF(EXITSW)
EXTRN _exit
$ENDIF
;-----------------------------------------------------------------------------
; external declaration of label for ROMable
;-----------------------------------------------------------------------------
EXTRN _?R_INIT,_?R_INIS,_?DATA,_?DATS
;-----------------------------------------------------------------------------
; allocation area which library uses
;
; _@FNCTBL top address of area used in atexit function
; _@FNCENT total number of functions registered by the atexit function
; _@SEED sequence of pseudo-random numbers
; _@DIVR a result of div library
; _@LDIVR a result of ldiv library
; _@TOKPTR pointer which strtok function uses
; _errno errno number code
; _@MEMTOP top address of area which memory management functions use
; _@MEMBTM bottom address of area which memory management functions use
; _@BRKADR break value
;-----------------------------------------------------------------------------
@@DATA DSEG UNITP
$_IF(EXITSW)
_@FNCTBL: DS 2*32
_@FNCENT: DS 2
$ENDIF
$_IF(RANDSW)
_@SEED: DS 4
$ENDIF
$_IF(DIVSW)
_@DIVR: DS 4
$ENDIF
$_IF(LDIVSW)
_@LDIVR: DS 8
$ENDIF
$_IF(STRTOKSW)
_@TOKPTR: DS 2
$ENDIF
$_IF(BRKSW OR FLOATSW)
_errno: DS 2
$ENDIF
$_IF(BRKSW)
_@BRKADR: DS 2
@@IXDATA DSEG UNITP
_@MEMTOP: DS MemPoolSize
_@MEMBTM:
$ENDIF
@@VECT00 CSEG AT 0
DW _@cstart
@@LCODE CSEG
_@cstart:
;-----------------------------------------------------------------------------
; setting the register bank RB0 as work register set
;-----------------------------------------------------------------------------
SEL RB0
;-----------------------------------------------------------------------------
; setting the stack pointer
;
; _@STBEG is created by linker with -S option.
;-----------------------------------------------------------------------------
MOVW SP,#_@STBEG ;SP <- stack begin address
CALL !_hdwinit
;-----------------------------------------------------------------------------
; errno and _@FNCENT are initialized to 0
;
; The positive error number will be set by several libraries at called them.
;-----------------------------------------------------------------------------
$_IF(BRKSW OR EXITSW OR RANDSW OR FLOATSW)
MOVW AX,#0
$ENDIF
$_IF(BRKSW OR FLOATSW)
MOVW !_errno,AX ;errno <- 0
$ENDIF
$_IF(EXITSW)
MOVW !_@FNCENT,AX ;FNCENT <- 0
$ENDIF
;-----------------------------------------------------------------------------
; initializing _@SEED as 1
;
; Pseudo-random sequence is decided by _@SEED value. This value can be set by
; srand function. If rand is called before srand, the random sequence will
; be the same as when srand is called with a _@SEED value as 1 at first.
;-----------------------------------------------------------------------------
$_IF(RANDSW)
MOVW !_@SEED+2,AX
INC X
MOVW !_@SEED,AX ;SEED <- 1
$ENDIF
;-----------------------------------------------------------------------------
; setting _@MEMTOP address to _@BRKADR
;-----------------------------------------------------------------------------
$_IF(BRKSW)
MOVW AX,#_@MEMTOP
MOVW !_@BRKADR,AX ;BRKADR <- #MEMTOP
$ENDIF
;-----------------------------------------------------------------------------
; clear saddr
;-----------------------------------------------------------------------------
MOVW HL,#0FE20H-1
MOV B,#0FEDFH-0FE20H+1
MOV A,#0
LSADR1:
MOV [HL+B], A
DBNZ B, $LSADR1
;-----------------------------------------------------------------------------
; ROM data copy
;-----------------------------------------------------------------------------
; copy external variables having initial value
MOVW HL,#_@R_INIT
MOVW DE,#_@INIT
LINIT1:
MOVW AX,HL
CMPW AX,#_?R_INIT
BZ $LINIT2
MOV A,[HL]
MOV [DE],A
INCW HL
INCW DE
BR $LINIT1
LINIT2:
MOVW HL,#_@DATA
; copy external variables which doesn't have initial value
LDATA1:
MOVW AX,HL
CMPW AX,#_?DATA
BZ $LDATA2
MOV A,#0
MOV [HL],A
INCW HL
BR $LDATA1
LDATA2:
; copy sreg variables having initial value
MOVW HL,#_@R_INIS
MOVW DE,#_@INIS
LINIS1:
MOVW AX,HL
CMPW AX,#_?R_INIS
BZ $LINIS2
MOV A,[HL]
MOV [DE],A
INCW HL
INCW DE
BR $LINIS1
LINIS2:
MOVW HL,#_@DATS
; copy sreg variables which doesn't have initial value
LDATS1:
MOVW AX,HL
CMPW AX,#_?DATS
BZ $LDATS2
MOV A,#0
MOV [HL],A
INCW HL
BR $LDATS1
LDATS2:
;-----------------------------------------------------------------------------
; call main function
;-----------------------------------------------------------------------------
CALL !_main ;main();
;-----------------------------------------------------------------------------
; call exit function
;-----------------------------------------------------------------------------
$_IF(EXITSW)
MOVW AX,#0
CALL !_exit ;exit(0);
$ENDIF
BR $$
;
_@cend:
;-----------------------------------------------------------------------------
; define segment and label used by ROMable processing
;-----------------------------------------------------------------------------
@@R_INIT CSEG UNITP
_@R_INIT:
@@R_INIS CSEG UNITP
_@R_INIS:
@@INIT DSEG UNITP
_@INIT:
@@DATA DSEG UNITP
_@DATA:
@@INIS DSEG SADDRP
_@INIS:
@@DATS DSEG SADDRP
_@DATS:
@@CALT CSEG CALLT0
@@CALF CSEG FIXED
@@CNST CSEG UNITP
@@BITS BSEG
;
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -