Subversion Repositories Kolibri OS

Rev

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