aboutsummaryrefslogtreecommitdiff
path: root/arclib/prom.c
diff options
context:
space:
mode:
Diffstat (limited to 'arclib/prom.c')
-rw-r--r--arclib/prom.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/arclib/prom.c b/arclib/prom.c
index ab3b49a..27a8e69 100644
--- a/arclib/prom.c
+++ b/arclib/prom.c
@@ -3,6 +3,94 @@
#include "arc.h"
#include "prom.h"
+#include <stddef.h>
+#include <stdlib.h>
+#include <subarch.h>
+
+void prom_wait(const char *prompt)
+{
+ int ch;
+
+ if (prompt != NULL)
+ puts(prompt);
+
+ do {
+ ch = getchar();
+ } while ((ch != EOF) && (((char) ch) != ' '));
+}
+
+
+void prom_fatal(const CHAR * message, ...)
+{
+ va_list ap;
+
+ if (message != NULL) {
+ printf("FATAL ERROR: ");
+ va_start(ap, message);
+ vprintf(message, ap);
+ va_end(ap);
+ }
+
+ prom_wait("\n\r--- Press <spacebar> to enter ARC interactive mode ---");
+ ArcEnterInteractiveMode();
+}
+
+void prom_init_malloc(void)
+{
+ MEMORYDESCRIPTOR *current = NULL;
+ unsigned long stack = (unsigned long) &current;
+#ifdef DEBUG
+ printf("stack starts at: 0x%lx\n\r", stack);
+#endif
+
+ current = ArcGetMemoryDescriptor(current);
+ if(!current ) {
+ prom_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) {
+ unsigned long start = KSEG0ADDR(current->BasePage * PAGE_SIZE);
+ unsigned long 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 >= KERNELADDR)
+ && (start < (KERNELADDR + MAXLOADSIZE)))
+ start = KERNELADDR + MAXLOADSIZE;
+ if ((end > KERNELADDR)
+ && (end <= (KERNELADDR + MAXLOADSIZE)))
+ end = KERNELADDR;
+ 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 prom_open(char *name, int mode, FILE *stream) {
/* Translate mode to Arc variant */
int amode=OpenReadOnly;