$MOD167 ; PreLoader und Loader Martin Gyurko ; Teile dieses Codes wurden aus verschiedensten Quellen geliehen ; SFRs are defined here $include (REG167.INC) C100 SECTION CODE WORD PUBLIC P100 PROC near org 0FA40h ; --- load code immediately following the boot script --- mov r0, #0FA60h ; --- loop to load the received code --- Schleife: jnb S0RIR, $ ; wait for byte movb [r0], S0RBUF ; store byte bclr S0RIR ; clear receive flag movb S0TBUF, [r0] ; echo the byte jnb S0TIR, $ bclr S0TIR ; increment pointer and check size cmpi1 R0, #(Ende-1) ; Ende des VSOS. jmpr cc_NE, Schleife nop P100 ENDP P110 PROC near ; --- a very small operating sytem from http://www.rigelcorp.com/C166/isp97.pdf org 0FA60h ; --- constants --- Cmd_SetAppID equ '1' Cmd_GetAppID equ '2' Cmd_LoadApp equ '3' Cmd_RunApp equ '4' ; --- register usage --- ; r0..r1 are used as general purpose registers ; --- memory variables are stored in FA40..FA5E --- AppID equ 0FA40h CodeEnd equ 0FA42h ; --- code is not relocatable due to the (absolute) intersegment jump --- org 0FA60h ; --- initialize system registers --- ; stksz roms1 sgtdis romen bytdis clken wrcfg cscfg pwdcfg owddis bdrsten xpen visible xpershare ; 011 0 1 1 1 0 0 0 0 0 0 1 0 0 mov SYSCON, #06e04h ; stack size 32, map FLASH to segment 0, segmentation disabled, internal rom enabled, BHE disabled, Clkout disabled, wrconfig normal, XRAM enabled, not visible, no sharing of bus ;mov SYSCON, #0e404h ; stack size 32, map FLASH to segment 0, segmentation disabled, internal rom enabled, BHE disabled, Clkout disabled, wrconfig normal, XRAM enabled, not visible, no sharing of bus mov BUSCON1, #04C0h ; ErrataWorkaround X11: Illegal Bus Trap after XPER access in Single Chip Mode jmps 0, next ; implicitly initialize CSP next: mov DPP0,#0h ; use DPP0 and DPP1 for FLASH mov DPP1,#1h mov DPP2,#2h mov DPP3,#3h ; --- initialize the stack and register space --- mov CP, #0FA00h mov SP, #0FA3Eh mov STKOV, #0FA20h mov STKUN, #0FA40h ; mov S0CON, #8011h ; wir nutzen selbe einstellung wie beim BSL ; mov S0BG, #10 DISWDT ; keep the watch doggie sleeping EINIT ; end of initialization Loop: callr GetByte ; get command cmp r0, #Cmd_SetAppID ; AppID identifies the current program jmpr cc_NE, Loop01 callr GetByte mov AppID, r0 jmpr cc_UC, Loop04 Loop01: cmp r0, #Cmd_GetAppID jmpr cc_NE, Loop02 mov r0, AppID callr SendByte jmpr cc_UC, Loop04 Loop02: cmp r0, #Cmd_LoadApp jmpr cc_NE, Loop03 callr GetByte ; end address high byte movb rH1, rL0 callr GetByte ; end address low byte movb rL1, rL0 sub r1, #1 ; adjust code end mov CodeEnd, r1 callr LoadApp jmpr cc_UC, Loop04 Loop03: cmp r0, #Cmd_RunApp jmpr cc_NE, Loop04 callr CodeBegin ;jmpr cc_UC, Loop Loop04: mov r0, #'>' ; the prompt callr SendByte jmpr cc_UC, Loop ; back to the top ; --- utilities --- ; CodeEnd holds the end address ; LoadApp: mov r0, #CodeBegin ; always load apps here LoadApp01: jnb S0RIR, $ ; wait for byte movb [r0], S0RBUF ; store byte bclr S0RIR ; clear receive flag movb S0TBUF, [r0] ; echo the byte jnb S0TIR, $ bclr S0TIR cmpi1 r0, CodeEnd ; inc pointer and check if download has reached codeend jmpr CC_NE, LoadApp01 ; repeat if more bytes ret SendByte: mov S0TBUF, r0 ; transmit char jnb S0TIR, $ bclr S0TIR ret GetByte: jnb S0RIR, $ mov r0, S0RBUF ; receive char bclr S0RIR ret ; --- this is where apps are to be loaded --- ; --- (OS_SIZE = CodeBegin - 0FA60h) --- nop Ende: CodeBegin: P110 ENDP C100 ENDS END