From 3084861d467b0c8a01585ec126ff09fb7669ab4c Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Thu, 13 Apr 2023 18:05:42 +0200 Subject: [PATCH] Fix a bug in MAPDRV and a bug in the MFRSD kernel. - MAPDRV was corrupting the register holding the drive number while unmapping all the drives in case the device reports it has changed. Thus the mapping information ended up written to an incorrect memory area. - The MFRSD driiver was reporting "device changed" even after the device had been accessed with DEV_RW. A device is no longer considered as "changed" after it has been accessed. Scenario to reproduce the issue: - MFRSD with two cards, second one has at least 2 partitions - On boot, A: is card 1 partition 1, B: is card 2 partition 1 - Right after boot map any drive to card 2 partition 2: MAPDDRV d: 2 3 1-3 - Now switch to drive D:, computer crashes --- source/kernel/bank4/partit.mac | 4 +++- source/kernel/drivers/MegaFlashRomSD/mfrsd.asm | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/kernel/bank4/partit.mac b/source/kernel/bank4/partit.mac index 94c0c441..5824c7f3 100644 --- a/source/kernel/bank4/partit.mac +++ b/source/kernel/bank4/partit.mac @@ -3137,7 +3137,7 @@ MAP_SPECIFIC: MAP_DRV_UNK: ;Unknown change status: assume unchanged media. - ;If it has changed, the boot checksum checksum + ;If it has changed, the boot checksum ;mechanism will do the work of unassigning ;all other drives mapped to this device ;if necessary. @@ -3147,6 +3147,7 @@ MAP_DRV_UNK: MAP_DRV_CH: push hl push iy + push bc ld e,(hl) inc hl ld d,(hl) @@ -3156,6 +3157,7 @@ MAP_DRV_CH: ld d,(iy+2) ld e,(iy+3) call UNMAPALL + pop bc pop iy pop hl diff --git a/source/kernel/drivers/MegaFlashRomSD/mfrsd.asm b/source/kernel/drivers/MegaFlashRomSD/mfrsd.asm index 63825574..5c13e030 100644 --- a/source/kernel/drivers/MegaFlashRomSD/mfrsd.asm +++ b/source/kernel/drivers/MegaFlashRomSD/mfrsd.asm @@ -666,7 +666,7 @@ DEV_RW: ;ld hl,(#f9f0) ;inc hl - ;ld (#f9f0),hl ; Cuenta lecturas + ;ld (#f9f0),hl ; Count reads call SD_OFF ei @@ -677,6 +677,9 @@ DEV_RW: ret .ok: + ;A successful device access must reset the "device changed" flag + res BIT_SD_CHG,(ix+STATUS) + xor a ; Ok ret