aboutsummaryrefslogtreecommitdiff
path: root/tip22/tftpload.c
diff options
context:
space:
mode:
Diffstat (limited to 'tip22/tftpload.c')
-rw-r--r--tip22/tftpload.c129
1 files changed, 22 insertions, 107 deletions
diff --git a/tip22/tftpload.c b/tip22/tftpload.c
index 36465bf..c438401 100644
--- a/tip22/tftpload.c
+++ b/tip22/tftpload.c
@@ -12,6 +12,7 @@
#include <types.h>
#include <arc.h>
+#include <prom.h>
#include <elf.h>
#include <sys/types.h>
@@ -30,92 +31,6 @@ extern void* __kernel_end;
extern void* __rd_start;
extern void* __rd_end;
-static void Wait(const char *prompt)
-{
- int ch;
-
- if (prompt != NULL)
- puts(prompt);
-
- do {
- ch = getchar();
- } while ((ch != EOF) && (((char) ch) != ' '));
-}
-
-
-static 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();
-}
-
-
-static 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
-
- /* 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);
- }
-}
-
/* convert an offset in the kernel image to an address in the loaded tftpboot image */
static void* offset2addr(unsigned long offset)
{
@@ -133,11 +48,11 @@ static ULONG CopyProgramSegments32(Elf32_Ehdr * header)
ULONG kernel_end=0L;
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");
segments = (Elf32_Phdr*)offset2addr(header->e_phoff);
@@ -172,7 +87,7 @@ static ULONG CopyProgramSegments32(Elf32_Ehdr * header)
}
if (!loaded)
- Fatal("No loadable program segments found\n\r");
+ prom_fatal("No loadable program segments found\n\r");
free(segments);
return kernel_end;
@@ -187,11 +102,11 @@ static ULONG CopyProgramSegments64(Elf64_Ehdr * header)
ULONG kernel_end=0L;
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");
segments = (Elf64_Phdr*)offset2addr(header->e_phoff);
@@ -229,7 +144,7 @@ static ULONG CopyProgramSegments64(Elf64_Ehdr * header)
}
if (!loaded)
- Fatal("No loadable program segments found\n\r");
+ prom_fatal("No loadable program segments found\n\r");
free(segments);
return kernel_end;
@@ -241,19 +156,19 @@ static ULONG CopyKernel(ULONG* kernel_end)
Elf64_Ehdr *header64 = (Elf64_Ehdr*)header;
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) {
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_type != ET_EXEC)
- Fatal("Not an executable file\n\r");
+ prom_fatal("Not an executable file\n\r");
if (header->e_machine != EM_MIPS)
- Fatal("Unsupported machine type\n\r");
+ prom_fatal("Unsupported machine type\n\r");
if (header->e_version != EV_CURRENT)
- Fatal("Wrong ELF version\n\r");
+ prom_fatal("Wrong ELF version\n\r");
(*kernel_end) = CopyProgramSegments32(header);
@@ -262,15 +177,15 @@ static ULONG CopyKernel(ULONG* kernel_end)
return KSEG0ADDR(header->e_entry);
} else if (header->e_ident[EI_CLASS] == ELFCLASS64) {
if (header64->e_ident[EI_DATA] != ELFDATA2MSB)
- Fatal("Not a big-endian file\n\r");
+ prom_fatal("Not a big-endian file\n\r");
if (header64->e_ident[EI_VERSION] != EV_CURRENT)
- Fatal("Wrong ELF version\n\r");
+ prom_fatal("Wrong ELF version\n\r");
if (header64->e_type != ET_EXEC)
- Fatal("Not an executable file\n\r");
+ prom_fatal("Not an executable file\n\r");
if (header64->e_machine != EM_MIPS)
- Fatal("Unsupported machine type\n\r");
+ prom_fatal("Unsupported machine type\n\r");
if (header64->e_version != EV_CURRENT)
- Fatal("Wrong ELF version\n\r");
+ prom_fatal("Wrong ELF version\n\r");
(*kernel_end) = CopyProgramSegments64(header64);
@@ -278,7 +193,7 @@ static ULONG CopyKernel(ULONG* kernel_end)
((ULONG)KSEG0ADDR(header64->e_entry)));
return KSEG0ADDR(header64->e_entry);
} else
- Fatal("Neither an ELF32 nor an ELF64 kernel\n\r");
+ prom_fatal("Neither an ELF32 nor an ELF64 kernel\n\r");
return 0L;
}
@@ -308,7 +223,7 @@ void _start(LONG argc, CHAR * argv[], CHAR * envp[])
printf(ANSI_CLEAR "\n\rtip32: IP32 Linux tftpboot loader " __ARCSBOOT_VERSION__ "\n\r");
#endif
- InitMalloc();
+ prom_init_malloc();
/* copy kernel and ramdisk to its load addresses */
#ifdef DEBUG
@@ -347,7 +262,7 @@ void _start(LONG argc, CHAR * argv[], CHAR * envp[])
printf("Arguments passed to kernel:\n\r");
for(i = 0; i < nargc; i++ )
printf("%u: %s\n\r", i, nargv[i]);
- Wait("\n\r--- Debug: press <spacebar> to boot kernel ---");
+ prom_wait("\n\r--- Debug: press <spacebar> to boot kernel ---");
#endif
/* Finally jump into the kernel */
printf("Starting kernel...\n\r");
@@ -359,6 +274,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();
}