# IDT stuff NOT INLINED at setup
#    install sets an event response (INT vector, reflex) in the IDT. 


L VMinstall		# install an interrupt gate in the veal mode IDT  

			# this has to be veal mode code for transients,
			# but init can be done in whatever

			# use16 code to build a gate descriptor
			# no trap gate option here
			# Reflex address in A
			# int vector # in DI

       = 16 to B                # pre-shifted GDT selector 2, ring0 CS
       = 14 to C		# 386 interrupt gate
       upshift 3 to DI		#    vector # is now IDT offset
       + $VMIDT to DI		#     now DI is the address of the gate
				# call-by-fall-through

#L makegate		# construct a gate descriptor at DI;4+DI in mem. 
			#	CS offset to handler code in A
			#	gate type in C
			 #       address of gate in DI
			    #	ASSUMES DPL ZERO
       = A to D				# copy offset
       = D to @ DI
			# low dual in place

      	OR  0x10 to D 			# high dual is ring0 CS selector
	= D to @ 2 DI
			# low quad in place
       upshift 8 to C			# gate type up a byte			
       OR 0x8000  to C			# marked present
          = C to @ 4 DI
                       return

			
					# these have to be veal mode code
					# use16, OOS the dismisses
L VMtwitch
push A
push DS
	= 0xb8000 to A
	= A to DS
	= @ 2610 to A
	1+ A
	= A to @ 2610
pull DS
pull A
otheroperandsize ; dismiss



L VMIRQtwitch
push A
push DS
	= 0xb8000 to A
	= A to DS
	=  @ 274	 to A 		# no regs
	1+ A
	= A to @  274
	# EOIRQ
		push D
			= `binary 00100000` to A
			= 0xa0 to D
			send byte
			= 0x20 to D
			send byte
		pull D
pull DS
	pull A
otheroperandsize ; dismiss



L VMIRQ0twitch
push A
push DS
	= 0xb8000 to A
	= A to DS
	= @  110	 to A # no regs
	+ 1111 to A
	= A to @ 110
	# EOIRQ
		push D
			= `binary 00100000` to A
			= 0xa0 to D
			send byte
			= 0x20 to D
			send byte
		pull D
pull DS
pull A
otheroperandsize ; dismiss



L VMIDTpointer
HL
ad 2048
aq $VMIDT











echo "
.........................................................................
                                80386 INTERRUPT GATE
   31                23                15                7                0
  -------------------------------------------------------------------------
  -           OFFSET 31..16           - P -DPL-0 1 1 1 0-0 0 0-(NOT USED) -4
  -------------------------------------------------------------------------
  -             SELECTOR              -           OFFSET 15..0            -0
  -------------------------------------------------------------------------


Figure 5-6.  Format of a Selector
						TYPO INDEX IS 13 bits.
                         15                      4 3   0
                        ---------------------------------
                        -                         -T-   -
                        -           INDEX         - -RPL-
                        -                         -I-   -
                        ---------------------------------

                         TI  - TABLE INDICATOR
                         RPL - REQUESTOR'S PRIVILEGE LEVEL


" > /dev/null
