+/*
+ * Resource map handling routines.
+ *
+ * A resource map is an array of structures each
+ * of which describes a segment of the address space of an available
+ * resource. The segments are described by their base address and
+ * length, and sorted in address order. Each resource map has a fixed
+ * maximum number of segments allowed. Resources are allocated
+ * by taking part or all of one of the segments of the map.
+ *
+ * Returning of resources will require another segment if
+ * the returned resources are not adjacent in the address
+ * space to an existing segment. If the return of a segment
+ * would require a slot which is not available, then one of
+ * the resource map segments is discarded after a warning is printed.
+ * Returning of resources may also cause the map to collapse
+ * by coalescing two existing segments and the returned space
+ * into a single segment. In this case the resource map is
+ * made smaller by copying together to fill the resultant gap.
+ *
+ * N.B.: the current implementation uses a dense array and does
+ * not admit the value ``0'' as a legal address, since that is used
+ * as a delimiter.
+ */
+
+/*
+ * Initialize map mp to have (mapsize-2) segments
+ * and to be called ``name'', which we print if
+ * the slots become so fragmented that we lose space.
+ * The map itself is initialized with size elements free
+ * starting at addr.
+ */
+rminit(mp, size, addr, name, mapsize)
+ register struct map *mp;
+ int size, addr;
+ char *name;
+ int mapsize;
+{
+ register struct mapent *ep = (struct mapent *)(mp+1);
+
+ mp->m_name = name;
+/* N.B.: WE ASSUME HERE THAT sizeof (struct map) == sizeof (struct mapent) */
+ /*
+ * One of the mapsize slots is taken by the map structure,
+ * segments has size 0 and addr 0, and acts as a delimiter.
+ * We insure that we never use segments past the end of
+ * the array which is given by mp->m_limit.
+ * Instead, when excess segments occur we discard some resources.
+ */
+ mp->m_limit = (struct mapent *)&mp[mapsize];
+ /*
+ * Simulate a rmfree(), but with the option to
+ * call with size 0 and addr 0 when we just want
+ * to initialize without freeing.
+ */
+ ep->m_size = size;
+ ep->m_addr = addr;
+}
+