| Copyright 1984 by the Massachusetts Institute of Technology

| This file contains the machine dependent parts of the operating system
| for a 68000.

	.insrt	"../../include/maclib.a68"
	.insrt	"../../include/system.a68"
	.insrt	"../../include/struct.a68"


	.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:
	save	A0!A1!A2!A3!A4!A5!A6!A7!D0!D1!D2!D3!D4!D5!D6!D7
	disable			|disable all interrupts
	movl	sp@(16*4),a0	|get DCT address
	push	A0		|DCT address is argument to interrupt handler
	movl	a0@(10),a0	|get address of interrupt handler
|		    ^
| There needs to be a magic number here
	jsr	a0@		|call interrupt handler
	addql	#4,sp		|remove DCT address from stack
	restore
	addql	#4,sp		|remove DCT address from stack
	rte

	.globl	disable
| Disables interrupts and returns the previous state of the status
| register
disable:
	clrl	d0
	movw	sr,d0
	disable
	rts

	.globl	enable
| Sets the status register to the passed value. This should be the return
| value from a previous disable call.
enable:
	movl	sp@(4),d0
	movw	d0,sr
	rts

	.globl	bus_int
| This routine enables interrupts on the processor card.
bus_int:
	movb	#PCR:l,d0
	orb	#0x8,d0		| enable bus interrupts
	movb	d0,#PCR:l
	rts

	.globl	bswap
| This routine is used to byte swap packets.
| Called:	bswap(data, len)
|		byte	*data;	/* pointer to data to be byte swapped */
|		unsw	len;	/* number of bytes to byte swap */
bswap:
	movl	sp@(4),a0	|get data pointer
	movl	sp@(8),d0	|get length
	addql	#1,d0
	lsrl	#1,d0		|compute word (16 bit) count

	cmpl	#0,d0
	jne	2$
	movl	#.L1,sp@-
	jsr	bughalt

2$:	subql	#1,d0		|to get loop termination at the right time
1$:	movw	a0@,d1		|get data word
	rolw	#8,d1		|this should swap its bytes
	movw	d1,a0@+		|put data back and increment pointer
	dbf	d0,1$		|do it for all data
	rts

	.data
.L1:	.asciz		"zero length byte swap "
