8.3 コーディング例

boot.asm,cstart.asmの例を次に示します。

boot.asm

    ; if using eiint as table reference method,
    ; enable next line's macro.
 
    ;USE_TABLE_REFERENCE_METHOD .set 1
 
;-----------------------------------------------------------------------------
;   exception vector table
;-----------------------------------------------------------------------------
    .section "RESET_PE1", text
    .align   512
    jr32     __start   ; RESET
 
    .align   16
    jr32     _Dummy    ; SYSERR
 
    .align   16
    jr32     _Dummy
 
    .align   16
    jr32     _Dummy    ; FETRAP
 
    .align   16
    jr32     _Dummy_EI ; TRAP0
 
    .align   16
    jr32     _Dummy_EI ; TRAP1
 
    .align   16
    jr32     _Dummy    ; RIE
 
    .align   16
    jr32     _Dummy_EI ; FPP/FPI
 
    .align   16
    jr32     _Dummy    ; UCPOP
 
    .align   16
    jr32     _Dummy    ; MIP/MDP
 
    .align   16
    jr32     _Dummy    ; PIE
 
    .align   16
    jr32     _Dummy
 
    .align   16
    jr32     _Dummy    ; MAE
 
    .align   16
    jr32     _Dummy
 
    .align   16
    jr32     _Dummy    ; FENMI
 
    .align   16
    jr32     _Dummy    ; FEINT
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority0)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority1)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority2)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority3)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority4)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority5)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority6)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority7)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority8)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority9)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority10)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority11)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority12)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority13)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority14)
 
    .align   16
    jr32     _Dummy_EI ; INTn(priority15)
 
    .section "EIINTTBL_PE1", const
    .align   512
    .dw      #_Dummy_EI ; INT0
    .dw      #_Dummy_EI ; INT1
    .dw      #_Dummy_EI ; INT2
    .rept    512 - 3
    .dw      #_Dummy_EI ; INTn
    .endm
 
    .section ".text", text
    .align   2
_Dummy:
    br       _Dummy
 
_Dummy_EI:
    br       _Dummy_EI
 
;-----------------------------------------------------------------------------
;   startup
;-----------------------------------------------------------------------------
    .section ".text", text
    .align   2
    .public  __start
__start:
$if 1    ; initialize register
    $nowarning
    mov      r0, r1
    $warning
    mov      r0, r2
    mov      r0, r3
    mov      r0, r4
    mov      r0, r5
    mov      r0, r6
    mov      r0, r7
    mov      r0, r8
    mov      r0, r9
    mov      r0, r10
    mov      r0, r11
    mov      r0, r12
    mov      r0, r13
    mov      r0, r14
    mov      r0, r15
    mov      r0, r16
    mov      r0, r17
    mov      r0, r18
    mov      r0, r19
    mov      r0, r20
    mov      r0, r21
    mov      r0, r22
    mov      r0, r23
    mov      r0, r24
    mov      r0, r25
    mov      r0, r26
    mov      r0, r27
    mov      r0, r28
    mov      r0, r29
    mov      r0, r30
    mov      r0, r31
    ldsr     r0, 0, 0       ;  EIPC
    ldsr     r0, 16, 0      ;  CTPC
$endif
 
$if 1
    ; jump to entry point of each PE
    stsr     0, r10, 2      ; get HTCFG0
    shr      16, r10        ; get PEID
 
    cmp      1, r10
    bz       .L.entry_PE1
    cmp      2, r10
    bz       .L.entry_PE2
    cmp      3, r10
    bz       .L.entry_PE3
    cmp      4, r10
    bz       .L.entry_PE4
    cmp      5, r10
    bz       .L.entry_PE5
    cmp      6, r10
    bz       .L.entry_PE6
    cmp      7, r10
    bz       .L.entry_PE7
__exit:
    br       __exit
 
.L.entry_PE1:
    jarl     _hdwinit_PE1, lp ; initialize hardware
$ifdef USE_TABLE_REFERENCE_METHOD
    mov       #__sEIINTTBL_PE1, r6
    jarl      _set_table_reference_method, lp ; set table reference method
$endif
 
    jr32      __cstart_pm1
 
.L.entry_PE2:
    jarl      _hdwinit_PE2, lp ; initialize hardware
;$ifdef USE_TABLE_REFERENCE_METHOD
;   mov       #__sEIINTTBL_PE2, r6
;   jarl      _set_table_reference_method, lp ; set table reference method
;$endif
;   jr32      __cstart_pm2
    br        __exit
 
.L.entry_PE3:
    br        __exit
.L.entry_PE4:
    br        __exit
.L.entry_PE5:
    br        __exit
.L.entry_PE6:
    br        __exit
.L.entry_PE7:
    br        __exit
$endif
 
;-----------------------------------------------------------------------------
; hdwinit_PE1
; Specify RAM addresses suitable to your system if needed.
;-----------------------------------------------------------------------------
    GLOBAL_RAM_ADDR     .set    0
    GLOBAL_RAM_END      .set    0
    LOCAL_RAM_PE1_ADDR  .set    0
    LOCAL_RAM_PE1_END   .set    0
 
    .align    2
