]> xenbits.xensource.com Git - seabios.git/commitdiff
Rework disk.c:fillLCHS to avoid using pointer parameters.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 27 May 2012 14:45:32 +0000 (10:45 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 31 May 2012 01:05:33 +0000 (21:05 -0400)
The compiler does a better job when passing parameters by value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/disk.c
src/disk.h

index ed54e97de195b5d9edc048818c1ebb2426cf2575..3ca56971e31802adb7bcad6a469a2c3d19cc826e 100644 (file)
@@ -55,23 +55,25 @@ __disk_stub(struct bregs *regs, int lineno, const char *fname)
     __disk_stub((regs), __LINE__, __func__)
 
 // Get the cylinders/heads/sectors for the given drive.
-static void
-fillLCHS(struct drive_s *drive_g, u16 *nlc, u16 *nlh, u16 *nlspt)
+static struct chs_s
+getLCHS(struct drive_s *drive_g)
 {
+    struct chs_s res = { };
     if (CONFIG_CDROM_EMU
         && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf))) {
         // Emulated drive - get info from CDEmu.  (It's not possible to
         // populate the geometry directly in the driveid because the
         // geometry is only known after the bios segment is made
         // read-only).
-        *nlc = GET_LOW(CDEmu.lchs.cylinders);
-        *nlh = GET_LOW(CDEmu.lchs.heads);
-        *nlspt = GET_LOW(CDEmu.lchs.spt);
-        return;
+        res.cylinders = GET_LOW(CDEmu.lchs.cylinders);
+        res.heads = GET_LOW(CDEmu.lchs.heads);
+        res.spt = GET_LOW(CDEmu.lchs.spt);
+        return res;
     }
-    *nlc = GET_GLOBAL(drive_g->lchs.cylinders);
-    *nlh = GET_GLOBAL(drive_g->lchs.heads);
-    *nlspt = GET_GLOBAL(drive_g->lchs.spt);
+    res.cylinders = GET_GLOBAL(drive_g->lchs.cylinders);
+    res.heads = GET_GLOBAL(drive_g->lchs.heads);
+    res.spt = GET_GLOBAL(drive_g->lchs.spt);
+    return res;
 }
 
 // Perform read/write/verify using old-style chs accesses
@@ -94,8 +96,8 @@ basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
     }
     dop.count = count;
 
-    u16 nlc, nlh, nlspt;
-    fillLCHS(drive_g, &nlc, &nlh, &nlspt);
+    struct chs_s chs = getLCHS(drive_g);
+    u16 nlc=chs.cylinders, nlh=chs.heads, nlspt=chs.spt;
 
     // sanity check on cyl heads, sec
     if (cylinder >= nlc || head >= nlh || sector > nlspt) {
@@ -206,8 +208,8 @@ disk_1305(struct bregs *regs, struct drive_s *drive_g)
 {
     debug_stub(regs);
 
-    u16 nlc, nlh, nlspt;
-    fillLCHS(drive_g, &nlc, &nlh, &nlspt);
+    struct chs_s chs = getLCHS(drive_g);
+    u16 nlh=chs.heads, nlspt=chs.spt;
 
     u8 num_sectors = regs->al;
     u8 head        = regs->dh;
@@ -232,8 +234,8 @@ static void noinline
 disk_1308(struct bregs *regs, struct drive_s *drive_g)
 {
     // Get logical geometry from table
-    u16 nlc, nlh, nlspt;
-    fillLCHS(drive_g, &nlc, &nlh, &nlspt);
+    struct chs_s chs = getLCHS(drive_g);
+    u16 nlc=chs.cylinders, nlh=chs.heads, nlspt=chs.spt;
     nlc--;
     nlh--;
     u8 count;
@@ -340,8 +342,8 @@ disk_1315(struct bregs *regs, struct drive_s *drive_g)
     // Hard drive
 
     // Get logical geometry from table
-    u16 nlc, nlh, nlspt;
-    fillLCHS(drive_g, &nlc, &nlh, &nlspt);
+    struct chs_s chs = getLCHS(drive_g);
+    u16 nlc=chs.cylinders, nlh=chs.heads, nlspt=chs.spt;
 
     // Compute sector count seen by int13
     u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nlspt;
index 68e866d4f38c986763df06ff8b8882d86b961429..6776ee636d974940829b271c3899d03c0de295c9 100644 (file)
@@ -186,6 +186,7 @@ struct chs_s {
     u16 heads;      // # heads
     u16 cylinders;  // # cylinders
     u16 spt;        // # sectors / track
+    u16 pad;
 };
 
 // ElTorito Device Emulation data