* Include file for "Mouse" Kernel Services

*---------------------------*
* System object definitions *
*---------------------------*

* Field offsets for general queue descriptors

q@next     equ  0  pointer to head or next item
q@prev     equ  4  pointer to tail or previous item
q@head     equ  8  pointer to descriptor
q@lock     equ 12  lock bit + 31 reserved bits

* Semaphore queue descriptor fields

sq@count   equ 16  (if neg) - no of waiting PBs
sq@size    equ 20

* Run queue descriptor fields

rq@intreg  equ 16  pointer to processor int reg
*                 (local extension follows)
rq@next    equ 20  address of next RQ
rq@prev    equ 24  address of previous RQ
rq@size    equ 28

* Message queue descriptor fields

mq@sema    equ 16  pointer to associated semaphore desc
mq@size    equ 20

* Message descriptor fields

md@from    equ 12  pointer to sender's PB
md@reply   equ 16  pointer to sender's MQ for reply
*                 (local extension follows)
md@data    equ 20  amount of data in message
md@addr    equ 24  address of message
md@size    equ 28

* Process Block fields

pb@runq    equ 12  pointer to target run queue desc
*                 (local extension follows)
pb@ssp     equ 16  process system stack pointer
pb@xvt     equ 20  address of exception vector table
pb@global  equ 24  address of process global data area
pb@cputime equ 28  milliseconds used at pb@reftime
pb@reftime equ 32
pb@cpload  equ 36  co-processor context load routine
pb@cpsave  equ 40  co-processor context save routine
pb@vmroot  equ 44  ASN and addr of sement table
*                 (space for registers etc)
pb@size    equ 512

*--------------------------*
* Local object definitions *
*--------------------------*

* Interrupt handler control block fields

ih@pc      equ  0  address of first instruction in handler
ih@data    equ  4  handler's A4 (pointer to data area)
ih@next    equ  8  address of next IH CB
ih@prev    equ 12  address of previous IH CB
ih@size    equ 16

*----------------------------*
* System service definitions *
*----------------------------*

** SwapSR
** OrtoSR
** GetPB
** AddHandler
** RemHandler
*  SemSigWait
*  (SemSignal)
*  (SemWait)
*  Lock
*  Unlock
*  AddTail
*  RemHead
*  AddHead
*  RemTail
*  Remove
*  SendMess
*  RecMess
*  RecFrom
** Local
** Global
** IntRet
** IntWait

* Swap SR with D0

swapsr macro
\* trap #0
  endm

* Or D0 into SR and return old SR in D0

ortosr macro
\* trap #1
  endm

* Acquire address of our PB, and Real Time

getpb macro
\* lea 0,a0
   trap #2
   endm

* Install interrupt handler A0 for autovector D0

addhandler macro
\* trap #2
   endm

* Remove interrupt handler A0

remhandler macro
\* moveq #0,d0
   addhandler
   endm

* Signal/Wait on semaphore A0

semsigwait macro
\* trap #3
   endm

semsignal macro
\* moveq #1,d0
   semsigwait
   endm

semwait macro
\* moveq #-1,d0
   semsigwait
   endm

* Lock queue A0

lock macro
\* trap #4
   endm

* Unlock queue A0

unlock macro
\* trap #5
   endm

* Enqueue object A1 on end of queue A0

addtail macro
\* trap #6
   endm

* Dequeue object from front of queue A0
* Result to A1

remhead macro
\* lea 0,a1
   addtail
   endm

* Putback object A1 to front of queue A0

addhead macro
\* trap #7
   endm

* Take back object from end of queue A0
* Result to A1

remtail macro
\* lea 0,a1
   addhead
   endm

* Send message A1 to message queue A0

sendmess macro
\* trap #8
   endm

* Receive message on queue A0

recmess macro
\* lea 0,a1
   sendmess
   endm

* Receive message on queue A0 from sender D0

recfrom macro
\* trap #9
   endm

* Convert global address to local address

local macro
\* add.l #$800000,\1
   endm

* Convert local address to global address

global macro
\* sub.l #$800000,\1
   endm

* Return from interrupt

intret macro
\* movem.l ih@pc(a6),a1/a4/a6
   jmp (a1)
   endm

* Wait for interrupt

intwait macro
\* lea \@,a0
   move.l ih@prev(a6),a1
   move.l a0,ih@pc(a1)
   intret
\@ equ *
   endm

   end
