SECTION .text align=0 [bits 32] %include "eelstd.h" GLOBAL r_bytes GLOBAL m_alloc GLOBAL dm_alloc GLOBAL get_physmem GLOBAL RAM RAM dd 0 get_physmem: xor eax,eax mov ebp,0xC0CAC01A mov ecx,4095 mov ebx,1024*1024 .check: mov edx,[ebx] mov [ebx],ebp jmp $+2 cmp [ebx],ebp jne .no_more_ram mov [ebx],edx add ebx,1024*1024 loop .check .no_more_ram: mov [RAM],ebx ret ; Allocates a chunc of memory (not very efficient for the moment, but it works..) ; ; IN: ecx = length in 4kb blocks ; ; OUT: eax = 0 if successfull ; esi -> absolute address of block ; r_bytes dd 0 m_alloc: cld push esi push ecx push edx push ds push byte data32 pop ds mov edx,ecx mov [r_bytes],ecx xor esi,esi mov ecx,1024*4 .scan_block: lodsd test eax,800h jnz .not_free dec edx jz .found_block jmp .scan_block .not_free: mov edx,[r_bytes] loop .scan_block mov al,0ffh jmp .mal_exit .found_block: push esi mov eax,[r_bytes] shl eax,2 sub esi,eax mov eax,[esi] and eax,0fffff000h mov esi,eax pop eax mov ecx,[r_bytes] .alloc_mem: or dword [eax-4],800h ;changes... lodsd = mov eax,[esi]; add esi,4 sub eax,byte 4 loop .alloc_mem pop ds pop edx pop ecx pop eax ;NOT esi xor eax,eax popfd iretd .mal_exit: pop ds pop edx pop ecx pop esi popfd iretd ; Deallocates a memory block ; ; IN: esi -> absolute address of block ; ecx = number of 4kb blocks to deallocate ; ; OUT: eax = 0 if successfull ; dm_alloc: push ds push ecx push esi push byte data32 pop ds shr esi,10 .dealloc: and dword [esi],0fffff7ffh add esi,byte 4 loop .dealloc xor eax,eax pop esi pop ecx pop ds popfd iretd