 # @(#)def.s	1.0	3/29/89
 # @(#)Copyright (C) 1988 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
 #
	.set	iobase, 0x00fff800	# on-board io base address
	.set	io_offset,2
	.set	prom_start, 0x0040000	# PROM location
	.set	demo_entry, prom_start+0x8000 # default demo entry 
	.set	sycfg,0xfff800		# config reg
	.set	pidat,0xfffc22		# data port = 0 (switch of overlape)
	.set	picfg,0xfffc20		# data port = 0 (switch of overlape)
	
#ifdef  RAM
        .set    modad, 0x8000		# monitor mod table
        .set    dataad,0x8010		# monitor data address

#else
        .set    modad, 0x1000		# monitor mod table
        .set    dataad, 0x1010		# monitor data address
#endif
	.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
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:		.blkb		# mcr written flag
mnpsr:		.blkw		# 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
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
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
timcnt:		.blkw		# $$$ timer/counter (new protocol use)
t1pckh:		.blkd   	# $$$ header field for term1 packet
ram_size:	.blkd		
jmpram:		.blkb	0x10	# scratch pad area for lpr cfg emulation
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:

 	.globl	_evars
	.set	_evars,		end_local_vars + dataad
	.globl	_printflag
	.set	_printflag, 0x150000

 #
 # **************************************************************
 #        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
  
 # UART definition and assignments
	.set 	uart0, iobase+0x0580	# base address of uart 0 (odd byte)
	.set	uart1, iobase+0x0590	# base address of uart 1 (even byte)

	.set	datap, (0*io_offset)	# transmit/receive register
	.set	dl_low, (0*io_offset)	# low byte of divisor value
	.set	ien_reg, (1*io_offset)	# interrupt enable register
	.set	dl_high, (1*io_offset)	# high byte of divisor value
	.set	ii_reg, (2*io_offset)	# interrupt ident register (read only)
	.set	fifo_cntl,(2*io_offset)	# fifo control register (write only)
	.set	lc_reg, (3*io_offset)	# line control register
	.set	mc_reg, (4*io_offset)	# modem control register
	.set	ls_reg, (5*io_offset)	# line status register
	.set	ms_reg, (6*io_offset)	# modem status register
	.set	sc_reg, (7*io_offset)	# scratch register

	.set	out_rdy, 5		# transmitter holding register empty
	.set	in_rdy, 0		# receiver data register ready
	.set	u_ipnd, 0		# uart interrupt pending bit in iir
	.set	ls_chng, 6		# line status change interrupt
	.set	i_rdy, 4		# received data interrupt
	.set	o_rdy, 2		# transmitter holding register int.
	.set	ms_chng, 0		# modem status change interrupt

 #
 # Configuration register
 #

        .set    mwdat, iobase+0x400     # Mw data register address
        .set    mwctl, iobase+0x402     # Mw control register address
	.set    mwctl_ready_bit, 4

	mw_call_idx := 1
	.macro  MW_DO data
 	movb	{data}, @mwdat
	movb    $0x51, @mwctl
	mw_wait{mw_call_idx}:           # Loop until bit is cleared
	tbitb   $mwctl_ready_bit, @mwctl
	bfs mw_wait{mw_call_idx}
	mw_call_idx := {{mw_call_idx} + 1}
	.endm
	
	.set	switchp, mwdat 		# address of config. switch
	.set	baud, 0x1		# mask bit 0 for baud select
	.set	baud_bit, 3		# bit 3 for baud select
	.set	demo_bit, 2		# bit 2 for demo select



	.macro SAVE_SB
	.endm
	.macro RESTORE_SB
	.endm

	.macro INIT_CFG
	movqd	0,svcfg(sb)
	setcfg	[]
	.endm
	
	.macro PRINT_SB	dest
 	movd	0(svmod(sb)),{dest}
	.endm
	
	.macro CHANGE_SB	src
	movd	{src},0(svmod(sb))
	.endm

