Subversion Repositories Kolibri OS

Rev

Rev 7773 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5598 pavelyakov 1
#ifndef INCLUDE_MEM_H
2
#define INCLUDE_MEM_H
3107 leency 3
 
5606 pavelyakov 4
#ifndef INCLUDE_KOLIBRI_H
5
#include "../lib/kolibri.h"
6
#endif
7
 
7774 leency 8
inline dword mem_init()
3067 leency 9
{
5598 pavelyakov 10
	$push    ebx
6021 leency 11
	$mov     eax, 68
12
	$mov     ebx, 11
13
	$int     0x40
14
 
15
	$pop     ebx
3067 leency 16
}
17
 
7160 leency 18
:dword malloc(dword size)
3067 leency 19
{
6021 leency 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;
3067 leency 31
}
32
 
7160 leency 33
:stdcall dword realloc(dword mptr, size)
3067 leency 34
{
6021 leency 35
	$push    ebx
36
	$push    ecx
37
	$push    edx
3067 leency 38
 
6021 leency 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;
3067 leency 49
}
50
 
7160 leency 51
:dword free(dword mptr)
3067 leency 52
{
6021 leency 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
3067 leency 63
   @end0:
6021 leency 64
	$pop     ecx
65
	$pop     ebx
66
	$pop     eax
67
	return 0;
3067 leency 68
}
69
 
3107 leency 70
inline fastcall memmov( EDI, ESI, ECX)
3067 leency 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
 
7774 leency 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
7773 leency 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
}
3128 leency 115
 
7773 leency 116
inline fastcall dword memclose(ECX)
117
{
118
	$mov     eax, 68
119
	$mov     ebx, 23
120
	$int     0x40
121
	// eax destroyed
122
}
3128 leency 123
 
3107 leency 124
#define mem_Alloc malloc
125
#define mem_ReAlloc realloc
126
#define mem_Free free
127
#define mem_Init mem_init
3067 leency 128
 
5598 pavelyakov 129
#endif