Subversion Repositories Kolibri OS

Rev

Rev 7160 | 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. inline fastcall dword memopen(ECX, EDX, ESI)
  102. {
  103.         $push    ebx
  104.         $mov     eax, 68
  105.         $mov     ebx, 22
  106.         // ecx = area name, 31 symbols max
  107.         // edx = area size for SHM_CREATE SHM_OPEN_ALWAYS
  108.         // esi = flags, see the list below:
  109.         #define SHM_OPEN        0x00
  110.         #define SHM_OPEN_ALWAYS 0x04
  111.         #define SHM_CREATE      0x08
  112.         #define SHM_READ        0x00
  113.         #define SHM_WRITE       0x01
  114.         $int     0x40
  115.         $pop     ebx
  116.         // eax, edx - please check system documentation
  117. }
  118.  
  119. inline fastcall dword memclose(ECX)
  120. {
  121.         $push    ebx
  122.         $mov     eax, 68
  123.         $mov     ebx, 23
  124.         $int     0x40
  125.         $pop     ebx
  126.         // eax destroyed
  127. }
  128.  
  129. #define mem_Alloc malloc
  130. #define mem_ReAlloc realloc
  131. #define mem_Free free
  132. #define mem_Init mem_init
  133.  
  134. #endif