mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 05:35:52 +03:00
Add the basic character devices to kernel.
This commit is contained in:
parent
12e515735b
commit
aec8ab0a60
Notes:
sideshowbarker
2024-07-19 18:47:17 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/aec8ab0a606
@ -55,6 +55,13 @@ T exchange(T& a, U&& b)
|
|||||||
return tmp;
|
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::move;
|
||||||
using AK::forward;
|
using AK::forward;
|
||||||
using AK::exchange;
|
using AK::exchange;
|
||||||
|
using AK::swap;
|
||||||
using AK::ceilDiv;
|
using AK::ceilDiv;
|
||||||
|
|
||||||
|
8
AK/kstdio.h
Normal file
8
AK/kstdio.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef SERENITY_KERNEL
|
||||||
|
#include <Kernel/kstdio.h>
|
||||||
|
#else
|
||||||
|
#include <cstdio>
|
||||||
|
#define kprintf printf
|
||||||
|
#endif
|
@ -3,6 +3,7 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "DataBuffer.h"
|
#include "DataBuffer.h"
|
||||||
#include "RefPtr.h"
|
#include "RefPtr.h"
|
||||||
|
#include <AK/StdLib.h>
|
||||||
|
|
||||||
/* IPC message types. There will be moar. */
|
/* IPC message types. There will be moar. */
|
||||||
#define MSG_INTERRUPT 0x00000001
|
#define MSG_INTERRUPT 0x00000001
|
||||||
|
@ -22,7 +22,12 @@ KERNEL_OBJS = \
|
|||||||
IDEDiskDevice.o
|
IDEDiskDevice.o
|
||||||
|
|
||||||
VFS_OBJS = \
|
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)
|
OBJS = $(KERNEL_OBJS) $(VFS_OBJS)
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "String.h"
|
#include "String.h"
|
||||||
#include "StdLib.h"
|
#include <AK/StdLib.h>
|
||||||
|
|
||||||
String::String()
|
String::String()
|
||||||
{
|
{
|
||||||
|
@ -15,6 +15,11 @@
|
|||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "Userspace.h"
|
#include "Userspace.h"
|
||||||
#include "IDEDiskDevice.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
|
#if 0
|
||||||
/* Keyboard LED disco task ;^) */
|
/* Keyboard LED disco task ;^) */
|
||||||
@ -124,7 +129,11 @@ void init()
|
|||||||
Disk::initialize();
|
Disk::initialize();
|
||||||
FileSystem::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(motd_main, "motd", IPC::Handle::MotdTask, Task::Ring0);
|
||||||
new Task(user_main, "user", IPC::Handle::UserTask, Task::Ring3);
|
new Task(user_main, "user", IPC::Handle::UserTask, Task::Ring3);
|
||||||
|
3
Kernel/kstdio.h
Normal file
3
Kernel/kstdio.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "VGA.h"
|
@ -6,48 +6,6 @@
|
|||||||
#define PUBLIC
|
#define PUBLIC
|
||||||
#define PRIVATE static
|
#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 char BYTE;
|
||||||
typedef unsigned short WORD;
|
typedef unsigned short WORD;
|
||||||
typedef unsigned int DWORD;
|
typedef unsigned int DWORD;
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
#include "Limits.h"
|
#include "Limits.h"
|
||||||
#include "sys-errno.h"
|
#include "sys-errno.h"
|
||||||
#include <AK/StdLib.h>
|
#include <AK/StdLib.h>
|
||||||
#include <cstring>
|
#include <AK/kstdio.h>
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
FullDevice::FullDevice()
|
FullDevice::FullDevice()
|
||||||
{
|
{
|
||||||
@ -15,7 +14,7 @@ FullDevice::~FullDevice()
|
|||||||
|
|
||||||
Unix::ssize_t FullDevice::read(byte* buffer, Unix::size_t bufferSize)
|
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);
|
Unix::size_t count = min(GoodBufferSize, bufferSize);
|
||||||
memset(buffer, 0, count);
|
memset(buffer, 0, count);
|
||||||
return count;
|
return count;
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
#include "UnixTypes.h"
|
#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;
|
static const Unix::size_t GoodBufferSize = 4096;
|
||||||
|
|
||||||
inline static const Unix::off_t maxFileOffset = std::numeric_limits<Unix::off_t>::max();
|
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#include "NullDevice.h"
|
#include "NullDevice.h"
|
||||||
#include "Limits.h"
|
#include "Limits.h"
|
||||||
#include <AK/StdLib.h>
|
#include <AK/StdLib.h>
|
||||||
#include <cstring>
|
#include <AK/kstdio.h>
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
NullDevice::NullDevice()
|
NullDevice::NullDevice()
|
||||||
{
|
{
|
||||||
@ -14,7 +13,7 @@ NullDevice::~NullDevice()
|
|||||||
|
|
||||||
Unix::ssize_t NullDevice::read(byte*, Unix::size_t)
|
Unix::ssize_t NullDevice::read(byte*, Unix::size_t)
|
||||||
{
|
{
|
||||||
printf("read from null\n");
|
kprintf("NullDevice: read from null\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "RandomDevice.h"
|
#include "RandomDevice.h"
|
||||||
#include "Limits.h"
|
#include "Limits.h"
|
||||||
#include <AK/StdLib.h>
|
#include <AK/StdLib.h>
|
||||||
#include <cstring>
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
RandomDevice::RandomDevice()
|
RandomDevice::RandomDevice()
|
||||||
{
|
{
|
||||||
@ -23,10 +21,12 @@ static int myrand()
|
|||||||
return((unsigned)(next/((MY_RAND_MAX + 1) * 2)) % (MY_RAND_MAX + 1));
|
return((unsigned)(next/((MY_RAND_MAX + 1) * 2)) % (MY_RAND_MAX + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void mysrand(unsigned seed)
|
static void mysrand(unsigned seed)
|
||||||
{
|
{
|
||||||
next = seed;
|
next = seed;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Unix::ssize_t RandomDevice::read(byte* buffer, Unix::size_t bufferSize)
|
Unix::ssize_t RandomDevice::read(byte* buffer, Unix::size_t bufferSize)
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#include "ZeroDevice.h"
|
#include "ZeroDevice.h"
|
||||||
#include "Limits.h"
|
#include "Limits.h"
|
||||||
#include <AK/StdLib.h>
|
#include <AK/StdLib.h>
|
||||||
#include <cstring>
|
#include <AK/kstdio.h>
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
ZeroDevice::ZeroDevice()
|
ZeroDevice::ZeroDevice()
|
||||||
{
|
{
|
||||||
@ -14,7 +13,7 @@ ZeroDevice::~ZeroDevice()
|
|||||||
|
|
||||||
Unix::ssize_t ZeroDevice::read(byte* buffer, Unix::size_t bufferSize)
|
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);
|
Unix::size_t count = min(GoodBufferSize, bufferSize);
|
||||||
memset(buffer, 0, count);
|
memset(buffer, 0, count);
|
||||||
return count;
|
return count;
|
||||||
|
Loading…
Reference in New Issue
Block a user