main: Use built-in memcpy

Signed-off-by: Markuss Broks <markuss.broks@gmail.com>
This commit is contained in:
Markuss Broks 2022-06-16 18:18:20 +03:00 committed by ivoszbg
parent 7ce00a6ed2
commit 3643d6a0c8
2 changed files with 32 additions and 9 deletions

View File

@ -3,6 +3,8 @@
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
*/
#include <stddef.h>
#ifndef MAIN_H_ /* Include guard */
#define MAIN_H_
@ -13,14 +15,35 @@ extern void board_init(void);
extern void printk(char *text);
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#if __has_builtin(__builtin_memcpy)
void memcpy(void *dest, void *src, size_t size) {
__builtin_memcpy(dest, src, size);
}
#else
#ifdef __aarch64__
/* Define our own 128 bit memcpy */
void memcpy(void *dest, void *src, int size)
void memcpy(void *dest, void *src, size_t size)
{
unsigned __int128 *src2 = src;
unsigned __int128 *dest2 = dest;
for (int i=0; i<size/16; i++)
for (size_t i = 0; i < size / 16; i++)
dest2[i] = src2[i];
}
#endif
#ifdef __arm__
void memcpy (char* src, char* dest, size_t len) {
for (size_t i = 0; i < len; i++)
dest[i] = src[i];
}
#endif
#endif
#endif // MAIN_H_

View File

@ -17,6 +17,6 @@ void main(void* dt, void* kernel) {
/* Copy kernel to memory and boot */
printk("Booting linux...");
memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) &kernel_size);
__builtin_memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) &kernel_size);
load_kernel(dt, 0, 0, 0, (void*)CONFIG_PAYLOAD_ENTRY);
}