📄 bootmain.asm
字号:
*********************************************************************************
* UART.ASM v1.00 *
* 版权(c) 2003- 北京合众达电子技术有限责任公司 *
* 设计者: 段立锋 *
*********************************************************************************
.copy "vc54x.inc" ; VC5402 Memory-Mapped Register Declaration
.copy "dec5416.inc" ; SEED DEC5416 Memory-Mapped Register Declaratio
.mmregs
.global _bootmain
.ref IV_RESET
.ref _c_int00
****************************************************************************
* I/O空间: 插2×2个等待 ? *
* 数据空间低32K: 插2×2个等待 ? *
* 数据空间高32K: 插5×2个等待 ? *
* 程序空间低512K:?插2×2个等待 ? *
* 程序空间高512K: 插5×2个等待 ? *
****************************************************************************
SWWSR_VAL .set 0ffffH
SWCR_VAL .set 0001H ; 等待×2
STACK_SIZE .set 0100H ; 堆栈长度为256字
OVLY_0 .set 005FH ; OVLY = '0'
PLLX2 .set 01007H
PLLX5 .set 06007H
****************************************************************************
* Declare the stack. Size is determined by the linker option -stack. The *
* default value is 256 words. *
****************************************************************************
stack: .usect ".stack",0 ; set the stack memory
.sect ".bootloader"
_bootmain:
****************************************************************************
* INIT STACK POINTER. REMEMBER STACK GROWS FROM HIGH TO LOW ADDRESSES. *
****************************************************************************
STM #stack,SP ; set to beginning of stack memory
ADDM #(STACK_SIZE-1),*(SP) ; add size to get to top
ANDM #0fffeh,*(SP) ; make sure it is an even address
RSBX SXM ; turn on SXM for LD #cinit,A
****************************************************************************
* 中断向量表重定位,配置软件等到寄存器 *
****************************************************************************
ANDM #OVLY_0,*(PMST) ; OVLY = 0
ORM #IV_RESET,*(PMST) ; 中断向量表重定位
STM #SWWSR_VAL,SWWSR ; 配置软件等待寄存器
STM #SWCR_VAL,SWCR
****************************************************************************
* SET UP REQUIRED VALUES IN STATUS REGISTER *
****************************************************************************
SSBX CPL ; turn on compiler mode bit
RSBX OVM ; clear overflow mode bit
SSBX INTM ; enable the interuption
STM #0,IMR ; enable the timer interuption
****************************************************************************
*设置系统时钟为32MHz *
****************************************************************************
STM #0B,CLKMD ;switch to DIV mode
TstSatu: LDM CLKMD,B
AND #01B,B ;poll STATUS bit
BC TstSatu,BNEQ
STM #PLLX5,CLKMD ;switch to PLL X 2 mode
PllSatu: LDM CLKMD,B
AND #01B,B ;poll STATUS bit
BC PllSatu,BEQ
****************************************************************************
*设置FLASH的地址在0x400000之后 *
****************************************************************************
STM #60H,AR0
STM #0,AH
STM #80H,AL
STL A,*AR0
NOP
PORTW *AR0,memcntl ;将数据写入到第二个寄存器
NOP
NOP
NOP
****************************************************************************
* erase flash *
****************************************************************************
STM #40h,AH
STM #05555H,AL
STM #Flash_CE,BL
PSHM BL
CALL _bflash_erase
POPM BL
BC step1,ANEQ
B $
****************************************************************************************
* the firt step of the bootload: *
* write the address of the boottable to 0xFFFF,which is the address of the data *
* space *
* the address of the Seeddsk's flash is 0x8000~0xFFFF,so ,the first address of our *
* boottable at 0x8000. *
* the first address of our flash in program is 0x400000,so, we write 0x8000 to *
* 0x8ffff. *
****************************************************************************************
step1: STM #Flash_base,AH
STM #0FFFFH,AL
STM #8000H,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step2,ANEQ
b $
****************************************************************************************
* the second step of the bootload: *
* write the first word of the boot table ,which is tell the DSP how many bit flash *
* you selected. we select 16-bit flash ,so we write 0x10aa to this word. *
****************************************************************************************
step2: STM #Flash_base,AH
STM #8000H,AL
STM #10AAH,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step3,ANEQ
b $
******************************************************************************************
* the third step of the bootload: *
* write the second word of the boot table ,which will initialize the value of SWWSR *
* we write 0xffff to this register ,this value is reset value *
******************************************************************************************
step3: STM #Flash_base,AH
STM #8001H,AL
STM #0FFFFH,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step4,ANEQ ;if A!=0 ,write next data
B $
******************************************************************************************
* the four step of the bootload: *
* write the third word of the boot table ,which will initialize the value of BSCR *
* we write 0x800 to this register, *
******************************************************************************************
step4: STM #Flash_base,AH
STM #8002H,AL
STM #01H,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step5,ANEQ ;if A!=0 ,write next data
B $
******************************************************************************************
* the five step of the bootload: *
* write the Entry point (Xpc) *
* in the example XPC is 2 *
******************************************************************************************
step5: STM #Flash_base,AH
STM #8003H,AL
STM #02H,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step6,ANEQ ;if A!=0 ,write next data
B $
*****************************************************************************************
* the six step of the bootload: *
* write the Entry point (pc) *
* in the example XPC is _c_int00 *
*****************************************************************************************
step6: STM #Flash_base,AH
STM #8004H,AL
STM #_c_int00,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step7,ANEQ ;if A!=0 ,write next data
B $
******************************************************************************************
* the seventh step of the bootload: *
* write the code to flash ,we only write the code and the INITIALIZED section. *
* First ,write the size of the section *
* Second ,write the destination XPC of the section *
* Third ,write the destination PC of the section *
* fourth, write the data of the code *
* so ,writing the first section *
* first section is intruption *
******************************************************************************************
; write the .vector to flash
; first write the longth to flash
step7: STM #Flash_base,AH
STM #8005H,AL
STM #078h,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step71,ANEQ ;if A!=0 ,write next data
B $
; write the xpc and pc to flash for this section
step71: STM #Flash_base,AH
STM #8006H,AL
STM #2h,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step72,ANEQ ;if A!=0 ,write next data
B $
step72: STM #Flash_base,AH
STM #8007H,AL
STM #IV_RESET,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step73,ANEQ ;if A!=0 ,write next data
B $
; write the .vector code to flash
step73: STM #Flash_base,AH
STM #8008H,AL
STM #71H,AR0
STL A,*AR0
ADDM #078H,*AR0
STM #IV_RESET,BL
STM #2H,AR0
STM #78H,BH
PSHM BL
PSHM AR0
PSHM BH
CALL _bflash_writem
POPM BH
POPM AR0
POPM BL
BC step8,ANEQ ;if A!=0 ,write next data
B $
; write the .text to flash
; the first write the longth to flash for this section
step8: STM #71H,AR0
LD *AR0,A
ADDM #1,*AR0 ;the address of flash add one
STM #Flash_base,AH
STM #_bootmain,BL
STM #0,BH
SUB #8200H,B
PSHM BL
CALL _bflash_writes
POPM BL
BC step81,ANEQ ;if A!=0 ,write next data
; write the xpc and pc for the .text section
step81: STM #71H,AR0
LD *AR0,A
ADDM #1,*AR0 ;the address of flash add one
STM #Flash_base,AH
STM #02h,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step82,ANEQ ;if A!=0 ,write next data
B $
step82: STM #71H,AR0
LD *AR0,A
ADDM #1,*AR0 ;the address of flash add one
STM #Flash_base,AH
STM 08200H,BL
PSHM BL
CALL _bflash_writes
POPM BL
BC step83,ANEQ ;if A!=0 ,write next data
B $
; write the code for .text to flash
step83: STM #71H,AR0
LD *AR0,A
ADDM #(_bootmain - 08200H),*AR0 ;the address of flash add one
STM #Flash_base,AH
STM #8200H,BL ;the address of source
STM #2h,AR0
STM #(_bootmain- 08200H),BH;longth
PSHM BL
PSHM AR0
PSHM BH
CALL _bflash_writem
POPM BH
POPM AR0
POPM BL
BC step9,ANEQ ;if A!=0 ,write next data
b $
; write 0 to over
step9: STM #71H,AR0
LD *AR0,A
ADDM #1,*AR0 ;the address of flash add one
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -