Add FUNC16() helper macro for converting a 16bit func to a segoff_s.
authorKevin O'Connor <kevin@koconnor.net>
Thu, 29 Jul 2010 01:31:38 +0000 (21:31 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 29 Jul 2010 01:31:38 +0000 (21:31 -0400)
src/ata.c
src/biosvar.h
src/clock.c
src/floppy.c
src/misc.c
src/pic.h
src/post.c
src/ps2port.c

index 2e934beeb3a0e279bab48de0ff70964fe57733ca..e9a8df707fa5729a3652f67198e4c78be0ad6eb9 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -1038,5 +1038,5 @@ ata_setup(void)
 
     SET_BDA(disk_control_byte, 0xc0);
 
-    enable_hwirq(14, entry_76);
+    enable_hwirq(14, FUNC16(entry_76));
 }
index df0df0eba47939723f4be69e480ed4408ff6cd27..415f9581b8e5867bcbeb058e2e6b9d9c12ad5c9b 100644 (file)
@@ -25,6 +25,12 @@ struct rmode_IVT {
 #define SET_IVT(vector, segoff)                                         \
     SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector], segoff)
 
+#define FUNC16(func) ({                                 \
+        ASSERT32FLAT();                                 \
+        extern void func (void);                        \
+        SEGOFF(SEG_BIOS, (u32)func - BUILD_BIOS_ADDR);  \
+    })
+
 
 /****************************************************************
  * Bios Data Area (BDA)
index 6d46501dac054cf87781c16c7964b3e6892fbb91..f6a43e9eebda9908a556a1fef793d174b8cc6454 100644 (file)
@@ -213,8 +213,8 @@ timer_setup(void)
     SET_BDA(timer_counter, ticks);
     SET_BDA(timer_rollover, 0);
 
-    enable_hwirq(0, entry_08);
-    enable_hwirq(8, entry_70);
+    enable_hwirq(0, FUNC16(entry_08));
+    enable_hwirq(8, FUNC16(entry_70));
 }
 
 
index a8942cf02217ae17879eb251da431a59155194e9..6491b969acf03b3da63d4a6adaf5a89273a5de85 100644 (file)
@@ -139,7 +139,7 @@ floppy_setup(void)
 
     outb(0x02, PORT_DMA1_MASK_REG);
 
-    enable_hwirq(6, entry_0e);
+    enable_hwirq(6, FUNC16(entry_0e));
 }
 
 // Find a floppy type that matches a given image size.
index 5cb4a01602279b0c6d0b0a07fdc05f1ac3ce1b99..9db49e3820c3f7bde31be04f306d649bd99ac424 100644 (file)
@@ -66,7 +66,7 @@ mathcp_setup(void)
     dprintf(3, "math cp init\n");
     // 80x87 coprocessor installed
     SETBITS_BDA(equipment_list_flags, 0x02);
-    enable_hwirq(13, entry_75);
+    enable_hwirq(13, FUNC16(entry_75));
 }
 
 // INT 75 - IRQ13 - MATH COPROCESSOR EXCEPTION
index 586ef3831f78a04c8961232b52c627f02858252a..c75af3e665d08efffc93db87f4ad5099689cdf14 100644 (file)
--- a/src/pic.h
+++ b/src/pic.h
@@ -8,6 +8,7 @@
 #define __PIC_H
 
 #include "ioport.h" // PORT_PIC*
+#include "biosvar.h" // SET_IVT
 
 // PORT_PIC1 bitdefs
 #define PIC1_IRQ0  (1<<0)
@@ -76,11 +77,8 @@ get_pic2_isr(void)
     return inb(PORT_PIC2_CMD);
 }
 
-// post.c
-void __set_irq(int vector, void *loc);
-
 static inline void
-__enable_hwirq(int hwirq, void (*func)(void))
+enable_hwirq(int hwirq, struct segoff_s func)
 {
     int vector;
     if (hwirq < 8) {
@@ -90,14 +88,9 @@ __enable_hwirq(int hwirq, void (*func)(void))
         unmask_pic2(1 << (hwirq - 8));
         vector = 0x70 + hwirq - 8;
     }
-    __set_irq(vector, func);
+    SET_IVT(vector, func);
 }
 
-#define enable_hwirq(irq, func) do {            \
-        extern void func (void);                \
-        __enable_hwirq(irq, func);              \
-    } while (0)
-
 void set_pics(u8 irq0, u8 irq8);
 void pic_setup(void);
 
index 0cb9e575877aedb455b5f52607b2f738a8d0ba4f..56e5eb5bbd66896a285b57de949d9789b12e0da3 100644 (file)
 #include "ps2port.h" // ps2port_setup
 #include "virtio-blk.h" // virtio_blk_setup
 
-void
-__set_irq(int vector, void *loc)
-{
-    SET_IVT(vector, SEGOFF(SEG_BIOS, (u32)loc - BUILD_BIOS_ADDR));
-}
-
-#define set_irq(vector, func) do {              \
-        extern void func (void);                \
-        __set_irq(vector, func);                \
-    } while (0)
-
 static void
 init_ivt(void)
 {
@@ -44,28 +33,28 @@ init_ivt(void)
     // Initialize all vectors to the default handler.
     int i;
     for (i=0; i<256; i++)
-        set_irq(i, entry_iret_official);
+        SET_IVT(i, FUNC16(entry_iret_official));
 
     // Initialize all hw vectors to a default hw handler.
     for (i=0x08; i<=0x0f; i++)
-        set_irq(i, entry_hwpic1);
+        SET_IVT(i, FUNC16(entry_hwpic1));
     for (i=0x70; i<=0x77; i++)
-        set_irq(i, entry_hwpic2);
+        SET_IVT(i, FUNC16(entry_hwpic2));
 
     // Initialize software handlers.
-    set_irq(0x02, entry_02);
-    set_irq(0x10, entry_10);
-    set_irq(0x11, entry_11);
-    set_irq(0x12, entry_12);
-    set_irq(0x13, entry_13_official);
-    set_irq(0x14, entry_14);
-    set_irq(0x15, entry_15);
-    set_irq(0x16, entry_16);
-    set_irq(0x17, entry_17);
-    set_irq(0x18, entry_18);
-    set_irq(0x19, entry_19_official);
-    set_irq(0x1a, entry_1a);
-    set_irq(0x40, entry_40);
+    SET_IVT(0x02, FUNC16(entry_02));
+    SET_IVT(0x10, FUNC16(entry_10));
+    SET_IVT(0x11, FUNC16(entry_11));
+    SET_IVT(0x12, FUNC16(entry_12));
+    SET_IVT(0x13, FUNC16(entry_13_official));
+    SET_IVT(0x14, FUNC16(entry_14));
+    SET_IVT(0x15, FUNC16(entry_15));
+    SET_IVT(0x16, FUNC16(entry_16));
+    SET_IVT(0x17, FUNC16(entry_17));
+    SET_IVT(0x18, FUNC16(entry_18));
+    SET_IVT(0x19, FUNC16(entry_19_official));
+    SET_IVT(0x1a, FUNC16(entry_1a));
+    SET_IVT(0x40, FUNC16(entry_40));
 
     // INT 60h-66h reserved for user interrupt
     for (i=0x60; i<=0x66; i++)
@@ -75,7 +64,7 @@ init_ivt(void)
     // this is used by 'gardian angel' protection system
     SET_IVT(0x79, SEGOFF(0, 0));
 
-    __set_irq(0x1E, &diskette_param_table2);
+    SET_IVT(0x1E, SEGOFF(SEG_BIOS, (u32)&diskette_param_table2 - BUILD_BIOS_ADDR));
 }
 
 static void
@@ -277,9 +266,7 @@ _start(void)
     make_bios_readonly();
 
     // Disable bootsplash if something has hooked int19.
-    extern void entry_19_official(void);
-    if (GET_IVT(0x19).segoff
-        != SEGOFF(SEG_BIOS, (u32)entry_19_official - BUILD_BIOS_ADDR).segoff)
+    if (GET_IVT(0x19).segoff != FUNC16(entry_19_official).segoff)
         disable_bootsplash();
 
     // Invoke int 19 to start boot process.
index 5b73d23941ac8631120338f468d1f1be7e4934a7..ccbd2f698b59210057b3be59f16d413129e8b6f3 100644 (file)
@@ -453,8 +453,8 @@ ps2port_setup(void)
         return;
     dprintf(3, "init ps2port\n");
 
-    enable_hwirq(1, entry_09);
-    enable_hwirq(12, entry_74);
+    enable_hwirq(1, FUNC16(entry_09));
+    enable_hwirq(12, FUNC16(entry_74));
 
     run_thread(keyboard_init, NULL);
 }