summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-10-16 14:17:43 +0200
committerAndreas Kling <awesomekling@gmail.com>2018-10-16 14:17:43 +0200
commit12e515735b94972c87426d8e6039e3dfd87cf33d (patch)
treeb9791d0fd2754b498ec94d279276bf429bc7cc03 /Kernel
parent8293a0ff36859aafb2b95835a6c2651659fa3ab9 (diff)
downloadserenity-12e515735b94972c87426d8e6039e3dfd87cf33d.zip
Add a simple IDEDiskDevice class that implements DiskDevice from VFS.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Assertions.h8
-rw-r--r--Kernel/IDEDiskDevice.cpp41
-rw-r--r--Kernel/IDEDiskDevice.h21
-rw-r--r--Kernel/Makefile18
-rw-r--r--Kernel/init.cpp3
-rw-r--r--Kernel/kassert.h8
6 files changed, 88 insertions, 11 deletions
diff --git a/Kernel/Assertions.h b/Kernel/Assertions.h
index 97c2c0a0b3..29eb1b7b34 100644
--- a/Kernel/Assertions.h
+++ b/Kernel/Assertions.h
@@ -1,8 +1,2 @@
#pragma once
-
-#include "VGA.h"
-
-#define CRASH() do { asm volatile("cli;hlt"); } while(0)
-#define ASSERT(x) do { if (!(x)) { vga_set_attr(0x4f); kprintf("ASSERTION FAILED: " #x "\n%s:%u in %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); CRASH(); } } while(0)
-#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0)
-#define ASSERT_NOT_REACHED() ASSERT(false)
+#include "kassert.h"
diff --git a/Kernel/IDEDiskDevice.cpp b/Kernel/IDEDiskDevice.cpp
new file mode 100644
index 0000000000..0ad82540ca
--- /dev/null
+++ b/Kernel/IDEDiskDevice.cpp
@@ -0,0 +1,41 @@
+#include "IDEDiskDevice.h"
+#include "Disk.h"
+
+RetainPtr<IDEDiskDevice> IDEDiskDevice::create()
+{
+ return adopt(*new IDEDiskDevice);
+}
+
+IDEDiskDevice::IDEDiskDevice()
+{
+}
+
+IDEDiskDevice::~IDEDiskDevice()
+{
+}
+
+const char* IDEDiskDevice::className() const
+{
+ return "IDEDiskDevice";
+}
+
+unsigned IDEDiskDevice::blockSize() const
+{
+ return 512;
+}
+
+bool IDEDiskDevice::readBlock(unsigned index, byte* out) const
+{
+ Disk::readSectors(index, 1, out);
+ return true;
+}
+
+bool IDEDiskDevice::writeBlock(unsigned index, const byte* data)
+{
+ (void) index;
+ (void) data;
+ kprintf("[IDEDiskDevice] writeBlock not implemented()\n");
+ notImplemented();
+ return false;
+}
+
diff --git a/Kernel/IDEDiskDevice.h b/Kernel/IDEDiskDevice.h
new file mode 100644
index 0000000000..efa9db087b
--- /dev/null
+++ b/Kernel/IDEDiskDevice.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <AK/RetainPtr.h>
+#include <VirtualFileSystem/DiskDevice.h>
+
+class IDEDiskDevice final : public DiskDevice {
+public:
+ static RetainPtr<IDEDiskDevice> create();
+ virtual ~IDEDiskDevice();
+
+ virtual unsigned blockSize() const override;
+ virtual bool readBlock(unsigned index, byte*) const override;
+ virtual bool writeBlock(unsigned index, const byte*) override;
+
+protected:
+ IDEDiskDevice();
+
+private:
+ virtual const char* className() const override;
+};
+
diff --git a/Kernel/Makefile b/Kernel/Makefile
index ad506f2f19..856284a36d 100644
--- a/Kernel/Makefile
+++ b/Kernel/Makefile
@@ -1,4 +1,4 @@
-OBJS = \
+KERNEL_OBJS = \
_start.o \
init.o \
VGA.o \
@@ -18,7 +18,14 @@ OBJS = \
panel.o \
Disk.o \
fs.o \
- Userspace.o
+ Userspace.o \
+ IDEDiskDevice.o
+
+VFS_OBJS = \
+ ../VirtualFileSystem/DiskDevice.o
+
+OBJS = $(KERNEL_OBJS) $(VFS_OBJS)
+
NASM = nasm
KERNEL = kernel
BOOTLOADER = Boot/boot.bin
@@ -30,8 +37,11 @@ WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -falign-functions=1 -falign-jumps=1 -falign-loops=1
#FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections
OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables
-INCLUDE_FLAGS = -Iinclude/ -I.
-CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(KERNEL_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS)
+INCLUDE_FLAGS = -I.. -I.
+
+DEFINES = -DSERENITY_KERNEL -DSANITIZE_PTRS
+
+CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(KERNEL_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
#CXX = /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-g++
#LD = /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-ld
CXX = g++
diff --git a/Kernel/init.cpp b/Kernel/init.cpp
index 746467e08a..f5ba6fdee4 100644
--- a/Kernel/init.cpp
+++ b/Kernel/init.cpp
@@ -14,6 +14,7 @@
#include "CMOS.h"
#include "FileSystem.h"
#include "Userspace.h"
+#include "IDEDiskDevice.h"
#if 0
/* Keyboard LED disco task ;^) */
@@ -123,6 +124,8 @@ void init()
Disk::initialize();
FileSystem::initialize();
+ auto hd0 = IDEDiskDevice::create();
+
// new Task(motd_main, "motd", IPC::Handle::MotdTask, Task::Ring0);
new Task(user_main, "user", IPC::Handle::UserTask, Task::Ring3);
diff --git a/Kernel/kassert.h b/Kernel/kassert.h
new file mode 100644
index 0000000000..97c2c0a0b3
--- /dev/null
+++ b/Kernel/kassert.h
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "VGA.h"
+
+#define CRASH() do { asm volatile("cli;hlt"); } while(0)
+#define ASSERT(x) do { if (!(x)) { vga_set_attr(0x4f); kprintf("ASSERTION FAILED: " #x "\n%s:%u in %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); CRASH(); } } while(0)
+#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0)
+#define ASSERT_NOT_REACHED() ASSERT(false)