📄 mem.s
字号:
/* Project: HARTIK 3.0 */
/* Description: Hard Real TIme Kernel for 386 & higher machines */
/* Author: Gerardo Lamastra */
/* Date: 9/5/96 */
/* Revision: Beta 2.0 */
/*
Assembler portion of the library!
Memory copy/cmp/set functions;
both for standard & Flat addressing mode
*/
#include "sel.h"
.text
.globl _memcpy
.globl _memcmp
.globl _memset
.globl _memchr
.globl _lmemcpy
.globl _lmemcmp
.globl _lmemset
.globl _lmemchr
.globl _fmemcpy
/* Standard C management functions */
/* These functions work into the PM address space */
/* void memcpy(void *dest,void *src,int n) */
_memcpy: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
/* Get parms into register */
movl 8(%ebp),%edi
movl 12(%ebp),%esi
movl 16(%ebp),%ecx
cld
rep
movsb
popl %edi
popl %esi
leave
ret
/* int memcmp(void *dest,void *src,int n) */
_memcmp: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
/* Get parms into register */
movl 8(%ebp),%edi
movl 12(%ebp),%esi
movl 16(%ebp),%ecx
cld
repe
cmpsb
jz mcmp_eq
movl $0,%eax
jmp mcmp_diff
mcmp_eq: movl $1,%eax
mcmp_diff: popl %edi
popl %esi
leave
ret
/* void memset(void *dest,char value,int n) */
_memset: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
/* Get parms into register */
movl 8(%ebp),%edi
movl 12(%ebp),%eax
movl 16(%ebp),%ecx
cld
rep
stosb
popl %edi
popl %esi
leave
ret
/* int memchr(void *dest,char value,int n) */
_memchr: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
/* Get parms into register */
movl 8(%ebp),%edi
movl 12(%ebp),%eax
movl 16(%ebp),%ecx
movl %ecx,%edx
cld
repne
scasb
je mscn_found
movl $0,%edx
jmp mscn_notfound
mscn_found: subl %ecx,%edx
mscn_notfound: movl %edx,%eax
popl %edi
popl %esi
leave
ret
/* These functions work into the flat address space */
/* They refer only liner phisical address */
/* void lmemcpy(LIN_ADDR dest,LIN_ADDR src,unsigned n) */
_lmemcpy: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
pushw %ds
pushw %es
movw $(X_FLATDATA_SEL),%ax
movw %ax,%ds
movw %ax,%es
/* Get parms into register */
movl 8(%ebp),%edi
movl 12(%ebp),%esi
movl 16(%ebp),%ecx
cld
rep
movsb
popw %es
popw %ds
popl %edi
popl %esi
leave
ret
/* int lmemcmp(LIN_ADDR dest,LIN_ADDR src,unsigned n) */
_lmemcmp: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
pushw %ds
pushw %es
movw $(X_FLATDATA_SEL),%ax
movw %ax,%ds
movw %ax,%es
/* Get parms into register */
movl 8(%ebp),%edi
movl 12(%ebp),%esi
movl 16(%ebp),%ecx
cld
repe
cmpsb
jz lmcmp_eq
movl $0,%eax
jmp lmcmp_diff
lmcmp_eq: movl $1,%eax
lmcmp_diff: popw %es
popw %ds
popl %edi
popl %esi
leave
ret
/* void lmemset(LIN_ADDR dest,char value,unsigned n) */
_lmemset: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
pushw %ds
pushw %es
movw $(X_FLATDATA_SEL),%ax
movw %ax,%ds
movw %ax,%es
/* Get parms into register */
movl 8(%ebp),%edi
movl 12(%ebp),%eax
movl 16(%ebp),%ecx
cld
rep
stosb
popw %es
popw %ds
popl %edi
popl %esi
leave
ret
/* int lmemchr(LIN_ADDR dest,char value,unsigned n) */
_lmemchr: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
pushw %ds
pushw %es
movw $(X_FLATDATA_SEL),%ax
movw %ax,%ds
movw %ax,%es
/* Get parms into register */
movl 8(%ebp),%edi
movl 12(%ebp),%eax
movl 16(%ebp),%ecx
movl %ecx,%edx
cld
repne
scasb
je lmscn_found
movl $0,%edx
jmp lmscn_notfound
lmscn_found: subl %ecx,%edx
lmscn_notfound: movl %edx,%eax
popw %es
popw %ds
popl %edi
popl %esi
leave
ret
/* void fmemcpy(unsigned short ds,unsigned long do,
unsigned short ss,unsigned long so,unsigned n) */
_fmemcpy: /* Build the standard stack frame */
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
pushw %ds
pushw %es
/* Get parms into register */
movl 8(%ebp),%eax
movw %ax,%es
movl 12(%ebp),%edi
movl 16(%ebp),%eax
movw %ax,%ds
movl 20(%ebp),%esi
movl 24(%ebp),%ecx
cld
rep
movsb
popw %es
popw %ds
popl %edi
popl %esi
leave
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -