2 Copyright (C) 2006-2011 The AROS Development Team. All rights reserved.
5 Desc: Miscellaneous support functions.
9 #include <bootconsole.h>
14 #include "bootstrap.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
)
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
--;
32 /* Own memcpy(), because librom's one can use CopyMem() */
33 void *memcpy(void *dest
, const void *src
, size_t len
)
39 *(unsigned long *)dest
= *(unsigned long *)src
;
46 *(unsigned short *)dest
= *(unsigned short *)src
;
53 *(unsigned char *)dest
= *(unsigned char *)src
;
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
)
77 /* Longword-align the size */
78 size
= (size
+ sizeof(void *) - 1) & ~(sizeof(void *) - 1);
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
))
95 /* This routine resets the allocator and releases all previously allocated memory */
101 static int kputc(int c
, void *data
)
108 /* KNOWN BUG: %llu and %lld will not work here. See notice in compiler/clib/__vcformat.c. */
109 void kprintf(const char *format
, ...)
113 va_start(ap
, format
);
115 __vcformat(0, kputc
, format
, ap
);
120 /* The same as kprintf(). Needed for ELF loader. */
121 void DisplayError(char *format
, ...)
125 va_start(ap
, format
);
127 __vcformat(0, kputc
, format
, ap
);