/* This code is in the public domain. You may use, modify or distribute it freely. */ /* Yet another C startup routine for CC-RL compiler and RL78/G10 group */ #pragma inline_asm start void __near start(void) { //-------------------------------------------------- // setting the stack pointer //-------------------------------------------------- MOVW SP, #LOWW(__STACK_ADDR_START) //-------------------------------------------------- // hardware initialization (this code assumes ROM < 64K) //-------------------------------------------------- // hdwinit function here cannot use any global/static variables // because they are not initialized with zero nor data // and they will be initialized with zero or data #if 1 // you can set 0 if you want to call hdwinit in main function CALL !_hdwinit #endif //-------------------------------------------------- // RAM clear (this code assumes RAM size > 0) //-------------------------------------------------- CLRW AX MOVW BC, #LOWW(__RAM_ADDR_END - __RAM_ADDR_START) .L1_RAM: DECW BC MOV #LOWW(__RAM_ADDR_START)[BC], A CMPW AX, BC BNZ $.L1_RAM //-------------------------------------------------- // ROM data copy (this code assumes ROM < 64K) //-------------------------------------------------- #if 1 // you can set 0 if there are no variables having initial value MOV ES, A // A = 0 just after RAM clear is finished #if 1 // you can set 0 if there are no normal variables having initial value // copy external variables having initial value MOVW DE, #LOWW(STARTOF(.data)) MOVW HL, #LOWW(STARTOF(.dataR)) MOVW BC, #LOWW(STARTOF(.dataR) + SIZEOF(.dataR)) CALL !.romdatacopy #endif #if 1 // you can set 0 if there are no saddr variables having initial value // copy saddr variables having initial value MOVW DE, #LOWW(STARTOF(.sdata)) MOVW HL, #LOWW(STARTOF(.sdataR)) MOVW BC, #LOWW(STARTOF(.sdataR) + SIZEOF(.sdataR)) CALL !.romdatacopy #endif #endif //-------------------------------------------------- // call main function (this code assumes ROM < 64K) //-------------------------------------------------- //CALL !_main //.L1_EXIT: //BR $.L1_EXIT // main function never return (this reduces 4 bytes of stack usage) BR !_main //-------------------------------------------------- // romdatacopy (this code assumes ROM < 64K) //-------------------------------------------------- #if 1 // you can set 0 if there are no variables having initial value //MOV ES, #0 // ROM //MOVW DE, #LOWW(STARTOF(.xxx)) // ROM //MOVW HL, #LOWW(STARTOF(.xxxR)) // RAM //MOVW BC, #LOWW(STARTOF(.xxxR) + SIZEOF(.xxxR)) // RAM .L1_DATA: MOV A,ES:[DE] MOV [HL], A INCW DE INCW HL .romdatacopy: MOVW AX, BC CMPW AX, HL BNZ $.L1_DATA //RET is in the next line #endif } #if 0 // please set 1 when exit function is necessary void __near exit(void) { for (;;) {} } #endif