├── .gitignore ├── Makefile ├── arch └── arm │ ├── include │ └── arm │ │ ├── align.h │ │ ├── asm.h │ │ ├── io.h │ │ ├── string.h │ │ ├── traps.h │ │ └── types.h │ ├── init │ ├── locore.S │ ├── module.mk │ ├── start.S │ ├── traps.c │ ├── vectors.S │ └── xboot.ld │ ├── lib │ ├── builtin │ │ └── div.S │ ├── module.mk │ └── string │ │ ├── bcopy.S │ │ ├── bzero.S │ │ ├── memcpy.S │ │ ├── memmove.S │ │ └── memset.S │ └── module.mk ├── bsp ├── raspberrypi2 │ ├── bcm2836.h │ ├── bcm2836.jsdt │ ├── bsp.mk │ ├── config.c │ └── raspberrypi.h ├── realview-pba8 │ ├── bsp.mk │ ├── config.c │ ├── realview-pba8.h │ ├── realview.jsdt │ └── rvpba8.h └── snowball │ ├── ap9500.h │ ├── bsp.mk │ ├── config.c │ ├── snowball.h │ └── snowball.jsdt ├── core ├── init.c ├── main.c └── module.mk ├── driver ├── timer │ ├── bcm_timer │ │ ├── bcm_timer.c │ │ ├── bcm_timer.h │ │ └── module.mk │ ├── sp804 │ │ ├── module.mk │ │ ├── sp804.c │ │ └── sp804.h │ └── ste_mtu │ │ ├── module.mk │ │ ├── ste_mtu.c │ │ └── ste_mtu.h └── uart │ └── pl011 │ ├── module.mk │ ├── pl011.c │ └── pl011.h ├── include ├── assert.h ├── boot │ ├── address.h │ ├── aslr.h │ ├── boot.h │ ├── boot_args.h │ ├── bsp.h │ ├── device_tree.h │ ├── dtre.h │ ├── globals.h │ ├── image3.h │ ├── macho.h │ ├── macho_loader.h │ └── memory_region.h ├── c99.h ├── crypto │ └── sha1.h ├── ctype.h ├── device │ ├── nvram.h │ ├── sysctl.h │ ├── timer.h │ └── uart.h ├── limits.h ├── panic.h ├── prng.h ├── shell │ ├── history.h │ └── shell.h ├── stdarg.h ├── stdbool.h ├── stddef.h ├── stdio.h ├── stdlib.h ├── string.h ├── sys │ ├── align.h │ ├── asm.h │ ├── io.h │ ├── page.h │ └── types.h └── tlsf │ └── tlsf.h ├── lib ├── boot │ ├── aslr.c │ ├── boot.c │ ├── device_tree.c │ ├── dtre.c │ ├── image3.c │ ├── jsdt.c │ ├── jsmn.c │ ├── jsmn.h │ ├── macho_loader.c │ ├── memory_region.c │ └── module.mk ├── crt │ ├── ctype │ │ ├── isacii.c │ │ ├── isalpha.c │ │ ├── isdigit.c │ │ ├── isspace.c │ │ ├── isupper.c │ │ └── module.mk │ ├── module.mk │ ├── stdio │ │ ├── module.mk │ │ └── printf.c │ ├── stdlib │ │ ├── env.c │ │ ├── malloc.c │ │ └── module.mk │ └── string │ │ ├── atoi.c │ │ ├── hextoul.c │ │ ├── module.mk │ │ ├── strchr.c │ │ ├── strcmp.c │ │ ├── strcpy.c │ │ ├── strdup.c │ │ ├── strlen.c │ │ ├── strncmp.c │ │ ├── strncpy.c │ │ ├── strtok.c │ │ └── strtoul.c ├── crypto │ ├── module.mk │ └── sha1.c ├── debug │ ├── assert.c │ ├── module.mk │ └── panic.c ├── device │ ├── module.mk │ ├── nvram.c │ ├── sysctl.c │ ├── timer.c │ └── uart.c ├── prng │ ├── module.mk │ └── prng.c ├── shell │ ├── cmds.c │ ├── cmds.h │ ├── cmds │ │ ├── boot.c │ │ ├── getenv.c │ │ ├── halt.c │ │ ├── help.c │ │ ├── history.c │ │ ├── module.mk │ │ ├── printenv.c │ │ ├── reset.c │ │ └── setenv.c │ ├── history.c │ ├── module.mk │ └── shell.c └── tlsf │ ├── module.mk │ └── tlsf.c ├── make ├── build.mk ├── dirs.mk ├── flags.mk ├── rules.mk ├── tools.mk └── vars.mk └── tools ├── Makefile ├── ccdv ├── Makefile └── ccdv.c ├── image3maker ├── Makefile └── image3maker.c └── scripts ├── archive.sh └── version.pl /.gitignore: -------------------------------------------------------------------------------- 1 | Build 2 | xboot*.bin 3 | tools/ccdv/ccdv 4 | tools/ccdv/ccdv.o 5 | tools/image3maker/image3maker 6 | tools/image3maker/image3maker.o 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Project name and version 2 | export RC_ProjectName := xBoot 3 | export RC_ProjectSourceVersion := 67 4 | export RC_ProjectBuildVersion := 4 5 | 6 | export SRCROOT := $(CURDIR) 7 | export OBJROOT := $(SRCROOT) 8 | export TOOLDIR := $(SRCROOT)/tools 9 | 10 | # Default build style 11 | export BUILD ?= DEBUG 12 | 13 | # Main build target 14 | export TARGET := xboot.$(PLATFORM).$(BUILD) 15 | 16 | include $(SRCROOT)/make/vars.mk 17 | include $(SRCROOT)/make/tools.mk 18 | ifdef PLATFORM 19 | BSP_DIR := $(SRCROOT)/bsp/$(PLATFORM) 20 | BSP_MKFILE := $(BSP_DIR)/bsp.mk 21 | ifneq ("$(wildcard $(BSP_MKFILE))","") 22 | include $(BSP_MKFILE) 23 | else 24 | $(error Unsupported platform "$(PLATFORM)" specified. Run "make help" for a list of supported platforms.) 25 | endif 26 | endif 27 | include $(SRCROOT)/make/dirs.mk 28 | include $(SRCROOT)/make/build.mk 29 | include $(SRCROOT)/make/flags.mk 30 | 31 | export DERIVED_SOURCES_DIR := $(BUILD_GEN) 32 | 33 | include $(SRCROOT)/make/rules.mk 34 | -------------------------------------------------------------------------------- /arch/arm/include/arm/align.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Misc helpers. 3 | */ 4 | 5 | #ifndef _HELPER_H_ 6 | #define _HELPER_H_ 7 | 8 | #define add_ptr2(x, y) ((uintptr_t)((uintptr_t)x + (uintptr_t)y)) 9 | #define add_ptr3(x, y, z) ((uintptr_t)((uintptr_t)x + (uintptr_t)y + (uintptr_t)z)) 10 | #define align_down(p, s) ((uintptr_t)(p)&~(s-1)) 11 | #define align_up(p, s) align_down((uintptr_t)(p)+s-1, s) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /arch/arm/include/arm/string.h: -------------------------------------------------------------------------------- 1 | /* String library - ARM-optimized functions 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef ARM_STRING_H 33 | #define ARM_STRING_H 34 | 35 | #include 36 | 37 | void bzero(void *ptr, size_t len); 38 | void *memset(void *ptr, int c, size_t len); 39 | void bcopy(const void *src, void *dest, size_t len); 40 | void *memcpy(void *dest, const void *src, size_t len); 41 | void *memmove(void *dest, const void *src, size_t len); 42 | 43 | void memset_pattern4(void *b, const void *c4, size_t len); 44 | void memset_pattern8(void *b, const void *c8, size_t len); 45 | void memset_pattern16(void *b, const void *c16, size_t len); 46 | 47 | size_t strlen(const char *str); 48 | char *strchr(const char *s, int c); 49 | int strcmp(const char *s1, const char *s2); 50 | int strncmp(const char *s1, const char *s2, size_t n); 51 | 52 | #endif /* !ARM_STRING_H */ -------------------------------------------------------------------------------- /arch/arm/include/arm/traps.h: -------------------------------------------------------------------------------- 1 | /* ARM exception trap handers - macros and definitions 2 | * 3 | * Copyright 2013, winocm. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * 16 | * If you are going to use this software in any form that does not involve 17 | * releasing the source to this project or improving it, let me know beforehand. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | 32 | #ifndef TRAPS_H 33 | #define TRAPS_H 34 | 35 | #include 36 | 37 | typedef enum { 38 | SLEH_ABORT_TYPE_PREFETCH_ABORT = 3, 39 | SLEH_ABORT_TYPE_DATA_ABORT = 4, 40 | } sleh_abort_reasons; 41 | 42 | typedef struct _abort_information_context { 43 | uint32_t gprs[13]; 44 | uint32_t sp; 45 | uint32_t lr; 46 | uint32_t pc; 47 | uint32_t cpsr; 48 | uint32_t fsr; 49 | uint32_t far; 50 | } abort_information_context_t; 51 | 52 | #endif /* !TRAPS_H */ -------------------------------------------------------------------------------- /arch/arm/include/arm/types.h: -------------------------------------------------------------------------------- 1 | /* ARM-specific size types 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef ARM_TYPES_H 33 | #define ARM_TYPES_H 34 | 35 | /* Primitive data types */ 36 | typedef char int8_t; 37 | typedef unsigned char uint8_t; 38 | typedef short int16_t; 39 | typedef unsigned short uint16_t; 40 | typedef int int32_t; 41 | typedef unsigned int uint32_t; 42 | typedef long long int64_t; 43 | typedef unsigned long long uint64_t; 44 | 45 | /* Pointer types */ 46 | typedef int ptrdiff_t; 47 | typedef int64_t intmax_t; 48 | typedef uint64_t uintmax_t; 49 | typedef int32_t intptr_t; 50 | typedef uint32_t uintptr_t; 51 | typedef int8_t* caddr_t; 52 | 53 | /* Size types */ 54 | typedef unsigned int size_t; 55 | 56 | #endif /* !ARM_TYPES_H */ -------------------------------------------------------------------------------- /arch/arm/init/locore.S: -------------------------------------------------------------------------------- 1 | /* CPU functions for xBoot 2 | * 3 | * Copyright 2013, winocm. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * 16 | * If you are going to use this software in any form that does not involve 17 | * releasing the source to this project or improving it, let me know beforehand. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | /** 34 | * locore_jump_to 35 | * 36 | * Shut down the bootloader and start the new OS image. 37 | */ 38 | EnterARM(locore_jump_to) 39 | cpsid if, #0x13 40 | 41 | #ifdef CORTEX_A8 42 | /* Disable L2 cache */ 43 | mov r9, r0 44 | mov r10, r1 45 | 46 | mrc p15, 0, r0, c1, c0, 1 /* read Auxiliary Control Register */ 47 | bic r0, r0, #0x00000002 /* disable L2 cache */ 48 | mcr p15, 0, r0, c1, c0, 1 /* store Auxiliary Control Register */ 49 | #endif 50 | 51 | /* Disable caching entirely. */ 52 | mrc p15, 0, r0, c1, c0, 0 53 | bic r0, r0, #0x00002300 54 | bic r0, r0, #0x00000005 55 | bic r0, r0, #0x00001000 56 | bic r0, r0, #(1 << 2) 57 | mcr p15, 0, r0, c1, c0, 0 58 | 59 | /* Disable VFP/SIMD */ 60 | mov r0, #0x00000000 61 | mcr p10, #0x7, r0, c8, c0, #0 62 | 63 | /* Disable I-cache */ 64 | mrc p15, 0, r0, c1, c0, 2 65 | bic r0, r0, #0x00f00000 66 | mcr p15, 0, r0, c1, c0, 2 67 | 68 | /* Clear caches. */ 69 | mov r0, #0 70 | mcr p15, 0, r0, c7, c5, 0 71 | mov r0, #0 72 | mcr p15, 0, r0, c7, c5, 4 73 | 74 | /* Disable MMU */ 75 | mrc p15, 0, r0, c1, c0, 0 76 | bic r0, r0, #1 77 | mcr p15, 0, r0, c1, c0, 0 78 | 79 | /* Clear prefetch buffer */ 80 | mov r0, #0 81 | mcr p15, 0, r0, c7, c5, 0 82 | mov r0, #0 83 | mcr p15, 0, r0, c7, c5, 4 84 | 85 | isb sy 86 | dsb sy 87 | 88 | /* Point of no return */ 89 | mov lr, r9 90 | mov r0, r1 91 | bx lr 92 | -------------------------------------------------------------------------------- /arch/arm/init/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/arch/arm/init 2 | 3 | S_SRC_FILES := \ 4 | start.S \ 5 | locore.S \ 6 | vectors.S 7 | 8 | C_SRC_FILES := \ 9 | traps.c 10 | 11 | SFLAGS += -I$(SRC_DIR)/../include 12 | CFLAGS += -I$(SRC_DIR)/../include 13 | 14 | S_SRCS += $(addprefix $(SRC_DIR)/, $(S_SRC_FILES)) 15 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 16 | -------------------------------------------------------------------------------- /arch/arm/init/xboot.ld: -------------------------------------------------------------------------------- 1 | /* Linker script for ARM xBoot 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | TARGET("elf32-littlearm") 33 | OUTPUT_FORMAT("elf32-littlearm") 34 | 35 | ENTRY(_start) 36 | 37 | SECTIONS 38 | { 39 | . = BOOT_TEXT_BASE; 40 | 41 | .init . : { 42 | . = ALIGN(4); 43 | KEEP(*(.init)); 44 | } 45 | .text . : { 46 | . = ALIGN(4); 47 | *(.text) 48 | } 49 | .rodata . : { 50 | . = ALIGN(4); 51 | *(.rodata) 52 | *(.rodata.*) 53 | } 54 | .data . : { 55 | . = ALIGN(4); 56 | *(.data) 57 | } 58 | .bss . : { 59 | . = ALIGN(4); 60 | PROVIDE(__sbss = .); 61 | *(.bss) 62 | PROVIDE(__ebss = .); 63 | } 64 | 65 | . = BOOT_TEXT_BASE + 512K; 66 | 67 | .heap . : { 68 | . = ALIGN(4); 69 | PROVIDE(__heap_start = .); 70 | __heap_size = 32M; 71 | . = . + __heap_size; 72 | PROVIDE(__heap_end = .); 73 | } 74 | 75 | .stack . : { 76 | . = ALIGN(8); 77 | PROVIDE(__stack_start = .); 78 | __stack_size = 256K; 79 | . = . + __stack_size; 80 | PROVIDE(__stack_end = .); 81 | } 82 | 83 | __end = .; 84 | 85 | /DISCARD/ : { 86 | *(.comment .note) 87 | *(.ARM.attributes) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /arch/arm/lib/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/arch/arm/lib 2 | 3 | S_SRC_FILES := \ 4 | string/bcopy.S \ 5 | string/bzero.S \ 6 | string/memcpy.S \ 7 | string/memmove.S \ 8 | string/memset.S \ 9 | builtin/div.S 10 | 11 | S_SRCS += $(addprefix $(SRC_DIR)/, $(S_SRC_FILES)) 12 | -------------------------------------------------------------------------------- /arch/arm/lib/string/bcopy.S: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: bcopy.S,v 1.3 2008/06/26 05:42:04 ray Exp $ */ 2 | /* $NetBSD: bcopy.S,v 1.2 2001/07/16 05:50:06 matt Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1997 The NetBSD Foundation, Inc. 6 | * All rights reserved. 7 | * 8 | * This code is derived from software contributed to The NetBSD Foundation 9 | * by Neil A. Carson and Mark Brinicombe 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | 35 | /* bcopy = memcpy/memmove with arguments reversed. */ 36 | 37 | EnterARM(bcopy) 38 | /* switch the source and destination registers */ 39 | eor r0, r1, r0 40 | eor r1, r0, r1 41 | eor r0, r1, r0 42 | b _memcpy 43 | -------------------------------------------------------------------------------- /arch/arm/lib/string/bzero.S: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: bzero.S,v 1.3 2008/06/26 05:42:04 ray Exp $ */ 2 | /* $NetBSD: bzero.S,v 1.2 2001/07/16 05:50:06 matt Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1997 The NetBSD Foundation, Inc. 6 | * All rights reserved. 7 | * 8 | * This code is derived from software contributed to The NetBSD Foundation 9 | * by Neil A. Carson and Mark Brinicombe 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | 35 | EnterARM(bzero) 36 | mov r2, r1 37 | mov r1, #0 38 | b _memset 39 | -------------------------------------------------------------------------------- /arch/arm/lib/string/memmove.S: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: memmove.S,v 1.3 2008/06/26 05:42:04 ray Exp $ */ 2 | /* $NetBSD: memmove.S,v 1.3 2003/04/05 23:08:52 bjh21 Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1997 The NetBSD Foundation, Inc. 6 | * All rights reserved. 7 | * 8 | * This code is derived from software contributed to The NetBSD Foundation 9 | * by Neil A. Carson and Mark Brinicombe 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | 35 | EnterARM(memmove) 36 | stmfd sp!, {r0, lr} 37 | bl _memcpy 38 | ldmfd sp!, {r0, pc} 39 | -------------------------------------------------------------------------------- /arch/arm/module.mk: -------------------------------------------------------------------------------- 1 | # Main make inclusions for ARM support 2 | 3 | include $(SRCROOT)/arch/arm/lib/module.mk 4 | include $(SRCROOT)/arch/arm/init/module.mk 5 | -------------------------------------------------------------------------------- /bsp/raspberrypi2/bcm2836.h: -------------------------------------------------------------------------------- 1 | /* BCM2836-specific definitions 2 | * 3 | * Copyright (c) 2014, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef BCM2836_H 33 | #define BCM2836_H 34 | 35 | /* bcm2836-specific memory map defs */ 36 | #define BCM2836_PERIPH_BASE 0x3F000000 37 | #define BCM2836_GPIO_BASE (BCM2836_PERIPH_BASE + 0x200000) 38 | #define BCM2836_UART0_BASE (BCM2836_PERIPH_BASE + 0x201000) 39 | #define BCM2836_TIMER_BASE (BCM2836_PERIPH_BASE + 0x3000) 40 | 41 | /* bcm2836 gpio stuff */ 42 | #define BCM_GPIO_GPPUD 0x94 43 | #define BCM_GPIO_GPPUDCLK0 0x98 44 | #define BCM_GPIO_PIN(p) (1 << p) 45 | 46 | /* uart clock speed in Hz */ 47 | #define PL011_CLOCK_RATE 3000000 48 | 49 | #endif /* !BCM2836_H */ 50 | -------------------------------------------------------------------------------- /bsp/raspberrypi2/bcm2836.jsdt: -------------------------------------------------------------------------------- 1 | { 2 | 'compatible': ['Broadcom BCM2836', 'arm-soc'], 3 | 'APPL,phandle': 0x1, 4 | @ [ 5 | { 6 | 'name': 'chosen', 7 | @ [ 8 | { 9 | 'name': 'memory-map', 10 | 'device_type': 'memory', 11 | 'reg': [0x0, 0x10000000] 12 | } 13 | ] 14 | }, 15 | { 16 | 'name': 'cpus', 17 | @ [ 18 | { 19 | 'name': 'cpu0', 20 | 'compatible': ['arm-cpu', 'armv7-cpu'], 21 | 'device_type': 'cpu', 22 | 'APPL,phandle': 0x2, 23 | 'reg': 0xf00 24 | }, 25 | { 26 | 'name': 'cpu1', 27 | 'compatible': ['arm-cpu', 'armv7-cpu'], 28 | 'device_type': 'cpu', 29 | 'APPL,phandle': 0x3, 30 | 'reg': 0xf01 31 | }, 32 | { 33 | 'name': 'cpu2', 34 | 'compatible': ['arm-cpu', 'armv7-cpu'], 35 | 'device_type': 'cpu', 36 | 'APPL,phandle': 0x4, 37 | 'reg': 0xf02 38 | }, 39 | { 40 | 'name': 'cpu3', 41 | 'compatible': ['arm-cpu', 'armv7-cpu'], 42 | 'device_type': 'cpu', 43 | 'APPL,phandle': 0x5, 44 | 'reg': 0xf03 45 | }, 46 | ] 47 | }, 48 | { 49 | 'name': 'arm-io', 50 | 'compatible': ['arm-io,brcm'], 51 | 'device_type': 'brcm-io', 52 | @ [ 53 | { 54 | 'name': 'mailbox', 55 | 'compatible': ['mailbox,brcm'], 56 | 'device_type': 'mailbox', 57 | 'APPL,phandle': 0x6, 58 | 'reg': [0x7e00b880 0x40] 59 | 60 | }, 61 | { 62 | 'name': 'gic', 63 | 'compatible': ['gic,brcm'], 64 | 'device_type': 'interrupt-controller', 65 | 'APPL,phandle': 0x7, 66 | 'interrupt-controller': 'master', 67 | 'reg': [0x7e00b200 0x200] 68 | } 69 | ] 70 | } 71 | ] 72 | } 73 | -------------------------------------------------------------------------------- /bsp/raspberrypi2/bsp.mk: -------------------------------------------------------------------------------- 1 | # xBoot BSP for the Raspberry Pi 2 Board 2 | 3 | ARCH := arm 4 | SUBARCH := cortex-a7 5 | PLATFORM := raspberrypi 6 | DRAM_BASE := 0x00008000 7 | DRAM_SIZE := 0x10000000 8 | BOOT_TEXT_BASE := 0x00008000 9 | 10 | SRC_DIR := $(SRCROOT)/bsp/raspberrypi2 11 | 12 | C_SRC_FILES := \ 13 | config.c 14 | 15 | PLAT_DT_FILE := \ 16 | bcm2836.jsdt 17 | 18 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 19 | 20 | include $(SRCROOT)/driver/timer/bcm_timer/module.mk 21 | include $(SRCROOT)/driver/uart/pl011/module.mk 22 | -------------------------------------------------------------------------------- /bsp/raspberrypi2/raspberrypi.h: -------------------------------------------------------------------------------- 1 | /* board-specific configuration information for Raspberry Pi2 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR AND 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef RASPBERRY_PI2_H 33 | #define RASPBERRY_PI2_H 34 | 35 | /* see arch/arm/tools/mach-types in linux kernel */ 36 | #define MACH_TYPE 3139 37 | 38 | #endif /* !RASPBERRY_PI2_H */ 39 | -------------------------------------------------------------------------------- /bsp/realview-pba8/bsp.mk: -------------------------------------------------------------------------------- 1 | # xBoot BSP for the ARM RealView Platform Board 2 | 3 | ARCH := arm 4 | SUBARCH := cortex-a8 5 | PLATFORM := realview-pb 6 | DRAM_BASE := 0x70000000 7 | DRAM_SIZE := 0x20000000 8 | BOOT_TEXT_BASE := 0x80000040 9 | 10 | SRC_DIR := $(SRCROOT)/bsp/realview-pba8 11 | 12 | C_SRC_FILES := \ 13 | config.c 14 | 15 | PLAT_DT_FILE := \ 16 | realview.jsdt 17 | 18 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 19 | 20 | include $(SRCROOT)/driver/timer/sp804/module.mk 21 | include $(SRCROOT)/driver/uart/pl011/module.mk 22 | -------------------------------------------------------------------------------- /bsp/realview-pba8/realview-pba8.h: -------------------------------------------------------------------------------- 1 | /* board-specific configuration information for snowball 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR AND 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef REALVIEW_PBA8_H 33 | #define REALVIEW_PBA8_H 34 | 35 | /* see arch/arm/tools/mach-types in linux kernel */ 36 | #define MACH_TYPE 1897 37 | 38 | #endif /* !REALVIEW_PBA8_H */ 39 | -------------------------------------------------------------------------------- /bsp/realview-pba8/realview.jsdt: -------------------------------------------------------------------------------- 1 | { 2 | 'compatible': ['ARM RealView PB-A8', 'arm-soc'], 3 | 'APPL,phandle': 0x1, 4 | @ [ 5 | { 6 | 'name': 'chosen', 7 | @ [ 8 | { 9 | 'name': 'memory-map', 10 | 'device_type': 'memory', 11 | 'reg': [0x0, 0x10000000] 12 | } 13 | ] 14 | }, 15 | { 16 | 'name': 'cpus', 17 | @ [ 18 | { 19 | 'name': 'cpu0', 20 | 'compatible': ['arm-cpu', 'armv7-cpu'], 21 | 'device_type': 'cpu', 22 | 'APPL,phandle': 0x2, 23 | 'reg': 0xf00 24 | }, 25 | { 26 | 'name': 'cpu1', 27 | 'compatible': ['arm-cpu', 'armv7-cpu'], 28 | 'device_type': 'cpu', 29 | 'APPL,phandle': 0x3, 30 | 'reg': 0xf01 31 | }, 32 | { 33 | 'name': 'cpu2', 34 | 'compatible': ['arm-cpu', 'armv7-cpu'], 35 | 'device_type': 'cpu', 36 | 'APPL,phandle': 0x4, 37 | 'reg': 0xf02 38 | }, 39 | { 40 | 'name': 'cpu3', 41 | 'compatible': ['arm-cpu', 'armv7-cpu'], 42 | 'device_type': 'cpu', 43 | 'APPL,phandle': 0x5, 44 | 'reg': 0xf03 45 | }, 46 | ] 47 | }, 48 | { 49 | 'name': 'arm-io', 50 | 'compatible': ['arm-io,rvpb'], 51 | 'device_type': 'rvpb-io', 52 | } 53 | ] 54 | } 55 | -------------------------------------------------------------------------------- /bsp/realview-pba8/rvpba8.h: -------------------------------------------------------------------------------- 1 | /* RVPBA8-specific definitions 2 | * 3 | * Copyright (c) 2014, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef RVPBA8_H 33 | #define RVPBA8_H 34 | 35 | /* RVPBA8-specific memory map defs */ 36 | #define PL011_UART0_BASE 0x10009000 37 | #define SP804_TIMER01_BASE 0x10011000 38 | #define SYS_CTRL0_BASE 0x10001000 39 | #define SYS_CTL_LOCK 0x10000020 40 | #define SYS_RESETCTL 0x10000040 41 | 42 | /* RVPBA8-specific control/status bits */ 43 | #define SYS_PORESET_BIT (1 << 2) 44 | 45 | /* uart clock speed in Hz */ 46 | #define PL011_CLOCK_RATE 27000000 47 | 48 | /* sysctl unlocking value */ 49 | #define SYS_CTL_KEY 0xA05F 50 | 51 | #endif /* !RVPBA8_H */ 52 | -------------------------------------------------------------------------------- /bsp/snowball/ap9500.h: -------------------------------------------------------------------------------- 1 | /* AP9500-specific definitions 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef AP9500_H 33 | #define AP9500_H 34 | 35 | /* AP9500-specific memory map defs */ 36 | #define AP9500_PERIPH1_BASE 0x80120000 37 | #define AP9500_PERIPH2_BASE 0x80110000 38 | #define AP9500_PERIPH3_BASE 0x80000000 39 | #define AP9500_PERIPH4_BASE 0x80150000 40 | #define AP9500_PERIPH5_BASE 0xA03E0000 41 | #define AP9500_PERIPH6_BASE 0xA03C0000 42 | 43 | /* uart clock speed in Hz */ 44 | #define PL011_CLOCK_RATE 38400000 45 | #define STE_MTU_CLOCK_RATE 133000000 46 | 47 | #endif /* !AP9500_H */ 48 | -------------------------------------------------------------------------------- /bsp/snowball/bsp.mk: -------------------------------------------------------------------------------- 1 | # xBoot BSP for ST-Ericsson Snowball 2 | 3 | ARCH := arm 4 | SUBARCH := cortex-a9 5 | PLATFORM := snowball 6 | DRAM_BASE := 0x00000000 7 | DRAM_SIZE := 0x40000000 8 | BOOT_TEXT_BASE := 0x00100000 9 | 10 | SRC_DIR := $(SRCROOT)/bsp/snowball 11 | 12 | C_SRC_FILES := \ 13 | config.c 14 | 15 | PLAT_DT_FILE := \ 16 | snowball.jsdt 17 | 18 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 19 | 20 | include $(SRCROOT)/driver/timer/ste_mtu/module.mk 21 | include $(SRCROOT)/driver/uart/pl011/module.mk 22 | -------------------------------------------------------------------------------- /bsp/snowball/config.c: -------------------------------------------------------------------------------- 1 | /* AP9500-specific configuration information 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR AND 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | 44 | #include "ap9500.h" 45 | #include "snowball.h" 46 | 47 | /* Platform name */ 48 | char *bsp_platform_name = "ST-Ericsson Snowball"; 49 | 50 | /* Serial port configuration */ 51 | pl011_cfg pl011_config = { 52 | /* UART2 */ 53 | .baud = 115200, 54 | .clock = PL011_CLOCK_RATE, 55 | .base = (addr_t)(AP9500_PERIPH3_BASE + 0x7000), 56 | }; 57 | 58 | /* Delay timer configuration */ 59 | ste_mtu_cfg mtu_config = { 60 | .base = (addr_t)(AP9500_PERIPH6_BASE + 0x6000), 61 | }; 62 | 63 | /* Default environment settings for this platform */ 64 | static void bsp_env_init(void) 65 | { 66 | setenv("bootdelay", "10", 1); 67 | } 68 | 69 | int bsp_init(void) 70 | { 71 | /* Initialize the delay timer */ 72 | timer_init(); 73 | 74 | /* Initialize the serial port */ 75 | uart_init(); 76 | 77 | /* Initialize console output */ 78 | printf_init(uart_putc); 79 | 80 | /* Initialize the default environment */ 81 | bsp_env_init(); 82 | 83 | return 0; 84 | } 85 | 86 | void prcmu_reset(void) 87 | { 88 | return; 89 | } 90 | 91 | void prcmu_halt(void) 92 | { 93 | return; 94 | } 95 | 96 | /* Register system control interface */ 97 | sysctl_driver sysctl_drv = { 98 | prcmu_reset, 99 | prcmu_halt 100 | }; 101 | -------------------------------------------------------------------------------- /bsp/snowball/snowball.h: -------------------------------------------------------------------------------- 1 | /* board-specific configuration information for snowball 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR AND 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef SNOWBALL_H 33 | #define SNOWBALL_H 34 | 35 | /* see arch/arm/tools/mach-types in linux kernel */ 36 | #define MACH_TYPE 3363 37 | 38 | #endif /* !SNOWBALL_H */ 39 | -------------------------------------------------------------------------------- /bsp/snowball/snowball.jsdt: -------------------------------------------------------------------------------- 1 | /* test */ 2 | { 3 | 'compatible': ['NovaThor A9500', 'arm-soc'], 4 | 'APPL,phandle': 0x1, 5 | @ [ 6 | { 7 | 'name': 'chosen', 8 | @ [ 9 | { 10 | 'name': 'memory-map', 11 | 'device_type': 'memory', 12 | 'reg': [0x0, 0x10000000] 13 | } 14 | ] 15 | }, 16 | { 17 | 'name': 'cpus', 18 | @ [ 19 | { 20 | 'name': 'cpu0', 21 | 'compatible': ['arm-cpu', 'armv7-cpu'], 22 | 'device_type': 'cpu', 23 | 'APPL,phandle': 0x2, 24 | 'reg': 0xf00 25 | }, 26 | { 27 | 'name': 'cpu1', 28 | 'compatible': ['arm-cpu', 'armv7-cpu'], 29 | 'device_type': 'cpu', 30 | 'APPL,phandle': 0x3, 31 | 'reg': 0xf01 32 | } 33 | ] 34 | }, 35 | { 36 | 'name': 'arm-io', 37 | 'compatible': ['arm-io,ste'], 38 | 'device_type': 'ste-io', 39 | } 40 | ] 41 | } 42 | /* !test */ 43 | -------------------------------------------------------------------------------- /core/init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Startup routine for xBoot 3 | * 4 | * Copyright (c) 2017, Brian McKenzie 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the organization nor the names of its contributors may 18 | * be used to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 22 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | boot_args gBootArgs; 44 | 45 | extern const char __xBoot_version[]; 46 | extern const char __xBoot_build_version[]; 47 | 48 | /** 49 | * init_boot_args 50 | * 51 | * Initialize kernel boot-args 52 | */ 53 | static void init_boot_args(void) 54 | { 55 | bzero((void *)&gBootArgs, sizeof(boot_args)); 56 | 57 | gBootArgs.Revision = kBootArgsRevision; 58 | gBootArgs.Version = kBootArgsVersion2; 59 | 60 | gBootArgs.physBase = DRAM_BASE; 61 | gBootArgs.memSize = DRAM_SIZE; 62 | 63 | /* Use a random, page-aligned address. */ 64 | gBootArgs.virtBase = calc_aslr_virtbase(KERNEL_VMADDR); 65 | } 66 | 67 | /** 68 | * init_build_info 69 | * 70 | * Initialize exported built-time information 71 | */ 72 | static void init_build_info(void) 73 | { 74 | setenv_protect("build-style", BUILD_STYLE); 75 | setenv_protect("build-version", __xBoot_version); 76 | } 77 | 78 | /** 79 | * xboot_init 80 | * 81 | * Main xBoot initialization routine 82 | */ 83 | void xboot_init(void) 84 | { 85 | /* Initialize environment */ 86 | env_init(); 87 | 88 | /* Initialize build version info */ 89 | init_build_info(); 90 | 91 | /* Initialize BSP */ 92 | bsp_init(); 93 | 94 | /* Initialize device tree */ 95 | dtre_init(); 96 | 97 | /* Initialize boot-args */ 98 | init_boot_args(); 99 | 100 | /* Jump to main */ 101 | xboot_main(); 102 | } 103 | -------------------------------------------------------------------------------- /core/main.c: -------------------------------------------------------------------------------- 1 | /* Main loop 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #define SHELL_PROMPT "] " 44 | 45 | static void xboot_banner(void) 46 | { 47 | /* display banner */ 48 | printf("\nxBoot for %s\n", bsp_platform_name); 49 | printf("Copyright (c) 2017 Brian McKenzie \n"); 50 | printf("Build: %s %s %s %s\n\n", getenv("build-version"), getenv("build-style"), 51 | __DATE__, __TIME__); 52 | 53 | return; 54 | } 55 | 56 | void xboot_main(void) 57 | { 58 | int boot_delay; 59 | 60 | /* Display the banner */ 61 | xboot_banner(); 62 | 63 | /* Delay the boot if necessary */ 64 | printf("Press any key to enter interactive shell.\n"); 65 | for (boot_delay = atoi(getenv("bootdelay")); boot_delay > 0; boot_delay--) { 66 | printf("Booting in %2d seconds...\r", boot_delay); 67 | if (uart_poll() != 0) 68 | shell_prompt(SHELL_PROMPT); 69 | usleep(1000 * 1000); 70 | } 71 | 72 | 73 | /* Attempt to boot */ 74 | start_darwin(); 75 | 76 | return; 77 | } 78 | -------------------------------------------------------------------------------- /core/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/core 2 | 3 | C_SRC_FILES := \ 4 | init.c \ 5 | main.c 6 | 7 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 8 | -------------------------------------------------------------------------------- /driver/timer/bcm_timer/bcm_timer.c: -------------------------------------------------------------------------------- 1 | /* BCM283x System Timer driver 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | #include "bcm_timer.h" 38 | 39 | /* pull in config */ 40 | extern bcm_timer_cfg bcm_timer_config; 41 | static bcm_timer_cfg *cfg = &bcm_timer_config; 42 | 43 | /** 44 | * bcm_timer_init - initialize the delay timer 45 | */ 46 | void bcm_timer_init(void) 47 | { 48 | /* reset the timer */ 49 | bcm_timer_reset(); 50 | 51 | return; 52 | } 53 | 54 | /** 55 | * bcm_timer_reset - reset the timer to zero 56 | */ 57 | void bcm_timer_reset(void) 58 | { 59 | return; 60 | } 61 | 62 | /** 63 | * bcm_timer_usec_count - get the tick value of the timer in microseconds 64 | * @return: value between 0 and 2^32, counting up. 65 | */ 66 | uint32_t bcm_timer_usec_count(void) 67 | { 68 | uint32_t value; 69 | addr_t timer_base = cfg->base; 70 | 71 | value = readl(timer_base + BCM_TMR_CLO); 72 | 73 | return value; 74 | } 75 | 76 | /* register this driver */ 77 | timer_driver timer_drv = { 78 | bcm_timer_init, 79 | bcm_timer_reset, 80 | bcm_timer_usec_count, 81 | }; 82 | -------------------------------------------------------------------------------- /driver/timer/bcm_timer/bcm_timer.h: -------------------------------------------------------------------------------- 1 | /* BCM283x System Timer driver - prototypes and definitions 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef BCM_TIMER_H 33 | #define BCM_TIMER_H 34 | 35 | #include 36 | #include 37 | 38 | /* BCM timer configuration structure */ 39 | typedef struct { 40 | addr_t base; 41 | } bcm_timer_cfg; 42 | 43 | /* BCM timer driver prototypes */ 44 | void bcm_timer_init(void); 45 | void bcm_timer_reset(void); 46 | uint32_t bcm_timer_usec_count(void); 47 | 48 | /* BCM Timer registers */ 49 | #define BCM_TMR_CS 0x00 /* System timer control/status */ 50 | #define BCM_TMR_CLO 0x04 /* System timer counter (lower 32 bits) */ 51 | #define BCM_TMR_CHI 0x08 /* System timer counter (higher 32 bits) */ 52 | #define BCM_TMR_C(x) (0x0C + (0x04 * x)) /* System timer compare 0..3 */ 53 | 54 | #endif /* !BCM_TIMER_H */ 55 | -------------------------------------------------------------------------------- /driver/timer/bcm_timer/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/driver/timer/bcm_timer 2 | 3 | C_SRC_FILES := \ 4 | bcm_timer.c 5 | 6 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 7 | -------------------------------------------------------------------------------- /driver/timer/sp804/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/driver/timer/sp804 2 | 3 | C_SRC_FILES := \ 4 | sp804.c 5 | 6 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 7 | -------------------------------------------------------------------------------- /driver/timer/sp804/sp804.c: -------------------------------------------------------------------------------- 1 | /* ARM SP804 Dual Timer driver 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | #include "sp804.h" 38 | 39 | #define DELAY_TIMER 2 /* timer 2 will be the delay timer */ 40 | 41 | /* pull in config */ 42 | extern sp804_cfg sp804_config; 43 | 44 | /** 45 | * sp804_timer_init - initialize the delay timer 46 | */ 47 | void sp804_timer_init(void) 48 | { 49 | sp804_cfg *cfg = &sp804_config; 50 | addr_t base = cfg->base; 51 | 52 | /* disable the timer, clear all settings */ 53 | writel((base + SP804_TIMER2_CR), 0x0); 54 | 55 | /* set up a 32bit timer, with a prescale divisor of 1 */ 56 | writel((base + SP804_TIMER2_CR), (SP804_CR_TSZ_32B | SP804_CR_TEN)); 57 | 58 | /* reset the timer */ 59 | sp804_timer_reset(); 60 | 61 | return; 62 | } 63 | 64 | /** 65 | * sp804_timer_reset - reset the timer to zero 66 | */ 67 | void sp804_timer_reset(void) 68 | { 69 | sp804_cfg *cfg = &sp804_config; 70 | addr_t base = cfg->base; 71 | 72 | writel((base + SP804_TIMER2_LR), 0x0); 73 | 74 | return; 75 | } 76 | 77 | /** 78 | * sp804_timer_usec_count - get the tick value of the timer in microseconds 79 | * @return: value between 0 and 2^32, counting up. 80 | */ 81 | uint32_t sp804_timer_usec_count(void) 82 | { 83 | uint32_t value; 84 | sp804_cfg *cfg = &sp804_config; 85 | addr_t base = cfg->base; 86 | 87 | value = ~readl(base + SP804_TIMER2_VAL); 88 | 89 | return value; 90 | } 91 | 92 | /* register this driver */ 93 | timer_driver timer_drv = { 94 | sp804_timer_init, 95 | sp804_timer_reset, 96 | sp804_timer_usec_count, 97 | }; 98 | -------------------------------------------------------------------------------- /driver/timer/ste_mtu/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/driver/timer/ste_mtu 2 | 3 | C_SRC_FILES := \ 4 | ste_mtu.c 5 | 6 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 7 | -------------------------------------------------------------------------------- /driver/uart/pl011/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/driver/uart/pl011 2 | 3 | C_SRC_FILES := \ 4 | pl011.c 5 | 6 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 7 | -------------------------------------------------------------------------------- /include/assert.h: -------------------------------------------------------------------------------- 1 | /* Assertion handling for xBoot - definitions and macros 2 | * 3 | * Copyright 2013, winocm. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * 16 | * If you are going to use this software in any form that does not involve 17 | * releasing the source to this project or improving it, let me know beforehand. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ASSERT_H 32 | #define ASSERT_H 33 | 34 | void __assert_func(const char *file, int line, const char *method, const char *expression); 35 | 36 | #define assert(e) \ 37 | ((e) ? (void)0 : __assert_func(__FILE__, __LINE__, __func__, #e)) 38 | 39 | #endif /* !ASSERT_H */ 40 | -------------------------------------------------------------------------------- /include/boot/address.h: -------------------------------------------------------------------------------- 1 | /* Common addresses 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef ADDRESS_H 33 | #define ADDRESS_H 34 | 35 | /* Default kernel virtual address */ 36 | #if defined(__arm__) 37 | #define KERNEL_VMADDR 0x80001000 38 | #else 39 | #error "Unsupported architecture" 40 | #endif 41 | 42 | #endif /* !ADDRESS_H */ 43 | -------------------------------------------------------------------------------- /include/boot/aslr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Brian McKenzie 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef ASLR_H 31 | #define ASLR_H 32 | 33 | #include 34 | 35 | #if defined(__arm__) 36 | #define ASLR_MULTIPLIER 0x00200000 37 | #else 38 | #error "Unsupported architecture" 39 | #endif 40 | 41 | extern uintptr_t calc_aslr_virtbase(uintptr_t addr); 42 | 43 | #endif /* !ASLR_H */ 44 | -------------------------------------------------------------------------------- /include/boot/boot.h: -------------------------------------------------------------------------------- 1 | /* Bootloader prototypes 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | 33 | #ifndef BOOT_H 34 | #define BOOT_H 35 | 36 | /* xBoot main routine */ 37 | extern void xboot_main(void); 38 | 39 | /* Bootload Darwin kernel */ 40 | extern void start_darwin(void); 41 | 42 | #endif /* !XBOOT_H */ 43 | -------------------------------------------------------------------------------- /include/boot/boot_args.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013, winocm. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _BOOT_ARGS_H_ 31 | #define _BOOT_ARGS_H_ 32 | 33 | /* 34 | * !!! Make sure this file matches with the kernel one !!! 35 | */ 36 | 37 | #include 38 | 39 | #define BOOT_LINE_LENGTH 256 40 | 41 | /* 42 | * Video information. 43 | */ 44 | 45 | struct Boot_Video { 46 | uint32_t v_baseAddr; 47 | uint32_t v_display; 48 | uint32_t v_rowBytes; 49 | uint32_t v_width; 50 | uint32_t v_height; 51 | uint32_t v_depth; 52 | }; 53 | typedef struct Boot_Video Boot_Video; 54 | 55 | /* 56 | * Boot arguments structure. 57 | */ 58 | #define kBootArgsRevision 1 59 | 60 | #define kBootArgsVersion1 1 /* Previous? */ 61 | #define kBootArgsVersion2 2 /* iOS 4 */ 62 | #define kBootArgsVersion3 3 /* iOS 6? 7 for sure. */ 63 | 64 | typedef struct boot_args { 65 | uint16_t Revision; 66 | uint16_t Version; 67 | uint32_t virtBase; 68 | uint32_t physBase; 69 | uint32_t memSize; 70 | uint32_t topOfKernelData; 71 | Boot_Video Video; 72 | uint32_t machineType; 73 | void *deviceTreeP; /* VA of DeviceTree */ 74 | uint32_t deviceTreeLength; 75 | char commandLine[BOOT_LINE_LENGTH]; 76 | } boot_args; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /include/boot/bsp.h: -------------------------------------------------------------------------------- 1 | /* Board Support Package prototypes 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef BSP_H 33 | #define BSP_H 34 | 35 | /* Platform name to be shown in banner */ 36 | extern char *bsp_platform_name; 37 | 38 | /* Platform bsp initialization routine */ 39 | extern int bsp_init(void); 40 | 41 | #endif /* !BSP_H */ 42 | -------------------------------------------------------------------------------- /include/boot/device_tree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights 7 | * Reserved. This file contains Original Code and/or Modifications of 8 | * Original Code as defined in and that are subject to the Apple Public 9 | * Source License Version 2.0 (the "License"). You may not use this file 10 | * except in compliance with the License. Please obtain a copy of the 11 | * License at http://www.apple.com/publicsource and read it before using 12 | * this file. 13 | * 14 | * The Original Code and all software distributed under the License are 15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the 19 | * License for the specific language governing rights and limitations 20 | * under the License. 21 | * 22 | * @APPLE_LICENSE_HEADER_END@ 23 | */ 24 | 25 | #ifndef __DEVICE_TREE_H 26 | #define __DEVICE_TREE_H 27 | 28 | #include 29 | 30 | #include 31 | 32 | typedef struct _Property { 33 | const char *name; 34 | uint32_t length; 35 | void *value; 36 | 37 | struct _Property *next; 38 | } Property; 39 | 40 | typedef struct _Node { 41 | struct _Property *properties; 42 | struct _Property *last_prop; 43 | 44 | struct _Node *children; 45 | 46 | struct _Node *next; 47 | } Node; 48 | 49 | extern Property *DT__AddProperty(Node * node, const char *name, uint32_t length, 50 | void *value); 51 | 52 | extern Node *DT__AddChild(Node * parent, const char *name); 53 | 54 | Node *DT__FindNode(const char *path, bool createIfMissing); 55 | 56 | extern void DT__FreeProperty(Property * prop); 57 | 58 | extern void DT__FreeNode(Node * node); 59 | 60 | extern char *DT__GetName(Node * node); 61 | 62 | Node *DT__RootNode(void); 63 | 64 | void DT__Initialize(void); 65 | 66 | /* 67 | * Free up memory used by in-memory representation 68 | * of device tree. 69 | */ 70 | extern void DT__Finalize(void); 71 | 72 | void DT__GetDeviceTreeSize(uint32_t *size); 73 | 74 | void DT__FlattenDeviceTree(void **result, uint32_t * length); 75 | 76 | void DTInit(void *base); 77 | 78 | typedef struct OpaqueDTEntry* DTEntry; 79 | void DT__RecreateFlattenedTree(DTEntry entry); 80 | 81 | int DTGetProperty(const DTEntry entry, const char *propertyName, void **propertyValue, unsigned int *propertySize); 82 | 83 | #endif /* __DEVICE_TREE_H */ 84 | -------------------------------------------------------------------------------- /include/boot/dtre.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef DTRE_H 31 | #define DTRE_H 32 | 33 | #include 34 | 35 | extern void dtre_init(void); 36 | extern uint32_t dtre_get_size(void); 37 | extern Node *dtre_root_node(void); 38 | extern Node *dtre_find_node(const char *path, bool create); 39 | extern int dtre_create_node(Node *node, char *name, void* datap, int size); 40 | extern int dtre_allocate_memory_range(char *name, long start, long length, long type); 41 | extern void dtre_flatten(void *data, uint32_t length); 42 | 43 | #endif /* !DTRE_H */ 44 | -------------------------------------------------------------------------------- /include/boot/globals.h: -------------------------------------------------------------------------------- 1 | /* Bootloader globals 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef GLOBALS_H 33 | #define GLOBALS_H 34 | 35 | #include 36 | #include 37 | 38 | extern boot_args gBootArgs; 39 | 40 | #endif /* !GLOBALS_H */ 41 | -------------------------------------------------------------------------------- /include/boot/macho_loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013, winocm. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _MACHO_LOADER_H_ 31 | #define _MACHO_LOADER_H_ 32 | 33 | #include 34 | 35 | /* 36 | * The global loader context is used to keep track of the loaded mach-o 37 | * file and related properties such as VM bias and so on. 38 | */ 39 | typedef struct __loader_context { 40 | uint8_t *source; /* Original file source */ 41 | uint8_t *load_addr; /* Load address */ 42 | uint32_t entry; /* Entrypoint */ 43 | uint32_t vm_bias; /* VM address the file is based to */ 44 | uint32_t vm_size; /* Size of the object after mapping. */ 45 | struct dysymtab_command* dsymtab; 46 | } loader_context_t; 47 | 48 | /* 49 | * These are the error codes returned by the loader for core operations. 50 | */ 51 | typedef enum { 52 | kLoadSuccess = 0, 53 | kLoadFailure = -1, 54 | kLoadBadImage = -2, 55 | kLoadMalformedSection = -3, 56 | kLoadWrongArchitecture = -4, 57 | kLoadUnexpectedError = -5, 58 | kLoadInvalidParameter = -6, 59 | kLoadBadContext = -7, 60 | kLoadThatImageSucks = 0xBEEF 61 | } loader_return_t; 62 | 63 | /* 64 | * API functions. 65 | */ 66 | loader_return_t macho_rebase(loader_context_t * ctx, uint32_t slide); 67 | 68 | loader_return_t macho_initialize(loader_context_t * ctx, void *file); 69 | 70 | loader_return_t macho_set_vm_bias(loader_context_t * ctx, uint32_t vmaddr); 71 | 72 | loader_return_t macho_get_entrypoint(loader_context_t * ctx, uint32_t * ep); 73 | 74 | loader_return_t macho_file_map(loader_context_t * ctx, uint32_t loadaddr, uint32_t slide); 75 | 76 | uint32_t macho_get_vmsize(loader_context_t * ctx); 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /include/boot/memory_region.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013, winocm. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _MEMORY_REGIONS_H_ 31 | #define _MEMORY_REGIONS_H_ 32 | 33 | #include 34 | 35 | typedef struct __memory_region_t { 36 | uint32_t base; 37 | uint32_t pos; 38 | } memory_region_t; 39 | 40 | void *memory_region_reserve(memory_region_t * reg, uint32_t size, int align); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/c99.h: -------------------------------------------------------------------------------- 1 | /* C99 macros and definitions 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef C99_H 33 | #define C99_H 34 | 35 | /* c99-specific keywords */ 36 | #define restrict __restrict__ 37 | 38 | #endif /* !C99_H */ 39 | -------------------------------------------------------------------------------- /include/crypto/sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA1_H 2 | #define SHA1_H 3 | 4 | /* 5 | SHA-1 in C 6 | By Steve Reid 7 | 100% Public Domain 8 | */ 9 | 10 | #include 11 | 12 | 13 | #define SHA_DIGEST_LENGTH 20 14 | 15 | typedef struct 16 | { 17 | uint32_t state[5]; 18 | uint32_t count[2]; 19 | unsigned char buffer[64]; 20 | } SHA1_CTX; 21 | 22 | void SHA1Transform( 23 | uint32_t state[5], 24 | const unsigned char buffer[64] 25 | ); 26 | 27 | void SHA1Init( 28 | SHA1_CTX * context 29 | ); 30 | 31 | void SHA1Update( 32 | SHA1_CTX * context, 33 | const unsigned char *data, 34 | uint32_t len 35 | ); 36 | 37 | void SHA1Final( 38 | unsigned char digest[20], 39 | SHA1_CTX * context 40 | ); 41 | 42 | void SHA1( 43 | char *hash_out, 44 | const char *str, 45 | int len); 46 | 47 | #endif /* SHA1_H */ 48 | -------------------------------------------------------------------------------- /include/ctype.h: -------------------------------------------------------------------------------- 1 | /* Standard library api 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef CTYPE_H 33 | #define CTYPE_H 34 | 35 | extern int isascii(int c); 36 | extern int isalpha(int c); 37 | extern int isdigit(int c); 38 | extern int isspace(int c); 39 | extern int isupper(int c); 40 | 41 | #endif /* !CTYPE_H */ 42 | -------------------------------------------------------------------------------- /include/device/sysctl.h: -------------------------------------------------------------------------------- 1 | /* System control device api 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef SYSCTL_H 33 | #define SYSCTL_H 34 | 35 | /* sysctl driver interface */ 36 | typedef struct { 37 | void (*reset)(void); 38 | void (*poweroff)(void); 39 | } sysctl_driver; 40 | 41 | /* sysctl driver prototypes */ 42 | extern void sysctl_reset(void); 43 | extern void sysctl_poweroff(void); 44 | 45 | #endif /* !SYSCTL_H */ 46 | -------------------------------------------------------------------------------- /include/device/timer.h: -------------------------------------------------------------------------------- 1 | /* Timer device api 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef TIMER_H 33 | #define TIMER_H 34 | 35 | #include 36 | 37 | /* timer device interface */ 38 | typedef struct { 39 | void (*init)(void); 40 | void (*reset)(void); 41 | uint32_t (*count_usec)(void); 42 | } timer_driver; 43 | 44 | /* timer device prototypes */ 45 | extern void timer_init(void); 46 | extern void timer_reset(void); 47 | extern uint32_t timer_read(void); 48 | extern void usleep(uint32_t us); 49 | 50 | #endif /* !TIMER_H */ 51 | -------------------------------------------------------------------------------- /include/device/uart.h: -------------------------------------------------------------------------------- 1 | /* UART device api 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef UART_H 33 | #define UART_H 34 | 35 | #include 36 | 37 | /* uart driver interface */ 38 | typedef struct { 39 | void (*init)(void); 40 | int (*poll)(void); 41 | uint32_t (*getc)(void); 42 | void (*putc)(uint32_t c); 43 | void (*puts)(const char *str); 44 | } uart_driver; 45 | 46 | /* uart driver prototypes */ 47 | extern void uart_init(void); 48 | extern int uart_poll(void); 49 | extern uint32_t uart_getc(void); 50 | extern void uart_putc(int c); 51 | extern void uart_puts(const char *str); 52 | 53 | #endif /* !UART_H */ 54 | -------------------------------------------------------------------------------- /include/limits.h: -------------------------------------------------------------------------------- 1 | /* Standard library api 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef LIMITS_H 33 | #define LIMITS_H 34 | 35 | #define CHAR_BIT 8 /* Max. number of bits that can fit in a char */ 36 | 37 | #define LINE_MAX 2048 /* Max. number of bytes of a utility's input line */ 38 | #define NAME_MAX 1024 /* Max. number of bytes in a file name */ 39 | 40 | /* TODO: This should go into an arch-specific header once we support 64bit systems. */ 41 | #if defined(__arm__) 42 | #define LONG_BIT 32 /* Number of bits in a long */ 43 | #define ULONG_MAX 0xFFFFFFFFUL /* Max. value of type unsigned long */ 44 | #else 45 | #error "Unsupported architecture" 46 | #endif 47 | 48 | #endif /* !LIMITS_H */ 49 | -------------------------------------------------------------------------------- /include/panic.h: -------------------------------------------------------------------------------- 1 | /* Panic handling for xBoot - prototypes and definitions 2 | * 3 | * Copyright 2013, winocm. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * 16 | * If you are going to use this software in any form that does not involve 17 | * releasing the source to this project or improving it, let me know beforehand. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef PANIC_H 32 | #define PANIC_H 33 | 34 | void panic(const char *panicStr, ...); 35 | 36 | #endif /* !PANIC_H */ -------------------------------------------------------------------------------- /include/prng.h: -------------------------------------------------------------------------------- 1 | /* PRNG api 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef PRNG_H 33 | #define PRNG_H 34 | 35 | #include 36 | 37 | #if defined(__arm__) 38 | #define ENTROPY_SIZE 9600 39 | #elif defined(__arm64__) 40 | #define ENTROPY_SIZE 4000 41 | #else 42 | #error "Unsupported architecture" 43 | #endif 44 | 45 | extern uint32_t prng_get_random_uint32(void); 46 | extern void prng_get_random_bytes(char *buf, uint32_t len); 47 | 48 | #endif /* !PRNG_H */ 49 | -------------------------------------------------------------------------------- /include/shell/history.h: -------------------------------------------------------------------------------- 1 | /* Common shell history structures and api. 2 | * 3 | * Copyright (c) 2018, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef SHELL_HISTROY_H 33 | #define SHELL_HISTORY_H 34 | 35 | #include 36 | 37 | #define DEFAULT_HISTORY_DEPTH 16 38 | 39 | typedef struct history_entry { 40 | size_t size; 41 | size_t count; 42 | char *buffer; 43 | struct history_entry *next; 44 | struct history_entry *last; 45 | } history_entry_t; 46 | 47 | typedef struct history_queue { 48 | size_t depth; 49 | size_t count; 50 | history_entry_t *head; 51 | history_entry_t *tail; 52 | } history_queue_t; 53 | 54 | extern int shell_history_init(size_t depth); 55 | extern int shell_history_push(const char *line, size_t size); 56 | extern int shell_history_print(void); 57 | 58 | extern char *shell_history_last_line(char *lp, size_t *size); 59 | extern char *shell_history_next_line(char *lp, size_t *size); 60 | 61 | #endif /* !SHELL_HISTORY_H */ 62 | -------------------------------------------------------------------------------- /include/shell/shell.h: -------------------------------------------------------------------------------- 1 | /* Common shell structures and apis. 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef SHELL_H 33 | #define SHELL_H 34 | 35 | /* Command entry structure */ 36 | typedef struct command_handle { 37 | char *name; /* Command name */ 38 | char *desc; /* Short description */ 39 | void (*help)(void); /* Help function */ 40 | int (*main)(int, char **); /* Entry function */ 41 | } cmd_handle_t; 42 | 43 | /* Command interface prototypes */ 44 | extern void shell_prompt(const char *prompt); 45 | extern cmd_handle_t query_command(const char *name); 46 | 47 | #endif /* !SHELL_H */ 48 | -------------------------------------------------------------------------------- /include/stdarg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1991, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * from: @(#)stdarg.h 8.1 (Berkeley) 6/10/93 30 | */ 31 | 32 | #ifndef STDARG_H 33 | #define STDARG_H 34 | 35 | typedef char *va_list; 36 | 37 | #define __va_size(type) \ 38 | (((sizeof(type) + sizeof(long) - 1) / sizeof(long)) * sizeof(long)) 39 | 40 | #define va_start(ap, last) \ 41 | ((ap) = (va_list)&(last) + __va_size(last)) 42 | 43 | #define va_arg(ap, type) \ 44 | (*(type *)(void *)((ap) += __va_size(type), (ap) - __va_size(type))) 45 | 46 | #define va_end(ap) 47 | 48 | #define va_copy(dest, src) ((dest) = (src)) 49 | 50 | #endif /* !STDARG_H */ 51 | -------------------------------------------------------------------------------- /include/stdbool.h: -------------------------------------------------------------------------------- 1 | /* Standard library api 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef STDBOOL_H 33 | #define STDBOOL_H 34 | 35 | #define __bool_true_false_are_defined 1 36 | 37 | #define bool _Bool 38 | 39 | typedef bool boolean_t; 40 | 41 | #define true 1 42 | #define false 0 43 | 44 | /* TODO: get rid of this. */ 45 | #define TRUE true 46 | #define FALSE false 47 | 48 | #endif /* !STDBOOL_H */ 49 | -------------------------------------------------------------------------------- /include/stddef.h: -------------------------------------------------------------------------------- 1 | /* Standard library api 2 | * 3 | * Copyright (c) 2014, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef STDDEF_H 33 | #define STDDEF_H 34 | 35 | #include 36 | 37 | #define offsetof(st, m) \ 38 | __builtin_offsetof(st, m) 39 | 40 | #endif /* !STDDEF_H */ -------------------------------------------------------------------------------- /include/stdio.h: -------------------------------------------------------------------------------- 1 | /* Standard library api 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef STDIO_H 33 | #define STDIO_H 34 | 35 | #include 36 | 37 | #define EOF (-1) 38 | #define NULL ((void *)0) 39 | 40 | /* Initialization functions */ 41 | extern void printf_init(void (*putc)(int c)); 42 | 43 | /* printf prototypes */ 44 | extern int printf(const char *fmt, ...); 45 | extern int vprintf(const char *fmt, va_list ap); 46 | extern int sprintf(char *buf, const char *fmt, ...); 47 | 48 | #endif /* !STDIO_H */ 49 | -------------------------------------------------------------------------------- /include/stdlib.h: -------------------------------------------------------------------------------- 1 | /* Standard library api 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef STDLIB_H 33 | #define STDLIB_H 34 | 35 | #include 36 | #include 37 | 38 | /* Initialization structs */ 39 | typedef struct { 40 | char *name; 41 | char *value; 42 | } env_init_list_t; 43 | 44 | /* Initialization prototypes */ 45 | extern int env_init(void); 46 | 47 | /* Memory allocation prototypes */ 48 | extern void free(void *ptr); 49 | extern void *malloc(size_t size); 50 | extern void *calloc(size_t nelem, size_t elsize); 51 | extern void *realloc(void *ptr, size_t size); 52 | extern void *memalign(size_t align, size_t size); 53 | 54 | /* Environment manipulation prototypes */ 55 | extern char *getenv(const char *var); 56 | extern int unsetenv(const char *var); 57 | extern int setenv_protect(const char *var, const char *val); 58 | extern int setenv(const char *var, const char *val, int overwrite); 59 | extern void printenv(const char *var); 60 | 61 | #endif /* !STDLIB_H */ 62 | -------------------------------------------------------------------------------- /include/string.h: -------------------------------------------------------------------------------- 1 | /* Standard library api 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef STRING_H 33 | #define STRING_H 34 | 35 | #include 36 | #include 37 | 38 | #if defined(__arm__) 39 | #include 40 | #else 41 | #error "Unsupported architecture" 42 | #endif 43 | 44 | extern int atoi(const char *str); 45 | extern char *strdup(char *str); 46 | extern char *strcpy(char *dst, const char *src); 47 | extern char *strncpy(char *dst, const char *src, size_t len); 48 | extern char *strtok(char *s, const char *delim); 49 | extern char *strtok_r(char *s, const char *delim, char **last); 50 | extern unsigned long strtoul(const char *nptr, char **endptr, int base); 51 | extern unsigned long hextoul(const char *str); 52 | 53 | #endif /* !STRING_H */ 54 | -------------------------------------------------------------------------------- /include/sys/align.h: -------------------------------------------------------------------------------- 1 | /* Alignment helpers 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef ALIGN_H 33 | #define ALIGN_H 34 | 35 | #if defined(__arm__) 36 | #include 37 | #else 38 | #error "Unsupported architecture" 39 | #endif 40 | 41 | #endif /* !ALIGN_H */ 42 | -------------------------------------------------------------------------------- /include/sys/asm.h: -------------------------------------------------------------------------------- 1 | /* Misc. assembly macros and definitions 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef ASM_H 33 | #define ASM_H 34 | 35 | #if defined(__arm__) 36 | #include 37 | #else 38 | #error "Unsupported architecture" 39 | #endif 40 | 41 | #endif /* !ARM_ASM_H */ 42 | -------------------------------------------------------------------------------- /include/sys/io.h: -------------------------------------------------------------------------------- 1 | /* Register read/write macros, definitions, and operations 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef IO_H 33 | #define IO_H 34 | 35 | #if defined(__arm__) 36 | #include 37 | #else 38 | #error "Unsupported architecture" 39 | #endif 40 | 41 | #endif /* !IO_H */ 42 | -------------------------------------------------------------------------------- /include/sys/page.h: -------------------------------------------------------------------------------- 1 | /* Page-related macros and constants 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef PAGE_H 33 | #define PAGE_H 34 | 35 | #include 36 | 37 | #if defined(USE_4K_PAGES) 38 | 39 | #define PAGE_SHIFT 12 40 | #define PAGE_SIZE (1 << PAGE_SHIFT) 41 | #define PAGE_MASK (PAGE_SIZE - 1) 42 | 43 | #elif defined(USE_16K_PAGES) 44 | 45 | #define PAGE_SHIFT 14 46 | #define PAGE_SIZE (1 << PAGE_SHIFT) 47 | #define PAGE_MASK (PAGE_MASK - 1) 48 | 49 | #endif 50 | 51 | #define round_to_page(x) \ 52 | ((((uintptr_t)(x)) + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1)) 53 | 54 | #endif /* !PAGE_H */ 55 | -------------------------------------------------------------------------------- /include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* Misc. size types 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef TYPES_H 33 | #define TYPES_H 34 | 35 | #if defined(__arm__) 36 | #include 37 | #else 38 | #error "Unsupported architecture" 39 | #endif 40 | 41 | #endif /* !TYPES_H */ 42 | -------------------------------------------------------------------------------- /lib/boot/aslr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Brian McKenzie 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | 36 | static uint32_t get_aslr_slide(void) 37 | { 38 | int8_t data[1]; 39 | 40 | prng_get_random_bytes(data, 1); 41 | 42 | return (uint32_t)data[0]; 43 | } 44 | 45 | uintptr_t calc_aslr_virtbase(uintptr_t addr) 46 | { 47 | uint32_t slide; 48 | uintptr_t base; 49 | 50 | slide = get_aslr_slide(); 51 | base = (addr + ((slide + 1) * ASLR_MULTIPLIER)); 52 | round_to_page(base); 53 | 54 | return base; 55 | } 56 | -------------------------------------------------------------------------------- /lib/boot/jsmn.h: -------------------------------------------------------------------------------- 1 | #ifndef __JSMN_H_ 2 | #define __JSMN_H_ 3 | 4 | /** 5 | * JSON type identifier. Basic types are: 6 | * o Object 7 | * o Array 8 | * o String 9 | * o Children 10 | * o Other primitive: number, boolean (true/false) or null 11 | */ 12 | typedef enum { 13 | JSMN_PRIMITIVE = 0, 14 | JSMN_OBJECT = 1, 15 | JSMN_ARRAY = 2, 16 | JSMN_STRING = 3, 17 | JSMN_CHILDREN_TOKEN = 4 18 | } jsmntype_t; 19 | 20 | typedef enum { 21 | /* Not enough tokens were provided */ 22 | JSMN_ERROR_NOMEM = -1, 23 | /* Invalid character inside JSON string */ 24 | JSMN_ERROR_INVAL = -2, 25 | /* The string is not a full JSON packet, more bytes expected */ 26 | JSMN_ERROR_PART = -3, 27 | /* Everything was fine */ 28 | JSMN_SUCCESS = 0 29 | } jsmnerr_t; 30 | 31 | /** 32 | * JSON token description. 33 | * @param type type (object, array, string etc.) 34 | * @param start start position in JSON data string 35 | * @param end end position in JSON data string 36 | */ 37 | typedef struct { 38 | jsmntype_t type; 39 | int start; 40 | int end; 41 | int size; 42 | #ifdef JSMN_PARENT_LINKS 43 | int parent; 44 | #endif 45 | } jsmntok_t; 46 | 47 | /** 48 | * JSON parser. Contains an array of token blocks available. Also stores 49 | * the string being parsed now and current position in that string 50 | */ 51 | typedef struct { 52 | unsigned int pos; /* offset in the JSON string */ 53 | int toknext; /* next token to allocate */ 54 | int toksuper; /* superior token node, e.g parent object or array */ 55 | } jsmn_parser; 56 | 57 | /** 58 | * Create JSON parser over an array of tokens 59 | */ 60 | void jsmn_init(jsmn_parser * parser); 61 | 62 | /** 63 | * Run JSON parser. It parses a JSON data string into and array of tokens, each describing 64 | * a single JSON object. 65 | */ 66 | jsmnerr_t jsmn_parse(jsmn_parser * parser, const char *js, 67 | jsmntok_t * tokens, unsigned int num_tokens); 68 | 69 | #endif /* __JSMN_H_ */ 70 | -------------------------------------------------------------------------------- /lib/boot/memory_region.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013, winocm. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | void *memory_region_reserve(memory_region_t * reg, uint32_t size, int align) 36 | { 37 | uintptr_t start; 38 | assert(reg); 39 | if (align) { 40 | reg->pos = align_up(reg->pos, align); 41 | } 42 | start = reg->pos; 43 | reg->pos += size; 44 | return (void *)start; 45 | } 46 | -------------------------------------------------------------------------------- /lib/boot/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/boot 2 | 3 | C_SRC_FILES := \ 4 | aslr.c \ 5 | boot.c \ 6 | dtre.c \ 7 | jsdt.c \ 8 | device_tree.c \ 9 | image3.c \ 10 | jsmn.c \ 11 | macho_loader.c \ 12 | memory_region.c 13 | 14 | # needed for image3.c 15 | CFLAGS += -Wno-multichar 16 | 17 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 18 | -------------------------------------------------------------------------------- /lib/crt/ctype/isacii.c: -------------------------------------------------------------------------------- 1 | /* Character type routines 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | int isascii(int c) 35 | { 36 | return (c >= 0 && c <= 127); 37 | } 38 | -------------------------------------------------------------------------------- /lib/crt/ctype/isalpha.c: -------------------------------------------------------------------------------- 1 | /* Character type routines 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | int isalpha(int c) 35 | { 36 | return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); 37 | } 38 | -------------------------------------------------------------------------------- /lib/crt/ctype/isdigit.c: -------------------------------------------------------------------------------- 1 | /* Character type routines 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | int isdigit(int c) 35 | { 36 | return (c >= '0' && c <= '9'); 37 | } 38 | -------------------------------------------------------------------------------- /lib/crt/ctype/isspace.c: -------------------------------------------------------------------------------- 1 | /* Character type routines 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | int isspace(int c) 35 | { 36 | return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v' ); 37 | } 38 | -------------------------------------------------------------------------------- /lib/crt/ctype/isupper.c: -------------------------------------------------------------------------------- 1 | /* Character type routines 2 | * 3 | * Copyright (c) 2015, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | int isupper(int c) 35 | { 36 | return (c >= 'A' && c <= 'Z'); 37 | } 38 | -------------------------------------------------------------------------------- /lib/crt/ctype/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/crt/ctype 2 | 3 | C_SRC_FILES := \ 4 | isacii.c \ 5 | isalpha.c \ 6 | isdigit.c \ 7 | isspace.c \ 8 | isupper.c 9 | 10 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 11 | -------------------------------------------------------------------------------- /lib/crt/module.mk: -------------------------------------------------------------------------------- 1 | # Main make inclusions for ARM support 2 | 3 | include $(SRCROOT)/lib/crt/ctype/module.mk 4 | include $(SRCROOT)/lib/crt/stdio/module.mk 5 | include $(SRCROOT)/lib/crt/stdlib/module.mk 6 | include $(SRCROOT)/lib/crt/string/module.mk 7 | -------------------------------------------------------------------------------- /lib/crt/stdio/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/crt/stdio 2 | 3 | C_SRC_FILES := \ 4 | printf.c 5 | 6 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 7 | -------------------------------------------------------------------------------- /lib/crt/stdlib/malloc.c: -------------------------------------------------------------------------------- 1 | /* Memory allocation routines for xBoot 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | #include 39 | 40 | static pool_t pool; 41 | 42 | extern int __heap_start[]; 43 | extern int __heap_end[]; 44 | 45 | static bool malloc_inited = false; 46 | 47 | static void tlsf_init(void) 48 | { 49 | pool = tlsf_create_with_pool(__heap_start, 50 | (size_t)(__heap_end - __heap_start)); 51 | 52 | malloc_inited = true; 53 | } 54 | 55 | void *malloc(size_t size) 56 | { 57 | if (!malloc_inited) 58 | tlsf_init(); 59 | 60 | return tlsf_malloc(pool, size); 61 | } 62 | 63 | void *calloc(size_t nelem, size_t elsize) 64 | { 65 | void *ptr; 66 | 67 | ptr = malloc(nelem * elsize); 68 | 69 | if (ptr != NULL) 70 | memset(ptr, 0, (nelem * elsize)); 71 | 72 | return ptr; 73 | } 74 | 75 | void *memalign(size_t align, size_t size) 76 | { 77 | if (!malloc_inited) 78 | tlsf_init(); 79 | 80 | return tlsf_memalign(pool, align, size); 81 | } 82 | 83 | void *realloc(void *ptr, size_t size) 84 | { 85 | if (ptr == NULL) 86 | return NULL; 87 | 88 | return tlsf_realloc(pool, ptr, size); 89 | } 90 | 91 | void free(void *ptr) 92 | { 93 | if (ptr == NULL) 94 | return; 95 | 96 | return tlsf_free(pool, ptr); 97 | } 98 | -------------------------------------------------------------------------------- /lib/crt/stdlib/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/crt/stdlib 2 | 3 | C_SRC_FILES := \ 4 | env.c \ 5 | malloc.c 6 | 7 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 8 | -------------------------------------------------------------------------------- /lib/crt/string/atoi.c: -------------------------------------------------------------------------------- 1 | /* C Runtime Library 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | int atoi(const char *str) 35 | { 36 | int val = 0; 37 | int neg = 0; 38 | 39 | if (*str == '-') { 40 | neg = 1; 41 | *str++; 42 | } 43 | 44 | while (*str != '\0') { 45 | if ( *str >= '0' || *str <= '9' ) { 46 | val *= 10; 47 | val += (int)(*str - '0'); 48 | } 49 | *str++; 50 | } 51 | 52 | if (neg == 1) 53 | val = 0 - val; 54 | 55 | return val; 56 | } 57 | -------------------------------------------------------------------------------- /lib/crt/string/hextoul.c: -------------------------------------------------------------------------------- 1 | /* String library 2 | * 3 | * Copyright (c) 2014, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | static int htoi(int h) 35 | { 36 | if (h <= '9') 37 | return h - 48; 38 | 39 | if (h <= 'F') 40 | return h - 55; 41 | 42 | if (h <= 'f') 43 | return h - 87; 44 | 45 | return 0; 46 | } 47 | 48 | unsigned long hextoul(const char *str) 49 | { 50 | unsigned long val = 0; 51 | 52 | if (*str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X')) 53 | str += 2; 54 | 55 | while (*str != '\0') { 56 | val *= 16; 57 | val += (unsigned long)htoi(*str); 58 | *str++; 59 | } 60 | 61 | return val; 62 | } 63 | -------------------------------------------------------------------------------- /lib/crt/string/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/crt/string 2 | 3 | C_SRC_FILES := \ 4 | atoi.c \ 5 | hextoul.c \ 6 | strchr.c \ 7 | strcmp.c \ 8 | strcpy.c \ 9 | strdup.c \ 10 | strlen.c \ 11 | strncmp.c \ 12 | strncpy.c \ 13 | strtok.c \ 14 | strtoul.c 15 | 16 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 17 | -------------------------------------------------------------------------------- /lib/crt/string/strchr.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | char *strchr(const char *p, int ch) 34 | { 35 | union { 36 | const char *cp; 37 | char *p; 38 | } u; 39 | 40 | u.cp = p; 41 | for (;; ++u.p) { 42 | if (*u.p == ch) 43 | return u.p; 44 | if (*u.p == '\0') 45 | return NULL; 46 | } 47 | /* NOTREACHED */ 48 | } 49 | -------------------------------------------------------------------------------- /lib/crt/string/strcmp.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from software contributed to Berkeley by 6 | * Chris Torek. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | 35 | /* 36 | * Compare strings. 37 | */ 38 | int strcmp(const char *s1, const char *s2) 39 | { 40 | while (*s1 == *s2++) { 41 | if (*s1++ == 0) 42 | return 0; 43 | } 44 | 45 | return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); 46 | } 47 | -------------------------------------------------------------------------------- /lib/crt/string/strcpy.c: -------------------------------------------------------------------------------- 1 | /* C Runtime Library 2 | * 3 | * Copyright (c) 1988 Regents of the University of California. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | char *strcpy(char *dst, const char *src) 34 | { 35 | char *save = dst; 36 | 37 | for (; (*dst = *src) != '\0'; ++dst, ++src); 38 | 39 | return save; 40 | } 41 | -------------------------------------------------------------------------------- /lib/crt/string/strdup.c: -------------------------------------------------------------------------------- 1 | /* C Runtime Library 2 | * 3 | * Copyright 2015, Brian McKenzie. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * 16 | * If you are going to use this software in any form that does not involve 17 | * releasing the source to this project or improving it, let me know beforehand. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | char *strdup(char *str) 36 | { 37 | int len; 38 | char *dup; 39 | 40 | len = strlen(str); 41 | dup = (char *)malloc(len + 1); 42 | 43 | if ((len == 0) || (dup == NULL)) 44 | return NULL; 45 | 46 | bcopy(str, dup, len); 47 | 48 | dup[len + 1] = '\0'; 49 | 50 | return dup; 51 | } 52 | -------------------------------------------------------------------------------- /lib/crt/string/strncmp.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1989, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | 32 | int strncmp(const char *s1, const char *s2, size_t n) 33 | { 34 | 35 | if (n == 0) 36 | return 0; 37 | do { 38 | if (*s1 != *s2++) 39 | return (*(const unsigned char *)s1 - 40 | *(const unsigned char *)(s2 - 1)); 41 | if (*s1++ == '\0') 42 | break; 43 | } while (--n != 0); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /lib/crt/string/strncpy.c: -------------------------------------------------------------------------------- 1 | /* C Runtime Library 2 | * 3 | * Copyright (c) 1990 The Regents of the University of California. 4 | * All rights reserved. 5 | * 6 | * This code is derived from software contributed to Berkeley by 7 | * Chris Torek. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include 36 | 37 | char *strncpy(char *dst, const char *src, size_t n) 38 | { 39 | if (n != 0) { 40 | char *d = dst; 41 | const char *s = src; 42 | 43 | do { 44 | if ((*d++ = *s++) == 0) { 45 | /* NUL pad the remaining n-1 bytes */ 46 | while (--n) { 47 | *d++ = 0; 48 | } 49 | break; 50 | } 51 | } while (--n); 52 | } 53 | 54 | return dst; 55 | } 56 | -------------------------------------------------------------------------------- /lib/crt/string/strtok.c: -------------------------------------------------------------------------------- 1 | /* C Runtime Library 2 | * 3 | * Copyright (c) 1998 Softweyr LLC. All rights reserved. 4 | * 5 | * strtok_r, from Berkeley strtok 6 | * Oct 13, 1998 by Wes Peters 7 | * 8 | * Copyright (c) 1988, 1993 9 | * The Regents of the University of California. All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notices, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notices, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. All advertising materials mentioning features or use of this software 20 | * must display the following acknowledgement: 21 | * This product includes software developed by Softweyr LLC, the 22 | * University of California, Berkeley, and its contributors. 23 | * 4. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS 28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 30 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE 31 | * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 33 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | #include 41 | #include 42 | 43 | char *strtok_r(char *s, const char *delim, char **last) 44 | { 45 | int c, sc; 46 | char *spanp, *tok; 47 | 48 | if (s == NULL && (s = *last) == NULL) 49 | return NULL; 50 | 51 | /* 52 | * Skip (span) leading delimiters (s += strspn(s, delim), sort of). 53 | */ 54 | cont: 55 | c = *s++; 56 | for (spanp = (char *)delim; (sc = *spanp++) != 0;) { 57 | if (c == sc) 58 | goto cont; 59 | } 60 | 61 | if (c == 0) { /* no non-delimiter characters */ 62 | *last = NULL; 63 | return NULL; 64 | } 65 | tok = s - 1; 66 | 67 | /* 68 | * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). 69 | * Note that delim must have one NUL; we stop if we see that, too. 70 | */ 71 | for (;;) { 72 | c = *s++; 73 | spanp = (char *)delim; 74 | do { 75 | if ((sc = *spanp++) == c) { 76 | if (c == 0) 77 | s = NULL; 78 | else 79 | s[-1] = '\0'; 80 | *last = s; 81 | return tok; 82 | } 83 | } while (sc != 0); 84 | } 85 | /* NOTREACHED */ 86 | } 87 | 88 | char *strtok(char *s, const char *delim) 89 | { 90 | static char *last; 91 | 92 | return strtok_r(s, delim, &last); 93 | } 94 | -------------------------------------------------------------------------------- /lib/crypto/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/crypto 2 | 3 | C_SRC_FILES := \ 4 | sha1.c 5 | 6 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 7 | -------------------------------------------------------------------------------- /lib/debug/assert.c: -------------------------------------------------------------------------------- 1 | /* Assertion handling for xBoot 2 | * 3 | * Copyright 2013, winocm. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * 16 | * If you are going to use this software in any form that does not involve 17 | * releasing the source to this project or improving it, let me know beforehand. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | /** 35 | * __assert_func 36 | * 37 | * Handler for assert() macro 38 | */ 39 | void __assert_func(const char *file, int line, const char *method, const char *expression) 40 | { 41 | panic("Assertion failed in file %s, line %d. (%s)\n", file, line, expression); 42 | while (1) ; 43 | } 44 | -------------------------------------------------------------------------------- /lib/debug/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/debug 2 | 3 | C_SRC_FILES := \ 4 | panic.c \ 5 | assert.c 6 | 7 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) -------------------------------------------------------------------------------- /lib/debug/panic.c: -------------------------------------------------------------------------------- 1 | /* Panic handling for xBoot 2 | * 3 | * Copyright 2013, winocm. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | * list of conditions and the following disclaimer in the documentation and/or 14 | * other materials provided with the distribution. 15 | * 16 | * If you are going to use this software in any form that does not involve 17 | * releasing the source to this project or improving it, let me know beforehand. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | extern void _locore_halt_system(void); 36 | 37 | /** 38 | * panic 39 | * 40 | * Halt the system and explain why. 41 | */ 42 | void panic(const char *panicStr, ...) 43 | { 44 | void *caller = __builtin_return_address(0); 45 | 46 | /* Prologue */ 47 | printf("panic(caller 0x%08x): ", caller); 48 | 49 | /* Epilogue */ 50 | va_list valist; 51 | va_start(valist, panicStr); 52 | vprintf((char *)panicStr, valist); 53 | va_end(valist); 54 | 55 | /* We are hanging here. */ 56 | printf("\npanic: we are hanging here...\n"); 57 | 58 | /* Halt */ 59 | _locore_halt_system(); 60 | } 61 | -------------------------------------------------------------------------------- /lib/device/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/device 2 | 3 | C_SRC_FILES := \ 4 | uart.c \ 5 | sysctl.c \ 6 | timer.c \ 7 | nvram.c 8 | 9 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 10 | -------------------------------------------------------------------------------- /lib/device/sysctl.c: -------------------------------------------------------------------------------- 1 | /* Generic system control interface 2 | * 3 | * Copyright (c) 2013, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | 35 | extern sysctl_driver sysctl_drv; 36 | static sysctl_driver *sysctl = &sysctl_drv; 37 | 38 | void sysctl_reset(void) 39 | { 40 | sysctl->reset(); 41 | 42 | return; 43 | } 44 | 45 | void sysctl_poweroff(void) 46 | { 47 | sysctl->poweroff(); 48 | 49 | return; 50 | } 51 | -------------------------------------------------------------------------------- /lib/device/timer.c: -------------------------------------------------------------------------------- 1 | /* Generic timer driver interface 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | extern timer_driver timer_drv; 37 | static timer_driver *timer = &timer_drv; 38 | 39 | void timer_init(void) 40 | { 41 | timer->init(); 42 | 43 | return; 44 | } 45 | 46 | void timer_reset(void) 47 | { 48 | timer->reset(); 49 | 50 | return; 51 | } 52 | 53 | uint32_t timer_read(void) 54 | { 55 | return timer->count_usec(); 56 | } 57 | 58 | void usleep(uint32_t us) 59 | { 60 | uint32_t ini, end; 61 | ini = end = 0; 62 | 63 | ini = timer->count_usec(); 64 | end = (ini + us); 65 | 66 | while ((int32_t)(end - timer->count_usec()) > 0) 67 | ; 68 | 69 | return; 70 | } 71 | -------------------------------------------------------------------------------- /lib/device/uart.c: -------------------------------------------------------------------------------- 1 | /* Generic UART driver interface 2 | * 3 | * Copyright (c) 2017, Brian McKenzie 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the organization nor the names of its contributors may 17 | * be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | #include 35 | 36 | extern uart_driver uart_drv; 37 | static uart_driver *uart = &uart_drv; 38 | 39 | void uart_init(void) 40 | { 41 | uart->init(); 42 | 43 | return; 44 | } 45 | 46 | int uart_poll(void) 47 | { 48 | int state; 49 | 50 | state = uart->poll(); 51 | 52 | return state; 53 | } 54 | 55 | uint32_t uart_getc(void) 56 | { 57 | uint32_t val = '\0'; 58 | 59 | val = uart->getc(); 60 | 61 | return val; 62 | } 63 | 64 | void uart_putc(int c) 65 | { 66 | if (c == '\n') 67 | uart->putc('\r'); 68 | 69 | uart->putc(c); 70 | 71 | return; 72 | } 73 | 74 | void uart_puts(const char *str) 75 | { 76 | uart->puts(str); 77 | 78 | return; 79 | } 80 | -------------------------------------------------------------------------------- /lib/prng/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/prng 2 | 3 | C_SRC_FILES := \ 4 | prng.c 5 | 6 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 7 | -------------------------------------------------------------------------------- /lib/prng/prng.c: -------------------------------------------------------------------------------- 1 | /* Simple PRNG using SHA1 on a clock source. 2 | * 3 | * This implementation was lifted from: 4 | * 5 | * http://mista.nu/research/early_random-paper.pdf 6 | * http://mista.nu/research/early_random-slides.pdf 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | /* TODO: put this in sys/param.h */ 19 | #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 20 | 21 | uint32_t prng_get_random_uint32(void) 22 | { 23 | int i, j; 24 | uint32_t result = 0; 25 | 26 | for (i = 0; i < 32; i++) { 27 | j = i + 1; 28 | 29 | do { 30 | j--; 31 | } while (j); 32 | 33 | result = ((timer_read() & 1) | (result << 1)); 34 | } 35 | 36 | return result; 37 | } 38 | 39 | void prng_get_random_bytes(char *buf, uint32_t len) 40 | { 41 | char hash_bytes[SHA_DIGEST_LENGTH]; 42 | uint32_t entropy_data[ENTROPY_SIZE]; 43 | uint32_t copylen, copylen_remaining, hash_bytes_remaining; 44 | 45 | copylen_remaining = len; 46 | hash_bytes_remaining = 0; 47 | 48 | if (len) { 49 | do { 50 | if(!hash_bytes_remaining) { 51 | for (uint32_t i = 0; i < (ENTROPY_SIZE / sizeof(uint32_t)); i++) { 52 | *(entropy_data + i) = prng_get_random_uint32(); 53 | } 54 | 55 | SHA1(hash_bytes, (char *)entropy_data, ENTROPY_SIZE); 56 | hash_bytes_remaining = SHA_DIGEST_LENGTH; 57 | } 58 | copylen = MIN(hash_bytes_remaining, copylen_remaining); 59 | memcpy(buf, hash_bytes + SHA_DIGEST_LENGTH - hash_bytes_remaining, copylen); 60 | 61 | buf += copylen; 62 | copylen_remaining -= copylen; 63 | hash_bytes_remaining -= copylen; 64 | } while (copylen_remaining); 65 | 66 | bzero(entropy_data, ENTROPY_SIZE); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lib/shell/cmds.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include "cmds.h" 36 | 37 | /** 38 | * query_command 39 | * 40 | * query a command and return its associated handle. 41 | */ 42 | cmd_handle_t query_command(const char *name) 43 | { 44 | int i = 0; 45 | cmd_handle_t cmd = { NULL, NULL, NULL }; 46 | 47 | cmd = commands[i]; 48 | while (cmd.name != NULL) { 49 | if (strcmp(cmd.name, name) == 0) 50 | return cmd; 51 | cmd = commands[++i]; 52 | } 53 | 54 | return cmd; 55 | } 56 | -------------------------------------------------------------------------------- /lib/shell/cmds.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef CMDS_H 31 | #define CMDS_H 32 | 33 | #include 34 | 35 | #include 36 | 37 | /* Command prototypes */ 38 | extern int help_main(int argc, char *argv[]); 39 | extern int reset_main(int argc, char *argv[]); 40 | extern int halt_main(int argc, char *argv[]); 41 | extern int boot_main(int argc, char *argv[]); 42 | 43 | extern void getenv_help(void); 44 | extern int getenv_main(int argc, char *argv[]); 45 | 46 | extern void setenv_help(void); 47 | extern int setenv_main(int argc, char *argv[]); 48 | 49 | extern void printenv_help(void); 50 | extern int printenv_main(int argc, char *argv[]); 51 | 52 | extern int history_main(int argc, char *argv[]); 53 | 54 | /* Command list */ 55 | cmd_handle_t commands[] = { 56 | { "help", "Display command help.", NULL, help_main }, 57 | { "boot", "Boot into Darwin.", NULL, boot_main }, 58 | { "halt", "Halt the system.", NULL, halt_main }, 59 | { "reset", "Reset the system.", NULL, reset_main }, 60 | { "getenv", "Read environment variable.", getenv_help, getenv_main }, 61 | { "setenv", "Set an environment variable.", setenv_help, setenv_main }, 62 | { "printenv", "Print one or all environment variables.", printenv_help, printenv_main }, 63 | { "history", "Print the command history.", NULL, history_main }, 64 | { NULL, NULL, NULL }, 65 | }; 66 | 67 | #endif /* !CMDS_H */ 68 | -------------------------------------------------------------------------------- /lib/shell/cmds/boot.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | int boot_main(int argc, char *argv[]) 34 | { 35 | printf("Booting darwin.\n"); 36 | start_darwin(); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /lib/shell/cmds/getenv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the organization nor the names of its contributors may 16 | * be used to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 25 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | void getenv_help(void) 35 | { 36 | printf("Usage:\n\tgetenv \n"); 37 | 38 | return; 39 | } 40 | 41 | int getenv_main(int argc, char *argv[]) 42 | { 43 | char *val; 44 | 45 | if (argc != 2) { 46 | getenv_help(); 47 | return -1; 48 | } 49 | 50 | if ((val = getenv(argv[1])) == NULL) { 51 | printf("no such variable: %s\n", argv[1]); 52 | return -1; 53 | } else 54 | printf("%s\n", val); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /lib/shell/cmds/halt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | int halt_main(int argc, char *argv[]) 34 | { 35 | printf("Halting system...\n"); 36 | sysctl_poweroff(); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /lib/shell/cmds/help.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | extern cmd_handle_t commands[]; 36 | 37 | int help_main(int argc, char *argv[]) 38 | { 39 | int i = 0; 40 | cmd_handle_t cmd; 41 | 42 | if (argc > 1) { 43 | cmd = query_command(argv[1]); 44 | if (cmd.help != NULL) 45 | cmd.help(); 46 | else 47 | printf("Detailed help for command \'%s\' does not exist.\n", argv[1]); 48 | } else { 49 | printf("Supported commands:\n\n"); 50 | while (commands[i].name != NULL) { 51 | printf(" %-8s\t - %s\n", commands[i].name, commands[i].desc); 52 | ++i; 53 | } 54 | 55 | printf("\nType \'help \' for detailed command help.\n\n"); 56 | } 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /lib/shell/cmds/history.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | int history_main(int argc, char *argv[]) 35 | { 36 | return shell_history_print(); 37 | } 38 | -------------------------------------------------------------------------------- /lib/shell/cmds/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/shell/cmds 2 | 3 | C_SRC_FILES := \ 4 | help.c \ 5 | halt.c \ 6 | boot.c \ 7 | reset.c \ 8 | getenv.c \ 9 | setenv.c \ 10 | printenv.c \ 11 | history.c 12 | 13 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 14 | -------------------------------------------------------------------------------- /lib/shell/cmds/printenv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Brian McKenzie 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the organization nor the names of its contributors may 16 | * be used to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 25 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | void printenv_help(void) 37 | { 38 | printf("Usage:\n\tprintenv\nOR\tprintenv \n"); 39 | 40 | return; 41 | } 42 | 43 | int printenv_main(int argc, char *argv[]) 44 | { 45 | char *value; 46 | 47 | value = argv[1]; 48 | 49 | printf("\n"); 50 | printenv(value); 51 | printf("\n"); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /lib/shell/cmds/reset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | int reset_main(int argc, char *argv[]) 34 | { 35 | printf("Resetting system...\n"); 36 | sysctl_reset(); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /lib/shell/cmds/setenv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Brian McKenzie. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * If you are going to use this software in any form that does not involve 16 | * releasing the source to this project or improving it, let me know beforehand. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | 34 | void setenv_help(void) 35 | { 36 | printf("Usage:\n\tsetenv \nOR\tsetenv to delete \n"); 37 | 38 | return; 39 | } 40 | 41 | int setenv_main(int argc, char *argv[]) 42 | { 43 | char *key, *value; 44 | 45 | if (argc < 2) { 46 | setenv_help(); 47 | return -1; 48 | } 49 | 50 | key = argv[1]; 51 | value = argv[2]; 52 | 53 | return setenv(key, value, 1); 54 | } 55 | -------------------------------------------------------------------------------- /lib/shell/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/shell 2 | 3 | C_SRC_FILES := \ 4 | cmds.c \ 5 | shell.c \ 6 | history.c 7 | 8 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 9 | 10 | include $(SRCROOT)/lib/shell/cmds/module.mk 11 | -------------------------------------------------------------------------------- /lib/tlsf/module.mk: -------------------------------------------------------------------------------- 1 | SRC_DIR := $(SRCROOT)/lib/tlsf 2 | 3 | C_SRC_FILES := \ 4 | tlsf.c 5 | 6 | C_SRCS += $(addprefix $(SRC_DIR)/, $(C_SRC_FILES)) 7 | -------------------------------------------------------------------------------- /make/build.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # Common build settings for xBoot build 3 | ## 4 | 5 | ## 6 | # Set build directory 7 | # 8 | 9 | BUILD_DIR += $(SRCROOT)/Build 10 | BUILD_ROOT += $(BUILD_DIR)/$(PLATFORM)/$(BUILD) 11 | BUILD_OBJS += $(BUILD_ROOT)/Objects 12 | BUILD_GEN += $(BUILD_ROOT)/GeneratedSources 13 | 14 | ## 15 | # Import all subdirectory source trees 16 | # 17 | 18 | ifdef PLATFORM 19 | include $(patsubst %,%/module.mk,$(DIRS)) 20 | endif 21 | 22 | ## 23 | # Create a list of objects to compile 24 | # 25 | 26 | OBJS += \ 27 | $(patsubst %.S,%.o, $(filter %.S,$(S_SRCS))) \ 28 | $(patsubst %.c,%.o, $(filter %.c,$(C_SRCS))) 29 | -------------------------------------------------------------------------------- /make/dirs.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # Source tree setup for xBoot build 3 | ## 4 | 5 | ## 6 | # Define basic source tree that makes up xBoot 7 | # 8 | 9 | DIRS += \ 10 | core \ 11 | lib/crt \ 12 | lib/prng \ 13 | lib/crypto \ 14 | lib/boot \ 15 | lib/shell \ 16 | lib/device \ 17 | lib/debug \ 18 | lib/tlsf \ 19 | arch/$(ARCH) 20 | -------------------------------------------------------------------------------- /make/flags.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # Common toolchain flags used for building xBoot 3 | ## 4 | 5 | ## 6 | # Common C compiler flags 7 | # 8 | 9 | CFLAGS_ARGS += \ 10 | -mcpu=$(SUBARCH) \ 11 | -fno-builtin \ 12 | -fPIC \ 13 | -nostdlib \ 14 | -nostartfiles \ 15 | -ffreestanding \ 16 | -std=c11 \ 17 | 18 | ifeq ($(BUILD),DEBUG) 19 | CFLAGS_ARGS += \ 20 | -g \ 21 | -O0 22 | else 23 | CFLAG_ARGS += \ 24 | -Os 25 | endif 26 | 27 | CFLAGS_DEFS += \ 28 | -D__LITTLE_ENDIAN__=1 \ 29 | -DDRAM_BASE=$(DRAM_BASE) \ 30 | -DDRAM_SIZE=$(DRAM_SIZE) \ 31 | -DBUILD_STYLE=\"$(BUILD)\" 32 | 33 | ifeq ($(SUBARCH),cortex-a9) 34 | CFLAGS_DEFS += \ 35 | -DCORTEX_A9 \ 36 | -DUSE_4K_PAGES 37 | endif 38 | 39 | ifeq ($(SUBARCH),cortex-a8) 40 | CFLAGS_DEFS += \ 41 | -DCORTEX_A8 \ 42 | -DUSE_4K_PAGES 43 | endif 44 | 45 | ifeq ($(SUBARCH),cortex-a7) 46 | CFLAGS_DEFS += \ 47 | -DCORTEX_A8 \ 48 | -DUSE_4K_PAGES 49 | endif 50 | 51 | CFLAGS_WARNS += \ 52 | -Wall \ 53 | -Werror \ 54 | -Wno-error=multichar \ 55 | -Wno-unused-value 56 | 57 | CFLAGS_INCS += \ 58 | -I$(SRCROOT) \ 59 | -I$(SRCROOT)/include \ 60 | -I$(SRCROOT)/arch/$(ARCH)/include 61 | 62 | # Set everything up 63 | CFLAGS += $(CFLAGS_ARGS) 64 | CFLAGS += $(CFLAGS_DEFS) 65 | CFLAGS += $(CFLAGS_WARNS) 66 | CFLAGS += $(CFLAGS_INCS) 67 | 68 | ## 69 | # Common assembler flags 70 | # 71 | 72 | SFLAGS_ARGS += \ 73 | $(CFLAGS_ARGS) 74 | 75 | SFLAGS_DEFS += \ 76 | $(CFLAGS_DEFS) \ 77 | -D__ASSEMBLY__=1 78 | 79 | SFLAGS_WARNS += \ 80 | $(CFLAGS_WARNS) 81 | 82 | SFLAGS_INCS += \ 83 | $(CFLAGS_INCS) 84 | 85 | # Set everything up 86 | SFLAGS += $(SFLAGS_ARGS) 87 | SFLAGS += $(SFLAGS_DEFS) 88 | SFLAGS += $(SFLAGS_WARNS) 89 | SFLAGS += $(SFLAGS_INCS) 90 | 91 | ## 92 | # Common linker flags 93 | # 94 | 95 | LDFLAGS += \ 96 | -static \ 97 | -nostdlib \ 98 | --gc-sections \ 99 | --defsym DRAM_SIZE=$(DRAM_SIZE) \ 100 | --defsym BOOT_TEXT_BASE=$(BOOT_TEXT_BASE) \ 101 | -L$(BUILD_ROOT) 102 | -------------------------------------------------------------------------------- /make/rules.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # Common make rules for building xBoot 3 | ## 4 | 5 | ## 6 | # C source code rules 7 | # 8 | 9 | %.o: %.c 10 | $(eval obj_uuid := $(shell uuidgen -r | cut -d'-' -f1)) 11 | $(_CC) $(CFLAGS) -c $< -o $(BUILD_OBJS)/$(notdir $*.$(obj_uuid).o) 12 | @echo "$(BUILD_OBJS)/$(notdir $*.$(obj_uuid).o)" >> $(BUILD_OBJS)/Objects.list 13 | 14 | ## 15 | # ASM source code rules 16 | # 17 | 18 | %.o: %.S 19 | $(eval obj_uuid := $(shell uuidgen -r | cut -d'-' -f1)) 20 | $(_CC) -x assembler-with-cpp $(SFLAGS) -c $< -o $(BUILD_OBJS)/$(notdir $*.$(obj_uuid).o) 21 | @echo "$(BUILD_OBJS)/$(notdir $*.$(obj_uuid).o)" >> $(BUILD_OBJS)/Objects.list 22 | 23 | ## 24 | # Main rules 25 | # 26 | 27 | .PHONY: all install clean help 28 | .SECONDARY: $(TARGET) 29 | 30 | all: setup $(TARGET) 31 | 32 | setup: 33 | @if [ -z $(PLATFORM) ]; then \ 34 | echo "Error: no platform specified.\n"; \ 35 | echo "Use PLATFORM= to specify a platform or run \"make help\" to get a list of supported platforms.\n"; \ 36 | exit 1; \ 37 | fi; 38 | @rm -rf $(BUILD_DIR) 39 | @mkdir -p $(BUILD_GEN) 40 | @mkdir -p $(BUILD_OBJS) 41 | @$(MAKE) -C $(TOOLDIR) HOST_CC=$(HOST_CC) 42 | @$(VERSION) $(RC_ProjectName) > $(BUILD_GEN)/$(RC_ProjectName)_version.c 43 | $(_CC) $(CFLAGS) -c $(BUILD_GEN)/$(RC_ProjectName)_version.c -o $(BUILD_ROOT)/$(RC_ProjectName)_version.o 44 | @$(IMAGE3MAKER) -t jsdt -f $(BSP_DIR)/$(PLAT_DT_FILE) -o $(BUILD_ROOT)/dtre.img3 45 | @cd $(BUILD_ROOT) && $(LD) -r -b binary -o dtre.o dtre.img3 46 | 47 | $(TARGET): $(OBJS) 48 | @bash -e $(ARCHIVE) $(AR) $(BUILD_OBJS)/Objects.list $(BUILD_ROOT)/$(TARGET).a 49 | $(_LD) -T $(SRCROOT)/arch/arm/init/xboot.ld $(BUILD_ROOT)/$(TARGET).a \ 50 | $(BUILD_ROOT)/dtre.o $(BUILD_ROOT)/$(RC_ProjectName)_version.o -o $(BUILD_ROOT)/$(TARGET).elf $(LDFLAGS) 51 | $(_OBJDMP) -D $(BUILD_ROOT)/$(TARGET).elf > $(BUILD_ROOT)/$(TARGET).list 52 | $(_OBJCPY) $(BUILD_ROOT)/$(TARGET).elf -g -S -O binary $(SRCROOT)/$(TARGET).bin 53 | @echo "$(TARGET).bin is ready." 54 | 55 | install: all 56 | 57 | clean: 58 | @rm -rf $(BUILD_DIR) $(SRCROOT)/$(TARGET).* $(SRCROOT)/xboot.*.bin 59 | @$(MAKE) -C $(TOOLDIR) clean 60 | @echo "Source tree is now clean." 61 | 62 | 63 | help: 64 | @echo "When building xBoot, you must set PLATFORM to to a desired platform target.\n" 65 | @echo -n "Platforms supported by xBoot: " 66 | @for i in `ls $(SRCROOT)/bsp`; do \ 67 | echo -n "$$i "; \ 68 | done; 69 | @echo "\n\nIf you wish to see commands being called while building, you can also set VERBOSE_BUILD to 1\n" 70 | -------------------------------------------------------------------------------- /make/tools.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # Tools used for building xBoot 3 | ## 4 | 5 | CROSS ?= arm-none-eabi- 6 | CC := $(CROSS)gcc 7 | LD := $(CROSS)ld 8 | AS := $(CROSS)as 9 | AR := $(CROSS)ar 10 | OBJDMP := $(CROSS)objdump 11 | OBJCPY := $(CROSS)objcopy 12 | HOST_CC := gcc 13 | 14 | CCDV := $(TOOLDIR)/ccdv/ccdv 15 | VERSION := $(TOOLDIR)/scripts/version.pl 16 | ARCHIVE := $(TOOLDIR)/scripts/archive.sh 17 | IMAGE3MAKER := $(TOOLDIR)/image3maker/image3maker 18 | 19 | ## 20 | # Used for quiet vs verbose building - do not touch! 21 | # 22 | 23 | ifneq ($(VERBOSE_BUILD),1) 24 | _CC := @$(CCDV) $(CC) 25 | _AS := @$(CCDV) $(AS) 26 | _AR := @$(CCDV) $(AR) 27 | _LD := @$(CCDV) $(LD) 28 | _OBJCPY := @$(CCDV) $(OBJCPY) 29 | _OBJDMP := @$(CCDV) $(OBJDMP) 30 | else 31 | _CC := $(CC) 32 | _AS := $(AS) 33 | _AR := $(AR) 34 | _LD := $(LD) 35 | _OBJCPY := $(OBJCPY) 36 | _OBJDMP := $(OBJDMP) 37 | endif 38 | -------------------------------------------------------------------------------- /tools/Makefile: -------------------------------------------------------------------------------- 1 | HOST_CC ?= gcc 2 | 3 | TOOLS := \ 4 | ccdv \ 5 | image3maker 6 | 7 | define do_make 8 | @for dir in $1; do \ 9 | $(MAKE) -C $$dir HOST_CC=$(HOST_CC) $2; \ 10 | done 11 | endef 12 | 13 | all: 14 | $(call do_make, $(TOOLS), all) 15 | 16 | .PHONY: clean 17 | clean: 18 | $(call do_make, $(TOOLS), clean) 19 | -------------------------------------------------------------------------------- /tools/ccdv/Makefile: -------------------------------------------------------------------------------- 1 | HOST_CC ?= gcc 2 | CFLAGS := 3 | 4 | TOOL := ccdv 5 | OBJS := ccdv.o 6 | 7 | %.o: %.c 8 | $(HOST_CC) -c $< $(CFLAGS) -o $@ 9 | 10 | $(TOOL): $(OBJS) 11 | $(HOST_CC) $(OBJS) -o $@ 12 | 13 | all: $(TOOL) 14 | 15 | .PHONY: clean 16 | clean: 17 | rm -f $(OBJS) $(TOOL) 18 | -------------------------------------------------------------------------------- /tools/image3maker/Makefile: -------------------------------------------------------------------------------- 1 | HOST_CC ?= gcc 2 | CFLAGS := -Wno-multichar 3 | 4 | TOOL := image3maker 5 | OBJS := image3maker.o 6 | 7 | %.o: %.c 8 | $(HOST_CC) -c $< $(CFLAGS) -o $@ 9 | 10 | $(TOOL): $(OBJS) 11 | $(HOST_CC) $(OBJS) -o $@ 12 | 13 | all: $(TOOL) 14 | 15 | .PHONY: clean 16 | clean: 17 | rm -f $(OBJS) $(TOOL) 18 | -------------------------------------------------------------------------------- /tools/scripts/archive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Generate an archive from a list of objects 4 | # 5 | # Copyright (c) 2014, Brian McKenzie 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without modification, 9 | # are permitted provided that the following conditions are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 14 | # 2. Redistributions in binary form must reproduce the above copyright notice, 15 | # this list of conditions and the following disclaimer in the documentation 16 | # and/or other materials provided with the distribution. 17 | # 18 | # 3. Neither the name of the organization nor the names of its contributors may 19 | # be used to endorse or promote products derived from this software without 20 | # specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 23 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 | # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 26 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 28 | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | 33 | create() { 34 | local arprog=${1} 35 | local objlist=${2} 36 | local outlib=${3} 37 | local first=1 38 | 39 | if [ -z ${1} ]; then 40 | echo -e "Usage:\n\t${0} [ar program] [/path/to/objlist].list [outputfile].a" 41 | return 1 42 | fi 43 | 44 | echo -n "Generating `basename ${outlib}`... " 45 | 46 | if [ -f ${outlib} ]; then 47 | rm -f ${outlib} 48 | fi 49 | 50 | for obj in `cat ${objlist}`; do 51 | if [ ${first} -ne 0 ]; then 52 | ${arprog} cr ${outlib} ${obj} 53 | first=0 54 | continue 55 | fi 56 | 57 | ${arprog} r ${outlib} ${obj} 58 | done 59 | 60 | echo "Done." 61 | 62 | return 0 63 | } 64 | 65 | create ${@} 66 | 67 | exit ${?} 68 | 69 | -------------------------------------------------------------------------------- /tools/scripts/version.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 4 | # 5 | # @APPLE_LICENSE_HEADER_START@ 6 | # 7 | # This file contains Original Code and/or Modifications of Original Code 8 | # as defined in and that are subject to the Apple Public Source License 9 | # Version 2.0 (the 'License'). You may not use this file except in 10 | # compliance with the License. Please obtain a copy of the License at 11 | # http://www.opensource.apple.com/apsl/ and read it before using this 12 | # file. 13 | # 14 | # The Original Code and all software distributed under the License are 15 | # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 | # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 | # Please see the License for the specific language governing rights and 20 | # limitations under the License. 21 | # 22 | # @APPLE_LICENSE_HEADER_END@ 23 | 24 | use strict; 25 | use POSIX (); 26 | 27 | # Create a version string from various environment variables, from the 28 | # argument list, or the current directory 29 | 30 | my $name = $ARGV[0]; 31 | $name = $ENV{RC_ProjectName} unless defined($name) && $name ne ''; 32 | $name = $ENV{PROJECT_NAME} unless defined($name) && $name ne ''; 33 | my $vers = $ENV{RC_ProjectNameAndSourceVersion}; 34 | $vers = "$name-$ENV{RC_ProjectSourceVersion}" unless defined($vers) && $vers ne '' && defined($ENV{RC_ProjectSourceVersion}) && $ENV{RC_ProjectSourceVersion} ne ''; 35 | if(defined($vers) && $vers ne '') { 36 | if(defined($name) && $name ne '') { 37 | $vers =~ s/^[^-]*-/$name-/; 38 | } else { 39 | ($name = $vers) =~ s/-.*//; 40 | } 41 | my $build = $ENV{RC_ProjectBuildVersion}; 42 | $vers .= "~$build" if defined($build) && $build ne ''; 43 | } else { 44 | if(defined($name) && $name ne '') { 45 | $vers = $name; 46 | } else { 47 | require Cwd; 48 | $vers = Cwd::cwd(); 49 | $name = time(); 50 | } 51 | } 52 | printf "const char __%s_version[] = \"%s\";\n", $name, $vers; 53 | --------------------------------------------------------------------------------