home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / SOURCE / ALL / CW / GENERAL.INC < prev    next >
Text File  |  1993-08-24  |  4KB  |  192 lines

  1. ;
  2. ;
  3. ;Some things to bear in mind when in protected mode.
  4. ;
  5. ;
  6. ;Loading a segment register with an invalid selector causes an exception. This includes
  7. ;pop'ing it off the stack. eg, ES points to a memory block used at some previous point in
  8. ;the program, you then release the memory, perhaps to load more sprites etc. ES now contains
  9. ;an invalid segment selector value, the next time its pop'd an exception will occur. The best
  10. ;solution to this problem seems to be to start with ALL segment regs pointing to something like
  11. ;your data seg which you know isn't going to become invalid, then procede on the assumption that
  12. ;any segment register loads require the old value to be preserved, just as you would normaly do
  13. ;when modifying DS.
  14. ;
  15. ;
  16. ;386SHELL.EXE assumes any program files it loads use a single 32 bit segment (USE32). A command
  17. ;line switch maybe added to 386PREP to allow for 16 bit segments.
  18. ;
  19. ;
  20. ;In a Use32 segment, the default oprand size is 32 bits. This includes LOOP,REP etc (ECX is used).
  21. ;String instructions, eg, lodsb/stosb use ESI/EDI. Using a DB 66h before the instuction will
  22. ;revert to the 16 bit usage. This overide sets the operand size for ALL registers involved in an
  23. ;instruction, eg, db 66h, rep movsb would use CX,SI,DI.
  24. ;
  25. ;
  26. ;"Only" 16384 different segment selectors in the LDT. Keep allocation of small chunks of memory
  27. ;to a minimum. Memory allocation requests may be refused by 386shell due to insuficient selector
  28. ;table space. No use is made of the GDT to preserve protection model.
  29. ;
  30.  
  31.  
  32. b    equ    byte ptr
  33. w    equ    word ptr
  34. d    equ    dword ptr
  35. f    equ    fword ptr
  36.  
  37. Pushm    MACRO    R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16
  38.     IRP    X,<R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16>     ;REPEAT FOR EACH PARM
  39.     IFNB    <X>            ;IF THIS PARM NOT BLANK
  40.     PUSH    X            ;SAVE THE REGISTER
  41.     ENDIF                ;END IFNB
  42.     ENDM                ;END IRP
  43.     ENDM
  44.  
  45. Popm    macro    R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16
  46.     IRP    X,<R16,R15,R14,R13,R12,R11,R10,R9,R8,R7,R6,R5,R4,R3,R2,R1> ;REPEAT FOR EACH PARM
  47.     IFNB    <X>                ;IF THIS PARM NOT BLANK
  48.     POP    X                ;POP THE REGISTER
  49.     ENDIF                    ;END IFNB
  50.     ENDM                    ;END IRP
  51.     ENDM
  52.  
  53. Rep_movs    macro
  54.     push    ecx
  55.     shr    ecx,1
  56.     push    ecx
  57.     shr    ecx,1
  58.     rep    movsd
  59.     pop    ecx
  60.     and    ecx,1
  61.     rep    movsw
  62.     pop    ecx
  63.     and    ecx,1
  64.     rep    movsb
  65.     endm
  66.  
  67. Rep_stos    macro
  68.     push    ecx
  69.     shr    ecx,1
  70.     push    ecx
  71.     shr    ecx,1
  72.     rep    stosd
  73.     pop    ecx
  74.     and    ecx,1
  75.     rep    stosw
  76.     pop    ecx
  77.     and    ecx,1
  78.     rep    stosb
  79.     endm
  80.  
  81.  
  82. GetMemory    macro p1,p2,p3
  83.     mov    ecx,p1
  84.     mov    dx,cx
  85.     shr    ecx,16
  86.     mov    ah,48h
  87.     sys    GetMem
  88.     jc    p3
  89.     mov    p2,bx
  90.     mov    esi,MemoryListPos
  91.     mov    [esi],bx
  92.     add    MemoryListPos,2
  93.     endm
  94.  
  95. LoseMemory    macro
  96.     local __reloop1
  97.     local __reloop2
  98.     pushm    ds,ds,ds
  99.     popm    es,fs,gs
  100.     lea    esi,MemoryList
  101. __reloop1:    mov    bx,[esi]
  102.     cmp    bx,-1
  103.     jz    __reloop2
  104.     push    esi
  105.     sys    RelMem
  106.     pop    esi
  107.     add    esi,2
  108.     jmp    __reloop1
  109. __reloop2:    nop
  110.     endm
  111.  
  112.  
  113. DDS    struc        ;Structure to get at Low/high words.
  114. lw    dw ?
  115. hw    dw ?
  116. DDS    ends
  117.  
  118.  
  119. DDF    struc        ;Structure to get at offset/segment in F word.
  120. of    dd ?
  121. sg    dw ?
  122. DDF    ends
  123.  
  124.  
  125. ;
  126. ;Some new instructions to take note of:-
  127. ;
  128. ;BT    test bit. eg BT Flags,1  bit is reflected in carry flag.
  129. ;
  130. ;BTC    bit test & complement.
  131. ;
  132. ;BTR    bit test & reset.
  133. ;
  134. ;BTS    bit test & set.
  135. ;
  136. ;CWDE    word to dword in EAX.
  137. ;
  138. ;CDQ    dword to qword.
  139. ;
  140. ;ENTER    make stack frame. ENTER bytes,?. subs bytes from sp.
  141. ;
  142. ;IRETD    32-bit iret.
  143. ;
  144. ;JECXZ    jump ECX zero.
  145. ;
  146. ;LAR    load access rights. LAR EAX,DS look in the book for bit details.
  147. ;
  148. ;LEAVE    cleanup the stack.
  149. ;
  150. ;LGDT    load global descriptor table reg.
  151. ;
  152. ;LIDT    load interupt descriptor table register.
  153. ;
  154. ;LLDT    load local descriptor table. (effectively segment selector value for GDT)
  155. ;
  156. ;LMSW    load machine status word.
  157. ;
  158. ;SMSW    store machine status word.
  159. ;
  160. ;LSL    load segment limit. LSL EAX,Segment (adjusts for G bit)
  161. ;
  162. ;LTR    load task register.
  163. ;
  164. ;MOVSX    mov with sign extend. eg, MOVSX EAX,AX (same as CWDE AX)
  165. ;
  166. ;MOVZX    mov with zero extend.
  167. ;
  168. ;PUSHAD    push 8 general regs 32 bit.
  169. ;
  170. ;POPAD    pop 8 general regs 32 bit.
  171. ;
  172. ;SETcc    set byte on condition.
  173. ;
  174. ;SGDT    store global descriptor table.
  175. ;
  176. ;SIDT    store interupt descriptor table.
  177. ;
  178. ;SHLD    double precision shift left. SHLD reg1,reg2,count. :- shl reg2,count rcl reg1,count etc
  179. ;
  180. ;SHRD    as above only not.
  181. ;
  182. ;SLDT    store local descriptor table register.
  183. ;
  184. ;STR    store task register.
  185. ;
  186. ;VERR    verify segment for reading.
  187. ;
  188. ;VERW    verify segment for writing.
  189. ;
  190.  
  191. 
  192.