Skip to content

Commit

Permalink
Use "FARPTR" consistently in macros.
Browse files Browse the repository at this point in the history
Rename MAKE_32_PTR to MAKE_FARPTR.
Rename PTR_TO_SEG to FARPTR_TO_SEG.
Rename PTR_TO_OFFSET to FARPTR_TO_OFFSET.
  • Loading branch information
KevinOConnor committed Mar 23, 2008
1 parent fad2da8 commit 070231b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/ata.c
Expand Up @@ -306,7 +306,7 @@ ata_cmd_packet(u16 biosid, u8 *cmdbuf, u8 cmdlen
SET_EBDA(ata.trsfbytes,0L);

// Send command to device
outsw_far(iobase1, MAKE_32_PTR(GET_SEG(SS), (u32)cmdbuf), cmdlen / 2);
outsw_far(iobase1, MAKE_FARPTR(GET_SEG(SS), (u32)cmdbuf), cmdlen / 2);

u8 status;
u16 loops = 0;
Expand Down Expand Up @@ -495,7 +495,7 @@ init_drive_atapi(u8 devid)
memset(buffer, 0, sizeof(buffer));
u16 ret = ata_cmd_data(devid, ATA_CMD_IDENTIFY_DEVICE_PACKET
, 1, 1
, MAKE_32_PTR(GET_SEG(SS), (u32)buffer));
, MAKE_FARPTR(GET_SEG(SS), (u32)buffer));
if (ret != 0)
BX_PANIC("ata-detect: Failed to detect ATAPI device\n");

Expand Down Expand Up @@ -536,7 +536,7 @@ init_drive_ata(u8 devid)
memset(buffer, 0, sizeof(buffer));
u16 ret = ata_cmd_data(devid, ATA_CMD_IDENTIFY_DEVICE
, 1, 1
, MAKE_32_PTR(GET_SEG(SS), (u32)buffer));
, MAKE_FARPTR(GET_SEG(SS), (u32)buffer));
if (ret)
BX_PANIC("ata-detect: Failed to detect ATA device\n");

Expand Down
10 changes: 5 additions & 5 deletions src/cdrom.c
Expand Up @@ -297,7 +297,7 @@ atapi_get_sense(u16 device, u8 *asc, u8 *ascq)
atacmd[4] = sizeof(buffer);
u16 ret = ata_cmd_packet(device, atacmd, sizeof(atacmd)
, 0, sizeof(buffer)
, MAKE_32_PTR(GET_SEG(SS), (u32)buffer));
, MAKE_FARPTR(GET_SEG(SS), (u32)buffer));
if (ret != 0)
return 0x0002;

Expand Down Expand Up @@ -334,7 +334,7 @@ atapi_is_ready(u16 device)
}
u16 ret = ata_cmd_packet(device, packet, sizeof(packet)
, 0, sizeof(buf)
, MAKE_32_PTR(GET_SEG(SS), (u32)buf));
, MAKE_FARPTR(GET_SEG(SS), (u32)buf));
if (ret == 0)
break;

Expand Down Expand Up @@ -432,7 +432,7 @@ cdrom_boot()
// Read the Boot Record Volume Descriptor
u8 buffer[2048];
ret = cdrom_read(device, 0x11, 2048
, MAKE_32_PTR(GET_SEG(SS), (u32)buffer), 0);
, MAKE_FARPTR(GET_SEG(SS), (u32)buffer), 0);
if (ret)
return 3;

Expand All @@ -447,7 +447,7 @@ cdrom_boot()

// And we read the Boot Catalog
ret = cdrom_read(device, lba, 2048
, MAKE_32_PTR(GET_SEG(SS), (u32)buffer), 0);
, MAKE_FARPTR(GET_SEG(SS), (u32)buffer), 0);
if (ret)
return 7;

Expand Down Expand Up @@ -485,7 +485,7 @@ cdrom_boot()

// And we read the image in memory
ret = cdrom_read(device, lba, nbsectors*512
, MAKE_32_PTR(boot_segment, 0), 0);
, MAKE_FARPTR(boot_segment, 0), 0);
if (ret)
return 12;

Expand Down
8 changes: 4 additions & 4 deletions src/disk.c
Expand Up @@ -78,7 +78,7 @@ basic_access(struct bregs *regs, u8 device, u16 command)
+ (u32)sector - 1);
irq_enable();
u8 status = ata_cmd_data(device, command, lba, count
, MAKE_32_PTR(segment, offset));
, MAKE_FARPTR(segment, offset));
irq_disable();

// Set nb of sector transferred
Expand Down Expand Up @@ -139,7 +139,7 @@ emu_access(struct bregs *regs, u8 device, u16 command)

