2012-05-08 22:38:37 +08:00
|
|
|
/*
|
|
|
|
* Floppy test cases.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Kevin Wolf <kwolf@redhat.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-02-09 02:08:51 +08:00
|
|
|
#include "qemu/osdep.h"
|
2012-05-08 22:38:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "libqtest.h"
|
|
|
|
#include "qemu-common.h"
|
|
|
|
|
|
|
|
#define TEST_IMAGE_SIZE 1440 * 1024
|
|
|
|
|
|
|
|
#define FLOPPY_BASE 0x3f0
|
|
|
|
#define FLOPPY_IRQ 6
|
|
|
|
|
|
|
|
enum {
|
|
|
|
reg_sra = 0x0,
|
|
|
|
reg_srb = 0x1,
|
|
|
|
reg_dor = 0x2,
|
|
|
|
reg_msr = 0x4,
|
|
|
|
reg_dsr = 0x4,
|
|
|
|
reg_fifo = 0x5,
|
|
|
|
reg_dir = 0x7,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2012-07-16 21:48:27 +08:00
|
|
|
CMD_SENSE_INT = 0x08,
|
2012-09-21 05:20:07 +08:00
|
|
|
CMD_READ_ID = 0x0a,
|
2012-07-16 21:48:27 +08:00
|
|
|
CMD_SEEK = 0x0f,
|
2012-09-19 05:04:56 +08:00
|
|
|
CMD_VERIFY = 0x16,
|
2012-07-16 21:48:27 +08:00
|
|
|
CMD_READ = 0xe6,
|
|
|
|
CMD_RELATIVE_SEEK_OUT = 0x8f,
|
|
|
|
CMD_RELATIVE_SEEK_IN = 0xcf,
|
2012-05-08 22:38:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2012-09-19 05:02:59 +08:00
|
|
|
BUSY = 0x10,
|
|
|
|
NONDMA = 0x20,
|
2012-05-08 22:38:37 +08:00
|
|
|
RQM = 0x80,
|
|
|
|
DIO = 0x40,
|
|
|
|
|
|
|
|
DSKCHG = 0x80,
|
|
|
|
};
|
|
|
|
|
2014-07-08 03:03:38 +08:00
|
|
|
static char test_image[] = "/tmp/qtest.XXXXXX";
|
2012-05-08 22:38:37 +08:00
|
|
|
|
|
|
|
#define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
|
|
|
|
#define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
|
|
|
|
|
2012-05-24 17:02:30 +08:00
|
|
|
static uint8_t base = 0x70;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CMOS_FLOPPY = 0x10,
|
|
|
|
};
|
|
|
|
|
2012-05-08 22:38:37 +08:00
|
|
|
static void floppy_send(uint8_t byte)
|
|
|
|
{
|
|
|
|
uint8_t msr;
|
|
|
|
|
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
assert_bit_set(msr, RQM);
|
|
|
|
assert_bit_clear(msr, DIO);
|
|
|
|
|
|
|
|
outb(FLOPPY_BASE + reg_fifo, byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t floppy_recv(void)
|
|
|
|
{
|
|
|
|
uint8_t msr;
|
|
|
|
|
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
assert_bit_set(msr, RQM | DIO);
|
|
|
|
|
|
|
|
return inb(FLOPPY_BASE + reg_fifo);
|
|
|
|
}
|
|
|
|
|
2012-07-16 22:06:56 +08:00
|
|
|
/* pcn: Present Cylinder Number */
|
|
|
|
static void ack_irq(uint8_t *pcn)
|
2012-05-08 22:38:37 +08:00
|
|
|
{
|
2012-07-16 21:48:27 +08:00
|
|
|
uint8_t ret;
|
|
|
|
|
2012-05-08 22:38:37 +08:00
|
|
|
g_assert(get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(CMD_SENSE_INT);
|
|
|
|
floppy_recv();
|
2012-07-16 22:06:56 +08:00
|
|
|
|
2012-07-16 21:48:27 +08:00
|
|
|
ret = floppy_recv();
|
2012-07-16 22:06:56 +08:00
|
|
|
if (pcn != NULL) {
|
|
|
|
*pcn = ret;
|
|
|
|
}
|
2012-07-16 21:48:27 +08:00
|
|
|
|
2012-07-16 22:06:56 +08:00
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
2012-05-08 22:38:37 +08:00
|
|
|
}
|
|
|
|
|
2012-09-19 05:04:56 +08:00
|
|
|
static uint8_t send_read_command(uint8_t cmd)
|
2012-06-13 21:43:12 +08:00
|
|
|
{
|
|
|
|
uint8_t drive = 0;
|
|
|
|
uint8_t head = 0;
|
|
|
|
uint8_t cyl = 0;
|
|
|
|
uint8_t sect_addr = 1;
|
|
|
|
uint8_t sect_size = 2;
|
|
|
|
uint8_t eot = 1;
|
|
|
|
uint8_t gap = 0x1b;
|
|
|
|
uint8_t gpl = 0xff;
|
|
|
|
|
|
|
|
uint8_t msr = 0;
|
|
|
|
uint8_t st0;
|
|
|
|
|
|
|
|
uint8_t ret = 0;
|
|
|
|
|
2012-09-19 05:04:56 +08:00
|
|
|
floppy_send(cmd);
|
2012-06-13 21:43:12 +08:00
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(cyl);
|
|
|
|
floppy_send(head);
|
|
|
|
floppy_send(sect_addr);
|
|
|
|
floppy_send(sect_size);
|
|
|
|
floppy_send(eot);
|
|
|
|
floppy_send(gap);
|
|
|
|
floppy_send(gpl);
|
|
|
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
uint8_t n = 2;
|
|
|
|
for (; i < n; i++) {
|
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
if (msr == 0xd0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= n) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
st0 = floppy_recv();
|
2012-09-21 05:07:53 +08:00
|
|
|
if (st0 != 0x40) {
|
2012-06-13 21:43:12 +08:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-19 05:02:59 +08:00
|
|
|
static uint8_t send_read_no_dma_command(int nb_sect, uint8_t expected_st0)
|
|
|
|
{
|
|
|
|
uint8_t drive = 0;
|
|
|
|
uint8_t head = 0;
|
|
|
|
uint8_t cyl = 0;
|
|
|
|
uint8_t sect_addr = 1;
|
|
|
|
uint8_t sect_size = 2;
|
|
|
|
uint8_t eot = nb_sect;
|
|
|
|
uint8_t gap = 0x1b;
|
|
|
|
uint8_t gpl = 0xff;
|
|
|
|
|
|
|
|
uint8_t msr = 0;
|
|
|
|
uint8_t st0;
|
|
|
|
|
|
|
|
uint8_t ret = 0;
|
|
|
|
|
|
|
|
floppy_send(CMD_READ);
|
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(cyl);
|
|
|
|
floppy_send(head);
|
|
|
|
floppy_send(sect_addr);
|
|
|
|
floppy_send(sect_size);
|
|
|
|
floppy_send(eot);
|
|
|
|
floppy_send(gap);
|
|
|
|
floppy_send(gpl);
|
|
|
|
|
|
|
|
uint16_t i = 0;
|
|
|
|
uint8_t n = 2;
|
|
|
|
for (; i < n; i++) {
|
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
if (msr == (BUSY | NONDMA | DIO | RQM)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= n) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Non-DMA mode */
|
|
|
|
for (i = 0; i < 512 * 2 * nb_sect; i++) {
|
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
assert_bit_set(msr, BUSY | RQM | DIO);
|
|
|
|
inb(FLOPPY_BASE + reg_fifo);
|
|
|
|
}
|
|
|
|
|
2015-05-21 21:19:38 +08:00
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
assert_bit_set(msr, BUSY | RQM | DIO);
|
|
|
|
g_assert(get_irq(FLOPPY_IRQ));
|
|
|
|
|
2012-09-19 05:02:59 +08:00
|
|
|
st0 = floppy_recv();
|
|
|
|
if (st0 != expected_st0) {
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
2015-05-21 21:19:38 +08:00
|
|
|
g_assert(get_irq(FLOPPY_IRQ));
|
2012-09-19 05:02:59 +08:00
|
|
|
floppy_recv();
|
|
|
|
|
2015-05-21 21:19:38 +08:00
|
|
|
/* Check that we're back in command phase */
|
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
assert_bit_clear(msr, BUSY | DIO);
|
|
|
|
assert_bit_set(msr, RQM);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
|
2012-09-19 05:02:59 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-16 22:06:56 +08:00
|
|
|
static void send_seek(int cyl)
|
2012-05-08 22:38:37 +08:00
|
|
|
{
|
|
|
|
int drive = 0;
|
|
|
|
int head = 0;
|
|
|
|
|
|
|
|
floppy_send(CMD_SEEK);
|
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(cyl);
|
2012-07-16 22:06:56 +08:00
|
|
|
ack_irq(NULL);
|
2012-05-08 22:38:37 +08:00
|
|
|
}
|
|
|
|
|
2012-05-24 17:02:30 +08:00
|
|
|
static uint8_t cmos_read(uint8_t reg)
|
2012-05-08 22:38:37 +08:00
|
|
|
{
|
2012-05-24 17:02:30 +08:00
|
|
|
outb(base + 0, reg);
|
|
|
|
return inb(base + 1);
|
|
|
|
}
|
2012-05-08 22:38:37 +08:00
|
|
|
|
2012-05-24 17:02:30 +08:00
|
|
|
static void test_cmos(void)
|
|
|
|
{
|
|
|
|
uint8_t cmos;
|
2012-05-08 22:38:37 +08:00
|
|
|
|
2012-05-24 17:02:30 +08:00
|
|
|
cmos = cmos_read(CMOS_FLOPPY);
|
2016-01-23 04:51:04 +08:00
|
|
|
g_assert(cmos == 0x40 || cmos == 0x50);
|
2012-05-24 17:02:30 +08:00
|
|
|
}
|
2012-05-08 22:38:37 +08:00
|
|
|
|
2012-05-24 17:02:30 +08:00
|
|
|
static void test_no_media_on_start(void)
|
|
|
|
{
|
|
|
|
uint8_t dir;
|
|
|
|
|
|
|
|
/* Media changed bit must be set all time after start if there is
|
|
|
|
* no media in drive. */
|
2012-05-08 22:38:37 +08:00
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
2012-07-16 22:06:56 +08:00
|
|
|
send_seek(1);
|
2012-05-08 22:38:37 +08:00
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
2012-05-24 17:02:30 +08:00
|
|
|
}
|
|
|
|
|
2012-06-13 21:43:12 +08:00
|
|
|
static void test_read_without_media(void)
|
|
|
|
{
|
|
|
|
uint8_t ret;
|
|
|
|
|
2012-09-19 05:04:56 +08:00
|
|
|
ret = send_read_command(CMD_READ);
|
2012-06-13 21:43:12 +08:00
|
|
|
g_assert(ret == 0);
|
|
|
|
}
|
|
|
|
|
2012-09-19 04:48:48 +08:00
|
|
|
static void test_media_insert(void)
|
2012-05-24 17:02:30 +08:00
|
|
|
{
|
|
|
|
uint8_t dir;
|
2012-05-08 22:38:37 +08:00
|
|
|
|
2012-05-24 17:02:30 +08:00
|
|
|
/* Insert media in drive. DSKCHK should not be reset until a step pulse
|
2012-05-08 22:38:37 +08:00
|
|
|
* is sent. */
|
2013-10-30 21:54:32 +08:00
|
|
|
qmp_discard_response("{'execute':'change', 'arguments':{"
|
2014-11-20 23:27:09 +08:00
|
|
|
" 'device':'floppy0', 'target': %s, 'arg': 'raw' }}",
|
2013-10-30 21:54:32 +08:00
|
|
|
test_image);
|
2012-05-08 22:38:37 +08:00
|
|
|
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
|
2012-07-16 22:06:56 +08:00
|
|
|
send_seek(0);
|
2012-07-04 22:26:04 +08:00
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
|
|
|
|
/* Step to next track should clear DSKCHG bit. */
|
2012-07-16 22:06:56 +08:00
|
|
|
send_seek(1);
|
2012-05-08 22:38:37 +08:00
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_clear(dir, DSKCHG);
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_clear(dir, DSKCHG);
|
2012-09-19 04:48:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_media_change(void)
|
|
|
|
{
|
|
|
|
uint8_t dir;
|
|
|
|
|
|
|
|
test_media_insert();
|
2012-05-24 17:02:30 +08:00
|
|
|
|
|
|
|
/* Eject the floppy and check that DSKCHG is set. Reading it out doesn't
|
|
|
|
* reset the bit. */
|
2013-10-30 21:54:32 +08:00
|
|
|
qmp_discard_response("{'execute':'eject', 'arguments':{"
|
|
|
|
" 'device':'floppy0' }}");
|
2012-05-24 17:02:30 +08:00
|
|
|
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
|
2012-07-16 22:06:56 +08:00
|
|
|
send_seek(0);
|
2012-07-04 22:26:04 +08:00
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
|
2012-07-16 22:06:56 +08:00
|
|
|
send_seek(1);
|
2012-05-24 17:02:30 +08:00
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
|
|
|
dir = inb(FLOPPY_BASE + reg_dir);
|
|
|
|
assert_bit_set(dir, DSKCHG);
|
2012-05-08 22:38:37 +08:00
|
|
|
}
|
|
|
|
|
2012-07-04 17:18:35 +08:00
|
|
|
static void test_sense_interrupt(void)
|
|
|
|
{
|
|
|
|
int drive = 0;
|
|
|
|
int head = 0;
|
|
|
|
int cyl = 0;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
floppy_send(CMD_SENSE_INT);
|
|
|
|
ret = floppy_recv();
|
|
|
|
g_assert(ret == 0x80);
|
|
|
|
|
|
|
|
floppy_send(CMD_SEEK);
|
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(cyl);
|
|
|
|
|
|
|
|
floppy_send(CMD_SENSE_INT);
|
|
|
|
ret = floppy_recv();
|
|
|
|
g_assert(ret == 0x20);
|
|
|
|
floppy_recv();
|
|
|
|
}
|
|
|
|
|
2012-07-16 21:48:27 +08:00
|
|
|
static void test_relative_seek(void)
|
|
|
|
{
|
|
|
|
uint8_t drive = 0;
|
|
|
|
uint8_t head = 0;
|
|
|
|
uint8_t cyl = 1;
|
2012-07-16 22:06:56 +08:00
|
|
|
uint8_t pcn;
|
2012-07-16 21:48:27 +08:00
|
|
|
|
|
|
|
/* Send seek to track 0 */
|
2012-07-16 22:06:56 +08:00
|
|
|
send_seek(0);
|
2012-07-16 21:48:27 +08:00
|
|
|
|
|
|
|
/* Send relative seek to increase track by 1 */
|
|
|
|
floppy_send(CMD_RELATIVE_SEEK_IN);
|
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(cyl);
|
|
|
|
|
2012-07-16 22:06:56 +08:00
|
|
|
ack_irq(&pcn);
|
|
|
|
g_assert(pcn == 1);
|
2012-07-16 21:48:27 +08:00
|
|
|
|
|
|
|
/* Send relative seek to decrease track by 1 */
|
|
|
|
floppy_send(CMD_RELATIVE_SEEK_OUT);
|
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(cyl);
|
|
|
|
|
2012-07-16 22:06:56 +08:00
|
|
|
ack_irq(&pcn);
|
|
|
|
g_assert(pcn == 0);
|
2012-07-16 21:48:27 +08:00
|
|
|
}
|
|
|
|
|
2012-09-21 05:20:07 +08:00
|
|
|
static void test_read_id(void)
|
|
|
|
{
|
|
|
|
uint8_t drive = 0;
|
|
|
|
uint8_t head = 0;
|
|
|
|
uint8_t cyl;
|
|
|
|
uint8_t st0;
|
2015-05-21 21:19:38 +08:00
|
|
|
uint8_t msr;
|
2012-09-21 05:20:07 +08:00
|
|
|
|
|
|
|
/* Seek to track 0 and check with READ ID */
|
|
|
|
send_seek(0);
|
|
|
|
|
|
|
|
floppy_send(CMD_READ_ID);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
|
2015-05-21 21:19:38 +08:00
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
if (!get_irq(FLOPPY_IRQ)) {
|
|
|
|
assert_bit_set(msr, BUSY);
|
|
|
|
assert_bit_clear(msr, RQM);
|
|
|
|
}
|
|
|
|
|
2012-09-21 05:20:07 +08:00
|
|
|
while (!get_irq(FLOPPY_IRQ)) {
|
|
|
|
/* qemu involves a timer with READ ID... */
|
|
|
|
clock_step(1000000000LL / 50);
|
|
|
|
}
|
|
|
|
|
2015-05-21 21:19:38 +08:00
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
assert_bit_set(msr, BUSY | RQM | DIO);
|
|
|
|
|
2012-09-21 05:20:07 +08:00
|
|
|
st0 = floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
cyl = floppy_recv();
|
|
|
|
head = floppy_recv();
|
|
|
|
floppy_recv();
|
2015-05-21 21:19:38 +08:00
|
|
|
g_assert(get_irq(FLOPPY_IRQ));
|
2012-09-21 05:20:07 +08:00
|
|
|
floppy_recv();
|
2015-05-21 21:19:38 +08:00
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
2012-09-21 05:20:07 +08:00
|
|
|
|
|
|
|
g_assert_cmpint(cyl, ==, 0);
|
|
|
|
g_assert_cmpint(head, ==, 0);
|
|
|
|
g_assert_cmpint(st0, ==, head << 2);
|
|
|
|
|
|
|
|
/* Seek to track 8 on head 1 and check with READ ID */
|
|
|
|
head = 1;
|
|
|
|
cyl = 8;
|
|
|
|
|
|
|
|
floppy_send(CMD_SEEK);
|
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(cyl);
|
|
|
|
g_assert(get_irq(FLOPPY_IRQ));
|
|
|
|
ack_irq(NULL);
|
|
|
|
|
|
|
|
floppy_send(CMD_READ_ID);
|
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
|
|
|
floppy_send(head << 2 | drive);
|
|
|
|
|
2015-05-21 21:19:38 +08:00
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
if (!get_irq(FLOPPY_IRQ)) {
|
|
|
|
assert_bit_set(msr, BUSY);
|
|
|
|
assert_bit_clear(msr, RQM);
|
|
|
|
}
|
|
|
|
|
2012-09-21 05:20:07 +08:00
|
|
|
while (!get_irq(FLOPPY_IRQ)) {
|
|
|
|
/* qemu involves a timer with READ ID... */
|
|
|
|
clock_step(1000000000LL / 50);
|
|
|
|
}
|
|
|
|
|
2015-05-21 21:19:38 +08:00
|
|
|
msr = inb(FLOPPY_BASE + reg_msr);
|
|
|
|
assert_bit_set(msr, BUSY | RQM | DIO);
|
|
|
|
|
2012-09-21 05:20:07 +08:00
|
|
|
st0 = floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
floppy_recv();
|
|
|
|
cyl = floppy_recv();
|
|
|
|
head = floppy_recv();
|
|
|
|
floppy_recv();
|
2015-05-21 21:19:38 +08:00
|
|
|
g_assert(get_irq(FLOPPY_IRQ));
|
2012-09-21 05:20:07 +08:00
|
|
|
floppy_recv();
|
2015-05-21 21:19:38 +08:00
|
|
|
g_assert(!get_irq(FLOPPY_IRQ));
|
2012-09-21 05:20:07 +08:00
|
|
|
|
|
|
|
g_assert_cmpint(cyl, ==, 8);
|
|
|
|
g_assert_cmpint(head, ==, 1);
|
|
|
|
g_assert_cmpint(st0, ==, head << 2);
|
|
|
|
}
|
|
|
|
|
2012-09-19 05:02:59 +08:00
|
|
|
static void test_read_no_dma_1(void)
|
|
|
|
{
|
|
|
|
uint8_t ret;
|
|
|
|
|
|
|
|
outb(FLOPPY_BASE + reg_dor, inb(FLOPPY_BASE + reg_dor) & ~0x08);
|
|
|
|
send_seek(0);
|
2012-09-21 05:07:53 +08:00
|
|
|
ret = send_read_no_dma_command(1, 0x04);
|
2012-09-19 05:02:59 +08:00
|
|
|
g_assert(ret == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_read_no_dma_18(void)
|
|
|
|
{
|
|
|
|
uint8_t ret;
|
|
|
|
|
|
|
|
outb(FLOPPY_BASE + reg_dor, inb(FLOPPY_BASE + reg_dor) & ~0x08);
|
|
|
|
send_seek(0);
|
2012-09-21 05:07:53 +08:00
|
|
|
ret = send_read_no_dma_command(18, 0x04);
|
2012-09-19 05:02:59 +08:00
|
|
|
g_assert(ret == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_read_no_dma_19(void)
|
|
|
|
{
|
|
|
|
uint8_t ret;
|
|
|
|
|
|
|
|
outb(FLOPPY_BASE + reg_dor, inb(FLOPPY_BASE + reg_dor) & ~0x08);
|
|
|
|
send_seek(0);
|
|
|
|
ret = send_read_no_dma_command(19, 0x20);
|
|
|
|
g_assert(ret == 0);
|
|
|
|
}
|
|
|
|
|
2012-09-19 05:04:56 +08:00
|
|
|
static void test_verify(void)
|
|
|
|
{
|
|
|
|
uint8_t ret;
|
|
|
|
|
|
|
|
ret = send_read_command(CMD_VERIFY);
|
|
|
|
g_assert(ret == 0);
|
|
|
|
}
|
|
|
|
|
2012-05-18 02:55:58 +08:00
|
|
|
/* success if no crash or abort */
|
|
|
|
static void fuzz_registers(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
|
|
uint8_t reg, val;
|
|
|
|
|
|
|
|
reg = (uint8_t)g_test_rand_int_range(0, 8);
|
|
|
|
val = (uint8_t)g_test_rand_int_range(0, 256);
|
|
|
|
|
|
|
|
outb(FLOPPY_BASE + reg, val);
|
|
|
|
inb(FLOPPY_BASE + reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 22:38:37 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *arch = qtest_get_arch();
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Check architecture */
|
|
|
|
if (strcmp(arch, "i386") && strcmp(arch, "x86_64")) {
|
|
|
|
g_test_message("Skipping test for non-x86\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a temporary raw image */
|
|
|
|
fd = mkstemp(test_image);
|
|
|
|
g_assert(fd >= 0);
|
|
|
|
ret = ftruncate(fd, TEST_IMAGE_SIZE);
|
|
|
|
g_assert(ret == 0);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
/* Run the tests */
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
2014-01-06 14:05:24 +08:00
|
|
|
qtest_start(NULL);
|
2012-05-08 22:38:37 +08:00
|
|
|
qtest_irq_intercept_in(global_qtest, "ioapic");
|
2012-05-24 17:02:30 +08:00
|
|
|
qtest_add_func("/fdc/cmos", test_cmos);
|
|
|
|
qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
|
2012-06-13 21:43:12 +08:00
|
|
|
qtest_add_func("/fdc/read_without_media", test_read_without_media);
|
2012-05-08 22:38:37 +08:00
|
|
|
qtest_add_func("/fdc/media_change", test_media_change);
|
2012-07-04 17:18:35 +08:00
|
|
|
qtest_add_func("/fdc/sense_interrupt", test_sense_interrupt);
|
2012-07-16 21:48:27 +08:00
|
|
|
qtest_add_func("/fdc/relative_seek", test_relative_seek);
|
2012-09-21 05:20:07 +08:00
|
|
|
qtest_add_func("/fdc/read_id", test_read_id);
|
2012-09-19 05:04:56 +08:00
|
|
|
qtest_add_func("/fdc/verify", test_verify);
|
2012-09-19 04:49:30 +08:00
|
|
|
qtest_add_func("/fdc/media_insert", test_media_insert);
|
2012-09-19 05:02:59 +08:00
|
|
|
qtest_add_func("/fdc/read_no_dma_1", test_read_no_dma_1);
|
|
|
|
qtest_add_func("/fdc/read_no_dma_18", test_read_no_dma_18);
|
|
|
|
qtest_add_func("/fdc/read_no_dma_19", test_read_no_dma_19);
|
2012-05-18 02:55:58 +08:00
|
|
|
qtest_add_func("/fdc/fuzz-registers", fuzz_registers);
|
2012-05-08 22:38:37 +08:00
|
|
|
|
|
|
|
ret = g_test_run();
|
|
|
|
|
|
|
|
/* Cleanup */
|
2013-06-20 14:55:29 +08:00
|
|
|
qtest_end();
|
2012-05-08 22:38:37 +08:00
|
|
|
unlink(test_image);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|