Ok, heres a tough one. Im writing a function that disables paging to access all of memory, just like in JamesM tutorial, so it can copy contents of one frame into another.
Code: Select all
copy_frame:
push ebx
pushf ; push flags in case interrups were enabled
cli
mov ebx, [esp+12] ; source
mov ecx, [esp+16] ; dest
mov edx, cr0
and edx, 0x7fffffff
mov cr0, edx ; disable paging.
mov edx, 1024
.loop:
mov eax, [ebx]
mov [ecx], eax
add ebx, 4
add ecx, 4
dec edx
jnz .loop
mov edx, cr0
or edx, 0x80000000
mov cr0, edx ; enable paging
popf
pop ebx
ret
Its pretty much the same thing, but heres the catch. My kernel is mapped to 0xc00100000, and this function is located within the compiled kernel, and it has to be in order to be called within the kernel, but it crashes everything. Ive realized its because after it disables paging, it thinks that the next instruction is at 0xc00100000 + offset, so it cant read it because theres not that much RAM in the system, and it fails. I tried an org directive right after paging is disabled, but nasm wont compile it because it has to look like [org 0x00100000 + label], and thats not a valid format for the directive. Any ideas on how to solve this? I thought of copying the frames without disabling paging, and thats all well and good, but if I get a frame address higher than what the kernel can see, which is 0x00400000, it will page fault. I dont want to make the kernel tables map all of memory, so I need to disable paging in case it tries to copy to a frame high than what is mapped in the kernels directory.