summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-24 14:29:29 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-24 14:29:29 +0100
commitf3ffe96d679742af95afa29e0cf612c6935eedd0 (patch)
tree94b401da87240ab83216a6a147ff99df6aef8d5d
parent0f536540de15202d44cd9b1d708ee04edccb8c66 (diff)
downloadMelon-f3ffe96d679742af95afa29e0cf612c6935eedd0.tar.gz
Melon-f3ffe96d679742af95afa29e0cf612c6935eedd0.zip
Reading from floppys supposedly fixed in qemu
-rw-r--r--Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp19
-rw-r--r--Source/Kernel/Linker/ElfBinary.class.cpp2
-rw-r--r--Source/Kernel/Linker/MelonBinary.class.cpp2
-rw-r--r--Source/Kernel/Shell/KernelShell-sys.class.cpp19
-rw-r--r--Source/Kernel/Shell/KernelShell.class.cpp1
-rw-r--r--Source/Kernel/Shell/KernelShell.class.h1
6 files changed, 29 insertions, 15 deletions
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 <TaskManager/Task.ns.h>
#include <DeviceManager/Time.ns.h>
+#include <VTManager/SimpleVT.class.h>
#include <Core/Log.ns.h>
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<elf_ehdr_t> (&hdr);
+ if (!file.read<elf_ehdr_t> (&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<u32int>(&magic);
+ if (!file.read<u32int>(&magic)) return 0;
if (magic == 0xFEEDBEEF) {
MelonBinary* r = new MelonBinary;
file.read<u32int>(&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<String>& args) {
}
}
}
+
+void KernelShell::readblock(Vector<String>& args) {
+ if (args.size() == 3) {
+ Vector<Device*> 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 <dev id> <block id>\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<String>& args);
void uptime(Vector<String>& args);
void part(Vector<String>& args);
+ void readblock(Vector<String>& args);
void setup(DirectoryNode* cwd, VirtualTerminal *vt);