/* Copyright 1986 by the Massachusetts Institute of Technology */

/* This file contains the machine dependent parts of the operating system
 * for a uVAX.
 */

.set	IPLR,0x12	/* The IPL processor register */
.set	_cpmbx,0x200B801C /* Console Program Mailbox */
	.globl	_cpmbx

	.globl	_md_inth
/* This routine gets all the interrupts. The address of the DCT is on the
 * stack upon entry. It saves the registers and calls the interrupt
 * handler specified in the DCT. The address of the DCT is passed to the
 * interrupt handler.
 */
_md_inth:
	pushr	$0x3fff		/* Save all registers */
	mtpr	$0x1f,$IPLR	/* disable all interrupts */
	movl	14*4(sp),r0	/* get DCT address */
	pushl	r0		/* DCT address is argument to int handler */
	movl	12(r0),r0	/* get address of interrupt handler */
/*		 ^
 * This is a magic number. */
	calls	$1,(r0)		/* call interrupt handler */
	popr	$0x3fff		/* restore registers */
	addl2	$4,sp		/* remove DCT address from stack */
	rei

	.globl	_disable
/* Disables interrupts and returns the previous state of the status
 * register
 */
_disable:
	.word	0
	mfpr	$IPLR,r0
	mtpr	$0x1f,$IPLR
	ret

	.globl	_enable
/* Sets the status register to the passed value. This should be the return
 * value from a previous disable call.
 */
_enable:
	.word	0
	mtpr	4(ap),$IPLR
	ret


	.globl	_swab
/* Byte swaps the short word passed as an argument.
 */
_swab:	.word	0
	rotl	$8,4(ap),r0
	movb	5(ap),r0
	movzwl	r0,r0
	ret

	.globl	_swabl
/* Byte swaps and word swaps the long word passed as an argument.
 * i.e. 0,1,2,3 --> 3,2,1,0.
 */
_swabl:	.word	0
	movb	7(ap),r0
	insv	6(ap),$8,$8,r0
	insv	5(ap),$16,$8,r0
	insv	4(ap),$24,$8,r0
	ret
