📄 crt0.c
字号:
/* $id:crt0.c V1.0 2001/11/13 */
/*******************************************************************************
* This source code has been made available to you by EPSON on an AS-IS
* basis. Anyone receiving this source is licensed under EPSON
* copyrights to use it in any way he or she deems fit, including
* copying it, modifying it, compiling it, and redistributing it either
* with or without modifications.
*
* Any person who transfers this source code or any derivative work
* must include the EPSON copyright notice, this paragraph, and the
* preceding two paragraphs in the transferred software.
*
* COPYRIGHT EPSON CORPORATION 2001
* LICENSED MATERIAL - PROGRAM PROPERTY OF EPSON
******************************************************************************/
/******************************************************************************
* File : crt0.c
* MODULE :
*
* PURPOSE :
*
* AUTHOR : Zhou Xiaohu
* GROUP : Kernel Group
* DATE CREATED : 2001/11/13
* REFERENCE DOCUMENT ID : Detailed Design of DDI
* MODIFICATION:
* DATE userName Description
* 2001/11/13 Zhou Xiaohu start
* 2001/12/04 Zhou Xiaohu add support to burn mode: copy data section and clear bss section
* 2001/12/04 Zhou Xiaohu support to copy CODE section, add preprosessor option
* 2001/12/10 Zhou Xiaohu codes rearrange
* 2001/12/17 Zhou Xiaohu RTL: 0x850000 ~ 0x87ffff
* 2001/12/18 Zhou Xiaohu implement _init_buc
*****************************************************************************/
/* for init lib */
#include <smcvals.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "int.h"
#include "bcu.h"
#include "idma.h"
#include "ct.h"
#include "io.h"
/********************************************************************************
* *
* for _init_lib *
* *
********************************************************************************/
//#define BURN
//#define FLASHBURN
//#define MOVEVECTOR
/* definition for all */
/* user main function */
extern void main(void);
/* exit */
void _exit(void);
void dummy(void);
/*******************************************************************************
* _init_bcu
* Type : void
* Ret val : none
* Argument : void
* Function : Initialize BCU.
*******************************************************************************/
void _init_bcu(void)
{
// [0x4812E] bus control register setting: BCLK output enable; Burst ROM burst length is 8;
// external interface method is #BSL system; #WAIT pin enable.
*(volatile unsigned short *)BCU_SWAITE_ADDR = BCU_RBCLK_ENA | BCU_RBST8_8 | BCU_SBUSST_BSL | BCU_SWAITE_DIS;
//*(volatile unsigned short *)BCU_SWAITE_ADDR = BCU_RBCLK_ENA | BCU_RBST8_8 | BCU_SBUSST_BSL | BCU_SWAITE_ENA;
// [0x48130] DRAM timing setup register setting: CEFUNC1 = '1' CEFUNC0 = 'x'.
*(volatile unsigned short *)BCU_RASC_ADDR = BCU_CEFUNC_COM;
// [48120] Areas 15-18 setup register setting: (15 and 16 )Device size 16 bits, Output disable delay 0.5, Wait control 2.
*(volatile unsigned short *)BCU_A15_A18_ADDR = BCU_SZH_16 | BCU_DFH_05 | BCU_WTH_1;
// [0x48122] Areas 13-14 setup register setting: device size 16 bits ,Output disable delay 2.5,Wait control 2.
*(volatile unsigned short *)BCU_A13_A14_ADDR = BCU_SZL_16 | BCU_DFL_25 | BCU_WTL_2;
// [0x48124] Areas 11-12( 0x1000000~0x17FFFFF; 0x1800000~1FFFFFF ) setup register setting: device size 16 bits ,Output disable delay 2.5,Wait control 2.
*(volatile unsigned short *)BCU_A11_A12_ADDR = BCU_SZL_8 | BCU_DFL_25 | BCU_WTL_2;
//*(volatile unsigned short *)BCU_A11_A12_ADDR = BCU_SZL_16 | BCU_DFL_05 | BCU_WTL_2;
// [0x48126] Area 9-10 setup register setting: device size 16 bits, output disable delay 0.5, wait control 2
*(volatile unsigned short *)BCU_A9_A10_ADDR = BCU_SZL_16 | BCU_DFL_15 | BCU_WTL_2;
// [0x48126] Area 9-10 setup register setting: device size 16 bits, output disable delay 0.5, wait control 2, area 9,10 use burst mode, burst wait cycle is 1
//*(volatile unsigned short *)BCU_A9_A10_ADDR = BCU_SZL_16 | BCU_DFL_25 | BCU_WTL_1 | BCU_BROH_USE | BCU_BROL_USE | BCU_BW_0;
// [0x48128] Area 7-8( 0x400000~0x5FFFFF; 0x600000~0x7FFFFF ) setup register setting: Device size 16 bits, output disable delay 3.5, wait control 7, DRAM is not used in area 8
*(volatile unsigned short *)BCU_A7_A8_ADDR = BCU_DRAH_NOT | BCU_DRAL_NOT | BCU_SZL_16 | BCU_DFL_05 | BCU_WTL_3;
// [0x4812A] Area 4-6 setup register setting: Device size 16 bits, output disable delay 3.5, wait control 7 in area 4,5,6
*(volatile unsigned short *)BCU_A4_A5_A6_ADDR = BCU_DFH_35 | BCU_WTH_7 | BCU_SZL_16 | BCU_DFL_35 | BCU_WTL_7;
// [4813A] BCLK select register setting: area1 access speed is 2 cycles when use x2speed mode, BCLK output PLL CLK
*(volatile unsigned short *)BCU_BCLKSEL_ADDR = BCU_BCLKSEL_OSC3 | BCU_A1X1MD;
/* to be continued */
}
/*******************************************************************************
* _init_int
* Type : void
* Ret val : none
* Argument : void
* Function : Initialize interrupt controller.
*******************************************************************************/
void _init_int(void)
{
/* Disable all interrupt enable register */
*(volatile unsigned char *)INT_EP0_EK_ADDR = INT_ENABLE_DIS;
*(volatile unsigned char *)INT_EHDM_EIDM_ADDR = INT_ENABLE_DIS;
*(volatile unsigned char *)INT_E16T0_E16T1_ADDR = INT_ENABLE_DIS;
*(volatile unsigned char *)INT_E16T2_E16T3_ADDR = INT_ENABLE_DIS;
*(volatile unsigned char *)INT_E16T4_E16T5_ADDR = INT_ENABLE_DIS;
*(volatile unsigned char *)INT_E8TU_ADDR = INT_ENABLE_DIS;
*(volatile unsigned char *)INT_ES_ADDR = INT_ENABLE_DIS;
*(volatile unsigned char *)INT_EADE_ECTM_EP4_ADDR = INT_ENABLE_DIS;
/* Reset all interrupt cause flag register (interrupt factor flag reset is read only mode) */
*(volatile unsigned char *)INT_FP0_FK_ADDR = INT_FLAG_RST;
*(volatile unsigned char *)INT_FHDM_FIDM_ADDR = INT_FLAG_RST;
*(volatile unsigned char *)INT_F16T0_F16T1_ADDR = INT_FLAG_RST;
*(volatile unsigned char *)INT_F16T2_F16T3_ADDR = INT_FLAG_RST;
*(volatile unsigned char *)INT_F16T4_F16T5_ADDR = INT_FLAG_RST;
*(volatile unsigned char *)INT_F8TU_ADDR = INT_FLAG_RST;
*(volatile unsigned char *)INT_FS_ADDR = INT_FLAG_RST;
*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR = INT_FLAG_RST;
/* Set all interrupt IDMA request register CPU request disable */
*(volatile unsigned char *)INT_RP0_RHDM_R16T0_ADDR = INT_RIDMA_DIS;
*(volatile unsigned char *)INT_R16T1_R16T4_ADDR = INT_RIDMA_DIS;
*(volatile unsigned char *)INT_R16T5_R8TU_RS0_ADDR = INT_RIDMA_DIS;
*(volatile unsigned char *)INT_RS1_RADE_RP4_ADDR = INT_RIDMA_DIS;
/* Set all IDMA disable */
*(volatile unsigned char *)IDMA_DEP0_DEHDM_DE16T0_ADDR = IDMA_DEIDMA_DIS;
*(volatile unsigned char *)IDMA_DE16T1_DE16T4_ADDR = IDMA_DEIDMA_DIS;
*(volatile unsigned char *)IDMA_DE16T5_DE8TU_DES0_ADDR = IDMA_DEIDMA_DIS;
*(volatile unsigned char *)IDMA_DES1_DEADE_DEP4_ADDR = IDMA_DEIDMA_DIS;
}
/*******************************************************************************
* FUNCTION : _init_tod
*
* PURPOSE : Init Time of Day
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return Value:
* Reentrant:
******************************************************************************/
void _init_tod(void)
{
/* Set clock timer interrupt disable on interrupt controller */
//*(volatile unsigned char *)INT_EADE_ECTM_EP4_ADDR = INT_ENABLE_DIS;
*(volatile unsigned char *)INT_EADE_ECTM_EP4_ADDR &= 0xfd; // zxh 2001-12-19
/* Stop clock timer */
*(volatile unsigned char *)CT_TCRUN_ADDR &= 0xfe;
/* Reset clock timer */
*(volatile unsigned char *)CT_TCRUN_ADDR |= CT_TCRST_RST;
/* Set clock timer data (1999.01.01 21:50) */
*(volatile unsigned char *)CT_TCHD_ADDR = 50;//0x32 // Minute data (5 minutes)
*(volatile unsigned char *)CT_TCDD_ADDR = 21;//0x15 // Hour data (21 hours)
*(volatile unsigned char *)CT_TCNDL_ADDR = 0xd7; // Year-month-day low byte data (3287 days)
*(volatile unsigned char *)CT_TCNDH_ADDR = 0x0c; // Year-month-day high byte data (3287 days)
/* Set clock timer interrupt factor control flag, 0x40152 */
*(volatile unsigned char *)CT_TCAF_ADDR = CT_TCISE_NONE | CT_TCASE_M | CT_TCIF_RST | CT_TCAF_RST;
/* Set clock timer interrupt priority level 3 on interrupt controller */
*(volatile unsigned char *)INT_PCTM_ADDR = INT_PRIL_LVL3;
/* Reset clock timer interrupt factor flag on interrupt controller */
*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR = INT_FCTM;
/* Set clock timer interrupt enable on interrupt controller */
//*(volatile unsigned char *)INT_EADE_ECTM_EP4_ADDR = INT_ECTM;
*(volatile unsigned char *)INT_EADE_ECTM_EP4_ADDR |= INT_ECTM; // zxh 2001-12-19
/* Run Clock Timer */
*(volatile unsigned char *)CT_TCRUN_ADDR |= 0x01;
}
/*******************************************************************************
* FUNCTION : boot
*
* PURPOSE : boot
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return Value:
* Reentrant:
******************************************************************************/
void boot(void)
{
/* Initialize Hardware */
asm("xld.w %r8,0x1fff"); /* Set SP in end of 8KB internal RAM */
asm("ld.w %sp,%r8");
asm("ld.w %r8,0b10000"); /* Set PSR to interrupt enable */
asm("ld.w %psr,%r8");
asm("xld.w %r8,0x0"); /* Set GPR is 0x0 */
_init_bcu(); /* Initialize BCU on boot time */
_init_int(); /* Initialize interrupt controller */
//_init_tod(); /* Initialize Time of Day */
main(); /* Call main */
_exit();
}
/*******************************************************************************
* FUNCTION : dummy
*
* PURPOSE :
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return Value:
* Reentrant:
******************************************************************************/
void dummy(void)
{
INT_LOOP:
goto INT_LOOP;
}
/*******************************************************************************
* FUNCTION : addr_err
*
* PURPOSE : Address Error Handler
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return Value:
* Reentrant:
******************************************************************************/
void add_err(void)
{
INT_LOOP:
goto INT_LOOP;
}
/*******************************************************************************
* FUNCTION : _exit
*
* PURPOSE :
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return Value:
* Reentrant:
******************************************************************************/
void _exit(void)
{
INT_LOOP:
goto INT_LOOP;
}
static void delay()
{
unsigned int iDelay;
for(iDelay=0;iDelay<50000;iDelay++)//38.4M 1 wite~=26200us
{
asm("nop");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -