Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. movedata:
  3.         push eax
  4.         xor eax,eax
  5.         sub eax,edi
  6.         and eax,3
  7.         xchg ecx,eax
  8.         sub eax,ecx
  9.         jle .l1
  10.         rep movsb
  11.         mov ecx,eax
  12.         shr ecx,2
  13.         rep movsd
  14.         and eax,3
  15.    .l1: add ecx,eax
  16.         rep  movsb
  17.         pop eax
  18.         ret
  19.  
  20. mallocz:
  21.         call malloc
  22.         pushad
  23.         add ecx,3
  24.         xor eax,eax
  25.         shr ecx,2
  26.         rep stosd
  27.         popad
  28.         ret
  29.  
  30.      mresize1: popad
  31.                 xor edi,edi
  32.                 stc
  33.      mresize2: ret
  34. mresize: ; puntero en di ncr retorna nuevo puntero en di
  35.        test edi,edi
  36.        jz malloc
  37.        cmp ecx,[edi-4]
  38.        je mresize2
  39.        call free
  40. malloc:
  41.         mov edi,ecx
  42.         jecxz mresize2
  43.         pushad
  44.         mov esi,iniciomemoria+4
  45.         lea ebx,[ecx+3]
  46.         and ebx,-4 ;redondeo a 4
  47.     .l1: mov edi,esi
  48.         add esi,[esi]
  49.         jc mresize1
  50.         lodsd
  51.         cmp eax,ebx
  52.         jc .l1
  53.         cmp esi,[iniciomemoria+8]
  54.         jc .l2
  55.         jne mresize1
  56.         lea edx,[ebx+esi+4]
  57.         cmp edx,[iniciomemoria+12]
  58.         jnc mresize1
  59.         mov [iniciomemoria+8],edx
  60.     .l2: pop dword [esi-4]
  61.         push esi
  62.         sub eax,ebx
  63.         je .l3
  64.         sub eax,4
  65.         mov [esi+ebx],eax
  66.         jz .l3
  67.         ;fragmentar
  68.         add ebx,4
  69.         add [edi],ebx
  70.         mov eax,[esi]
  71.         sub eax,ebx
  72.         mov [esi+ebx],eax
  73.         popad
  74.         ret
  75.     .l3: lodsd
  76.         add eax,4
  77.         add [edi],eax
  78.         popad
  79.         ret
  80.  
  81. realloc: test edi,edi
  82.         jz malloc
  83.         jecxz free
  84.        pushad
  85.        pop esi
  86.        mov eax,[edi-4]
  87.        call malloc
  88.        push edi
  89.        cmp ecx,eax
  90.        jc .l1
  91.        mov ecx,eax
  92.     .l1: push esi
  93.         call movedata
  94.        pop edi
  95.        call free
  96.        popad
  97.    .l2: ret
  98. free:           ;puntero en di
  99.                 ;no se comprueban los punteros
  100.                 ;retorna di=0 , ncr
  101.        test edi,edi
  102.        jz realloc.l2
  103.        pushad
  104.        pop edi
  105.        mov ebp,[edi-4]
  106.        dec ebp
  107.        and ebp,-4  ;redondeo a 4,dx=dx-4
  108.        xor edx,edx
  109.        push edx
  110.        mov edx,iniciomemoria+4
  111.        mov esi,edx
  112.        ;buscar puntero libre anterior
  113.     .l1: mov ebx,esi
  114.        lodsd
  115.        add esi,eax
  116.        cmp esi,edi
  117.        jc .l1
  118.         ;enlazar
  119.        mov ecx,esi
  120.        sub ecx,edi
  121.        sub eax,ecx
  122.        sub ecx,4
  123.        mov [ebx],eax
  124.         ;fusionar con el anterior
  125.        cmp eax,[ebx-4]
  126.        jne .l2
  127.        cmp ebx,edx
  128.        je .l2 ;no fusionar con el primero
  129.        mov edi,ebx
  130.        add eax,4
  131.        add ecx,eax
  132.        add ebp,eax
  133.     .l2: mov ebx,ebp ;fusionar con bloques de tama¤o 0
  134.     .l3: add ebx,4
  135.        test dword [edi+ebx],-1
  136.        jz .l3
  137.        cmp ebx,ecx
  138.        jne .l4
  139.         ;fusionar con el siguiente
  140.         add ebx,[esi-4]
  141.         add ecx,[esi]
  142.         add ebx,4
  143.         add ecx,4
  144.         cmp esi,[edx+4]
  145.         jne .l4
  146.         mov [edx+4],edi
  147.      .l4: mov [edi-4],ebx
  148.         mov [edi],ecx
  149.         popad
  150.         ret
  151.  
  152. add_mem: ;edi,ecx ;el ultimo bloque libre debe ser >8 bytes para poder fragmentarlo
  153.         cmp ecx,64
  154.         jc .l1
  155.         add ecx,edi
  156.         add edi,3
  157.         and edi,-4
  158.         and ecx,-4
  159.         mov eax,ecx
  160.         sub ecx,edi   ;redondeo
  161.         xchg eax,[iniciomemoria+12]
  162.         cmp edi,eax
  163.         jna .l1
  164.         lea esi,[edi+4]
  165.         mov edx,esi
  166.         xchg esi,[iniciomemoria+8]
  167.         neg edx
  168.         mov [edi],edx
  169.         mov [edi+4],edx
  170.         lea edx,[edi-4]
  171.         sub edi,esi
  172.         mov [esi],edi
  173.         sub eax,4
  174.         sub eax,esi
  175.         mov [esi-4],eax
  176.         add esi,eax
  177.         sub edx,esi
  178.         mov [esi],edx
  179.    .l1: ret
  180.  
  181. check_mem:  ;busqueda de errores en la memoria
  182.            ;retorna edx nbloques o 0 si error,ecx memoria libre
  183.            ;ncr: ebp,ebx,eax
  184.         mov edi,iniciomemoria
  185.         mov esi,edi
  186.         xor edx,edx
  187.         mov ecx,[edi]
  188.         neg ecx ;el primer bloque no cuenta
  189.     .l1: add ecx,[edi]
  190.         add edi,4
  191.         add edi,[edi]
  192.    .l2: inc edx
  193.         add esi,[esi]
  194.         jc .l4
  195.         add esi,7
  196.         jc .l3
  197.         and esi,-4
  198.         cmp esi,edi
  199.         jc .l2
  200.         je .l1
  201.         jmp .l4
  202.     .l3: test edi,edi
  203.        jnz .l4
  204.        add ecx,[iniciomemoria+12]
  205.        ret
  206.      .l4: xor edx,edx
  207.       stc
  208.       ret
  209.  
  210.  
  211.