📄 cstartxf.asm
字号:
; @(#)cstart.asm 1.42
;*****************************************************************************
;*
;* MODULE : cstartex.asm (RAM)
;*
;* DESCRIPTION : Startup code for the 80166/80167
;*
;* - Processor initialization.
;* - Initialization of static variables in internal or external
;* ram. C variables which have to be initialized are specified
;* in ROM section C166_INIT. C variables which must
;* be cleared are specified in ROM section C166_BSS.
;* - Set user stack pointer.
;* - Call the user program: main().
;* - On exit cpu is set in idle mode.
;*
;* COPYRIGHTS : Tasking B.V., Amersfoort 1990
;* modified : 12.02.1993 V. Ebner, Vector Informatik GmbH,
;* 07.02.1997 W. Janz (OSEK, P-Option)
;*
;*****************************************************************************
; Following defines can be set on the command line of the macro pre-processor,
; with the DEFINE() control. ( Syntax: DEFINE( identifier [, replacement] )
; Example: DEFINE( MODEL, LARGE ) )
@IF( ! @DEFINED( @C167 ) )
@SET( C167, 0 ) ; set to 1 for 80167 derivate
@ENDI
@IF( ! @DEFINED( @FUZZY_DEMO ) )
@SET( FUZZY_DEMO, 0 ) ; set to 1 for fuzzy-166 evaluation kit
@ENDI
@IF( ! @DEFINED( @PXROS ) )
@SET( PXROS, 1 ) ; set to 1 for PXROS support
@ENDI
@IF( ! @DEFINED( @EVA ) )
@SET( EVA, 0 ) ; set to 1 when execution environment is ertec
; EVA166/EVA167 or EPC166. Needed to:
; 1) force tiny model to execute with
; segmentation enabled.
; 2) do not clear monitor data in
; bit-addressable area.
; 3) run application with interrupts
; enabled, allowing the monitor to
; break it (not needed for EPC166).
; 4) define symbols that can be used by
; a debugger to initialize the EVA167
; before monitor or user program is
; downloaded.
; Hardware is expected to be configured for
; non-multiplexed bus mode to get the maximum
; performance.
@ENDI
@IF( ! @DEFINED( @EX_AB ) )
@SET( EX_AB, 0 ) ; enable EX_AB if the function 'exit()' or
; 'abort()' is used else it can be disabled.
@ENDI
@IF( ! @DEFINED( @FLOAT ) )
@SET( FLOAT, 0 ) ; enable FLOAT if floating point functions are
; used else it can be disabled.
@ENDI
@IF( ! @DEFINED( @BIT_INIT ) )
@SET( BIT_INIT, 0 ) ; enable initialization of bit variables at
; startup. Only needed if "bit b = 1;" is used.
@ENDI
@IF( @C167 )
$EXTEND ; enable all 80167 extensions
$NOMOD166 ; disable the internal set of 80166 SFRs
$STDNAMES(reg167b.def) ; load set of 80167 SFRs from reg167b.def
@ENDI
@IF( @FUZZY_DEMO )
@MATCH( MODEL, "TINY" ) ; override memory model selected
@SET( EVA, 0 ) ; execution environment is fuzzy-166
; evaluation kit, tiny memory model
@ENDI
; set assembler controls.
@IF( @DEFINED( @MODEL ) )
@IF( @EQS(@MODEL,"SMALL") )
$MODEL(small)
$NONSEGMENTED
@ENDI
@IF( @EQS(@MODEL,"TINY") )
$MODEL(tiny)
$NONSEGMENTED
@ENDI
@IF( @EQS(@MODEL,"MEDIUM") )
$MODEL(medium)
$SEGMENTED
@ENDI
@IF( @EQS(@MODEL,"LARGE") )
$MODEL(large)
$SEGMENTED
@ENDI
@ELSE ; Default memory model is SMALL
@MATCH( MODEL, "SMALL" )
$MODEL(small)
$NONSEGMENTED
@ENDI
$CASE
$GENONLY
$DEBUG
$NOLOCALS
NAME CSTART ; module name.
@IF( @EQS(@MODEL,"LARGE") | @EQS(@MODEL,"SMALL") )
EXTERN _main:FAR ; start label user program.
@ELSE
EXTERN _main:NEAR ; start label user program.
@ENDI
;EXTERN _bRestartFromError:BYTE
PUBLIC __IDLE ; cstart end
PUBLIC __EXIT ; address to jump to on 'exit()'.
PUBLIC RECOVERY ; address to jump after error recovery
@IF( @EX_AB )
@IF( @EQS(@MODEL,"LARGE") | @EQS(@MODEL,"SMALL") )
EXTERN _exit:FAR ; exit()
@ELSE
EXTERN _exit:NEAR ; exit()
@ENDI
@ENDI
@IF( @EQS(@MODEL,"MEDIUM") | @EQS(@MODEL,"LARGE") )
ASSUME DPP3:SYSTEM ; assume system data page pointer.
@IF( @FLOAT )
ASSUME DPP2:?FPSTKUN
ASSUME DPP2:?FPSP
@ENDI
@ENDI
; Value definitions for System Configuration Register : SYSCON/BUSCON0
; 'Default' is the value after reset.
@IF( @C167 )
; Memory Cycle Time is extended by a number of additional State Times.
; in a range from 0 through 15. BUSCON0[3..0]
__MCTC LIT '2' ; Memory wait states is 1 (MCTC = 0EH).
; (Default=15 additional state times)
; The Read/Write Signal Delay is 0.5 or 0 State Times. BUSCON0.4
__RWDC0 LIT '1' ; 0 = Delay Time (Default)
; 1 = No Delay Time
; Memory Tri-state is extended by either 1 or 0 State Times. BUSCON0.5
__MTTC0 LIT '0' ; 0 = Delay Time (Default)
; 1 = No Delay Time
; External bus configurations. BUSCON0[7..6]
; Default state is determined by the
; state of the port pins P0L.7 and P0L.6
; at reset.
; Note: coding changed in the C167
; ALE Signal is lengthened by either 1 or 0 State Times. BUSCON0.9
__ALECTL0 LIT '0' ; 1 = Delay Time (Default if pin #EA is
; low)
; 0 = No Delay Time (Default if pin #EA
; is high)
; Do not disable the ALE lengthening option for a multiplexed bus
; configuration. See problem 17 in errata sheet SAB-C167A-LM,ES-AC,1.1
; on page 4/9.
; READY# Input Enable control bit. BUSCON0.12
__RDYEN0 LIT '0' ; 0 = disabled (Default)
; 1 = enabled
; Process BUSCON0 low byte and high byte values
BUSC0_L EQU ((__MTTC0<<5) | (__RWDC0<<4) | ((~__MCTC)&000Fh))
BUSC0_H EQU ((__RDYEN0<<4) | (__ALECTL0<<1))
BUSC0_M_L EQU 03Fh ; Mask low byte BUSCON0
BUSC0_M_H EQU 012h ; Mask high byte BUSCON0
; Write Configuration Mode Control Bit (CLKOUT) Enable bit. SYSCON.7
__WRCFG LIT '0' ; 0 = Normal operation of WR# end BHE# (default)
; 1 = WR# acts as WRL#. BHE# acts as WRH#
; System Clock Output (CLKOUT) Enable bit. SYSCON.8
__CLKEN LIT '0' ; 0 = disabled (Default)
; 1 = enabled
; Byte High Enable (BHE#) pin control bit. SYSCON.9
__BYTDIS LIT '0' ; 0 = enabled (Default)
; 1 = disabled
; Internal ROM Access Enable (Read Only). SYSCON.10
; Default state is determined by the state
; of the #EA pin at reset
; Segmentation Disable control bit. SYSCON.11
@IF( @EQS( @MODEL, "TINY" ) & NOT (@EVA) )
__SGTDIS LIT '1' ; Disable segmented memory mode
; for TINY model and NOT EVA
@ELSE
__SGTDIS LIT '0' ; Default is segmentation enabled
@ENDI
; ROM Segment Mapping control bit. SYSCON.12
__ROMS1 LIT '0' ; 0 = Internal ROM mapped to segm.0 (default)
; 1 = Internal ROM mapped to segm.1
; Stack Size selection of between 32 and 512 words. SYSCON[15..13]
__STKSZ LIT '0' ; System stack sizes
; 0 = 256 words (Default)
; 1 = 128 words
; 2 = 64 words
; 3 = 32 words
; 4 = 512 words
; 7 = No wrapping
; Process SYSCON low byte and high byte values.
SYSC_L EQU (__WRCFG << 7)
SYSC_H EQU ((__STKSZ << 5) | (__ROMS1 << 4) | (__SGTDIS<<3) | (__BYTDIS<<1) | __CLKEN)
SYSC_M_L EQU 080H ; Mask low byte SYSCON.
SYSC_M_H EQU 0FBH ; Mask high byte SYSCON.
@IF( @EVA )
; Symbols __EVA_SYSCON and __EVA_MEMSZ should be defined when the
; XVW166 debugger uses the EVA167 target board as its execution
; environment.
; They let the debugger configure the target environment correctly
; before the boot program downloads the monitor program MON167.
;
__MEMSZ LIT '0' ; EVA167 Memory configuration
; 0 = 1 MBit RAM (Default)
; 1 = 2 MBit RAM
; 2 = 4 MBit RAM
__EVA_SYSCON EQU ((SYSC_H << 8) | SYSC_L)
__EVA_MEMSZ EQU __MEMSZ
PUBLIC __EVA_SYSCON,__EVA_MEMSZ
@ENDI
@ELSE
@IF( @FUZZY_DEMO )
__MCTC LIT '0FH' ; Memory wait states is 15 (MCTC = 00H).
__RWDC LIT '0' ; Delay Time
__MTTC LIT '1' ; No Delay Time
@ELSE
; Memory Cycle Time is extended by a number of additional State Times.
; in a range from 0 through 15. SYSCON[3..0]
__MCTC LIT '1' ; Memory wait states is 1 (MCTC = 0EH).
; (Default=15 additional state times)
; At least 1 waitstate is needed
; for EVA166 to meet the EPROM
; specification.
; The Read/Write Signal Delay is 0.5 or 0 State Times. SYSCON.4
__RWDC LIT '1' ; 0 = Delay Time (Default)
; 1 = No Delay Time
; If multiplexed bus mode is selected
; RWDC must be set to 0 for EVA166.
; Memory Tri-state is extended by either 1 or 0 State Times. SYSCON.5
__MTTC LIT '0' ; 0 = Delay Time (Default)
; 1 = No Delay Time
; Default is expected that Tri-state
; delay is needed for memory.
@ENDI
; BTYP is read only for external bus configurations. SYSCON[7..6]
; System Clock Output (CLKOUT) Enable bit. SYSCON.8
__CLKEN LIT '0' ; 0 = disabled (Default)
; 1 = enabled
; Byte High Enable (BHE#) pin control bit. SYSCON.9
__BYTDIS LIT '0' ; 0 = enabled (Default)
; 1 = disabled
; Internal ROM Access Enable (Read Only). SYSCON.10
; Segmentation Disable control bit. SYSCON.11
@IF( @EQS( @MODEL, "TINY" ) & NOT (@EVA) )
__SGTDIS LIT '1' ; Disable segmented memory mode .
; for TINY model and NOT EVA
@ELSE
__SGTDIS LIT '0' ; Default is segmentation enabled.
@ENDI
; READY# Input Enable control bit. SYSCON.12
__RDYEN LIT '0' ; 0 = disabled (Default)
; 1 = enabled
; Stack Size selection of between 32 and 256 words. SYSCON[14..13]
__STKSZ LIT '0' ; System stack sizes
; 0 = 256 words (Default)
; 1 = 128 words
; 2 = 64 words
; 3 = 32 words
; Process SYSCON low byte and high byte values.
SYSC_L EQU ((__MTTC << 5) | (__RWDC << 4) | ((~__MCTC) & 000FH))
SYSC_H EQU ((__STKSZ << 5) | (__RDYEN <<4) | (__SGTDIS << 3) | (__BYTDIS << 1) | __CLKEN)
SYSC_M_L EQU 03FH ; Mask low byte SYSCON.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -