; 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 (no init) ; ; Version 4.00 01 Nov 2006 ;------------------------------------- NAME @cstart 利用NAME 指令,声明此模块的名称为@cstart $INCLUDE (def.inc) $INCLUDE (macro.inc) ;----------------------------------------------------------------------------- ; declaration of symbol ; ; attention): change to EQU value 1 -> 0 if necessary ;----------------------------------------------------------------------------- $_IF(_STATIC) 编译器编译开关 FLOATSW EQU 0 ;floating point variables use $ELSE FLOATSW EQU 1 ;floating point variables use $ENDIF PUBLIC _@cstart,_@cend 定义两个符号(symbol) $_IF(FLOATSW) PUBLIC _errno 如果定义了 FLOATSW=1,则定义符号: _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 这些符号为函数 EXTRN _?R_INIT,_?R_INIS,_?DATA,_?DATS 此部分的符号为段的结尾地址 ;----------------------------------------------------------------------------- ; allocation area which library uses ; _errno errno number code ;----------------------------------------------------------------------------- $_IF(FLOATSW) @@DATA DSEG UNITP _errno: DS 2 $ENDIF @@VECT00 CSEG AT 0 将 CSEG段(ROM)地址为 0000H 的地方定义一个段, 名字为@@VECT00,并使用 DW指令将此处的值初始化为_@cstart DW _@cstart @@LCODE CSEG 在 CSEG段定义一个名字为@@LCODE 的段, 将下面的代码放置在这一区域 _@cstart: ;----------------------------------------------------------------------------- ; setting the register bank RB0 as work register set ;----------------------------------------------------------------------------- SEL RB0 选择寄存器组 0 ;----------------------------------------------------------------------------- ; setting the stack pointer ; ; _@STBEG is created by linker with -S option. ;----------------------------------------------------------------------------- 初始化堆栈指针,_@STBEG是编译器自动产生的 MOVW SP,#_@STBEG ;SP <- stack begin address 调用_hdwinit函数, CALL !_hdwinit ;----------------------------------------------------------------------------- ; errno are initialized to 0 ; ; The positive error number will be set by several libraries at called them. ;----------------------------------------------------------------------------- $_IF(FLOATSW) MOVW AX,#0 MOVW !_errno,AX ;errno <- 0 $ENDIF ;----------------------------------------------------------------------------- ; clear saddr ;----------------------------------------------------------------------------- MOVW HL,#0FE20H-1 MOV B,#0FEDFH-0FE20H+1 MOV A,#0 LSADR1: MOV [HL+B], A 在此处循环,以将 saddr区域清零 DBNZ B, $LSADR1 saddr:短寻址区,FE20~FF1F处 ;----------------------------------------------------------------------------- ; ROM data copy ;----------------------------------------------------------------------------- ; copy external variables having initial value 此部分程序,将有初值的变量,从ROM复制到 RAM(@@INIT 段)中, 有初值的变量放置在@@ R_INIT 段(位于ROM中), 开始地址为_@R_INIT,结束地址为_?R_INIT, RAM中,@@INIT 段的开始地址为_@INIT。 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: 此部分程序,将无初值的变量,初始化为 0。 RAM 的@@DATA 段用于存放无初值的变量, 开始地址为_@DATA,结束地址为_?DATA 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: 此部分程序将有初值的sreg型变量,从ROM复制到RAM (@@INIS段)。 ROM中的@@R_INIS 段用于存放有初值的 sreg型变量。 @@R_INIS 段的开始地址为_@R_INIS,结束地址为_?R_INIS, _@INIS 为@@INIS 段的开始地址 ; 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: 此部分程序用于初始化无初值的 sreg 型变量为 0。 RAM中的@@DATS 段用于放置无初值的 sreg 型变量, _@DATS 为其开始地址,_?DATS为其结束地址。 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(); 跳转到主函数 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