mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-25 23:10:32 +00:00
Change ZealBooter library files to verifiably Public Domain implementations.
This commit is contained in:
parent
c58fa6561d
commit
0bfb500c16
7 changed files with 1977 additions and 132 deletions
104
zealbooter/lib.c
104
zealbooter/lib.c
|
@ -1,105 +1,13 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <lib.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t n) {
|
||||
uint8_t *pdest = (uint8_t *)dest;
|
||||
const uint8_t *psrc = (const uint8_t *)src;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
pdest[i] = psrc[i];
|
||||
}
|
||||
|
||||
return dest;
|
||||
uint64_t div_roundup_u64(uint64_t a, uint64_t b)
|
||||
{
|
||||
return (a + (b - 1)) / b;
|
||||
}
|
||||
|
||||
void *memset(void *s, int c, size_t n) {
|
||||
uint8_t *p = (uint8_t *)s;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
p[i] = (uint8_t)c;
|
||||
}
|
||||
|
||||
return s;
|
||||
uint64_t align_up_u64(uint64_t a, uint64_t b)
|
||||
{
|
||||
return div_roundup_u64(a, b) * b;
|
||||
}
|
||||
|
||||
void *memmove(void *dest, const void *src, size_t n) {
|
||||
uint8_t *pdest = (uint8_t *)dest;
|
||||
const uint8_t *psrc = (const uint8_t *)src;
|
||||
|
||||
if (src > dest) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
pdest[i] = psrc[i];
|
||||
}
|
||||
} else if (src < dest) {
|
||||
for (size_t i = n; i > 0; i--) {
|
||||
pdest[i-1] = psrc[i-1];
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n) {
|
||||
const uint8_t *p1 = (const uint8_t *)s1;
|
||||
const uint8_t *p2 = (const uint8_t *)s2;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (p1[i] != p2[i])
|
||||
return p1[i] < p2[i] ? -1 : 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; src[i]; i++)
|
||||
dest[i] = src[i];
|
||||
|
||||
dest[i] = 0;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *strncpy(char *dest, const char *src, size_t n) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < n && src[i]; i++)
|
||||
dest[i] = src[i];
|
||||
for ( ; i < n; i++)
|
||||
dest[i] = 0;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
for (size_t i = 0; ; i++) {
|
||||
char c1 = s1[i], c2 = s2[i];
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
if (!c1)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
char c1 = s1[i], c2 = s2[i];
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
if (!c1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t strlen(const char *str) {
|
||||
size_t len;
|
||||
|
||||
for (len = 0; str[len]; len++);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
|
|
@ -1,37 +1,8 @@
|
|||
#ifndef __LIB_H__
|
||||
#define __LIB_H__
|
||||
#include <stdint.h>
|
||||
#include <memcpy.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define DIV_ROUNDUP(A, B) ({ \
|
||||
typeof(A) _a_ = A; \
|
||||
typeof(B) _b_ = B; \
|
||||
(_a_ + (_b_ - 1)) / _b_; \
|
||||
})
|
||||
|
||||
#define ALIGN_UP(A, B) ({ \
|
||||
typeof(A) _a__ = A; \
|
||||
typeof(B) _b__ = B; \
|
||||
DIV_ROUNDUP(_a__, _b__) * _b__; \
|
||||
})
|
||||
|
||||
#define ALIGN_DOWN(A, B) ({ \
|
||||
typeof(A) _a_ = A; \
|
||||
typeof(B) _b_ = B; \
|
||||
(_a_ / _b_) * _b_; \
|
||||
})
|
||||
uint64_t div_roundup_u64(uint64_t a, uint64_t b);
|
||||
uint64_t align_up_u64(uint64_t a, uint64_t b);
|
||||
|
||||
typedef char symbol[];
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t n);
|
||||
void *memset(void *s, int c, size_t n);
|
||||
void *memmove(void *dest, const void *src, size_t n);
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
size_t strlen(const char *str);
|
||||
|
||||
#endif
|
||||
|
|
21
zealbooter/memcpy.c
Normal file
21
zealbooter/memcpy.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* memcpy( void *, const void *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *memcpy(void *s1, const void *s2, size_t n)
|
||||
{
|
||||
char *dest = (char *)s1;
|
||||
const char *src = (const char *)s2;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
||||
|
4
zealbooter/memcpy.h
Normal file
4
zealbooter/memcpy.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
void *memcpy(void *s1, const void *s2, size_t n);
|
31
zealbooter/print.c
Normal file
31
zealbooter/print.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#define STB_SPRINTF_DECORATE(name) name
|
||||
#define STB_SPRINTF_IMPLEMENTATION 1
|
||||
#define STB_SPRINTF_NOFLOAT 1
|
||||
#include <stb_sprintf.h>
|
||||
#include <limine.h>
|
||||
|
||||
static volatile struct limine_terminal_request terminal_request = {
|
||||
.id = LIMINE_TERMINAL_REQUEST,
|
||||
.revision = 0
|
||||
};
|
||||
|
||||
#define PRINT_BUFFER_SIZE 8192
|
||||
|
||||
int printf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buffer[PRINT_BUFFER_SIZE];
|
||||
struct limine_terminal *terminal;
|
||||
size_t length;
|
||||
|
||||
va_start(args, format);
|
||||
|
||||
length = vsnprintf(buffer, PRINT_BUFFER_SIZE, format, args);
|
||||
terminal = terminal_request.response->terminals[0];
|
||||
terminal_request.response->write(terminal, buffer, length);
|
||||
|
||||
va_end(args);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
3
zealbooter/print.h
Normal file
3
zealbooter/print.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
int printf(const char *format, ...);
|
||||
|
1907
zealbooter/stb_sprintf.h
Normal file
1907
zealbooter/stb_sprintf.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue