Everything
8.3 コーディング例

スタートアップ・ルーチンの例を, 次に示します。

表 8.1

スタートアップ・ルーチンの例

; Copyright (C) 2014 Renesas Electronics Corporation
; RENESAS ELECTRONICS CONFIDENTIAL AND PROPRIETARY.
; This program must be used solely for the purpose for which
; it was furnished by Renesas Electronics Corporation. No part of this
; program may be reproduced or disclosed to others, in any
; form, without the prior written permission of Renesas Electronics
; Corporation.
 
; NOTE : THIS IS A TYPICAL EXAMPLE
 
        .public _start
        .public _exit
;-----------------------------------------------------------------------------
; RAM section
;-----------------------------------------------------------------------------
.SECTION        .dataR, DATA
.SECTION        .sdataR, DATA
 
;-----------------------------------------------------------------------------
; RESET vector
;-----------------------------------------------------------------------------
_start  .VECTOR 0
;-----------------------------------------------------------------------------
; startup
;-----------------------------------------------------------------------------
.SECTION        .text, TEXT
_start:
        ;--------------------------------------------------
        ; setting the stack pointer
        ;--------------------------------------------------
        MOVW    SP,#LOWW(__STACK_ADDR_START)
 
        ;--------------------------------------------------
        ; initializing stack area
        ;--------------------------------------------------
        MOVW    AX,#LOWW(__STACK_ADDR_END)
        CALL    !!_stkinit
 
        ;--------------------------------------------------
        ; hardware initialization
        ;--------------------------------------------------
        CALL    !!_hdwinit
$IFNDEF __USE_RAM_INIT_TABLE
 
        ;--------------------------------------------------
        ; initializing BSS
        ;--------------------------------------------------
        ; clear external variables which doesn't have initial value (near)
        MOVW    HL,#LOWW(STARTOF(.bss))
        MOVW    AX,#LOWW(STARTOF(.bss) + SIZEOF(.bss))
        BR      $.L2_BSS
.L1_BSS:
        MOV     [HL+0],#0
        INCW    HL
.L2_BSS:
        CMPW    AX,HL
        BNZ     $.L1_BSS
 
        ; clear saddr variables which doesn't have initial value
        MOVW    HL,#LOWW(STARTOF(.sbss))
        MOVW    AX,#LOWW(STARTOF(.sbss) + SIZEOF(.sbss))
        BR      $.L2_SBSS
.L1_SBSS:
        MOV     [HL+0],#0
        INCW    HL
.L2_SBSS:
        CMPW    AX,HL
        BNZ     $.L1_SBSS
 
        ;--------------------------------------------------
        ; ROM data copy
        ;--------------------------------------------------
        ; copy external variables having initial value (near)
        MOV     ES,#HIGHW(STARTOF(.data))
        MOVW    BC,#LOWW(SIZEOF(.data))
        BR      $.L2_DATA
.L1_DATA:
        DECW    BC
        MOV     A,ES:LOWW(STARTOF(.data))[BC]
        MOV     LOWW(STARTOF(.dataR))[BC],A
.L2_DATA:
        CLRW    AX
        CMPW    AX,BC
        BNZ     $.L1_DATA
        ; copy saddr variables having initial value
        MOV     ES,#HIGHW(STARTOF(.sdata))
        MOVW    BC,#LOWW(SIZEOF(.sdata))
        BR      $.L2_SDATA
.L1_SDATA:
        DECW    BC
        MOV     A,ES:LOWW(STARTOF(.sdata))[BC]
        MOV     LOWW(STARTOF(.sdataR))[BC],A
.L2_SDATA:
        CLRW    AX
        CMPW    AX,BC
        BNZ     $.L1_SDATA
 
$ELSE
        MOVW DE, #LOWW(STARTOF(.ram_init_table))
        MOV A, #LOW(HIGHW(STARTOF(.ram_init_table)))
        
        CALL $!_ram_init
 
$ENDIF
 
        ;--------------------------------------------------
        ; call main function
        ;--------------------------------------------------
        CALL    !!_main          ; main();
 
        ;--------------------------------------------------
        ; call exit function
        ;--------------------------------------------------
        CLRW    AX               ; exit(0);
_exit:
        BR      $_exit
 
$IFDEF __USE_RAM_INIT_TABLE
# A,DE: FAR ADDRESS
_ram_init:
        PUSH AX
        PUSH DE
        
.TABLE_LOOP:
        MOV A, [SP+0x03]
        MOV ES, A
        MOVW AX, [SP+0x00]
        MOVW DE, AX
        
        CLRB B
        
        # src_lo
        CALL $!.GET_RAM_INIT_RECORD
        PUSH AX
        
        # src_hi
        CALL $!.GET_RAM_INIT_RECORD
        PUSH AX
        
        # size
        CALL $!.GET_RAM_INIT_RECORD
        PUSH AX
        
        # dest
        CALL $!.GET_RAM_INIT_RECORD
        PUSH AX
        
        CMP0 B
        BZ $.RETURN
        
        MOVW AX, DE
        MOVW [SP+0x08], AX
        MOV A, ES
        MOV [SP+0x0B], A
        
        # dest
        POP DE
        # size
        POP BC
        # src_hi
        POP AX
        MOV A, X
        MOV ES, A
        # src_lo
        POP HL
        
        MOVW AX, DE
        CMPW AX, HL
        BNZ $.COPY
        MOV A, ES
        CMP A, #0xF
        BNZ $.COPY
        
.CLEAR:
        MOVW AX, BC
        OR A, X
        BZ $.TABLE_LOOP
        DECW BC
        CLRB A
        MOV [DE], A
        INCW DE
        BR $.CLEAR
        
.COPY:
        MOVW AX, BC
        OR A, X
        BZ $.TABLE_LOOP
        DECW BC
        MOV A, ES:[HL]
        MOV [DE], A
        INCW HL
        INCW DE
        BR $.COPY
        
.RETURN:
        ADDW SP, #0x0C
        RET
        
.GET_RAM_INIT_RECORD:
        MOVW AX, ES:[DE]
        MOVW HL, AX
        
        OR A, X
        OR B, A
        
        MOVW AX, DE
        ADDW AX, #0x0002
        MOVW DE, AX
        MOV A, ES
        ADDC A, #0
        MOV ES, A
        
        MOVW AX, HL
        RET
        
$ENDIF
 
;-----------------------------------------------------------------------------
; section
;-----------------------------------------------------------------------------
.SECTION .RLIB, TEXTF
.L_section_RLIB:
.SECTION .SLIB, TEXTF
.L_section_SLIB:
.SECTION .textf, TEXTF
.L_section_textf:
.SECTION .const, CONST           ; ミラー空間ありデバイスの場合のみ
.L_section_const:                ; ミラー空間ありデバイスの場合のみ
.SECTION .constf, CONSTF
.L_section_constf:
.SECTION .data, DATA
.L_section_data:
.SECTION .sdata, SDATA
.L_section_sdata:
.SECTION .bss, BSS
.L_section_bss:
.SECTION .sbss, SBSS
.L_section_sbss:
 

ミラー空間がないデバイス用のスタートアップは,const属性の記述はありません。【V1.02以降】