[haiku-commits] r35801 - in haiku/trunk: headers/private/kernel/boot src/system/boot/loader

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 10 Mar 2010 19:36:44 +0100 (CET)

Author: bonefish
Date: 2010-03-10 19:36:44 +0100 (Wed, 10 Mar 2010)
New Revision: 35801
Changeset: http://dev.haiku-os.org/changeset/35801/haiku

Modified:
   haiku/trunk/headers/private/kernel/boot/addr_range.h
   haiku/trunk/src/system/boot/loader/kernel_args.cpp
Log:
Added get_free_address_range() to get a free range in a given range array.


Modified: haiku/trunk/headers/private/kernel/boot/addr_range.h
===================================================================
--- haiku/trunk/headers/private/kernel/boot/addr_range.h        2010-03-10 
18:11:58 UTC (rev 35800)
+++ haiku/trunk/headers/private/kernel/boot/addr_range.h        2010-03-10 
18:36:44 UTC (rev 35801)
@@ -23,6 +23,8 @@
        addr_t start, uint32 size);
 status_t remove_addr_range(addr_range *ranges, uint32 *_numRanges, uint32 
maxRanges,
        addr_t start, uint32 size);
+bool get_free_address_range(addr_range *ranges, uint32 numRanges, addr_t base,
+       size_t size, addr_t *_rangeBase);
 
 status_t insert_physical_memory_range(addr_t start, uint32 size);
 status_t insert_physical_allocated_range(addr_t start, uint32 size);

Modified: haiku/trunk/src/system/boot/loader/kernel_args.cpp
===================================================================
--- haiku/trunk/src/system/boot/loader/kernel_args.cpp  2010-03-10 18:11:58 UTC 
(rev 35800)
+++ haiku/trunk/src/system/boot/loader/kernel_args.cpp  2010-03-10 18:36:44 UTC 
(rev 35801)
@@ -180,6 +180,40 @@
 }
 
 
+bool
+get_free_address_range(addr_range *ranges, uint32 numRanges, addr_t base,
+       size_t size, addr_t *_rangeBase)
+{
+       addr_t end = base + size - 1;
+       if (end < base)
+               return false;
+
+       // Note: We don't assume that the ranges are sorted, so we can't do this
+       // in a simple loop. Instead we restart the loop whenever our range
+       // intersects with an existing one.
+
+       for (uint32 i = 0; i < numRanges;) {
+               addr_t rangeStart = ranges[i].start;
+               addr_t rangeEnd = ranges[i].start + ranges[i].size - 1;
+
+               if (base <= rangeEnd && rangeStart <= end) {
+                       base = rangeEnd + 1;
+                       end = rangeEnd + size;
+                       if (base == 0 || end < base)
+                               return false;
+
+                       i = 0;
+                       continue;
+               }
+
+               i++;
+       }
+
+       *_rangeBase = base;
+       return true;
+}
+
+
 status_t
 insert_physical_memory_range(addr_t start, uint32 size)
 {


Other related posts:

  • » [haiku-commits] r35801 - in haiku/trunk: headers/private/kernel/boot src/system/boot/loader - ingo_weinhold