home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / 22rsx / rsx12.ark / RELOCCP.MAC < prev    next >
Encoding:
Text File  |  1985-11-09  |  9.1 KB  |  342 lines

  1.     title    'RELOCCP 1.2 - load programs below CCP (84/07/28)'
  2. ; ***********************************************
  3. ; * Copyright (C) 1982,1984            *
  4. ; *                        *
  5. ; * by    C.B. Falconer        (203) 281-1438    *
  6. ; *    680 Hartford Tpk.            *
  7. ; *    Hamden, Conn. 06517            *
  8. ; *                        *
  9. ; * All rights reserved                *
  10. ; ***********************************************
  11. ;
  12. ; Relocate a program, by pages, to reside below BDOS. The program
  13. ; is loaded below CCP, assumed present.  The program to be relocated
  14. ; is at 0200h up, and is assembled as if it begins at location 0.
  15. ; Following the program code proper is a relocation bit map.  Each
  16. ; byte specifies relocation for 8 bytes of the program, with the ms
  17. ; bit of the relocation byte corresponding to the lower of the 8
  18. ; object bytes.  See revision 1.2 below for format of program size
  19. ; and space requirement data.
  20. ;
  21. ; The bit image is formed by comparing the code image with another
  22. ; assembled for org 0.  See "makeprl" and "vect" below for details.
  23. ;
  24. ; The first execution of this system forms the relocation bit vector
  25. ; from the two images, and self-modifies to become a loader on the
  26. ; next execution.
  27. ;
  28. ; Note that any data areas to be reserved for the relocated program
  29. ; must be reserved by the pages value at 205h.
  30. ;
  31. ; If the program image extends beyond the relocated origin, this
  32. ; system will fail. It relocates first, then moves, and thus would
  33. ; self destroy its upper portion.
  34. ;
  35. ; Revisions etc
  36. ; =============
  37. ; 85/11/09    No changes. Converted to Intel mnemnonics cbf.
  38. ; 84/07/28    Ver 1.2            C.B. Falconer
  39. ;    Converted for standard code unit size data.
  40. ;    The 0 based image at location 0200h is:
  41. ;        jmp somewhere;    the entry point.
  42. ;        dw  codesize;    to be moved/relocated
  43. ;        db  pages;    of memory required, total
  44. ;    added the overlay conditional to modify application load
  45. ;
  46. ; 84/06/02     Ver 1.1            C.B. Falconer
  47. ;    converted to Zilog mnemnonic set.  Added prompt for
  48. ;    CCPLUS 1/2 page save ability.
  49. ;
  50.     aseg;            For M80 compatibility
  51. ;
  52. true    equ    -1
  53. false    equ    not true
  54. overlay    equ    false;        Handy for creating overlays
  55. ;
  56.     if    overlay
  57.      subttl    'Overlay system, load/execute only'
  58.     else
  59.      subttl    'Create relocation bits and load/execute'
  60.     endif
  61. ;
  62. ; cp/m values
  63. cout    equ    2
  64. tstr    equ    9
  65. reboot    equ    0
  66. sysfnc    equ    5
  67. @bdos    equ    sysfnc+1
  68. ;
  69. ; This governs the code below BDOS retained.  0 to discard CCP
  70. ccpsiz    equ    8;        256 byte pages, preserve this
  71. bdosiz    equ    14;        pages, normal bios/bdos relation
  72. ;
  73.     org    0100h;        cp/m compatible
  74. ;
  75. ; Use the CCP stack so that moved/executed systems can "ret"
  76. ; This stack is limited.  CCPLUS supplies adequate room.
  77.     lxi    h,@prgimg+3
  78.     mov    c,m;
  79.     inx    h
  80.     mov    b,m;        get size
  81.     inx    h
  82.     mov    a,m;        get pages
  83.     lxi    h,@prgimg
  84.     mov    d,h
  85.     mov    e,l;        save pointer to start
  86.     dad    b;        ^ to 1st relocation byte
  87. ;    "    "
  88. ; (a) is pages, (bc) is size, (de) is start, (hl) is reloc bits
  89. ;    "    "
  90. ; The following location, after forming the relocation bits,
  91. ; is automatically patched to be "jmp relocup".  However it
  92. ; may be patched to a "call" instruction for system verification,
  93. ; which will then fall through to "reloc" below.  The overlaid
  94. ; verification/adjustment code may use the space from "makeprl"
  95. ; below through the end of the page.  For example the overlay
  96. ; may query the operator as to whether the CCP is to be retained,
  97. ; and if not subtract 8 from (a).  Such a system may also detect
  98. ; that CCP is already retained by the bios/bdos jump relationship,
  99. ; and automatically remove the CCP retention bias.
  100. patch:    if    overlay;    Setup for creating an overlay
  101.      call    adjust;        call the overlay code
  102.     else
  103.      jmp    makeprl;    on 1st execution only
  104.     endif;        overlay
  105. ;    "    "        fall through as noted above
  106. ; do relocation, move and execute
  107. ; (a) is pages, (bc) is size, (de) is start, (hl) is reloc bits
  108. relocup:
  109.     push    h
  110.     lxi    h,reboot
  111.     shld    patch+1;    prevent another execution
  112.     lhld    @bdos;        form origin for relocated
  113.     cma;                code on page boundary
  114.     add    h;        This trucates bdos ptr downward
  115.     sui    ccpsiz-1;    allow for ccp retention
  116.     pop    h;        ^ relocation bits
  117. ;    "    "
  118. ; relocate the image (de)^, length (bc), in place
  119. ; using the bit vector at (hl);
  120. ; relocate by (a) pages.
  121. ; At completion the image is ready to be moved
  122. ; into place at location (a) [entry] * 256.
  123. ; h,l
  124. reloc:    push    b;        save length
  125.     push    d;        save pointer to image
  126.     push    psw;        save relocation amount
  127.     call    vlength;    form bit vector length
  128. reloc1:    pop    psw
  129.     push    b;        save byte counter
  130.     push    psw;        relocation amount
  131.     mvi    c,8
  132.     mov    b,m;        get reloc bits
  133.     xchg
  134. reloc2:    mov    a,b
  135.     add    a
  136.     mov    b,a
  137.     jnc    reloc3;        dont relocate this
  138.     pop    psw;        relocation amount
  139.     push    psw
  140.     add    m
  141.     mov    m,a
  142. reloc3:    inx    h;        next object byte
  143.     dcr    c
  144.     jnz    reloc2;        more bits to scan
  145.     xchg
  146.     inx    h;        next reloc bit vector
  147.     pop    psw
  148.     pop    b
  149.     push    psw
  150.     dcx    b
  151.     mov    a,b
  152.     ora    c
  153.     jnz    reloc1;        not done
  154.     pop    h;        h := pushed a
  155.     mov    l,b;        zero, form origin
  156.     pop    d;        ^image
  157.     pop    b;        restore length
  158. ;    "    "        relocation done
  159.     push    h;        save as execution point, move exit
  160. ;    "    "        Note that CCP return is under this
  161. ;    "    "
  162. ; move (bc) bytes from (de)^ to (hl)^
  163. ; (bc) <> 0 on entry.
  164. ; a,f,b,c,d,e,h,l
  165. move:    ldax    d;        move relocated image
  166.     mov    m,a
  167.     inx    d
  168.     inx    h
  169.     dcx    b
  170.     mov    a,b
  171.     ora    c
  172.     jnz    move
  173.     ret;            execute relocated image
  174. ;
  175. ; form length of relocation bit vector
  176. ;  = ((bc)+7) DIV 8)
  177. ; a,f,b,c
  178. vlength:
  179.     push    h;        round size up to
  180.     lxi    h,7
  181.     dad    b;        multiple of 8
  182.     mov    c,l
  183.     mov    b,h
  184.     pop    h
  185. ;    "    "
  186. ; shift (bc) right 3 places, 0s in
  187. ; a,f,b,c
  188. bcrz3:    call    bcrz
  189. ;    "    "
  190. ; shift (bc) right 2 places, 0s in
  191. ; a,f,b,c
  192. bcrz2:    call    bcrz
  193. ;    "    "
  194. ; shift (bc) right, inserting zero bit
  195. ; a,f,b,c
  196. bcrz:    ora    a;        clear any carry
  197.     mov    a,b
  198.     rar
  199.     mov    b,a
  200.     mov    a,c
  201.     rar
  202.     mov    c,a
  203.     ret
  204. ;
  205. ; ***************************************************************
  206. ; * After initial execution to form the relocation bit vectori    *
  207. ; * the code from here up may be overlaid by load-time code to    *
  208. ; * verify system validity, modify parameters, etc.  Caution:    *
  209. ; * the CCP stack is in use.   Typical overlay code would be:    *
  210. ; *        org    patch                    *
  211. ; *        call    whatzis;    with regs as at patch    *
  212. ; *        org    makeprl                    *
  213. ; * whatzis:    ....;            preserving stack levels *
  214. ; *        ret;        reg. state governs relocation    *
  215. ; ***************************************************************
  216. ;
  217.     if    overlay;    insert the overlay code here
  218. ;
  219. ; Check if the CCP has already been retained, and if so adjust
  220. ; the relocation values so as not to retain the space twice
  221. adjust:     push    psw
  222.      push    h
  223.      lda    reboot+2;    Page for bios system
  224.      lxi    h,sysfnc+2
  225.      sub    m
  226.      pop    h
  227.      sui    bdosiz;        If this is not exact, assume
  228.      jnz    adjust1;    that ccp is already saved
  229.      pop    psw
  230.      ret
  231. adjust1: pop    psw;        Dont need this space reserved
  232.      sui    ccpsiz;
  233.      ret
  234.     else;            form the relocation bits
  235. ; make relocatable code file from double image at 0200h up
  236. ; A second image is located immediately above the zero based
  237. ; image, assembled for origin at 0100h.
  238. makeprl: push    h
  239.      lxi    h,relocup
  240.      shld    patch+1;        next execution moves
  241.      pop    h
  242. ;     "    "
  243. ; make bit vector
  244. ; at entry, (bc) = bytes to examine
  245. ;           (de) = ^0 based image
  246. ;           (hl) = ^ 0100h based image,
  247. ;                   and to start of bit
  248. ;                   vector storage area.
  249. ; At exit (hl) points to free byte above
  250. ;   the computed relocation vector.
  251. ; a,f,b,c,d,e,h,l
  252. vect:     call    vlength;    form bit vector length
  253.      push    b;        save vector byte counter
  254.      push    h;        save vector storage ptr.
  255. vect1:     lxi    b,8;        bit count and zero reloc byte
  256. vect2:     ldax    d
  257.      sub    m
  258.      adi    1;        carry if difference was 1
  259.      mov    a,b
  260.      adc    a;        2*a+cy
  261.      mov    b,a
  262.      inx    d
  263.      inx    h
  264.      dcr    c
  265.      jnz    vect2;        same vector byte
  266.      pop    b;        ^ vector storage
  267.      stax    b;        save vector byte
  268.      inx    b
  269.      xthl;            save ^ 1 based,
  270.      dcx    h;        get & decrement counter
  271.      mov    a,h
  272.      ora    l
  273.      xthl;            restack counter
  274.      push    b;        and vector pointer
  275.      jnz    vect1;        more bytes to generate
  276.      pop    h;        point to next free byte
  277.      pop    b;        purge stack
  278. ;     "    "
  279.      push    h
  280.      lxi    d,pgmsg
  281.      mvi    c,tstr
  282.      call    sysfnc
  283.      pop    h
  284.      dcx    h;        ^ last used byte
  285.      push    h
  286.      mov    a,h
  287.      call    tadzs;        signal pages to save
  288.      pop    h
  289.      mov    a,l
  290.      ora    a
  291.      jm    reboot;        last 1/2 page used
  292.      mov    a,h
  293.      dcr    a
  294.      push    psw
  295.      mvi    a,'('
  296.      call    couta;        signal usage for "SAVE nn+"
  297.      pop    psw;          available in CCPLUS
  298.      call    tadzs
  299.      mvi    a,'+'
  300.      call    couta
  301.      mvi    a,')'
  302.      call    couta
  303.      jmp    reboot;        cp/m exit
  304. ;
  305. ; output (a) in decimal to console, no leading zeroes
  306. ; a,f,b,c,d,e,h,l
  307. tadzs:     mov    l,a
  308.      mvi    h,0
  309. ;     "    "
  310. ; output (hl) in decimal to console.
  311. ;  suppress leading zeros.
  312. ; a,f,b,c,d,e,h,l
  313. tdzs:     lxi    b,0f00ah;    c=divisor=1 , b=iter cnt=-16
  314.      xra    a;        clear
  315. tdzs1:     dad    h;        m := (hl)/10; rdr to (a)
  316.      ral;            shift off into (a)
  317.      cmp    c;        test
  318.      jc    tdzs2;        no bit
  319.      sub    c;        bit = 1
  320.      inx    h
  321. tdzs2:     inr    b
  322.      jm    tdzs1;        not done
  323.      push    psw;        save output digit
  324.      mov    a,h
  325.      ora    l
  326.      cnz    tdzs;        not left digit, recursive
  327.      pop    psw;        last unlisted digit
  328.      adi    '0'
  329. ;     "    "
  330. ; output (a) to console
  331. ; a,f,b,c,d,e,h,l
  332. couta:     mov    e,a;        output (a) to console
  333.      mvi    c,cout
  334.      jmp    sysfnc;        and exit
  335. ;
  336. pgmsg:     db    'Now SAVE $'
  337.     endif;        Not overlay
  338. ;
  339. ; Where the zero based program image belongs.
  340. @prgimg    equ    ($+0ffh) AND 0ff00h
  341.     end
  342. U