2018-09-07 16:00:13 +01:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2018-09-07 16:00:13 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-11-30 01:29:07 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
2018-03-15 15:14:41 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include "utils.h"
|
2018-04-28 07:34:32 +01:00
|
|
|
|
2020-11-30 01:29:07 +00:00
|
|
|
static void copy_forwards(uint8_t *dst, const uint8_t *src, size_t size) {
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
dst[i] = src[i];
|
2018-05-20 13:11:46 +01:00
|
|
|
}
|
2018-03-15 15:14:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 01:29:07 +00:00
|
|
|
static void copy_backwards(uint8_t *dst, const uint8_t *src, size_t size) {
|
|
|
|
for (int i = size - 1; i >= 0; --i) {
|
|
|
|
dst[i] = src[i];
|
2019-01-26 07:50:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-30 01:29:07 +00:00
|
|
|
void loader_memcpy(void *dst, const void *src, size_t size) {
|
|
|
|
copy_forwards(dst, src, size);
|
2018-03-15 15:14:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 01:29:07 +00:00
|
|
|
void loader_memmove(void *dst, const void *src, size_t size) {
|
|
|
|
const uintptr_t dst_u = (uintptr_t)dst;
|
|
|
|
const uintptr_t src_u = (uintptr_t)src;
|
2019-07-31 20:01:01 +01:00
|
|
|
|
2020-11-30 01:29:07 +00:00
|
|
|
if (dst_u < src_u) {
|
|
|
|
copy_forwards(dst, src, size);
|
|
|
|
} else if (dst_u > src_u) {
|
|
|
|
copy_backwards(dst, src, size);
|
|
|
|
} else {
|
|
|
|
/* Nothing to do */
|
2019-07-31 20:01:01 +01:00
|
|
|
}
|
2020-11-30 01:29:07 +00:00
|
|
|
}
|