Search the exception table with linear algorithm
authorZang Roy-r61911 <tie-fei.zang@freescale.com>
Wed, 9 May 2007 00:10:57 +0000 (08:10 +0800)
committerWolfgang Denk <wd@denx.de>
Tue, 15 May 2007 20:19:41 +0000 (22:19 +0200)
Search the exception table with linear algorithm instead of
bisecting algorithm.
Because the exception table might be unsorted.

Signed-off-by: Roy Zang <tie-fei.zang@freescale.com>
lib_ppc/extable.c

index b14d661bbea885ff1d24925aeb3686fbc84a451c..8354411f01fd51cfd58ecf10585e1906368c3746 100644 (file)
@@ -52,30 +52,27 @@ search_one_table(const struct exception_table_entry *first,
                 const struct exception_table_entry *last,
                 unsigned long value)
 {
-       while (first <= last) {
-               const struct exception_table_entry *mid;
-               long diff;
-
-               mid = (last - first) / 2 + first;
-               if ((ulong) mid > CFG_MONITOR_BASE) {
-                       /* exception occurs in FLASH, before u-boot relocation.
-                        * No relocation offset is needed.
-                        */
-                       diff = mid->insn - value;
+       long diff;
+       if ((ulong) first > CFG_MONITOR_BASE) {
+               /* exception occurs in FLASH, before u-boot relocation.
+                * No relocation offset is needed.
+                */
+               while (first <= last) {
+                       diff = first->insn - value;
                        if (diff == 0)
-                               return mid->fixup;
-               } else {
-                       /* exception occurs in RAM, after u-boot relocation.
-                        * A relocation offset should be added.
-                        */
-                       diff = (mid->insn + gd->reloc_off) - value;
+                               return first->fixup;
+                       first++;
+               }
+       } else {
+               /* exception occurs in RAM, after u-boot relocation.
+                * A relocation offset should be added.
+                */
+               while (first <= last) {
+                       diff = (first->insn + gd->reloc_off) - value;
                        if (diff == 0)
-                               return (mid->fixup + gd->reloc_off);
+                               return (first->fixup + gd->reloc_off);
+                       first++;
                }
-               if (diff < 0)
-                       first = mid + 1;
-               else
-                       last = mid - 1;
        }
        return 0;
 }