Add the basic character devices to kernel.

This commit is contained in:
Andreas Kling 2018-10-16 14:33:16 +02:00
parent 12e515735b
commit aec8ab0a60
Notes: sideshowbarker 2024-07-19 18:47:17 +09:00
13 changed files with 52 additions and 58 deletions

View file

@ -55,6 +55,13 @@ T exchange(T& a, U&& b)
return tmp;
}
template<typename T, typename U>
void swap(T& a, U& b)
{
U tmp = move((U&)a);
a = (T&&)move(b);
b = move(tmp);
}
}
@ -63,5 +70,6 @@ using AK::max;
using AK::move;
using AK::forward;
using AK::exchange;
using AK::swap;
using AK::ceilDiv;

8
AK/kstdio.h Normal file
View file

@ -0,0 +1,8 @@
#pragma once
#ifdef SERENITY_KERNEL
#include <Kernel/kstdio.h>
#else
#include <cstdio>
#define kprintf printf
#endif

View file

@ -3,6 +3,7 @@
#include "types.h"
#include "DataBuffer.h"
#include "RefPtr.h"
#include <AK/StdLib.h>
/* IPC message types. There will be moar. */
#define MSG_INTERRUPT 0x00000001

View file

@ -22,7 +22,12 @@ KERNEL_OBJS = \
IDEDiskDevice.o
VFS_OBJS = \
../VirtualFileSystem/DiskDevice.o
../VirtualFileSystem/DiskDevice.o \
../VirtualFileSystem/CharacterDevice.o \
../VirtualFileSystem/NullDevice.o \
../VirtualFileSystem/FullDevice.o \
../VirtualFileSystem/ZeroDevice.o \
../VirtualFileSystem/RandomDevice.o
OBJS = $(KERNEL_OBJS) $(VFS_OBJS)

View file

@ -1,5 +1,5 @@
#include "String.h"
#include "StdLib.h"
#include <AK/StdLib.h>
String::String()
{

View file

@ -15,6 +15,11 @@
#include "FileSystem.h"
#include "Userspace.h"
#include "IDEDiskDevice.h"
#include <VirtualFileSystem/NullDevice.h>
#include <VirtualFileSystem/ZeroDevice.h>
#include <VirtualFileSystem/FullDevice.h>
#include <VirtualFileSystem/RandomDevice.h>
#include <AK/OwnPtr.h>
#if 0
/* Keyboard LED disco task ;^) */
@ -124,7 +129,11 @@ void init()
Disk::initialize();
FileSystem::initialize();
auto hd0 = IDEDiskDevice::create();
auto dev_hd0 = IDEDiskDevice::create();
auto dev_null = make<NullDevice>();
auto dev_full = make<FullDevice>();
auto dev_zero = make<ZeroDevice>();
auto dev_random = make<RandomDevice>();
// new Task(motd_main, "motd", IPC::Handle::MotdTask, Task::Ring0);
new Task(user_main, "user", IPC::Handle::UserTask, Task::Ring3);

3
Kernel/kstdio.h Normal file
View file

@ -0,0 +1,3 @@
#pragma once
#include "VGA.h"

View file

@ -6,48 +6,6 @@
#define PUBLIC
#define PRIVATE static
template <typename T>
T&& move(T& arg)
{
return static_cast<T&&>(arg);
}
template<typename T>
T min(T a, T b)
{
return (a < b) ? a : b;
}
template<typename T>
T max(T a, T b)
{
return (a > b) ? a : b;
}
template<typename T, typename U>
void swap(T& a, U& b)
{
U tmp = move((U&)a);
a = (T&&)move(b);
b = move(tmp);
}
template<typename T>
struct identity {
typedef T type;
};
template<typename T>
T&& forward(typename identity<T>::type&& param)
{ return static_cast<typename identity<T>::type&&>(param); }
template<typename T, typename U>
T exchange(T& a, U&& b)
{
T tmp = move(a);
a = move(b);
return tmp;
}
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int DWORD;

View file

@ -2,8 +2,7 @@
#include "Limits.h"
#include "sys-errno.h"
#include <AK/StdLib.h>
#include <cstring>
#include <cstdio>
#include <AK/kstdio.h>
FullDevice::FullDevice()
{
@ -15,7 +14,7 @@ FullDevice::~FullDevice()
Unix::ssize_t FullDevice::read(byte* buffer, Unix::size_t bufferSize)
{
printf("read from full device\n");
kprintf("FullDevice: read from full\n");
Unix::size_t count = min(GoodBufferSize, bufferSize);
memset(buffer, 0, count);
return count;

View file

@ -1,9 +1,14 @@
#pragma once
#include <limits>
#include "UnixTypes.h"
#ifdef SERENITY_KERNEL
inline static const Unix::off_t maxFileOffset = 9223372036854775807LL;
#else
#include <limits>
inline static const Unix::off_t maxFileOffset = std::numeric_limits<Unix::off_t>::max();
#endif
static const Unix::size_t GoodBufferSize = 4096;
inline static const Unix::off_t maxFileOffset = std::numeric_limits<Unix::off_t>::max();

View file

@ -1,8 +1,7 @@
#include "NullDevice.h"
#include "Limits.h"
#include <AK/StdLib.h>
#include <cstring>
#include <cstdio>
#include <AK/kstdio.h>
NullDevice::NullDevice()
{
@ -14,7 +13,7 @@ NullDevice::~NullDevice()
Unix::ssize_t NullDevice::read(byte*, Unix::size_t)
{
printf("read from null\n");
kprintf("NullDevice: read from null\n");
return 0;
}

View file

@ -1,8 +1,6 @@
#include "RandomDevice.h"
#include "Limits.h"
#include <AK/StdLib.h>
#include <cstring>
#include <cstdio>
RandomDevice::RandomDevice()
{
@ -23,10 +21,12 @@ static int myrand()
return((unsigned)(next/((MY_RAND_MAX + 1) * 2)) % (MY_RAND_MAX + 1));
}
#if 0
static void mysrand(unsigned seed)
{
next = seed;
}
#endif
Unix::ssize_t RandomDevice::read(byte* buffer, Unix::size_t bufferSize)
{

View file

@ -1,8 +1,7 @@
#include "ZeroDevice.h"
#include "Limits.h"
#include <AK/StdLib.h>
#include <cstring>
#include <cstdio>
#include <AK/kstdio.h>
ZeroDevice::ZeroDevice()
{
@ -14,7 +13,7 @@ ZeroDevice::~ZeroDevice()
Unix::ssize_t ZeroDevice::read(byte* buffer, Unix::size_t bufferSize)
{
printf("read from zero device\n");
kprintf("ZeroDevice: read from zero\n");
Unix::size_t count = min(GoodBufferSize, bufferSize);
memset(buffer, 0, count);
return count;