⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cstart.asm

📁 上传一个带源代码的嵌入式实时多任务操作系统CMX
💻 ASM
📖 第 1 页 / 共 3 页
字号:
; @(#)cstart.asm	1.53
;*****************************************************************************
;*
;* MODULE	: cstart.asm
;*
;* DESCRIPTION	: C startup code for SAB 80C166/C167 microcontroller.
;*
;*		- 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	: 1994 Tasking Software B.V.
;*
;*****************************************************************************

; Following defines can be set on the command line of the macro pre-processor,
; with the DEFINE() control. ( Syntax:  DEFINE( identifier [, replacement] )

; Example:			       
;	m166 cstart.asm DEFINE(MODEL, LARGE) DEFINE(MUXBUS) DEFINE(FLOAT)
;

@IF( ! @DEFINED( @C167 ) )
  @SET( C167, 0 )		; set to 1 for SAB C167 microcontroller
@ENDI

@IF( ! @DEFINED( @FUZZY_DEMO ) )
  @SET( FUZZY_DEMO, 0 )		; set to 1 for fuzzy-166 evaluation kit
@ENDI

@IF( ! @DEFINED( @PXROS ) )
  @SET( PXROS, 0 )		; set to 1 for PXROS support
@ENDI

@IF( ! @DEFINED( @EVA ) )
  @SET( EVA, 1 )		; 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.
				; By default the 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( ! @DEFINED( @MUXBUS ) )
  @SET( MUXBUS, 0 )		; select non-multiplexed bus
@ENDI

@IF( @C167 )
  $EXTEND			; enable all SAB C167 extensions
  $NOMOD166			; disable the internal set of SAB 80C166 SFRs
  $STDNAMES(reg167b.def)	; load set of SAB C167 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

; The macro _BFWDNOP() expands to two NOP instructions when FIX_BFWD 
; is defined. This is used for a software bypass for the Erroneous Byte 
; Forwarding problem of older steps of the CPU. 
@IF( @DEFINED(FIX_BFWD) )
@DEFINE _BFWDNOP2()
	NOP
	NOP
@ENDD
@ELSE
@DEFINE _BFWDNOP2()
@ENDD
@ENDI


$CASE
$GENONLY
$DEBUG
$NOLOCALS

	NAME	CSTART			; module name.
	
@IF( @EQS(@MODEL,"LARGE") | @EQS(@MODEL,"SMALL") )
  @IF( @DEFINED( @CALLINIT))
	EXTERN	@CALLINIT:FAR		; optional call
  @ENDI
	EXTERN	_main:FAR		; start label user program.
@ELSE
  @IF( @DEFINED( @CALLINIT))
	EXTERN	@CALLINIT:NEAR		; optional call
  @ENDI
	EXTERN	_main:NEAR		; start label user program.
@ENDI

	PUBLIC	__IDLE			; cstart end
	PUBLIC	__EXIT			; address to jump to on 'exit()'.

@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

@IF( @C167 )
	; Memory Cycle Time is extended by a number of additional State Times.
	; in a range from 0 through 15. BUSCON0[3..0]
				; Reset value MCTC = 15 additional state times
  @IF( @NO_WAIT_STATES )
	__MCTC		LIT	'0'	; Memory wait states is 0 (MCTC = 0FH).
  @ELSE
	__MCTC		LIT	'1'	; Memory wait states is 1 (MCTC = 0EH).
  @ENDI

	; The Read/Write Signal Delay is 0.5 or 0 State Times. BUSCON0.4
	__RWDC0		LIT	'1'	; 0 = Delay Time (Reset value)
					; 1 = No Delay Time
	; Memory Tri-state is extended by either 1 or 0 State Times. BUSCON0.5
	__MTTC0		LIT	'0'	; 0 = Delay Time (Reset value)
					; 1 = No Delay Time

	; External bus configurations. BUSCON0[7..6]
					; After reset determined by the state 
					; of the port pins P0L.7 and P0L.6.
					; Note: coding changed in the SAB C167
					
	; ALE Signal is lengthened by either 1 or 0 State Times. BUSCON0.9
	; 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.

  @IF( @MUXBUS )
	__ALECTL0	LIT	'1'	; 1 = Delay Time (Reset value if pin #EA
					;     is low)
  @ELSE
	__ALECTL0	LIT	'0'	; 0 = No Delay Time (Reset value if pin
					;      #EA is high)
  @ENDI
	
	; READY# Input Enable control bit. BUSCON0.12
	__RDYEN0	LIT	'0'	; 0 = disabled (Reset value)
					; 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# and 
					; BHE# (Reset value)			
					; 1 = WR# acts as WRL#. 
					; BHE# acts as WRH#
					
	; System Clock Output (CLKOUT) Enable bit. SYSCON.8
	__CLKEN		LIT	'0'	; 0 = disabled (Reset value)
					; 1 = enabled

	; Byte High Enable (BHE#) pin control bit. SYSCON.9
	__BYTDIS	LIT	'0'	; 0 = enabled (Reset value)
					; 1 = disabled

	; Internal ROM Access Enable (Read Only). SYSCON.10
					; After reset determined by the state
					; of the #EA pin.

	; 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'	; Reset value is segmentation enabled
  @ENDI

	; ROM Segment Mapping control bit. SYSCON.12
	__ROMS1		LIT 	'0'	; 0 = Internal ROM mapped to 
					; segment 0 (Reset value)
					; 1 = Internal ROM mapped to segment 1

	; Stack Size selection of between 32 and 512 words. SYSCON[15..13]
	__STKSZ		LIT	'0'	; System stack sizes
					; 0 = 256 words (Reset value)
					; 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 (Reset value)
					; 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]
				; Reset value MCTC = 15 additional state times
    @IF( @NO_WAIT_STATES )
	__MCTC		LIT	'0'	; Memory wait states is 0 (MCTC = 0FH).
    @ELSE
	__MCTC		LIT	'1'	; Memory wait states is 1 (MCTC = 0EH).
					; At least 1 waitstate is needed
					; for EVA166 to meet the EPROM
					; specification.
    @ENDI


	; The Read/Write Signal Delay is 0.5 or 0 State Times. SYSCON.4
	; If multiplexed bus mode is selected RWDC must be set to 0 for EVA166.
    @IF( @EVA && @MUXBUS )
	__RWDC		LIT	'0'	; 0 = Delay Time (Reset value)
    @ELSE
	__RWDC		LIT	'1'	; 1 = No Delay Time
    @ENDI

	; Memory Tri-state is extended by either 1 or 0 State Times. SYSCON.5
	__MTTC		LIT	'0'	; 0 = Delay Time (Reset value)
					; 1 = No Delay Time
					; It is expected that the Tri-state
					; delay is needed for the memory.
  @ENDI

	; BTYP is read only for external bus configurations. SYSCON[7..6]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -