Subversion Repositories Kolibri OS

Rev

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