📄 boot.asm
字号:
;* Changes: H:X
;*
CGMChange:
psha ; save pointer lsb on stack
pshx ; save pointer msb on stack
pulh ; initialize
pulx ; H:X points to data array
;* Internal CGM PLL Bus Frequency Change Subroutine =======================================
;*
;* This subroutine will program the CGM PLL to change the bus frequency in accordance with
;* the data being pointed to by H:X.
;*
;* Calling convention:
;*
;* ldhx #parameters ; point to CGM parameter table
;* jsr PLLset ; go change the bus speed
;*
;* Returns: nothing
;*
;* Changes: H:X
;*
PLLset:
bclr BCS,pctl ; select external reference as base clock
bclr PLLON,pctl ; turn off PLL
mov x+,pctl ; program P & E
mov x+,pmrs ; program L
mov x+,pmsh ; program N msb
mov x+,pmsl ; program N lsb
bset AUTO,pbwc ; enable automatic bandwidth control
bset PLLON,pctl ; turn on PLL
PLLwait:
brclr LOCK,pbwc,PLLwait ; wait for PLL to lock (Note: won't simulate)
bset BCS,pctl ; select VCO as base clock
rts ; return
;* PutChar Subroutine =====================================================================
;*
;* This subroutine will output the character passed in ACC to the SCI.
;*
;* C function prototype:
;*
;* void PutChar (char data);
;*
;* Calling convention:
;*
;* lda data ; get character
;* jsr PutChar ; go output it
;*
;* Returns: nothing
;*
;* Changes: nothing
;*
PutChar:
brclr SCTE,scs1,PutChar ; wait until SCI transmitter is empty
sta scdr ; output character to the SCI
rts ; return
;* Power-on Reset Bootloader Entry ========================================================
;*
;* This is where the Bootloader starts from power-on reset.
;*
BootReset1:
;
; Initialize the PLL CGM for 7.3728 MHz bus speed from 32.768 kHz crystal.
;
; ldhx #bus7372800 ; point to 7.3728 MHz parameters
; bsr PLLset ; change bus speed
;
; Copy user Flash parameters into RAM.
;
ldhx #user_scbr ; point to first parameter
mov x+,count ; copy user SCI baud rate
mov x+,temp_sp ; copy user Configuration Register 1
mov x+,temp_sp+1 ; copy user Configuration Register 2
mov x+,flash_first ; copy first user Flash address MSB
mov x+,flash_first+1 ; copy first user Flash address LSB
mov x+,flash_last ; copy last user Flash address MSB
mov x+,flash_last+1 ; copy last user Flash address LSB
ldhx #count ; point to first parameter, now saved in RAM
txs ; use SP to point to parameter list in RAM
;
; Test the user SCI baud rate. The user can override the default baud rate.
;
pula ; get user SCBR initial data
cmp #flash_erased ; check if it's erased
bne BootReset2 ; skip if not
lda #init_scbr ; else, force default value
BootReset2:
sta count ; save initial SCI baud rate
;
; Program the write-once configuration registers. The user can override the defaults.
;
pula ; get user Configuration Register 1 initial data
cmp #flash_erased ; check if it's erased
bne BootReset3 ; skip if not
lda #init_config1 ; else, force default value
BootReset3:
sta config1 ; initialize Configuration Register 1
;
pula ; get user Configuration Register 2 initial data
cmp #flash_erased ; check if it's erased
bne BootReset4 ; skip if not
lda #init_config2 ; else, force default value
BootReset4:
sta config2 ; initialize Configuration Register 2
;
; Program the first and last user Flash addresses. The user can override the defaults.
;
pulx ; get first user Flash address LSB
pulh ; get first user Flash address MSB
cphx #$FFFF ; check if it's erased
bne BootReset5 ; skip if not
lda #{init_first&$FF} ; else, get default first user address LSB
psha ; save it
lda #{init_first>8} ; and get default first user address MSB
psha ; save it
ais #2 ; move stack pointer back
;
BootReset5:
pulx ; get last user Flash address LSB
pulh ; get last user Flash address MSB
cphx #$FFFF ; check if it's erased
bne BootReset6 ; skip if not
lda #{init_last&$FF}
; ldx #{init_last&$FF} ; else, get default last user address LSB
psha ; save it
lda #{init_last>8} ; and get default last user address MSB
psha ; save it
BootReset6:
;* User Bootloader Entry ==================================================================
;*
;* The user can launch the bootloader from here.
;*
BootResetUser:
sei ; disable all interrupts
sta copctl ; clear the COP counter
ldhx #init_stack+1 ; initialize
txs ; the stack pointer
;
; Initialize the PLL CGM for 7.3728 MHz bus speed from 32.768 kHz crystal.
;
ldhx #bus7372800 ; point to 7.3728 MHz parameters
bsr PLLset ; change bus speed
;
; Take over and initialize the SCI. The user can override the default baud rate.
;
mov count,scbr ; initialize SCI baud rate
mov #init_scc1,scc1 ; initialize SCI Control Register 1
mov #init_scc2,scc2 ; initialize SCI Control Register 2
;* Main Bootloader Control Loop ==========================================================
;*
;* Bootloader program supports the following commands:
;*
;* 'X' = Exit and execute user program via user reset vector
;* 'P' = Program Flash via S-Records
;* 'W' = Erase Flash (Wipe)
;* 'U' = Upgrade Flash by erasing all user space, then programming via S-Records
;* 'H' = Help
;* '?' = Help
;*
;* Note: avoid using 'A' - 'F', as these are valid S-Record characters that could get
;* misinterpreted.
;*
cmd_exit: equ 'X' ; Exit command
cmd_program: equ 'P' ; Program Flash command
cmd_erase: equ 'W' ; Erase Flash command (Wipe)
cmd_upgrade: equ 'U' ; Upgrade Flash command
cmd_help: equ 'H' ; Help command
cmd_help1: equ $1F ; '?' = alternate Help command
;
Boot:
ldhx #msg_hello ; point to hello message
bsr PrintString ; output it
jsr GetChar ; get a character from the SCI
cmp #ascii_CR ; check for ASCII carriage return
beq Boot ; just loop back if so
bsr PutChar ; else, echo character back
and #$DF ; convert to uppercase
;* Execute User Program Command Check =====================================================
;*
cmp #cmd_exit ; check for Exit command
bne Boot2 ; skip if not
lda user_reset+1 ; else, get the MSB of the user reset vector
cmp #flash_erased ; check if it's erased
beq Boot1 ; skip if not
jmp user_reset ; else, jump to user reset jump vector
;
; Remain in the Bootloader if the MSB of the User Reset Jump Vector is erased.
;
Boot1:
ldhx #msg_noreset ; point to error message
bsr PrintString ; output it
bra Boot ; jump back to top
;* Erase Flash Command Check ==============================================================
;*
Boot2:
cmp #cmd_erase ; check for Erase Flash command
bne Boot3 ; skip if not
bsr EraseFlash ; else, go erase Flash
;
; Common Bootloader command completion points.
;
BootDone:
ldhx #msg_complete ; point to operation complete message
BootDone1:
bsr PrintString ; output it
BootDone2:
bra Boot ; jump back to top
;* External PutString Subroutine ==========================================================
;*
;* This subroutine will output the null terminated string pointed to by X:A (which is a
;* common implementation for pointer parameter passing used by HC08 C compilers) to the SCI.
;*
;* C function prototype:
;*
;* void PutString (char string*);
;*
;* Calling convention:
;*
;* ldx #{string>8} ; get CGM parameter table address msb
;* lda #{string&$FF} ; get CGM parameter table address lsb
;* jsr PutString ; go change the bus speed
;*
;* Returns: nothing
;*
;* Changes: H:X
;*
PutString:
psha ; save pointer lsb on stack
pshx ; save pointer msb on stack
pulh ; initialize
pulx ; H:X points to data array
bra PrintString ; go output string
;* PrintString Subroutine =================================================================
;*
;* This subroutine will output the null teminated string pointed to by H:X to the SCI.
;*
;* Calling convention:
;*
;* ldhx #string ; point to start of string
;* jsr PrintString ; go output it
;*
;* Returns: nothing
;*
;* Changes: H:X
;*
PrintString1:
brclr SCTE,scs1,PrintString1 ; wait until SCI transmitter is empty
mov x+,scdr ; output character to the SCI and advance pointer
PrintString:
tst ,x ; test string character
bne PrintString1 ; loop back if not null
rts ; else, return
;* Program Flash Command Check ============================================================
;*
Boot3:
cmp #cmd_program ; check for Program Flash command
bne Boot4 ; skip if not
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -