unsigned long dest_paddr = va2pa(dest);
// 不能跨64K边界
+#if 1
const uint32_t size = count * SECT_SIZE;
const uint32_t _64K = 1 << 16;
- assert(((dest_paddr + size) & _64K) == (dest_paddr & _64K));
+ assert(((dest_paddr & (_64K - 1)) + size) <= _64K);
+#else
+ const uint32_t size = count * SECT_SIZE;
+ const uint32_t _64K = 0xFFFF0000;
+ assert(((dest_paddr + size - (size == 0 ? 0 : 1)) & _64K) == (dest_paddr & _64K));
+#endif
ide_ctrl->prdt[0].phys_addr = dest_paddr;
ide_ctrl->prdt[0].byte_count = size;
// 校验buffer是否跨64K
// 先不处理
- if (((uint32_t)r->buf & 0xFFFF0000) != (((uint32_t)(r->buf + r->count * 512)) & 0xFFFF0000)) {
+
+#if 1
+ {
+ const uint32_t size = r->count * 512;
+ const uint32_t _64K = 1 << 16;
+ assert(((((uint32_t)r->buf) & (_64K - 1)) + size) <= _64K);
+ }
+#else
+ if (((uint32_t)r->buf & 0xFFFF0000) != (((uint32_t)(r->buf + r->count * 512 - 1)) & 0xFFFF0000)) {
+ printk("dma read addr %08x count %d\n", r->buf, r->count);
panic("disk DMA read cross 64K");
}
+#endif
mutex_lock(&drv->ide_pci_controller->request_mutex);
atomic_inc(&drv->ide_pci_controller->request_cnt);
switch (r->command) {
case DISK_REQ_IDENTIFY:
- printk("try to read disk drive %u identify", drv_no);
+ printk("try to read disk drive %u identify\n", drv_no);
assert(r->count == 1);
ata_read_identify(drv_no, 0);
break;
case DISK_REQ_READ:
assert(r->count > 0);
assert(r->buf != NULL || r->bb->data != NULL);
- // printk("DISK READ drv_no %u pos %u count %u\n", drv_no, (uint32_t)pos, r->count);
+ // printk("DISK READ drv_no %u pos %u count %u bb %x\n", drv_no, (uint32_t)pos, r->count, r->bb);
if (r->bb != 0) {
ata_dma_read_ext(drv_no, pos, r->count, r->bb->data);
} else {
}
}
-u16 disk_buf1[256];
-u16 disk_buf2[256];
+// 保存它们不跨64KB
+u16 disk_buf1[256] __attribute__((__aligned__(512)));
+u16 disk_buf2[256] __attribute__((__aligned__(512)));
void taskA_entry() {
current->priority = 7;
while (1) {
- sysc_wait(37);
+ sysc_wait(97);
uint64_t sect_nr = get_next_deubug_sect_nr();
memset(disk_buf1, 0, 512);
current->priority = 13;
while (1) {
- sysc_wait(73);
- uint64_t sect_nr = get_next_deubug_sect_nr();
- memset(disk_buf2, 0, 512);
- disk_request_t r;
- r.dev = MAKE_DISK_DEV(2, 0);
- r.command = DISK_REQ_READ;
- r.pos = sect_nr;
- r.count = 1;
- r.buf = disk_buf2;
- r.bb = 0;
-
- send_disk_request(&r);
- // verify_hd_data(sect_nr, disk_buf2, current->name);
-
- for (int i = 0; i < 1; i++) {
- asm("hlt;");
- }
+ sysc_wait(7);
+ // uint64_t sect_nr = get_next_deubug_sect_nr();
+ // memset(disk_buf2, 0, 512);
+ // disk_request_t r;
+ // r.dev = MAKE_DISK_DEV(2, 0);
+ // r.command = DISK_REQ_READ;
+ // r.pos = sect_nr;
+ // r.count = 1;
+ // r.buf = disk_buf2;
+ // r.bb = 0;
+
+ // send_disk_request(&r);
+ // // verify_hd_data(sect_nr, disk_buf2, current->name);
+
+ // for (int i = 0; i < 1; i++) {
+ // asm("hlt;");
+ // }
}
}