
 #
 # this file includes all the constants and sb variable offsets for the
 # monitor and the diagnostics
 #
 #
 #  global constants
 #
#if (defined (DEBUG) || defined (RAM))
	.set	modad, 0x0010
	.set	dataad, 0x0020
#else
        .set    modad, 0x8000		# monitor mod table
        .set    dataad, 0x8010		# monitor data address
#endif

        .set    is_size,    0x400       #interrupt stack size
        .set    mon_stack_size,0x200    #monitor stack size
 
  # ***** use 0 for downloadable monitor, or f0000000 to make PROM  dgm

 ###	.set	prom_start, 0x00000000	# downloadable test monitor
	.set	prom_start, 0xF0000000	# for monitor in PROM
	.set	demo_entry, 0xF0010000	# entry point to user application
	.set	ram_start, 0x0		# start of RAM
        .set    timeout,1		# timeout error

#ifdef	ETHER
        .globl  _Einit, _Eread, _Ewrite, _Eload
        .globl  _printflag
        .set    _printflag, 0x150000
#endif

 #--- communication type check macros -----#


.macro	br_on_serial	test_val,  dest
        andb    $0x7,{test_val}
        cmpqd   1,{test_val}
        blt     {dest}
.endm


	#this macro test for thin ethernet.
	# upon entrence {test_val} contains value read from dip switch
	# upon exit {test_val} = 1 if thin ethernet used, 
	#           {test_val} = 0 if thick ethernet used. 
.macro	thin_ether	test_val
		andd	$0x1, {test_val}
.endm

 # This macro translate dip switch value to integer in the range 0-7 used as
 # entry to divisor table for baud rate selecting.
 
.macro	dip_to_baud	test_val
		andd	$0x7, {test_val}
.endm


 # 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 comp for read)
        .set    bptc, 0xf2            	# bpt instruction
        .set    rxpc,0x32             	# rxp instruction
        .set    puti,1                	# put indication for get_put proc
        .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
tmppsr:		.blkd		
heapp:		.blkd		# heap pointer
heape:		.blkd		# heap end
heaps:		.blkd		# heap begin
mnpsr:		.blkw		# monitor psr
mnfp:		.blkd		# save monitor fp
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
curchr1:	.blkb		# current 1st command char
lstchr1:	.blkb		# last 1st command char
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		
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
#ifdef	ETHER
force_serial:	.blkb		# flag to force serial link
#endif

		.align		4
stacks:		.blkb		is_size  # allocate intterupt stack space
svrsp:		.blkd
		.blkb	mon_stack_size	# allocate monitor stack space
stackl:		.blkd

