Subversion Repositories Kolibri OS

Rev

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