 # @(#)def.s	- SWIFT    1.0	12/10/90
 # @(#)Copyright (C) 1990  National Semiconductor Corp.

 #
 # def.s file includes all the global constants and variables
 #


 #
 # this file includes all the constants and sb variable offsets of the
 # monitor and the diagnostics
 #
 #
 #
 #  global constants
 #
#ifdef RAM
        .set    modad, 0x8000		# monitor mod table
        .set    dataad, 0x8010		# monitor data address

#else
        .set    modad, 0x200		# monitor mod table
        .set    dataad, 0x210		# monitor data address
	.set	prom_start, 0x400000	# PROM location
#endif
	.set	demo_entry, 0x408000	# default demo entry 
	
	.set	is_size,    0x400	# interrupt stack size (in bytes)
	.set	mon_stack_size,	0x200	# monitor stack size
	.set	ram_start, 0x0		# start of RAM
        .set    timeout,1		# timeout error

 # Protocol errors stored in proerr(sb):

 #      0       no error
 #      1       timeout while in get char loop
 #      2       not used
 #      3       illegal char in the command length field
 #      4       command too short (no. of char received < command length)
 #      5       illegal char in the crc field
 #      6       crc error
 #
        .set    stalon, 0             	# stand alone indicator
        .set    transp, 1             	# transparent mode
        .set    true, 1               	# define logical true
        .set    false, 0              	# define logical false
        .set    trma, 0               	# terminal a
        .set    trmb, 1               	# terminal b
        .set    nswbpt, 14             	# number of software break-points
        .set    mncfg, 0              	# monitor cfg reg. value #### not used
        .set    cfg_de, 8             	# cfg direct exception bit
        .set    cfg_dc,9              	# cfg data cache enable bit
        .set    cfg_ic,11             	# cfg instruction  cache enable bit
        .set    psr_u, 8              	# u bit in psr
        .set    psr_t, 1              	# t bit in psr
        .set    psr_s, 9              	# s bit in psr
        .set    psr_p, 10             	# p bit in psr
        .set    psrs, 0x200           	# psr s number
        .set    psrt, 2               	# psr t number
        .set    pce_dcr,20            	# pce bit in dcr (pc match enable)
        .set    crd_dcr,6             	#crd bit in dcr (addr compare for read)
        .set    bptc, 0xf2            	# bpt instruction
        .set    rxpc,0x32             	# rxp instruction
        .set    puti,1                	# put indication for get_put procedure
        .set    cfgn,20               	# cfg number in get_put procedure
        .set    handb,0               	# hand_shaking bit of opmod word
        .set    handlf,1              	# on hand_shaking cr echo is lf
        .set    echob,2               	# echo bit
        .set    echolf,3              	# flag for echo to cr by cr lf
 #
 #  ascii characters
 #
        .set    cntra, 0x1            	# cntr/a
        .set    cntrt, 0x14           	# cntr/t
        .set    cr, 0x0d              	# return
        .set    lf, 0x0a              	# line feed
        .set    dot, 0x2e             	# dot
        .set    comma, 0x2c           	# comma character
        .set    space, 0x20           	# space character
 #
 # ***************************************************************
 #        global variables   (sb relative)
 # *************************************************************** 
 #

    .dsect	globals,	0
opmod:		.blkb		# operation mode variable
ophnd:		.blkb		# operation mode hand_shaking
mon_usr:	.blkb		# monitor/user time flag
pndf:		.blkb		# pending interrpts flag
dtrm:		.blkd		# pointer to defult terminal buffer
ndtrm:		.blkb		# num of defult terminal
svcpf:		.blkb		# svc flag for read/write for movus
errtyp:		.blkb		# entry type
com_num:	.blkb		# save command number
    .align 4
