void platform_early_init(void) { /* initialize the interrupt controller */ arm_gic_init(); arm_generic_timer_init(ARM_GENERIC_TIMER_PHYSICAL_INT, 0); uart_init_early(); /* look for a flattened device tree just before the kernel */ const void *fdt = (void *)KERNEL_BASE; int err = fdt_check_header(fdt); if (err >= 0) { /* walk the nodes, looking for 'memory' */ int depth = 0; int offset = 0; for (;;) { offset = fdt_next_node(fdt, offset, &depth); if (offset < 0) break; /* get the name */ const char *name = fdt_get_name(fdt, offset, NULL); if (!name) continue; /* look for the 'memory' property */ if (strcmp(name, "memory") == 0) { int lenp; const void *prop_ptr = fdt_getprop(fdt, offset, "reg", &lenp); if (prop_ptr && lenp == 0x10) { /* we're looking at a memory descriptor */ //uint64_t base = fdt64_to_cpu(*(uint64_t *)prop_ptr); uint64_t len = fdt64_to_cpu(*((const uint64_t *)prop_ptr + 1)); /* trim size on certain platforms */ #if ARCH_ARM if (len > 1024*1024*1024U) { len = 1024*1024*1024; /* only use the first 1GB on ARM32 */ printf("trimming memory to 1GB\n"); } #endif /* set the size in the pmm arena */ arena.size = len; } } } } /* add the main memory arena */ pmm_add_arena(&arena); /* reserve the first 64k of ram, which should be holding the fdt */ struct list_node list = LIST_INITIAL_VALUE(list); pmm_alloc_range(MEMBASE, 0x10000 / PAGE_SIZE, &list); }
#include <list.h> #include <kernel/spinlock.h> #include <lib/console.h> #include <lib/page_alloc.h> #define LOCAL_TRACE 0 /* heap tracing */ #if LK_DEBUGLEVEL > 0 static bool heap_trace = false; #else #define heap_trace (false) #endif /* delayed free list */ struct list_node delayed_free_list = LIST_INITIAL_VALUE(delayed_free_list); spin_lock_t delayed_free_lock = SPIN_LOCK_INITIAL_VALUE; #if WITH_LIB_HEAP_MINIHEAP /* miniheap implementation */ #include <lib/miniheap.h> static inline void *HEAP_MALLOC(size_t s) { return miniheap_alloc(s, 0); } static inline void *HEAP_REALLOC(void *ptr, size_t s) { return miniheap_realloc(ptr, s); } static inline void *HEAP_MEMALIGN(size_t boundary, size_t s) { return miniheap_alloc(s, boundary); } #define HEAP_FREE miniheap_free static inline void *HEAP_CALLOC(size_t n, size_t s) { size_t realsize = n * s; void *ptr = miniheap_alloc(n * s, 0); if (likely(ptr))
#include <stddef.h> #include <list.h> #include <malloc.h> #include <err.h> #include <lib/dpc.h> #include <kernel/thread.h> #include <kernel/event.h> struct dpc { struct list_node node; dpc_callback cb; void *arg; }; static struct list_node dpc_list = LIST_INITIAL_VALUE(dpc_list); static event_t dpc_event; static int dpc_thread_routine(void *arg); void dpc_init(void) { event_init(&dpc_event, false, 0); thread_detach_and_resume(thread_create("dpc", &dpc_thread_routine, NULL, DPC_PRIORITY, DEFAULT_STACK_SIZE)); } status_t dpc_queue(dpc_callback cb, void *arg, uint flags) { struct dpc *dpc;
* * Output is to the default graphics display */ #include <debug.h> #include <list.h> #include <stdlib.h> #include <string.h> #include <dev/display.h> #include <lib/gfx.h> #include <lib/font.h> #include <lib/text.h> #define TEXT_COLOR 0xffffffff static struct list_node text_list = LIST_INITIAL_VALUE(text_list); struct text_line { struct list_node node; const char *str; int x, y; }; /** * @brief Add a string to the console text */ void text_draw(int x, int y, const char *string) { struct text_line *line = malloc(sizeof(struct text_line)); line->str = strdup(string);
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "minip-internal.h" #include <err.h> #include <errno.h> #include <iovec.h> #include <list.h> #include <malloc.h> #include <stdint.h> #include <trace.h> #define LOCAL_TRACE 0 static struct list_node udp_list = LIST_INITIAL_VALUE(udp_list); struct udp_listener { struct list_node list; uint16_t port; udp_callback_t callback; void *arg; }; typedef struct udp_socket { uint32_t host; uint16_t sport; uint16_t dport; const uint8_t *mac; } udp_socket_t;
int ref; const struct fs_api *api; }; struct filehandle { filecookie *cookie; struct fs_mount *mount; }; struct dirhandle { dircookie *cookie; struct fs_mount *mount; }; static mutex_t mount_lock = MUTEX_INITIAL_VALUE(mount_lock); static struct list_node mounts = LIST_INITIAL_VALUE(mounts); static struct list_node fses = LIST_INITIAL_VALUE(fses); // defined in the linker script extern const struct fs_impl __fs_impl_start; extern const struct fs_impl __fs_impl_end; static const struct fs_impl *find_fs(const char *name) { for (const struct fs_impl *fs = &__fs_impl_start; fs != &__fs_impl_end; fs++) { if (!strcmp(name, fs->name)) return fs; } return NULL; }