
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   1

    1                      *debug macro
    2                      *   move.w sr,-(sp)
    3                      *   push d0
    4                      *   moveq #'\1',d0
    5                      *   jsr rompsym
    6                      *   pop d0
    7                      *   move.w (sp)+,sr
    8                      *   endm
    9                      
   10                         ttl Mouse Kernel and FE02 Bootstrap - Sep 86
   11                      
   12                      * Configuration constants
   13                      
   14                         bin
   15                      
   16         0000000A     mhz         equ 10
   17         00400100     ptm         equ $400100
   18         004000C1     acia        equ $4000c1  used only to disable ints
   19         0007FFFC     eths        equ $07fffc  likewise
   20         00FF3FFF     tickler     equ $ff3fff
   21                      
   22                      * NB when changing number of run queues or
   23                      * priority state descriptors, remember to change
   24                      * lines containing *rq*
   25                      
   26         00000018     part1size equ 24
   27         00005303     part1     equ d0-d1/a0-a1/a4/a6
   28         00003CFC     part2     equ d2-d7/a2-a5
   29         00000000     susp      equ a4
   30                      
   31                      * Offsets for kernel and most system objects
   32                      
   33         00000000     ketag      equ  0   * Tag field and lock bit
   34         00000002     kesize     equ  2   * Object size field
   35         00000004     kefwd      equ  4   * Next object
   36         00000008     kebck      equ  8   * Previous object
   37         0000000C     keheader   equ 12   * Queue in which object is
   38                      
   39                      * Semaphores
   40                      
   41         00000010     secount    equ 16   * Semaphore count field
   42         00000014     seassoc    equ 20   * Associated sempahore
   43         00000018     sesize     equ 24
   44                      
   45                      * Mailboxes
   46                      
   47         00000010     mbsema     equ 16   * Doorbell semaphore
   48         00000014     mbsize     equ 20
   49                      
   50                      * Messages
   51                      
   52         00000010     mereply    equ 16   * Return address
   53         00000024     mesize     equ 20+16 *non-global allowance*
   54                      
   55                      * Run Queues
   56                      
   57         00000010     rqtickler  equ 16   * Address of interrupt register
   58         00000014     rqsize     equ 20
   59                      
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   2

   60                      * Processes
   61                      
   62         00000010     prtarget   equ 16   * Run queue desired
   63         00000014     prasync    equ 20   * Asynchronous mailbox
   64                      *                   *non-global* part follows
   65         00000018     prssp      equ 24   * system stack pointer
   66         0000001C     prxvt      equ 28   * exception vector table
   67         00000020     prtvt      equ 32   * trap vector table
   68         00000024     prreftime  equ 36   * time at which we got cpu
   69         00000028     prcputime  equ 40   * cpu time consumed at reftime
   70         0000002C     prmembot   equ 44   * Low end of store [heap..
   71         00000030     prmemtop   equ 48   * High end of store ..stack]
   72         00000034     prpoa      equ 52   * FE02 A5
   73         00000038     prstate    equ 56   * current scheduling state
   74         0000003C     prquota    equ 60   * clock ticks left
   75         0000003E     prhyst     equ 62   * hysteresis for scheduler
   76         00000200     prsize     equ 512  * remainder is System Stack
   77                      
   78                      * Interrupt handler descriptors   *non-global*
   79                      
   80         00000010     ihpc       equ 16
   81         00000014     iha4       equ 20
   82         00000018     ihsize     equ 24
   83                      
   84                      * Scheduling state descriptors   *non-global*
   85                      
   86         00000004     sslower    equ kefwd   * next lower priority state
   87         00000008     sshigher   equ kebck   * next higher priority state
   88         00000010     sstarget   equ 16      * associated run queue
   89         00000014     ssprio     equ 20      * numeric priority (0:min)
   90         00000016     ssquota    equ 22      * clock tick allowance
   91         00000018     sshyst     equ 24      * hysteresis
   92                      *spare     equ 26
   93         0000001C     sssize     equ 28
   94                      
   95                      * Exception, trap, and interrupt despatching
   96                      
   97                      * Primary exception vector table
   98                      
   99         00001000       org $1000
  100  001000 00003000       dc.l $3000,startpc
  101  001008 0000155A       dc.l ex2,ex3
  102  001010 00001566       dc.l ex4,ex5,ex6,ex7
  103  001020 0000159A       dc.l pvh,ex9,exa,exb
  104  001030 0000131C       dc.l exn,exn,exn,exn
  105  001040 0000131C       dc.l exn,exn,exn,exn
  106  001050 0000131C       dc.l exn,exn,exn,exn
  107  001060 0000131C       dc.l exn,ih1,ih2,ih3
  108  001070 0000141A       dc.l ih4,ih5,ih6,ih7
  109  001080 0000148E       dc.l tr0,tr1,tr2,tr3
  110  001090 000014B6       dc.l tr4,tr5,tr6,tr7
  111  0010A0 000014DE       dc.l tr8,tr9,tra,trb
  112  0010B0 0000150C       dc.l trc,trd,tre,trf
  113                      
  114                      * Former extracode tables
  115                      
  116         4AFC4AFC     i2 equ $4afc4afc
  117                      
  118  0010C0 4AFC4AFC       dc.l i2,i2,i2,i2,i2,i2,i2,i2
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   3

  119  0010E0 4AFC4AFC       dc.l i2,i2,i2,i2,i2,i2,i2,i2
  120  001100 4AFC4AFC       dc.l i2,i2,i2,i2,i2,i2,i2,i2
  121  001120 4AFC4AFC       dc.l i2,i2,i2,i2,i2,i2,i2,i2
  122  001140 4AFC4AFC       dc.l i2,i2,i2,i2,i2,i2,i2,i2
  123  001160 4AFC4AFC       dc.l i2,i2,i2,i2,i2,i2,i2,i2
  124  001180 4AFC4AFC       dc.l i2,i2,i2,i2,i2,i2,i2,i2
  125  0011A0 4AFC4AFC       dc.l i2,i2,i2,i2,i2,i2,i2,i2
  126                      
  127                      * Kernel variables
  128                      
  129  0011C0 000109A0     cpu          dc.l 68000
  130  0011C4 00000000     milliseconds dc.l 0
  131  0011C8 00000000     curpro       dc.l 0
  132                      
  133                      * Kernel statistics counters
  134                      
  135  0011CC 00000000     ksint0      dc.l 0      *stats*
  136  0011D0 00000000     ksint1      dc.l 0
  137  0011D4 00000000     ksint2      dc.l 0
  138  0011D8 00000000     ksint3      dc.l 0
  139  0011DC 00000000     ksint4      dc.l 0
  140  0011E0 00000000     ksint5      dc.l 0
  141  0011E4 00000000     ksint6      dc.l 0
  142  0011E8 00000000     ksint7      dc.l 0
  143  0011EC 00000000     kstrap0     dc.l 0
  144  0011F0 00000000     kstrap1     dc.l 0
  145  0011F4 00000000     kstrap2     dc.l 0
  146  0011F8 00000000     kstrap3     dc.l 0
  147  0011FC 00000000     kstrap4     dc.l 0
  148  001200 00000000     kstrap5     dc.l 0
  149  001204 00000000     kstrap6     dc.l 0
  150  001208 00000000     kstrap7     dc.l 0
  151  00120C 00000000     kstrap8     dc.l 0
  152  001210 00000000     kstrap9     dc.l 0
  153  001214 00000000     kstrapa     dc.l 0
  154  001218 00000000     kstrapb     dc.l 0
  155  00121C 00000000     kstrapc     dc.l 0
  156  001220 00000000     kstrapd     dc.l 0
  157  001224 00000000     kstrape     dc.l 0
  158  001228 00000000     kstrapf     dc.l 0
  159  00122C 00000000     kssign      dc.l 0
  160  001230 00000000     kssigt      dc.l 0
  161  001234 00000000     kswaitn     dc.l 0
  162  001238 00000000     kswaitt     dc.l 0
  163                      
  164                      * Scheduling state descriptors
  165                      
  166                      sd macro [prio,lower,higher,hyst,quota]
  167                      sd\1 dc.w 'SS',sssize
  168                         dc.l sd\2,sd\3,sd\1
  169                      rq\1 dc.l 0
  170                         dc.w \1,\5,\4,0
  171                         endm
  172                      
  173                         sd 0,0,0,30000,10    *rq*
  174                         sd 1,1,1,30000,15    *rq*
  175                         sd 2,2,3,9,5         *rq*
  176                         sd 3,2,4,9,5         *rq*
  177                         sd 4,3,5,9,5         *rq*
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   4

  178                         sd 5,4,5,9,5         *rq*
  179                         sd 6,6,6,30000,5     *rq*
  180                         sd 7,7,7,30000,30000 *rq*
  181                      
  182         0000123C     minprio equ sd0  *rq*
  183         00001300     maxprio equ sd7  *rq*
  184                      
  185                      * Interrupt handling
  186                      
  187                      push macro
  188                      \* move.l \1,-(sp)
  189                         endm
  190                      
  191                      pop macro
  192                      \* move.l (sp)+,\1
  193                         endm
  194                      
  195                      pushm macro
  196                      \* movem.l \1,-(sp)
  197                         endm
  198                      
  199                      popm macro
  200                      \* movem.l (sp)+,\1
  201                         endm
  202                      
  203  00131C 4E73         exn rte           * ignore unknown exception
  204                      
  205                      ihlist macro
  206                      \* dc.w 'IH',ihsize
  207                         dc.l \*,\*,\*
  208                         dc.l \1,0
  209                         endm
  210                      
  211                      ihl0 ihlist intdone       *dummy*
  212                      ihl1 ihlist ticklerint
  213                      ihl2 ihlist intdone
  214                      ihl3 ihlist intdone
  215                      ihl4 ihlist intdone
  216                      ihl5 ihlist intdone
  217                      ihl6 ihlist clockint
  218                      ihl7 ihlist intdone
  219                      
  220                      ih macro
  221                      \* addq.l #1,ksint\1    *stats*
  222                         pushm part1
  223                         move.l ihl\1+kefwd,a6
  224                         movem.l ihpc(a6),a0/a4
  225                         jmp (a0)
  226                         endm
  227                      
  228                      ih1 ih 1
  229                      ih2 ih 2
  230                      ih3 ih 3
  231                      ih4 ih 4
  232                      ih5 ih 5
  233                      ih6 ih 6
  234                      ih7 ih 7
  235                      
  236                      intdone popm part1
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   5

  237  00146E 4E73            rte
  238                      
  239                      * Trap-exception despatching
  240                      
  241                      tr macro
  242                      tr\1  addq.l #1,kstrap\1   *stats*
  243                         pea $\1*4
  244                         bra trh
  245                         endm
  246                      
  247                      trh push a0
  248  001472 207811C8        move.l curpro,a0
  249  001476 B0FC0000        cmp #0,a0
  250  00147A 6700102A        beq trapcrash
  251  00147E 20680020        move.l prtvt(a0),a0
  252  001482 D1EF0004        add.l 4(sp),a0
  253  001486 2F500004        move.l (a0),4(sp)
  254                         pop a0
  255  00148C 4E75            rts
  256                      
  257                         tr 0
  258                         tr 1
  259                         tr 2
  260                         tr 3
  261                         tr 4
  262                         tr 5
  263                         tr 6
  264                         tr 7
  265                         tr 8
  266                         tr 9
  267                         tr a
  268                         tr b
  269                         tr c
  270                         tr d
  271                         tr e
  272                         tr f
  273                      
  274                      * Machine exception despatching
  275                      
  276                      ex macro
  277                      ex\1 pea $\1*4
  278                         bra exh
  279                         endm
  280                      
  281                      exh push a0
  282  00153E 207811C8        move.l curpro,a0
  283  001542 B0FC0000        cmp #0,a0
  284  001546 67000F80        beq exccrash
  285  00154A 2068001C        move.l prxvt(a0),a0
  286  00154E D1EF0004        add.l 4(sp),a0
  287  001552 2F500004        move.l (a0),4(sp)
  288                         pop a0
  289  001558 4E75            rts
  290                      
  291                         ex 2
  292                         ex 3
  293                         ex 4
  294                         ex 5
  295                         ex 6
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   6

  296                         ex 7
  297                         ex 8
  298                         ex 9
  299                         ex a
  300                         ex b
  301                      
  302                      * Primary privilege violation handler
  303                      * for 68010->68000 compatibility:
  304                      * allow moves from SR to -(SP) or Dn
  305                      * Also intercept STOP #0
  306                      
  307  001596 4E720000     stopzero stop #0
  308                      pvh pushm d0/a0
  309  00159E 206F000A        move.l 10(sp),a0
  310  0015A2 3010            move.w (a0),d0
  311  0015A4 B07C40E7        cmp.w #$40e7,d0
  312  0015A8 671A            beq.s pushsr
  313  0015AA C07CFFF8        and.w #-8,d0
  314  0015AE B07C40C0        cmp.w #$40c0,d0
  315  0015B2 672A            beq.s readsr
  316  0015B4 2010            move.l (a0),d0
  317  0015B6 B0B81596        cmp.l stopzero,d0
  318  0015BA 67000EC2        beq crash
  319                         popm d0/a0
  320  0015C2 60BA            bra ex8
  321  0015C4 4E68         pushsr move.l usp,a0
  322  0015C6 312F0008        move.w 8(sp),-(a0)
  323  0015CA 4E60            move.l a0,usp
  324                         popm d0/a0
  325  0015D0 54AF0002        addq.l #2,2(sp)
  326  0015D4 21FC000109AA    move.l #68010,cpu
  327  0015DC 4E73            rte
  328  0015DE 7007         readsr moveq #7,d0
  329  0015E0 C050            and.w (a0),d0
  330  0015E2 EB48            lsl.w #5,d0
  331  0015E4 E948            lsl.w #4,d0
  332  0015E6 D07C3017        add.w #$3017,d0  move.w (sp),d0
  333  0015EA 41F815F8        lea nasty,a0
  334  0015EE 3080            move.w d0,(a0)
  335                         popm d0/a0
  336  0015F4 54AF0002        addq.l #2,2(sp)
  337  0015F8 4E71         nasty nop
  338  0015FA 4E73            rte
  339                      
  340                      * Queue operation macros for internal use
  341                      * NB: Lock/Unlock are not exported.
  342                      * WAITs are not available to int handlers.
  343                      
  344                      lock macro
  345                      \* tas ketag(\1)
  346                         bpl.s \@a
  347                         push d0
  348                      *  pea (\1)
  349                      *  bsr niltest
  350                         moveq #-1,d0
  351                      \@ tas ketag(\1)
  352                         dbpl d0,\@
  353                         bmi lockcrash
  354                         pop d0
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   7

  355                      \@a equ *
  356                         endm
  357                      
  358                      unlock macro
  359                      \* bclr #7,ketag(\1)
  360                         endm
  361                      
  362                      * Enqueue item A0 on end of queue A1
  363                      
  364                      enqueue macro
  365                         move.l kebck(a1),a2
  366                         move.l a2,kebck(a0)
  367                         move.l a1,kefwd(a0)
  368                         move.l a1,keheader(a0)
  369                         move.l a0,kefwd(a2)
  370                         move.l a0,kebck(a1)
  371                         endm
  372                      
  373                      * Dequeue head of A1 to A0
  374                      
  375                      dequeue macro
  376                         move.l kefwd(a1),a0
  377                         move.l kefwd(a0),a2
  378                         move.l a1,kebck(a2)
  379                         move.l a2,kefwd(a1)
  380                         move.l #0,keheader(a0)
  381                         move.l a0,kefwd(a0)
  382                         move.l a0,kebck(a0)
  383                         endm
  384                      
  385                      * Enqueue item A0 on front of queue A1
  386                      
  387                      requeue macro
  388                         move.l kefwd(a1),a2
  389                         move.l a2,kefwd(a0)
  390                         move.l a1,kebck(a0)
  391                         move.l a1,keheader(a0)
  392                         move.l a0,kebck(a2)
  393                         move.l a0,kefwd(a1)
  394                         endm
  395                      
  396                      * Dequeue tail of A1 to A0
  397                      
  398                      unqueue macro
  399                         move.l kebck(a1),a0
  400                         move.l kebck(a0),a2
  401                         move.l a1,kefwd(a2)
  402                         move.l a2,kebck(a1)
  403                         move.l #0,keheader(a0)
  404                         move.l a0,kefwd(a0)
  405                         move.l a0,kebck(a0)
  406                         endm
  407                      
  408                      iof macro
  409                      \* move.w sr,-(sp)
  410                         or #$700,sr
  411                         endm
  412                      
  413                      ion macro
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   8

  414                      \* move.w (sp)+,sr
  415                         endm
  416                      
  417                      * Exported routines for use by interrupt handlers
  418                      * or special code "in the know"
  419                      
  420                      * Add interrupt handler A0 to chain
  421                      * of handlers for level D0.
  422                      inthandadd pushm d0/a0-a2
  423  001600 C0BC00000007    and.l #7,d0
  424  001606 C0FC0018        mulu #ihsize,d0
  425  00160A 43F8131E        lea ihl0,a1
  426  00160E D3C0            add.l d0,a1
  427                      ** iof
  428                         enqueue
  429                      ** ion
  430                         popm d0/a0-a2
  431  00162C 4E75            rts
  432                      
  433                      * Remove interrupt handler A0 from
  434                      * whichever chain it is in.
  435                      inthandrem pushm a0-a2
  436  001632 2248            move.l a0,a1
  437                      ** iof
  438                         dequeue
  439                      ** ion
  440                         popm a0-a2
  441  001658 4E75            rts
  442                      
  443                      * Wait for interrupt (i.e. at next interrupt
  444                      * enter handler at point of call)
  445  00165A 2D570010     intwait move.l (sp),ihpc(a6)
  446                      
  447                      * + return from interrupt (i.e. at next interrupt
  448                      * enter handler at same place as before)
  449                      * NB BOTH of these two are CALLED.
  450  00165E 2C6E0004     intret move.l kefwd(a6),a6
  451  001662 2EAE0010        move.l ihpc(a6),(sp)
  452  001666 286E0014        move.l iha4(a6),a4
  453  00166A 4E75            rts
  454                      
  455                      * Exported entry points for kernel operations
  456                      * both for use by interrupt handlers
  457                      * and callable as traps.
  458                      
  459                      trapop macro
  460                      \* or #$700,sr
  461                        push a2
  462                        lock a1
  463                        \1
  464                        unlock a1
  465                        pop a2
  466                        rte
  467                        endm
  468                      
  469                      intop macro
  470                      \* iof
  471                        push a2
  472                        lock a1
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page   9

  473                        \1
  474                        unlock a1
  475                        pop a2
  476                        ion
  477                        rts
  478                        endm
  479                      
  480                      niltest push a0
  481  00166E 206F0008       move.l 8(sp),a0
  482  001672 4AA80004       tst.l kefwd(a0)
  483  001676 6626           bne.s notnil
  484  001678 21480004       move.l a0,kefwd(a0)
  485  00167C 21480008       move.l a0,kebck(a0)
  486  001680 42A8000C       clr.l keheader(a0)
  487  001684 30BC3F3F       move.w #'??',ketag(a0)
  488  001688 41F816A4       lea uiqmess,a0
  489  00168C 4EB80420       jsr rompstr
  490  001690 202F0008       move.l 8(sp),d0
  491  001694 4EB8040C       jsr romphex
  492  001698 700A           moveq #nl,d0
  493  00169A 4EB8041C       jsr rompsym
  494                      notnil pop a0
  495  0016A0 2E9F           move.l (sp)+,(sp)
  496  0016A2 4E75           rts
  497  0016A4 FF           uiqmess dc.b 255,'*Uninitialised queue ',0
  498  0016BC 00000000       ds.w 0
  499                      
  500                      intenq  intop  enqueue
  501                      trapenq trapop enqueue
  502                      intreq  intop  requeue
  503                      trapreq trapop requeue
  504  0017AC 2248         intdeq  move.l a0,a1
  505                              intop  dequeue
  506  0017F4 2248         trapdeq move.l a0,a1
  507                              trapop dequeue
  508  001838 2248         intunq  move.l a0,a1
  509                              intop  unqueue
  510  001880 2248         trapunq move.l a0,a1
  511                              trapop unqueue
  512                      
  513                      * Extract A0 from whichever queue it is in.
  514                      * Result: A0 = that queue (or NIL)
  515                      
  516                      intexq iof
  517                         pushm a1-a2
  518  0018CE 2268000C        move.l keheader(a0),a1
  519  0018D2 B2FC0000        cmp #0,a1
  520  0018D6 674E            beq.s exqno
  521                         lock a1
  522  0018EC B3E8000C        cmp.l keheader(a0),a1
  523  0018F0 6630            bne.s exqnou
  524  0018F2 22680008        move.l kebck(a0),a1
  525  0018F6 24680004        move.l kefwd(a0),a2
  526  0018FA 234A0004        move.l a2,kefwd(a1)
  527  0018FE 25490008        move.l a1,kebck(a2)
  528  001902 2268000C        move.l keheader(a0),a1
  529  001906 217C00000000    move.l #0,keheader(a0)
  530  00190E 21480004        move.l a0,kefwd(a0)
  531  001912 21480008        move.l a0,kebck(a0)
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  10

  532                         unlock a1
  533                         popm a1-a2
  534                         ion
  535  001920 4E75            rts
  536                      exqnou unlock a1
  537                      exqno popm a1-a2
  538  00192A 41F80000        lea 0,a0
  539                         ion
  540  001930 4E75            rts
  541                      
  542  001932 6190         trapexq bsr intexq
  543  001934 4E73            rte
  544                      
  545                      * Insert A0 into a queue between items A1 and A2.
  546                      * A1 or A2 (but not both) may be NIL, but if not,
  547                      * they must be consistent.   Result:
  548                      * A0 = queue into which inserted (NIL if not).
  549                      
  550                      intinq iof
  551                         push a3
  552  00193E B2FC0000        cmp #0,a1
  553  001942 675C            beq.s a1nil
  554  001944 B4FC0000        cmp #0,a2
  555  001948 6762            beq.s a2nil
  556  00194A 2669000C     nonil move.l keheader(a1),a3
  557  00194E B6FC0000        cmp #0,a3
  558  001952 67000062        beq inqno
  559                         lock a3
  560  00196A B7E9000C        cmp.l keheader(a1),a3
  561  00196E 6642            bne.s inqnou
  562  001970 B7EA000C        cmp.l keheader(a2),a3
  563  001974 663C            bne.s inqnou
  564  001976 B5E90004        cmp.l kefwd(a1),a2
  565  00197A 6636            bne.s inqnou
  566  00197C B3EA0008        cmp.l kebck(a2),a1
  567  001980 6630            bne.s inqnou
  568  001982 21490008        move.l a1,kebck(a0)
  569  001986 214A0004        move.l a2,kefwd(a0)
  570  00198A 214B000C        move.l a3,keheader(a0)
  571  00198E 23480004        move.l a0,kefwd(a1)
  572  001992 25480008        move.l a0,kebck(a2)
  573                         unlock a3
  574                         pop a3
  575                         ion
  576  00199E 4E75            rts
  577  0019A0 B4FC0000     a1nil cmp #0,a2
  578  0019A4 6710            beq.s inqno
  579  0019A6 226A0008        move.l kebck(a2),a1
  580  0019AA 609E            bra nonil
  581  0019AC 24690004     a2nil move.l kefwd(a1),a2
  582  0019B0 6098            bra nonil
  583                      inqnou unlock a3
  584                      inqno pop a3
  585  0019B8 41F80000        lea 0,a0
  586                         ion
  587  0019BE 4E75            rts
  588                      
  589  0019C0 6100FF74     trapinq bsr intinq
  590  0019C4 4E73           rte
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  11

  591                      
  592                      * Signal semaphore A0
  593                      * and its associated chained semaphores
  594                      
  595                      intsignal iof
  596                         pushm a0-a2
  597                      sigmore lock a0
  598  0019E4 52A80010        addq.l #1,secount(a0)   * bump
  599  0019E8 6E6C            bgt.s sigtriv           * no-one to dequeue ->
  600  0019EA 52B8122C        addq.l #1,kssign        *stats*
  601  0019EE 2248            move.l a0,a1
  602                         dequeue                 * take process from S Q
  603                         unlock a1
  604                         push a1                 * A0=process, TOS=sema
  605  001A16 22680010        move.l prtarget(a0),a1  * A1=target of process
  606                         lock a1
  607                         enqueue
  608                         unlock a1
  609  001A4A 20690010        move.l rqtickler(a1),a0 * tickle processor
  610  001A4E 10BC00FF        move.b #$ff,(a0)
  611                         pop a0                  * restore sema to A0
  612  001A54 6008            bra.s signext
  613                      sigtriv unlock a0
  614  001A5A 52B81230        addq.l #1,kssigt        *stats*
  615  001A5E 20680014     signext move.l seassoc(a0),a0  * move on to
  616  001A62 B0FC0000        cmp #0,a0                   * chained semaphore
  617  001A66 6600FF68        bne sigmore                 * if any
  618                         popm a0-a2
  619                         ion
  620  001A70 4E75            rts
  621                      
  622  001A72 6100FF52     trapsignal bsr intsignal
  623  001A76 4E73            rte
  624                      
  625                      * Test semaphore A0
  626                      * Decrement counter only if positive
  627                      * Result: D0 = original counter value
  628                      
  629                      inttest iof
  630                         lock a0
  631  001A92 20280010        move.l secount(a0),d0
  632  001A96 6F04            ble.s negative
  633  001A98 53A80010        subq.l #1,secount(a0)
  634                      negative unlock a0
  635                         ion
  636  001AA2 4E75            rts
  637                      
  638  001AA4 61D2         traptest bsr inttest
  639  001AA6 4E73            rte
  640                      
  641                      * Wait on semaphore A0
  642                      * GDMR 11/8/88  Test the semaphore count first befo
  642+                     re
  643                      * saving context.  If it's +ve then don't bother, j
  643+                     ust
  644                      * decrement it and return.  If it's -ve then we'll 
  644+                     have
  645                      * to wait, so just drop through to do the full work
  645+                     s.
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  12

  646                      
  647                      * +GDMR
  648  001AA8 53A80010     nullwait subq.l #1,secount(a0)
  649                         unlock a0
  650  001AB0 52B81238        addq.l #1,kswaitt    *stats*
  651  001AB4 4E73            rte
  652                      * -GDMR
  653                      
  654  001AB6 007C0700     trapwait or #$700,sr
  655                      * +GDMR
  656                         lock a0
  657  001ACE 4AA80010        tst.l secount(a0)
  658  001AD2 6ED4            bgt.s nullwait
  659                         unlock a0
  660                      * -GDMR
  661  001AD8 52B81234        addq.l #1,kswaitn     *stats*
  662                         pushm part1           * save context
  663  001AE0 4E6C            move.l usp,susp
  664                         pushm part2
  665  001AE6 2248            move.l a0,a1
  666  001AE8 207811C8        move.l curpro,a0
  667  001AEC 214F0018        move.l sp,prssp(a0)   * A0=process, A1=semaphore
  668  001AF0 61000078        bsr gettime
  669  001AF4 90A80024        sub.l prreftime(a0),d0
  670  001AF8 D1A80028        add.l d0,prcputime(a0)
  671  001AFC D1A80024        add.l d0,prreftime(a0)
  672  001B00 24680038        move.l prstate(a0),a2
  673  001B04 5268003E        addq.w #1,prhyst(a0)  * reward
  674  001B08 6B16            bmi.s staylow
  675  001B0A 6E0E            bgt.s settop
  676  001B0C 246A0008        move.l sshigher(a2),a2 * change to higher prio
  677  001B10 214A0038        move.l a2,prstate(a0)
  678  001B14 216A00100010    move.l sstarget(a2),prtarget(a0)
  679  001B1A 316A0018003E settop move.w sshyst(a2),prhyst(a0) * set ceiling
  680         00001B20     staylow equ *
  681                         lock a1
  682  001B34 53A90010        subq.l #1,secount(a1)
  683  001B38 6A20            bpl.s unsuspend
  684                         enqueue
  685                         unlock a1
  686  001B56 600000E2        bra maybeidle
  687                      unsuspend unlock a1
  688                         popm part2
  689  001B62 4E64            move.l susp,usp
  690                         popm part1
  691  001B68 4E73            rte
  692                      
  693                      * Get elapsed time to D0
  694                      * Interrupts assumed disabled
  695                      
  696  001B6A 7063         gettime moveq #99,d0
  697  001B6C 90390040010C    sub.b ptm+12,d0
  698  001B72 6618            bne.s gettime1
  699  001B74 083900020040    btst.b #2,ptm+2
  700  001B7C 670E            beq.s gettime1
  701  001B7E 4A390040010C    tst.b ptm+12
  702  001B84 06B800000064    add.l #100,milliseconds
  703  001B8C D0B811C4     gettime1 add.l milliseconds,d0
  704  001B90 4E75            rts
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  13

  705                      
  706                      * Clock interrupt handler
  707                      * (hung off the IPL6 header)
  708                      
  709  001B92 41F900400100 clockint lea ptm,a0
  710  001B98 7004            moveq #4,d0
  711  001B9A C0280002        and.b 2(a0),d0
  712  001B9E 6700F8CA        beq intdone               * Not clock ->
  713  001BA2 0108000C        movep.w 12(a0),d0         * Placate
  714  001BA6 06B800000064    add.l #100,milliseconds   * Count time
  715  001BAE 203811C8        move.l curpro,d0
  716  001BB2 6700F8B6        beq intdone               * No process to slice 
  716+                     ->
  717  001BB6 2040            move.l d0,a0
  718  001BB8 5368003C        subq.w #1,prquota(a0)
  719  001BBC 6A00F8AC        bpl intdone               * Not expired ->
  720  001BC0 007C0700        or #$700,sr
  721  001BC4 7007            moveq #7,d0
  722  001BC6 C02F0018        and.b part1size(sp),d0    * interrupted IPL
  723  001BCA 6600F89E        bne intdone               * in int handler ->
  724  001BCE 4E6C            move.l usp,susp
  725                         pushm part2
  726  001BD4 214F0018        move.l sp,prssp(a0)
  727  001BD8 6190            bsr gettime
  728  001BDA 90A80024        sub.l prreftime(a0),d0
  729  001BDE D1A80028        add.l d0,prcputime(a0)
  730  001BE2 D1A80024        add.l d0,prreftime(a0)
  731  001BE6 24680038        move.l prstate(a0),a2
  732  001BEA 5368003E        subq.w #1,prhyst(a0)      * punish
  733  001BEE 6A16            bpl.s stayhigh
  734  001BF0 6E0A            bgt.s setbot
  735  001BF2 246A0004        move.l sslower(a2),a2     * change to low prio
  736  001BF6 216A00100010    move.l sstarget(a2),prtarget(a0)
  737  001BFC 316A0018003E setbot move.w sshyst(a2),prhyst(a0)
  738  001C02 4468003E        neg.w prhyst(a0)
  739         00001C06     stayhigh equ *
  740  001C06 22680010        move.l prtarget(a0),a1    * put proc on its RQ
  741                         lock a1
  742                         enqueue
  743                         unlock a1
  744                      * fall through to maybeidle
  745                      
  746                      * Tickler interrupt handler
  747                      * (hung off IPL1 header)
  748                      
  749                      try macro
  750                         cmp.w sd\1+ssprio,d0
  751                         bge nogo
  752                         move.l rq\1,a1
  753                         lock a1
  754                         dequeue
  755                         cmp.l a0,a1
  756                         bne go
  757                         unlock a1
  758                         endm
  759                      
  760  001C3A 2E781000     maybeidle move.l $1000,sp
  761  001C3E 42B811C8        clr.l curpro
  762  001C42 007C0700     ticklerint or #$700,sr
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  14

  763                         push a2
  764                      * Set D0.W to the priority of the
  765                      * interrupted process (-1 if none)
  766  001C48 70FF            moveq #-1,d0
  767  001C4A 247811C8        move.l curpro,a2
  768  001C4E B4FC0000        cmp #0,a2
  769  001C52 6708            beq.s idling
  770  001C54 246A0038        move.l prstate(a2),a2
  771  001C58 302A0014        move.w ssprio(a2),d0
  772         00001C5C     idling equ *
  773                      * Scan run queues for higher priority process
  774                         try 7  *rq*
  775                         try 6  *rq*
  776                         try 5  *rq*
  777                         try 4  *rq*
  778                         try 3  *rq*
  779                         try 2  *rq*
  780                         try 1  *rq*
  781                         try 0  *rq*
  782                      * If there is none, pretend nothing happened
  783                      nogo pop a2
  784  001EAE 4AB811C8        tst.l curpro
  785  001EB2 6706            beq.s idle
  786                         popm part1
  787  001EB8 4E73            rte
  788  001EBA 2E781000     idle move.l $1000,sp
  789  001EBE 4E722000     idleloop stop #$2000
  790  001EC2 60FA            bra idleloop
  791                      
  792                      * Now A0 is the highest priority contender, and
  793                      * A1 (still locked) is the queue it came from.
  794                      
  795  001EC4 203811C8     go move.l curpro,d0    
  796  001EC8 6700007E        beq nosave            * No current context ->
  797                         unlock a1
  798                         pop a2
  799  001ED2 4E6C            move.l usp,susp       * Switch contexts
  800                         pushm part2
  801  001ED8 2648            move.l a0,a3
  802  001EDA 2040            move.l d0,a0          * A0=old, A3=new process
  803  001EDC 214F0018        move.l sp,prssp(a0)
  804  001EE0 6100FC88        bsr gettime
  805  001EE4 27400024        move.l d0,prreftime(a3)
  806  001EE8 90A80024        sub.l prreftime(a0),d0
  807  001EEC D1A80028        add.l d0,prcputime(a0)
  808  001EF0 D1A80024        add.l d0,prreftime(a0)
  809  001EF4 22680010        move.l prtarget(a0),a1
  810                         lock a1
  811                         enqueue               * put old on its RQ
  812                         unlock a1
  813  001F28 244B            move.l a3,a2
  814  001F2A 21CA11C8     unsave move.l a2,curpro
  815  001F2E 2E6A0018        move.l prssp(a2),sp   * pick up new p's context
  816  001F32 206A0038        move.l prstate(a2),a0
  817  001F36 35680016003C    move.w ssquota(a0),prquota(a2) * set clock quota
  818                         popm part2
  819  001F40 4E64            move.l susp,usp
  820                         popm part1
  821  001F46 4E73            rte
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  15

  822                      nosave unlock a1
  823  001F4C 6100FC1C        bsr gettime
  824  001F50 21400024        move.l d0,prreftime(a0)
  825  001F54 2448            move.l a0,a2
  826  001F56 60D2            bra unsave
  827                      
  828                      ** End of kernel code, initialisation follows
  829                      
  830         0000000D     cr equ 13
  831         0000000A     lf equ 10
  832         0000000A     nl equ lf
  833                      
  834                      string macro
  835                      \* dc.b \@1-*-1,\1
  836                      \@1 equ *
  837                         ds.w 0
  838                         endm
  839                      
  840                      ptext macro
  841                      \* lea \@1,a0
  842                         bra.s \@2
  843                      \@1 string <\1>
  844                      \@2 jsr rompstr
  845                         endm
  846                      
  847                      psym macro
  848                      \* moveq #\1,d0
  849                         jsr rompsym
  850                         endm
  851                      
  852                      space macro
  853                      \* psym <' '>
  854                         endm
  855                      
  856                      newline macro
  857                      \* psym lf
  858                         endm
  859                      
  860         00000408     romload  equ $408
  861         0000040C     romphex  equ $40c
  862         00000410     romphex4 equ $410
  863         00000414     romphex2 equ $414
  864         00000418     romphex1 equ $418
  865         0000041C     rompsym  equ $41c
  866         00000420     rompstr  equ $420
  867                      
  868         00003EFA     impsignal equ $3f00-6
  869         00003E70     psym equ $3f00-144
  870         00003E6A     pstr equ $3f00-150
  871         00003E88     new  equ $3f00-120
  872                      
  873         00003FF0     freebot equ $3ff0
  874         00003FF4     freetop equ $3ff4
  875         00003FF8     membot  equ $3ff8
  876         00003FFC     memtop  equ $3ffc
  877                      
  878         00000000     heaplevel equ 0   [byte]
  879         00000000     heapsize  equ 0   [long &$ffffff]
  880         00000004     heapholes equ 4   hole list
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  16

  881         00000008     heapfront equ 8   ad of free space
  882         0000000C     heaplimit equ 12  current expansion limit
  883         00000010     heapend   equ 16  max exp lim
  884         00000014     hhsize    equ 20  heap header cell size
  885                      
  886                      * Initial entry from ROM is to here
  887                      
  888  001F58 46FC2700     startpc move.w #$2700,sr
  889  001F5C 13FC00110040    move.b #$11,acia     disable terminal interrupts
  890  001F64 13FC00000007    move.b #0,eths       and ether board interrupts
  891                      
  892                      * Make obsolete FREEBOT/TOP appear empty
  893                      
  894  001F6C 2E783FFC        move.l memtop,sp
  895  001F70 21CF3FF0        move.l sp,freebot
  896  001F74 21CF3FF4        move.l sp,freetop
  897                      
  898                      * initialise the main heap header cell.
  899                      
  900  001F78 20783FF8        move.l membot,a0
  901  001F7C 20BC00000014    move.l #hhsize,heapsize(a0)
  902  001F82 10BC0001        move.b #1,heaplevel(a0)
  903  001F86 42A80004        clr.l heapholes(a0)
  904  001F8A 21480008        move.l a0,heapfront(a0)
  905  001F8E 06A800000014    add.l #hhsize,heapfront(a0)
  906  001F96 214F000C        move.l sp,heaplimit(a0)
  907  001F9A 214F0010        move.l sp,heapend(a0)
  908                      
  909                      * Set up the FE02 extracode table
  910                      
  911                      xcode macro
  912                         move.l #\2,$3f02-\1
  913                         endm
  914                      
  915  001F9E 703F            moveq #63,d0
  916  001FA0 41F83F00        lea $3f00,a0
  917  001FA4 213C0000226A xcloop move.l #absent,-(a0)
  918  001FAA 313C4EF9        move.w #$4ef9,-(a0)
  919  001FAE 51C8FFF4        dbra d0,xcloop
  920  001FB2 21FC0000226A    move.l #absent,$3fa4  [screenput]
  921  001FBA 31FC4EF93FA2    move.w #$4ef9,$3fa2
  922  001FC0 31FC18503FA0    move.w #$1850,$3fa0   [screenrows/cols]
  923                         xcode 6,signalevent
  924                         xcode 12,mull
  925                         xcode 18,divl
  926                         xcode 120,heapget
  927                         xcode 144,rompsym
  928                         xcode 150,rompstr
  929                         xcode 6*64,intenq
  930                         xcode 6*63,intdeq
  931                         xcode 6*62,intreq
  932                         xcode 6*61,intunq
  933                         xcode 6*60,intinq
  934                         xcode 6*59,intexq
  935                         xcode 6*58,intsignal
  936                         xcode 6*57,inttest
  937                         xcode 6*56,intret
  938                         xcode 6*55,intwait
  939                         xcode 6*54,inthandadd
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  17

  940                         xcode 6*53,inthandrem
  941                      
  942                      * Create the master dictionary
  943                      
  944  002056 7008            moveq #8,d0
  945  002058 4EB83E88        jsr new
  946  00205C 4298            clr.l (a0)+
  947  00205E 4298            clr.l (a0)+
  948                      
  949                      * Create the run queues
  950                      
  951                      rq macro
  952                         jsr rq
  953                         move.l a0,rq\1
  954                         endm
  955                      
  956                         rq 7  *rq*
  957                         rq 6  *rq*
  958                         rq 5  *rq*
  959                         rq 4  *rq*
  960                         rq 3  *rq*
  961                         rq 2  *rq*
  962                         rq 1  *rq*
  963                         rq 0  *rq*
  964                      
  965                      * Create the PCB and POA for the initial process
  966                      
  967  0020A0 204F            move.l sp,a0
  968  0020A2 707F            moveq #512/4-1,d0
  969  0020A4 42A0         pcbloop clr.l -(a0)
  970  0020A6 51C8FFFC        dbra d0,pcbloop
  971  0020AA 2A48            move.l a0,a5
  972  0020AC 203C000000FF    move.l #1024/4-1,d0
  973  0020B2 42A5         poaloop clr.l -(a5)
  974  0020B4 51C8FFFC        dbra d0,poaloop
  975  0020B8 21C811C8        move.l a0,curpro
  976  0020BC 214D0034        move.l a5,prpoa(a0)
  977  0020C0 30BC5052        move.w #'PR',ketag(a0)
  978  0020C4 317C02000002    move.w #prsize,kesize(a0)
  979  0020CA 21783FF8002C    move.l membot,prmembot(a0)
  980  0020D0 21783FFC0030    move.l memtop,prmemtop(a0)
  981  0020D6 43F8123C        lea minprio,a1
  982  0020DA 21490038        move.l a1,prstate(a0)
  983  0020DE 216900100010    move.l sstarget(a1),prtarget(a0)
  984  0020E4 31690016003C    move.w ssquota(a1),prquota(a0)
  985  0020EA 31690018003E    move.w sshyst(a1),prhyst(a0)
  986  0020F0 217C000021EA    move.l #defxvt,prxvt(a0)
  987  0020F8 217C0000222A    move.l #deftvt,prtvt(a0)
  988                      
  989                      * Start the millisecond clock
  990                      * and decisecond interrupt generator
  991                      
  992  002100 41F900400100    lea ptm,a0
  993  002106 117C00010002    move.b #1,2(a0)           cr1
  994  00210C 10BC0001        move.b #1,0(a0)           reset
  995  002110 117C0063000C    move.b #99,12(a0)         1kHz -> 10Hz
  996  002116 117C007C000E    move.b #mhz/2*25-1,14(a0) .8/1 MHz -> 1kHz
  997  00211C 117C00000002    move.b #0,2(a0)           cr3
  998  002122 10BC0047        move.b #$47,(a0)          mode
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  18

  999  002126 117C00010002    move.b #1,2(a0)           cr1
 1000  00212C 10BC0000        move.b #0,0(a0)           run
 1001                      
 1002                      * Set up the user stack and IMP registers,
 1003                      * switch to user mode with interrupts enabled
 1004                      * before loading the rest of the system.
 1005                      
 1006  002130 4DF80000        lea 0,a6
 1007  002134 49F80000        lea 0,a4
 1008  002138 2E3C80808080    move.l #$80808080,d7
 1009  00213E 7C00            moveq #0,d6
 1010  002140 7A00            moveq #0,d5
 1011  002142 7800            moveq #0,d4
 1012  002144 4E65            move.l a5,usp
 1013  002146 46FC0000        move #0,sr
 1014                      
 1015                      * Establish whether 68000 or 68010
 1016                      
 1017  00214A 40E7            move sr,-(sp)
 1018  00214C 301F            move.w (sp)+,d0
 1019                      
 1020                      * Read in system base file
 1021                      
 1022  00214E 4EB82560       jsr heapguess
 1023  002152 4EB8040C       jsr romphex
 1024                        space
 1025  00215C 41F821DA       lea basefile,a0
 1026  002160 4EB80420       jsr rompstr
 1027  002164 4EB82560        jsr heapguess
 1028  002168 41F821DA        lea basefile,a0
 1029  00216C 4EB80408        jsr romload
 1030  002170 4EB83E88        jsr new
 1031                         newline
 1032                      
 1033                      * Enter it
 1034                      
 1035         00000000     fe02     equ 0
 1036         00000004     export   equ 4
 1037         00000006     import   equ 6
 1038         00000008     codesize equ 8
 1039         0000000C     reset    equ 12
 1040         0000000E     begin    equ 14
 1041         00000010     ownsize  equ 16
 1042         00000020     fe02size equ 32
 1043                      
 1044  00217A 0C50FE02        cmp.w #$fe02,fe02(a0)
 1045  00217E 6644            bne.s no
 1046  002180 7003            moveq #3,d0
 1047  002182 D0A80010        add.l ownsize(a0),d0
 1048  002186 E488            lsr.l #2,d0
 1049  002188 5380            subq.l #1,d0
 1050  00218A 7200            moveq #0,d1
 1051  00218C 2F01         ownloop move.l d1,-(sp)
 1052  00218E 51C8FFFC        dbra d0,ownloop
 1053  002192 284F            move.l sp,a4
 1054  002194 30280006        move.w import(a0),d0
 1055  002198 662A            bne.s no
 1056  00219A 4280            clr.l d0
 1057  00219C 30280004        move.w export(a0),d0
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  19

 1058  0021A0 4281            clr.l d1
 1059  0021A2 3228000C        move.w reset(a0),d1
 1060  0021A6 D281            add.l d1,d1
 1061  0021A8 4282            clr.l d2
 1062  0021AA 3428000E        move.w begin(a0),d2
 1063  0021AE D482            add.l d2,d2
 1064  0021B0 43F00820        lea fe02size(a0,d0.l),a1
 1065  0021B4 48712800        pea 0(a1,d2.l)
 1066                         push a0
 1067  0021BA 4EB11800        jsr 0(a1,d1.l)
 1068                         popm a0-a1
 1069  0021C2 4E91            jsr (a1)
 1070                      no ptext <'Squeak'>
 1071  0021D6 600002A6        bra crash
 1072                      basefile string 'moose:base.mob'
 1073                      
 1074                      * Default exception and trap vector tables
 1075                      
 1076  0021EA 000022EE     defxvt dc.l bum,bum,berr,aerr
 1077  0021FA 00002360        dc.l ille,zero,chkf,over
 1078  00220A 00002380        dc.l priv,trac,ille,ille
 1079  00221A 000022EE        dc.l bum,bum,bum,bum
 1080  00222A 000023A0     deftvt dc.l trapmtsr,trapotsr,trapenv,bum
 1081  00223A 000022EE        dc.l bum,bum,trapsignal,trapwait
 1082  00224A 000016FA        dc.l trapenq,trapdeq,trapreq,trapunq
 1083  00225A 000019C0        dc.l trapinq,trapexq,traptest,trapline
 1084                      
 1085                      * The absent extracode
 1086                      
 1087  00226A 2057         absent move.l (sp),a0
 1088  00226C 4282            clr.l d2
 1089  00226E 3428FFFE        move.w -2(a0),d2
 1090  002272 7209            moveq #9,d1
 1091  002274 7070            moveq #$70,d0
 1092  002276 41F8227E        lea absmess,a0
 1093  00227A 4EF83EFA        jmp impsignal
 1094                      absmess string <'Missing extracode'>
 1095                      
 1096                      * Exception to IMP event conversion
 1097                      
 1098  002290 7202         berr moveq #2,d1
 1099  002292 41F822E4        lea berrmess,a0
 1100  002296 6006            bra.s aberr
 1101  002298 7203         aerr moveq #3,d1
 1102  00229A 41F822D6        lea aerrmess,a0
 1103  00229E 7070         aberr moveq #$70,d0
 1104  0022A0 0CB8000109A0    cmp.l #68000,cpu
 1105  0022A8 671A            beq.s be000
 1106  0022AA 242F000A        move.l 10(sp),d2
 1107  0022AE 3F570032        move.w (sp),50(sp)
 1108  0022B2 2F6F00020034    move.l 2(sp),52(sp)
 1109  0022B8 3F7C00000038    move.w #0,56(sp)
 1110  0022BE 4FEF0032        lea 50(sp),sp
 1111  0022C2 6008            bra.s sig
 1112  0022C4 242F0002     be000 move.l 2(sp),d2
 1113  0022C8 4FEF0008        lea 8(sp),sp
 1114  0022CC 2F7C00003EFA sig move.l #impsignal,2(sp)
 1115  0022D4 4E73            rte
 1116                      aerrmess string <'Address error'>
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  20

 1117                      berrmess string <'Bus error'>
 1118                      
 1119                      event macro
 1120                      \* lea \@1,a0
 1121                         moveq #$5\1,d0
 1122                         moveq #\2,d1
 1123                         bra sig
 1124                      \@1 equ *
 1125                         string <\3>
 1126                         endm
 1127                      
 1128                      bum  event 0,5,<'Reserved exception'>
 1129                      zero event 1,4,<'Division by zero'>
 1130                      chkf event 6,2,<'CHK: Out of range'>
 1131                      over event 1,4,<'TRAPV: Overflow'>
 1132                      ille event 0,4,<'Illegal instruction'>
 1133                      priv event 0,8,<'Privilege violation'>
 1134                      
 1135                      * Move D0 to SR, returning previous SR to D0
 1136                      
 1137  0023A0 3F17         trapmtsr move.w (sp),-(sp)
 1138  0023A2 3F400002        move.w d0,2(sp)
 1139  0023A6 301F            move.w (sp)+,d0
 1140  0023A8 4E73            rte
 1141                      
 1142                      * Or D0 to SR, returning previous SR to D0
 1143                      
 1144  0023AA 3F17         trapotsr move.w (sp),-(sp)
 1145  0023AC 816F0002        or.w d0,2(sp)
 1146  0023B0 301F            move.w (sp)+,d0
 1147  0023B2 41F811CC        lea ksint0,a0       *stats*
 1148  0023B6 4E73            rte
 1149                      
 1150                      * Update timers in current PCB, and return
 1151                      * D0 = cpu type,
 1152                      * A0 = current PCB,
 1153                      * A1 = scheduling state for priority 0
 1154                      
 1155  0023B8 007C0700     trapenv or #$700,sr
 1156  0023BC 6100F7AC        bsr gettime
 1157  0023C0 207811C8        move.l curpro,a0
 1158  0023C4 90A80024        sub.l prreftime(a0),d0
 1159  0023C8 D1A80028        add.l d0,prcputime(a0)
 1160  0023CC D1A80024        add.l d0,prreftime(a0)
 1161  0023D0 203811C0        move.l cpu,d0
 1162  0023D4 43F8123C        lea minprio,a1
 1163  0023D8 4E73            rte
 1164                      
 1165                      * Imp line-trace exception
 1166                      
 1167                      trapline pushm part1
 1168  0023DE 206F001A        move.l part1size+2(sp),a0
 1169  0023E2 7000            moveq #0,d0
 1170  0023E4 3018            move.w (a0)+,d0
 1171  0023E6 2F48001A        move.l a0,part1size+2(sp)
 1172  0023EA 3F00            move.w d0,-(sp)
 1173                         ptext <'Line '>
 1174  0023FC 301F            move.w (sp)+,d0
 1175  0023FE 4EB80410        jsr romphex4
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  21

 1176                         newline
 1177                         popm part1
 1178  00240C 4E73            rte
 1179                      
 1180                      * Trace exception
 1181                      
 1182                      trac pushm part1
 1183                         ptext <'PC '>
 1184  002420 202F001A        move.l part1size+2(sp),d0
 1185  002424 4EB8040C        jsr romphex
 1186                         newline
 1187                         popm part1
 1188  002432 4E73            rte
 1189                      
 1190                      * Preliminary Imp signal routine
 1191                      
 1192  002434 48E7E080     signalevent movem.l d0-d2/a0,-(sp)
 1193                         ptext <nl,'Premature event '>
 1194  002454 201F            move.l (sp)+,d0
 1195  002456 4EB80414        jsr romphex2
 1196                         space
 1197  002460 201F            move.l (sp)+,d0
 1198  002462 4EB80414        jsr romphex2
 1199                         space
 1200  00246C 201F            move.l (sp)+,d0
 1201  00246E 4EB8040C        jsr romphex
 1202                         space
 1203  002478 205F            move.l (sp)+,a0
 1204  00247A 4EB80420        jsr rompstr
 1205  00247E 303C2700     crash move #$2700,d0
 1206  002482 4E40            trap #0
 1207  002484 1039004000C3    move.b acia+2,d0
 1208  00248A 1039004000C3    move.b acia+2,d0
 1209  002490 083900000040 hang btst #0,acia
 1210  002498 67F6            beq hang
 1211  00249A 4E70            reset
 1212  00249C 2E780000        move.l 0,sp
 1213  0024A0 2F380004        move.l 4,-(sp)
 1214  0024A4 4E75            rts
 1215                      
 1216                      trapcrash pop a0
 1217                         ptext <nl,'* Anony-mouse-trap'>
 1218  0024C6 60B6            bra crash
 1219                      exccrash pop a0
 1220                         ptext <nl,'* Anonymous exception'>
 1221  0024EC 6090            bra crash
 1222                      lockcrash push a0
 1223                         ptext <nl,'* Lock timeout for '>
 1224                         pop d0
 1225  002512 4EB8040C        jsr romphex
 1226  002516 6000FF66        bra crash
 1227                      
 1228                      * Allocate space for and initialise a run queue
 1229                      
 1230  00251A 7014         rq moveq #rqsize,d0
 1231  00251C 4EB83E88        jsr new
 1232  002520 30BC5251        move.w #'RQ',ketag(a0)
 1233  002524 317C00140002    move.w #rqsize,kesize(a0)
 1234  00252A 21480004        move.l a0,kefwd(a0)
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  22

 1235  00252E 21480008        move.l a0,kebck(a0)
 1236  002532 42A8000C        clr.l keheader(a0)
 1237  002536 217C00FF3FFF    move.l #tickler,rqtickler(a0)
 1238  00253E 4E75            rts
 1239                      
 1240                      * Grab a heap chunk of size D0 bytes
 1241                      * and return its start address in A0 and D0.
 1242                      * Used only during initialisation, hence no
 1243                      * limit checking or hole searching.
 1244                      
 1245  002540 20783FF8     heapget move.l membot,a0
 1246  002544 5E80            addq.l #7,d0
 1247  002546 C03C00FC        and.b #$fc,d0
 1248  00254A D1A80008        add.l d0,heapfront(a0)
 1249  00254E 20680008        move.l heapfront(a0),a0
 1250  002552 91C0            sub.l d0,a0
 1251  002554 20C0            move.l d0,(a0)+
 1252  002556 117C0001FFFC    move.b #1,-4(a0)
 1253  00255C 2008            move.l a0,d0
 1254  00255E 4E75            rts
 1255                      
 1256                      * Preview the address of the next heap chunk
 1257                      * which HEAPGET would allocate, but without
 1258                      * actually allocating it.  Used during file
 1259                      * loading before we know how big the file is.
 1260                      
 1261  002560 70FC         heapguess moveq #-4,d0
 1262  002562 60DC            bra heapget
 1263                      
 1264                      * 32-bit nultiply and divide
 1265                      
 1266  002564 48E77800     mull movem.l d1-d4,-(sp)
 1267  002568 7800            moveq #0,d4
 1268  00256A 2400            move.l d0,d2
 1269  00256C 6A06            bpl.s m1
 1270  00256E 4480            neg.l d0
 1271  002570 7801            moveq #1,d4
 1272  002572 2400            move.l d0,d2
 1273  002574 4842         m1 swap d2
 1274  002576 2601            move.l d1,d3
 1275  002578 6A08            bpl.s m2
 1276  00257A 4481            neg.l d1
 1277  00257C 0A440001        eor.w #1,d4
 1278  002580 2601            move.l d1,d3
 1279  002582 4843         m2 swap d3
 1280  002584 4A42            tst.w d2
 1281  002586 6714            beq.s maz     * A>>16=0 ->
 1282  002588 4A43            tst.w d3
 1283  00258A 6726            beq.s mbz     * B>>16=0 ->
 1284  00258C C6C0            mulu d0,d3
 1285  00258E C4C1            mulu d1,d2
 1286  002590 C0C1            mulu d1,d0
 1287  002592 D483            add.l d3,d2
 1288  002594 4840            swap d0
 1289  002596 D042            add.w d2,d0
 1290  002598 4840            swap d0
 1291  00259A 603E            bra.s mv      * mandatory overflow ->
 1292  00259C 4A43         maz tst.w d3
 1293  00259E 6724            beq.s mabz    * A>>16=B>>16=0 ->
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  23

 1294  0025A0 C6C0            mulu d0,d3
 1295  0025A2 C0C1            mulu d1,d0
 1296  0025A4 4840            swap d0
 1297  0025A6 D043            add.w d3,d0
 1298  0025A8 4840            swap d0
 1299  0025AA 4843            swap d3
 1300  0025AC 4A43            tst.w d3
 1301  0025AE 662A            bne.s mv      * certain overflow ->
 1302  0025B0 6014            bra.s mvt     * possible overflow ->
 1303  0025B2 C4C1         mbz mulu d1,d2
 1304  0025B4 C0C1            mulu d1,d0
 1305  0025B6 4840            swap d0
 1306  0025B8 D042            add.w d2,d0
 1307  0025BA 4840            swap d0
 1308  0025BC 4842            swap d2
 1309  0025BE 4A42            tst.w d2
 1310  0025C0 6618            bne.s mv
 1311  0025C2 6002            bra.s mvt
 1312  0025C4 C0C1         mabz mulu d1,d0
 1313  0025C6 4A80         mvt tst.l d0
 1314  0025C8 6B10            bmi.s mv
 1315  0025CA 08040000        btst #0,d4
 1316  0025CE 6702            beq.s m8
 1317  0025D0 4480            neg.l d0
 1318  0025D2 4A80         m8 tst.l d0
 1319  0025D4 4CDF001E        movem.l (sp)+,d1-d4
 1320  0025D8 4E75            rts
 1321  0025DA 08040000     mv btst #0,d4
 1322  0025DE 6702            beq.s m9
 1323  0025E0 4480            neg.l d0
 1324  0025E2 4A80         m9 tst.l d0
 1325  0025E4 4CDF001E        movem.l (sp)+,d1-d4
 1326  0025E8 003C0002        or.b #2,ccr
 1327  0025EC 4E75            rts
 1328                      
 1329  0025EE 48E73800     divl     movem.l d2-d4,-(sp)
 1330  0025F2 4244                  clr     d4
 1331  0025F4 2401                  move.l  d1,d2
 1332  0025F6 6744                  beq.s   zdivoflow
 1333  0025F8 6A06                  bpl.s   divpos1
 1334  0025FA 4482                  neg.l   d2
 1335  0025FC 887C0002              or      #2,d4
 1336  002600 2200         divpos1  move.l  d0,d1
 1337  002602 6A08                  bpl.s   divpos2
 1338  002604 4481                  neg.l   d1
 1339  002606 0A8400000003          eor.l   #3,d4
 1340  00260C 4280         divpos2  clr.l   d0
 1341  00260E 7601                  move.l  #1,d3
 1342  002610 6004                  bra.s   divsulps
 1343  002612 E38A         divsulp  lsl.l   #1,d2
 1344  002614 E38B                  lsl.l   #1,d3
 1345  002616 B282         divsulps cmp.l   d2,d1
 1346  002618 62F8                  bhi.s   divsulp
 1347  00261A B282         divlp    cmp.l   d2,d1
 1348  00261C 6504                  bcs.s   divnosub
 1349  00261E D083                  add.l   d3,d0
 1350  002620 9282                  sub.l   d2,d1
 1351  002622 E28A         divnosub lsr.l   #1,d2
 1352  002624 E28B                  lsr.l   #1,d3
 Motorola M68010 Assembler Mouse Kernel and FE02 Bootstrap - Sep 86  Page  24

 1353  002626 66F2                  bne     divlp
 1354  002628 E24C                  lsr     #1,d4
 1355  00262A 6402                  bcc.s   nonegrem
 1356  00262C 4481                  neg.l   d1
 1357  00262E 4A44         nonegrem tst     d4
 1358  002630 6702                  beq.s   nonegquo
 1359  002632 4480                  neg.l   d0
 1360  002634 4A80         nonegquo tst.l   d0
 1361  002636 4CDF001C              movem.l (sp)+,d2-d4
 1362  00263A 4E75                  rts
 1363  00263C 4CDF001C     zdivoflow movem.l (sp)+,d2-d4
 1364  002640 80FC0000              divu #0,d0
 1365  002644 4E75                  rts
 1366                      
 1367                         end

No faults and no warnings in this assembly.
