/* 读磁盘的一个扇区 */ void readsect(void *dst, int offset) { int i; waitdisk(); out_byte(0x1F2, 1); out_byte(0x1F3, offset); out_byte(0x1F4, offset >> 8); out_byte(0x1F5, offset >> 16); out_byte(0x1F6, (offset >> 24) | 0xE0); out_byte(0x1F7, 0x20); waitdisk(); for (i = 0; i < SECTSIZE / 4; i ++) { ((int *)dst)[i] = in_long(0x1F0); } }
// Read a single sector at offset into dst. void readsect(void *dst, uint offset) { // Issue command. waitdisk(); outb(0x1F2, 1); // count = 1 outb(0x1F3, offset); outb(0x1F4, offset >> 8); outb(0x1F5, offset >> 16); outb(0x1F6, (offset >> 24) | 0xE0); outb(0x1F7, 0x20); // cmd 0x20 - read sectors // Read data. waitdisk(); insl(0x1F0, dst, SECTSIZE/4); }
// Read a single sector at offset into dst. void readsect(void *dst, uint offset) { // Issue command. waitdisk(); outb(IDE_DATA_PRIMARY+IDE_REG_SECTORS, 1); outb(IDE_DATA_PRIMARY+IDE_REG_LBA0, offset & 0xff); outb(IDE_DATA_PRIMARY+IDE_REG_LBA1, (offset >> 8) & 0xff); outb(IDE_DATA_PRIMARY+IDE_REG_LBA2, (offset >> 16) & 0xff); outb(IDE_DATA_PRIMARY+IDE_REG_DISK, ((offset >> 24) & 0x0f) | IDE_DISK_LBA); outb(IDE_DATA_PRIMARY+IDE_REG_COMMAND, IDE_CMD_READ); // Read data. waitdisk(); insl(IDE_DATA_PRIMARY+IDE_REG_DATA, dst, SECTOR_SIZE/4); }
//write disk void writesect(void *src, int offset) { int i; waitdisk(); out_byte(0x1F2, 1); out_byte(0x1F3, offset); out_byte(0x1F4, offset >> 8); out_byte(0x1F5, offset >> 16); out_byte(0x1F6, (offset >> 24) | 0xE0); out_byte(0x1F7, 0x20); waitdisk(); for (i = 0; i < SECTSIZE / 4; i ++) { //((int *)dst)[i] = in_long(0x1F0); out_long(0x1F0,((unsigned int*)src)[i]); } }
/* readsect - read a single sector at @secno into @dst */ static void readsect(void *dst, uint32_t secno) { // wait for disk to be ready waitdisk(); outb(0x1F2, 1); // count = 1 outb(0x1F3, secno & 0xFF); outb(0x1F4, (secno >> 8) & 0xFF); outb(0x1F5, (secno >> 16) & 0xFF); outb(0x1F6, ((secno >> 24) & 0xF) | 0xE0); outb(0x1F7, 0x20); // cmd 0x20 - read sectors // wait for disk to be ready waitdisk(); // read a sector insl(0x1F0, dst, SECTSIZE / 4); }
static void readsect(void *dst, uint32_t offset) { // wait for disk to be ready waitdisk(); outb(0x1F2, 1); // count = 1 outb(0x1F3, offset); outb(0x1F4, offset >> 8); outb(0x1F5, offset >> 16); outb(0x1F6, (offset >> 24) | 0xE0); outb(0x1F7, 0x20); // cmd 0x20 - read sectors // wait for disk to be ready waitdisk(); // read a sector insl(0x1F0, dst, SECTSIZE / 4); }
static void ide_prepare(uint32_t sector) { waitdisk(); // out_byte(IDE_PORT_CTRL, 0); out_byte(IDE_PORT_BASE + 2, 1); out_byte(IDE_PORT_BASE + 3, sector & 0xFF); out_byte(IDE_PORT_BASE + 4, (sector >> 8) & 0xFF); out_byte(IDE_PORT_BASE + 5, (sector >> 16) & 0xFF); out_byte(IDE_PORT_BASE + 6, 0xE0 | ((sector >> 24) & 0xFF)); }
void disk_do_read(void *buf, uint32_t sector) { int i; ide_prepare(sector); issue_read(); waitdisk(); for (i = 0; i < 512 / sizeof(uint32_t); i ++) { *(((uint32_t*)buf) + i) = in_long(IDE_PORT_BASE); } }
void ata_rwsects(int drv_slave, int rwtype, void *buf, lba_t lba, unsigned count) { ATA_CRIT_BEGIN(1); ata_cmd_out(drv_slave, rwtype, lba, count); waitdisk(); if (rwtype == ATA_READ) { ata_data_in(buf, count); } else if (rwtype == ATA_WRITE) { ata_data_out(buf, count); } else { assert(0); } ATA_CRIT_END(1); }