Subversion Repositories Kolibri OS

Rev

Rev 6887 | Rev 7774 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef INCLUDE_MEM_H
  2. #define INCLUDE_MEM_H
  3.  
  4. #ifndef INCLUDE_KOLIBRI_H
  5. #include "../lib/kolibri.h"
  6. #endif
  7.  
  8. :dword mem_init()
  9. {
  10.         $push    ebx
  11.         $mov     eax, 68
  12.         $mov     ebx, 11
  13.         $int     0x40
  14.        
  15.         $pop     ebx
  16.         return  EAX;
  17. }
  18.  
  19. :dword malloc(dword size)
  20. {
  21.         $push    ebx
  22.         $push    ecx
  23.  
  24.         $mov     eax, 68
  25.         $mov     ebx, 12
  26.         $mov     ecx, size
  27.         $int     0x40
  28.        
  29.         $pop     ecx
  30.         $pop     ebx
  31.         return  EAX;
  32. }
  33.  
  34. :stdcall dword realloc(dword mptr, size)
  35. {
  36.         $push    ebx
  37.         $push    ecx
  38.         $push    edx
  39.  
  40.         $mov     eax, 68
  41.         $mov     ebx, 20
  42.         $mov     ecx, size
  43.         $mov     edx, mptr
  44.         $int     0x40
  45.  
  46.         $pop     edx
  47.         $pop     ecx
  48.         $pop     ebx
  49.         return   EAX;
  50. }
  51.  
  52. :dword free(dword mptr)
  53. {
  54.         $push    eax
  55.         $push    ebx
  56.         $push    ecx
  57.        
  58.         $mov     eax, 68
  59.         $mov     ebx, 13
  60.         $mov     ecx, mptr
  61.         $test    ecx, ecx
  62.         $jz      end0
  63.         $int     0x40
  64.    @end0:
  65.         $pop     ecx
  66.         $pop     ebx
  67.         $pop     eax
  68.         return 0;
  69. }
  70.  
  71. inline fastcall memmov( EDI, ESI, ECX)
  72. {
  73.   asm {
  74.     MOV EAX, ECX
  75.     CMP EDI, ESI
  76.     JG L1
  77.     JE L2
  78.     SAR ECX, 2
  79.     JS L2
  80.     REP MOVSD
  81.     MOV ECX, EAX
  82.     AND ECX, 3
  83.     REP MOVSB
  84.     JMP SHORT L2
  85. L1: LEA ESI, DSDWORD[ ESI+ECX-4]
  86.     LEA EDI, DSDWORD[ EDI+ECX-4]
  87.     SAR ECX, 2
  88.     JS L2
  89.     STD
  90.     REP MOVSD
  91.     MOV ECX, EAX
  92.     AND ECX, 3
  93.     ADD ESI, 3
  94.     ADD EDI, 3
  95.     REP MOVSB
  96.     CLD
  97. L2:
  98.   }
  99. }
  100.  
  101.  
  102.  
  103. #define mem_Alloc malloc
  104. #define mem_ReAlloc realloc
  105. #define mem_Free free
  106. #define mem_Init mem_init
  107.  
  108. #endif