📄 c0startup.asm
字号:
;/*
; $Workfile: C0startup.asm $
; $Revision: 1.1 $
; $Date: May 12 2003 17:57:10 $
;*/
;//******************************************************************************
;//
;// Copyright (C) 2002. GENESIS MICROCHIP INC.
;// All rights reserved. No part of this program may be reproduced.
;//
;// Genesis Microchip Inc., 165 Commerce Valley Dr. West
;// Thornhill, Ontario, Canada, L3T 7V8
;//
;//==============================================================================
;//
;// MODULE: C0Startup.asm
;//
;// USAGE: This module contains system and External ROM data initialization
;//
;//******************************************************************************
.186 ; Required for target independence
;//******************************************************************************
;// L O C A L D E F I N I T I O N S
;//******************************************************************************
;
; Some options can be disabled to reduce the size of the startup code
; and run-time library helper code. Simply place a semicolon in front
; of the following definitions to remove support for selected item.
;
; __ENABLE_EXCEPTIONS Includes C++ exception handling support
;
__ENABLE_EXCEPTIONS = 1 ;
__IROM_DATA_END = 00400h ; Internal ROM data end - note, leaving room for irom expansion
;;;__IROM_FAILED = 1 ; If internal ROM not working properly
;//******************************************************************************
;// T E X T S E G M E N T D E F I N I T I O N S
;//******************************************************************************
;
; Segment and group declarations. The order of these declarations is
; used to control the order of segments in the .ROM file since the
; Paradigm linker copies segments in the same order they
; are encountered in the object files.
;
; Make sure that this startup module is specified first when linking
; the application.
;
_TEXT segment para public use16 'CODE' ; Default code
_TEXT ends
;//******************************************************************************
;// R O M D A T A S E G M E N T D E F I N I T I O N S
;//******************************************************************************
;
; These are segment definitions for the classes ROMDATA and ENDROMDATA. Class
; ROMDATA never contains anything (it is filled in by a Paradigm LOCATE DUP
; directive). Class ENDROMDATA is used to mark the end of class ROMDATA and
; prevent a segment alias (since class ROMDATA will have zero length).
;
; NOTE: You can't take the address of segments in class ENDROMDATA as they are
; aliased with class ROMDATA.
;
_RD segment para public use16 'ROMDATA'
public _romdata_start ; Mark the start of class ROMDATA
_romdata_start label byte
_RD ends
_ERD segment para public use16 'ENDROMDATA'
public _romdata_end ; Mark the end of class ROMDATA
_romdata_end label byte
db 16 dup (?) ; Force the next segment to a new paragraph
_ERD ends
;//******************************************************************************
;// D A T A A N D B S S S E G M E N T D E F I N I T I O N S
;//******************************************************************************
;
; These are the segment definitions for class DATA and BSS.
; the size of class DATA is calculated by subtracting the offset of _DATA
; from the offset _BSS. The size of the BSS is done by subtracting the
; offset of _BSS from the offset of _NVRAM.
;
_DATA segment para public use16 'DATA' ; Initialized data
org __IROM_DATA_END ; Buffered for Internal ROM RAM usage
public _initialized_data_start ; Offset zero within the DATA class
_initialized_data_start label byte
_DATA ends
DGROUP group _DATA
_BSS segment para public use16 'BSS' ; Uninitialized data
public _uninitialized_data_start ; Offset zero within the BSS class
_uninitialized_data_start label byte
_BSS ends
DGROUP group _BSS
_NVRAM segment para public use16 'NVRAM' ; Dummy NVRAM para to make linker happy
db 16 dup (?)
_NVRAM ends
DGROUP group _NVRAM
;//******************************************************************************
;// E X T E R N A L F U N C T I O N S
;//******************************************************************************
IFDEF __ENABLE_EXCEPTIONS
extrn __ExceptInit:far ; Exception handling initialization
ENDIF
extrn _gmi_RamInit:far ; Initialiization for internal ROM
extrn _main:far ; User application entry point
;//******************************************************************************
;// C O D E
;//******************************************************************************
_TEXT segment
assume cs:_TEXT
_XROM_Initialization proc far ; Startup code entry point
public _XROM_Initialization
call _gmi_RamInit ; If IROM_Initialization fail
; to operate, system setup code
; will insert here.
IFDEF __IROM_FAILED
;;;
;;; Disable interrupts and force the forward direction
;;;
cli
cld
;;;
;;; Set UMCS base address to 0xF0000 and
;;; READY Generation = 0 Wait states, and external READY also used
;;;
mov dx, 0FFA0h ; Upper Memory Chip Select Register (UMCS)
mov ax, 0F038h ; A(18:16)=0x7, R(4:0)=0x18
out dx, ax
ENDIF
;;;
;;; Prepare the segment registers for initialization. The initialized
;;; data is assumed to have been located in the class ROMDATA which begins
;;; with the segment _RD.
;;;
mov ax, DGROUP
mov es, ax
mov ax, _RD
mov ds, ax
assume ds:_RD, es:DGROUP
;;;
;;; Copy DGROUP initialized data from its position in ROM to the target
;;; address in RAM. Because this is a group, there is never more than
;;; 64K of data to copy.
;;;
mov si, offset _romdata_start
add si, __IROM_DATA_END
;;;
;;; Beginning of initialized data
;;;
mov di, offset DGROUP:_initialized_data_start
;;;
;;; End of initialized data
;;;
mov cx, offset DGROUP:_uninitialized_data_start
sub cx, di
shr cx, 1
jcxz $$Copy_Data
rep movsw
$$Copy_Data:
mov ax, DGROUP
mov ds, ax
mov es, ax
assume ds:DGROUP, es:DGROUP
IFDEF __IROM_FAILED
;;;
;;; Zero out the uninitilized data area (8K bytes - Internal RAM Area (4K bytes) - _DATA - (SP - 1))
;;;
xor ax, ax
;;;
;;; Beginning of uninitialized data
;;;
mov di, offset DGROUP:_uninitialized_data_start
mov cx, SP
sub cx, 1
sub cx, di
shr cx, 1
jcxz $$Inti_OnChip_RAM
rep stosw
$$Inti_OnChip_RAM:
;;;
;;; Relocate the T186 Peripheral Register Block
;;; to memory space 0A000h
;;;
mov dx, 0FFFEh ; Relocation Register
mov ax, 010A0h ; MIO=0x1, RA(19:8)=0x026
out dx, ax
ENDIF
;;;
;;; Memory is now initialized. We need to initialize the exception handling
;;; logic and call any linked in initializers before handling control over to
;;; the user code.
;;;
mov bp, 0h
IFDEF __ENABLE_EXCEPTIONS
push bp
call __ExceptInit
pop ax
ENDIF
;
; Call the C entry point main() - initialization is complete and user
; application can take control.
;
jmp _main
_XROM_Initialization endp
;;;
;;; Called by the exit handling code to execute C++ static destructors and
;;; any #pragma exit routines.
;;;
__cleanup proc dist
public __cleanup
ret
__cleanup endp
_TEXT ends
end _XROM_Initialization ; Program entry point
;//********************************* END **************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -