Sfoglia il codice sorgente

Add a simple IDEDiskDevice class that implements DiskDevice from VFS.

Andreas Kling 6 anni fa
parent
commit
12e515735b
6 ha cambiato i file con 88 aggiunte e 11 eliminazioni
  1. 1 7
      Kernel/Assertions.h
  2. 41 0
      Kernel/IDEDiskDevice.cpp
  3. 21 0
      Kernel/IDEDiskDevice.h
  4. 14 4
      Kernel/Makefile
  5. 3 0
      Kernel/init.cpp
  6. 8 0
      Kernel/kassert.h

+ 1 - 7
Kernel/Assertions.h

@@ -1,8 +1,2 @@
 #pragma once
 #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 - 0
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;
+}
+

+ 21 - 0
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;
+};
+

+ 14 - 4
Kernel/Makefile

@@ -1,4 +1,4 @@
-OBJS = \
+KERNEL_OBJS = \
        _start.o \
        _start.o \
        init.o \
        init.o \
        VGA.o \
        VGA.o \
@@ -18,7 +18,14 @@ OBJS = \
        panel.o \
        panel.o \
        Disk.o \
        Disk.o \
        fs.o \
        fs.o \
-       Userspace.o
+       Userspace.o \
+       IDEDiskDevice.o
+
+VFS_OBJS = \
+    ../VirtualFileSystem/DiskDevice.o
+
+OBJS = $(KERNEL_OBJS) $(VFS_OBJS)
+
 NASM = nasm
 NASM = nasm
 KERNEL = kernel
 KERNEL = kernel
 BOOTLOADER = Boot/boot.bin
 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 -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
 #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
 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++
 #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
 #LD = /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-ld
 CXX = g++
 CXX = g++

+ 3 - 0
Kernel/init.cpp

@@ -14,6 +14,7 @@
 #include "CMOS.h"
 #include "CMOS.h"
 #include "FileSystem.h"
 #include "FileSystem.h"
 #include "Userspace.h"
 #include "Userspace.h"
+#include "IDEDiskDevice.h"
 
 
 #if 0
 #if 0
 /* Keyboard LED disco task ;^) */
 /* Keyboard LED disco task ;^) */
@@ -123,6 +124,8 @@ void init()
     Disk::initialize();
     Disk::initialize();
     FileSystem::initialize();
     FileSystem::initialize();
 
 
+    auto hd0 = IDEDiskDevice::create();
+
 //    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);
 
 

+ 8 - 0
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)