summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile2
-rw-r--r--README.md30
-rw-r--r--bochsrc4
-rw-r--r--boot/mbr.asm2
-rw-r--r--kernel/floppy.c104
-rw-r--r--kernel/interrupts.c1
-rw-r--r--kernel/kernel.c2
-rw-r--r--kernel/x86.h4
9 files changed, 114 insertions, 36 deletions
diff --git a/.gitignore b/.gitignore
index 1377554..6fb6e12 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
*.swp
+xxx/
diff --git a/Makefile b/Makefile
index 125d957..9cea089 100644
--- a/Makefile
+++ b/Makefile
@@ -78,6 +78,6 @@ run: FoolOS.img
bochs
clean:
- -rm *.bin *.o *.img dump.elf dump.xxd
+ -rm *.bin *.o *.img dump.elf dump.xxd bochs.log
.PHONY: all clean
diff --git a/README.md b/README.md
index 62a6560..0ee580e 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,36 @@ Issues
* redesign command handling (not inside the interrupt!!!)
* implement a real shell (in user mode)
+
+MEMORY LAYOUT
+=============
+
+FLOPPY IMAGE
+------------
+0x0000 - MASTER BOOT RECORD
+0x0200 - kernel image (contains sotrage for interrupt desc. table)
+0x8000 - file system will go here
+
+RAM
+---
+0x1000
+ boot loader puts the kernel here.
+
+0x7c00
+ first stage boot loader (loaded by bios) boot/mbr.asm
+ includes initial Global Descriptor Table!
+
+0x7c00 + 3
+ boot loader puts number of boot floppy disk here.
+
+0x7c00 + 0x140
+ the boot loader puts the memory map obtained from the
+ bios here before switching to protected mode.
+
+0xb000
+ memory above this is used for dma (by our floppy.c driver)
+
+
REFERENCES
==========
diff --git a/bochsrc b/bochsrc
index 17ddec3..d733635 100644
--- a/bochsrc
+++ b/bochsrc
@@ -451,8 +451,7 @@ floppy_bootsig_check: disabled=0
# log: /dev/tty
#=======================================================================
log: /dev/stdout
-#log: /dev/null
-#log: /tmp/bochsout.txt
+log: ./bochs.log
#=======================================================================
# LOGPREFIX:
@@ -496,6 +495,7 @@ panic: action=ask
error: action=ask
info: action=report
debug: action=ignore
+#debug: action=report
#pass: action=fatal
#=======================================================================
diff --git a/boot/mbr.asm b/boot/mbr.asm
index 2d87c20..3406b55 100644
--- a/boot/mbr.asm
+++ b/boot/mbr.asm
@@ -26,7 +26,7 @@ KERNEL_OFFSET equ 0x1000
jmp boot_16 ;start boot process
BOOT_DRIVE:
- db 0
+ db 0xff
;SOME Global Data, mainly strings
STR_VERSION:
diff --git a/kernel/floppy.c b/kernel/floppy.c
index 2c71cdb..a3c1c2a 100644
--- a/kernel/floppy.c
+++ b/kernel/floppy.c
@@ -1,3 +1,22 @@
+/*
+ * Fool OS Simple Floppy Driver.
+ *
+ * coded by M.idziorek <m.i@gmx.at> on 20th of august 2014 A.D
+ *
+ * tested in : bochs, qemu and virutalbox so far
+ *
+ * resources:
+ *
+ * * http://wiki.osdev.org/Floppy_Disk_Controller#DMA_Data_Transfers
+ * * http://forum.osdev.org/viewtopic.php?f=1&t=13538
+ * * http://www.brokenthorn.com/Resources/OSDev20.html
+ * * http://bochs.sourceforge.net/cgi-bin/lxr/source/iodev/floppy.cc
+ *
+ *
+ *
+ *
+ *
+ */
#include "x86.h"
#define FLPY_SECTORS_PER_TRACK 80
@@ -14,7 +33,7 @@ void flpydsk_initialize_dma () {
//changed to 0x000 (Address)
x86_outb (0x04, 0x0); //low
- x86_outb (0x04, 0xa0); //high
+ x86_outb (0x04, 0xb0); //high
x86_outb (0xd8, 0xff); //reset master flip-flop
x86_outb (0x05, 0xff); //count to 0x23ff (number of bytes in a 3.5" floppy disk track)
@@ -140,14 +159,16 @@ void sleep(int i)
void flpydsk_motor_on()
{
scr_put_string("floppy: starting motor...");
- x86_outb (FLPYDSK_DOR, FLPYDSK_DOR_MASK_DRIVE0_MOTOR | FLPYDSK_DOR_MASK_RESET);
+ //x86_outb (FLPYDSK_DOR, FLPYDSK_DOR_MASK_DRIVE0_MOTOR | FLPYDSK_DOR_MASK_RESET);
+ x86_outb (FLPYDSK_DOR, 0x1c);
sleep(20);
scr_put_string_nl("ok");
}
void flpydsk_motor_off()
{
scr_put_string("floppy: stopping motor...");
- x86_outb (FLPYDSK_DOR,FLPYDSK_DOR_MASK_RESET);
+ x86_outb (FLPYDSK_DOR, 0x0c);
+ //x86_outb (FLPYDSK_DOR,FLPYDSK_DOR_MASK_RESET);
scr_put_string_nl("ok");
}
@@ -177,12 +198,15 @@ int flpydsk_calibrate (uint32_t drive) {
//! did we fine cylinder 0? if so, we are done
if (!cyl) {
-
+ if(st0 & 0xC0) {
+ scr_put_string_nl("floppy: calibration FAILED!");
+ }
// flpydsk_control_motor (false);
flpydsk_motor_off();
return 0;
}
}
+ scr_put_string_nl("floppy: calibration FAILED!");
// flpydsk_control_motor (false);
flpydsk_motor_off();
@@ -215,6 +239,8 @@ uint8_t flpydsk_read_data () {
for (i = 0; i < 500; i++ )
if ( flpydsk_read_status () & FLPYDSK_MSR_MASK_DATAREG )
return x86_inb (FLPYDSK_FIFO);
+
+ scr_put_string_nl("floppy: read data fail!");
}
void flpydsk_send_command (uint8_t cmd) {
@@ -226,9 +252,10 @@ void flpydsk_send_command (uint8_t cmd) {
x86_outb(FLPYDSK_FIFO, cmd);
return;
}
+ scr_put_string_nl("floppy: write data fail!");
}
-void flpydsk_drive_data (uint32_t stepr, uint32_t loadt, uint32_t unloadt, int nondma ) {
+void flpydsk_drive_data (uint32_t stepr, uint32_t loadt, uint32_t unloadt, int dma ) {
uint32_t data = 0;
@@ -237,7 +264,7 @@ void flpydsk_drive_data (uint32_t stepr, uint32_t loadt, uint32_t unloadt, int n
data = ( (stepr & 0xf) << 4) | (unloadt & 0xf);
flpydsk_send_command (data);
- data = (loadt) << 1 | nondma;
+ data = (loadt) << 1 | dma;
flpydsk_send_command (data);
}
@@ -260,31 +287,22 @@ void flpydsk_reset()
flpydsk_write_ccr (0);
//! pass mechanical drive info. steprate=3ms, unload time=240ms, load time=16ms
- flpydsk_drive_data (3,16,240,0);
+// flpydsk_drive_data (3,16,240,0);
+//
+
+ flpydsk_send_command (FDC_CMD_SPECIFY);
+ flpydsk_send_command (0xdf); /* steprate = 3ms, unload time = 240ms */
+ flpydsk_send_command (0x02); /* load time = 16ms, no-DMA = 0 */
//! calibrate the disk
flpydsk_calibrate ( _CurrentDrive );
}
-void floppy_init()
-{
- // init dma
- flpydsk_initialize_dma ();
-
- _CurrentDrive=0;
- _FloppyDiskIRQ = 0;
-
- scr_put_string_nl("floppy: init floppy driver.");
-
- flpydsk_reset ();
- flpydsk_drive_data (13, 1, 0xf, 0);
-
-}
-
void int_floppy_handler()
{
X86_IRQ_BEGIN
+ scr_put_string_nl("floppy: inside interrupt handler.");
_FloppyDiskIRQ=1;
X86_IRQ_END
@@ -311,8 +329,8 @@ void flpydsk_read_sector_imp (uint8_t head, uint8_t track, uint8_t sector) {
//! set the DMA for read transfer
flpydsk_dma_read ();
- flpydsk_drive_data (13, 1, 0xf, 0);
- scr_put_string_nl("floppy: reading sector (2)");
+ //flpydsk_drive_data (13, 1, 0xf, 0);
+ scr_put_string_nl("floppy: reading (head/track/sector)");
uint32_t st0, cyl;
@@ -333,7 +351,7 @@ void flpydsk_read_sector_imp (uint8_t head, uint8_t track, uint8_t sector) {
flpydsk_send_command ( 0xff );
//! wait for irq
- //flpydsk_wait_irq ();
+ flpydsk_wait_irq ();
//! read status info
int j;
@@ -346,6 +364,8 @@ void flpydsk_read_sector_imp (uint8_t head, uint8_t track, uint8_t sector) {
int flpydsk_seek ( uint32_t cyl, uint32_t head )
{
+ cyl=1;
+ head=1;
uint32_t st0, cyl0;
@@ -363,12 +383,12 @@ int flpydsk_seek ( uint32_t cyl, uint32_t head )
//! send the command
flpydsk_send_command (FDC_CMD_SEEK);
- flpydsk_send_command ( (head) << 2 | _CurrentDrive);
+ flpydsk_send_command ( (head << 2) | _CurrentDrive);
flpydsk_send_command (cyl);
+
//! wait for the results phase IRQ
- //flpydsk_wait_irq ();
-
+ flpydsk_wait_irq ();
flpydsk_check_int (&st0,&cyl0);
//! found the cylinder?
@@ -389,8 +409,6 @@ void flpydsk_lba_to_chs (int lba,int *head,int *track,int *sector) {
uint8_t* flpydsk_read_sector (int sectorLBA) {
- sectorLBA=0x10;
-
scr_put_string("floppy: reading sector:");
scr_put_hex(sectorLBA);
scr_put_string_nl(".");
@@ -405,7 +423,6 @@ uint8_t* flpydsk_read_sector (int sectorLBA) {
//! turn motor on and seek to track
-// flpydsk_control_motor (true);
// start motor
flpydsk_motor_on();
@@ -424,3 +441,28 @@ uint8_t* flpydsk_read_sector (int sectorLBA) {
}
+void floppy_init()
+{
+ // init dma
+ flpydsk_initialize_dma ();
+
+ _CurrentDrive=0;
+ _FloppyDiskIRQ = 0;
+
+ scr_put_string_nl("floppy: init floppy driver.");
+
+ flpydsk_reset ();
+// flpydsk_drive_data (13, 1, 0xf, 0);
+ // flpydsk_drive_data (3,16,240,0);
+ //
+ flpydsk_read_sector(1);
+ uint16_t *dma=0xb000;
+ int i;
+ for(i=0;i<10;i++)
+ scr_put_hex(dma[i]);
+
+
+ scr_put_string_nl("");
+
+}
+
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 944103d..bac687b 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -81,6 +81,7 @@ void int_init(uint16_t sel)
void int_install()
{
+
idtd.size=sizeof(struct int_desc)*INT_MAX; //TODO
idtd.baseHi=0x0000;
idtd.baseLo=&idt[0];
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 964a8f5..f4c9653 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -38,7 +38,7 @@ void kernel_main()
scr_put_string_nl("");
//pit config
- timer_init();
+ //timer_init();
// we know that here the bootloader placed the mamory map!
mem_init(0x7c00+0x140);
diff --git a/kernel/x86.h b/kernel/x86.h
index 425ab38..1e80405 100644
--- a/kernel/x86.h
+++ b/kernel/x86.h
@@ -5,6 +5,10 @@
#define X86_IRQ_BEGIN asm("cli\npusha");
#define X86_IRQ_END asm("mov $0x20, %al\nout %al, $0x20\npopa\nsti\nleave\niret");
+
+//#define X86_IRQ_BEGIN asm("pusha");
+//#define X86_IRQ_END asm("mov $0x20, %al\nout %al, $0x20\npopa\nleave\niret");
+//
void x86_outb(int port, uint8_t data);
uint8_t x86_inb(int port);
void x86_outw(int port, uint16_t data);