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:
@@ -34,6 +34,7 @@ KernelStaticLibrary boot_loader :
|
|||||||
elf.cpp
|
elf.cpp
|
||||||
menu.cpp
|
menu.cpp
|
||||||
loader.cpp
|
loader.cpp
|
||||||
|
kernel_args.cpp
|
||||||
|
|
||||||
# utils
|
# utils
|
||||||
list.c
|
list.c
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002-2003, Axel Dörfler, [email protected]. All rights reserved.
|
** Copyright 2002-2004, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
** Distributed under the terms of the OpenBeOS License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define TRACE_ELF 1
|
//#define TRACE_ELF
|
||||||
#if TRACE_ELF
|
#ifdef TRACE_ELF
|
||||||
# define TRACE(x) dprintf x
|
# define TRACE(x) dprintf x
|
||||||
#else
|
#else
|
||||||
# define TRACE(x) ;
|
# define TRACE(x) ;
|
||||||
@@ -181,7 +181,7 @@ elf_load_image(Directory *directory, const char *path)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
image = (preloaded_image *)malloc(sizeof(preloaded_image));
|
image = (preloaded_image *)kernel_args_malloc(sizeof(preloaded_image));
|
||||||
if (image == NULL) {
|
if (image == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -195,7 +195,7 @@ elf_load_image(Directory *directory, const char *path)
|
|||||||
image->next = gKernelArgs.preloaded_images;
|
image->next = gKernelArgs.preloaded_images;
|
||||||
gKernelArgs.preloaded_images = image;
|
gKernelArgs.preloaded_images = image;
|
||||||
} else
|
} else
|
||||||
free(image);
|
kernel_args_free(image);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
** Copyright 2004, Axel Dörfler, [email protected]. 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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -26,6 +26,8 @@
|
|||||||
// temp. VFS API
|
// temp. VFS API
|
||||||
extern Node *get_node_from(int fd);
|
extern Node *get_node_from(int fd);
|
||||||
|
|
||||||
|
addr_t gKernelEntry;
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_bootable(Directory *volume)
|
is_bootable(Directory *volume)
|
||||||
|
|||||||
@@ -16,18 +16,14 @@
|
|||||||
#include <util/kernel_cpp.h>
|
#include <util/kernel_cpp.h>
|
||||||
|
|
||||||
|
|
||||||
#define TRACE_MAIN 0
|
//#define TRACE_MAIN
|
||||||
#if TRACE_MAIN
|
#ifdef TRACE_MAIN
|
||||||
# define TRACE(x) printf x
|
# define TRACE(x) printf x
|
||||||
#else
|
#else
|
||||||
# define TRACE(x) ;
|
# define TRACE(x) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
kernel_args gKernelArgs;
|
|
||||||
addr_t gKernelEntry;
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
main(stage2_args *args)
|
main(stage2_args *args)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user