aboutsummaryrefslogtreecommitdiff
path: root/src/hw/floppy.c
AgeCommit message (Collapse)AuthorFilesLines
2018-02-15floppy: Send 4 sense interrupt commands during controller initializationNikolay Nikolov1-1/+14
During initialization, real floppy controllers need 4 sense interrupt commands to clear the interrupt status (this represents the transition from "not ready" to "ready" for each of the four virtual floppy drives), instead of just one. This is described in detail in section 7.4 - Drive Polling of the Intel 82077AA datasheet. Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-15floppy: Wait for the floppy motor to reach a stable speed, after startingNikolay Nikolov1-2/+11
When starting up the floppy motor, wait for a certain amount of time, so that it can spin up and reach a stable speed. This delay is skipped, if the motor was already running (which can happen, since the floppy motor is intentionally kept spinning for 2 seconds after the previous floppy operation completes). Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-15floppy: Support up to 4 floppy drives when turning on the floppy motorNikolay Nikolov1-1/+1
The previous version allowed for only two floppies. Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-15floppy: Execute a SPECIFY command after sensing the media typeNikolay Nikolov1-2/+20
The SPECIFY command sets the Step Rate Time, Head Load Time, Head Unload Time and the DMA enable/disable bit. Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-15floppy: hold the DOR reset bit low for 4 microseconds, when resettingNikolay Nikolov1-0/+2
Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-07floppy: Use timer_check() in floppy_wait_irq()Nikolay Nikolov1-4/+5
Use timer_check() instead of using floppy_motor_counter in BDA for the timeout check in floppy_wait_irq(). The problem with using floppy_motor_counter was that, after it reaches 0, it immediately stops the floppy motors, which is not what is supposed to happen on real hardware. Instead, after a timeout (like in the end of every floppy operation, regardless of the result - success, timeout or error), the floppy motors must be kept spinning for additional 2 seconds (the FLOPPY_MOTOR_TICKS). So, now the floppy_motor_counter is initialized to 255 (the max value) in the beginning of the floppy operation. For IRQ timeouts, a different timeout is used, specified by the new FLOPPY_IRQ_TIMEOUT constant (currently set to 5 seconds - a fairly conservative value, but should work reliably on most floppies). After the floppy operation, floppy_drive_pio() resets the floppy_motor_counter to 2 seconds (FLOPPY_MOTOR_TICKS). This is also consistent with what other PC BIOSes do. Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-07floppy: Reset the floppy motor count in floppy_drive_pio()Nikolay Nikolov1-0/+1
Reset the floppy motor count, so the motor keeps spinning 2 seconds after a floppy operation, performed by floppy_drive_pio(). Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-07floppy: Preserve motor and drive sel bits when resetting the floppy controllerNikolay Nikolov1-3/+6
In case of read or write errors, the floppy system is usually reset and the operation is retried. In that case, the floppy motor state must be preserved in order to avoid creating jitter and keep the floppy motor spinning smoothly at a constant speed. Additionally, the drive select bits should probably also be preserved, because some systems might need a small delay after selecting a new drive. In that case, the operation would be retried, without changing the currently selected drive. In floppy_enable_controller(), the IRQ bit is now enabled first, before the reset bit is set. I'm not completely sure whether this is necessary. It is done just in case some hardware introduces a delay between setting this bit and actually enabling the IRQ, which would cause us to miss the IRQ, sent by the controller immediately after reset. Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-07floppy: Introduce FLOPPY_DOR_XXX constantsNikolay Nikolov1-4/+13
Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-07floppy: Introduce floppy_dor_mask()Nikolay Nikolov1-1/+7
Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2018-02-07floppy: Introduce the floppy_dor_read() functionNikolay Nikolov1-2/+8
Signed-off-by: Nikolay Nikolov <nickysn@users.sourceforge.net>
2017-09-27block: Rename disk_op_s->drive_gf to drive_flKevin O'Connor1-10/+10
Now that the drive_s struct does not need to be in the f-segment, rename references to drive_gf in the generic drive code to drive_fl. This is just variable renames - no code changes. Tested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-02-03pci: Split low-level pci code from higher-level 'struct pci_device' codeKevin O'Connor1-1/+1
Split pci.c into pci.c and pcidevice.c. The low-level code that interacts directly with the PCI devices remains in pci.c, while functions dealing with the higher level pci_device cache move to pcidevice.c. Only pci.c is needed in 16bit mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14block: Rename process_XXX_op() functions to XXX_process_op()Kevin O'Connor1-1/+1
Rename disk driver dispatch functions to a consistent naming style. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-12-03floppy: Make sure to yield() during floppy PIOKevin O'Connor1-0/+2
The floppy Programmed IO code really should yield while the controller is busy. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-06-04Move most of the VAR16FIXED() defs to misc.c.Kevin O'Connor1-2/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-27Remove unnecesary updates of the disk op->count field.Kevin O'Connor1-30/+14
Now that the op->count field is cleared in a global location on simple errors, remove various local clears done in individual drivers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-12floppy: Implement cylinder seeking when accessing a different cylinder.Kevin O'Connor1-38/+48
It appears that on real hardware, floppies require a seek command to move the floppy head between cylinders. So, track what cylinder is active and issue a seek command whenever a new cylinder is requested. This also breaks up the floppy_cmd() code so that the low-level command functions can pass the desired cylinder directly to the seeking code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-12On disk format request, verify cylinders and pass to driver.Kevin O'Connor1-2/+2
The regs->ch field contains the cylinder to format on a disk_1305 call. Verify that parameter and pass to the low-level driver code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-12floppy: Encode command and flags into single value in floppy pio code.Kevin O'Connor1-112/+93
Eliminate struct floppy_pio_s and change floppy_pio() to take the command type and parameters in a single encoded value. This makes the code similar to the ps2port.c pio code. It also reduces some of the boilerplate code in the callers of floppy_pio(). Also, collapse pairs of floppy_select_drive() and floppy_pio() calls into new call floppy_drive_pio(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-07floppy: Fix accesses to DOR register.Kevin O'Connor1-7/+20
The DOR register is a write-only register (even though QEMU and at least some real hardware permit read/write acess). So, do not read from the DOR port. Introduce a VARLOW variable (FloppyDOR) to store the current state. When resetting the controller, make sure to enable both the controller and interrupts. Also, make sure the controller is really reset (by writing a 0 to DOR first) to ensure an IRQ is received on reset. Also, add some additional dprintf statements to the floppy init path. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-07floppy: Fix incorrect LBA to CHS translation.Kevin O'Connor1-3/+2
The floppy LBA to CHS translation was incorrect for the last sector of a given cylinder. This wasn't a problem under QEMU as it came to the same results anyway, but it causes errors of real floppy controllers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-04floppy: Minor - add warnings if timeouts occur.Kevin O'Connor1-0/+3
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-26Convert op->drive_g from a 16bit pointer to a 32 bit "GLOBALFLAT" pointer.Kevin O'Connor1-29/+29
The "drive" structure is always malloc'ed and therefore always starts off described as a 32-bit "flat" pointer. Instead of switching to/from 16bit pointers, make all the code use the 32bit pointer. This eliminates the confusing 16/32 bit pointer switches. This patch also removes the "_g" suffixes on local variables in functions that are always called in 32bit mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-14Rename fields of 'struct chs_s' and use in floppy lba2chs().Kevin O'Connor1-34/+34
Rename the fields of 'struct chs_s' so that it can be used both to describe a drive and to describe a particular sector on a drive. Update floppy.c:lba2chs() to return a 'struct chs_s' instead of passing the results via pointers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-28Remove ioport.h; disperse its contents to other header files.Kevin O'Connor1-0/+6
Move the inb(), insb(), etc. code from ioport.h to x86.h. Move the PORT_* definitions to their appropriate hardware files. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-28Move dma code to new file hw/dma.c.Kevin O'Connor1-34/+6
Move the DMA controller code in resume.c and hw/floppy.c to a new file hw/dma.c. This centralizes the DMA controller code into one place. Also, don't unmask the floppy DRQ during floppy setup - there is no reason to unmask the DRQ prior to a command being programmed into the DMA controller. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-28Rename hw/cmos.h to hw/rtc.h and copy RTC code from clock.c to hw/rtc.c.Kevin O'Connor1-2/+2
Group the Real Time Clock code into hw/rtc.[ch]. Also, use rtc_read/write/mask function naming (instead of inb/outb_cmos) to be more consistent with other register accessors. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Merge bmp.h, boot.h, jpeg.h, and post.h into util.h.Kevin O'Connor1-1/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Split disk.h into block.h and std/disk.h.Kevin O'Connor1-1/+2
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Move function definitions for output.c from util.h to new file output.h.Kevin O'Connor1-7/+7
Also, sort the order of include files in the c files. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Move malloc code from pmm.c to new files malloc.c and malloc.h.Kevin O'Connor1-0/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Move romfile definitions from util.h to new file romfile.h.Kevin O'Connor1-0/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Move stacks.c definitions from util.h to new file stacks.h.Kevin O'Connor1-0/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Rename util.c to string.c and introduce string.h.Kevin O'Connor1-0/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-02Move code centered around specific hardware devices to src/hw/Kevin O'Connor1-0/+701
Move many C files from the src/ directory to the new src/hw/ directory. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>