Trust uboot's device list only if it does not look suspicious.
[AROS.git] / arch / all-pc / bootstrap / support.c
blob8f78ebb1d6a7450a5a944f12f11413b6ee2a8b30
1 /*
2 Copyright (C) 2006-2011 The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Miscellaneous support functions.
6 Lang: English
7 */
9 #include <bootconsole.h>
10 #include <runtime.h>
11 #include <stdarg.h>
12 #include <string.h>
14 #include "bootstrap.h"
15 #include "support.h"
17 /* This comes from librom32 */
18 int __vcformat (void *data, int(*outc)(int, void *), const char * format, va_list args);
20 char *__bs_remove_path(char *in)
22 char *p;
24 /* Go to the end of string */
25 for (p = in; *p; p++);
26 /* Now go backwards until we find a separator */
27 while (p > in && p[-1] != '/' && p[-1] != ':') p--;
29 return p;
32 /* Own memcpy(), because librom's one can use CopyMem() */
33 void *memcpy(void *dest, const void *src, size_t len)
35 void *ret = dest;
37 while (len >= 4)
39 *(unsigned long *)dest = *(unsigned long *)src;
40 len-=4;
41 dest+=4;
42 src+=4;
44 if (len >= 2)
46 *(unsigned short *)dest = *(unsigned short *)src;
47 dest+=2;
48 src+=2;
49 len-=2;
51 if (len == 1)
53 *(unsigned char *)dest = *(unsigned char *)src;
54 dest += 1;
57 return ret;
61 * Our extremely simple working memory allocator.
62 * We can't just use some memory region because kickstart modules are placed there by GRUB.
63 * We risk clobbering loaded kickstart in such a case.
64 * The only 100% usable memory is memory contained in our own file.
65 * So we reserve some workspace here. I hope 1MB is more than enough for out needs.
66 * This space ends up in .bss section, so it does not occupy this megabyte on disk.
68 static char workspace[0x1000000];
70 static char *MemPtr = workspace;
72 void *__bs_malloc(unsigned long size)
74 char *start = MemPtr;
75 char *end;
77 /* Longword-align the size */
78 size = (size + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
79 end = start + size;
82 * _start is provided by linker script, it marks start of
83 * our executable. This is the end of allocatable region.
84 * We also count reserved space for stack which is placed in the
85 * end of our working memory.
87 if (end > workspace + sizeof(workspace))
88 return 0;
90 MemPtr = end;
92 return start;
95 /* This routine resets the allocator and releases all previously allocated memory */
96 void __bs_free(void)
98 MemPtr = workspace;
101 static int kputc(int c, void *data)
103 con_Putc(c);
105 return 1;
108 /* KNOWN BUG: %llu and %lld will not work here. See notice in compiler/clib/__vcformat.c. */
109 void kprintf(const char *format, ...)
111 va_list ap;
113 va_start(ap, format);
115 __vcformat(0, kputc, format, ap);
117 va_end(ap);
120 /* The same as kprintf(). Needed for ELF loader. */
121 void DisplayError(char *format, ...)
123 va_list ap;
125 va_start(ap, format);
127 __vcformat(0, kputc, format, ap);
129 va_end(ap);