aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2009-09-09 11:34:39 -0400
committerKevin O'Connor <kevin@koconnor.net>2009-09-09 11:34:39 -0400
commit9f985427ffeb877f6eb6531a61c0d51250bdf7f3 (patch)
tree6c4ef72950230409e2a3e4f9de2463894c83458b /src
parent372e071ed4b6a66fb371cf13b6f6d14ddd00837a (diff)
downloadseabios-9f985427ffeb877f6eb6531a61c0d51250bdf7f3.tar.gz
Replace common segment/offset pairs with struct segoff_s.
Introduce 'struct segoff_s' to more places.
Diffstat (limited to 'src')
-rw-r--r--src/asm-offsets.c2
-rw-r--r--src/biosvar.h25
-rw-r--r--src/block.c8
-rw-r--r--src/boot.c3
-rw-r--r--src/bregs.h5
-rw-r--r--src/clock.c12
-rw-r--r--src/disk.c4
-rw-r--r--src/disk.h4
-rw-r--r--src/farptr.h19
-rw-r--r--src/mouse.c8
-rw-r--r--src/optionroms.c3
-rw-r--r--src/output.c2
-rw-r--r--src/post.c4
-rw-r--r--src/resume.c14
-rw-r--r--src/romlayout.S2
-rw-r--r--src/util.c6
16 files changed, 61 insertions, 60 deletions
diff --git a/src/asm-offsets.c b/src/asm-offsets.c
index c3241512..5035cef8 100644
--- a/src/asm-offsets.c
+++ b/src/asm-offsets.c
@@ -20,7 +20,7 @@ void foo(void)
OFFSET(BREGS_esi, bregs, esi);
OFFSET(BREGS_edi, bregs, edi);
OFFSET(BREGS_flags, bregs, flags);
- OFFSET(BREGS_ip, bregs, ip);
+ OFFSET(BREGS_code, bregs, code);
COMMENT("BDA");
OFFSET(BDA_ebda_seg, bios_data_area_s, ebda_seg);
diff --git a/src/biosvar.h b/src/biosvar.h
index b200645f..d6a7a152 100644
--- a/src/biosvar.h
+++ b/src/biosvar.h
@@ -11,17 +11,6 @@
#include "config.h" // CONFIG_*
#include "disk.h" // struct chs_s
-struct segoff_s {
- union {
- struct {
- u16 offset;
- u16 seg;
- };
- u32 segoff;
- };
-};
-#define SEGOFF(s,o) ({struct segoff_s __so; __so.offset=(o); __so.seg=(s); __so;})
-
/****************************************************************
* Interupt vector table
@@ -33,8 +22,8 @@ struct rmode_IVT {
#define GET_IVT(vector) \
GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
-#define SET_IVT(vector, seg, off) \
- SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector].segoff, ((seg) << 16) | (off))
+#define SET_IVT(vector, segoff) \
+ SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector], segoff)
/****************************************************************
@@ -77,8 +66,7 @@ struct bios_data_area_s {
u16 crtc_address;
u8 video_msr;
u8 video_pal;
- u16 jump_ip;
- u16 jump_cs;
+ struct segoff_s jump;
u8 other_6b;
u32 timer_counter;
// 40:70
@@ -110,13 +98,12 @@ struct bios_data_area_s {
u8 floppy_track[2];
u8 kbd_mode;
u8 kbd_led;
- u32 ptr_user_wait_complete_flag;
+ struct segoff_s user_wait_complete_flag;
u32 user_wait_timeout;
// 40:A0
u8 rtc_wait_flag;
u8 other_a1[7];
- u16 video_savetable_ptr;
- u16 video_savetable_seg;
+ struct segoff_s video_savetable;
u8 other_ac[4];
// 40:B0
u8 other_b0[10];
@@ -204,7 +191,7 @@ struct fdpt_s {
struct extended_bios_data_area_s {
u8 size;
u8 reserved1[0x21];
- u32 far_call_pointer;
+ struct segoff_s far_call_pointer;
u8 mouse_flag1;
u8 mouse_flag2;
u8 mouse_data[0x08];
diff --git a/src/block.c b/src/block.c
index c96daaf6..3550dcdd 100644
--- a/src/block.c
+++ b/src/block.c
@@ -163,11 +163,11 @@ fill_fdpt(int driveid)
fdpt->checksum -= checksum(fdpt, sizeof(*fdpt));
if (driveid == 0)
- SET_IVT(0x41, get_ebda_seg()
- , offsetof(struct extended_bios_data_area_s, fdpt[0]));
+ SET_IVT(0x41, SEGOFF(get_ebda_seg(), offsetof(
+ struct extended_bios_data_area_s, fdpt[0])));
else
- SET_IVT(0x46, get_ebda_seg()
- , offsetof(struct extended_bios_data_area_s, fdpt[1]));
+ SET_IVT(0x46, SEGOFF(get_ebda_seg(), offsetof(
+ struct extended_bios_data_area_s, fdpt[1])));
}
// Map a drive (that was registered via add_bcv_hd)
diff --git a/src/boot.c b/src/boot.c
index 9a08d26b..af2a893b 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -323,8 +323,7 @@ call_boot_entry(u16 bootseg, u16 bootip, u8 bootdrv)
struct bregs br;
memset(&br, 0, sizeof(br));
- br.ip = bootip;
- br.cs = bootseg;
+ br.code = SEGOFF(bootseg, bootip);
// Set the magic number in ax and the boot drive in dl.
br.dl = bootdrv;
br.ax = 0xaa55;
diff --git a/src/bregs.h b/src/bregs.h
index e59a7f44..3042ab2e 100644
--- a/src/bregs.h
+++ b/src/bregs.h
@@ -21,6 +21,8 @@
#ifndef __ASSEMBLY__
+#include "farptr.h" // struct segoff_s
+
/****************************************************************
* Registers saved/restored in romlayout.S
****************************************************************/
@@ -42,8 +44,7 @@ struct bregs {
UREG(edx, dx, dh, dl);
UREG(ecx, cx, ch, cl);
UREG(eax, ax, ah, al);
- u16 ip;
- u16 cs;
+ struct segoff_s code;
u16 flags;
} PACKED;
diff --git a/src/clock.c b/src/clock.c
index c95f0a14..9009d49c 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -454,7 +454,7 @@ set_usertimer(u32 usecs, u16 seg, u16 offset)
// Interval not already set.
SET_BDA(rtc_wait_flag, RWS_WAIT_PENDING); // Set status byte.
- SET_BDA(ptr_user_wait_complete_flag, (seg << 16) | offset);
+ SET_BDA(user_wait_complete_flag, SEGOFF(seg, offset));
SET_BDA(user_wait_timeout, usecs);
// Turn on the Periodic Interrupt timer
@@ -561,11 +561,11 @@ handle_70()
u32 time = GET_BDA(user_wait_timeout); // Time left in microseconds.
if (time < 0x3D1) {
// Done waiting - write to specified flag byte.
- u32 segoff = GET_BDA(ptr_user_wait_complete_flag);
- u16 segment = segoff >> 16;
- u16 offset = segoff & 0xffff;
- u8 oldval = GET_FARVAR(segment, *(u8*)(offset+0));
- SET_FARVAR(segment, *(u8*)(offset+0), oldval | 0x80);
+ struct segoff_s segoff = GET_BDA(user_wait_complete_flag);
+ u16 ptr_seg = segoff.seg;
+ u8 *ptr_far = (u8*)(segoff.offset+0);
+ u8 oldval = GET_FARVAR(ptr_seg, *ptr_far);
+ SET_FARVAR(ptr_seg, *ptr_far, oldval | 0x80);
clear_usertimer();
} else {
diff --git a/src/disk.c b/src/disk.c
index 014701a4..b021c405 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -180,9 +180,7 @@ extended_access(struct bregs *regs, u8 driveid, u16 command)
return;
}
- u16 segment = GET_INT13EXT(regs, segment);
- u16 offset = GET_INT13EXT(regs, offset);
- dop.buf_fl = MAKE_FLATPTR(segment, offset);
+ dop.buf_fl = SEGOFF_TO_FLATPTR(GET_INT13EXT(regs, data));
dop.count = GET_INT13EXT(regs, count);
int status = send_disk_op(&dop);
diff --git a/src/disk.h b/src/disk.h
index 96bc509d..36941b71 100644
--- a/src/disk.h
+++ b/src/disk.h
@@ -8,6 +8,7 @@
#include "types.h" // u8
#include "config.h" // CONFIG_*
+#include "farptr.h" // struct segoff_s
#define DISK_RET_SUCCESS 0x00
#define DISK_RET_EPARAM 0x01
@@ -35,8 +36,7 @@ struct int13ext_s {
u8 size;
u8 reserved;
u16 count;
- u16 offset;
- u16 segment;
+ struct segoff_s data;
u64 lba;
} PACKED;
diff --git a/src/farptr.h b/src/farptr.h
index 1f3df9d2..acc9d596 100644
--- a/src/farptr.h
+++ b/src/farptr.h
@@ -190,4 +190,23 @@ extern void __force_link_error__only_in_16bit() __attribute__ ((noreturn));
#endif
+// Definition for common 16bit segment/offset pointers.
+struct segoff_s {
+ union {
+ struct {
+ u16 offset;
+ u16 seg;
+ };
+ u32 segoff;
+ };
+};
+#define SEGOFF(s,o) ({struct segoff_s __so; __so.offset=(o); __so.seg=(s); __so;})
+
+static inline struct segoff_s FLATPTR_TO_SEGOFF(void *p) {
+ return SEGOFF(FLATPTR_TO_SEG(p), FLATPTR_TO_OFFSET(p));
+}
+static inline void *SEGOFF_TO_FLATPTR(struct segoff_s so) {
+ return MAKE_FLATPTR(so.seg, so.offset);
+}
+
#endif // farptr.h
diff --git a/src/mouse.c b/src/mouse.c
index e6abbb9a..e7ec0c17 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -235,10 +235,10 @@ mouse_15c206(struct bregs *regs)
static void
mouse_15c207(struct bregs *regs)
{
- u32 farptr = (regs->es << 16) | regs->bx;
+ struct segoff_s farptr = SEGOFF(regs->es, regs->bx);
u16 ebda_seg = get_ebda_seg();
u8 mouse_flags_2 = GET_EBDA2(ebda_seg, mouse_flag2);
- if (! farptr) {
+ if (! farptr.segoff) {
/* remove handler */
if ((mouse_flags_2 & 0x80) != 0) {
mouse_flags_2 &= ~0x80;
@@ -311,7 +311,7 @@ process_mouse(u8 data)
u16 Y = GET_EBDA2(ebda_seg, mouse_data[2]);
SET_EBDA2(ebda_seg, mouse_flag1, 0);
- u32 func = GET_EBDA2(ebda_seg, far_call_pointer);
+ struct segoff_s func = GET_EBDA2(ebda_seg, far_call_pointer);
asm volatile(
"sti\n"
@@ -327,7 +327,7 @@ process_mouse(u8 data)
"cli\n"
"cld\n"
:
- : "r"(func), "r"(status), "r"(X), "r"(Y)
+ : "r"(func.segoff), "r"(status), "r"(X), "r"(Y)
: "cc"
);
}
diff --git a/src/optionroms.c b/src/optionroms.c
index 0a5d85c1..cd8f9d1a 100644
--- a/src/optionroms.c
+++ b/src/optionroms.c
@@ -92,8 +92,7 @@ __callrom(struct rom_header *rom, u16 offset, u16 bdf)
br.dx = 0xffff;
br.es = SEG_BIOS;
br.di = get_pnp_offset();
- br.cs = seg;
- br.ip = offset;
+ br.code = SEGOFF(seg, offset);
call16big(&br);
debug_serial_setup();
diff --git a/src/output.c b/src/output.c
index 1cd0b8cb..6a164e1e 100644
--- a/src/output.c
+++ b/src/output.c
@@ -327,7 +327,7 @@ dump_regs(struct bregs *regs)
, regs->ds, regs->es, GET_SEG(SS));
dprintf(1, " si=%08x di=%08x bp=%08x sp=%08x cs=%04x ip=%04x f=%04x\n"
, regs->esi, regs->edi, regs->ebp, (u32)&regs[1]
- , regs->cs, regs->ip, regs->flags);
+ , regs->code.seg, regs->code.offset, regs->flags);
}
// Report entry to an Interrupt Service Routine (ISR).
diff --git a/src/post.c b/src/post.c
index 69aeb93c..7edd1f61 100644
--- a/src/post.c
+++ b/src/post.c
@@ -23,7 +23,7 @@
void
__set_irq(int vector, void *loc)
{
- SET_IVT(vector, SEG_BIOS, (u32)loc - BUILD_BIOS_ADDR);
+ SET_IVT(vector, SEGOFF(SEG_BIOS, (u32)loc - BUILD_BIOS_ADDR));
}
#define set_irq(vector, func) do { \
@@ -64,7 +64,7 @@ init_ivt()
// set vector 0x79 to zero
// this is used by 'gardian angel' protection system
- SET_IVT(0x79, 0, 0);
+ SET_IVT(0x79, SEGOFF(0, 0));
__set_irq(0x1E, &diskette_param_table2);
}
diff --git a/src/resume.c b/src/resume.c
index cfe26cda..097bb6f3 100644
--- a/src/resume.c
+++ b/src/resume.c
@@ -60,12 +60,12 @@ handle_resume(u8 status)
eoi_pic2();
// NO BREAK
case 0x0a:
-#define BDA_JUMP_IP (((struct bios_data_area_s *)0)->jump_ip)
+#define BDA_JUMP (((struct bios_data_area_s *)0)->jump)
// resume execution by jump via 40h:0067h
asm volatile(
"movw %w1, %%ds\n"
"ljmpw *%0\n"
- : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
+ : : "m"(BDA_JUMP), "r"(SEG_BDA)
);
break;
@@ -75,7 +75,7 @@ handle_resume(u8 status)
"movw %w1, %%ds\n"
"lssw %0, %%sp\n"
"iretw\n"
- : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
+ : : "m"(BDA_JUMP), "r"(SEG_BDA)
);
break;
@@ -85,7 +85,7 @@ handle_resume(u8 status)
"movw %w1, %%ds\n"
"lssw %0, %%sp\n"
"lretw\n"
- : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
+ : : "m"(BDA_JUMP), "r"(SEG_BDA)
);
break;
}
@@ -115,13 +115,11 @@ s3_resume()
memset(&br, 0, sizeof(br));
if (s3_resume_vector) {
dprintf(1, "Jump to resume vector (%x)\n", s3_resume_vector);
- br.ip = FLATPTR_TO_OFFSET(s3_resume_vector);
- br.cs = FLATPTR_TO_SEG(s3_resume_vector);
+ br.code = FLATPTR_TO_SEGOFF((void*)s3_resume_vector);
} else {
dprintf(1, "No resume vector set!\n");
// Jump to the post vector to restart with a normal boot.
- br.ip = (u32)reset_vector - BUILD_BIOS_ADDR;
- br.cs = SEG_BIOS;
+ br.code = SEGOFF(SEG_BIOS, (u32)reset_vector - BUILD_BIOS_ADDR);
}
call16big(&br);
}
diff --git a/src/romlayout.S b/src/romlayout.S
index d430d287..1bbdd9ca 100644
--- a/src/romlayout.S
+++ b/src/romlayout.S
@@ -152,7 +152,7 @@ __call16:
pushw %cs
pushw $1f // return point
pushw BREGS_flags(%eax) // flags
- pushl BREGS_ip(%eax) // CS:IP
+ pushl BREGS_code(%eax) // CS:IP
// Load calling registers.
movl BREGS_edi(%eax), %edi
diff --git a/src/util.c b/src/util.c
index 283ec088..841c00a7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -42,10 +42,10 @@ inline void
__call16_int(struct bregs *callregs, u16 offset)
{
if (MODE16)
- callregs->cs = GET_SEG(CS);
+ callregs->code.seg = GET_SEG(CS);
else
- callregs->cs = SEG_BIOS;
- callregs->ip = offset;
+ callregs->code.seg = SEG_BIOS;
+ callregs->code.offset = offset;
call16(callregs);
}