end_local_vars:
 
        .globl  _evars
        .set    _evars,         end_local_vars + dataad 


 #
 # **************************************************************
 #        end  of  global  variables
 # **************************************************************
 #
 
 #  other constants

	.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
 
 # ICU stuff

	.set	diag_sp, 0x8000		# stack pointer for ICU test
        .set    icu_addr, 0xfffffe00	# ADDRess of ICU
        .set    hvct, 0			# hdw vector
        .set    svct, 1			# sfw vector (bias setting)
        .set    eltg, 2			# edge/level trig (low)
        .set    eltg_2, 3		# edge/level trig (high)
        .set    tpl, 4			# trig polarity (low)
        .set    tpl_2, 5		# trig polarity (high)
        .set    ipnd, 6			# interrupts pending (low)
        .set    ipnd_2, 7		# interrupts pending (high)
        .set    isrv, 8			# intr in service (low)
        .set    isrv_2, 9		# intr in service (high)
        .set    imsk, 10		# interrupt mask (low)
        .set    imsk_2, 11		# interrupt mask (high)
        .set    csrc, 12		# cascaded source (low)
        .set    csrc_2, 13		# cascaded source (high)
        .set    fprt, 14		# first priority (low)
        .set    fprt_2, 15		# first priority (high)
        .set    mctl, 16		# mode control
        .set    ocasn, 17		# output clock assignment
        .set    ciptr, 18		# counter intr pointer
        .set    pdat, 19		# port/data
        .set    ips, 20			# intr/port select
        .set    pdir, 21		# port direction
        .set    cctl, 22		# counter control
        .set    cictl, 23		# counter intr control
        .set    lcsv, 24		# l-counter starting value (low)
        .set    lcsv_2, 25		# l-counter starting value (high)
        .set    hcsv, 26		# h-counter starting value (low)
        .set    hcsv_2, 27		# h-counter starting value (high)
        .set    lccv, 28		# l-counter current value (low)
        .set    lccv_2, 29		# l-counter current value (high)
        .set    hccv, 30		# h-counter current value (low)
        .set    hccv_2, 31		# h-counter current value (high)

        .set    sio_intr, 1             # serial I/O interrupt
        .set    clear, 0x40          	# clear ipnd register
        .set    frz, 3             	# mctl freeze bit
	.set	cfrz, 7			# mctl counter freeze bit

 #
 #  terminal record
 #
        .set    inlen, 0x420   		# length of input buffer
        .set    inbuf, 0       		# input buffer
        .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, 0xf0080480	# base ADDRess of uart 0 (even)
	.set	uart1, 0xf0080400	# base ADDRess of uart 1 (odd)

  # --- DS16552 DUART internal register address map ---------
	.set u_rx_data,         0       # rx. data
	.set u_tx_data,         0       # tx. data
	.set u_ier,             1       # interrupt enable register
	.set u_iir,             2       # interrupt identification register
	.set u_fifocr,          2       # FIFO control register (write)
	.set u_lcr,             3       # line control register
	.set u_mcr,             4       # MODEM control register
	.set u_lsr,             5       # line status registe
	.set u_msr,             6       # MODEM status register
	.set u_scratch,         7       # scratch register
	.set u_ldlr,            0       # (DLAB=1) LSB divisor latch register
	.set u_mdlr,            1       # (DLAB=1) MSB divisor latch register
	.set u_afr,             2       # (DLAB=1) alternate function register

 # --- common used bits in UART ---------
	.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



	
 #	.set	datap, 0		# transmit/receive register
 #	.set	dl_low, 0		# low byte of divisor value
 #	.set	ien_reg, 1		# interrupt enable register
 #	.set	dl_high, 1		# high byte of divisor value
 #	.set	ii_reg, 2		# interrupt ident register (read only)
 #	.set	fifo_cntl, 2		# fifo control register (write only)
 #	.set	lc_reg, 3		# line control register
 #	.set	mc_reg, 4		# modem control register
 #	.set	ls_reg, 5		# line status register
 #	.set	ms_reg, 6		# modem status register
 #	.set	sc_reg, 7		# 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
 #
 # 
 # Timer definition and assignments
 #
 
	.set	tmr_base, 0xf0080800	# base ADDRess of timer (INS8254-2)

 #
 # Configuration register
 #

	.set	dip_switch, 0xf0080000	# ADDRess of config. switch
	.set	baud, 0xf		# mask lower 4 bits for baud select
	.set	fpu, 4			# mask for fpu present

 #
 # Seven segment LED location
 #

	.set	led, 0xf0080100		# ADDRess of 7-segment LED display

 #
 # 	7-Segment Port:			L.E.D.
 #					   
 #	bit0 ---- a			   a
 #	bit1 ---- b			.-----.
 #	bit2 ---- c		      f |     | b     
 #	bit3 ---- d		        |  g  |
 #	bit4 ---- e			+-----+ 
 #	bit5 ---- f		        |     |
 #	bit6 ---- g		      e	|  d  | c
 #	bit7 ---- rom shadow		`-----'	
 #
 #  7-Segment patterns
 #
	.set	led_0,	0xc0		#	0 
	.set	led_1,	0xf9		#	1 
	.set	led_2,	0xa4		#	2 
	.set	led_3,	0xb0		#	3 
	.set	led_4,	0x99		#	4 
	.set	led_5,	0x92		#	5 
	.set	led_6,	0x82		#	6 
	.set	led_7,	0xf8		#	7 
	.set	led_8,	0x80		#	8 
	.set	led_9,	0x90		#	9 
	.set	led_A,	0x88		#	A 
	.set	led_b,	0x83		#	b 
	.set	led_C,	0xc6		#	C 
	.set	led_d,	0xa1		#	d 
	.set	led_E,	0x86		#	E 
	.set	led_F,	0x8e		#	F 
	.set	led_G,	0xc4		#	G 
	.set	led_H,	0x89		#	H 
	.set	led_J,	0xe1		#	J 
	.set	led_L,	0xc7		#	L 
	.set	led_P,	0x8c		#	P 
	.set	led_U,	0xc1		#	U 
	.set	led_Y,	0x91		#	Y 
	.set	led_vr,	0xc9		#	||
	.set	led_ho, 0xb6		#	_
	.set	led_run, 0xaf		#	r
	.set	led_bl,	0xff		#	blank 
	.set	ram_on, 0x80		#	turn on RAM
