Page 1 of 1

Memory manager

Posted: Wed May 21, 2003 11:00 pm
by pepito
Hello:

I am writing a basic memory manager for my OS (for i386). Up to now I have the basic:  'initialization', 'allocation' and 'deallocation' functions (as Tim Robinson stay).

I like add the 'mapping' functions but have a problem:

My first function try to add an entry to the page directory. I follow this steps:

1) Find a free entry into the page directory
2) Get a page for the page table (I do it with my allocation function)
3) Update the page directorio
4) Fill the page table with 'no present' entries

The first 3 steps are easy, but when I try to fill the page table with 'no present' entries (zeros) I DON'T KNOW HOW ACCESS THE PAGE:

My code say some like this (it is not tested):

-------------------------------------------------------------------------

; Load gs with the linear selector (begin at 0x000, comprise the whole memory)

mov ax, _desc_lineal  
mov gs, ax

mov ebx, 0x1000 ; I put my page directory at 0x1000
mov ecx, 0x400 ; 1024 entries counter

; Find the first 'no present' entry

.find
mov eax, [gs:ebx] ; Get the entry
and eax, 1        ; Get the 'present´bit
jne .space        ; If 0 then I get the space
add ebx, 4        ; If 1 go to the next entry
loop .find

jmp .error        ; There is not space! Jump to .error

.space:

mov ah, 0x01 ; This service allocate a page and return EAX=address
int 0x33 ; Do it!

; Update the directory.

or eax, 0x0003 ; Add some control bits to EAX (where the address is)
mov [gs:ebx], eax ; Insert the entry

; Fill the page with 1024 32bit 'no present' entries.
; Oh, oh. How can I refer the page I've created <--- MY PROBLEM


-------------------------------------------------------------------------

Because the CPU is working with 'paging' active then it try to resolve the
address as DIR-PAGE-OFFSET but I have a real address.

I hope somebody understand my problem.

Thank you

pepito