home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / driver6s / occupied.asm < prev    next >
Assembly Source File  |  1990-03-05  |  4KB  |  98 lines

  1. ; Subroutine to check if an address range is available for allocation
  2. ; as shared memory.
  3. ; Input:  bx = segment start address
  4. ;         di = # of bytes / 16
  5. ; Returns with carry set if range is occupied
  6. ; All registers saved and restored
  7. ;
  8.         public  occupied_chk
  9. occupied_chk:
  10.         push    ax                      ; save registers
  11.         push    bx
  12.         push    cx
  13.         push    dx
  14.         push    si
  15.         push    di
  16.         push    ds
  17. ;
  18. ; first check if there is any ROM in our range
  19. ;
  20.         add     di,bx                   ; end of range to check
  21.         mov     dx,0c000h               ; start of possible ROM area
  22. occ_next2k:
  23.         mov     ds,dx
  24.         xor     si,si
  25.         mov     cx,0aa55h               ; ROM signature
  26.         mov     ax,[si]
  27.         cmp     ax,cx                   ; any signature?
  28.         jne     occ_no_ROM
  29.         mov     ah,[si+2]               ; ROM length in 512 byte blocks
  30.         xor     al,al
  31.         mov     cx,ax
  32.         shr     ax,1
  33.         shr     ax,1
  34.         shr     ax,1
  35.         add     ax,dx                   ; end of ROM
  36.         cmp     ax,bx                   ; does it reach into our area?
  37.         jb      occ_no_ROM
  38.         shl     cx,1                    ; # of bytes to checksum
  39.         xor     ah,ah                   ; clear accumulated checksum
  40. occ_chksum:
  41.         lodsb                           ; get a byte
  42.         add     ah,al                   ; add modulo 100h
  43.         loop    occ_chksum              ; repeat for all bytes
  44.         or      ah,ah                   ; is checksum zero?
  45.         jz      occ_is_ROM              ; -yes, range is occupied
  46. occ_no_ROM:
  47.         add     dx,2048 shr 4           ; next 2k segment
  48.         cmp     dx,di                   ; at end of our range?
  49.         jbe     occ_next2k
  50. ;
  51. ; no ROM found in our range, check for RAM
  52. ;
  53.         mov     ds,bx                   ; point segment at start of range
  54.         sub     di,bx                   ; compute # of bytes
  55.         mov     cl,4
  56.         shl     di,cl
  57.         xor     bx,bx                   ; clear word pointer
  58.         mov     ax,0a5a5h               ; test pattern
  59.         mov     si,05a5ah               ;   and its complement
  60. occ_nextword:
  61.         sti                             ; disable interrupts
  62.         mov     cx,[bx]                 ; save original contents
  63.         mov     dx,[bx+2]               ; save original contents
  64.         mov     [bx],si                 ; put our pattern
  65.         mov     [bx+2],ax               ; drain any capacitive memory
  66.         cmp     [bx],si                 ; is our pattern still there?
  67.         mov     [bx],cx                 ; restore original contents
  68.         mov     [bx+2],dx               ; restore original contents
  69.         cli                             ; enable interrupts
  70.         jne     occ_no_RAM
  71.         sti                             ; disable interrupts
  72.         mov     [bx],ax                 ; put the complement pattern
  73.         mov     [bx+2],si               ; drain capacitive memory
  74.         cmp     [bx],ax                 ; our pattern still there?
  75.         mov     [bx],cx                 ; restore original contents
  76.         mov     [bx+2],dx               ; restore original contents
  77.         sti                             ; enable interrupts
  78.         je      occ_is_RAM              ; -yes, range is occupied
  79. occ_no_RAM:
  80.         add     bx,2                    ; check next word
  81.         cmp     bx,di                   ; at end of range?
  82.         jb      occ_nextword
  83.         clc                             ; clear carry - range is available
  84.         jmp     short occ_return
  85. occ_is_ROM:
  86. occ_is_RAM:
  87.         stc                             ; set carry - range is occupied
  88. occ_return:
  89.         pop     ds                      ; restore registers
  90.         pop     di
  91.         pop     si
  92.         pop     dx
  93.         pop     cx
  94.         pop     bx
  95.         pop     ax
  96.         ret
  97.  
  98.