Initial cd emulation code.
[seabios.git] / src / post.c
index e566e83bb31e8ed97f726b5a8ff1cdb3d606d5cc..00361d7fe7e3f9f9b7b3379dc662dba063713946 100644 (file)
@@ -16,7 +16,7 @@
 #define ebda ((struct extended_bios_data_area_s *)(EBDA_SEG<<4))
 #define ipl ((struct ipl_s *)(IPL_SEG<<4))
 
-static int
+static u8
 checksum(u8 *p, u32 len)
 {
     u32 i;
@@ -33,7 +33,7 @@ init_bda()
 
     int i;
     for (i=0; i<256; i++) {
-        bda->ivecs[i].seg = 0xf000;
+        bda->ivecs[i].seg = SEG_BIOS;
         bda->ivecs[i].offset = OFFSET_dummy_iret_handler;
     }
 
@@ -108,7 +108,7 @@ static void
 kbd_wait(u8 mask, u8 code)
 {
     u16 max = 0xffff;
-    while ( ((inb(PORT_KBD_STATUS) & mask) == 0) && (--max>0) )
+    while ( ((inb(PORT_PS2_STATUS) & mask) == 0) && (--max>0) )
         outb(code, PORT_DIAG);
     if (!max)
         keyboard_panic(code);
@@ -137,8 +137,8 @@ keyboard_init()
     u16 max=0x2000;
     while (--max > 0) {
         outb(0x00, PORT_DIAG);
-        if (inb(PORT_KBD_STATUS) & 0x01) {
-            inb(PORT_KBD_DATA);
+        if (inb(PORT_PS2_STATUS) & 0x01) {
+            inb(PORT_PS2_DATA);
             max = 0x2000;
             }
         }
@@ -150,74 +150,74 @@ keyboard_init()
 
     /* ------------------- controller side ----------------------*/
     /* send cmd = 0xAA, self test 8042 */
-    outb(0xaa, PORT_KBD_STATUS);
+    outb(0xaa, PORT_PS2_STATUS);
 
     kbd_flush(0x00);
     kbd_waitdata(0x01);
 
     /* read self-test result, 0x55 should be returned from 0x60 */
-    if ((inb(PORT_KBD_DATA) != 0x55))
+    if (inb(PORT_PS2_DATA) != 0x55)
         keyboard_panic(991);
 
     /* send cmd = 0xAB, keyboard interface test */
-    outb(0xab, PORT_KBD_STATUS);
+    outb(0xab, PORT_PS2_STATUS);
 
     kbd_flush(0x10);
     kbd_waitdata(0x11);
 
     /* read keyboard interface test result, */
     /* 0x00 should be returned form 0x60 */
-    if ((inb(PORT_KBD_DATA) != 0x00))
+    if (inb(PORT_PS2_DATA) != 0x00)
         keyboard_panic(992);
 
     /* Enable Keyboard clock */
-    outb(0xae, PORT_KBD_STATUS);
-    outb(0xa8, PORT_KBD_STATUS);
+    outb(0xae, PORT_PS2_STATUS);
+    outb(0xa8, PORT_PS2_STATUS);
 
     /* ------------------- keyboard side ------------------------*/
     /* reset kerboard and self test  (keyboard side) */
-    outb(0xff, PORT_KBD_DATA);
+    outb(0xff, PORT_PS2_DATA);
 
     kbd_flush(0x20);
     kbd_waitdata(0x21);
 
     /* keyboard should return ACK */
-    if ((inb(PORT_KBD_DATA) != 0xfa))
+    if (inb(PORT_PS2_DATA) != 0xfa)
         keyboard_panic(993);
 
     kbd_waitdata(0x31);
 
-    if ((inb(PORT_KBD_DATA) != 0xaa))
+    if (inb(PORT_PS2_DATA) != 0xaa)
         keyboard_panic(994);
 
     /* Disable keyboard */
-    outb(0xf5, PORT_KBD_DATA);
+    outb(0xf5, PORT_PS2_DATA);
 
     kbd_flush(0x40);
     kbd_waitdata(0x41);
 
     /* keyboard should return ACK */
-    if ((inb(PORT_KBD_DATA) != 0xfa))
+    if (inb(PORT_PS2_DATA) != 0xfa)
         keyboard_panic(995);
 
     /* Write Keyboard Mode */
-    outb(0x60, PORT_KBD_STATUS);
+    outb(0x60, PORT_PS2_STATUS);
 
     kbd_flush(0x50);
 
     /* send cmd: scan code convert, disable mouse, enable IRQ 1 */
-    outb(0x61, PORT_KBD_DATA);
+    outb(0x61, PORT_PS2_DATA);
 
     kbd_flush(0x60);
 
     /* Enable keyboard */
-    outb(0xf4, PORT_KBD_DATA);
+    outb(0xf4, PORT_PS2_DATA);
 
     kbd_flush(0x70);
     kbd_waitdata(0x71);
 
     /* keyboard should return ACK */
-    if ((inb(PORT_KBD_DATA) != 0xfa))
+    if (inb(PORT_PS2_DATA) != 0xfa)
         keyboard_panic(996);
 
     outb(0x77, PORT_DIAG);
@@ -317,7 +317,7 @@ static void
 pic_setup()
 {
     outb(0x11, PORT_PIC1);
-    outb(0x11, PORT_PIC2_DATA);
+    outb(0x11, PORT_PIC2);
     outb(0x08, PORT_PIC1_DATA);
     outb(0x70, PORT_PIC2_DATA);
     outb(0x04, PORT_PIC1_DATA);
@@ -451,8 +451,8 @@ callrom(u16 seg, u16 offset)
 {
     struct bregs br;
     memset(&br, 0, sizeof(br));
-    br.es = 0xf000;
-    br.di = OFFSET_pnp_string;
+    br.es = SEG_BIOS;
+    br.di = OFFSET_pnp_string + 1; // starts 1 past for alignment
     br.cs = seg;
     br.ip = offset;
     call16(&br);
@@ -533,7 +533,7 @@ post()
     init_boot_vectors();
     rom_scan(0xc8000, 0xe0000);
 
-    callrom(0xf000, OFFSET_begin_boot);
+    callrom(SEG_BIOS, OFFSET_begin_boot);
 }
 
 static void
@@ -548,19 +548,6 @@ init_dma()
     outb(0x00, PORT_DMA2_MASK_REG);
 }
 
-static void
-eoi_jmp_post()
-{
-    // XXX - this is supposed to jump without changing any memory -
-    // but the stack has been altered by the time the code gets here.
-    eoi_both_pics();
-    struct bregs br;
-    memset(&br, 0, sizeof(br));
-    br.cs = bda->jump_cs_ip >> 16;
-    br.ip = bda->jump_cs_ip;
-    call16(&br);
-}
-
 static void
 check_restart_status()
 {
@@ -572,10 +559,19 @@ check_restart_status()
         // Normal post
         return;
 
-    if (status == 0x05)
-        eoi_jmp_post();
+    if (status != 0x05) {
+        BX_PANIC("Unimplemented shutdown status: %02x\n", status);
+        return;
+    }
 
-    BX_PANIC("Unimplemented shutdown status: %02x\n",(Bit8u)status);
+    // XXX - this is supposed to jump without changing any memory -
+    // but the stack has been altered by the time the code gets here.
+    eoi_both_pics();
+    struct bregs br;
+    memset(&br, 0, sizeof(br));
+    br.cs = bda->jump_cs_ip >> 16;
+    br.ip = bda->jump_cs_ip;
+    call16(&br);
 }
 
 void VISIBLE