scrch1:		.blkd		# scratch 1
scrch2:		.blkd		# scratch 2
svsize:		.blkd		# size of return value in getput.
strtadr:	.blkd		# save raddress
endadr:		.blkd		# save end interrupt routine address
serea:		.blkd		
svfp:		.blkd		# save fp
svus:		.blkd		# save us
svis:		.blkd		# save is
svpc:		.blkd		# save pc
svmod:		.blkd		# save mod
svpsr:		.blkd		# save psr
svsb:		.blkd		# save sb
svcfg:		.blkd		# save cfg
svr7:		.blkd	7	# save r
svr0:		.blkd		# save r0
svmcr:		.blkd		# save mcr 
tmppsr:		.blkd		
tmpmcr:		.blkd		# temporay save mcr
svmsr:		.blkd		# save run time msr
mnmsr:		.blkd		# monitor time msr 
heapp:		.blkd		# heap pointer
heape:		.blkd		# heap end
heaps:		.blkd		# heap begin
mcrwf:		.blkd		# mcr written flag
mnpsr:		.blkd		# monitor psr
mnfp:		.blkd		# save monitor fp
mnmcr:		.blkd		# save monitor mcr
mnsp:		.blkd		# save monitor sp
mnsph:		.blkd		# monitor high sp
brkar:		.blkd	nswbpt	# soft-bpr array
stepflg:	.blkb		# step flag
ackflg:		.blkb		# acknowledge flag
cxpflg:		.blkb		# cxp command counter
ins:		.blkb	nswbpt	# array of brpr instruction save
monusr1:	.blkb		# temp save of mon_user flag
    .align 4
stpcnt:		.blkd		# step counter
actbrk:		.blkd		# # of current break
oldpc:		.blkd   2	# save old pc,us,is,mod in cxp command
endpc:		.blkd		# pc of inserted bpt on stack
endpc1:		.blkd		# pc of begin when cxp also
cntrlb:		.blkb		# cntrl/b starts every command     
cntrll:		.blkb		# cntrl/l start fast load message
cntrls:		.blkb		# cntrl/s hold screen
cntrlq:		.blkb		# cntrl/q resume screen
    .align 4
stptype:	.blkd		# step type (step while,step until etc)
stuadd:		.blkd		# stu command variable address
stpmsk:		.blkd		# step until/while mask
stpup:		.blkd		# upper bound in step while/until
stplow:		.blkd		# lower bound of step while/until
rstint:		.blkd		# save reset value of intbase
lstfrm:		.blkb		# $$$ frame number of last command
prot_chng:	.blkb		# $$$ protocol is going to be changed
protoc:		.blkb		# $$$ 1 if new protocol, 0 if old
proerr:		.blkb		# $$$ protocol error
curfrm:		.blkb		# $$$ current frame number
profld:		.blkb		# $$$ binary load in new protocol
fldfrm:		.blkb		# $$$ current frame is fast load frame
    .align 4
timcnt:		.blkd		# $$$ timer/counter (new protocol use)
t1pckh:		.blkd   	# $$$ header field for term1 packet
ram_size:	.blkd		
    .align 4
jmpram:		.blkb	0x10	# scratch pad area for lpr cfg emulation
    .align 4
rbptf:		.blkd		# rem bpt flag
fpubuf:		.blkd	4	# working buffer for getput fpu lregs 
 #
term1:		.blkd	137	# terminal 1 record
t2pckh:		.blkd		# $$$ header field for term2 packet
term2:		.blkd	137	# terminal 2 record
sresp:		.blkd		# $$$ response saved for retransmission
esbvar:		.blkd		# $$$ end of static base variables
force_serial:	.blkb		# force use of serial link on Ethernet
		.align		0x16
stacks:		.blkb		is_size  # alloctae intterupt stack space
svrsp:		.blkd
		.blkb		mon_stack_size
