summaryrefslogtreecommitdiff
path: root/LibC
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-10-23 10:12:50 +0200
committerAndreas Kling <awesomekling@gmail.com>2018-10-23 10:12:50 +0200
commitfe237ee215fafd2012e6f4e5da88e3c2b8f9d33d (patch)
tree9c88982f0717bd2ee465d19ccb967dd1b27de91f /LibC
parent72514c8b97891a3a032ae7b3003064ac9cf554e7 (diff)
downloadserenity-fe237ee215fafd2012e6f4e5da88e3c2b8f9d33d.zip
Lots of hacking:
- Turn Keyboard into a CharacterDevice (85,1) at /dev/keyboard. - Implement MM::unmapRegionsForTask() and MM::unmapRegion() - Save SS correctly on interrupt. - Add a simple Spawn syscall for launching another process. - Move a bunch of IO syscall debug output behind DEBUG_IO. - Have ASSERT do a "cli" immediately when failing. This makes the output look proper every time. - Implement a bunch of syscalls in LibC. - Add a simple shell ("sh"). All it can do now is read a line of text from /dev/keyboard and then try launching the specified executable by calling spawn(). There are definitely bugs in here, but we're moving on forward.
Diffstat (limited to 'LibC')
-rw-r--r--LibC/Makefile2
-rw-r--r--LibC/process.cpp12
-rw-r--r--LibC/process.h8
-rw-r--r--LibC/stdio.cpp3
-rw-r--r--LibC/string.cpp14
-rw-r--r--LibC/string.h10
-rw-r--r--LibC/types.h7
-rw-r--r--LibC/unistd.cpp17
-rw-r--r--LibC/unistd.h3
9 files changed, 75 insertions, 1 deletions
diff --git a/LibC/Makefile b/LibC/Makefile
index 592a212efe..47485d29fd 100644
--- a/LibC/Makefile
+++ b/LibC/Makefile
@@ -1,6 +1,8 @@
OBJS = \
stdio.o \
unistd.o \
+ string.o \
+ process.o \
entry.o
LIBRARY = LibC.a
diff --git a/LibC/process.cpp b/LibC/process.cpp
new file mode 100644
index 0000000000..045b3e3eeb
--- /dev/null
+++ b/LibC/process.cpp
@@ -0,0 +1,12 @@
+#include "process.h"
+#include <Kernel/Syscall.h>
+
+extern "C" {
+
+int spawn(const char* path)
+{
+ return Syscall::invoke(Syscall::Spawn, (dword)path);
+}
+
+}
+
diff --git a/LibC/process.h b/LibC/process.h
new file mode 100644
index 0000000000..2a35644085
--- /dev/null
+++ b/LibC/process.h
@@ -0,0 +1,8 @@
+#pragma once
+
+extern "C" {
+
+int spawn(const char* path);
+
+}
+
diff --git a/LibC/stdio.cpp b/LibC/stdio.cpp
index dd5b26f9a5..31f0d14d41 100644
--- a/LibC/stdio.cpp
+++ b/LibC/stdio.cpp
@@ -141,7 +141,8 @@ extern "C" {
int putchar(int ch)
{
- return ch;
+ Syscall::invoke(Syscall::PutCharacter, ch);
+ return (byte)ch;
}
int printf(const char* fmt, ...)
diff --git a/LibC/string.cpp b/LibC/string.cpp
new file mode 100644
index 0000000000..252dc65657
--- /dev/null
+++ b/LibC/string.cpp
@@ -0,0 +1,14 @@
+#include "string.h"
+
+extern "C" {
+
+size_t strlen(const char* str)
+{
+ size_t len = 0;
+ while (*(str++))
+ ++len;
+ return len;
+}
+
+}
+
diff --git a/LibC/string.h b/LibC/string.h
new file mode 100644
index 0000000000..21e4ccf287
--- /dev/null
+++ b/LibC/string.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "types.h"
+
+extern "C" {
+
+size_t strlen(const char*);
+
+}
+
diff --git a/LibC/types.h b/LibC/types.h
index 5bb4538f41..fc990e79f7 100644
--- a/LibC/types.h
+++ b/LibC/types.h
@@ -6,9 +6,16 @@ typedef unsigned int dword;
typedef unsigned short word;
typedef unsigned char byte;
+typedef signed int signed_dword;
+typedef signed short signed_word;
+typedef signed char signed_byte;
+
typedef dword uid_t;
typedef dword gid_t;
typedef dword pid_t;
+typedef dword size_t;
+typedef signed_dword ssize_t;
+
}
diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp
index 2a7efa95c2..6efa2da1b2 100644
--- a/LibC/unistd.cpp
+++ b/LibC/unistd.cpp
@@ -1,4 +1,5 @@
#include "unistd.h"
+#include "string.h"
#include <Kernel/Syscall.h>
extern "C" {
@@ -18,5 +19,21 @@ uid_t getpid()
return Syscall::invoke(Syscall::PosixGetpid);
}
+int open(const char* path)
+{
+ size_t length = strlen(path);
+ return Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)length);
+}
+
+ssize_t read(int fd, void* buf, size_t count)
+{
+ return Syscall::invoke(Syscall::PosixRead, (dword)fd, (dword)buf, (dword)count);
+}
+
+int close(int fd)
+{
+ return Syscall::invoke(Syscall::PosixClose, fd);
+}
+
}
diff --git a/LibC/unistd.h b/LibC/unistd.h
index bffc5840b5..2395eadf13 100644
--- a/LibC/unistd.h
+++ b/LibC/unistd.h
@@ -7,6 +7,9 @@ extern "C" {
uid_t getuid();
gid_t getgid();
pid_t getpid();
+int open(const char* path);
+ssize_t read(int fd, void* buf, size_t count);
+int close(int fd);
}