summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Bochs.cfg1
-rw-r--r--HDD.imgbin0 -> 20643840 bytes
-rw-r--r--Source/Kernel/Devices/Floppy/FloppyController.class.cpp14
-rw-r--r--Source/Kernel/Devices/Floppy/FloppyController.class.h6
-rw-r--r--Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp28
-rw-r--r--Source/Kernel/FileSystems/FAT/FATFS.class.cpp4
-rw-r--r--Source/Kernel/Shell/KernelShell-fs.class.cpp18
-rw-r--r--Source/Kernel/Shell/KernelShell.class.cpp1
-rw-r--r--Source/Kernel/Shell/KernelShell.class.h1
9 files changed, 54 insertions, 19 deletions
diff --git a/Bochs.cfg b/Bochs.cfg
index 88d2d0f..2a1bf42 100644
--- a/Bochs.cfg
+++ b/Bochs.cfg
@@ -12,6 +12,7 @@ ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata2: enabled=0
ata3: enabled=0
+ata0-master: type=disk, path="HDD.img", mode=flat, cylinders=40, heads=16, spt=63
parport1: enabled=1, file=""
parport2: enabled=0
com1: enabled=1, mode=null, dev=""
diff --git a/HDD.img b/HDD.img
new file mode 100644
index 0000000..b3dcc9d
--- /dev/null
+++ b/HDD.img
Binary files differ
diff --git a/Source/Kernel/Devices/Floppy/FloppyController.class.cpp b/Source/Kernel/Devices/Floppy/FloppyController.class.cpp
index 146ce28..db148d0 100644
--- a/Source/Kernel/Devices/Floppy/FloppyController.class.cpp
+++ b/Source/Kernel/Devices/Floppy/FloppyController.class.cpp
@@ -96,6 +96,7 @@ FloppyController::FloppyController(u32int base, u8int irq) : m_driveMutex(false)
m_drives[0] = NULL;
m_drives[1] = NULL;
m_first = false;
+ Dev::requestIRQ(this, m_irq);
}
void FloppyController::detect() { //TODO : do this better
@@ -144,15 +145,14 @@ void FloppyController::setDOR() {
dor |= 0x10;
if (m_drives[1] != NULL and m_drives[1]->m_motorState != 0)
dor |= 0x20;
- asm volatile ("cli");
+ resetIrq();
outb(m_base + FR_DOR, dor);
if (m_first) { //First time we set the DOR, controller initialized
- Task::currThread()->waitIRQ(m_irq);
+ waitIrq();
int st0, cyl;
checkInterrupt(&st0, &cyl);
m_first = false;
}
- asm volatile ("sti");
//PANIC("test");
}
@@ -203,3 +203,11 @@ bool FloppyController::reset() {
}
return true;
}
+
+void FloppyController::handleIRQ(registers_t regs, int irq) {
+ m_irqHappened = true;
+}
+
+void FloppyController::waitIrq() {
+ while (!m_irqHappened) Task::currThread()->sleep(10);
+}
diff --git a/Source/Kernel/Devices/Floppy/FloppyController.class.h b/Source/Kernel/Devices/Floppy/FloppyController.class.h
index a27d853..f0a7c10 100644
--- a/Source/Kernel/Devices/Floppy/FloppyController.class.h
+++ b/Source/Kernel/Devices/Floppy/FloppyController.class.h
@@ -60,6 +60,8 @@ class FloppyController : public Device {
bool m_first;
+ bool m_irqHappened;
+
FloppyDrive* m_drives[2];
void checkInterrupt(int *st0, int *cyl);
@@ -69,6 +71,10 @@ class FloppyController : public Device {
bool writeCmd(u8int cmd); //Sends command to controller
u8int readData(); //Reads a byte from controller
bool reset();
+
+ void handleIRQ(registers_t regs, int irq);
+ void resetIrq() { m_irqHappened = false; }
+ void waitIrq();
public:
static void detect();
diff --git a/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp b/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp
index 9335cb7..23d007c 100644
--- a/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp
+++ b/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp
@@ -95,13 +95,12 @@ bool FloppyDrive::calibrate() {
if (!setMotorState(true)) return false;
for (int i = 0; i < 10; i++) {
- asm volatile("cli");
+ m_fdc->resetIrq();
m_fdc->writeCmd(FC_RECALIBRATE);
m_fdc->writeCmd(m_driveNumber);
- Task::currThread()->waitIRQ(m_fdc->m_irq);
+ m_fdc->waitIrq();
m_fdc->checkInterrupt(&st0, &cyl);
- asm volatile("sti");
if (st0 & 0xC0) {
continue;
@@ -112,6 +111,7 @@ bool FloppyDrive::calibrate() {
}
}
setMotorState(false);
+ *kvt << getName() << ": calibrate fail\n";
return false;
}
@@ -146,27 +146,29 @@ bool FloppyDrive::seek(u32int cyli, s32int head) {
int st0, cyl = -1;
- for (u32int i = 0; i < 5; i++) {
- asm volatile ("cli");
+ for (u32int i = 0; i < 10; i++) {
+ m_fdc->resetIrq();
m_fdc->writeCmd(FC_SEEK);
m_fdc->writeCmd(head << 2);
m_fdc->writeCmd(cyl);
- Task::currThread()->waitIRQ(m_fdc->m_irq);
+ m_fdc->waitIrq();
m_fdc->checkInterrupt(&st0, &cyl);
- asm volatile("sti");
if (st0 & 0xC0) { //Error
+ Task::currThread()->sleep(10);
continue;
}
- if (cyl == 0xFF or cyl == 0x00 or cyl == 0x01 or cyl == (int)cyli) { //0xFF for bochs, 0x00 for qemu :D
+ if (cyl == 0xFF or cyl == 0x00 or cyl == (int)cyli) { //0xFF for bochs, 0x00 for qemu :D
setMotorState(false);
m_fdc->setNoActiveDrive();
return true;
}
+ Task::currThread()->sleep(10);
}
setMotorState(false);
m_fdc->setNoActiveDrive();
+ *kvt << getName() << ": seek fail\n";
return false;
}
@@ -199,7 +201,7 @@ bool FloppyDrive::doTrack(u32int cyl, u8int dir) {
Task::currThread()->sleep(100);
- asm volatile("cli");
+ m_fdc->resetIrq();
m_fdc->writeCmd(cmd);
m_fdc->writeCmd(m_driveNumber); //Drive number & first head << 2
m_fdc->writeCmd(cyl); //Cylinder
@@ -210,7 +212,7 @@ bool FloppyDrive::doTrack(u32int cyl, u8int dir) {
m_fdc->writeCmd(0x1B);
m_fdc->writeCmd(0xFF);
- Task::currThread()->waitIRQ(m_fdc->m_irq);
+ m_fdc->waitIrq();
u8int st0, st1, st2, rcy, rhe, rse, bps;
st0 = m_fdc->readData();
@@ -220,7 +222,6 @@ bool FloppyDrive::doTrack(u32int cyl, u8int dir) {
rhe = m_fdc->readData();
rse = m_fdc->readData();
bps = m_fdc->readData();
- asm volatile("sti");
int error = 0;
@@ -270,12 +271,11 @@ bool FloppyDrive::doTrack(u32int cyl, u8int dir) {
bool FloppyDrive::readOnly() {
m_fdc->setActiveDrive(m_driveNumber);
- asm volatile("cli");
+ m_fdc->resetIrq();
m_fdc->writeCmd(FC_SENSE_DRIVE_STATUS);
m_fdc->writeCmd(m_driveNumber);
- Task::currThread()->waitIRQ(m_fdc->m_irq);
+ m_fdc->waitIrq();
u8int st3 = m_fdc->readData();
- asm volatile("sti");
bool ret = (st3 & 0x80 ? true : false);
diff --git a/Source/Kernel/FileSystems/FAT/FATFS.class.cpp b/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
index 67b4013..4c662de 100644
--- a/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
+++ b/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
@@ -136,8 +136,8 @@ u32int FATFS::read(FileNode* file, u64int position, u32int max_length, u8int *da
//Read first cluster
u8int* temp = (u8int*)Mem::alloc(m_clusterSize);
readCluster(clust, temp);
- memcpy(data, temp + clusterOffset, (m_clusterSize - clusterOffset));
- //Read next clusters
+ memcpy(data, temp + clusterOffset, (len > m_clusterSize - clusterOffset ? m_clusterSize - clusterOffset : len));
+ //Read next cluster
u32int pos = (m_clusterSize - clusterOffset);
for (u32int i = 1; i < clusters; i++) {
clust = nextCluster(clust);
diff --git a/Source/Kernel/Shell/KernelShell-fs.class.cpp b/Source/Kernel/Shell/KernelShell-fs.class.cpp
index fa2078d..c389d45 100644
--- a/Source/Kernel/Shell/KernelShell-fs.class.cpp
+++ b/Source/Kernel/Shell/KernelShell-fs.class.cpp
@@ -125,3 +125,21 @@ void KernelShell::run(Vector<String>& args) {
}
}
}
+
+void KernelShell::hexdump(Vector<String>& args) {
+ if (args.size() == 1) {
+ *m_vt << "No file to hexdump.\n";
+ } else {
+ for (u32int i = 1; i < args.size(); i++) {
+ File f(args[i], FM_READ, m_cwd);
+ if (f.valid()) {
+ u8int *buff = (u8int*)Mem::alloc(f.length());
+ f.read(f.length(), buff);
+ m_vt->hexDump(buff, f.length());
+ Mem::free(buff);
+ } else {
+ *m_vt << "Error reading from file " << args[i] << "\n";
+ }
+ }
+ }
+}
diff --git a/Source/Kernel/Shell/KernelShell.class.cpp b/Source/Kernel/Shell/KernelShell.class.cpp
index 9f9858b..f35b4dc 100644
--- a/Source/Kernel/Shell/KernelShell.class.cpp
+++ b/Source/Kernel/Shell/KernelShell.class.cpp
@@ -62,6 +62,7 @@ u32int KernelShell::run() {
{"uptime", &KernelShell::uptime},
{"part", &KernelShell::part},
{"readblock", &KernelShell::readblock},
+ {"hexdump", &KernelShell::hexdump},
{0, 0}
};
diff --git a/Source/Kernel/Shell/KernelShell.class.h b/Source/Kernel/Shell/KernelShell.class.h
index 4fa9c66..d3fd5e1 100644
--- a/Source/Kernel/Shell/KernelShell.class.h
+++ b/Source/Kernel/Shell/KernelShell.class.h
@@ -27,6 +27,7 @@ class KernelShell {
void rm(Vector<String>& args);
void wf(Vector<String>& args);
void run(Vector<String>& args);
+ void hexdump(Vector<String>& args);
//in KernelShell-sys
void devices(Vector<String>& args);