[syslinux:master] core: define and use set_flags() helper

syslinux-bot for H. Peter Anvin hpa at linux.intel.com
Mon Jul 26 14:00:04 PDT 2010


Commit-ID:  9d9525aba8b8aece54b4c3b45245eb050e961ed5
Gitweb:     http://syslinux.zytor.com/commit/9d9525aba8b8aece54b4c3b45245eb050e961ed5
Author:     H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Mon, 26 Jul 2010 13:57:34 -0700
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Mon, 26 Jul 2010 13:57:34 -0700

core: define and use set_flags() helper

Rather than opencoding the arithmetic flag mask, define an inline to
make that happen properly.

Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>


---
 core/fs/fs.c        |    3 +--
 core/fs/loadhigh.c  |    9 ++++-----
 core/include/core.h |   13 +++++++++++++
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/core/fs/fs.c b/core/fs/fs.c
index d10f6a8..ad2fb37 100644
--- a/core/fs/fs.c
+++ b/core/fs/fs.c
@@ -86,8 +86,7 @@ void pm_load_config(com32sys_t *regs)
     if (err)
 	printf("ERROR: No configuration file found\n");
 
-    regs->eflags.l &= ~(EFLAGS_ZF | EFLAGS_CF);
-    regs->eflags.l |= err ? EFLAGS_ZF : 0;
+    set_flags(regs, err ? EFLAGS_ZF : 0);
 }
 
 void pm_mangle_name(com32sys_t *regs)
diff --git a/core/fs/loadhigh.c b/core/fs/loadhigh.c
index e365b1a..bd9d353 100644
--- a/core/fs/loadhigh.c
+++ b/core/fs/loadhigh.c
@@ -50,6 +50,7 @@ void pm_load_high(com32sys_t *regs)
     struct file *file;
     uint32_t sector_mask;
     size_t pad;
+    uint32_t retflags = 0;
 
     bytes     = regs->eax.l;
     zero_mask = regs->edx.w[0];
@@ -58,9 +59,6 @@ void pm_load_high(com32sys_t *regs)
     file      = handle_to_file(regs->esi.w[0]);
     fs        = file->fs;
 
-    regs->eflags.l &= ~(EFLAGS_CF|EFLAGS_OF|EFLAGS_AF|
-			EFLAGS_PF|EFLAGS_ZF|EFLAGS_SF);
-
     sector_mask = SECTOR_SIZE(fs) - 1;
 
     while (bytes) {
@@ -69,7 +67,7 @@ void pm_load_high(com32sys_t *regs)
 
 	if (buf + SECTOR_SIZE(fs) > limit) {
 	    /* Can't fit even one more sector in... */
-	    regs->eflags.l |= EFLAGS_OF;
+	    retflags = EFLAGS_OF;
 	    break;
 	}
 
@@ -99,7 +97,7 @@ void pm_load_high(com32sys_t *regs)
 	     */
 	    _close_file(file);
 	    regs->esi.w[0] = 0;
-	    regs->eflags.l |= EFLAGS_CF;
+	    retflags = EFLAGS_CF;
 	    break;
 	}
     }
@@ -110,4 +108,5 @@ void pm_load_high(com32sys_t *regs)
 
     regs->ebx.l = (size_t)buf;
     regs->edi.l = (size_t)buf + pad;
+    set_flags(regs, retflags);
 }
diff --git a/core/include/core.h b/core/include/core.h
index 7db5daf..114b049 100644
--- a/core/include/core.h
+++ b/core/include/core.h
@@ -75,4 +75,17 @@ static inline uint32_t ms_timer(void)
     return __ms_timer;
 }
 
+/*
+ * Helper routine to return a specific set of flags
+ */
+static inline void set_flags(com32sys_t *regs, uint32_t flags)
+{
+    uint32_t eflags;
+
+    eflags = regs->eflags.l;
+    eflags &= ~(EFLAGS_CF|EFLAGS_PF|EFLAGS_AF|EFLAGS_ZF|EFLAGS_SF|EFLAGS_OF);
+    eflags |= flags;
+    regs->eflags.l = eflags;
+}
+
 #endif /* CORE_H */



More information about the Syslinux-commits mailing list