Move floppy setup code from post.c to floppy.c.
[seabios.git] / src / post.c
index c5dbaf3bed2b89236c924da53265439b667f6497..f8a3de9aa21ff01986b47b05f52ee1bf726d2ced 100644 (file)
 #include "cmos.h" // CMOS_*
 #include "util.h" // memset
 #include "biosvar.h" // struct bios_data_area_s
-#include "ata.h"
-#include "kbd.h"
+#include "ata.h" // ata_detect
+#include "kbd.h" // kbd_setup
+#include "disk.h" // floppy_drive_setup
 
-#define bda ((struct bios_data_area_s *)0)
-#define ebda ((struct extended_bios_data_area_s *)(EBDA_SEG<<4))
-#define ipl ((struct ipl_s *)(IPL_SEG<<4))
-
-static u8
-checksum(u8 *p, u32 len)
-{
-    u32 i;
-    u8 sum = 0;
-    for (i=0; i<len; i++)
-        sum += p[i];
-    return sum;
-}
+#define bda ((struct bios_data_area_s *)MAKE_FARPTR(SEG_BDA, 0))
+#define ebda ((struct extended_bios_data_area_s *)MAKE_FARPTR(SEG_EBDA, 0))
 
 static void
 init_bda()
@@ -73,6 +63,8 @@ init_handlers()
     SET_BDA(ivecs[0x74].offset, OFFSET_entry_74);
     SET_BDA(ivecs[0x75].offset, OFFSET_entry_75);
     SET_BDA(ivecs[0x10].offset, OFFSET_entry_10);
+
+    SET_BDA(ivecs[0x1E].offset, OFFSET_diskette_param_table2);
 }
 
 static void
@@ -80,11 +72,11 @@ init_ebda()
 {
     memset(ebda, 0, sizeof(*ebda));
     ebda->size = EBDA_SIZE;
-    SET_BDA(ebda_seg, EBDA_SEG);
-    SET_BDA(ivecs[0x41].seg, EBDA_SEG);
+    SET_BDA(ebda_seg, SEG_EBDA);
+    SET_BDA(ivecs[0x41].seg, SEG_EBDA);
     SET_BDA(ivecs[0x41].offset
             , offsetof(struct extended_bios_data_area_s, fdpt0));
-    SET_BDA(ivecs[0x46].seg, EBDA_SEG);
+    SET_BDA(ivecs[0x46].seg, SEG_EBDA);
     SET_BDA(ivecs[0x41].offset
             , offsetof(struct extended_bios_data_area_s, fdpt1));
 }
@@ -191,21 +183,6 @@ pic_setup()
         outb(0x9f, PORT_PIC2_DATA);
 }
 
-static void
-floppy_drive_post()
-{
-    u8 type = inb_cmos(CMOS_FLOPPY_DRIVE_TYPE);
-    u8 out = 0;
-    if (type & 0xf0)
-        out |= 0x07;
-    if (type & 0x0f)
-        out |= 0x70;
-    SET_BDA(floppy_harddisk_info, out);
-    outb(0x02, PORT_DMA1_MASK_REG);
-
-    SET_BDA(ivecs[0x1E].offset, OFFSET_diskette_param_table2);
-}
-
 static void
 ata_init()
 {
@@ -259,13 +236,13 @@ fill_hdinfo(struct fdpt_s *info, u8 typecmos, u8 basecmos)
     }
     info->cylinders = cyl;
     info->heads = heads;
-    info->checksum = ~checksum((u8*)info, sizeof(*info)-1) + 1;
+    info->checksum = -checksum((u8*)info, sizeof(*info)-1);
 }
 
 static void
 hard_drive_post()
 {
-    outb(0x0a, 0x03f6); // 0000 1010 = reserved, disable IRQ 14
+    outb(0x0a, PORT_HD_DATA); // 0000 1010 = reserved, disable IRQ 14
     SET_BDA(disk_count, 1);
     SET_BDA(disk_control_byte, 0xc0);
 
@@ -277,18 +254,14 @@ hard_drive_post()
     if ((diskinfo & 0x0f) == 0x0f)
         // XXX - bochs halts on any other type
         // Fill EBDA table for hard disk 1.
-        fill_hdinfo(&ebda->fdpt0, CMOS_DISK_DRIVE2_TYPE, CMOS_DISK_DRIVE2_CYL);
+        fill_hdinfo(&ebda->fdpt1, CMOS_DISK_DRIVE2_TYPE, CMOS_DISK_DRIVE2_CYL);
 }
 
-
 static void
 init_boot_vectors()
 {
-    // Clear out the IPL table.
-    memset(ipl, 0, sizeof(*ipl));
-
     // Floppy drive
-    struct ipl_entry_s *ip = &ipl->table[0];
+    struct ipl_entry_s *ip = &ebda->ipl.table[0];
     ip->type = IPL_TYPE_FLOPPY;
     ip++;
 
@@ -302,8 +275,9 @@ init_boot_vectors()
         ip++;
     }
 
-    ipl->count = ip - ipl->table;
-    ipl->sequence = 0xffff;
+    ebda->ipl.count = ip - ebda->ipl.table;
+    ebda->ipl.sequence = 0xffff;
+    ebda->ipl.bootfirst = 0xffff;
 }
 
 static void
@@ -330,7 +304,7 @@ rom_scan(u32 start, u32 end)
         if (checksum(rom, len) != 0)
             continue;
         p = (u8*)(((u32)p + len) / 2048 * 2048);
-        callrom(PTR_TO_SEG(rom), PTR_TO_OFFSET(rom + 3));
+        callrom(FARPTR_TO_SEG(rom), FARPTR_TO_OFFSET(rom + 3));
 
         // Look at the ROM's PnP Expansion header.  Properly, we're supposed
         // to init all the ROMs and then go back and build an IPL table of
@@ -346,18 +320,18 @@ rom_scan(u32 start, u32 end)
         // Found a device that thinks it can boot the system.  Record
         // its BEV and product name string.
 
-        if (ipl->count >= ARRAY_SIZE(ipl->table))
+        if (ebda->ipl.count >= ARRAY_SIZE(ebda->ipl.table))
             continue;
 
-        struct ipl_entry_s *ip = &ipl->table[ipl->count];
+        struct ipl_entry_s *ip = &ebda->ipl.table[ebda->ipl.count];
         ip->type = IPL_TYPE_BEV;
-        ip->vector = (PTR_TO_SEG(rom) << 16) | entry;
+        ip->vector = (FARPTR_TO_SEG(rom) << 16) | entry;
 
         u16 desc = *(u16*)&rom[0x1a+0x10];
         if (desc)
-            ip->description = (PTR_TO_SEG(rom) << 16) | desc;
+            ip->description = (u32)MAKE_FARPTR(FARPTR_TO_SEG(rom), desc);
 
-        ipl->count++;
+        ebda->ipl.count++;
     }
 }
 
@@ -387,9 +361,7 @@ post()
 
     rombios32_init();
 
-    init_boot_vectors();
-
-    floppy_drive_post();
+    floppy_drive_setup();
     hard_drive_post();
     if (CONFIG_ATA) {
         ata_init();
@@ -400,6 +372,8 @@ post()
 
     rom_scan(0xc8000, 0xe0000);
 
+    interactive_bootmenu();
+
     // reset the memory (some boot loaders such as syslinux suppose
     // that the memory is set to zero)
     memset((void*)0x40000, 0, 0x40000); // XXX - shouldn't use globals