OUTPUT = klibc.a
OBJECTS = string.o spinlock.o mutex.o posixcall.o coraxcall.o heap.o stdio.o signal.o \
- kq.o sem.o
+ kq.o sem.o string_ia32.o
PHONY = clean
INCLUDES = -I../include -I../../include -I../..
CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding $(INCLUDES)
return(ret_val);
}
-void* memcpy(void *dst, const void *src, size_t n)
-{
- u32_t *d;
- const u32_t *s;
-
- d = (u32_t*)dst;
- s = (const u32_t*)src;
-
- while(n > 4) {
- *d++ = *s++;
- n -= 4;
- }
-
- if(n >= 2) {
- *((u16_t*)d) = *((u16_t*)s);
- d = (u32_t*)(((void*)d) + 2);
- s = (u32_t*)(((void*)s) + 2);
- n -= 2;
- }
-
- if(n >= 1) {
- *((u8_t*)d) = *((u8_t*)s);
- }
-
- return(dst);
-}
-
void* memset(void *dst, int val, u32_t n)
{
char *ptr;
--- /dev/null
+#define __ASSEMBLY_SOURCE
+
+#include <config.h>
+
+.section .text
+
+.global memcpy
+
+memcpy:
+ pushl %ebx
+
+ movl 8(%esp), %eax
+ movl 12(%esp), %ebx
+ movl 16(%esp), %ecx
+
+0: testl $0xfffffffc, %ecx
+ jz 1f
+
+ movl (%ebx), %edx
+ movl %edx, (%eax)
+ addl $4, %eax
+ addl $4, %ebx
+ subl $4, %ecx
+ jmp 0b
+
+1: testl $0x2, %ecx
+ jz 2f
+
+ movw (%ebx), %dx
+ movw %dx, (%eax)
+ addl $2, %eax
+ addl $2, %ebx
+ subl $2, %ecx
+
+2: testl $0x1, %ecx
+ jz 3f
+
+ movb (%ebx), %dl
+ movb %dl, (%eax)
+
+3: movl 8(%esp), %eax
+
+ popl %ebx
+ ret
OUTPUT = libc.a
-OBJECTS = syscall.o string.o signal.o start.o stdio.o
+OBJECTS = syscall.o string.o signal.o start.o stdio.o string_ia32.o
PHONY = clean
-INCLUDES = -I../include
+INCLUDES = -I../include -I..
CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding $(INCLUDES)
ASFLAGS = $(CFLAGS)
LIBGCC = /usr/lib/gcc-cross/i686-linux-gnu/8/libgcc.a
return(s);
}
-
-void* memcpy(void *dst, const void *src, size_t n)
-{
- u32_t *d;
- const u32_t *s;
-
- d = (u32_t*)dst;
- s = (const u32_t*)src;
-
- while(n > 4) {
- *d++ = *s++;
- n -= 4;
- }
-
- if(n >= 2) {
- *((u16_t*)d) = *((u16_t*)s);
- d = (u32_t*)(((void*)d) + 2);
- s = (u32_t*)(((void*)s) + 2);
- n -= 2;
- }
-
- if(n >= 1) {
- *((u8_t*)d) = *((u8_t*)s);
- }
-
- return(dst);
-}
--- /dev/null
+#define __ASSEMBLY_SOURCE
+
+#include <config.h>
+
+.section .text
+
+.global memcpy
+
+memcpy:
+ pushl %ebx
+
+ movl 8(%esp), %eax
+ movl 12(%esp), %ebx
+ movl 16(%esp), %ecx
+
+0: testl $0xfffffffc, %ecx
+ jz 1f
+
+ movl (%ebx), %edx
+ movl %edx, (%eax)
+ addl $4, %eax
+ addl $4, %ebx
+ subl $4, %ecx
+ jmp 0b
+
+1: testl $0x2, %ecx
+ jz 2f
+
+ movw (%ebx), %dx
+ movw %dx, (%eax)
+ addl $2, %eax
+ addl $2, %ebx
+ subl $2, %ecx
+
+2: testl $0x1, %ecx
+ jz 3f
+
+ movb (%ebx), %dl
+ movb %dl, (%eax)
+
+3: movl 8(%esp), %eax
+
+ popl %ebx
+ ret