home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CCDL151L.ZIP / MSDOS / 386 / LLMALLOC.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-06-12  |  2.0 KB  |  134 lines

  1.         .386
  2. locals
  3.  
  4. _TEXT        segment para public use32 'CODE'
  5.  
  6. _TEXT        ends
  7. _DATA       SEGMENT DWORD PUBLIC USE32 'DATA'
  8. extrn __linear : DWORD, __pmodew:word
  9. maxaddr    dd    0
  10.                 ENDS
  11.  
  12.     public __ll_malloc, __ll_free, __ll_transfer
  13.  
  14. DGROUP group _TEXT, _DATA
  15.  
  16. _TEXT        segment
  17.         assume cs:DGROUP,ds:DGROUP
  18. _main:
  19.         ret
  20. ;________________________________________________________________________
  21. ;
  22. ; doesn't resize SS or CS!!!! use at own risk!!!
  23. ;
  24. resizeds proc
  25.     test [__pmodew],-1
  26.     jnz noresize
  27.     cmp eax,[maxaddr]
  28.     jbe noresize
  29.     mov [maxaddr],eax
  30.     push ebx
  31.     push esi
  32.     push edi
  33.     dec eax
  34.     mov dx,ax
  35.     shr eax,16
  36.     mov cx,ax
  37.     mov bx,ds
  38.     mov ax,8
  39.     int 31h
  40.     pop edi
  41.     pop esi
  42.     pop ebx
  43.     cli
  44.     sub ax,ax
  45.     push es
  46.     mov es,ax
  47.     pop es
  48.     push fs
  49.     mov fs,ax
  50.     pop fs
  51.     push gs
  52.     mov gs,ax
  53.     pop gs
  54.     sti
  55. noresize:
  56.     ret
  57. resizeds endp
  58. ;
  59. ;void *__ll_malloc(int size)
  60. __ll_malloc:
  61.     push ebp
  62.     push esi
  63.     push edi
  64.     push ebx
  65.     mov ebx,[esp+20]
  66.     or ebx,ebx
  67.     jz @@failed
  68.     add ebx,4
  69.     and ebx,0fffff000h
  70.     mov cx,bx
  71.     shr ebx,16
  72.     mov ax,501h
  73.     int 31h
  74.     jc @@failed
  75.     shl ebx,16
  76.     mov bx,cx
  77.     sub ebx,[__linear]
  78.     mov eax,[esp+20]
  79.     add eax,4095+4
  80.     add eax,ebx
  81.     and eax,0fffff000h
  82.     call resizeds
  83.     mov [ebx],si
  84.     mov [ebx+2],di
  85.     add ebx,4
  86. @@go2:
  87.     mov eax,ebx
  88.     pop ebx
  89.     pop edi
  90.     pop esi
  91.     pop ebp
  92.     ret
  93. @@failed:
  94.     sub eax,eax
  95.     pop ebx
  96.     pop edi
  97.     pop esi
  98.     pop ebp
  99.     ret
  100. ;
  101. ;________________________________________________________________________
  102. ;void __ll_free(void *block)
  103. ;
  104. __ll_free:
  105.     push ebp
  106.     push esi
  107.     push edi
  108.     push ebx
  109.     mov ebx,[esp+20]
  110.     or ebx,ebx
  111.     jz @@failed
  112. ;
  113. ; if this were meant to be called by the user it would have more guards
  114. ; but the RTL should be the only thing calling it...
  115. ;
  116.     sub ebx,4
  117.     mov si,[ebx]
  118.     mov di,[ebx+2]
  119.     mov ax,502h
  120.     int 31h
  121. @@failed:
  122.     pop ebx
  123.     pop edi
  124.     pop esi
  125.     pop ebp
  126.     ret
  127.     
  128. ;________________________________________________________________________
  129. ;void __ll_transfer(void)
  130. __ll_transfer:
  131.     ret
  132. _TEXT        ends
  133.  
  134.                 END