diff --git a/AK/StdLib.h b/AK/StdLib.h index a5046e530f..20d32e8139 100644 --- a/AK/StdLib.h +++ b/AK/StdLib.h @@ -55,6 +55,13 @@ T exchange(T& a, U&& b) return tmp; } +template +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; diff --git a/AK/kstdio.h b/AK/kstdio.h new file mode 100644 index 0000000000..6f7c887e66 --- /dev/null +++ b/AK/kstdio.h @@ -0,0 +1,8 @@ +#pragma once + +#ifdef SERENITY_KERNEL +#include +#else +#include +#define kprintf printf +#endif diff --git a/Kernel/IPC.h b/Kernel/IPC.h index 100714ceb0..a15a406eff 100644 --- a/Kernel/IPC.h +++ b/Kernel/IPC.h @@ -3,6 +3,7 @@ #include "types.h" #include "DataBuffer.h" #include "RefPtr.h" +#include /* IPC message types. There will be moar. */ #define MSG_INTERRUPT 0x00000001 diff --git a/Kernel/Makefile b/Kernel/Makefile index 856284a36d..93a28f5515 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -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) diff --git a/Kernel/String.cpp b/Kernel/String.cpp index 6b155cbea7..e8a199226f 100644 --- a/Kernel/String.cpp +++ b/Kernel/String.cpp @@ -1,5 +1,5 @@ #include "String.h" -#include "StdLib.h" +#include String::String() { diff --git a/Kernel/init.cpp b/Kernel/init.cpp index f5ba6fdee4..bd3aee7755 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -15,6 +15,11 @@ #include "FileSystem.h" #include "Userspace.h" #include "IDEDiskDevice.h" +#include +#include +#include +#include +#include #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(); + auto dev_full = make(); + auto dev_zero = make(); + auto dev_random = make(); // new Task(motd_main, "motd", IPC::Handle::MotdTask, Task::Ring0); new Task(user_main, "user", IPC::Handle::UserTask, Task::Ring3); diff --git a/Kernel/kstdio.h b/Kernel/kstdio.h new file mode 100644 index 0000000000..8bf872581c --- /dev/null +++ b/Kernel/kstdio.h @@ -0,0 +1,3 @@ +#pragma once + +#include "VGA.h" diff --git a/Kernel/types.h b/Kernel/types.h index b69b2af662..5c1f35d66d 100644 --- a/Kernel/types.h +++ b/Kernel/types.h @@ -6,48 +6,6 @@ #define PUBLIC #define PRIVATE static -template -T&& move(T& arg) -{ - return static_cast(arg); -} - -template -T min(T a, T b) -{ - return (a < b) ? a : b; -} - -template -T max(T a, T b) -{ - return (a > b) ? a : b; -} - -template -void swap(T& a, U& b) -{ - U tmp = move((U&)a); - a = (T&&)move(b); - b = move(tmp); -} - -template -struct identity { - typedef T type; -}; -template -T&& forward(typename identity::type&& param) -{ return static_cast::type&&>(param); } - -template -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; diff --git a/VirtualFileSystem/FullDevice.cpp b/VirtualFileSystem/FullDevice.cpp index 28e0325c12..aa0a4a55ed 100644 --- a/VirtualFileSystem/FullDevice.cpp +++ b/VirtualFileSystem/FullDevice.cpp @@ -2,8 +2,7 @@ #include "Limits.h" #include "sys-errno.h" #include -#include -#include +#include 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; diff --git a/VirtualFileSystem/Limits.h b/VirtualFileSystem/Limits.h index a2a9227455..763e4c2c96 100644 --- a/VirtualFileSystem/Limits.h +++ b/VirtualFileSystem/Limits.h @@ -1,9 +1,14 @@ #pragma once -#include #include "UnixTypes.h" +#ifdef SERENITY_KERNEL +inline static const Unix::off_t maxFileOffset = 9223372036854775807LL; +#else +#include +inline static const Unix::off_t maxFileOffset = std::numeric_limits::max(); +#endif + static const Unix::size_t GoodBufferSize = 4096; -inline static const Unix::off_t maxFileOffset = std::numeric_limits::max(); diff --git a/VirtualFileSystem/NullDevice.cpp b/VirtualFileSystem/NullDevice.cpp index 6df9fc0b51..4636c8cfdc 100644 --- a/VirtualFileSystem/NullDevice.cpp +++ b/VirtualFileSystem/NullDevice.cpp @@ -1,8 +1,7 @@ #include "NullDevice.h" #include "Limits.h" #include -#include -#include +#include 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; } diff --git a/VirtualFileSystem/RandomDevice.cpp b/VirtualFileSystem/RandomDevice.cpp index a47dc246dc..4ef3064d10 100644 --- a/VirtualFileSystem/RandomDevice.cpp +++ b/VirtualFileSystem/RandomDevice.cpp @@ -1,8 +1,6 @@ #include "RandomDevice.h" #include "Limits.h" #include -#include -#include 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) { diff --git a/VirtualFileSystem/ZeroDevice.cpp b/VirtualFileSystem/ZeroDevice.cpp index 9a7685201f..cdb168a763 100644 --- a/VirtualFileSystem/ZeroDevice.cpp +++ b/VirtualFileSystem/ZeroDevice.cpp @@ -1,8 +1,7 @@ #include "ZeroDevice.h" #include "Limits.h" #include -#include -#include +#include 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;