What all do I need to achieve this?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
TheChuckster

What all do I need to achieve this?

Post by TheChuckster »

I would like to write a simple single-tasking console OS that is capable of loading and running simple programs off of the floppy its on.

So far, I have written kprintf, a segmented memory manager with malloc, free, realloc, and calloc, and I have begun work on a floppy driver (though I'm stuck due to the tutorial missing info on starting the motor).

What more would I need to write in order to achieve this goal?
Tim

Re:What all do I need to achieve this?

Post by Tim »

You'll need something to access the file system, and something to arrange the loaded image in such a way that it can be executed.

BTW: to start the floppy motor, set the relevant "motor on" bit in the DOR, then wait a couple of seconds.
For example:

Code: Select all

// Digital output register flags
#define DOR_DRIVE_SHIFT   0      // bottom two bits select drive
#define DOR_ENABLE      0x04   // enable controller (= !reset)
#define DOR_IRQDMA      0x08   // IRQ & DMA enabled
#define DOR_MOTORA      0x10   // motor for drive A
#define DOR_MOTORB      0x20   // motor for drive B
#define DOR_MOTORC      0x40   // motor for drive C
#define DOR_MOTORD      0x80   // motor for drive D

/*
 * Default settings for DOR:
 *   Controller & IRQ/DMA enabled
 *   All motors off
 */
#define DOR_DEFAULT(d)   (DOR_ENABLE | DOR_IRQDMA | ((d) << DOR_DRIVE_SHIFT))

void floppy_controller::motor_on(unsigned drive)
{
    m_motors |= DOR_MOTORA << drive;
    out(m_base + REG_DOR, m_motors | DOR_DEFAULT(0));
}
Tux

Re:What all do I need to achieve this?

Post by Tux »

I just need a read floppy driver too, I had one and had goten far. But I lost all the data. When I ran it in boch's it said BOCH'S WAS ACTUALLY DOING FLOPPY CODE. Then boch's would quit saying that I sent a messed up floppy table. Hey, at least I was close. I am pist though, I have to do it all over again :/
Slasher

Re:What all do I need to achieve this?

Post by Slasher »

hi, check out my floppy driver tutorial at
http://www.mega-tokyo.com/forum/index.p ... 77;start=0
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

Cool tutorial! I'll see what I can do with it later. Do I need to have a way of timing miliseconds to write this? If so, what IO ports would I need to program and use the PIT?
nullify

Re:What all do I need to achieve this?

Post by nullify »

Well, I guess you don't *need* to have it right now for simply testing purposes - you could just wait for a key press before continuing, which will serve as your "delay". Of course, if you don't have a keyboard driver, that's a different problem. :-)

Look on the net to find PIT programming info.
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

I already have a keyboard driver. That will do for now.
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

Thanks a lot! Your tutorial is great -- I got the parameter table read but I can't get any further because my compiler complains of floppy_mailbox, fmess, st0, cylinder, and START being undeclared. There is no word about them in the tutorial either. :(
Slasher

Re:What all do I need to achieve this?

Post by Slasher »

hi, floppy_mess is the mail box that the floppy driver and floppy interrupt use for interprocess communication ie the floppy driver waits at the box to receive messages that a floppy int has occured.
The rest are just variables i was using to test the code. As far as you understand the code there and the sequence of operations you'll be fine.
LilHelper

Re:What all do I need to achieve this?

Post by LilHelper »

TheChuckster wanted to know about: st0, cylnder, or START :(
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

Yeah that's missing too. But I'm thinking about giving up. I mean there's no point in doing this if I'm just going to rip someone's code. I really know nothing about floppy drivers or x86 in general. I would like to learn, though. How did you manage to get this far?
Slasher

Re:What all do I need to achieve this?

Post by Slasher »

Do not give up! All the fustration will pay off later.Believe me, the more you try and fail the easier the next attempt will be cause you would have gathered a little info on why the previous one failed. I'm trying to get my kernel to use paging with memory mapped from linear 0xC0000000 into physical 0x200000 after 8 days of 9+ hrs per day of Failure
But I've done so much trial and error that PAGING theory is so clear and imprinted in my brain.
The floppy code developed in the same way,try and fail...try again!The main problem is that, the docs leave out vital minute details that unless you come across them you'll be wondering why you are so dumb as not to get the hardware to responde as wanted after reading the docs over and over again. So just keep trying and re-reading the docs! Hang in there :)
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

Thanks! You have contributed to the few docs there are! ;D

I have begun to write one from scratch, as there is no existing code that is useful. I have started the motor by:

outportb(FDC_DOR,0x1c);

and can seek to tracks by

sendbyte(SEEK_TRACK);
sendbyte(0);
sendbyte(track);

However, there are no signs of my floppy drive actually doing this! The light isn't lit and I do not hear a spinning sound! Am I too premature in writing the driver for these signs to occur or am I doing things wrong?
Tim

Re:What all do I need to achieve this?

Post by Tim »

After turning on the motor, you've got to wait for 500ms or so before you can do anything useful.
TheChuckster

Re:What all do I need to achieve this?

Post by TheChuckster »

Nevermind, this only happened in Bochs. I tried it on a real PC and it worked. YEAH!!! THE MOTOR WORKS!!! *pats back*
Post Reply