Index: kernel/generic/src/mm/frame.c
===================================================================
--- kernel/generic/src/mm/frame.c	(revision 5f0f29ce3c25993ee100bdb9354b66dc6b762ae7)
+++ kernel/generic/src/mm/frame.c	(revision e49e2348e7647a4dd4d4e2879082790396c4f4f3)
@@ -49,5 +49,4 @@
 #include <debug.h>
 #include <adt/list.h>
-#include <synch/spinlock.h>
 #include <synch/mutex.h>
 #include <synch/condvar.h>
@@ -61,38 +60,5 @@
 #include <config.h>
 
-typedef struct {
-	count_t refcount;     /**< Tracking of shared frames */
-	uint8_t buddy_order;  /**< Buddy system block order */
-	link_t buddy_link;    /**< Link to the next free block inside
-                               one order */
-	void *parent;         /**< If allocated by slab, this points there */
-} frame_t;
-
-typedef struct {
-	pfn_t base;                    /**< Frame_no of the first frame
-                                        in the frames array */
-	count_t count;                 /**< Size of zone */
-	count_t free_count;            /**< Number of free frame_t
-                                        structures */
-	count_t busy_count;            /**< Number of busy frame_t
-                                        structures */
-	zone_flags_t flags;            /**< Type of the zone */
-	
-	frame_t *frames;               /**< Array of frame_t structures
-                                        in this zone */
-	buddy_system_t *buddy_system;  /**< Buddy system for the zone */
-} zone_t;
-
-/*
- * The zoneinfo.lock must be locked when accessing zoneinfo structure.
- * Some of the attributes in zone_t structures are 'read-only'
- */
-typedef struct {
-	SPINLOCK_DECLARE(lock);
-	count_t count;
-	zone_t info[ZONES_MAX];
-} zones_t;
-
-static zones_t zones;
+zones_t zones;
 
 /*
@@ -127,9 +93,4 @@
 {
 	return (frame - zone->frames);
-}
-
-static inline bool zone_flags_available(zone_flags_t flags)
-{
-	return ((flags & (ZONE_RESERVED | ZONE_FIRMWARE)) == 0);
 }
 
@@ -181,6 +142,9 @@
 	/* Move other zones up */
 	count_t j;
-	for (j = i; j < zones.count; j++)
-		zones.info[j + 1] = zones.info[j];
+	for (j = zones.count; j > i; j--) {
+		zones.info[j] = zones.info[j - 1];
+		zones.info[j].buddy_system->data =
+		    (void *) &zones.info[j - 1];
+	}
 	
 	zones.count++;
@@ -207,5 +171,5 @@
 }
 
-/** Find a zone with a given frame.
+/** Find a zone with a given frames.
  *
  * Assume interrupts are disabled and zones lock is
@@ -213,4 +177,5 @@
  *
  * @param frame Frame number contained in zone.
+ * @param count Number of frames to look for.
  * @param hint  Used as zone hint.
  *
@@ -218,5 +183,5 @@
  *
  */
-static count_t find_zone(pfn_t frame, count_t hint)
+count_t find_zone(pfn_t frame, count_t count, count_t hint)
 {
 	if (hint >= zones.count)
@@ -226,5 +191,5 @@
 	do {
 		if ((zones.info[i].base <= frame)
-		    && (zones.info[i].base + zones.info[i].count > frame))
+		    && (zones.info[i].base + zones.info[i].count >= frame + count))
 			return i;
 		
@@ -766,8 +731,12 @@
 	    zones.info[z2].count);
 	
-	/* Shift existing zones */
+	/* Move zones down */
 	count_t i;
-	for (i = z2 + 1; i < zones.count; i++)
+	for (i = z2 + 1; i < zones.count; i++) {
 		zones.info[i - 1] = zones.info[i];
+		zones.info[i - 1].buddy_system->data =
+		    (void *) &zones.info[i - 1];
+	}
+	
 	zones.count--;
 	
@@ -965,5 +934,5 @@
 	spinlock_lock(&zones.lock);
 	
-	count_t znum = find_zone(pfn, hint);
+	count_t znum = find_zone(pfn, 1, hint);
 	
 	ASSERT(znum != (count_t) -1);
@@ -981,5 +950,5 @@
 	spinlock_lock(&zones.lock);
 	
-	count_t znum = find_zone(pfn, hint);
+	count_t znum = find_zone(pfn, 1, hint);
 	
 	ASSERT(znum != (count_t) -1);
@@ -1112,5 +1081,5 @@
 	 */
 	pfn_t pfn = ADDR2PFN(frame);
-	count_t znum = find_zone(pfn, NULL);
+	count_t znum = find_zone(pfn, 1, NULL);
 	
 	ASSERT(znum != (count_t) -1);
@@ -1151,5 +1120,5 @@
 	 * First, find host frame zone for addr.
 	 */
-	count_t znum = find_zone(pfn, NULL);
+	count_t znum = find_zone(pfn, 1, NULL);
 	
 	ASSERT(znum != (count_t) -1);
@@ -1169,5 +1138,5 @@
 	count_t i;
 	for (i = 0; i < count; i++) {
-		count_t znum = find_zone(start + i, 0);
+		count_t znum = find_zone(start + i, 1, 0);
 		if (znum == (count_t) -1)  /* PFN not found */
 			continue;
@@ -1238,11 +1207,11 @@
 {
 #ifdef __32_BITS__
-	printf("#  base address flags    free frames  busy frames\n");
-	printf("-- ------------ -------- ------------ ------------\n");
+	printf("#  base address frames       flags    free frames  busy frames\n");
+	printf("-- ------------ ------------ -------- ------------ ------------\n");
 #endif
 
 #ifdef __64_BITS__
-	printf("#  base address         flags    free frames  busy frames\n");
-	printf("-- -------------------- -------- ------------ ------------\n");
+	printf("#  base address          frames      flags    free frames  busy frames\n");
+	printf("-- -------------------- ------------ -------- ------------ ------------\n");
 #endif
 	
@@ -1270,4 +1239,5 @@
 		
 		uintptr_t base = PFN2ADDR(zones.info[i].base);
+		count_t count = zones.info[i].count;
 		zone_flags_t flags = zones.info[i].flags;
 		count_t free_count = zones.info[i].free_count;
@@ -1279,21 +1249,23 @@
 		bool available = zone_flags_available(flags);
 		
+		printf("%-2" PRIc, i);
+		
 #ifdef __32_BITS__
-		printf("%-2" PRIc "   %10p %c%c%c      ", i, base,
+		printf("   %10p", base);
+#endif
+		
+#ifdef __64_BITS__
+		printf("   %18p", base);
+#endif
+		
+		printf(" %12" PRIc " %c%c%c      ", count,
 		    available ? 'A' : ' ',
 		    (flags & ZONE_RESERVED) ? 'R' : ' ',
 		    (flags & ZONE_FIRMWARE) ? 'F' : ' ');
-#endif
-		
-#ifdef __64_BITS__
-		printf("%-2" PRIc "   %18p %c%c%c      ", i, base,
-		    available ? 'A' : ' ',
-		    (flags & ZONE_RESERVED) ? 'R' : ' ',
-		    (flags & ZONE_FIRMWARE) ? 'F' : ' ');
-#endif
 		
 		if (available)
 			printf("%12" PRIc " %12" PRIc,
 			    free_count, busy_count);
+		
 		printf("\n");
 	}
