📄 start.s
字号:
;**********************************************************************
; Copyright 1993 Software Development Systems, Inc.
; All rights reserved
;
; Example startup code for the 68000 family to initialize RAM
; and call the user function main().
;**********************************************************************
XDEF START,__brkp,__brksz,__exit
XREF STKTOP,DATA,_main
;***********************************************************************
; If C++ style startup code is not desired, then
; define CPLUSPLUS to 0
;***********************************************************************
CPLUSPLUS = 1
;**********************************************************************
; Define variables to track memory allocations for mbrk().
;**********************************************************************
SECTION ram
__brkp DS.L 1 ; point to available memory
__brksz DS.L 1 ; number of available bytes
;***************************************************************
; The reset vector will point to this code (START).
; By the time we get here, A7 will have been initialized.
;***************************************************************
SECTION code
.STK "none" ; terminate call chain for -OG
START MOVE.L #STKTOP,A7 ; set the stack pointer
MOVE.L #0,A6 ; terminate call chain for -Og
;***********************************************************
; Zero out uninitialized RAM.
;***********************************************************
MOVE.L #`BASE(ram),A1 ; A1 = base of region ram
MOVE.L #`SIZE(ram),D0 ; D0 = size of region ram
LSR.L #2,D0 ; compute size in longs
BRA ZDBF ; enter a fast loop
ZLP: CLR.L (A1)+ ; clear four bytes at a time
ZDBF: DBF D0,ZLP ; up to 256K in inner loop
SUB.L #$10000,D0 ; rest in outer loop
BHS ZLP
;***********************************************************
; Initialize other RAM from ROM.
;***********************************************************
MOVE.L #DATA,A0 ; A0 = ROM base of region data
MOVE.L #`BASE(data),A1 ; A1 = RAM base of region data
MOVE.L #`SIZE(data),D0 ; D0 = size of region data
LSR.L #2,D0 ; compute size in longs
BRA IDBF ; enter a fast loop
ILP: MOVE.L (A0)+,(A1)+ ; move four bytes at a time
IDBF: DBF D0,ILP ; up to 256K in inner loop
SUB.L #$10000,D0 ; rest in outer loop
BHS ILP
;***********************************************************
; Initialize memory allocator.
;***********************************************************
MOVE.L #`BASE(malloc),D0 ; address of malloc region
MOVE.L #`SIZE(malloc),D1 ; size of malloc region
.IF "ptrd"?"2"
SWAP D0 ; handle 2-byte C "pointers"
.ENDIF
.IF "long"?"2"
SWAP D1 ; handle 2-byte C "longs"
.ENDIF
MOVE.L D0,__brkp ; vars referenced by mbrk()
MOVE.L D1,__brksz
.IF CPLUSPLUS
;***********************************************************
; Call any C++ initializer thunks.
;***********************************************************
MOVE.L #`BASE(init),A5 ; A5 = base of region init
MOVE.L #`SIZE(init),D7 ; D7 = size of region init
.IF "ptrf"?"2"
LSR.L #1,D7 ; number of initializer thunks
.ELSE
LSR.L #2,D7 ; number of initializer thunks
.ENDIF
BRA NDBF ; enter loop
NLP:
.IF "ptrf"?"2"
MOVE.W (A5)+,A0 ; get address of thunk
.ELSE
MOVE.L (A5)+,A0 ; get address of thunk
.ENDIF
CMP.W #0x4E71,A0 ; NOP may pad region
BEQ NDBF
JSR (A0) ; call initializer thunk
NDBF: DBF D7,NLP ; up to 256K in inner loop
SUB.L #$10000,D7 ; rest in outer loop
BHS NLP
.ENDIF
;***********************************************************
; Invoke main() with no arguments.
;***********************************************************
JSR _main ; "int" return value in D0
;***********************************************************
; Call any C++ exit thunks.
;***********************************************************
__exit
.IF CPLUSPLUS
MOVE.L #`BASE(exit),A5 ; A5 = base of region exit
MOVE.L #`SIZE(exit),D7 ; D7 = size of region exit
ADD.L D7,A5 ; reverse order
.IF "ptrf"?"2"
LSR.L #1,D7 ; number of exit thunks
.ELSE
LSR.L #2,D7 ; number of exit thunks
.ENDIF
BRA XDBF ; enter loop
XLP:
.IF "ptrf"?"2"
MOVE.W -(A5),A0 ; get address of thunk
.ELSE
MOVE.L -(A5),A0 ; get address of thunk
.ENDIF
CMP.W #0x4E71,A0 ; NOP may pad region
BEQ XDBF
JSR (A0) ; call exit thunk
XDBF: DBF D7,XLP ; up to 256K in inner loop
SUB.L #$10000,D7 ; rest in outer loop
BHS XLP
.ENDIF
DONE BRA DONE ; loop if main ever returns
;**********************************************************************
; RESET VECTOR: to supervisor program space at address 0.
;**********************************************************************
SECTION reset
DC.L STKTOP ; initial stack pointer
DC.L START ; initial execution address
;**********************************************************************
; OTHER EXCEPTION VECTORS: to supervisor data space at address 8,
; or 8 bytes beyond where the vector base register will point.
; This table is commented out because no actual interrupt rou-
; tines are provided.
;**********************************************************************
; SECTION vects
; DC.L BUSERROR,ADRERROR ; 0x08
; DC.L ILLEGAL,ZERODIV,CHK,TRAPV ; 0x10
; DC.L PRIVILEGE,TRACE,EMULA,EMULF ; 0x20
; DC.L RESVD,PROTO,FORMAT,UNINIT ; 0x30
; DCB.L 8,RESVD ; 0x40
; DC.L SPURIOUS,AUTO1,AUTO2,AUTO3 ; 0x60
; DC.L AUTO4,AUTO5,AUTO6,AUTO7 ; 0x70
; DC.L TRAP0,TRAP1,TRAP2,TRAP3 ; 0x80
; DC.L TRAP4,TRAP5,TRAP6,TRAP7 ; 0x90
; DC.L TRAP8,TRAP9,TRAPA,TRAPB ; 0xa0
; DC.L TRAPC,TRAPD,TRAPE,TRAPF ; 0xb0
; DC.L FUNORD,FNEXACT,FZERODIV,FUNFLOW ; 0xc0
; DC.L FOPND,FOVFLOW,FSNAN,RESVD ; 0xd0
; DCB.L 8,RESVD ; 0xe0
; DCB.L 192,USER ; 0x100
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -