Implement enough runtime for binutils to compile

This commit is contained in:
apio 2022-10-31 12:29:53 +01:00
parent 497a52dd82
commit 534500cda0
13 changed files with 135 additions and 3 deletions

View File

@ -126,7 +126,7 @@ void InitRD::for_each(void (*callback)(File& f))
}
}
#define INITRD_MAX_FILES_IN_DIR 16
#define INITRD_MAX_FILES_IN_DIR 32
#define INITRD_MAX_FILES 64
namespace InitRD
@ -378,7 +378,7 @@ static bool initrd_register_file(InitRD::File& f, uint64_t inode)
static void initrd_scan()
{
initrd_for_each_dir([](InitRD::Directory& dir) {
if (total_dirs >= 32)
if (total_dirs >= INITRD_MAX_FILES)
{
kwarnln("Failed to register directory %s: Too many directories in initrd", dir.name);
return;
@ -387,7 +387,7 @@ static void initrd_scan()
if (initrd_register_dir(dir, inode)) dirs[total_dirs++] = dir;
});
InitRD::for_each([](InitRD::File& f) {
if (total_files >= 32)
if (total_files >= INITRD_MAX_FILES)
{
kwarnln("Failed to register file %s: Too many files in initrd", f.name);
return;

View File

@ -0,0 +1,19 @@
#ifndef _LOCALE_H
#define _LOCALE_H
#define LC_ALL 0
#define LC_CTYPE 1
#define LC_COLLATE 2
#ifdef __cplusplus
extern "C"
{
#endif
char* setlocale(int category, const char* locale); // Not implemented.
#ifdef __cplusplus
}
#endif
#endif

View File

View File

@ -48,6 +48,9 @@ extern "C"
/* Registers a handler function to be run at normal program termination. */
int atexit(void (*handler)(void));
/* Returns a floating point number parsed from the string str. */
float atof(const char* str);
/* Returns an integer (of type int) parsed from the string str. */
int atoi(const char* str);

View File

@ -68,6 +68,7 @@ extern "C"
mode_t umask(mode_t cmask);
int chmod(const char* pathname, mode_t mode); // Not implemented.
int fchmod(int fd, mode_t mode); // Not implemented.
#ifdef __cplusplus
}

View File

@ -99,6 +99,9 @@ extern "C"
char* getcwd(char* buf, size_t size);
int unlink(const char* path); // Not implemented.
int rmdir(const char* path); // Not implemented.
int chdir(const char* path); // Not implemented.
int pipe(int fd[2]); // Not implemented.
#ifdef __cplusplus
}

23
libs/libc/include/utime.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef _UTIME_H
#define _UTIME_H
#include <sys/types.h>
struct utimbuf
{
time_t actime;
time_t modtime;
};
#ifdef __cplusplus
extern "C"
{
#endif
int utime(const char*, const struct utimbuf*); // Not implemented.
#ifdef __cplusplus
}
#endif
#endif

View File

@ -4,6 +4,8 @@
#include <stdlib.h>
#include <unistd.h>
char** environ = {nullptr};
static void terminate_libc()
{
fclose(stdout);

12
libs/libc/src/locale.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <locale.h>
#include <luna.h>
static char default_locale[] = "C";
extern "C"
{
char* setlocale(int, const char*)
{
return default_locale;
}
}

View File

@ -26,6 +26,40 @@ template <typename T> static T string_to_integer_type(const char* str)
return (neg ? -val : val);
}
template <typename T> static T string_to_float_type(const char* str)
{
bool neg = false;
T val = 0;
T small = 0;
switch (*str)
{
case '-':
neg = true;
str++;
break;
case '+': str++; break;
default: break;
}
while (isdigit(*str)) { val = (10 * val) + (T)(*str++ - '0'); }
if (*str == '.')
{
str++;
T div = 10;
while (isdigit(*str))
{
small = small + (T)(*str++ - '0') / div;
div *= 10;
}
val += small;
}
return (neg ? -val : val);
}
template <typename Arg, typename Struct> static inline Struct common_div(Arg a, Arg b)
{
Struct result;
@ -48,6 +82,11 @@ extern "C"
_Exit(-1);
}
float atof(const char* str)
{
return string_to_float_type<float>(str);
}
int atoi(const char* str)
{
return string_to_integer_type<int>(str);

View File

@ -29,4 +29,9 @@ extern "C"
{
NOT_IMPLEMENTED("chmod");
}
int fchmod(int, mode_t)
{
NOT_IMPLEMENTED("fchmod");
}
}

View File

@ -148,4 +148,19 @@ extern "C"
{
NOT_IMPLEMENTED("unlink");
}
int rmdir(const char*)
{
NOT_IMPLEMENTED("rmdir");
}
int chdir(const char*)
{
NOT_IMPLEMENTED("chdir");
}
int pipe(int[2])
{
NOT_IMPLEMENTED("pipe");
}
}

10
libs/libc/src/utime.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <luna.h>
#include <utime.h>
extern "C"
{
int utime(const char*, const struct utimbuf*)
{
NOT_IMPLEMENTED("utime");
}
}