added devices and lang directories, added skeleton kio and string modules
git-svn-id: svn://anubis/hos/trunk@43 5b3e749e-e535-0410-8002-a9bb6afbdfca
This commit is contained in:
parent
1aace858da
commit
be17cde305
@ -13,7 +13,7 @@ export CFLAGS := -Wall -O2
|
||||
export CXXFLAGS := -Wall -O2 -fno-rtti -fno-exceptions
|
||||
export LDFLAGS := -T $(LDSCRIPT) -Map $(KERNEL).map
|
||||
|
||||
SUBDIRS := boot mm
|
||||
SUBDIRS := boot mm lang
|
||||
SUBDIRS_clean := $(SUBDIRS:%=%.clean)
|
||||
|
||||
.PHONY: all
|
||||
|
2
kernel/lang/Makefile
Normal file
2
kernel/lang/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
include $(HOS_TOPLEVEL)/subdir.mak
|
157
kernel/lang/kio.cc
Normal file
157
kernel/lang/kio.cc
Normal file
@ -0,0 +1,157 @@
|
||||
|
||||
#include "kio.h"
|
||||
#include "string.h"
|
||||
|
||||
#include <stdarg.h> /* va_*() */
|
||||
|
||||
static void fmt_d2a(char * buf, int val);
|
||||
static void fmt_u2a(char * buf, unsigned int val);
|
||||
static void fmt_ll2a(char * buf, long long val);
|
||||
static void fmt_ull2a(char * buf, unsigned long long val);
|
||||
static void fmt_x2a(char * buf, unsigned int val);
|
||||
static void fmt_o2a(char * buf, unsigned int val);
|
||||
|
||||
extern "C" {
|
||||
|
||||
void kprintf(char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
kvprintf(fmt, args);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void kvprintf(char * fmt, va_list args)
|
||||
{
|
||||
char tmpbuf[25];
|
||||
for ( ; *fmt; fmt++)
|
||||
{
|
||||
if (*fmt == '%')
|
||||
{
|
||||
fmt++;
|
||||
if (*fmt)
|
||||
{
|
||||
switch (*fmt)
|
||||
{
|
||||
case 'c':
|
||||
kputc(va_arg(args, int));
|
||||
break;
|
||||
case 'd':
|
||||
fmt_d2a(tmpbuf, va_arg(args, int));
|
||||
kputs(tmpbuf);
|
||||
break;
|
||||
case 'l':
|
||||
fmt_ll2a(tmpbuf, va_arg(args, long long));
|
||||
kputs(tmpbuf);
|
||||
break;
|
||||
case 'L':
|
||||
fmt_ull2a(tmpbuf, va_arg(args, unsigned long long));
|
||||
kputs(tmpbuf);
|
||||
break;
|
||||
case 'o':
|
||||
fmt_o2a(tmpbuf, va_arg(args, unsigned int));
|
||||
kputs(tmpbuf);
|
||||
break;
|
||||
case 's':
|
||||
kputs(va_arg(args, char *));
|
||||
break;
|
||||
case 'u':
|
||||
fmt_u2a(tmpbuf, va_arg(args, unsigned int));
|
||||
kputs(tmpbuf);
|
||||
break;
|
||||
case 'x':
|
||||
fmt_x2a(tmpbuf, va_arg(args, unsigned int));
|
||||
kputs(tmpbuf);
|
||||
break;
|
||||
case '%':
|
||||
kputc('%');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
kputc(*fmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void kputc(char c)
|
||||
{
|
||||
}
|
||||
|
||||
void kputs(char * s)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
kputc(*s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
||||
|
||||
static void fmt_d2a(char * buf, int val)
|
||||
{
|
||||
if (val == 0x7FFFFFFF)
|
||||
{
|
||||
strcpy(buf, "-2147483648");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (val < 0)
|
||||
{
|
||||
*buf++ = '-';
|
||||
val = -val;
|
||||
}
|
||||
fmt_u2a(buf, (unsigned int) val);
|
||||
}
|
||||
}
|
||||
|
||||
static void fmt_u2a(char * buf, unsigned int val)
|
||||
{
|
||||
}
|
||||
|
||||
static void fmt_ll2a(char * buf, long long val)
|
||||
{
|
||||
}
|
||||
|
||||
static void fmt_ull2a(char * buf, unsigned long long val)
|
||||
{
|
||||
}
|
||||
|
||||
static void fmt_x2a(char * buf, unsigned int val)
|
||||
{
|
||||
bool printing = false;
|
||||
for (int s = 28; s >= 0; s -= 4)
|
||||
{
|
||||
unsigned int n = (val >> s) & 0xF;
|
||||
if (n)
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
*buf++ = "0123456789ABCDEF"[n];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void fmt_o2a(char * buf, unsigned int val)
|
||||
{
|
||||
bool printing = false;
|
||||
for (int s = 30; s >= 0; s -= 3)
|
||||
{
|
||||
unsigned int n = (val >> s) & 0x7;
|
||||
if (n)
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
*buf++ = "01234567"[n];
|
||||
}
|
||||
}
|
||||
}
|
23
kernel/lang/kio.h
Normal file
23
kernel/lang/kio.h
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
#ifndef KIO_H
|
||||
#define KIO_H
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void kprintf(char * fmt, ...);
|
||||
|
||||
void kvprintf(char * fmt, va_list args);
|
||||
|
||||
void kputc(char c);
|
||||
|
||||
void kputs(char * s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
14
kernel/lang/string.cc
Normal file
14
kernel/lang/string.cc
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
#include "string.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void strcpy(char * dst, const char * src)
|
||||
{
|
||||
while (*src)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
15
kernel/lang/string.h
Normal file
15
kernel/lang/string.h
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void strcpy(char * dst, const char * src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user