_hdwinit_PE1:
    mov       lp, r29           ; save return address
 
    ; clear Global RAM
    mov       GLOBAL_RAM_ADDR, r6
    mov       GLOBAL_RAM_END, r7
    jarl      _zeroclr4, lp
 
    ; clear Local RAM PE1
    mov       LOCAL_RAM_PE1_ADDR, r6
    mov       LOCAL_RAM_PE1_END, r7
    jarl      _zeroclr4, lp
 
    mov       r29, lp
    jmp       [lp]
 
;-----------------------------------------------------------------------------
; hdwinit_PE2
; Specify RAM addresses suitable to your system if needed.
;-----------------------------------------------------------------------------
    LOCAL_RAM_PE2_ADDR  .set    0
    LOCAL_RAM_PE2_END   .set    0
 
    .align    2
_hdwinit_PE2:
    mov       lp, r14           ; save return address
 
    ; clear Local RAM PE2
    mov       LOCAL_RAM_PE2_ADDR, r6
    mov       LOCAL_RAM_PE2_END, r7
    jarl      _zeroclr4, lp
 
    mov       r14, lp
    jmp       [lp]
 
;-----------------------------------------------------------------------------
;   zeroclr4
;-----------------------------------------------------------------------------
    .align    2
_zeroclr4:
    br        .L.zeroclr4.2
.L.zeroclr4.1:
    st.w      r0, [r6]
    add       4, r6
.L.zeroclr4.2:
    cmp       r6, r7
    bh        .L.zeroclr4.1
    jmp       [lp]
 
$ifdef USE_TABLE_REFERENCE_METHOD
;-----------------------------------------------------------------------------
;   set table reference method
;-----------------------------------------------------------------------------
    ; interrupt control register address
    ICBASE    .set 0xfffeea00
 
    .align    2
_set_table_reference_method:
    ldsr      r6, 4, 1      ; set INTBP
 
    ; Some interrupt channels use the table reference method.
    mov       ICBASE, r10   ; get interrupt control register address
    set1      6, 0[r10]     ; set INT0 as table reference
    set1      6, 2[r10]     ; set INT1 as table reference
    set1      6, 4[r10]     ; set INT2 as table reference
 
    jmp       [lp]
$endif
;-------------------- end of start up module -------------------;

 

cstart.asm

;-----------------------------------------------------------------------------
;   system stack
;-----------------------------------------------------------------------------
STACKSIZE    .set    0x200
    .section ".stack.bss", bss
    .align   4
    .ds      (STACKSIZE)
    .align   4
_stacktop:
 
;-----------------------------------------------------------------------------
;   section initialize table
;-----------------------------------------------------------------------------
    .section ".INIT_DSEC.const", const
    .align   4
    .dw      #__s.data, #__e.data, #__s.data.R
 
    .section ".INIT_BSEC.const", const
    .align   4
    .dw      #__s.bss, #__e.bss
 
;-----------------------------------------------------------------------------
;   startup
;-----------------------------------------------------------------------------
    .section ".text.cmn", text
    .public  __cstart_pm1
    .align   2
__cstart_pm1:
    mov      #_stacktop, sp     ;  set sp register
    mov      #__gp_data, gp     ;  set gp register
    mov      #__ep_data, ep     ;  set ep register
 
    mov      #__s.INIT_DSEC.const, r6
    mov      #__e.INIT_DSEC.const, r7
    mov      #__s.INIT_BSEC.const, r8
    mov      #__e.INIT_BSEC.const, r9
    jarl32   __INITSCT_RH, lp   ;  initialize RAM area
 
    ; set various flags to PSW via FEPSW
 
    stsr     5, r10, 0          ; r10 <- PSW
 
    movhi    0x0001, r0, r11
    or       r11, r10
    ldsr     r10, 5, 0          ; enable FPU
 
    movhi    0x0002, r0, r11
    ldsr     r11, 6, 0          ; initialize FPSR
    ldsr     r0, 7, 0           ; initialize FPEPC
 
    stsr     5, r10, 0          ; r10 <- PSW
 
    ;xori    0x0020, r10, r10   ; enable interrupt
 
    ;movhi   0x4000, r0, r11
    ;or      r11, r10           ; supervisor mode -> user mode
 
    ldsr     r10, 3, 0          ; FEPSW <- r10
 
    mov      #_exit, lp         ; lp <- #_exit
    mov      #_main, r10
    ldsr     r10, 2, 0          ; FEPC <- #_main
 
    ; apply PSW and PC to start user mode
    feret
 
_exit:
    br       _exit              ;  end of program
 
;-----------------------------------------------------------------------------
;   dummy section
;-----------------------------------------------------------------------------
    .section    ".data", data
.L.dummy.data:
    .section    ".bss", bss
.L.dummy.bss:
    .section    ".const", const
.L.dummy.const:
    .section    ".text", text
.L.dummy.text:
;-------------------- end of start up module -------------------;