From f3ffe96d679742af95afa29e0cf612c6935eedd0 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Tue, 24 Nov 2009 14:29:29 +0100 Subject: Reading from floppys supposedly fixed in qemu --- Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp | 19 ++++++------------- Source/Kernel/Linker/ElfBinary.class.cpp | 2 +- Source/Kernel/Linker/MelonBinary.class.cpp | 2 +- Source/Kernel/Shell/KernelShell-sys.class.cpp | 19 +++++++++++++++++++ Source/Kernel/Shell/KernelShell.class.cpp | 1 + Source/Kernel/Shell/KernelShell.class.h | 1 + 6 files changed, 29 insertions(+), 15 deletions(-) (limited to 'Source') diff --git a/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp b/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp index 7edf24a..9335cb7 100644 --- a/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp +++ b/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp @@ -2,6 +2,7 @@ #include "FloppyController.class.h" #include #include +#include #include using namespace Sys; @@ -145,7 +146,7 @@ bool FloppyDrive::seek(u32int cyli, s32int head) { int st0, cyl = -1; - for (u32int i = 0; i < 10; i++) { + for (u32int i = 0; i < 5; i++) { asm volatile ("cli"); m_fdc->writeCmd(FC_SEEK); m_fdc->writeCmd(head << 2); @@ -158,12 +159,7 @@ bool FloppyDrive::seek(u32int cyli, s32int head) { if (st0 & 0xC0) { //Error continue; } - if (cyl == 0xFF or cyl == 0x00) { //0xFF for bochs, 0x00 for qemu :D - setMotorState(false); - m_fdc->setNoActiveDrive(); - return true; - } - if (cyl == (int)cyli) { + if (cyl == 0xFF or cyl == 0x00 or cyl == 0x01 or cyl == (int)cyli) { //0xFF for bochs, 0x00 for qemu :D setMotorState(false); m_fdc->setNoActiveDrive(); return true; @@ -296,16 +292,13 @@ bool FloppyDrive::readBlocks(u64int start, u32int count, u8int *data) { u32int startblock = start; if (count == 1) { u32int cylinder = (startblock / (m_sectors * 2)), offset = (startblock % (m_sectors * 2)) * 512; - if (m_buffCyl == cylinder && m_buffTime >= Time::uptime() - 4) { - memcpy(data, (const u8int*)(&m_buffer[offset]), 512); - return true; - } else { + if (m_buffCyl != cylinder or m_buffTime < Time::uptime() - 4) { if (!doTrack(cylinder, FD_READ)) return false; m_buffCyl = cylinder; m_buffTime = Time::uptime(); - memcpy(data, (const u8int*)(&m_buffer[offset]), 512); - return true; } + memcpy(data, (const u8int*)(&m_buffer[offset]), 512); + return true; } else { m_buffCyl = 0xFFFF; //Invalid cylinder m_buffTime = 0; diff --git a/Source/Kernel/Linker/ElfBinary.class.cpp b/Source/Kernel/Linker/ElfBinary.class.cpp index 27e5474..0518c38 100644 --- a/Source/Kernel/Linker/ElfBinary.class.cpp +++ b/Source/Kernel/Linker/ElfBinary.class.cpp @@ -9,7 +9,7 @@ ElfBinary::~ElfBinary() { Binary* ElfBinary::load(File& file) { elf_ehdr_t hdr; - file.read (&hdr); + if (!file.read (&hdr)) return 0; //Verify we have an elf file if (hdr.e_ident[0] != 0x7F or hdr.e_ident[1] != 'E' or hdr.e_ident[2] != 'L' or hdr.e_ident[3] != 'F') return 0; diff --git a/Source/Kernel/Linker/MelonBinary.class.cpp b/Source/Kernel/Linker/MelonBinary.class.cpp index 0737b71..8a85977 100644 --- a/Source/Kernel/Linker/MelonBinary.class.cpp +++ b/Source/Kernel/Linker/MelonBinary.class.cpp @@ -2,7 +2,7 @@ Binary* MelonBinary::load(File& file) { u32int magic; - file.read(&magic); + if (!file.read(&magic)) return 0; if (magic == 0xFEEDBEEF) { MelonBinary* r = new MelonBinary; file.read(&r->m_size); diff --git a/Source/Kernel/Shell/KernelShell-sys.class.cpp b/Source/Kernel/Shell/KernelShell-sys.class.cpp index 6243b0f..b039c4d 100644 --- a/Source/Kernel/Shell/KernelShell-sys.class.cpp +++ b/Source/Kernel/Shell/KernelShell-sys.class.cpp @@ -58,3 +58,22 @@ void KernelShell::part(Vector& args) { } } } + +void KernelShell::readblock(Vector& args) { + if (args.size() == 3) { + Vector devcs = Dev::findDevices("block"); + u32int id = args[1].toInt(), block = args[2].toInt(); + if (id < devcs.size()) { + BlockDevice* bdev = (BlockDevice*)devcs[id]; + *m_vt << "Block " << block << " from device " << bdev->getName() << " (" << bdev->getClass() << ")\n"; + u8int* buff = (u8int*)Mem::alloc(bdev->blockSize()); + bdev->readBlocks(block, 1, buff); + m_vt->hexDump(buff, 32); + Mem::free(buff); + } else { + *m_vt << "Block device #" << id << " does not exist.\n"; + } + } else { + *m_vt << "Usage: readblock \n"; + } +} diff --git a/Source/Kernel/Shell/KernelShell.class.cpp b/Source/Kernel/Shell/KernelShell.class.cpp index 7f57f8b..9f9858b 100644 --- a/Source/Kernel/Shell/KernelShell.class.cpp +++ b/Source/Kernel/Shell/KernelShell.class.cpp @@ -61,6 +61,7 @@ u32int KernelShell::run() { {"free", &KernelShell::free}, {"uptime", &KernelShell::uptime}, {"part", &KernelShell::part}, + {"readblock", &KernelShell::readblock}, {0, 0} }; diff --git a/Source/Kernel/Shell/KernelShell.class.h b/Source/Kernel/Shell/KernelShell.class.h index e7549c2..4fa9c66 100644 --- a/Source/Kernel/Shell/KernelShell.class.h +++ b/Source/Kernel/Shell/KernelShell.class.h @@ -34,6 +34,7 @@ class KernelShell { void free(Vector& args); void uptime(Vector& args); void part(Vector& args); + void readblock(Vector& args); void setup(DirectoryNode* cwd, VirtualTerminal *vt); -- cgit v1.2.3