Subversion Repositories Kolibri OS

Rev

Rev 7773 | 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. inline dword mem_init()
  9. {
  10.         $push    ebx
  11.         $mov     eax, 68
  12.         $mov     ebx, 11
  13.         $int     0x40
  14.        
  15.         $pop     ebx
  16. }
  17.  
  18. :dword malloc(dword size)
  19. {
  20.         $push    ebx
  21.         $push    ecx
  22.  
  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.  
  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.        
  57.         $mov     eax, 68
  58.         $mov     ebx, 13
  59.         $mov     ecx, mptr
  60.         $test    ecx, ecx
  61.         $jz      end0
  62.         $int     0x40
  63.    @end0:
  64.         $pop     ecx
  65.         $pop     ebx
  66.         $pop     eax
  67.         return 0;
  68. }
  69.  
  70. inline fastcall memmov( EDI, ESI, ECX)
  71. {
  72.   asm {
  73.     MOV EAX, ECX
  74.     CMP EDI, ESI
  75.     JG L1
  76.     JE L2
  77.     SAR ECX, 2
  78.     JS L2
  79.     REP MOVSD
  80.     MOV ECX, EAX
  81.     AND ECX, 3
  82.     REP MOVSB
  83.     JMP SHORT L2
  84. L1: LEA ESI, DSDWORD[ ESI+ECX-4]
  85.     LEA EDI, DSDWORD[ EDI+ECX-4]
  86.     SAR ECX, 2
  87.     JS L2
  88.     STD
  89.     REP MOVSD
  90.     MOV ECX, EAX
  91.     AND ECX, 3
  92.     ADD ESI, 3
  93.     ADD EDI, 3
  94.     REP MOVSB
  95.     CLD
  96. L2:
  97.   }
  98. }
  99.  
  100. #define SHM_OPEN        0x00
  101. #define SHM_OPEN_ALWAYS 0x04
  102. #define SHM_CREATE      0x08
  103. #define SHM_READ        0x00
  104. #define SHM_WRITE       0x01
  105. inline fastcall dword memopen(ECX, EDX, ESI)
  106. {
  107.         $mov     eax, 68
  108.         $mov     ebx, 22
  109.         // ecx = area name, 31 symbols max
  110.         // edx = area size for SHM_CREATE SHM_OPEN_ALWAYS
  111.         // esi = flags, see the list below:
  112.         $int     0x40
  113.         // eax, edx - please check system documentation
  114. }
  115.  
  116. inline fastcall dword memclose(ECX)
  117. {
  118.         $mov     eax, 68
  119.         $mov     ebx, 23
  120.         $int     0x40
  121.         // eax destroyed
  122. }
  123.  
  124. #define mem_Alloc malloc
  125. #define mem_ReAlloc realloc
  126. #define mem_Free free
  127. #define mem_Init mem_init
  128.  
  129. #endif