return 512;
}
+static int ata_pio_inited = 0;
+
int ata_pio_init_primary_master(void) {
+ if (ata_pio_inited) return 0;
+
// Register IRQ 14 handler early to prevent INTRQ storm
register_interrupt_handler(46, ata_pio_irq14_handler);
kprintf("[ATA] Using PIO mode (DMA unavailable).\n");
}
+ ata_pio_inited = 1;
return 0;
}
#include "keyboard.h"
#include "console.h"
+#include "ata_pio.h"
#include "hal/mm.h"
#include <stddef.h>
(void)vfs_mount("/persist", persist);
}
- fs_node_t* disk = diskfs_create_root();
- if (disk) {
- (void)vfs_mount("/disk", disk);
- }
-
fs_node_t* proc = procfs_create_root();
if (proc) {
(void)vfs_mount("/proc", proc);
}
- /* Probe second IDE disk partition (LBA 0) for FAT or ext2.
- * The primary disk is used by diskfs; a second partition could
- * be formatted as FAT or ext2 and mounted at /mnt. */
- {
- fs_node_t* fatfs = fat_mount(0);
- if (fatfs) {
- (void)vfs_mount("/fat", fatfs);
+ /* Probe the ATA primary master disk and mount the appropriate
+ * filesystem. ext2, FAT, and diskfs are mutually exclusive on
+ * the same device — we probe in order of specificity so that
+ * diskfs auto-format never overwrites a recognized filesystem.
+ *
+ * Probe order: ext2 (magic 0xEF53), FAT (BPB validation), diskfs.
+ * If neither ext2 nor FAT is detected, diskfs initializes and may
+ * auto-format the disk. */
+ if (ata_pio_init_primary_master() == 0) {
+ int disk_mounted = 0;
+
+ /* 1. Try ext2 — superblock at byte 1024 (LBA 2), magic at offset 56 */
+ {
+ fs_node_t* ext2fs = ext2_mount(0);
+ if (ext2fs) {
+ (void)vfs_mount("/ext2", ext2fs);
+ disk_mounted = 1;
+ }
}
- }
- {
- fs_node_t* ext2fs = ext2_mount(0);
- if (ext2fs) {
- (void)vfs_mount("/ext2", ext2fs);
+
+ /* 2. Try FAT — BPB at LBA 0 */
+ if (!disk_mounted) {
+ fs_node_t* fatfs = fat_mount(0);
+ if (fatfs) {
+ (void)vfs_mount("/fat", fatfs);
+ disk_mounted = 1;
+ }
+ }
+
+ /* 3. Fallback to diskfs (may auto-format blank/unrecognized disks) */
+ if (!disk_mounted) {
+ fs_node_t* disk = diskfs_create_root();
+ if (disk) {
+ (void)vfs_mount("/disk", disk);
+ }
}
}
void kconsole_enter(void) {
keyboard_set_callback(0);
- kc_puts("\n*** AdrOS Kernel Console (kconsole) ***\n");
- kc_puts("Type 'help' for available commands.\n");
+ kc_puts("\n[PANIC] Userspace init failed -- dropping to kconsole.\n");
+ kc_puts(" Type 'help' for commands, 'reboot' to restart.\n\n");
char line[KCMD_MAX];