aboutsummaryrefslogtreecommitdiff
path: root/ext2load
diff options
context:
space:
mode:
authorFlorian Lohoff <flo@rfc822.org>2008-10-04 16:08:49 +0000
committerGuido Günther <agx@sigxcpu.org>2009-04-26 15:26:26 +0200
commit88aacc5ec96304a23c4d33ac3cdc71985f099c72 (patch)
tree414c5902472e83ad988fc3db247188700b4e9f48 /ext2load
parentae4dcabd39938e93afa1fb095ed5421e92c10d7d (diff)
Move memory init, Fatal and Wait into prom specific
Abstract memory initialization into prom specific code. Put Fatal and Wait into prom specific code.
Diffstat (limited to 'ext2load')
-rw-r--r--ext2load/loader.c154
1 files changed, 40 insertions, 114 deletions
diff --git a/ext2load/loader.c b/ext2load/loader.c
index 75fa4cc..f4c06c6 100644
--- a/ext2load/loader.c
+++ b/ext2load/loader.c
@@ -11,6 +11,7 @@
#include <stdint.h>
#include <arc.h>
+#include <prom.h>
#include <elf.h>
#include <sys/types.h>
@@ -43,93 +44,18 @@ typedef union {
Elf64_Ehdr header64;
} Elf_Ehdr;
-static void Wait(const char *prompt)
-{
- int ch;
-
- if (prompt != NULL)
- puts(prompt);
-
- do {
- ch = getchar();
- } while ((ch != EOF) && (((char) ch) != ' '));
-}
-
-
-void Fatal(const CHAR * message, ...)
-{
- va_list ap;
-
- if (message != NULL) {
- printf("FATAL ERROR: ");
- va_start(ap, message);
- vprintf(message, ap);
- va_end(ap);
- }
-
- Wait("\n\r--- Press <spacebar> to enter ARC interactive mode ---");
- ArcEnterInteractiveMode();
-}
-
-
-void InitMalloc(void)
-{
- MEMORYDESCRIPTOR *current = NULL;
- ULONG stack = (ULONG) &current;
-#ifdef DEBUG
- printf("stack starts at: 0x%lx\n\r", stack);
-#endif
-
- current = ArcGetMemoryDescriptor(current);
- if(! current ) {
- Fatal("Can't find any valid memory descriptors!\n\r");
- }
- while (current != NULL) {
- /*
- * The spec says we should have an adjacent FreeContiguous
- * memory area that includes our stack. It would be much
- * easier to just look for that and give it to malloc, but
- * the Indy only shows FreeMemory areas, no FreeContiguous.
- * Oh well.
- */
- if (current->Type == FreeMemory) {
- ULONG start = KSEG0ADDR(current->BasePage * PAGE_SIZE);
- ULONG end =
- start + (current->PageCount * PAGE_SIZE);
-#if DEBUG
- printf("Free Memory(%u) segment found at (0x%lx,0x%lx).\n\r",
- current->Type, start, end);
-#endif
+/* we filter these out of the command line */
+static char* env_vars[] = { "ConsoleIn=",
+ "ConsoleOut=",
+ "OSLoader=",
+ "OSLoadPartition=",
+ "OSLoadFilename=",
+ "OSLoadOptions=",
+ };
+#define NENTS(foo) ((sizeof((foo)) / (sizeof((foo[0])))))
- /* Leave some space for our stack */
- if ((stack >= start) && (stack < end))
- end =
- (stack -
- (STACK_PAGES *
- PAGE_SIZE)) & ~(PAGE_SIZE - 1);
- /* Don't use memory from reserved region */
- if ((start >= kernel_load[SUBARCH].base )
- && (start < (kernel_load[SUBARCH].base
- + kernel_load[SUBARCH].reserved )))
- start = kernel_load[SUBARCH].base
- + kernel_load[SUBARCH].reserved;
- if ((end > kernel_load[SUBARCH].base)
- && (end <= (kernel_load[SUBARCH].base
- + kernel_load[SUBARCH].reserved )))
- end = kernel_load[SUBARCH].base;
- if (end > start) {
-#ifdef DEBUG
- printf("Adding %lu bytes at 0x%lx to the list of available memory\n\r",
- end-start, start);
-#endif
- malloc_area_add(start, end - start);
- }
- }
- current = ArcGetMemoryDescriptor(current);
- }
-}
-int isEnvVar(const char* arg)
+static int isEnvVar(const char* arg)
{
unsigned int i;
@@ -159,7 +85,7 @@ int ProcessArguments(LONG argc, CHAR * argv[])
/* Copy options to local memory to avoid overwrite later */
OSLoadOptions = strdup(equals + 1);
if (OSLoadOptions == NULL)
- Fatal ("Cannot allocate memory for options string\n\r");
+ prom_fatal("Cannot allocate memory for options string\n\r");
}
}
}
@@ -211,7 +137,7 @@ int LoadProgramSegments32(ext2_file_t file, Elf_Ehdr * header, void *segments)
EXT2_SEEK_SET, NULL);
if (status != 0) {
print_ext2fs_error(status);
- Fatal("Cannot seek to program segment\n\r");
+ prom_fatal("Cannot seek to program segment\n\r");
}
arc_do_progress = 1;
@@ -223,7 +149,7 @@ int LoadProgramSegments32(ext2_file_t file, Elf_Ehdr * header, void *segments)
arc_do_progress = 0;
if (status != 0) {
print_ext2fs_error(status);
- Fatal("Cannot read program segment\n\r");
+ prom_fatal("Cannot read program segment\n\r");
}
size = segment->p_memsz - segment->p_filesz;
@@ -279,7 +205,7 @@ int LoadProgramSegments64(ext2_file_t file, Elf_Ehdr * header, void *segments)
EXT2_SEEK_SET, NULL);
if (status != 0) {
print_ext2fs_error(status);
- Fatal("Cannot seek to program segment\n\r");
+ prom_fatal("Cannot seek to program segment\n\r");
}
arc_do_progress = 1;
@@ -290,7 +216,7 @@ int LoadProgramSegments64(ext2_file_t file, Elf_Ehdr * header, void *segments)
arc_do_progress = 0;
if (status != 0) {
print_ext2fs_error(status);
- Fatal("Cannot read program segment\n\r");
+ prom_fatal("Cannot read program segment\n\r");
}
size = (ULONG)segment->p_memsz - (ULONG)segment->p_filesz;
@@ -329,11 +255,11 @@ void LoadProgramSegments(ext2_file_t file, Elf_Ehdr * header)
header->header64.e_phnum);
if (size <= 0)
- Fatal("No program segments\n\r");
+ prom_fatal("No program segments\n\r");
segments = malloc(size);
if (segments == NULL)
- Fatal("Cannot allocate memory for segment headers\n\r");
+ prom_fatal("Cannot allocate memory for segment headers\n\r");
else
printf("Allocated 0x%x bytes for segments\n\r",size);
@@ -348,13 +274,13 @@ void LoadProgramSegments(ext2_file_t file, Elf_Ehdr * header)
}
if (status != 0) {
print_ext2fs_error(status);
- Fatal("Cannot seek to program segment headers\n\r");
+ prom_fatal("Cannot seek to program segment headers\n\r");
}
status = ext2fs_file_read(file, segments, size, NULL);
if (status != 0) {
print_ext2fs_error(status);
- Fatal("Cannot read program segment headers\n\r");
+ prom_fatal("Cannot read program segment headers\n\r");
}
if(header->e_ident[EI_CLASS] == ELFCLASS32)
@@ -363,7 +289,7 @@ void LoadProgramSegments(ext2_file_t file, Elf_Ehdr * header)
loaded = LoadProgramSegments64(file, header, segments);
if (!loaded)
- Fatal("No loadable program segments found\n\r");
+ prom_fatal("No loadable program segments found\n\r");
free(segments);
}
@@ -379,42 +305,42 @@ Elf64_Addr LoadKernelFile(ext2_file_t file)
ext2fs_file_read(file, (void *) &header, sizeof(header), NULL);
if (status != 0) {
print_ext2fs_error(status);
- Fatal("Can't read file header\n\r");
+ prom_fatal("Can't read file header\n\r");
}
if (memcmp(&(header.e_ident[EI_MAG0]), ELFMAG, SELFMAG) != 0)
- Fatal("Not an ELF file\n\r");
+ prom_fatal("Not an ELF file\n\r");
if (header.e_ident[EI_CLASS] != ELFCLASS32 &&
header.e_ident[EI_CLASS] != ELFCLASS64)
- Fatal("Not a 32-bit or 64-bit file\n\r");
+ prom_fatal("Not a 32-bit or 64-bit file\n\r");
if (header.e_ident[EI_DATA] != ELFDATA2MSB)
- Fatal("Not a big-endian file\n\r");
+ prom_fatal("Not a big-endian file\n\r");
if (header.e_ident[EI_VERSION] != EV_CURRENT)
- Fatal("Wrong ELF version\n\r");
+ prom_fatal("Wrong ELF version\n\r");
if (header.e_ident[EI_CLASS]==ELFCLASS32) {
if (header.header32.e_type != ET_EXEC)
- Fatal("Not an executable file\n\r");
+ prom_fatal("Not an executable file\n\r");
if (header.header32.e_machine != EM_MIPS)
- Fatal("Unsupported machine type\n\r");
+ prom_fatal("Unsupported machine type\n\r");
if (header.header32.e_version != EV_CURRENT)
- Fatal("Wrong ELF version\n\r");
+ prom_fatal("Wrong ELF version\n\r");
entry = (Elf64_Addr) header.header32.e_entry;
} else {
if (header.header64.e_type != ET_EXEC)
- Fatal("Not an executable file\n\r");
+ prom_fatal("Not an executable file\n\r");
if (header.header64.e_machine != EM_MIPS)
- Fatal("Unsupported machine type\n\r");
+ prom_fatal("Unsupported machine type\n\r");
if (header.header64.e_version != EV_CURRENT)
- Fatal("Wrong ELF version\n\r");
+ prom_fatal("Wrong ELF version\n\r");
entry = header.header64.e_entry;
}
@@ -460,7 +386,7 @@ Elf64_Addr LoadKernel(const char *partition, const char *filename)
ext2_file_t file;
if(!OpenFile( partition, filename, &file ))
- Fatal("Can't load kernel!\n\r");
+ prom_fatal("Can't load kernel!\n\r");
return LoadKernelFile(file);
}
@@ -472,14 +398,14 @@ void LoadInitrd(const char *partition, const char *filename, int *argc, char **a
int status;
if (!OpenFile(partition, filename, &file))
- Fatal("Can't load initrd!\n\r");
+ prom_fatal("Can't load initrd!\n\r");
initrd_sz = ext2fs_file_get_size(file);
initrd_addr = (ULONG)malloc(initrd_sz + max_page_size);
if (initrd_addr == 0) {
- Fatal("Cannot allocate memory for initrd\n\r");
+ prom_fatal("Cannot allocate memory for initrd\n\r");
}
initrd_addr = (initrd_addr + max_page_size) & ~(max_page_size - 1);
@@ -492,7 +418,7 @@ void LoadInitrd(const char *partition, const char *filename, int *argc, char **a
arc_do_progress = 0;
if (status != 0) {
print_ext2fs_error(status);
- Fatal("Cannot read initrd\n\r");
+ prom_fatal("Cannot read initrd\n\r");
}
/* Add rd_start=, rd_size= */
@@ -542,7 +468,7 @@ void _start(LONG argc, CHAR *argv[], CHAR *envp[])
printf(ANSI_CLEAR "\n\rarcsboot: ARCS Linux ext2fs loader "
__ARCSBOOT_VERSION__ "\n\n\r");
- InitMalloc();
+ prom_init_malloc();
nopt = ProcessArguments(argc, argv);
@@ -559,7 +485,7 @@ void _start(LONG argc, CHAR *argv[], CHAR *envp[])
OSLoadFilename = "Linux";
if (OSLoadPartition == NULL)
- Fatal("Invalid load partition\n\r");
+ prom_fatal("Invalid load partition\n\r");
#if DEBUG
printf("OSLoadPartition: %s\n\r", OSLoadPartition);
printf("OSLoadFilename: %s\n\r", OSLoadFilename);
@@ -607,7 +533,7 @@ void _start(LONG argc, CHAR *argv[], CHAR *envp[])
printCmdLine(nargc, nargv);
printf("Kernel entry: 0x%lx %lx\n\r",
(long)(kernel_entry64>>32),(long)(kernel_entry64&0xffffffff));
- Wait("\n\r--- Debug: press <spacebar> to boot kernel ---");
+ prom_wait("\n\r--- Debug: press <spacebar> to boot kernel ---");
#endif
if( kernel_entry64 ) {
if(is64==0){
@@ -625,6 +551,6 @@ void _start(LONG argc, CHAR *argv[], CHAR *envp[])
}
/* Not likely to get back here in a functional state, but what the heck */
- Wait("\n\r--- Press <spacebar> to restart ---");
+ prom_wait("\n\r--- Press <spacebar> to restart ---");
ArcRestart();
}