1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:27:45 +00:00

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.
This commit is contained in:
Andreas Kling 2018-10-23 10:12:50 +02:00
parent 72514c8b97
commit fe237ee215
29 changed files with 276 additions and 32 deletions

View file

@ -1,6 +1,8 @@
OBJS = \
stdio.o \
unistd.o \
string.o \
process.o \
entry.o
LIBRARY = LibC.a

12
LibC/process.cpp Normal file
View file

@ -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);
}
}

8
LibC/process.h Normal file
View file

@ -0,0 +1,8 @@
#pragma once
extern "C" {
int spawn(const char* path);
}

View file

@ -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, ...)

14
LibC/string.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "string.h"
extern "C" {
size_t strlen(const char* str)
{
size_t len = 0;
while (*(str++))
++len;
return len;
}
}

10
LibC/string.h Normal file
View file

@ -0,0 +1,10 @@
#pragma once
#include "types.h"
extern "C" {
size_t strlen(const char*);
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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);
}