; ; $Header: E:/HAM/EVM/RCS/flshboot.asm 1.8 1997/02/11 09:29:18 dbraun Exp $ ; ; $Log: flshboot.asm $ ; Revision 1.8 1997/02/11 09:29:18 dbraun ; Added instructions on how to use. ; ; Revision 1.7 1996/12/26 08:07:53 dbraun ; Adjusted to save and load some external P/X and Y memory. ; ; Revision 1.6 1996/10/25 06:30:52 dbraun ; Fixed the $D555 bug. The wrong code sequences were being ; used to enable and disable the EEPROM. I'm surprised it ; worked at all. Now the algorithm matches the Atmel documentation ; and the AlefNull algorithm. ; ; Revision 1.5 1996/10/25 06:04:46 dbraun ; Worked around bug where block at address $D555 doesn't program. ; ; Revision 1.4 1996/10/14 16:02:19 dbraun ; This program, and the loader itself, now run at $3400, just ; underneath the monitor. ; ; Revision 1.3 1996/10/14 13:16:01 dbraun ; Modified to load/restore memory regions according to new scheme ; where monitor lives in highest P/X memory. ; ; Revision 1.2 1996/06/19 12:55:30 dbraun ; Only change from original version: enter debugger when finished. ; ; ; Previous Authors: ; ; Johan Forrer ; Chris Hanna ; Helmut Strickner 26/01/96 ; Somebody at Motorola ; ; ; Previous Revisions: ; ; 28 JUN 95 CMH 1. Created. ; 30 JUN 95 CMH 1. Updated. ; 26 JAN 96 HSTR adapted for use with BOOT.ASM by JF ; ; ; NOTE: ; ; 1) J12 on EVM in 16K position ! ; ; ; How to Use FLSHBOOT.ASM: (notes by N1OWU) ; ; This program is designed to program the EVM's FLASH EPROM ; with the Leonid BIOS and an application. It is set up to ; work with the N1OWU version of the Leonid BIOS, which ; lives in high external P/X memory from $3800 to $3FFF. ; This program will load into the EPROM: ; ; 1: All internal P/X/Y memory from $0000 to $01FF ; 2: The BIOS external P/X memory from $3800 to $3FFF ; 3: A user-specificed amount of external P/X memory starting at $0200 ; 4: A user-specificed amount of external Y memory starting at $0200 ; 5: A short bootstrap routine ; ; To program your EEPROM, do this: ; ; 1: Adjust the values of WORDS_PX_EXT and WORDS_Y_EXT below ; to match the size of your application, and assemble this program. ; ; 2: Assemble N1OWU's bios2.asm and your application. ; ; 3: Start up the EVM debugger program. ; ; 4: If you are a perfectionist, clear all P/X/Y memory from ; 0000 to $01ff, since it will be saved for posterity in ; the EEPROM. ; ; 5: Load bios2.cld, then your application's .cld file, then ; flshboot.cld (this program). ; ; 6: Start execution at $3400, the entry point of this program. ; The program will take 3 or 4 seconds to run. ; ; 7: Quit the debugger and reset the EVM, and off you go!!! ; Don't forget to switch your RS-232 cable from the OnCE ; port to the SCI port... ; ;*************************************************************** opt cex,mex page 132,66,0,0 nolist include 'leonid' list TRUE_ equ 1 FALSE_ equ 0 EEPROM equ $8000 ; address of EEPROM FLASH_DELAY equ xtal/10000 ;6600 for 66 mhz clock TOGGLE_BIT equ 6 BEGIN equ $3400 ;An out-of-the-way location just below the BIOS ; You must adjust these two values, based on how big your application is !!! ; All these sizes must be a multiple of 64 ($40) !!! ; Note: We always initialize all the internal memory, since it's so small... WORDS_PX_EXT equ $0800 ;Amount of external P/X memory to save. WORDS_Y_EXT equ $0800 ;Amount of external Y memory to save. WORDS_PX_EXT_M equ $0800 ;Monitor P/X memory: save everything from ;p:$3800 to $3FFF ; These addresses are fixed by the 56002 and EVM architecture; don't change RAM_P_INT equ $0000 RAM_X_INT equ $0000 RAM_Y_INT equ $0000 ; These addresses depend on where in memory the monitor and application live. ; Change these only if the BIOS is re-designed!!! RAM_PX_EXT equ $0200 ;Probably never need to change RAM_Y_EXT equ $0100 ;Probably never need to change RAM_PX_EXT_M equ $3800 ;Monitor lives from p:$3800 to $3FFF ; "Blocks" are 64 bytes (or words) long ; These sizes are fixed by the 56002 and EVM architecture; don't change BLOCKS_BOOT equ 8 BLOCKS_P_INT equ 8 ;8blocks*64bytes*3 BLOCKS_X_INT equ 8 ;256 bytes true internal X RAM plus ;first 256 bytes of external X RAM ;that is not aliased to external P RAM BLOCKS_Y_INT equ 4 BLOCKS_PX_EXT equ WORDS_PX_EXT/64 BLOCKS_PX_EXT_M equ WORDS_PX_EXT_M/64 BLOCKS_Y_EXT equ WORDS_Y_EXT/64 ; These define where everything goes in the EEPROM. ; Don't mess with these... EEPROM_BOOT equ $C000 ;600h bytes boot code (must be at $C000!!!) EEPROM_P_INT equ $C600 ;600h bytes p_int EEPROM_X_INT equ $CC00 ;600h bytes x_int plus low x_ext EEPROM_Y_INT equ $D200 ;300h bytes y_int EEPROM_PX_EXT_M equ $D500 ;2A00 bytes for monitor P/X: $0C40 max words EEPROM_PX_EXT equ EEPROM EEPROM_Y_EXT equ EEPROM_PX_EXT+(3*64*BLOCKS_PX_EXT) ; sanity check values if BLOCKS_PX_EXT+BLOCKS_Y_EXT>$0055 fail 'External PX or Y memory too big to fit in EPROM' endif if BLOCKS_PX_EXT_M>$0037 fail 'Monitor PX memory too big to fit in EPROM' endif PLL equ $FFFD BCR equ $FFFE INIT_PLL equ $261009 INIT_BCR equ $BBB0 BOOT_RUN equ $0000 LOAD_RUN equ $3400 START equ $0000 org p:BEGIN ;*************************************************************** ; ; FlashCopy ; ; This routine copies P, X, and Y RAM to the FLASH EEPROM. ; This routine also copies the boot and loader code to ; the EEPROM at P:$C000 so that the DSP boot loader will ; copy it into P RAM and execute it. ; ; Inputs: ; ; Outputs: ; ; Registers modified: ; ; a, r0, r1, r2 ; ;*************************************************************** FlashCopy ; Call this from the debugger to program the EEPROM move #CopyP,r0 ;return address jmp FlashInit ;init DSP registers ; Copy P (and P/X) memory CopyP move #RAM_P_INT,r0 ;get start address of P RAM move #EEPROM_P_INT,r1 ;get start address of P EEPROM move #BLOCKS_P_INT,r2 ;get number of 64 word blocks to copy jsr FlashWriteP ;copy P RAM to FLASH EEPROM if BLOCKS_PX_EXT>0 move #RAM_PX_EXT,r0 ;get start address of P/X RAM move #EEPROM_PX_EXT,r1 ;get start address of P/X EEPROM move #BLOCKS_PX_EXT,r2 ;get number of 64 word blocks to copy jsr FlashWriteX ;copy P/X RAM to FLASH EEPROM endif move #RAM_PX_EXT_M,r0 ;get start address of P/X RAM move #EEPROM_PX_EXT_M,r1 ;get start address of P/X EEPROM move #BLOCKS_PX_EXT_M,r2 ;get number of 64 word blocks to copy jsr FlashWriteP ;copy P/X RAM to FLASH EEPROM ; Copy X memory CopyX move #RAM_X_INT,r0 ;get start address of X RAM move #EEPROM_X_INT,r1 ;get start address of X EEPROM move #BLOCKS_X_INT,r2 ;get number of 64 word blocks to copy jsr FlashWriteX ;copy X RAM to FLASH EEPROM ; Copy Y memory CopyY move #RAM_Y_INT,r0 ;get start address of Y RAM move #EEPROM_Y_INT,r1 ;get start address of Y EEPROM move #BLOCKS_Y_INT,r2 ;get number of 64 word blocks to copy jsr FlashWriteY ;copy Y RAM to FLASH EEPROM if BLOCKS_Y_EXT>0 move #RAM_Y_EXT,r0 ;get start address of Y RAM move #EEPROM_Y_EXT,r1 ;get start address of Y EEPROM move #BLOCKS_Y_EXT,r2 ;get number of 64 word blocks to copy jsr FlashWriteY ;copy Y RAM to FLASH EEPROM endif ; Copy boot and loader code to EEPROM CopyBoot move #BOOT_LOAD,r0 ;get load address move #EEPROM_BOOT,r1 ;get boot address move #BLOCKS_BOOT,r2 ;get number of 64 word blocks to copy jsr FlashWriteP ;copy P RAM to FLASH EEPROM FlashCopyEnd debug ;;jmp * ;*************************************************************** ; ; FlashWriteP ; ; This routine writes blocks of 64 24-bit words (192 bytes) from ; the P RAM to the FLASH EEPROM. ; ; Inputs: ; ; r0 : Starting address of the P RAM where the ; blocks of words are read from ; r1 : Starting address of the FLASH EEPROM where the ; blocks of words are to be written ; r2 : Number of blocks to write ; ; Outputs: ; ; Registers modified: ; ; a, r0, r1 ; ;*************************************************************** FlashWriteP do r2,LoopWriteP ;loop for number of blocks ;*************************************************************** ; Do block 1. This consists of: ; words 1 to 21 + ; low byte of word 22 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes do #21,MoveBlockP1 ;move 21 words move p:(r0)+,a ;get words 1 to 21 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockP1 move p:(r0)+,a ;get 22nd word move a1,p:(r1)+ ;move low byte to FLASH EEPROM jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete ;*************************************************************** ; Do block 2. This consists of: ; mid and high bytes of word 22 + ; words 23 to 42 + ; low and mid bytes of word 43 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes rep #8 ;continue with 22nd word lsr a move a1,p:(r1)+ ;move mid byte to FLASH EEPROM rep #8 lsr a move a1,p:(r1)+ ;move high byte to FLASH EEPROM do #20,MoveBlockP2 ;move 20 words move p:(r0)+,a ;get words 23 to 42 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockP2 move p:(r0)+,a ;get 43rd word move a1,p:(r1)+ ;move low byte to FLASH EEPROM rep #8 lsr a move a1,p:(r1)+ ;move mid byte to FLASH EEPROM jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete ;*************************************************************** ; Do block 3. This consists of: ; high byte of word 43 + ; words 44 to 64 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes rep #8 ;continue with 43rd word lsr a move a1,p:(r1)+ ;move high byte to FLASH EEPROM do #21,MoveBlockP3 ;move 21 words move p:(r0)+,a ;get words 44 to 64 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockP3 jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete LoopWriteP nop FlashWritePEnd rts ;*************************************************************** ; ; FlashWriteX ; ; This routine writes blocks of 64 24-bit words (192 bytes) from ; the X RAM to the FLASH EEPROM. ; ; Inputs: ; ; r0 : Starting address of the X RAM where the ; blocks of words are read from ; r1 : Starting address of the FLASH EEPROM where the ; blocks of words are to be written ; r2 : Number of blocks to write ; ; Outputs: ; ; Registers modified: ; ; a, r0, r1 ; ;*************************************************************** FlashWriteX do r2,LoopWriteX ;loop for number of blocks ;*************************************************************** ; Do block 1. This consists of: ; words 1 to 21 + ; low byte of word 22 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes do #21,MoveBlockX1 ;move 21 words move x:(r0)+,a ;get words 1 to 22 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockX1 move x:(r0)+,a ;get 22nd word move a1,p:(r1)+ ;move low byte to FLASH EEPROM jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete ;*************************************************************** ; Do block 2. This consists of: ; mid and high bytes of word 22 + ; words 23 to 42 + ; low and mid bytes of word 43 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes rep #8 ;continue with 22nd word lsr a move a1,p:(r1)+ ;move mid byte to FLASH EEPROM rep #8 lsr a move a1,p:(r1)+ ;move high byte to FLASH EEPROM do #20,MoveBlockX2 ;move 20 words move x:(r0)+,a ;get words 23 to 42 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockX2 move x:(r0)+,a ;get 43rd word move a1,p:(r1)+ ;move low byte to FLASH EEPROM rep #8 lsr a move a1,p:(r1)+ ;move mid byte to FLASH EEPROM jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete ;*************************************************************** ; Do block 3. This consists of: ; high byte of word 43 + ; words 44 to 64 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes rep #8 ;continue with 43rd word lsr a move a1,p:(r1)+ ;move high byte to FLASH EEPROM do #21,MoveBlockX3 ;move 21 words move x:(r0)+,a ;get words 44 to 64 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockX3 jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete LoopWriteX nop FlashWriteXEnd rts ;*************************************************************** ; ; FlashWriteY ; ; This routine writes blocks of 64 24-bit words (192 bytes) from ; the Y RAM to the FLASH EEPROM. ; ; Inputs: ; ; r0 : Starting address of the Y RAM where the ; blocks of words are read from ; r1 : Starting address of the FLASH EEPROM where the ; blocks of words are to be written ; r2 : Number of blocks to write ; ; Outputs: ; ; Registers modified: ; ; a, r0, r1 ; ;*************************************************************** FlashWriteY do r2,LoopWriteY ;loop for number of blocks ;*************************************************************** ; Do block 1. This consists of: ; words 1 to 21 + ; low byte of word 22 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes do #21,MoveBlockY1 ;move 21 words move y:(r0)+,a ;get words 1 to 21 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockY1 move y:(r0)+,a ;get 22nd word move a1,p:(r1)+ ;move low byte to FLASH EEPROM jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete ;*************************************************************** ; Do block 2. This consists of: ; mid and high bytes of word 22 + ; words 23 to 42 + ; low and mid bytes of word 43 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes rep #8 ;continue with 22nd word lsr a move a1,p:(r1)+ ;move mid byte to FLASH EEPROM rep #8 lsr a move a1,p:(r1)+ ;move high byte to FLASH EEPROM do #20,MoveBlockY2 ;move 20 words move y:(r0)+,a ;get words 23 to 42 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockY2 move y:(r0)+,a ;get 43rd word move a1,p:(r1)+ ;move low byte to FLASH EEPROM rep #8 lsr a move a1,p:(r1)+ ;move mid byte to FLASH EEPROM jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete ;*************************************************************** ; Do block 3. This consists of: ; high byte of word 43 + ; words 44 to 64 ;*************************************************************** jsr FlashDisable ;enable EEPROM writes rep #8 ;continue with 43rd word lsr a move a1,p:(r1)+ ;move high byte to FLASH EEPROM do #21,MoveBlockY3 ;move 21 words move y:(r0)+,a ;get words 44 to 64 jsr WriteWord ;write bytes to FLASH EEPROM MoveBlockY3 jsr FlashDelay ;delay for programming cycle to begin jsr FlashCheck ;check if programming cycle complete LoopWriteY nop FlashWriteYEnd rts ;*************************************************************** ; ; FlashDisable ; ; This function performs the sequence for activating software ; data protection, i.e. disables writes to the EEPROM. ; ;*************************************************************** FlashDisable move #>$AA,x0 move x0,x:EEPROM+$5555 move #>$55,x0 move x0,x:EEPROM+$2AAA move #>$A0,x0 move x0,x:EEPROM+$5555 rts ;writes are now disabled ;*************************************************************** ; ; FlashDelay ; ; This function performs a 200 us delay (assuming 40MHz clock). ; It is used to wait for the programming cycle to begin. ; ;*************************************************************** FlashDelay rep #FLASH_DELAY/2 nop rep #FLASH_DELAY/2 nop rts ;*************************************************************** ; ; FlashCheck ; ; This function waits for the programming cycle to complete. ; It uses the EEPROM toggle bit method. ; ;*************************************************************** FlashCheck btst #TOGGLE_BIT,x:EEPROM ;check the initial status of bit 6 jcs check_set check_clr ; jsr FlashDelay btst #TOGGLE_BIT,x:EEPROM ;test bit, it was clear jcs check_set ;if it is now set, continue... rts check_set ; jsr FlashDelay btst #TOGGLE_BIT,x:EEPROM ;test bit, it was set jcc check_clr ;if it is now clear, continue... rts ;*************************************************************** ; ; FlashInit ; ; This function performs the initialization required before ; the flash routines are used. ; ;*************************************************************** FlashInit movep #INIT_PLL,x:PLL ;set PLL movep #INIT_BCR,x:BCR ;set BCR ori #3,mr ;disable interrupts movec #0,sp ;reset stack pointer movec #0,omr ;single chip mode nop ;delay for remapping jmp (r0) ;return ;*************************************************************** ; ; WriteWord ; ; This function writes a word to the EEPROM one byte at a ; time, starting with the low byte. ; ;*************************************************************** WriteWord move a1,p:(r1)+ ;move low byte to FLASH EEPROM rep #8 lsr a move a1,p:(r1)+ ;move mid byte to FLASH EEPROM rep #8 lsr a move a1,p:(r1)+ ;move high byte to FLASH EEPROM rts ;*************************************************************** ; ; FlashBoot ; ; This function executes the code to enter the DSP ; bootstrap mode (Mode 1). ; ;*************************************************************** FlashBoot ori #3,mr ;disable interrupts movec #0,sp ;reset stack pointer movec #1,omr ;bootstrap mode nop ;delay for remapping jmp <$0 ;begin bootstrap BOOT_LOAD org p:BOOT_RUN,p: ;*************************************************************** ; ; Boot ; ; This is the boot routine. It is an overlay that is copied ; from its P memory load address (EEPROM @ P:$C000) to its ; P memory runtime address (RAM @ P:$0000) and executed by ; the DSP bootloader. It then copies the loader routine from ; its P memory load address to its P memory runtime address ; and then jumps to it. ; ;*************************************************************** Boot jmp DoBoot org p:@LCV(R)+$40,p:@LCV(L)+$40 DoBoot move #LOAD_LOAD,r0 ;get loader load address move #LOAD_RUN,r1 ;get loader runtime address do #LOAD_LENGTH,LoadLoop move p:(r0)+,x0 ;read code from load address move x0,p:(r1)+ ;write code to runtime address LoadLoop jmp Load ;jump to the loader routine rts LOAD_LOAD org p:LOAD_RUN,p: ;*************************************************************** ; ; Load ; ; This is the loader routine. It is an overlay that the boot ; routine copies from its load address to its runtime address ; and then executes. This routine then loads P, X, and Y RAM ; from the P, X, and Y EEPROM, and then jumps to P:$0000 to ; execute the application. ; ;*************************************************************** Load LoadP move #RAM_P_INT,r0 ;get start address of P RAM move #EEPROM_P_INT,r1 ;get start address of P EEPROM move #BLOCKS_P_INT*64,r2 ;get number of words to copy jsr BootCopyP ;Load P RAM from EEPROM if BLOCKS_PX_EXT>0 move #RAM_PX_EXT,r0 ;get start address of P/X RAM move #EEPROM_PX_EXT,r1 ;get start address of P/X EEPROM move #BLOCKS_PX_EXT*64,r2 ;get number of words to copy jsr BootCopyP ;Load P/X RAM from EEPROM endif move #RAM_PX_EXT_M,r0 ;get start address of P/X RAM move #EEPROM_PX_EXT_M,r1 ;get start address of P/X EEPROM move #BLOCKS_PX_EXT_M*64,r2 ;get number of words to copy jsr BootCopyP ;Load P/X RAM from EEPROM LoadX move #RAM_X_INT,r0 ;get start address of X RAM move #EEPROM_X_INT,r1 ;get start address of X EEPROM move #BLOCKS_X_INT*64,r2 ;get number of words to copy jsr BootCopyX ;Load X RAM from EEPROM LoadY move #RAM_Y_INT,r0 ;get start address of Y RAM move #EEPROM_Y_INT,r1 ;get start address of Y EEPROM move #BLOCKS_Y_INT*64,r2 ;get number of words to copy jsr BootCopyY ;Load Y RAM from EEPROM if BLOCKS_Y_EXT>0 move #RAM_Y_EXT,r0 ;get start address of Y RAM move #EEPROM_Y_EXT,r1 ;get start address of Y EEPROM move #BLOCKS_Y_EXT*64,r2 ;get number of words to copy jsr BootCopyY ;Load Y RAM from EEPROM endif LoadEnd jmp START ;run the application ;*************************************************************** ; ; BootCopyP ; ; This function copies from the FLASH EEPROM to the P RAM. ; ; Inputs: ; ; r0 : Starting address of the RAM for writing ; r1 : Starting address of the FLASH EEPROM for reading ; r2 : Number of words to copy ; ; Outputs: ; ; Registers modified: ; ; a, r0, r1 ; ;*************************************************************** BootCopyP do r2,BootLoopP1 ;loop for number of words do #3,BootLoopP2 ;loop to read 3 bytes and pack into a word move p:(r1)+,a2 ;read byte from FLASH EEPROM rep #8 ;shift right eight bits asr a BootLoopP2 move a1,p:(r0)+ ;write word to RAM BootLoopP1 nop rts ;*************************************************************** ; ; BootCopyX ; ; This function copies from the FLASH EEPROM to the X RAM. ; ; Inputs: ; ; r0 : Starting address of the RAM for writing ; r1 : Starting address of the FLASH EEPROM for reading ; r2 : Number of words to copy ; ; Outputs: ; ; Registers modified: ; ; a, r0, r1 ; ;*************************************************************** BootCopyX do r2,BootLoopX1 ;loop for number of words do #3,BootLoopX2 ;loop to read 3 bytes and pack into a word move p:(r1)+,a2 ;read byte from FLASH EEPROM rep #8 ;shift right eight bits asr a BootLoopX2 move a1,x:(r0)+ ;write word to RAM BootLoopX1 nop rts ;*************************************************************** ; ; BootCopyY ; ; This function copies from the FLASH EEPROM to the Y RAM. ; ; Inputs: ; ; r0 : Starting address of the RAM for writing ; r1 : Starting address of the FLASH EEPROM for reading ; r2 : Number of words to copy ; ; Outputs: ; ; Registers modified: ; ; a, r0, r1 ; ;*************************************************************** BootCopyY do r2,BootLoopY1 ;loop for number of words do #3,BootLoopY2 ;loop to read 3 bytes and pack into a word move p:(r1)+,a2 ;read byte from FLASH EEPROM rep #8 ;shift right eight bits asr a BootLoopY2 move a1,y:(r0)+ ;write word to RAM BootLoopY1 nop rts LOAD_LENGTH equ *-Load end