Subversion Repositories Kolibri OS

Rev

Rev 7774 | 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. inline fastcall void mem_init()
  9. {
  10.         $mov     eax, 68
  11.         $mov     ebx, 11
  12.         $int     0x40
  13. }
  14.  
  15. :dword malloc(dword size)
  16. {
  17.         $push    ebx
  18.         $push    ecx
  19.  
  20.         $mov     eax, 68
  21.         $mov     ebx, 12
  22.         $mov     ecx, size
  23.         $int     0x40
  24.        
  25.         $pop     ecx
  26.         $pop     ebx
  27.         return  EAX;
  28. }
  29.  
  30. :stdcall dword realloc(dword mptr, size)
  31. {
  32.         $push    ebx
  33.         $push    ecx
  34.         $push    edx
  35.  
  36.         $mov     eax, 68
  37.         $mov     ebx, 20
  38.         $mov     ecx, size
  39.         $mov     edx, mptr
  40.         $int     0x40
  41.  
  42.         $pop     edx
  43.         $pop     ecx
  44.         $pop     ebx
  45.         return   EAX;
  46. }
  47.  
  48. :dword free(dword mptr)
  49. {
  50.         $push    eax
  51.         $push    ebx
  52.         $push    ecx
  53.        
  54.         $mov     eax, 68
  55.         $mov     ebx, 13
  56.         $mov     ecx, mptr
  57.         $test    ecx, ecx
  58.         $jz      end0
  59.         $int     0x40
  60.    @end0:
  61.         $pop     ecx
  62.         $pop     ebx
  63.         $pop     eax
  64.         return 0;
  65. }
  66.  
  67. inline fastcall memmov( EDI, ESI, ECX)
  68. {
  69.   asm {
  70.     MOV EAX, ECX
  71.     CMP EDI, ESI
  72.     JG L1
  73.     JE L2
  74.     SAR ECX, 2
  75.     JS L2
  76.     REP MOVSD
  77.     MOV ECX, EAX
  78.     AND ECX, 3
  79.     REP MOVSB
  80.     JMP SHORT L2
  81. L1: LEA ESI, DSDWORD[ ESI+ECX-4]
  82.     LEA EDI, DSDWORD[ EDI+ECX-4]
  83.     SAR ECX, 2
  84.     JS L2
  85.     STD
  86.     REP MOVSD
  87.     MOV ECX, EAX
  88.     AND ECX, 3
  89.     ADD ESI, 3
  90.     ADD EDI, 3
  91.     REP MOVSB
  92.     CLD
  93. L2:
  94.   }
  95. }
  96.  
  97. #define SHM_OPEN        0x00
  98. #define SHM_OPEN_ALWAYS 0x04
  99. #define SHM_CREATE      0x08
  100. #define SHM_READ        0x00
  101. #define SHM_WRITE       0x01
  102. inline fastcall dword memopen(ECX, EDX, ESI)
  103. {
  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.         $int     0x40
  110.         // eax, edx - please check system documentation
  111. }
  112.  
  113. inline fastcall dword memclose(ECX)
  114. {
  115.         $mov     eax, 68
  116.         $mov     ebx, 23
  117.         $int     0x40
  118.         // eax destroyed
  119. }
  120.  
  121. #define mem_Alloc malloc
  122. #define mem_ReAlloc realloc
  123. #define mem_Free free
  124. #define mem_Init mem_init
  125.  
  126. #endif