stackl:		.blkd
end_local_vars:


 #
 # **************************************************************
 #        end  of  global  variables
 # **************************************************************
 #
 
 #  other constatnts

	.set	cnfmmu,2		# mmu bit in configuration
        .set    mont, 0			# flag monitor time
        .set    usert, 1		# flag user time
        .set    pndmod, 2		# flag to delay interrupts
 

 #
 #  terminal record
 #
        .set    inlen, 0x220   		# length of input buffer (544 bytes)
        .set    inbuf, 0       		# input bufer
        .set    inlm, inbuf+inlen	# offset into inbuf of last character 
					#  read
        .set    outb, inbuf    		# output buffer (same as input )
        .set    outlm, inlm    		# pointer to last byte in outb to be 
					#  printed
        .set    trmrlg, inlm+4 		# terminal record length
  

 #
 # Configuration register
 #
	.set	esr, 0x0f80200		# External Status Register (Read)
	.set	edr, 0x0f80200		# External Data Register (Write)
	.set	cfr, 0x0f88000		# Configuration Register
	.set	switchp, esr		# address of config. switch
	.set	baud, 0x1		# mask lower bit for baud select
	.set	demo_bit, 1
	
    #
    # Z8530 SCC (Serial Comunication controler) Const
    #
#ifndef RAM
	.set	scc1,	    0xf80000  # Channel A (User)
	.set	scc0,	    0xf80002  # Channel B (Dbug)
#else
	.set	scc1,	    0xf80002  # Channel A (Dbug)
	.set	scc0,	    0xf80000  # Channel B (User)
#endif
	.set	in_rdy,	    0
	.set	out_rdy,    2



 #
 # Seven segment LED location
 #


count := 0
#define	SWIFT

.macro INIT_CFG
	movd	$0x100, r1
	movd	r1, svcfg(sb)
        bsr     lprw_cfg_r1
.endm 

.macro PRINT_SB	dest
        movd    svsb(sb),{dest}
.endm

.macro	RESTORE_SB
	lprd    sb,svsb(sb) 
.endm

.macro	SAVE_SB
	sprd	sb, tos
	lprd	sb, $dataad
	movd	tos, svsb(sb)
.endm

.macro CHANGE_SB        src
	movd    {src},svsb(sb)
.endm



 
 
 
    ########################################################################
    #
    # SCC Z8530 macros.
    #
    #   R0 is used as in-macro volatile register
    #   Note: the A/B line of Z8530  is connected on the SWIFT to addr2 line
    #         the C/D line of Z8530  is connected on the SWIFT to addr1 line
    #   This mean that: 
    #                   port A - Data register is in    *UART-ADDRESS* + 0
    #                   port B - Data register is in    *UART-ADDRESS* + 2
    #                   port A - Control register is in *UART-ADDRESS* + 4
    #			port B - Control register is in *UART-ADDRESS* + 6



    #
    # Wait is used for delay of 1.2 micro sec between two access to SCC device
    #


    .set WAIT_COUNT,  20
    .macro wait
     # Lior: No need for delay on Swift
     #       movd    $WAIT_COUNT, r0  
     #  Loop..{count}:
     #         acbb    $(-1), r0, Loop..{count}
     #    count := {{count} + 1}
    .endm
 

    #
    # sreg selects regn as the next accessed register for read or write
    # It accepts the chanell addrress & the register number.
    #
    .macro sreg   portp, regn
            movb        ${regn}, 4({portp})
            wait
    .endm
    

    .macro read_reg portp, regn, dest_reg
        .if {regn} = 8  # Read data reg directly
            movb        0({portp}), {dest_reg}
            wait
        .elsif {regn} = 0 # Read command reg directly
            movb        4({portp}), {dest_reg}
            wait
        .else           # Read reg via control reg
            sreg        {portp}, {regn}
            movb        4({portp}), {dest_reg}  
            wait
        .endif
    .endm
 
    .macro write_reg portp, regn, val
        .if {regn} = 8  # Write data reg directly
            movb        {val}, 0({portp})
            wait
        .elsif {regn} = 0 # Write command reg directly
            movb        {val}, 4({portp})
            wait
        .else           # Write reg via control reg
            sreg        {portp}, {regn}
            movb        {val}, 4({portp})
            wait
        .endif
    .endm
 



