* Enlarged a single kernel_args chunk to 32 KB (was 16 KB).

* Reduced the kernel_args array size from 32 to 16 (7 are used on a normal
  build).
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27690 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-09-22 15:36:46 +00:00
parent 65a9d40a9d
commit 4a47b14ea4
2 changed files with 46 additions and 49 deletions
+1 -1
View File
@@ -21,7 +21,7 @@
#include <util/KMessage.h> #include <util/KMessage.h>
#define CURRENT_KERNEL_ARGS_VERSION 1 #define CURRENT_KERNEL_ARGS_VERSION 1
#define MAX_KERNEL_ARGS_RANGE 32 #define MAX_KERNEL_ARGS_RANGE 16
// names of common boot_volume fields // names of common boot_volume fields
#define BOOT_METHOD "boot method" #define BOOT_METHOD "boot method"
+45 -48
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2006, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2008, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -13,17 +13,17 @@
#include <string.h> #include <string.h>
static const size_t kChunkSize = 4 * B_PAGE_SIZE; static const size_t kChunkSize = 8 * B_PAGE_SIZE;
kernel_args gKernelArgs; kernel_args gKernelArgs;
static void *sFirstFree; static void* sFirstFree;
static void *sLast; static void* sLast;
static size_t sFree = kChunkSize; static size_t sFree = kChunkSize;
static void static void
remove_range_index(addr_range *ranges, uint32 &numRanges, uint32 index) remove_range_index(addr_range* ranges, uint32& numRanges, uint32 index)
{ {
if (index + 1 == numRanges) { if (index + 1 == numRanges) {
// remove last range // remove last range
@@ -31,15 +31,16 @@ remove_range_index(addr_range *ranges, uint32 &numRanges, uint32 index)
return; return;
} }
memmove(&ranges[index], &ranges[index + 1], sizeof(addr_range) * (numRanges - 1 - index)); memmove(&ranges[index], &ranges[index + 1],
sizeof(addr_range) * (numRanges - 1 - index));
numRanges--; numRanges--;
} }
static status_t static status_t
add_kernel_args_range(void *start, uint32 size) add_kernel_args_range(void* start, uint32 size)
{ {
return insert_address_range(gKernelArgs.kernel_args_range, return insert_address_range(gKernelArgs.kernel_args_range,
&gKernelArgs.num_kernel_args_ranges, MAX_KERNEL_ARGS_RANGE, &gKernelArgs.num_kernel_args_ranges, MAX_KERNEL_ARGS_RANGE,
(addr_t)start, size); (addr_t)start, size);
} }
@@ -48,16 +49,15 @@ add_kernel_args_range(void *start, uint32 size)
// #pragma mark - addr_range utility // #pragma mark - addr_range utility
/** Inserts the specified (start, size) pair (aka range) in the /*! Inserts the specified (start, size) pair (aka range) in the
* addr_range array. addr_range array.
* It will extend existing ranges in order to have as little It will extend existing ranges in order to have as little
* ranges in the array as possible. ranges in the array as possible.
* Returns B_OK on success, or B_ENTRY_NOT_FOUND if there was Returns B_OK on success, or B_ENTRY_NOT_FOUND if there was
* no free array entry available anymore. no free array entry available anymore.
*/ */
extern "C" status_t extern "C" status_t
insert_address_range(addr_range *ranges, uint32 *_numRanges, uint32 maxRanges, insert_address_range(addr_range* ranges, uint32* _numRanges, uint32 maxRanges,
addr_t start, uint32 size) addr_t start, uint32 size)
{ {
uint32 numRanges = *_numRanges; uint32 numRanges = *_numRanges;
@@ -122,7 +122,7 @@ insert_address_range(addr_range *ranges, uint32 *_numRanges, uint32 maxRanges,
} }
// no range matched, we need to create a new one // no range matched, we need to create a new one
if (numRanges >= maxRanges) if (numRanges >= maxRanges)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
@@ -135,7 +135,7 @@ insert_address_range(addr_range *ranges, uint32 *_numRanges, uint32 maxRanges,
extern "C" status_t extern "C" status_t
remove_address_range(addr_range *ranges, uint32 *_numRanges, uint32 maxRanges, remove_address_range(addr_range* ranges, uint32* _numRanges, uint32 maxRanges,
addr_t start, uint32 size) addr_t start, uint32 size)
{ {
uint32 numRanges = *_numRanges; uint32 numRanges = *_numRanges;
@@ -183,7 +183,7 @@ remove_address_range(addr_range *ranges, uint32 *_numRanges, uint32 maxRanges,
status_t status_t
insert_physical_memory_range(addr_t start, uint32 size) insert_physical_memory_range(addr_t start, uint32 size)
{ {
return insert_address_range(gKernelArgs.physical_memory_range, return insert_address_range(gKernelArgs.physical_memory_range,
&gKernelArgs.num_physical_memory_ranges, MAX_PHYSICAL_MEMORY_RANGE, &gKernelArgs.num_physical_memory_ranges, MAX_PHYSICAL_MEMORY_RANGE,
start, size); start, size);
} }
@@ -192,16 +192,16 @@ insert_physical_memory_range(addr_t start, uint32 size)
status_t status_t
insert_physical_allocated_range(addr_t start, uint32 size) insert_physical_allocated_range(addr_t start, uint32 size)
{ {
return insert_address_range(gKernelArgs.physical_allocated_range, return insert_address_range(gKernelArgs.physical_allocated_range,
&gKernelArgs.num_physical_allocated_ranges, MAX_PHYSICAL_ALLOCATED_RANGE, &gKernelArgs.num_physical_allocated_ranges,
start, size); MAX_PHYSICAL_ALLOCATED_RANGE, start, size);
} }
status_t status_t
insert_virtual_allocated_range(addr_t start, uint32 size) insert_virtual_allocated_range(addr_t start, uint32 size)
{ {
return insert_address_range(gKernelArgs.virtual_allocated_range, return insert_address_range(gKernelArgs.virtual_allocated_range,
&gKernelArgs.num_virtual_allocated_ranges, MAX_VIRTUAL_ALLOCATED_RANGE, &gKernelArgs.num_virtual_allocated_ranges, MAX_VIRTUAL_ALLOCATED_RANGE,
start, size); start, size);
} }
@@ -210,21 +210,20 @@ insert_virtual_allocated_range(addr_t start, uint32 size)
// #pragma mark - kernel_args allocations // #pragma mark - kernel_args allocations
/** This function can be used to allocate memory that is going /*! This function can be used to allocate memory that is going
* to be passed over to the kernel. For example, the preloaded_image to be passed over to the kernel. For example, the preloaded_image
* structures are allocated this way. structures are allocated this way.
* The boot loader heap doesn't make it into the kernel! The boot loader heap doesn't make it into the kernel!
*/ */
extern "C" void*
extern "C" void *
kernel_args_malloc(size_t size) kernel_args_malloc(size_t size)
{ {
//dprintf("kernel_args_malloc(): %ld bytes (%ld bytes left)\n", size, sFree); //dprintf("kernel_args_malloc(): %ld bytes (%ld bytes left)\n", size, sFree);
if (sFirstFree != NULL && size <= sFree) { if (sFirstFree != NULL && size <= sFree) {
// there is enough space in the current buffer // there is enough space in the current buffer
void *address = sFirstFree; void* address = sFirstFree;
sFirstFree = (void *)((addr_t)sFirstFree + size); sFirstFree = (void*)((addr_t)sFirstFree + size);
sLast = address; sLast = address;
sFree -= size; sFree -= size;
@@ -233,9 +232,9 @@ kernel_args_malloc(size_t size)
if (size > kChunkSize / 2 && sFree < size) { if (size > kChunkSize / 2 && sFree < size) {
// the block is so large, we'll allocate a new block for it // the block is so large, we'll allocate a new block for it
void *block = NULL; void* block = NULL;
if (platform_allocate_region(&block, size, B_READ_AREA | B_WRITE_AREA, if (platform_allocate_region(&block, size, B_READ_AREA | B_WRITE_AREA,
false) != B_OK) { false) != B_OK) {
return NULL; return NULL;
} }
@@ -245,13 +244,13 @@ kernel_args_malloc(size_t size)
} }
// just allocate a new block and "close" the old one // just allocate a new block and "close" the old one
void *block = NULL; void* block = NULL;
if (platform_allocate_region(&block, kChunkSize, if (platform_allocate_region(&block, kChunkSize, B_READ_AREA | B_WRITE_AREA,
B_READ_AREA | B_WRITE_AREA, false) != B_OK) { false) != B_OK) {
return NULL; return NULL;
} }
sFirstFree = (void *)((addr_t)block + size); sFirstFree = (void*)((addr_t)block + size);
sLast = block; sLast = block;
sFree = kChunkSize - size; sFree = kChunkSize - size;
if (add_kernel_args_range(block, kChunkSize) != B_OK) if (add_kernel_args_range(block, kChunkSize) != B_OK)
@@ -261,10 +260,9 @@ kernel_args_malloc(size_t size)
} }
/** Convenience function that copies strdup() functions for the /*! Convenience function that copies strdup() functions for the
* kernel args heap. kernel args heap.
*/ */
extern "C" char * extern "C" char *
kernel_args_strdup(const char *string) kernel_args_strdup(const char *string)
{ {
@@ -282,11 +280,10 @@ kernel_args_strdup(const char *string)
} }
/** This function frees a block allocated via kernel_args_malloc(). /*! This function frees a block allocated via kernel_args_malloc().
* It's very simple; it can only free the last allocation. It's It's very simple; it can only free the last allocation. It's
* enough for its current usage in the boot loader, though. enough for its current usage in the boot loader, though.
*/ */
extern "C" void extern "C" void
kernel_args_free(void *block) kernel_args_free(void *block)
{ {