Files
haiku-beta6/src/kernel/boot/loader/loader.cpp
T
Axel Dörfler fbe5e77d0b 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
2004-04-21 02:32:36 +00:00

116 lines
2.4 KiB
C++

/*
** Copyright 2003-2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include "loader.h"
#include "elf.h"
#include <OS.h>
#include <boot/stage2.h>
#include <boot/vfs.h>
#include <boot/platform.h>
#include <boot/stdio.h>
#include <unistd.h>
#ifndef BOOT_ARCH
# error BOOT_ARCH has to be defined to differentiate the kernel per platform
#endif
#define KERNEL_IMAGE "kernel_" BOOT_ARCH
#define KERNEL_PATH "beos/system/" KERNEL_IMAGE
// temp. VFS API
extern Node *get_node_from(int fd);
addr_t gKernelEntry;
bool
is_bootable(Directory *volume)
{
if (volume->IsEmpty())
return false;
// check for the existance of a kernel (for our platform)
int fd = open_from(volume, KERNEL_PATH, O_RDONLY);
if (fd < B_OK)
return false;
close(fd);
return true;
}
status_t
load_kernel(stage2_args *args, Directory *volume)
{
int fd = open_from(volume, KERNEL_PATH, O_RDONLY);
if (fd < B_OK)
return fd;
puts("load kernel...");
preloaded_image image;
status_t status = elf_load_image(fd, &image);
close(fd);
if (status < B_OK) {
printf("loading kernel failed: %ld!\n", status);
return status;
}
puts("kernel loaded successfully");
// init kernel args with loaded image data
gKernelArgs.kernel_seg0_addr.start = image.text_region.start;
gKernelArgs.kernel_seg0_addr.size = image.text_region.size;
gKernelArgs.kernel_seg1_addr.start = image.data_region.start;
gKernelArgs.kernel_seg1_addr.size = image.data_region.size;
gKernelArgs.kernel_dynamic_section_addr = image.dynamic_section;
gKernelEntry = image.elf_header.e_entry;
/* void *cookie;
if (volume->Open(&cookie, O_RDONLY) == B_OK) {
char name[B_FILE_NAME_LENGTH];
while (volume->GetNextEntry(cookie, name, sizeof(name)) == B_OK)
printf("\t%s\n", name);
volume->Close(cookie);
}*/
return B_OK;
}
status_t
load_modules(stage2_args *args, Directory *volume)
{
// we don't have readdir() & co. yet...
int fd = open_from(volume, "beos/system/add-ons/kernel/boot", O_RDONLY);
if (fd < B_OK)
return fd;
Directory *modules = (Directory *)get_node_from(fd);
if (modules == NULL)
return B_ENTRY_NOT_FOUND;
void *cookie;
if (modules->Open(&cookie, O_RDONLY) == B_OK) {
char name[B_FILE_NAME_LENGTH];
while (modules->GetNextEntry(cookie, name, sizeof(name)) == B_OK)
printf("\t%s\n", name);
modules->Close(cookie);
}
return B_OK;
}