Basic stdio.h support working
This commit is contained in:
parent
b607141ce1
commit
3fc2949c5c
@ -10,6 +10,7 @@ src_common = [
|
||||
"assert.c",
|
||||
"exit.c",
|
||||
"file.c",
|
||||
"string.c",
|
||||
"syscall.c",
|
||||
"posix/mman.c",
|
||||
]
|
||||
|
132
lib/libc/string.c
Normal file
132
lib/libc/string.c
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014 Stanford University
|
||||
* Copyright (c) 2006-2008 Ali Mashtizadeh
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strchr(const char *s, int c)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
if (s[i] == c)
|
||||
return (char *)s + i;
|
||||
if (s[i] == '\0')
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
strcpy(char *to, const char *from)
|
||||
{
|
||||
char *save = to;
|
||||
|
||||
for (; (*to = *from); ++from, ++to);
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
char *
|
||||
strncpy(char *to, const char *from, size_t length)
|
||||
{
|
||||
char *save = to;
|
||||
|
||||
for (; (*to = *from) != '\0' && length > 0; ++from, ++to, length--);
|
||||
|
||||
*to = '\0';
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
int
|
||||
strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 == *s2++)
|
||||
if (*s1++ == 0)
|
||||
return 0;
|
||||
|
||||
return (*(const uint8_t *)s1 - *(const uint8_t *)(s2 - 1));
|
||||
}
|
||||
|
||||
int
|
||||
strncmp(const char *s1, const char *s2, size_t len)
|
||||
{
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
while (*s1 == *s2) {
|
||||
if (*s1 == 0)
|
||||
return 0;
|
||||
|
||||
s1++;
|
||||
s2++;
|
||||
|
||||
len--;
|
||||
if (len == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (*(const uint8_t *)s1 - *(const uint8_t *)s2);
|
||||
}
|
||||
|
||||
size_t
|
||||
strlen(const char *str)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
for (s = str; *s; ++s);
|
||||
|
||||
return (s - str);
|
||||
}
|
||||
|
||||
void *
|
||||
memset(void *dst, int c, size_t length)
|
||||
{
|
||||
uint8_t *p = (uint8_t *)dst;
|
||||
|
||||
while (length-- != 0) {
|
||||
*p = c;
|
||||
p += 1;
|
||||
};
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *
|
||||
memcpy(void *dst, const void *src, size_t length)
|
||||
{
|
||||
uint8_t *d = (uint8_t *)dst;
|
||||
const uint8_t *s = (const uint8_t *)src;
|
||||
|
||||
while (length-- != 0) {
|
||||
*d = *s;
|
||||
d += 1;
|
||||
s += 1;
|
||||
};
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
int
|
||||
memcmp(const void *b1, const void *b2, size_t length)
|
||||
{
|
||||
int i;
|
||||
const char *c1 = (const char *)b1;
|
||||
const char *c2 = (const char *)b2;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if (*c1 != *c2)
|
||||
return *c2 - *c1;
|
||||
c1++;
|
||||
c2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ static uint8_t keyMap[256] = {
|
||||
0x00, 0x1B, '1', '2', '3', '4', '5', '6',
|
||||
'7', '8', '9', '0', '-', '=', 0x08, 0x09,
|
||||
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
|
||||
'o', 'p', '[', ']', 0x0D, 0x00, 'a', 's',
|
||||
'o', 'p', '[', ']', 0x0A, 0x00, 'a', 's',
|
||||
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
|
||||
'\'', '`', 0x00, '\\', 'z', 'x', 'c', 'v',
|
||||
'b', 'n', 'm', ',', '.', '/', 0x00, '*',
|
||||
|
@ -106,6 +106,9 @@ Loader_Load(Thread *thr, VNode *vn, void *buf, uint64_t len)
|
||||
return true;
|
||||
}
|
||||
|
||||
// XXX: Cleanup
|
||||
Handle *Console_OpenHandle();
|
||||
|
||||
void
|
||||
Loader_LoadInit()
|
||||
{
|
||||
@ -126,6 +129,15 @@ Loader_LoadInit()
|
||||
Panic("Reading init process failed!");
|
||||
|
||||
Thread *thr = Thread_Current();
|
||||
|
||||
// Open stdin/out/err
|
||||
Handle *handle = Console_OpenHandle();
|
||||
Handle_Add(thr, handle);
|
||||
handle = Console_OpenHandle();
|
||||
Handle_Add(thr, handle);
|
||||
handle = Console_OpenHandle();
|
||||
Handle_Add(thr, handle);
|
||||
|
||||
Loader_Load(thr, init, pg, 1024);
|
||||
|
||||
VFS_Close(init);
|
||||
|
@ -95,7 +95,7 @@ Syscall_Read(uint64_t fd, uint64_t addr, uint64_t off, uint64_t length)
|
||||
if (handle == NULL)
|
||||
return -EBADF;
|
||||
|
||||
return (handle->write)(handle, (void *)addr, off, length);;
|
||||
return (handle->read)(handle, (void *)addr, off, length);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
|
Loading…
Reference in New Issue
Block a user