Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
crt.c
Go to the documentation of this file.
1 #include "crt.h"
2 #include <stddef.h>
3 #include <stdint.h>
4 #include <string.h>
5 
6 extern int __bss_start__;
7 extern int __bss_end__;
8 extern void (*__preinit_array_start[])(void) __attribute__((weak));
9 extern void (*__preinit_array_end[])(void) __attribute__((weak));
10 extern void (*__init_array_start[])(void) __attribute__((weak));
11 extern void (*__init_array_end[])(void) __attribute__((weak));
12 extern void (*__fini_array_start[])(void) __attribute__((weak));
13 extern void (*__fini_array_end[])(void) __attribute__((weak));
14 
15 void __libc_init_array(void)
16 {
17  size_t count = __preinit_array_end - __preinit_array_start;
18  for(size_t i = 0; i < count; i++)
19  {
21  }
22 
23  count = __init_array_end - __init_array_start;
24  for(size_t i = 0; i < count; i++)
25  {
26  __init_array_start[i]();
27  }
28 }
29 
31 {
32  size_t count = __fini_array_end - __fini_array_start;
33  for(size_t i = count - 1; i > 0; i--)
34  {
35  __fini_array_start[i]();
36  }
37 }
38 
39 void CRTStartup(void)
40 {
41  memset(&__bss_start__, 0, (uintptr_t)&__bss_end__ - (uintptr_t)&__bss_start__);
42 
44 
45  // TODO: handle relocs?
46 }
__attribute__((noreturn, weak)) void __assert_fail(const char *expr
void __libc_fini_array(void)
Definition: crt.c:30
void CRTStartup(void)
Definition: crt.c:39
int __bss_end__
void * memset(void *dest, int c, size_t n)
Copies the value c into each of the first n characters of the object pointed to by dest.
void __libc_init_array(void)
void(* __preinit_array_start[])(void)
int __bss_start__