Compare commits
11 Commits
55c8a15983
...
609067cefa
Author | SHA1 | Date |
---|---|---|
|
609067cefa | |
|
9d497ad311 | |
|
72059a9441 | |
|
ebecbb69ec | |
|
b129bab81a | |
|
14c70c5cc8 | |
|
d62a67502e | |
|
4b2c303873 | |
|
d189f00f38 | |
|
a5cf92b2ff | |
|
8c45249c06 |
|
@ -148,6 +148,10 @@ set(BAN_SOURCES
|
|||
set(KLIBC_SOURCES
|
||||
klibc/ctype.cpp
|
||||
klibc/string.cpp
|
||||
|
||||
# Ehhh don't do this but for now libc uses the same stuff kernel can use
|
||||
# This won't work after libc starts using sse implemetations tho
|
||||
../userspace/libraries/LibC/arch/${BANAN_ARCH}/string.S
|
||||
)
|
||||
|
||||
set(LIBFONT_SOURCES
|
||||
|
|
|
@ -186,211 +186,26 @@ isr 29
|
|||
isr 30
|
||||
isr 31
|
||||
|
||||
irq 0
|
||||
irq 1
|
||||
irq 2
|
||||
irq 3
|
||||
irq 4
|
||||
irq 5
|
||||
irq 6
|
||||
irq 7
|
||||
irq 8
|
||||
irq 9
|
||||
irq 10
|
||||
irq 11
|
||||
irq 12
|
||||
irq 13
|
||||
irq 14
|
||||
irq 15
|
||||
irq 16
|
||||
irq 17
|
||||
irq 18
|
||||
irq 19
|
||||
irq 20
|
||||
irq 21
|
||||
irq 22
|
||||
irq 23
|
||||
irq 24
|
||||
irq 25
|
||||
irq 26
|
||||
irq 27
|
||||
irq 28
|
||||
irq 29
|
||||
irq 30
|
||||
irq 31
|
||||
irq 32
|
||||
irq 33
|
||||
irq 34
|
||||
irq 35
|
||||
irq 36
|
||||
irq 37
|
||||
irq 38
|
||||
irq 39
|
||||
irq 40
|
||||
irq 41
|
||||
irq 42
|
||||
irq 43
|
||||
irq 44
|
||||
irq 45
|
||||
irq 46
|
||||
irq 47
|
||||
irq 48
|
||||
irq 49
|
||||
irq 50
|
||||
irq 51
|
||||
irq 52
|
||||
irq 53
|
||||
irq 54
|
||||
irq 55
|
||||
irq 56
|
||||
irq 57
|
||||
irq 58
|
||||
irq 59
|
||||
irq 60
|
||||
irq 61
|
||||
irq 62
|
||||
irq 63
|
||||
irq 64
|
||||
irq 65
|
||||
irq 66
|
||||
irq 67
|
||||
irq 68
|
||||
irq 69
|
||||
irq 70
|
||||
irq 71
|
||||
irq 72
|
||||
irq 73
|
||||
irq 74
|
||||
irq 75
|
||||
irq 76
|
||||
irq 77
|
||||
irq 78
|
||||
irq 79
|
||||
irq 80
|
||||
irq 81
|
||||
irq 82
|
||||
irq 83
|
||||
irq 84
|
||||
irq 85
|
||||
irq 86
|
||||
irq 87
|
||||
irq 88
|
||||
irq 89
|
||||
irq 90
|
||||
irq 91
|
||||
irq 92
|
||||
irq 93
|
||||
irq 94
|
||||
irq 95
|
||||
irq 96
|
||||
irq 97
|
||||
irq 98
|
||||
irq 99
|
||||
irq 100
|
||||
irq 101
|
||||
irq 102
|
||||
irq 103
|
||||
irq 104
|
||||
irq 105
|
||||
irq 106
|
||||
irq 107
|
||||
irq 108
|
||||
irq 109
|
||||
irq 110
|
||||
irq 111
|
||||
irq 112
|
||||
irq 113
|
||||
irq 114
|
||||
irq 115
|
||||
irq 116
|
||||
irq 117
|
||||
irq 118
|
||||
irq 119
|
||||
irq 120
|
||||
irq 121
|
||||
irq 122
|
||||
irq 123
|
||||
irq 124
|
||||
irq 125
|
||||
irq 126
|
||||
irq 127
|
||||
irq 128
|
||||
irq 129
|
||||
irq 130
|
||||
irq 131
|
||||
irq 132
|
||||
irq 133
|
||||
irq 134
|
||||
irq 135
|
||||
irq 136
|
||||
irq 137
|
||||
irq 138
|
||||
irq 139
|
||||
irq 140
|
||||
irq 141
|
||||
irq 142
|
||||
irq 143
|
||||
irq 144
|
||||
irq 145
|
||||
irq 146
|
||||
irq 147
|
||||
irq 148
|
||||
irq 149
|
||||
irq 150
|
||||
irq 151
|
||||
irq 152
|
||||
irq 153
|
||||
irq 154
|
||||
irq 155
|
||||
irq 156
|
||||
irq 157
|
||||
irq 158
|
||||
irq 159
|
||||
irq 160
|
||||
irq 161
|
||||
irq 162
|
||||
irq 163
|
||||
irq 164
|
||||
irq 165
|
||||
irq 166
|
||||
irq 167
|
||||
irq 168
|
||||
irq 169
|
||||
irq 170
|
||||
irq 171
|
||||
irq 172
|
||||
irq 173
|
||||
irq 174
|
||||
irq 175
|
||||
irq 176
|
||||
irq 177
|
||||
irq 178
|
||||
irq 179
|
||||
irq 180
|
||||
irq 181
|
||||
irq 182
|
||||
irq 183
|
||||
irq 184
|
||||
irq 185
|
||||
irq 186
|
||||
irq 187
|
||||
irq 188
|
||||
irq 189
|
||||
irq 190
|
||||
irq 191
|
||||
irq 192
|
||||
irq 193
|
||||
irq 194
|
||||
irq 195
|
||||
irq 196
|
||||
irq 197
|
||||
irq 198
|
||||
irq 199
|
||||
irq 200
|
||||
irq 201
|
||||
irq 202
|
||||
irq 203
|
||||
irq 204
|
||||
irq 205
|
||||
irq 206
|
||||
irq 207
|
||||
.irp i, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, \
|
||||
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, \
|
||||
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, \
|
||||
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, \
|
||||
50, 51, 52, 53, 54, 55, 56, 57, 58, 59, \
|
||||
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, \
|
||||
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, \
|
||||
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, \
|
||||
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, \
|
||||
100,101,102,103,104,105,106,107,108,109, \
|
||||
110,111,112,113,114,115,116,117,118,119, \
|
||||
120,121,122,123,124,125,126,127,128,129, \
|
||||
130,131,132,133,134,135,136,137,138,139, \
|
||||
140,141,142,143,144,145,146,147,148,149, \
|
||||
150,151,152,153,154,155,156,157,158,159, \
|
||||
160,161,162,163,164,165,166,167,168,169, \
|
||||
170,171,172,173,174,175,176,177,178,179, \
|
||||
180,181,182,183,184,185,186,187,188,189, \
|
||||
190,191,192,193,194,195,196,197,198,199, \
|
||||
200,201,202,203,204,205,206,207
|
||||
irq \i
|
||||
.endr
|
||||
|
|
|
@ -140,211 +140,26 @@ isr 29
|
|||
isr 30
|
||||
isr 31
|
||||
|
||||
irq 0
|
||||
irq 1
|
||||
irq 2
|
||||
irq 3
|
||||
irq 4
|
||||
irq 5
|
||||
irq 6
|
||||
irq 7
|
||||
irq 8
|
||||
irq 9
|
||||
irq 10
|
||||
irq 11
|
||||
irq 12
|
||||
irq 13
|
||||
irq 14
|
||||
irq 15
|
||||
irq 16
|
||||
irq 17
|
||||
irq 18
|
||||
irq 19
|
||||
irq 20
|
||||
irq 21
|
||||
irq 22
|
||||
irq 23
|
||||
irq 24
|
||||
irq 25
|
||||
irq 26
|
||||
irq 27
|
||||
irq 28
|
||||
irq 29
|
||||
irq 30
|
||||
irq 31
|
||||
irq 32
|
||||
irq 33
|
||||
irq 34
|
||||
irq 35
|
||||
irq 36
|
||||
irq 37
|
||||
irq 38
|
||||
irq 39
|
||||
irq 40
|
||||
irq 41
|
||||
irq 42
|
||||
irq 43
|
||||
irq 44
|
||||
irq 45
|
||||
irq 46
|
||||
irq 47
|
||||
irq 48
|
||||
irq 49
|
||||
irq 50
|
||||
irq 51
|
||||
irq 52
|
||||
irq 53
|
||||
irq 54
|
||||
irq 55
|
||||
irq 56
|
||||
irq 57
|
||||
irq 58
|
||||
irq 59
|
||||
irq 60
|
||||
irq 61
|
||||
irq 62
|
||||
irq 63
|
||||
irq 64
|
||||
irq 65
|
||||
irq 66
|
||||
irq 67
|
||||
irq 68
|
||||
irq 69
|
||||
irq 70
|
||||
irq 71
|
||||
irq 72
|
||||
irq 73
|
||||
irq 74
|
||||
irq 75
|
||||
irq 76
|
||||
irq 77
|
||||
irq 78
|
||||
irq 79
|
||||
irq 80
|
||||
irq 81
|
||||
irq 82
|
||||
irq 83
|
||||
irq 84
|
||||
irq 85
|
||||
irq 86
|
||||
irq 87
|
||||
irq 88
|
||||
irq 89
|
||||
irq 90
|
||||
irq 91
|
||||
irq 92
|
||||
irq 93
|
||||
irq 94
|
||||
irq 95
|
||||
irq 96
|
||||
irq 97
|
||||
irq 98
|
||||
irq 99
|
||||
irq 100
|
||||
irq 101
|
||||
irq 102
|
||||
irq 103
|
||||
irq 104
|
||||
irq 105
|
||||
irq 106
|
||||
irq 107
|
||||
irq 108
|
||||
irq 109
|
||||
irq 110
|
||||
irq 111
|
||||
irq 112
|
||||
irq 113
|
||||
irq 114
|
||||
irq 115
|
||||
irq 116
|
||||
irq 117
|
||||
irq 118
|
||||
irq 119
|
||||
irq 120
|
||||
irq 121
|
||||
irq 122
|
||||
irq 123
|
||||
irq 124
|
||||
irq 125
|
||||
irq 126
|
||||
irq 127
|
||||
irq 128
|
||||
irq 129
|
||||
irq 130
|
||||
irq 131
|
||||
irq 132
|
||||
irq 133
|
||||
irq 134
|
||||
irq 135
|
||||
irq 136
|
||||
irq 137
|
||||
irq 138
|
||||
irq 139
|
||||
irq 140
|
||||
irq 141
|
||||
irq 142
|
||||
irq 143
|
||||
irq 144
|
||||
irq 145
|
||||
irq 146
|
||||
irq 147
|
||||
irq 148
|
||||
irq 149
|
||||
irq 150
|
||||
irq 151
|
||||
irq 152
|
||||
irq 153
|
||||
irq 154
|
||||
irq 155
|
||||
irq 156
|
||||
irq 157
|
||||
irq 158
|
||||
irq 159
|
||||
irq 160
|
||||
irq 161
|
||||
irq 162
|
||||
irq 163
|
||||
irq 164
|
||||
irq 165
|
||||
irq 166
|
||||
irq 167
|
||||
irq 168
|
||||
irq 169
|
||||
irq 170
|
||||
irq 171
|
||||
irq 172
|
||||
irq 173
|
||||
irq 174
|
||||
irq 175
|
||||
irq 176
|
||||
irq 177
|
||||
irq 178
|
||||
irq 179
|
||||
irq 180
|
||||
irq 181
|
||||
irq 182
|
||||
irq 183
|
||||
irq 184
|
||||
irq 185
|
||||
irq 186
|
||||
irq 187
|
||||
irq 188
|
||||
irq 189
|
||||
irq 190
|
||||
irq 191
|
||||
irq 192
|
||||
irq 193
|
||||
irq 194
|
||||
irq 195
|
||||
irq 196
|
||||
irq 197
|
||||
irq 198
|
||||
irq 199
|
||||
irq 200
|
||||
irq 201
|
||||
irq 202
|
||||
irq 203
|
||||
irq 204
|
||||
irq 205
|
||||
irq 206
|
||||
irq 207
|
||||
.irp i, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, \
|
||||
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, \
|
||||
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, \
|
||||
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, \
|
||||
50, 51, 52, 53, 54, 55, 56, 57, 58, 59, \
|
||||
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, \
|
||||
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, \
|
||||
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, \
|
||||
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, \
|
||||
100,101,102,103,104,105,106,107,108,109, \
|
||||
110,111,112,113,114,115,116,117,118,119, \
|
||||
120,121,122,123,124,125,126,127,128,129, \
|
||||
130,131,132,133,134,135,136,137,138,139, \
|
||||
140,141,142,143,144,145,146,147,148,149, \
|
||||
150,151,152,153,154,155,156,157,158,159, \
|
||||
160,161,162,163,164,165,166,167,168,169, \
|
||||
170,171,172,173,174,175,176,177,178,179, \
|
||||
180,181,182,183,184,185,186,187,188,189, \
|
||||
190,191,192,193,194,195,196,197,198,199, \
|
||||
200,201,202,203,204,205,206,207
|
||||
irq \i
|
||||
.endr
|
||||
|
|
|
@ -278,7 +278,7 @@ namespace Kernel::ACPI::AML
|
|||
BAN::ErrorOr<NameString> parse_name_string(BAN::ConstByteSpan& aml_data);
|
||||
BAN::ErrorOr<BAN::ConstByteSpan> parse_pkg(BAN::ConstByteSpan& aml_data);
|
||||
|
||||
BAN::ErrorOr<Node> convert_node(Node&& source, uint8_t conversion, size_t max_length);
|
||||
BAN::ErrorOr<Node> convert_node(Node&& source, uint8_t conversion, uint64_t max_length);
|
||||
BAN::ErrorOr<Node> convert_node(Node&& source, const Node& target);
|
||||
|
||||
BAN::ErrorOr<Node> evaluate_node(const Scope& node_path, const Node& node);
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Kernel::ACPI::AML
|
|||
BAN::ErrorOr<void> parse_index_field_op(ParseContext& context);
|
||||
BAN::ErrorOr<void> parse_bank_field_op(ParseContext& context);
|
||||
|
||||
BAN::ErrorOr<Node> convert_from_field_unit(const Node& node, uint8_t conversion, size_t max_length);
|
||||
BAN::ErrorOr<Node> convert_from_field_unit(const Node& node, uint8_t conversion, uint64_t max_length);
|
||||
BAN::ErrorOr<void> store_to_field_unit(const Node& source, const Node& target);
|
||||
|
||||
}
|
||||
|
|
|
@ -551,7 +551,7 @@ namespace Kernel::ACPI::AML
|
|||
}
|
||||
}
|
||||
|
||||
BAN::ErrorOr<Node> convert_node(Node&& source, uint8_t conversion, size_t max_length)
|
||||
BAN::ErrorOr<Node> convert_node(Node&& source, uint8_t conversion, uint64_t max_length)
|
||||
{
|
||||
dprintln_if(AML_DUMP_FUNCTION_CALLS, "convert_node {} -> 0b{3b}", source, conversion);
|
||||
|
||||
|
|
|
@ -652,7 +652,7 @@ namespace Kernel::ACPI::AML
|
|||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<Node> convert_from_field_unit(const Node& source, uint8_t conversion, size_t max_length)
|
||||
BAN::ErrorOr<Node> convert_from_field_unit(const Node& source, uint8_t conversion, uint64_t max_length)
|
||||
{
|
||||
ASSERT(source.type == Node::Type::FieldUnit);
|
||||
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
namespace CPUID
|
||||
{
|
||||
void get_cpuid(uint32_t code, uint32_t* out)
|
||||
|
||||
static inline void get_cpuid(uint32_t code, uint32_t* out)
|
||||
{
|
||||
asm volatile("cpuid" : "=a"(out[0]), "=b"(out[1]), "=c"(out[2]), "=d"(out[3]) : "a"(code));
|
||||
}
|
||||
|
||||
void get_cpuid_string(uint32_t code, uint32_t* out)
|
||||
static inline void get_cpuid_string(uint32_t code, uint32_t* out)
|
||||
{
|
||||
asm volatile ("cpuid": "=a"(out[0]), "=b"(out[0]), "=d"(out[1]), "=c"(out[2]) : "a"(code));
|
||||
}
|
||||
|
|
|
@ -473,6 +473,7 @@ namespace Kernel
|
|||
dirp->d_ino = entry.ino;
|
||||
dirp->d_type = entry.type;
|
||||
strncpy(dirp->d_name, entry.name, entry.name_len);
|
||||
dirp->d_name[entry.name_len] = '\0';
|
||||
dirp++;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/weak_alias.h>
|
||||
|
||||
int memcmp(const void* s1, const void* s2, size_t n)
|
||||
extern "C" int _memcmp(const void* s1, const void* s2, size_t n)
|
||||
{
|
||||
auto* u1 = static_cast<const unsigned char*>(s1);
|
||||
auto* u2 = static_cast<const unsigned char*>(s2);
|
||||
|
@ -10,8 +11,9 @@ int memcmp(const void* s1, const void* s2, size_t n)
|
|||
return u1[i] - u2[i];
|
||||
return 0;
|
||||
}
|
||||
weak_alias(_memcmp, memcmp);
|
||||
|
||||
void* memcpy(void* __restrict s1, const void* __restrict s2, size_t n)
|
||||
extern "C" void* _memcpy(void* __restrict s1, const void* __restrict s2, size_t n)
|
||||
{
|
||||
auto* dst = static_cast<unsigned char*>(s1);
|
||||
auto* src = static_cast<const unsigned char*>(s2);
|
||||
|
@ -19,8 +21,9 @@ void* memcpy(void* __restrict s1, const void* __restrict s2, size_t n)
|
|||
dst[i] = src[i];
|
||||
return s1;
|
||||
}
|
||||
weak_alias(_memcpy, memcpy);
|
||||
|
||||
void* memmove(void* s1, const void* s2, size_t n)
|
||||
extern "C" void* _memmove(void* s1, const void* s2, size_t n)
|
||||
{
|
||||
auto* dst = static_cast<unsigned char*>(s1);
|
||||
auto* src = static_cast<const unsigned char*>(s2);
|
||||
|
@ -36,40 +39,57 @@ void* memmove(void* s1, const void* s2, size_t n)
|
|||
}
|
||||
return s1;
|
||||
}
|
||||
weak_alias(_memmove, memmove);
|
||||
|
||||
void* memset(void* s, int c, size_t n)
|
||||
extern "C" void* _memset(void* s, int c, size_t n)
|
||||
{
|
||||
auto* u = static_cast<unsigned char*>(s);
|
||||
for (size_t i = 0; i < n; i++)
|
||||
u[i] = c;
|
||||
return s;
|
||||
}
|
||||
weak_alias(_memset, memset);
|
||||
|
||||
size_t strlen(const char* str)
|
||||
extern "C" size_t _strlen(const char* str)
|
||||
{
|
||||
size_t len = 0;
|
||||
while (str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
weak_alias(_strlen, strlen);
|
||||
|
||||
char* strcpy(char* __restrict dst, const char* __restrict src)
|
||||
extern "C" char* _stpcpy(char* __restrict dst, const char* __restrict src)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (; src[i]; i++)
|
||||
dst[i] = src[i];
|
||||
dst[i] = '\0';
|
||||
return dst;
|
||||
return &dst[i];
|
||||
}
|
||||
weak_alias(_stpcpy, stpcpy);
|
||||
|
||||
char* strncpy(char* __restrict dst, const char* __restrict src, size_t len)
|
||||
extern "C" char* _stpncpy(char* __restrict dst, const char* __restrict src, size_t n)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (; i < len && src[i]; i++)
|
||||
for (; src[i] && n; i++, n--)
|
||||
dst[i] = src[i];
|
||||
if (i < len)
|
||||
for (; n; i++, n--)
|
||||
dst[i] = '\0';
|
||||
return dst;
|
||||
return &dst[i];
|
||||
}
|
||||
weak_alias(_stpncpy, stpncpy);
|
||||
|
||||
char* strcpy(char* __restrict__ dest, const char* __restrict__ src)
|
||||
{
|
||||
stpcpy(dest, src);
|
||||
return dest;
|
||||
}
|
||||
|
||||
char* strncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n)
|
||||
{
|
||||
stpncpy(dest, src, n);
|
||||
return dest;
|
||||
}
|
||||
|
||||
const char* strerrordesc_np(int error)
|
||||
|
|
|
@ -45,6 +45,7 @@ set(LIBC_SOURCES
|
|||
icxxabi.cpp
|
||||
|
||||
arch/${BANAN_ARCH}/setjmp.S
|
||||
arch/${BANAN_ARCH}/string.S
|
||||
|
||||
../../../BAN/BAN/Assert.cpp
|
||||
)
|
||||
|
@ -52,7 +53,7 @@ set(LIBC_SOURCES
|
|||
add_library(objlibc OBJECT ${LIBC_SOURCES})
|
||||
target_compile_definitions(objlibc PRIVATE __arch=${BANAN_ARCH})
|
||||
|
||||
target_compile_options(objlibc PRIVATE -O2 -g -Wstack-usage=512 -fno-tree-loop-distribute-patterns -fno-exceptions -fpic -nolibc)
|
||||
target_compile_options(objlibc PRIVATE -O2 -g -Wstack-usage=512 -fno-exceptions -fpic -nolibc)
|
||||
target_compile_options(objlibc PUBLIC -Wall -Wextra -Werror -Wno-error=stack-usage=)
|
||||
|
||||
function(add_crtx crtx)
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
.global memchr
|
||||
memchr:
|
||||
xchgl 4(%esp), %edi
|
||||
movl 8(%esp), %eax
|
||||
movl 12(%esp), %ecx
|
||||
repne scasb
|
||||
xorl %eax, %eax
|
||||
testl %ecx, %ecx
|
||||
cmovnzl %edi, %eax
|
||||
movl 4(%esp), %edi
|
||||
ret
|
||||
|
||||
.global memcmp
|
||||
memcmp:
|
||||
xchgl 4(%esp), %edi
|
||||
xchgl 8(%esp), %esi
|
||||
movl 12(%esp), %ecx
|
||||
repe cmpsb
|
||||
jne .memcmp_not_equal
|
||||
xorl %eax, %eax
|
||||
jmp .memcmp_done
|
||||
.memcmp_not_equal:
|
||||
movzbl -1(%edi), %eax
|
||||
movzbl -1(%esi), %ecx
|
||||
subl %ecx, %eax
|
||||
.memcmp_done:
|
||||
movl 4(%esp), %edi
|
||||
movl 8(%esp), %esi
|
||||
ret
|
||||
|
||||
.global memcpy
|
||||
memcpy:
|
||||
xchgl 4(%esp), %edi
|
||||
xchgl 8(%esp), %esi
|
||||
movl 12(%esp), %ecx
|
||||
movl %edi, %edx
|
||||
rep movsb
|
||||
movl 4(%esp), %edi
|
||||
movl 8(%esp), %esi
|
||||
movl %edx, %eax
|
||||
ret
|
||||
|
||||
.global memmove
|
||||
memmove:
|
||||
xchgl 4(%esp), %edi
|
||||
xchgl 8(%esp), %esi
|
||||
movl 12(%esp), %ecx
|
||||
movl %edi, %edx
|
||||
cmpl %edi, %esi
|
||||
jb .memmove_slow
|
||||
rep movsb
|
||||
.memmove_done:
|
||||
movl 4(%esp), %edi
|
||||
movl 8(%esp), %esi
|
||||
movl %edx, %eax
|
||||
ret
|
||||
.memmove_slow:
|
||||
leal -1(%edi, %ecx), %edi
|
||||
leal -1(%esi, %ecx), %esi
|
||||
std
|
||||
rep movsb
|
||||
cld
|
||||
jmp .memmove_done
|
||||
|
||||
.global memset
|
||||
memset:
|
||||
xchgl 4(%esp), %edi
|
||||
movl 8(%esp), %eax
|
||||
movl 12(%esp), %ecx
|
||||
movl %edi, %edx
|
||||
rep stosb
|
||||
movl 4(%esp), %edi
|
||||
movl %edx, %eax
|
||||
ret
|
||||
|
||||
.global strlen
|
||||
strlen:
|
||||
xchgl 4(%esp), %edi
|
||||
xorb %al, %al
|
||||
movl $-1, %ecx
|
||||
repne scasb
|
||||
movl 4(%esp), %edi
|
||||
movl $-2, %eax
|
||||
subl %ecx, %eax
|
||||
ret
|
|
@ -0,0 +1,62 @@
|
|||
.global memchr
|
||||
memchr:
|
||||
movb %sil, %al
|
||||
movq %rdx, %rcx
|
||||
repne scasb
|
||||
xorq %rax, %rax
|
||||
testq %rcx, %rcx
|
||||
cmovnzq %rdi, %rax
|
||||
ret
|
||||
|
||||
.global memcmp
|
||||
memcmp:
|
||||
movq %rdx, %rcx
|
||||
repe cmpsb
|
||||
jne .memcmp_not_equal
|
||||
xorq %rax, %rax
|
||||
ret
|
||||
.memcmp_not_equal:
|
||||
movzbl -1(%rdi), %eax
|
||||
movzbl -1(%rsi), %ecx
|
||||
subq %rcx, %rax
|
||||
ret
|
||||
|
||||
.global memcpy
|
||||
memcpy:
|
||||
movq %rdi, %rax
|
||||
movq %rdx, %rcx
|
||||
movq %rdi, %rdx
|
||||
rep movsb
|
||||
movq %rdx, %rax
|
||||
ret
|
||||
|
||||
.global memmove
|
||||
memmove:
|
||||
cmpq %rdi, %rsi
|
||||
jae memcpy
|
||||
leaq -1(%rdi, %rdx), %rdi
|
||||
leaq -1(%rsi, %rdx), %rsi
|
||||
movq %rdx, %rcx
|
||||
std
|
||||
rep movsb
|
||||
cld
|
||||
leaq 1(%rdi), %rax
|
||||
ret
|
||||
|
||||
.global memset
|
||||
memset:
|
||||
movq %rdi, %r8
|
||||
movb %sil, %al
|
||||
movq %rdx, %rcx
|
||||
rep stosb
|
||||
movq %r8, %rax
|
||||
ret
|
||||
|
||||
.global strlen
|
||||
strlen:
|
||||
xorb %al, %al
|
||||
movq $-1, %rcx
|
||||
repne scasb
|
||||
movq $-2, %rax
|
||||
subq %rcx, %rax
|
||||
ret
|
|
@ -32,9 +32,9 @@ __BEGIN_DECLS
|
|||
#define F_WRLCK 3
|
||||
|
||||
// NOTE: also defined in stdio.h
|
||||
#define SEEK_SET 1
|
||||
#define SEEK_CUR 2
|
||||
#define SEEK_END 3
|
||||
#define SEEK_SET 0
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
/* bits 0-3 */
|
||||
#define O_RDONLY 0x00001
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
#ifndef _STDINT_H
|
||||
#define _STDINT_H 1
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
typedef __INT8_TYPE__ int8_t;
|
||||
typedef __INT16_TYPE__ int16_t;
|
||||
typedef __INT32_TYPE__ int32_t;
|
||||
typedef __INT64_TYPE__ int64_t;
|
||||
|
||||
typedef __UINT8_TYPE__ uint8_t;
|
||||
typedef __UINT16_TYPE__ uint16_t;
|
||||
typedef __UINT32_TYPE__ uint32_t;
|
||||
typedef __UINT64_TYPE__ uint64_t;
|
||||
|
||||
typedef __INT_LEAST8_TYPE__ int_least8_t;
|
||||
typedef __INT_LEAST16_TYPE__ int_least16_t;
|
||||
typedef __INT_LEAST32_TYPE__ int_least32_t;
|
||||
typedef __INT_LEAST64_TYPE__ int_least64_t;
|
||||
|
||||
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
|
||||
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
|
||||
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
|
||||
typedef __UINT_LEAST64_TYPE__ uint_least64_t;
|
||||
|
||||
typedef __INT_FAST8_TYPE__ int_fast8_t;
|
||||
typedef __INT_FAST16_TYPE__ int_fast16_t;
|
||||
typedef __INT_FAST32_TYPE__ int_fast32_t;
|
||||
typedef __INT_FAST64_TYPE__ int_fast64_t;
|
||||
|
||||
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
|
||||
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
|
||||
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
|
||||
typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||
|
||||
typedef __INTPTR_TYPE__ intptr_t;
|
||||
typedef __UINTPTR_TYPE__ uintptr_t;
|
||||
|
||||
// FIXME: is this the correct?
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
#define INT8_MIN (-INT8_MAX - 1)
|
||||
#define INT16_MIN (-INT16_MAX - 1)
|
||||
#define INT32_MIN (-INT32_MAX - 1)
|
||||
#define INT64_MIN (-INT64_MAX - 1)
|
||||
|
||||
#define INT8_MAX __INT8_MAX__
|
||||
#define INT16_MAX __INT16_MAX__
|
||||
#define INT32_MAX __INT32_MAX__
|
||||
#define INT64_MAX __INT64_MAX__
|
||||
|
||||
#define UINT8_MAX __UINT8_MAX__
|
||||
#define UINT16_MAX __UINT16_MAX__
|
||||
#define UINT32_MAX __UINT32_MAX__
|
||||
#define UINT64_MAX __UINT64_MAX__
|
||||
|
||||
#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1)
|
||||
#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1)
|
||||
#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)
|
||||
#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1)
|
||||
|
||||
#define INT_LEAST8_MAX __INT_LEAST8_MAX__
|
||||
#define INT_LEAST16_MAX __INT_LEAST16_MAX__
|
||||
#define INT_LEAST32_MAX __INT_LEAST32_MAX__
|
||||
#define INT_LEAST64_MAX __INT_LEAST64_MAX__
|
||||
|
||||
#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
|
||||
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
|
||||
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
|
||||
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
|
||||
|
||||
#define INT_FAST8_MIN (-INT_FAST8_MAX - 1)
|
||||
#define INT_FAST16_MIN (-INT_FAST16_MAX - 1)
|
||||
#define INT_FAST32_MIN (-INT_FAST32_MAX - 1)
|
||||
#define INT_FAST64_MIN (-INT_FAST64_MAX - 1)
|
||||
|
||||
#define INT_FAST8_MAX __INT_FAST8_MAX__
|
||||
#define INT_FAST16_MAX __INT_FAST16_MAX__
|
||||
#define INT_FAST32_MAX __INT_FAST32_MAX__
|
||||
#define INT_FAST64_MAX __INT_FAST64_MAX__
|
||||
|
||||
#define UINT_FAST8_MAX __UINT_FAST8_MAX__
|
||||
#define UINT_FAST16_MAX __UINT_FAST16_MAX__
|
||||
#define UINT_FAST32_MAX __UINT_FAST32_MAX__
|
||||
#define UINT_FAST64_MAX __UINT_FAST64_MAX__
|
||||
|
||||
#define INTPTR_MIN (-INTPTR_MAX - 1)
|
||||
#define INTPTR_MAX __INTPTR_MAX__
|
||||
#define UINTPTR_MAX __UINTPTR_MAX__
|
||||
|
||||
// FIXME: is this the correct?
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
#define PTRDIFF_MIN -65535
|
||||
#define PTRDIFF_MAX +65535
|
||||
|
||||
#define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__
|
||||
#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
|
||||
|
||||
#define SIZE_MAX __SIZE_MAX__
|
||||
|
||||
#define WCHAR_MIN __WCHAR_MIN__
|
||||
#define WCHAR_MAX __WCHAR_MAX__
|
||||
|
||||
#define WINT_MIN __WINT_MIN__
|
||||
#define WINT_MAX __WINT_MAX__
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -35,9 +35,9 @@ typedef off_t fpos_t;
|
|||
#define _IONBF 3
|
||||
|
||||
// NOTE: also defined in fcntl.h
|
||||
#define SEEK_SET 1
|
||||
#define SEEK_CUR 2
|
||||
#define SEEK_END 3
|
||||
#define SEEK_SET 0
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
#define FILENAME_MAX 256
|
||||
#define FOPEN_MAX 16
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef _SYS_WEAK_ALIAS
|
||||
#define _SYS_WEAK_ALIAS 1
|
||||
|
||||
#define weak_alias(name, aliasname) _weak_alias (name, aliasname)
|
||||
#define _weak_alias(name, aliasname) extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)))
|
||||
|
||||
#endif
|
|
@ -7,8 +7,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/weak_alias.h>
|
||||
|
||||
void* memccpy(void* __restrict s1, const void* __restrict s2, int c, size_t n)
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC optimize "no-tree-loop-distribute-patterns"
|
||||
#endif
|
||||
|
||||
extern "C" void* _memccpy(void* __restrict s1, const void* __restrict s2, int c, size_t n)
|
||||
{
|
||||
unsigned char* dst = static_cast<unsigned char*>(s1);
|
||||
const unsigned char* src = static_cast<const unsigned char*>(s2);
|
||||
|
@ -17,8 +22,9 @@ void* memccpy(void* __restrict s1, const void* __restrict s2, int c, size_t n)
|
|||
return dst + i + 1;
|
||||
return nullptr;
|
||||
}
|
||||
weak_alias(_memccpy, memccpy);
|
||||
|
||||
void* memchr(const void* s, int c, size_t n)
|
||||
extern "C" void* _memchr(const void* s, int c, size_t n)
|
||||
{
|
||||
const unsigned char* u = static_cast<const unsigned char*>(s);
|
||||
for (size_t i = 0; i < n; i++)
|
||||
|
@ -26,20 +32,20 @@ void* memchr(const void* s, int c, size_t n)
|
|||
return const_cast<unsigned char*>(u + i);
|
||||
return nullptr;
|
||||
}
|
||||
weak_alias(_memchr, memchr);
|
||||
|
||||
int memcmp(const void* s1, const void* s2, size_t n)
|
||||
extern "C" int _memcmp(const void* s1, const void* s2, size_t n)
|
||||
{
|
||||
const unsigned char* a = static_cast<const unsigned char*>(s1);
|
||||
const unsigned char* b = static_cast<const unsigned char*>(s2);
|
||||
|
||||
for (size_t i = 0; i < n; i++)
|
||||
if (a[i] != b[i])
|
||||
return a[i] - b[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
weak_alias(_memcmp, memcmp);
|
||||
|
||||
void* memcpy(void* __restrict__ dstp, const void* __restrict__ srcp, size_t n)
|
||||
extern "C" void* _memcpy(void* __restrict__ dstp, const void* __restrict__ srcp, size_t n)
|
||||
{
|
||||
unsigned char* dst = static_cast<unsigned char*>(dstp);
|
||||
const unsigned char* src = static_cast<const unsigned char*>(srcp);
|
||||
|
@ -47,12 +53,12 @@ void* memcpy(void* __restrict__ dstp, const void* __restrict__ srcp, size_t n)
|
|||
dst[i] = src[i];
|
||||
return dstp;
|
||||
}
|
||||
weak_alias(_memcpy, memcpy);
|
||||
|
||||
void* memmove(void* destp, const void* srcp, size_t n)
|
||||
extern "C" void* _memmove(void* destp, const void* srcp, size_t n)
|
||||
{
|
||||
unsigned char* dest = static_cast<unsigned char*>(destp);
|
||||
const unsigned char* src = static_cast<const unsigned char*>(srcp);
|
||||
|
||||
if (dest < src)
|
||||
{
|
||||
for (size_t i = 0; i < n; i++)
|
||||
|
@ -63,19 +69,20 @@ void* memmove(void* destp, const void* srcp, size_t n)
|
|||
for (size_t i = 1; i <= n; i++)
|
||||
dest[n - i] = src[n - i];
|
||||
}
|
||||
|
||||
return destp;
|
||||
}
|
||||
weak_alias(_memmove, memmove);
|
||||
|
||||
void* memset(void* s, int c, size_t n)
|
||||
extern "C" void* _memset(void* s, int c, size_t n)
|
||||
{
|
||||
unsigned char* p = static_cast<unsigned char*>(s);
|
||||
for (size_t i = 0; i < n; i++)
|
||||
p[i] = c;
|
||||
return s;
|
||||
}
|
||||
weak_alias(_memset, memset);
|
||||
|
||||
int strcmp(const char* s1, const char* s2)
|
||||
extern "C" int _strcmp(const char* s1, const char* s2)
|
||||
{
|
||||
const unsigned char* u1 = (unsigned char*)s1;
|
||||
const unsigned char* u2 = (unsigned char*)s2;
|
||||
|
@ -84,8 +91,9 @@ int strcmp(const char* s1, const char* s2)
|
|||
break;
|
||||
return *u1 - *u2;
|
||||
}
|
||||
weak_alias(_strcmp, strcmp);
|
||||
|
||||
int strncmp(const char* s1, const char* s2, size_t n)
|
||||
extern "C" int _strncmp(const char* s1, const char* s2, size_t n)
|
||||
{
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
@ -96,8 +104,9 @@ int strncmp(const char* s1, const char* s2, size_t n)
|
|||
break;
|
||||
return *u1 - *u2;
|
||||
}
|
||||
weak_alias(_strncmp, strncmp);
|
||||
|
||||
char* stpcpy(char* __restrict__ dest, const char* __restrict__ src)
|
||||
extern "C" char* _stpcpy(char* __restrict__ dest, const char* __restrict__ src)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (; src[i]; i++)
|
||||
|
@ -105,8 +114,9 @@ char* stpcpy(char* __restrict__ dest, const char* __restrict__ src)
|
|||
dest[i] = '\0';
|
||||
return &dest[i];
|
||||
}
|
||||
weak_alias(_stpcpy, stpcpy);
|
||||
|
||||
char* stpncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n)
|
||||
extern "C" char* _stpncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (; src[i] && n; i++, n--)
|
||||
|
@ -115,6 +125,7 @@ char* stpncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n)
|
|||
dest[i] = '\0';
|
||||
return &dest[i];
|
||||
}
|
||||
weak_alias(_stpncpy, stpncpy);
|
||||
|
||||
char* strcpy(char* __restrict__ dest, const char* __restrict__ src)
|
||||
{
|
||||
|
@ -202,31 +213,30 @@ char* strndup(const char* str, size_t size)
|
|||
return new_str;
|
||||
}
|
||||
|
||||
size_t strlen(const char* str)
|
||||
extern "C" size_t _strlen(const char* str)
|
||||
{
|
||||
size_t len = 0;
|
||||
while (str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
weak_alias(_strlen, strlen);
|
||||
|
||||
size_t strnlen(const char* str, size_t maxlen)
|
||||
extern "C" size_t _strnlen(const char* str, size_t maxlen)
|
||||
{
|
||||
size_t len = 0;
|
||||
while (len < maxlen && str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
weak_alias(_strnlen, strnlen);
|
||||
|
||||
char* strchr(const char* str, int c)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (*str == (char)c)
|
||||
return (char*)str;
|
||||
str++;
|
||||
}
|
||||
return (*str == (char)c) ? (char*)str : nullptr;
|
||||
if (c == '\0')
|
||||
return const_cast<char*>(str + strlen(str));
|
||||
char* result = strchrnul(str, c);
|
||||
return *result ? result : nullptr;
|
||||
}
|
||||
|
||||
char* strchrnul(const char* str, int c)
|
||||
|
@ -237,7 +247,7 @@ char* strchrnul(const char* str, int c)
|
|||
return (char*)str;
|
||||
str++;
|
||||
}
|
||||
return (char*)str;
|
||||
return const_cast<char*>(str);
|
||||
}
|
||||
|
||||
char* strrchr(const char* str, int c)
|
||||
|
|
Loading…
Reference in New Issue