Added a simple second heap that will survive the switch to the kernel.

elf_load_image() now uses this heap for the preloaded_image structures.
Moved gKernelArgs and gKernelEntry to different files.
Improved enabling debug output (it can now be activated by a makefile, too)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7281 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-04-21 02:32:36 +00:00
parent d8023a2fc5
commit fbe5e77d0b
5 changed files with 90 additions and 11 deletions

View File

@ -34,6 +34,7 @@ KernelStaticLibrary boot_loader :
elf.cpp
menu.cpp
loader.cpp
kernel_args.cpp
# utils
list.c

View File

@ -1,5 +1,5 @@
/*
** Copyright 2002-2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
@ -15,8 +15,8 @@
#include <string.h>
#include <stdlib.h>
#define TRACE_ELF 1
#if TRACE_ELF
//#define TRACE_ELF
#ifdef TRACE_ELF
# define TRACE(x) dprintf x
#else
# define TRACE(x) ;
@ -181,7 +181,7 @@ elf_load_image(Directory *directory, const char *path)
if (fd < 0)
return fd;
image = (preloaded_image *)malloc(sizeof(preloaded_image));
image = (preloaded_image *)kernel_args_malloc(sizeof(preloaded_image));
if (image == NULL) {
close(fd);
return B_NO_MEMORY;
@ -195,7 +195,7 @@ elf_load_image(Directory *directory, const char *path)
image->next = gKernelArgs.preloaded_images;
gKernelArgs.preloaded_images = image;
} else
free(image);
kernel_args_free(image);
close(fd);
return B_OK;

View File

@ -0,0 +1,80 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include <boot/stage2.h>
#include <boot/platform.h>
static const size_t kChunkSize = 16384;
kernel_args gKernelArgs;
static void *sFirstFree;
static void *sLast;
static size_t sFree = kChunkSize;
/** This function can be used to allocate memory that is going
* to be passed over to the kernel. For example, the preloaded_image
* structures are allocated this way.
* The boot loader heap doesn't make it into the kernel!
*/
extern "C" void *
kernel_args_malloc(size_t size)
{
if (sFirstFree != NULL && size <= sFree) {
// there is enough space in the current buffer
void *address = sFirstFree;
sFirstFree = (void *)((addr_t)sFirstFree + size);
sLast = address;
sFree -= size;
return address;
}
if (size > kChunkSize / 2 && sFree < size) {
// the block is so large, we'll allocate a new block for it
void *block = NULL;
if (platform_allocate_region(&block, size, B_READ_AREA | B_WRITE_AREA) != B_OK)
return NULL;
return block;
}
// just allocate a new block and "close" the old one
void *block = NULL;
if (platform_allocate_region(&block, kChunkSize, B_READ_AREA | B_WRITE_AREA) != B_OK)
return NULL;
sFirstFree = (void *)((addr_t)block + size);
sLast = block;
sFree = kChunkSize - size;
return block;
}
/** This function frees a block allocated via kernel_args_malloc().
* It's very simple; it can only free the last allocation. It's
* enough for its current usage in the boot loader, though.
*/
extern "C" void
kernel_args_free(void *block)
{
if (sLast != block) {
// sorry, we're dumb
return;
}
sFree = (addr_t)sFirstFree - (addr_t)sLast;
sFirstFree = block;
sLast = NULL;
}

View File

@ -26,6 +26,8 @@
// temp. VFS API
extern Node *get_node_from(int fd);
addr_t gKernelEntry;
bool
is_bootable(Directory *volume)

View File

@ -16,18 +16,14 @@
#include <util/kernel_cpp.h>
#define TRACE_MAIN 0
#if TRACE_MAIN
//#define TRACE_MAIN
#ifdef TRACE_MAIN
# define TRACE(x) printf x
#else
# define TRACE(x) ;
#endif
kernel_args gKernelArgs;
addr_t gKernelEntry;
extern "C" int
main(stage2_args *args)
{