Rev 6887 | Rev 7773 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6887 | Rev 7160 | ||
---|---|---|---|
1 | #ifndef INCLUDE_MEM_H |
1 | #ifndef INCLUDE_MEM_H |
2 | #define INCLUDE_MEM_H |
2 | #define INCLUDE_MEM_H |
3 | 3 | ||
4 | #ifndef INCLUDE_KOLIBRI_H |
4 | #ifndef INCLUDE_KOLIBRI_H |
5 | #include "../lib/kolibri.h" |
5 | #include "../lib/kolibri.h" |
6 | #endif |
6 | #endif |
7 | 7 | ||
8 | dword mem_init() |
8 | :dword mem_init() |
9 | { |
9 | { |
10 | $push ebx |
10 | $push ebx |
11 | $mov eax, 68 |
11 | $mov eax, 68 |
12 | $mov ebx, 11 |
12 | $mov ebx, 11 |
13 | $int 0x40 |
13 | $int 0x40 |
14 | 14 | ||
15 | $pop ebx |
15 | $pop ebx |
16 | return EAX; |
16 | return EAX; |
17 | } |
17 | } |
18 | 18 | ||
19 | dword malloc(dword size) |
19 | :dword malloc(dword size) |
20 | { |
20 | { |
21 | $push ebx |
21 | $push ebx |
22 | $push ecx |
22 | $push ecx |
23 | 23 | ||
24 | $mov eax, 68 |
24 | $mov eax, 68 |
25 | $mov ebx, 12 |
25 | $mov ebx, 12 |
26 | $mov ecx, size |
26 | $mov ecx, size |
27 | $int 0x40 |
27 | $int 0x40 |
28 | 28 | ||
29 | $pop ecx |
29 | $pop ecx |
30 | $pop ebx |
30 | $pop ebx |
31 | return EAX; |
31 | return EAX; |
32 | } |
32 | } |
33 | 33 | ||
34 | stdcall dword realloc(dword mptr, size) |
34 | :stdcall dword realloc(dword mptr, size) |
35 | { |
35 | { |
36 | $push ebx |
36 | $push ebx |
37 | $push ecx |
37 | $push ecx |
38 | $push edx |
38 | $push edx |
39 | 39 | ||
40 | $mov eax, 68 |
40 | $mov eax, 68 |
41 | $mov ebx, 20 |
41 | $mov ebx, 20 |
42 | $mov ecx, size |
42 | $mov ecx, size |
43 | $mov edx, mptr |
43 | $mov edx, mptr |
44 | $int 0x40 |
44 | $int 0x40 |
45 | 45 | ||
46 | $pop edx |
46 | $pop edx |
47 | $pop ecx |
47 | $pop ecx |
48 | $pop ebx |
48 | $pop ebx |
49 | return EAX; |
49 | return EAX; |
50 | } |
50 | } |
51 | 51 | ||
52 | dword free(dword mptr) |
52 | :dword free(dword mptr) |
53 | { |
53 | { |
54 | $push eax |
54 | $push eax |
55 | $push ebx |
55 | $push ebx |
56 | $push ecx |
56 | $push ecx |
57 | 57 | ||
58 | $mov eax, 68 |
58 | $mov eax, 68 |
59 | $mov ebx, 13 |
59 | $mov ebx, 13 |
60 | $mov ecx, mptr |
60 | $mov ecx, mptr |
61 | $test ecx, ecx |
61 | $test ecx, ecx |
62 | $jz end0 |
62 | $jz end0 |
63 | $int 0x40 |
63 | $int 0x40 |
64 | @end0: |
64 | @end0: |
65 | $pop ecx |
65 | $pop ecx |
66 | $pop ebx |
66 | $pop ebx |
67 | $pop eax |
67 | $pop eax |
68 | return 0; |
68 | return 0; |
69 | } |
69 | } |
70 | 70 | ||
71 | inline fastcall memmov( EDI, ESI, ECX) |
71 | inline fastcall memmov( EDI, ESI, ECX) |
72 | { |
72 | { |
73 | asm { |
73 | asm { |
74 | MOV EAX, ECX |
74 | MOV EAX, ECX |
75 | CMP EDI, ESI |
75 | CMP EDI, ESI |
76 | JG L1 |
76 | JG L1 |
77 | JE L2 |
77 | JE L2 |
78 | SAR ECX, 2 |
78 | SAR ECX, 2 |
79 | JS L2 |
79 | JS L2 |
80 | REP MOVSD |
80 | REP MOVSD |
81 | MOV ECX, EAX |
81 | MOV ECX, EAX |
82 | AND ECX, 3 |
82 | AND ECX, 3 |
83 | REP MOVSB |
83 | REP MOVSB |
84 | JMP SHORT L2 |
84 | JMP SHORT L2 |
85 | L1: LEA ESI, DSDWORD[ ESI+ECX-4] |
85 | L1: LEA ESI, DSDWORD[ ESI+ECX-4] |
86 | LEA EDI, DSDWORD[ EDI+ECX-4] |
86 | LEA EDI, DSDWORD[ EDI+ECX-4] |
87 | SAR ECX, 2 |
87 | SAR ECX, 2 |
88 | JS L2 |
88 | JS L2 |
89 | STD |
89 | STD |
90 | REP MOVSD |
90 | REP MOVSD |
91 | MOV ECX, EAX |
91 | MOV ECX, EAX |
92 | AND ECX, 3 |
92 | AND ECX, 3 |
93 | ADD ESI, 3 |
93 | ADD ESI, 3 |
94 | ADD EDI, 3 |
94 | ADD EDI, 3 |
95 | REP MOVSB |
95 | REP MOVSB |
96 | CLD |
96 | CLD |
97 | L2: |
97 | L2: |
98 | } |
98 | } |
99 | } |
99 | } |
100 | 100 | ||
101 | 101 | ||
102 | 102 | ||
103 | #define mem_Alloc malloc |
103 | #define mem_Alloc malloc |
104 | #define mem_ReAlloc realloc |
104 | #define mem_ReAlloc realloc |
105 | #define mem_Free free |
105 | #define mem_Free free |
106 | #define mem_Init mem_init |
106 | #define mem_Init mem_init |
107 | 107 | ||
108 | #endif |
108 | #endif |