metalsvm/arch/x86/kernel/string.asm
Stefan Lankes 464f31a53b optimize the system call fork
- add a function to copy a physical page
=> reduce the using of vm_alloc and vm_free
2011-03-03 09:13:00 +01:00

98 lines
2.3 KiB
NASM

;
; Written by the Chair for Operating Systems, RWTH Aachen University
;
; NO Copyright (C) 2010-2011, Stefan Lankes
; consider these trivial functions to be public domain.
;
; These functions are distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;
[BITS 32]
SECTION .code
global strcpy
strcpy:
push ebp
mov ebp, esp
push edi
push esi
mov esi, [ebp+12]
mov edi, [ebp+8]
L1:
lodsb
stosb
test al, al
jne L1
mov eax, [ebp+8]
pop esi
pop edi
pop ebp
ret
global strncpy
strncpy:
push ebp
mov ebp, esp
push edi
push esi
mov ecx, [ebp+16]
mov esi, [ebp+12]
mov edi, [ebp+8]
L2:
dec ecx
js L3
lodsb
stosb
test al, al
jne L1
rep
stosb
L3:
mov eax, [ebp+8]
pop esi
pop edi
pop ebp
ret
; The following function based on JamesM's kernel development tutorials
; (http://www.jamesmolloy.co.uk/tutorial_html/)
global copy_page_physical
copy_page_physical:
push ebx ; According to __cdecl, we must preserve the contents of EBX.
pushf ; push EFLAGS, so we can pop it and reenable interrupts
; later, if they were enabled anyway.
cli ; Disable interrupts, so we aren't interrupted.
; Load these in BEFORE we disable paging!
mov ebx, [esp+16] ; Source address
mov ecx, [esp+12] ; Destination address
mov edx, cr0 ; Get the control register...
and edx, 0x7fffffff ; and...
mov cr0, edx ; Disable paging.
mov edx, 1024 ; 1024*4bytes = 4096 bytes
.loop:
mov eax, [ebx] ; Get the word at the source address
mov [ecx], eax ; Store it at the dest address
add ebx, 4 ; Source address += sizeof(word)
add ecx, 4 ; Dest address += sizeof(word)
dec edx ; One less word to do
jnz .loop
mov edx, cr0 ; Get the control register again
or edx, 0x80000000 ; and...
mov cr0, edx ; Enable paging.
popf ; Pop EFLAGS back.
pop ebx ; Get the original value of EBX back.
ret
SECTION .note.GNU-stack noalloc noexec nowrite progbits