summaryrefslogtreecommitdiff
path: root/kernel/rtl
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2016-06-01 19:37:09 -0700
committerScott Gasch <[email protected]>2016-06-01 19:37:09 -0700
commit0a41dae5f406d498b5c9ab1542cb5660e0d982f6 (patch)
tree67ade9fe31cfd0458cc485e95550f7aaf14abdd1 /kernel/rtl
Initial checkin of toy OS project.HEADmaster
Diffstat (limited to 'kernel/rtl')
-rw-r--r--kernel/rtl/Makefile19
-rw-r--r--kernel/rtl/memory.c29
-rw-r--r--kernel/rtl/string.c138
3 files changed, 186 insertions, 0 deletions
diff --git a/kernel/rtl/Makefile b/kernel/rtl/Makefile
new file mode 100644
index 0000000..1767c0a
--- /dev/null
+++ b/kernel/rtl/Makefile
@@ -0,0 +1,19 @@
+CC= gcc
+CFLAGS= -Wall -imacros ../defines -I../inc
+OBJS= string.o memory.o
+RM= /bin/rm
+NASM= nasm
+NASMFLAGS=
+
+.SUFFIXES: .c .o .asm
+
+all: $(OBJS)
+
+.c.o:
+ $(CC) $(CFLAGS) -c $<
+
+.asm.o:
+ $(NASM) $(NASMFLAGS) -o $*.o $<
+
+clean:
+ $(RM) -f $(OBJS) *~ #*# .#*
diff --git a/kernel/rtl/memory.c b/kernel/rtl/memory.c
new file mode 100644
index 0000000..f4f845e
--- /dev/null
+++ b/kernel/rtl/memory.c
@@ -0,0 +1,29 @@
+//+----------------------------------------------------------------------------
+//
+// File: memory.c
+//
+// Module:
+//
+// Synopsis:
+//
+// Copyright (C) Scott Gasch
+//
+// Created: sgasch 5 Jul 2003
+//
+//+----------------------------------------------------------------------------
+
+#include "kernel.h"
+
+void
+RtlSetMemory(void *pStart,
+ BYTE bFill,
+ ULONG uLength)
+{
+ BYTE *p = (BYTE *)pStart;
+
+ while(uLength > 0)
+ {
+ *p++ = bFill;
+ uLength--;
+ }
+}
diff --git a/kernel/rtl/string.c b/kernel/rtl/string.c
new file mode 100644
index 0000000..da42000
--- /dev/null
+++ b/kernel/rtl/string.c
@@ -0,0 +1,138 @@
+//+----------------------------------------------------------------------------
+//
+// File: string.c
+//
+// Module:
+//
+// Synopsis:
+//
+// Copyright (C) 2003 Scott Gasch
+//
+// Created: sgasch 5 Jul 2003
+//
+//+----------------------------------------------------------------------------
+
+#include "kernel.h"
+
+CHAR *
+strncpy(CHAR *pDest, CHAR *pSrc, SIZE_T u)
+{
+ char *p = pDest;
+ ULONG v = 0;
+
+ while ((v < u) && (*pSrc))
+ {
+ *pDest = *pSrc;
+ pDest++; pSrc++; v++;
+ }
+
+ //
+ // If we ran out of space, null terminate the dest buffer
+ //
+ if ((*pSrc) && (u > 0))
+ {
+ *(pDest - 1) = 0;
+ }
+
+ return(p);
+}
+
+SIZE_T
+strlen(CHAR *p)
+{
+ ULONG i = 0;
+ while(*p)
+ {
+ i++;
+ p++;
+ }
+ return(i);
+}
+
+CHAR *
+RtlIntToAscii(INT i,
+ CHAR *buf,
+ ULONG uBufLen,
+ ULONG uBase)
+{
+ CHAR *p = (buf + uBufLen);
+ ULONG uSpaceLeft = uBufLen;
+ ULONG uMagnitude;
+ BOOL fNeg = FALSE;
+
+ //
+ // null terminate the workspace buffer
+ //
+ if (uSpaceLeft == 0)
+ {
+ return(NULL);
+ }
+ *p = '\0';
+ p--;
+ uSpaceLeft--;
+
+ //
+ // Get the int's sign
+ //
+ if (i < 0)
+ {
+ fNeg = TRUE;
+ uMagnitude = -i;
+ }
+ else
+ {
+ uMagnitude = i;
+ }
+
+ //
+ // Based on base, do the conversion. Build the string backwards from
+ // less significant digits. Stop if we finish or if we run out of
+ // uSpaceLeft.
+ //
+ switch(uBase)
+ {
+ case 10:
+ do
+ {
+ *p = (uMagnitude % 10) + '0';
+ p--;
+ uSpaceLeft--;
+ uMagnitude /= 10;
+ }
+ while((uSpaceLeft > 0) && (uMagnitude != 0));
+ break;
+ case 16:
+ do
+ {
+ *p = "0123456789ABCDEF"[uMagnitude & 15];
+ p--;
+ uSpaceLeft--;
+ uMagnitude >>= 4;
+ }
+ while((uSpaceLeft > 0) && (uMagnitude != 0));
+ break;
+ case 8:
+ do
+ {
+ *p = (uMagnitude & 7) + '0';
+ p--;
+ uSpaceLeft--;
+ uMagnitude >>= 3;
+ }
+ while((uSpaceLeft > 0) && (uMagnitude != 0));
+ break;
+ }
+
+ if (TRUE == fNeg)
+ {
+ if (uSpaceLeft > 0)
+ {
+ *p = '-';
+ }
+ }
+ else
+ {
+ p++;
+ }
+ return(p);
+}