home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / books / 68k_book / arp_src / prg_6cp.s < prev    next >
Text File  |  1985-11-20  |  6KB  |  175 lines

  1.  ; Program Name: PRG_6CP.S
  2.  ;      Version: 1.002
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;     Assemble in PC-relative mode and save with a TOS extension.
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;     Execute from the desktop or from SPAWN.TTP.  This program uses traps
  11.  ; installed by CUSTOM.PRG.
  12.  
  13.  ; Program Function:
  14.  
  15.  ;     Prints the content of register A7 during various stages of execution
  16.  ; while the state of the processor is varied from user mode to supervisor
  17.  ; mode, from supervisor mode back to user mode, from user mode to supervisor
  18.  ; mode a second time and from supervisor mode back to user mode a second time.
  19.  
  20.  ;     In this program, GEMDOS function $20 is used to toggle the state of the
  21.  ; processor.  Refer to pages 117 and 118 of the Internals book, under the
  22.  ; $20 SUPER heading.  Aside from the fundamental methodology of function
  23.  ; invocation, two important items of information are discussed there.
  24.  
  25.  ;     1. GEMDOS $20 transfers the address of the user stack to the supervisor
  26.  ; stack pointer (SSP).  This means that while the processor is in the
  27.  ; supervisor state, if that state was forced by invocation of GEMDOS $20,
  28.  ; then the user stack is active and the supervisor stack is inactive.  This
  29.  ; means that the user stack must be large enough to accomodate supervisor
  30.  ; state activity.  Among other things, this activity includes the storage of
  31.  ; the program counter and status register during exception processing.
  32.  
  33.  ;     2. Invocation of GEMDOS $20 can corrupt, and usually does as far as I can
  34.  ; determine, registers A1 and D1.  Information in that section of the Internals
  35.  ; book indicates that only this GEMDOS function can alter the values in those
  36.  ; registers.
  37.  
  38. calculate_program_size:
  39.  lea        -$102(pc), a1       ; Fetch basepage start address.
  40.  lea        program_end, a0     ; Fetch program end address.
  41.  trap       #6                  ; Return unused memory to op system.
  42.  
  43. print_heading:
  44.  lea        heading, a0
  45.  bsr        print_string
  46.  
  47.  ; NOTE: During this section of the program, no user stack has yet been
  48.  ;       assigned, therefore, the user stack address is that of the default
  49.  ;       user stack assigned by the system when execution commences.
  50.  
  51. print_address_of_default_user_stack:
  52.  lea        header_1, a0
  53.  bsr        print_string
  54.  move.l     a7, d1              ; Convert address to ASCII hexadecimal.         
  55.  trap       #5
  56.  bsr        print_string
  57.  bsr        print_newline
  58.  
  59. invoke_gemdos_super_mode_function:
  60.  move.l     #0, -(sp)           ; The zero turns on supervisor mode.
  61.  move.w     #$20, -(sp)         ; Function = super = GEMDOS $20.
  62.  trap       #1                  ; Supervisor stack pointer (SSP) returned in D0.
  63.  addq.l     #6, sp              ; SSP = address of supervisor stack.
  64.  movea.l    d0, a5              ; Save SSP in scratch register.
  65.  
  66. print_SSP_returned_by_GEMDOS_20:
  67.  lea        header_6, a0
  68.  bsr        print_string
  69.  move.l     a5, d1              ; Convert to ASCII hexadecimal.
  70.  trap       #5
  71.  bsr        print_string
  72.  bsr        print_newline
  73.  
  74. print_current_SSP:              ; Did GEMDOS $20 alter the address in the
  75.  lea        header_2, a0        ; supervisor stack pointer?
  76.  bsr        print_string
  77.  move.l     a7, d1              ; Convert to ASCII hexadecimal.
  78.  trap       #5
  79.  bsr.s      print_string
  80.  bsr        print_newline
  81.  bsr        print_newline
  82.  
  83. enter_user_mode:
  84.  pea        (a5)                ; Restore supervisor stack pointer.
  85.  move.w     #$20, -(sp)         ; Function = super = GEMDOS $20.
  86.  trap       #1
  87.  addq.l     #6, sp
  88.  
  89.  ; NOTE: During this section of the program, a user stack is assigned.  The
  90.  ;       user stack address is that of the label "stack".
  91.  
  92. print_address_of_assigned_user_stack:
  93.  lea        header_3, a0
  94.  bsr.s      print_string
  95.  lea        stack, a7
  96.  move.l     a7, d1              ; Convert to ASCII hexadecimal.
  97.  trap       #5
  98.  bsr.s      print_string
  99.  bsr.s      print_newline
  100.  
  101. invoke_gemdos_function_again:
  102.  move.l     #0, -(sp)           ; The zero turns on supervisor mode.
  103.  move.w     #$20, -(sp)         ; Function = super = GEMDOS $20.
  104.  trap       #1                  ; Supervisor stack pointer (SSP) returned in D0.
  105.  addq.l     #6, sp
  106.  movea.l    d0, a5              ; Save SSP in scratch register.
  107.  
  108. print_SSP_returned_by_GEMDOS_20_again:
  109.  lea        header_7, a0
  110.  bsr        print_string
  111.  move.l     a5, d1
  112.  trap       #5
  113.  bsr        print_string
  114.  bsr        print_newline
  115.  
  116. print_current_SSP_again:
  117.  lea        header_4, a0
  118.  bsr.s      print_string
  119.  move.l     a7, d1              ; Convert to ASCII hexadecimal.
  120.  trap       #5
  121.  bsr.s      print_string
  122.  bsr.s      print_newline
  123.  
  124. enter_user_mode_again:
  125.  pea        (a5)                ; Restore supervisor stack pointer.
  126.  move.w     #$20, -(sp)         ; Function = super = GEMDOS $20.
  127.  trap       #1
  128.  addq.l     #6, sp
  129.  
  130. print_address_of_assigned_user_stack_again:
  131.  lea        header_5, a0
  132.  bsr.s      print_string
  133.  move.l     a7, d1              ; Convert to ASCII hexadecimal.
  134.  trap       #5
  135.  bsr.s      print_string
  136.  bsr.s      print_newline
  137.  
  138. terminate:
  139.  trap       #8
  140.  
  141.  ;
  142.  ; SUBROUTINES
  143.  ;
  144.  
  145. print_string:         
  146.  pea        (a0)
  147.  move.w     #9, -(sp) 
  148.  trap       #1        
  149.  addq.l     #6, sp    
  150.  rts
  151.  
  152. print_newline:
  153.  lea        newline, a0
  154.  bsr.s      print_string
  155.  rts
  156.  
  157.  data
  158. newline:   dc.b $D,$A,0
  159. heading:   dc.b 'PRG_6CP Execution Results => Content of A7:',$D,$A,$D,$A,0
  160. header_1:  dc.b   '  NO USER STACK ASSIGNED',$D,$A
  161.            dc.b   '    Start of program:             ',0
  162. header_2:  dc.b   '    After GEMDOS $20 invocation:  ',0
  163. header_6:  dc.b   '    SSP returned by GEMDOS $20:    ',0
  164. header_3:  dc.b   '  USER STACK ASSIGNED',$D,$A
  165.            dc.b   '    After force to user mode:     ',0
  166. header_4:  dc.b   '    After GEMDOS $20 invocation:  ',0
  167. header_7:  dc.b   '    SSP returned by GEMDOS $20:    ',0
  168. header_5:  dc.b   '    After force to user mode:     ',0
  169.  bss
  170.  align
  171.                ds.l   96
  172. stack:         ds.l    0
  173. program_end:   ds.l    0
  174.  end