irq_enable();
u8 status = cdrom_read(device, lba, count*512
, MAKE_32_PTR(segment, offset), before*512);
, MAKE_FARPTR(segment, offset), before*512);
irq_disable();
if (status != 0) {
BX_INFO("int13_harddisk: function %02x, error %02x !\n"
Expand Down Expand Up @@ -189,10 +189,10 @@ extended_access(struct bregs *regs, u8 device, u16 command)
u8 status;
if (type == ATA_TYPE_ATA)
status = ata_cmd_data(device, command, lba, count
, MAKE_32_PTR(segment, offset));
, MAKE_FARPTR(segment, offset));
else
status = cdrom_read(device, lba, count*2048
, MAKE_32_PTR(segment, offset), 0);
, MAKE_FARPTR(segment, offset), 0);

irq_disable();

Expand Down
32 changes: 16 additions & 16 deletions src/farptr.h
Expand Up @@ -95,9 +95,9 @@ extern void __force_link_error__unknown_type();

// Macros for converting to/from 32bit style pointers to their
// equivalent 16bit segment/offset values.
#define PTR_TO_SEG(p) (((u32)(p)) >> 4)
#define PTR_TO_OFFSET(p) (((u32)(p)) & 0xf)
#define MAKE_32_PTR(seg,off) ((void*)(((seg)<<4)+(off)))
#define FARPTR_TO_SEG(p) (((u32)(p)) >> 4)
#define FARPTR_TO_OFFSET(p) (((u32)(p)) & 0xf)
#define MAKE_FARPTR(seg,off) ((void*)(((seg)<<4)+(off)))


#ifdef MODE16
Expand All @@ -113,35 +113,35 @@ extern void __force_link_error__unknown_type();
#define SET_FARPTR(ptr, val) __SET_FARPTR((ptr), (val))

static inline void insb_far(u16 port, void *farptr, u16 count) {
SET_SEG(ES, PTR_TO_SEG(farptr));
insb(port, (u8*)PTR_TO_OFFSET(farptr), count);
SET_SEG(ES, FARPTR_TO_SEG(farptr));
insb(port, (u8*)FARPTR_TO_OFFSET(farptr), count);
}
static inline void insw_far(u16 port, void *farptr, u16 count) {
SET_SEG(ES, PTR_TO_SEG(farptr));
insw(port, (u16*)PTR_TO_OFFSET(farptr), count);
SET_SEG(ES, FARPTR_TO_SEG(farptr));
insw(port, (u16*)FARPTR_TO_OFFSET(farptr), count);
}
static inline void insl_far(u16 port, void *farptr, u16 count) {
SET_SEG(ES, PTR_TO_SEG(farptr));
insl(port, (u32*)PTR_TO_OFFSET(farptr), count);
SET_SEG(ES, FARPTR_TO_SEG(farptr));
insl(port, (u32*)FARPTR_TO_OFFSET(farptr), count);
}
static inline void outsb_far(u16 port, void *farptr, u16 count) {
SET_SEG(ES, PTR_TO_SEG(farptr));
outsb(port, (u8*)PTR_TO_OFFSET(farptr), count);
SET_SEG(ES, FARPTR_TO_SEG(farptr));
outsb(port, (u8*)FARPTR_TO_OFFSET(farptr), count);
}
static inline void outsw_far(u16 port, void *farptr, u16 count) {
SET_SEG(ES, PTR_TO_SEG(farptr));
outsw(port, (u16*)PTR_TO_OFFSET(farptr), count);
SET_SEG(ES, FARPTR_TO_SEG(farptr));
outsw(port, (u16*)FARPTR_TO_OFFSET(farptr), count);
}
static inline void outsl_far(u16 port, void *farptr, u16 count) {
SET_SEG(ES, PTR_TO_SEG(farptr));
outsl(port, (u32*)PTR_TO_OFFSET(farptr), count);
SET_SEG(ES, FARPTR_TO_SEG(farptr));
outsl(port, (u32*)FARPTR_TO_OFFSET(farptr), count);
}

#else

// In 32-bit mode there is no need to mess with the segments.
#define GET_FARVAR(seg, var) \
(*((typeof(&(var)))MAKE_32_PTR((seg), (u32)&(var))))
(*((typeof(&(var)))MAKE_FARPTR((seg), (u32)&(var))))
#define SET_FARVAR(seg, var, val) \
do { GET_FARVAR((seg), (var)) = (val); } while (0)
#define GET_VAR(seg, var) (var)
Expand Down
6 changes: 3 additions & 3 deletions src/post.c
Expand Up @@ -330,7 +330,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
Expand All @@ -351,11 +351,11 @@ rom_scan(u32 start, u32 end)

struct ipl_entry_s *ip = &ipl->table[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 = (FARPTR_TO_SEG(rom) << 16) | desc;

ipl->count++;
}
Expand Down

0 comments on commit 070231b

Please sign in to comment.