]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
feat: multi-drive ATA support (4 drives) + fstab/mount command
authorTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 08:07:10 +0000 (05:07 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 08:07:10 +0000 (05:07 -0300)
commitf5cffcafbf3e927b3c2801f7e318b7aa1cdc45fc
tree7ac8008ea737bb28e57d354e11b293e3ee3d548b
parenta3698e075ca713d6fb57b330e48ea7b4f0ed5f23
feat: multi-drive ATA support (4 drives) + fstab/mount command

Major ATA driver refactoring:

1. ATA PIO driver (ata_pio.h, hal/x86/ata_pio.c):
   - Support all 4 ATA drives: primary/master (hda), primary/slave (hdb),
     secondary/master (hdc), secondary/slave (hdd)
   - New API: ata_pio_init() probes both channels, ata_pio_read28/write28
     take a drive ID parameter, ata_pio_drive_present() query
   - ata_name_to_drive/ata_drive_to_name helpers for device name mapping
   - Per-channel I/O ports (0x1F0/0x3F6 primary, 0x170/0x376 secondary)
   - Master/slave selection (0xE0/0xF0 LBA mode bits)
   - Floating bus detection (0xFF = no controller)
   - ATAPI rejection (non-zero LBA1/LBA2 after IDENTIFY)

2. ATA DMA driver (ata_dma.h, hal/x86/ata_dma.c):
   - Per-channel DMA state: separate PRDT, bounce buffer, spinlock, IRQ
     handler for primary (BAR4+0) and secondary (BAR4+8)
   - KVA map extended: 4 pages (PRDT+buf x 2 channels) at 0xC0320000-3
   - PCI Bus Master probe factored out and cached (single PCI lookup)
   - DMA-aware IRQ handlers for both IRQ 14 and IRQ 15

3. Filesystem drivers updated to accept drive parameter:
   - fat_mount(int drive, uint32_t lba) — stores drive in g_fat struct
   - ext2_mount(int drive, uint32_t lba) — stores drive in g_ext2 struct
   - diskfs_create_root(int drive) — static g_diskfs_drive for all I/O
   - persistfs_create_root(int drive) — delegates to diskfs on same drive

4. Mount system redesigned — no more auto-mount of disk FS:
   - init.c: calls ata_pio_init() once, then parses /etc/fstab
   - Fstab format: /dev/hdX  /mountpoint  fstype  options
   - init_mount_fs() helper reusable by both fstab and kconsole
   - rootfs/etc/fstab created with default diskfs+persistfs on hda

5. kconsole mount command:
   - 'mount -t <type> /dev/<hd> <mountpoint>' for manual mounting
   - 'lsblk' lists all 4 ATA drives and their detection status
   - Help text updated with new commands

6. Weak stubs updated for new API signatures (src/drivers/ata_pio.c)
7. Mount table increased from 8 to 16 slots (previous commit)

Build: clean, cppcheck: clean, smoke: 19/19 pass
20 files changed:
Makefile
include/ata_dma.h
include/ata_pio.h
include/diskfs.h
include/ext2.h
include/fat.h
include/kernel/init.h
include/kernel_va_map.h
include/persistfs.h
rootfs/etc/fstab [new file with mode: 0644]
src/drivers/ata_pio.c
src/hal/x86/ata_dma.c
src/hal/x86/ata_pio.c
src/kernel/diskfs.c
src/kernel/ext2.c
src/kernel/fat.c
src/kernel/init.c
src/kernel/kconsole.c
src/kernel/persistfs.c
tests/smoke_test.exp