2010-08-11 10:46:23 +00:00
|
|
|
;
|
2011-03-02 05:32:25 +01:00
|
|
|
; Written by the Chair for Operating Systems, RWTH Aachen University
|
|
|
|
;
|
2012-05-24 10:49:45 +02:00
|
|
|
; NO Copyright (C) 2010-2012, Stefan Lankes
|
2011-03-02 05:32:25 +01:00
|
|
|
; consider these trivial functions to be public domain.
|
|
|
|
;
|
|
|
|
; These functions are distributed on an "AS IS" BASIS,
|
2010-08-11 10:46:23 +00:00
|
|
|
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
;
|
|
|
|
|
2012-06-10 08:05:24 +02:00
|
|
|
[BITS 64]
|
2011-03-31 12:38:04 -07:00
|
|
|
SECTION .text
|
2010-08-11 10:46:23 +00:00
|
|
|
global strcpy
|
|
|
|
strcpy:
|
2012-06-10 08:05:24 +02:00
|
|
|
push rdi
|
2010-08-11 10:46:23 +00:00
|
|
|
|
|
|
|
L1:
|
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
test al, al
|
|
|
|
jne L1
|
|
|
|
|
2012-06-10 08:05:24 +02:00
|
|
|
pop rax
|
2010-08-11 10:46:23 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
global strncpy
|
|
|
|
strncpy:
|
2012-06-10 08:05:24 +02:00
|
|
|
push rdi
|
|
|
|
mov rcx, rdx
|
2010-08-11 10:46:23 +00:00
|
|
|
|
|
|
|
L2:
|
2012-06-10 08:05:24 +02:00
|
|
|
dec rcx
|
2010-08-11 10:46:23 +00:00
|
|
|
js L3
|
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
test al, al
|
|
|
|
jne L1
|
|
|
|
rep
|
|
|
|
stosb
|
|
|
|
|
|
|
|
L3:
|
2012-06-10 08:05:24 +02:00
|
|
|
pop rax
|
2010-08-11 10:46:23 +00:00
|
|
|
ret
|
2011-02-16 21:19:44 +01:00
|
|
|
|
2012-06-10 08:05:24 +02:00
|
|
|
%if 0
|
2011-03-08 14:39:21 +01:00
|
|
|
; The following function is derived from JamesM's kernel development tutorials
|
2011-03-03 09:13:00 +01:00
|
|
|
; (http://www.jamesmolloy.co.uk/tutorial_html/)
|
|
|
|
global copy_page_physical
|
|
|
|
copy_page_physical:
|
2011-03-08 14:39:21 +01:00
|
|
|
push esi ; According to __cdecl, we must preserve the contents of ESI
|
|
|
|
push edi ; and EDI.
|
2011-03-03 09:13:00 +01:00
|
|
|
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!
|
|
|
|
|
2011-03-08 14:39:21 +01:00
|
|
|
mov edi, [esp+12+4] ; Destination address
|
|
|
|
mov esi, [esp+12+8] ; Source address
|
2011-03-03 09:13:00 +01:00
|
|
|
|
|
|
|
mov edx, cr0 ; Get the control register...
|
|
|
|
and edx, 0x7fffffff ; and...
|
|
|
|
mov cr0, edx ; Disable paging.
|
2011-03-08 14:39:21 +01:00
|
|
|
|
|
|
|
cld
|
|
|
|
mov ecx, 0x400 ; 1024*4bytes = 4096 bytes = page size
|
|
|
|
rep movsd ; copy page
|
|
|
|
|
2011-03-03 09:13:00 +01:00
|
|
|
mov edx, cr0 ; Get the control register again
|
|
|
|
or edx, 0x80000000 ; and...
|
|
|
|
mov cr0, edx ; Enable paging.
|
|
|
|
|
|
|
|
popf ; Pop EFLAGS back.
|
2011-03-08 14:39:21 +01:00
|
|
|
pop edi ; Get the original value of EDI
|
|
|
|
pop esi ; and ESI back.
|
2011-03-03 09:13:00 +01:00
|
|
|
ret
|
|
|
|
|
2012-05-24 10:49:45 +02:00
|
|
|
%endif
|
|
|
|
|
2011-02-16 21:19:44 +01:00
|
|
|
SECTION .note.GNU-stack noalloc noexec nowrite progbits
|