Add a simple IDEDiskDevice class that implements DiskDevice from VFS.

This commit is contained in:
Andreas Kling 2018-10-16 14:17:43 +02:00
parent 8293a0ff36
commit 12e515735b
Notes: sideshowbarker 2024-07-19 18:47:19 +09:00
6 changed files with 88 additions and 11 deletions

View file

@ -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"

41
Kernel/IDEDiskDevice.cpp Normal file
View file

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

21
Kernel/IDEDiskDevice.h Normal file
View file

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

View file

@ -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++

View file

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

8
Kernel/kassert.h Normal file
View file

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