From 5ee82510b5fefd10fd8de1fa85adb38c9fa87975 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 27 Apr 2025 15:00:29 -0400 Subject: lba48 for more then 256 sectors --- kernel/drivers/ata.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'kernel/drivers/ata.c') diff --git a/kernel/drivers/ata.c b/kernel/drivers/ata.c index 63c4559..022ec81 100644 --- a/kernel/drivers/ata.c +++ b/kernel/drivers/ata.c @@ -506,7 +506,7 @@ static uint8_t get_ata_cmd_for_access(enum lba_mode lba_mode, static enum ide_error ide_device_ata_access(struct ide_device *dev, enum access_mode mode, uint32_t lba, - uint8_t numsects, + uint16_t numsects, uint16_t buf[numsects * 256]) { struct ide_channel *chan = channel(dev->channel_idx); @@ -521,7 +521,7 @@ static enum ide_error ide_device_ata_access(struct ide_device *dev, chan->no_interrupt = (ide_irq_invoked = 0x0) + 0x02); // select one from LBA28, LBA48 or CHS - if (lba >= 0x10000000) { + if (lba >= 0x10000000 || numsects > UINT8_MAX) { // drive should support LBA in this case, or you are giving a bad LBA lba_mode = LBA48; lba_io[0] = (lba & 0x000000FF) >> 0; @@ -565,19 +565,22 @@ static enum ide_error ide_device_ata_access(struct ide_device *dev, if (lba_mode == CHS) { ide_channel_write(chan, ATA_REG_HDDEVSEL, 0xA0 | (dev->drive_idx << 4) | head); - } else { + } else if (lba_mode == LBA28) { ide_channel_write(chan, ATA_REG_HDDEVSEL, 0xE0 | (dev->drive_idx << 4) | head); + } else { + ide_channel_write(chan, ATA_REG_HDDEVSEL, + 0x40 | (dev->drive_idx << 4)); } // write Parameters - if (lba_mode == 2) { - ide_channel_write(chan, ATA_REG_SECCOUNT1, 0); + if (lba_mode == LBA48) { + ide_channel_write(chan, ATA_REG_SECCOUNT1, (numsects >> 8) & 0xff); ide_channel_write(chan, ATA_REG_LBA3, lba_io[3]); ide_channel_write(chan, ATA_REG_LBA4, lba_io[4]); ide_channel_write(chan, ATA_REG_LBA5, lba_io[5]); } - ide_channel_write(chan, ATA_REG_SECCOUNT0, numsects); + ide_channel_write(chan, ATA_REG_SECCOUNT0, numsects & 0xff); ide_channel_write(chan, ATA_REG_LBA0, lba_io[0]); ide_channel_write(chan, ATA_REG_LBA1, lba_io[1]); ide_channel_write(chan, ATA_REG_LBA2, lba_io[2]); @@ -624,7 +627,7 @@ static enum ide_error ide_device_ata_access(struct ide_device *dev, } enum ide_error ide_device_read_sectors(ide_device_t dev_identifier, - uint8_t numsects, uint32_t lba, + uint16_t numsects, uint32_t lba, uint16_t buf[numsects * 256]) { struct ide_device *dev = device(dev_identifier); @@ -656,7 +659,7 @@ enum ide_error ide_device_read_sectors(ide_device_t dev_identifier, } enum ide_error ide_device_write_sectors(ide_device_t device_identifier, - uint8_t numsects, uint32_t lba, + uint16_t numsects, uint32_t lba, uint16_t buf[numsects * 256]) { struct ide_device *dev = device(device_identifier); -- cgit v1.2.3-freya From 91fb39db553dea9d07bb124f38c83460abc48d21 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 27 Apr 2025 16:11:54 -0400 Subject: fmt --- kernel/drivers/ata.c | 3 +-- kernel/include/comus/asm.h | 5 ++++- kernel/syscall.c | 6 ++---- user/apple.c | 7 +++++-- 4 files changed, 12 insertions(+), 9 deletions(-) (limited to 'kernel/drivers/ata.c') diff --git a/kernel/drivers/ata.c b/kernel/drivers/ata.c index 022ec81..6c8de86 100644 --- a/kernel/drivers/ata.c +++ b/kernel/drivers/ata.c @@ -569,8 +569,7 @@ static enum ide_error ide_device_ata_access(struct ide_device *dev, ide_channel_write(chan, ATA_REG_HDDEVSEL, 0xE0 | (dev->drive_idx << 4) | head); } else { - ide_channel_write(chan, ATA_REG_HDDEVSEL, - 0x40 | (dev->drive_idx << 4)); + ide_channel_write(chan, ATA_REG_HDDEVSEL, 0x40 | (dev->drive_idx << 4)); } // write Parameters diff --git a/kernel/include/comus/asm.h b/kernel/include/comus/asm.h index a6a8a45..4f376b1 100644 --- a/kernel/include/comus/asm.h +++ b/kernel/include/comus/asm.h @@ -36,7 +36,10 @@ static inline uint16_t inw(uint16_t port) static inline void rep_inw(uint16_t port, uint16_t *buffer, size_t count) { - __asm__ volatile("rep insw" : "+D"(buffer), "+c"(count) : "d"(port) : "memory"); + __asm__ volatile("rep insw" + : "+D"(buffer), "+c"(count) + : "d"(port) + : "memory"); } static inline void outw(uint16_t port, uint16_t val) diff --git a/kernel/syscall.c b/kernel/syscall.c index 7a57353..11db5e5 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -13,8 +13,7 @@ #define ARG3(type, name) type name = (type)(current_pcb->regs->rdx) #define ARG4(type, name) type name = (type)(current_pcb->regs->rcx) -__attribute__((noreturn)) -static int sys_exit(void) +__attribute__((noreturn)) static int sys_exit(void) { ARG1(int, status); @@ -57,8 +56,7 @@ static int sys_write(void) return nbytes; } -__attribute__((noreturn)) -static int sys_poweroff(void) +__attribute__((noreturn)) static int sys_poweroff(void) { // TODO: we should probably // kill all user processes diff --git a/user/apple.c b/user/apple.c index d0a5cc4..000718c 100644 --- a/user/apple.c +++ b/user/apple.c @@ -8,7 +8,7 @@ INCBIN(APPLE, "data/apple.bin"); #define APPLE_WIDTH 256 #define APPLE_HEIGHT 144 #define APPLE_FPS 12 -#define APPLE_FRAMES 5259 +#define APPLE_FRAMES 2630 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -33,7 +33,10 @@ static void draw_frame(void) } } - frame = ((ticks() - ticks_off) / (1000 / APPLE_FPS)) % APPLE_FRAMES; + frame = ((ticks() - ticks_off) / (1000 / APPLE_FPS)); + + if (frame >= APPLE_FRAMES) + exit(0); } int main(void) -- cgit v1.2.3-freya