diff --git a/.gitignore b/.gitignore index 931d6bf..39e0583 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ uniLoader *.o main/*.o -arch/aarch64/linker.lds +arch/*/linker.lds board/*/*.o* board/*.a* soc/*/*.o* diff --git a/Makefile b/Makefile index 1a3b6a1..6606969 100644 --- a/Makefile +++ b/Makefile @@ -206,6 +206,11 @@ KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := KBUILD_AFLAGS := -D__ASSEMBLY__ +ifeq ($(ARCH), arm) +KBUILD_CFLAGS += -march=armv7-a -mfloat-abi=soft -mtune=cortex-a9 +KBUILD_AFLAGS += -march=armv7-a -mfloat-abi=soft -mtune=cortex-a9 +endif + # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) @@ -345,9 +350,7 @@ all: arch/$(ARCH)/linker.lds uniLoader main-y := arch/$(ARCH)/start.o \ main/main.o -ifeq ($(ARCH), aarch64) arch-libs-y := arch/$(ARCH)/memcpy.o -endif # Object directories objs-y := main diff --git a/arch/Makefile b/arch/Makefile index d7b8634..699fca0 100644 --- a/arch/Makefile +++ b/arch/Makefile @@ -1,4 +1,2 @@ obj-y += $(ARCH)/start.o - -# libs obj-y += $(ARCH)/memcpy.o diff --git a/arch/aarch64/asmdefs.h b/arch/aarch64/asmdefs.h index 131b95e..2379348 100644 --- a/arch/aarch64/asmdefs.h +++ b/arch/aarch64/asmdefs.h @@ -1,4 +1,6 @@ /* + * https://github.com/ARM-software/optimized-routines/blob/master/string/aarch64/asmdefs.h + * * Macros for asm code. AArch64 version. * * Copyright (c) 2019-2023, Arm Limited. diff --git a/arch/aarch64/memcpy.S b/arch/aarch64/memcpy.S index 3c98c93..e3de08f 100644 --- a/arch/aarch64/memcpy.S +++ b/arch/aarch64/memcpy.S @@ -1,4 +1,6 @@ /* + * https://github.com/ARM-software/optimized-routines/blob/master/string/aarch64/memcpy.S + * * memcpy - copy memory area * * Copyright (c) 2012-2022, Arm Limited. diff --git a/arch/aarch64/start.S b/arch/aarch64/start.S index 4abdae8..16df791 100644 --- a/arch/aarch64/start.S +++ b/arch/aarch64/start.S @@ -24,6 +24,6 @@ ENTRY(_start) bl main END(_start) -ENTRY(load_kernel) +ENTRY(load_kernel_and_jump) br x4 -END(load_kernel) +END(load_kernel_and_jump) diff --git a/arch/arm/asmdefs.h b/arch/arm/asmdefs.h new file mode 100644 index 0000000..afc8896 --- /dev/null +++ b/arch/arm/asmdefs.h @@ -0,0 +1,470 @@ +/* + * https://github.com/ARM-software/optimized-routines/blob/master/string/arm/asmdefs.h + * + * Macros for asm code. Arm version. + * + * Copyright (c) 2019-2022, Arm Limited. + * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception + */ + +#ifndef _ASMDEFS_H +#define _ASMDEFS_H + +/* Check whether leaf function PAC signing has been requested in the + -mbranch-protect compile-time option. */ +#define LEAF_PROTECT_BIT 2 + +#ifdef __ARM_FEATURE_PAC_DEFAULT +# define HAVE_PAC_LEAF \ + ((__ARM_FEATURE_PAC_DEFAULT & (1 << LEAF_PROTECT_BIT)) && 1) +#else +# define HAVE_PAC_LEAF 0 +#endif + +/* Provide default parameters for PAC-code handling in leaf-functions. */ +#if HAVE_PAC_LEAF +# ifndef PAC_LEAF_PUSH_IP +# define PAC_LEAF_PUSH_IP 1 +# endif +#else /* !HAVE_PAC_LEAF */ +# undef PAC_LEAF_PUSH_IP +# define PAC_LEAF_PUSH_IP 0 +#endif /* HAVE_PAC_LEAF */ + +#define STACK_ALIGN_ENFORCE 0 + +/****************************************************************************** +* Implementation of the prologue and epilogue assembler macros and their +* associated helper functions. +* +* These functions add support for the following: +* +* - M-profile branch target identification (BTI) landing-pads when compiled +* with `-mbranch-protection=bti'. +* - PAC-signing and verification instructions, depending on hardware support +* and whether the PAC-signing of leaf functions has been requested via the +* `-mbranch-protection=pac-ret+leaf' compiler argument. +* - 8-byte stack alignment preservation at function entry, defaulting to the +* value of STACK_ALIGN_ENFORCE. +* +* Notes: +* - Prologue stack alignment is implemented by detecting a push with an odd +* number of registers and prepending a dummy register to the list. +* - If alignment is attempted on a list containing r0, compilation will result +* in an error. +* - If alignment is attempted in a list containing r1, r0 will be prepended to +* the register list and r0 will be restored prior to function return. for +* functions with non-void return types, this will result in the corruption of +* the result register. +* - Stack alignment is enforced via the following helper macro call-chain: +* +* {prologue|epilogue} ->_align8 -> _preprocess_reglist -> +* _preprocess_reglist1 -> {_prologue|_epilogue} +* +* - Debug CFI directives are automatically added to prologues and epilogues, +* assisted by `cfisavelist' and `cfirestorelist', respectively. +* +* Arguments: +* prologue +* -------- +* - first - If `last' specified, this serves as start of general-purpose +* register (GPR) range to push onto stack, otherwise represents +* single GPR to push onto stack. If omitted, no GPRs pushed +* onto stack at prologue. +* - last - If given, specifies inclusive upper-bound of GPR range. +* - push_ip - Determines whether IP register is to be pushed to stack at +* prologue. When pac-signing is requested, this holds the +* the pac-key. Either 1 or 0 to push or not push, respectively. +* Default behavior: Set to value of PAC_LEAF_PUSH_IP macro. +* - push_lr - Determines whether to push lr to the stack on function entry. +* Either 1 or 0 to push or not push, respectively. +* - align8 - Whether to enforce alignment. Either 1 or 0, with 1 requesting +* alignment. +* +* epilogue +* -------- +* The epilogue should be called passing the same arguments as those passed to +* the prologue to ensure the stack is not corrupted on function return. +* +* Usage examples: +* +* prologue push_ip=1 -> push {ip} +* epilogue push_ip=1, align8=1 -> pop {r2, ip} +* prologue push_ip=1, push_lr=1 -> push {ip, lr} +* epilogue 1 -> pop {r1} +* prologue 1, align8=1 -> push {r0, r1} +* epilogue 1, push_ip=1 -> pop {r1, ip} +* prologue 1, 4 -> push {r1-r4} +* epilogue 1, 4 push_ip=1 -> pop {r1-r4, ip} +* +******************************************************************************/ + +/* Emit .cfi_restore directives for a consecutive sequence of registers. */ + .macro cfirestorelist first, last + .cfi_restore \last + .if \last-\first + cfirestorelist \first, \last-1 + .endif + .endm + +/* Emit .cfi_offset directives for a consecutive sequence of registers. */ + .macro cfisavelist first, last, index=1 + .cfi_offset \last, -4*(\index) + .if \last-\first + cfisavelist \first, \last-1, \index+1 + .endif + .endm + +.macro _prologue first=-1, last=-1, push_ip=PAC_LEAF_PUSH_IP, push_lr=0 + .if \push_ip & 1 != \push_ip + .error "push_ip may be either 0 or 1" + .endif + .if \push_lr & 1 != \push_lr + .error "push_lr may be either 0 or 1" + .endif + .if \first != -1 + .if \last == -1 + /* Upper-bound not provided: Set upper = lower. */ + _prologue \first, \first, \push_ip, \push_lr + .exitm + .endif + .endif +#if HAVE_PAC_LEAF +# if __ARM_FEATURE_BTI_DEFAULT + pacbti ip, lr, sp +# else + pac ip, lr, sp +# endif /* __ARM_FEATURE_BTI_DEFAULT */ + .cfi_register 143, 12 +#else +# if __ARM_FEATURE_BTI_DEFAULT + bti +# endif /* __ARM_FEATURE_BTI_DEFAULT */ +#endif /* HAVE_PAC_LEAF */ + .if \first != -1 + .if \last != \first + .if \last >= 13 + .error "SP cannot be in the save list" + .endif + .if \push_ip + .if \push_lr + /* Case 1: push register range, ip and lr registers. */ + push {r\first-r\last, ip, lr} + .cfi_adjust_cfa_offset ((\last-\first)+3)*4 + .cfi_offset 14, -4 + .cfi_offset 143, -8 + cfisavelist \first, \last, 3 + .else // !\push_lr + /* Case 2: push register range and ip register. */ + push {r\first-r\last, ip} + .cfi_adjust_cfa_offset ((\last-\first)+2)*4 + .cfi_offset 143, -4 + cfisavelist \first, \last, 2 + .endif + .else // !\push_ip + .if \push_lr + /* Case 3: push register range and lr register. */ + push {r\first-r\last, lr} + .cfi_adjust_cfa_offset ((\last-\first)+2)*4 + .cfi_offset 14, -4 + cfisavelist \first, \last, 2 + .else // !\push_lr + /* Case 4: push register range. */ + push {r\first-r\last} + .cfi_adjust_cfa_offset ((\last-\first)+1)*4 + cfisavelist \first, \last, 1 + .endif + .endif + .else // \last == \first + .if \push_ip + .if \push_lr + /* Case 5: push single GP register plus ip and lr registers. */ + push {r\first, ip, lr} + .cfi_adjust_cfa_offset 12 + .cfi_offset 14, -4 + .cfi_offset 143, -8 + cfisavelist \first, \first, 3 + .else // !\push_lr + /* Case 6: push single GP register plus ip register. */ + push {r\first, ip} + .cfi_adjust_cfa_offset 8 + .cfi_offset 143, -4 + cfisavelist \first, \first, 2 + .endif + .else // !\push_ip + .if \push_lr + /* Case 7: push single GP register plus lr register. */ + push {r\first, lr} + .cfi_adjust_cfa_offset 8 + .cfi_offset 14, -4 + cfisavelist \first, \first, 2 + .else // !\push_lr + /* Case 8: push single GP register. */ + push {r\first} + .cfi_adjust_cfa_offset 4 + cfisavelist \first, \first, 1 + .endif + .endif + .endif + .else // \first == -1 + .if \push_ip + .if \push_lr + /* Case 9: push ip and lr registers. */ + push {ip, lr} + .cfi_adjust_cfa_offset 8 + .cfi_offset 14, -4 + .cfi_offset 143, -8 + .else // !\push_lr + /* Case 10: push ip register. */ + push {ip} + .cfi_adjust_cfa_offset 4 + .cfi_offset 143, -4 + .endif + .else // !\push_ip + .if \push_lr + /* Case 11: push lr register. */ + push {lr} + .cfi_adjust_cfa_offset 4 + .cfi_offset 14, -4 + .endif + .endif + .endif +.endm + +.macro _epilogue first=-1, last=-1, push_ip=PAC_LEAF_PUSH_IP, push_lr=0 + .if \push_ip & 1 != \push_ip + .error "push_ip may be either 0 or 1" + .endif + .if \push_lr & 1 != \push_lr + .error "push_lr may be either 0 or 1" + .endif + .if \first != -1 + .if \last == -1 + /* Upper-bound not provided: Set upper = lower. */ + _epilogue \first, \first, \push_ip, \push_lr + .exitm + .endif + .if \last != \first + .if \last >= 13 + .error "SP cannot be in the save list" + .endif + .if \push_ip + .if \push_lr + /* Case 1: pop register range, ip and lr registers. */ + pop {r\first-r\last, ip, lr} + .cfi_restore 14 + .cfi_register 143, 12 + cfirestorelist \first, \last + .else // !\push_lr + /* Case 2: pop register range and ip register. */ + pop {r\first-r\last, ip} + .cfi_register 143, 12 + cfirestorelist \first, \last + .endif + .else // !\push_ip + .if \push_lr + /* Case 3: pop register range and lr register. */ + pop {r\first-r\last, lr} + .cfi_restore 14 + cfirestorelist \first, \last + .else // !\push_lr + /* Case 4: pop register range. */ + pop {r\first-r\last} + cfirestorelist \first, \last + .endif + .endif + .else // \last == \first + .if \push_ip + .if \push_lr + /* Case 5: pop single GP register plus ip and lr registers. */ + pop {r\first, ip, lr} + .cfi_restore 14 + .cfi_register 143, 12 + cfirestorelist \first, \first + .else // !\push_lr + /* Case 6: pop single GP register plus ip register. */ + pop {r\first, ip} + .cfi_register 143, 12 + cfirestorelist \first, \first + .endif + .else // !\push_ip + .if \push_lr + /* Case 7: pop single GP register plus lr register. */ + pop {r\first, lr} + .cfi_restore 14 + cfirestorelist \first, \first + .else // !\push_lr + /* Case 8: pop single GP register. */ + pop {r\first} + cfirestorelist \first, \first + .endif + .endif + .endif + .else // \first == -1 + .if \push_ip + .if \push_lr + /* Case 9: pop ip and lr registers. */ + pop {ip, lr} + .cfi_restore 14 + .cfi_register 143, 12 + .else // !\push_lr + /* Case 10: pop ip register. */ + pop {ip} + .cfi_register 143, 12 + .endif + .else // !\push_ip + .if \push_lr + /* Case 11: pop lr register. */ + pop {lr} + .cfi_restore 14 + .endif + .endif + .endif +#if HAVE_PAC_LEAF + aut ip, lr, sp +#endif /* HAVE_PAC_LEAF */ + bx lr +.endm + +/* Clean up expressions in 'last'. */ +.macro _preprocess_reglist1 first:req, last:req, push_ip:req, push_lr:req, reglist_op:req + .if \last == 0 + \reglist_op \first, 0, \push_ip, \push_lr + .elseif \last == 1 + \reglist_op \first, 1, \push_ip, \push_lr + .elseif \last == 2 + \reglist_op \first, 2, \push_ip, \push_lr + .elseif \last == 3 + \reglist_op \first, 3, \push_ip, \push_lr + .elseif \last == 4 + \reglist_op \first, 4, \push_ip, \push_lr + .elseif \last == 5 + \reglist_op \first, 5, \push_ip, \push_lr + .elseif \last == 6 + \reglist_op \first, 6, \push_ip, \push_lr + .elseif \last == 7 + \reglist_op \first, 7, \push_ip, \push_lr + .elseif \last == 8 + \reglist_op \first, 8, \push_ip, \push_lr + .elseif \last == 9 + \reglist_op \first, 9, \push_ip, \push_lr + .elseif \last == 10 + \reglist_op \first, 10, \push_ip, \push_lr + .elseif \last == 11 + \reglist_op \first, 11, \push_ip, \push_lr + .else + .error "last (\last) out of range" + .endif +.endm + +/* Clean up expressions in 'first'. */ +.macro _preprocess_reglist first:req, last, push_ip=0, push_lr=0, reglist_op:req + .ifb \last + _preprocess_reglist \first \first \push_ip \push_lr + .else + .if \first > \last + .error "last (\last) must be at least as great as first (\first)" + .endif + .if \first == 0 + _preprocess_reglist1 0, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 1 + _preprocess_reglist1 1, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 2 + _preprocess_reglist1 2, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 3 + _preprocess_reglist1 3, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 4 + _preprocess_reglist1 4, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 5 + _preprocess_reglist1 5, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 6 + _preprocess_reglist1 6, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 7 + _preprocess_reglist1 7, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 8 + _preprocess_reglist1 8, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 9 + _preprocess_reglist1 9, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 10 + _preprocess_reglist1 10, \last, \push_ip, \push_lr, \reglist_op + .elseif \first == 11 + _preprocess_reglist1 11, \last, \push_ip, \push_lr, \reglist_op + .else + .error "first (\first) out of range" + .endif + .endif +.endm + +.macro _align8 first, last, push_ip=0, push_lr=0, reglist_op=_prologue + .ifb \first + .ifnb \last + .error "can't have last (\last) without specifying first" + .else // \last not blank + .if ((\push_ip + \push_lr) % 2) == 0 + \reglist_op first=-1, last=-1, push_ip=\push_ip, push_lr=\push_lr + .exitm + .else // ((\push_ip + \push_lr) % 2) odd + _align8 2, 2, \push_ip, \push_lr, \reglist_op + .exitm + .endif // ((\push_ip + \push_lr) % 2) == 0 + .endif // .ifnb \last + .endif // .ifb \first + + .ifb \last + _align8 \first, \first, \push_ip, \push_lr, \reglist_op + .else + .if \push_ip & 1 <> \push_ip + .error "push_ip may be 0 or 1" + .endif + .if \push_lr & 1 <> \push_lr + .error "push_lr may be 0 or 1" + .endif + .ifeq (\last - \first + \push_ip + \push_lr) % 2 + .if \first == 0 + .error "Alignment required and first register is r0" + .exitm + .endif + _preprocess_reglist \first-1, \last, \push_ip, \push_lr, \reglist_op + .else + _preprocess_reglist \first \last, \push_ip, \push_lr, \reglist_op + .endif + .endif +.endm + +.macro prologue first, last, push_ip=PAC_LEAF_PUSH_IP, push_lr=0, align8=STACK_ALIGN_ENFORCE + .if \align8 + _align8 \first, \last, \push_ip, \push_lr, _prologue + .else + _prologue first=\first, last=\last, push_ip=\push_ip, push_lr=\push_lr + .endif +.endm + +.macro epilogue first, last, push_ip=PAC_LEAF_PUSH_IP, push_lr=0, align8=STACK_ALIGN_ENFORCE + .if \align8 + _align8 \first, \last, \push_ip, \push_lr, reglist_op=_epilogue + .else + _epilogue first=\first, last=\last, push_ip=\push_ip, push_lr=\push_lr + .endif +.endm + +#define ENTRY_ALIGN(name, alignment) \ + .global name; \ + .type name,%function; \ + .align alignment; \ + name: \ + .cfi_startproc; + +#define ENTRY(name) ENTRY_ALIGN(name, 6) + +#define ENTRY_ALIAS(name) \ + .global name; \ + .type name,%function; \ + name: + +#define END(name) \ + .cfi_endproc; \ + .size name, .-name; + +#define L(l) .L ## l + +#endif diff --git a/arch/arm/linker.lds.S b/arch/arm/linker.lds.S index fe7cea2..bd415d4 100644 --- a/arch/arm/linker.lds.S +++ b/arch/arm/linker.lds.S @@ -1,31 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2025, Ivaylo Ivanov + */ + ENTRY(_start); OUTPUT_FORMAT("elf32-littlearm") OUTPUT_ARCH(arm) TARGET(binary) -INPUT(KERNEL_PATH) -INPUT(DTB_PATH) SECTIONS { - /* The default TEXT_BASE address is 0x0 if not specified otherwise, so compare it to 0x1 */ - __start_address = (TEXT_BASE > 0x1) ? TEXT_BASE : 0x80008000; - . = __start_address; - - .boot : { - arch/arm/start.o - } + . = TEXT_BASE; - .dtb ALIGN(0x1000) : { - dtb = .; - DTB_PATH - } + .text : { + KEEP(*(.text.start)) + *(.text) + *(.text.*) + } - .kernel ALIGN(0x1000) : { - kernel = .; - KERNEL_PATH - } + .rodata ALIGN(4) : { + *(.rodata) + *(.rodata.*) + } - kernel_size = SIZEOF(.kernel); + .data ALIGN(4) : { + *(.data) + *(.data.*) + } + + .bss ALIGN(4) : { + __bss_start = .; + *(.bss) + *(.bss.*) + *(COMMON) + __bss_end = .; + } + + .stack ALIGN(0x1000) : { + __stack_top = .; + . += 0x1000; + __stack_bottom = .; + } + + _end = .; } diff --git a/arch/arm/memcpy.S b/arch/arm/memcpy.S new file mode 100644 index 0000000..6fdac74 --- /dev/null +++ b/arch/arm/memcpy.S @@ -0,0 +1,589 @@ +/* + * https://github.com/ARM-software/optimized-routines/blob/master/string/arm/memcpy.S + * + * memcpy - copy memory area + * + * Copyright (c) 2013-2022, Arm Limited. + * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception + */ + +/* + This memcpy routine is optimised for Cortex-A15 cores and takes advantage + of VFP or NEON when built with the appropriate flags. + + Assumptions: + + ARMv6 (ARMv7-a if using Neon) + ARM state + Unaligned accesses + + */ + +#include "asmdefs.h" + + .syntax unified + /* This implementation requires ARM state. */ + .arm + +#ifdef __ARM_NEON__ + + .fpu neon + .arch armv7-a +# define FRAME_SIZE 4 +# define USE_VFP +# define USE_NEON + +#elif !defined (__SOFTFP__) + + .arch armv6 + .fpu vfpv2 +# define FRAME_SIZE 32 +# define USE_VFP + +#else + .arch armv6 +# define FRAME_SIZE 32 + +#endif + +/* Old versions of GAS incorrectly implement the NEON align semantics. */ +#ifdef BROKEN_ASM_NEON_ALIGN +#define ALIGN(addr, align) addr,:align +#else +#define ALIGN(addr, align) addr:align +#endif + +#define PC_OFFSET 8 /* PC pipeline compensation. */ +#define INSN_SIZE 4 + +/* Call parameters. */ +#define dstin r0 +#define src r1 +#define count r2 + +/* Locals. */ +#define tmp1 r3 +#define dst ip +#define tmp2 r10 + +#ifndef USE_NEON +/* For bulk copies using GP registers. */ +#define A_l r2 /* Call-clobbered. */ +#define A_h r3 /* Call-clobbered. */ +#define B_l r4 +#define B_h r5 +#define C_l r6 +#define C_h r7 +#define D_l r8 +#define D_h r9 +#endif + +/* Number of lines ahead to pre-fetch data. If you change this the code + below will need adjustment to compensate. */ + +#define prefetch_lines 5 + +#ifdef USE_VFP + .macro cpy_line_vfp vreg, base + vstr \vreg, [dst, #\base] + vldr \vreg, [src, #\base] + vstr d0, [dst, #\base + 8] + vldr d0, [src, #\base + 8] + vstr d1, [dst, #\base + 16] + vldr d1, [src, #\base + 16] + vstr d2, [dst, #\base + 24] + vldr d2, [src, #\base + 24] + vstr \vreg, [dst, #\base + 32] + vldr \vreg, [src, #\base + prefetch_lines * 64 - 32] + vstr d0, [dst, #\base + 40] + vldr d0, [src, #\base + 40] + vstr d1, [dst, #\base + 48] + vldr d1, [src, #\base + 48] + vstr d2, [dst, #\base + 56] + vldr d2, [src, #\base + 56] + .endm + + .macro cpy_tail_vfp vreg, base + vstr \vreg, [dst, #\base] + vldr \vreg, [src, #\base] + vstr d0, [dst, #\base + 8] + vldr d0, [src, #\base + 8] + vstr d1, [dst, #\base + 16] + vldr d1, [src, #\base + 16] + vstr d2, [dst, #\base + 24] + vldr d2, [src, #\base + 24] + vstr \vreg, [dst, #\base + 32] + vstr d0, [dst, #\base + 40] + vldr d0, [src, #\base + 40] + vstr d1, [dst, #\base + 48] + vldr d1, [src, #\base + 48] + vstr d2, [dst, #\base + 56] + vldr d2, [src, #\base + 56] + .endm +#endif + +ENTRY (__memcpy_arm) + + mov dst, dstin /* Preserve dstin, we need to return it. */ + cmp count, #64 + bhs L(cpy_not_short) + /* Deal with small copies quickly by dropping straight into the + exit block. */ + +L(tail63unaligned): +#ifdef USE_NEON + and tmp1, count, #0x38 + rsb tmp1, tmp1, #(56 - PC_OFFSET + INSN_SIZE) + add pc, pc, tmp1 + vld1.8 {d0}, [src]! /* 14 words to go. */ + vst1.8 {d0}, [dst]! + vld1.8 {d0}, [src]! /* 12 words to go. */ + vst1.8 {d0}, [dst]! + vld1.8 {d0}, [src]! /* 10 words to go. */ + vst1.8 {d0}, [dst]! + vld1.8 {d0}, [src]! /* 8 words to go. */ + vst1.8 {d0}, [dst]! + vld1.8 {d0}, [src]! /* 6 words to go. */ + vst1.8 {d0}, [dst]! + vld1.8 {d0}, [src]! /* 4 words to go. */ + vst1.8 {d0}, [dst]! + vld1.8 {d0}, [src]! /* 2 words to go. */ + vst1.8 {d0}, [dst]! + + tst count, #4 + ldrne tmp1, [src], #4 + strne tmp1, [dst], #4 +#else + /* Copy up to 15 full words of data. May not be aligned. */ + /* Cannot use VFP for unaligned data. */ + and tmp1, count, #0x3c + add dst, dst, tmp1 + add src, src, tmp1 + rsb tmp1, tmp1, #(60 - PC_OFFSET/2 + INSN_SIZE/2) + /* Jump directly into the sequence below at the correct offset. */ + add pc, pc, tmp1, lsl #1 + + ldr tmp1, [src, #-60] /* 15 words to go. */ + str tmp1, [dst, #-60] + + ldr tmp1, [src, #-56] /* 14 words to go. */ + str tmp1, [dst, #-56] + ldr tmp1, [src, #-52] + str tmp1, [dst, #-52] + + ldr tmp1, [src, #-48] /* 12 words to go. */ + str tmp1, [dst, #-48] + ldr tmp1, [src, #-44] + str tmp1, [dst, #-44] + + ldr tmp1, [src, #-40] /* 10 words to go. */ + str tmp1, [dst, #-40] + ldr tmp1, [src, #-36] + str tmp1, [dst, #-36] + + ldr tmp1, [src, #-32] /* 8 words to go. */ + str tmp1, [dst, #-32] + ldr tmp1, [src, #-28] + str tmp1, [dst, #-28] + + ldr tmp1, [src, #-24] /* 6 words to go. */ + str tmp1, [dst, #-24] + ldr tmp1, [src, #-20] + str tmp1, [dst, #-20] + + ldr tmp1, [src, #-16] /* 4 words to go. */ + str tmp1, [dst, #-16] + ldr tmp1, [src, #-12] + str tmp1, [dst, #-12] + + ldr tmp1, [src, #-8] /* 2 words to go. */ + str tmp1, [dst, #-8] + ldr tmp1, [src, #-4] + str tmp1, [dst, #-4] +#endif + + lsls count, count, #31 + ldrhcs tmp1, [src], #2 + ldrbne src, [src] /* Src is dead, use as a scratch. */ + strhcs tmp1, [dst], #2 + strbne src, [dst] + bx lr + +L(cpy_not_short): + /* At least 64 bytes to copy, but don't know the alignment yet. */ + str tmp2, [sp, #-FRAME_SIZE]! + and tmp2, src, #7 + and tmp1, dst, #7 + cmp tmp1, tmp2 + bne L(cpy_notaligned) + +#ifdef USE_VFP + /* Magic dust alert! Force VFP on Cortex-A9. Experiments show + that the FP pipeline is much better at streaming loads and + stores. This is outside the critical loop. */ + vmov.f32 s0, s0 +#endif + + /* SRC and DST have the same mutual 64-bit alignment, but we may + still need to pre-copy some bytes to get to natural alignment. + We bring SRC and DST into full 64-bit alignment. */ + lsls tmp2, dst, #29 + beq 1f + rsbs tmp2, tmp2, #0 + sub count, count, tmp2, lsr #29 + ldrmi tmp1, [src], #4 + strmi tmp1, [dst], #4 + lsls tmp2, tmp2, #2 + ldrhcs tmp1, [src], #2 + ldrbne tmp2, [src], #1 + strhcs tmp1, [dst], #2 + strbne tmp2, [dst], #1 + +1: + subs tmp2, count, #64 /* Use tmp2 for count. */ + blo L(tail63aligned) + + cmp tmp2, #512 + bhs L(cpy_body_long) + +L(cpy_body_medium): /* Count in tmp2. */ +#ifdef USE_VFP +1: + vldr d0, [src, #0] + subs tmp2, tmp2, #64 + vldr d1, [src, #8] + vstr d0, [dst, #0] + vldr d0, [src, #16] + vstr d1, [dst, #8] + vldr d1, [src, #24] + vstr d0, [dst, #16] + vldr d0, [src, #32] + vstr d1, [dst, #24] + vldr d1, [src, #40] + vstr d0, [dst, #32] + vldr d0, [src, #48] + vstr d1, [dst, #40] + vldr d1, [src, #56] + vstr d0, [dst, #48] + add src, src, #64 + vstr d1, [dst, #56] + add dst, dst, #64 + bhs 1b + tst tmp2, #0x3f + beq L(done) + +L(tail63aligned): /* Count in tmp2. */ + and tmp1, tmp2, #0x38 + add dst, dst, tmp1 + add src, src, tmp1 + rsb tmp1, tmp1, #(56 - PC_OFFSET + INSN_SIZE) + add pc, pc, tmp1 + + vldr d0, [src, #-56] /* 14 words to go. */ + vstr d0, [dst, #-56] + vldr d0, [src, #-48] /* 12 words to go. */ + vstr d0, [dst, #-48] + vldr d0, [src, #-40] /* 10 words to go. */ + vstr d0, [dst, #-40] + vldr d0, [src, #-32] /* 8 words to go. */ + vstr d0, [dst, #-32] + vldr d0, [src, #-24] /* 6 words to go. */ + vstr d0, [dst, #-24] + vldr d0, [src, #-16] /* 4 words to go. */ + vstr d0, [dst, #-16] + vldr d0, [src, #-8] /* 2 words to go. */ + vstr d0, [dst, #-8] +#else + sub src, src, #8 + sub dst, dst, #8 +1: + ldrd A_l, A_h, [src, #8] + strd A_l, A_h, [dst, #8] + ldrd A_l, A_h, [src, #16] + strd A_l, A_h, [dst, #16] + ldrd A_l, A_h, [src, #24] + strd A_l, A_h, [dst, #24] + ldrd A_l, A_h, [src, #32] + strd A_l, A_h, [dst, #32] + ldrd A_l, A_h, [src, #40] + strd A_l, A_h, [dst, #40] + ldrd A_l, A_h, [src, #48] + strd A_l, A_h, [dst, #48] + ldrd A_l, A_h, [src, #56] + strd A_l, A_h, [dst, #56] + ldrd A_l, A_h, [src, #64]! + strd A_l, A_h, [dst, #64]! + subs tmp2, tmp2, #64 + bhs 1b + tst tmp2, #0x3f + bne 1f + ldr tmp2,[sp], #FRAME_SIZE + bx lr +1: + add src, src, #8 + add dst, dst, #8 + +L(tail63aligned): /* Count in tmp2. */ + /* Copy up to 7 d-words of data. Similar to Ltail63unaligned, but + we know that the src and dest are 64-bit aligned so we can use + LDRD/STRD to improve efficiency. */ + /* TMP2 is now negative, but we don't care about that. The bottom + six bits still tell us how many bytes are left to copy. */ + + and tmp1, tmp2, #0x38 + add dst, dst, tmp1 + add src, src, tmp1 + rsb tmp1, tmp1, #(56 - PC_OFFSET + INSN_SIZE) + add pc, pc, tmp1 + ldrd A_l, A_h, [src, #-56] /* 14 words to go. */ + strd A_l, A_h, [dst, #-56] + ldrd A_l, A_h, [src, #-48] /* 12 words to go. */ + strd A_l, A_h, [dst, #-48] + ldrd A_l, A_h, [src, #-40] /* 10 words to go. */ + strd A_l, A_h, [dst, #-40] + ldrd A_l, A_h, [src, #-32] /* 8 words to go. */ + strd A_l, A_h, [dst, #-32] + ldrd A_l, A_h, [src, #-24] /* 6 words to go. */ + strd A_l, A_h, [dst, #-24] + ldrd A_l, A_h, [src, #-16] /* 4 words to go. */ + strd A_l, A_h, [dst, #-16] + ldrd A_l, A_h, [src, #-8] /* 2 words to go. */ + strd A_l, A_h, [dst, #-8] + +#endif + tst tmp2, #4 + ldrne tmp1, [src], #4 + strne tmp1, [dst], #4 + lsls tmp2, tmp2, #31 /* Count (tmp2) now dead. */ + ldrhcs tmp1, [src], #2 + ldrbne tmp2, [src] + strhcs tmp1, [dst], #2 + strbne tmp2, [dst] + +L(done): + ldr tmp2, [sp], #FRAME_SIZE + bx lr + +L(cpy_body_long): /* Count in tmp2. */ + + /* Long copy. We know that there's at least (prefetch_lines * 64) + bytes to go. */ +#ifdef USE_VFP + /* Don't use PLD. Instead, read some data in advance of the current + copy position into a register. This should act like a PLD + operation but we won't have to repeat the transfer. */ + + vldr d3, [src, #0] + vldr d4, [src, #64] + vldr d5, [src, #128] + vldr d6, [src, #192] + vldr d7, [src, #256] + + vldr d0, [src, #8] + vldr d1, [src, #16] + vldr d2, [src, #24] + add src, src, #32 + + subs tmp2, tmp2, #prefetch_lines * 64 * 2 + blo 2f +1: + cpy_line_vfp d3, 0 + cpy_line_vfp d4, 64 + cpy_line_vfp d5, 128 + add dst, dst, #3 * 64 + add src, src, #3 * 64 + cpy_line_vfp d6, 0 + cpy_line_vfp d7, 64 + add dst, dst, #2 * 64 + add src, src, #2 * 64 + subs tmp2, tmp2, #prefetch_lines * 64 + bhs 1b + +2: + cpy_tail_vfp d3, 0 + cpy_tail_vfp d4, 64 + cpy_tail_vfp d5, 128 + add src, src, #3 * 64 + add dst, dst, #3 * 64 + cpy_tail_vfp d6, 0 + vstr d7, [dst, #64] + vldr d7, [src, #64] + vstr d0, [dst, #64 + 8] + vldr d0, [src, #64 + 8] + vstr d1, [dst, #64 + 16] + vldr d1, [src, #64 + 16] + vstr d2, [dst, #64 + 24] + vldr d2, [src, #64 + 24] + vstr d7, [dst, #64 + 32] + add src, src, #96 + vstr d0, [dst, #64 + 40] + vstr d1, [dst, #64 + 48] + vstr d2, [dst, #64 + 56] + add dst, dst, #128 + add tmp2, tmp2, #prefetch_lines * 64 + b L(cpy_body_medium) +#else + /* Long copy. Use an SMS style loop to maximize the I/O + bandwidth of the core. We don't have enough spare registers + to synthesise prefetching, so use PLD operations. */ + /* Pre-bias src and dst. */ + sub src, src, #8 + sub dst, dst, #8 + pld [src, #8] + pld [src, #72] + subs tmp2, tmp2, #64 + pld [src, #136] + ldrd A_l, A_h, [src, #8] + strd B_l, B_h, [sp, #8] + ldrd B_l, B_h, [src, #16] + strd C_l, C_h, [sp, #16] + ldrd C_l, C_h, [src, #24] + strd D_l, D_h, [sp, #24] + pld [src, #200] + ldrd D_l, D_h, [src, #32]! + b 1f + .p2align 6 +2: + pld [src, #232] + strd A_l, A_h, [dst, #40] + ldrd A_l, A_h, [src, #40] + strd B_l, B_h, [dst, #48] + ldrd B_l, B_h, [src, #48] + strd C_l, C_h, [dst, #56] + ldrd C_l, C_h, [src, #56] + strd D_l, D_h, [dst, #64]! + ldrd D_l, D_h, [src, #64]! + subs tmp2, tmp2, #64 +1: + strd A_l, A_h, [dst, #8] + ldrd A_l, A_h, [src, #8] + strd B_l, B_h, [dst, #16] + ldrd B_l, B_h, [src, #16] + strd C_l, C_h, [dst, #24] + ldrd C_l, C_h, [src, #24] + strd D_l, D_h, [dst, #32] + ldrd D_l, D_h, [src, #32] + bcs 2b + /* Save the remaining bytes and restore the callee-saved regs. */ + strd A_l, A_h, [dst, #40] + add src, src, #40 + strd B_l, B_h, [dst, #48] + ldrd B_l, B_h, [sp, #8] + strd C_l, C_h, [dst, #56] + ldrd C_l, C_h, [sp, #16] + strd D_l, D_h, [dst, #64] + ldrd D_l, D_h, [sp, #24] + add dst, dst, #72 + tst tmp2, #0x3f + bne L(tail63aligned) + ldr tmp2, [sp], #FRAME_SIZE + bx lr +#endif + +L(cpy_notaligned): + pld [src] + pld [src, #64] + /* There's at least 64 bytes to copy, but there is no mutual + alignment. */ + /* Bring DST to 64-bit alignment. */ + lsls tmp2, dst, #29 + pld [src, #(2 * 64)] + beq 1f + rsbs tmp2, tmp2, #0 + sub count, count, tmp2, lsr #29 + ldrmi tmp1, [src], #4 + strmi tmp1, [dst], #4 + lsls tmp2, tmp2, #2 + ldrbne tmp1, [src], #1 + ldrhcs tmp2, [src], #2 + strbne tmp1, [dst], #1 + strhcs tmp2, [dst], #2 +1: + pld [src, #(3 * 64)] + subs count, count, #64 + ldrlo tmp2, [sp], #FRAME_SIZE + blo L(tail63unaligned) + pld [src, #(4 * 64)] + +#ifdef USE_NEON + vld1.8 {d0-d3}, [src]! + vld1.8 {d4-d7}, [src]! + subs count, count, #64 + blo 2f +1: + pld [src, #(4 * 64)] + vst1.8 {d0-d3}, [ALIGN (dst, 64)]! + vld1.8 {d0-d3}, [src]! + vst1.8 {d4-d7}, [ALIGN (dst, 64)]! + vld1.8 {d4-d7}, [src]! + subs count, count, #64 + bhs 1b +2: + vst1.8 {d0-d3}, [ALIGN (dst, 64)]! + vst1.8 {d4-d7}, [ALIGN (dst, 64)]! + ands count, count, #0x3f +#else + /* Use an SMS style loop to maximize the I/O bandwidth. */ + sub src, src, #4 + sub dst, dst, #8 + subs tmp2, count, #64 /* Use tmp2 for count. */ + ldr A_l, [src, #4] + ldr A_h, [src, #8] + strd B_l, B_h, [sp, #8] + ldr B_l, [src, #12] + ldr B_h, [src, #16] + strd C_l, C_h, [sp, #16] + ldr C_l, [src, #20] + ldr C_h, [src, #24] + strd D_l, D_h, [sp, #24] + ldr D_l, [src, #28] + ldr D_h, [src, #32]! + b 1f + .p2align 6 +2: + pld [src, #(5 * 64) - (32 - 4)] + strd A_l, A_h, [dst, #40] + ldr A_l, [src, #36] + ldr A_h, [src, #40] + strd B_l, B_h, [dst, #48] + ldr B_l, [src, #44] + ldr B_h, [src, #48] + strd C_l, C_h, [dst, #56] + ldr C_l, [src, #52] + ldr C_h, [src, #56] + strd D_l, D_h, [dst, #64]! + ldr D_l, [src, #60] + ldr D_h, [src, #64]! + subs tmp2, tmp2, #64 +1: + strd A_l, A_h, [dst, #8] + ldr A_l, [src, #4] + ldr A_h, [src, #8] + strd B_l, B_h, [dst, #16] + ldr B_l, [src, #12] + ldr B_h, [src, #16] + strd C_l, C_h, [dst, #24] + ldr C_l, [src, #20] + ldr C_h, [src, #24] + strd D_l, D_h, [dst, #32] + ldr D_l, [src, #28] + ldr D_h, [src, #32] + bcs 2b + + /* Save the remaining bytes and restore the callee-saved regs. */ + strd A_l, A_h, [dst, #40] + add src, src, #36 + strd B_l, B_h, [dst, #48] + ldrd B_l, B_h, [sp, #8] + strd C_l, C_h, [dst, #56] + ldrd C_l, C_h, [sp, #16] + strd D_l, D_h, [dst, #64] + ldrd D_l, D_h, [sp, #24] + add dst, dst, #72 + ands count, tmp2, #0x3f +#endif + ldr tmp2, [sp], #FRAME_SIZE + bne L(tail63unaligned) + bx lr + +END (__memcpy_arm) diff --git a/arch/arm/start.S b/arch/arm/start.S index 4c66634..4df34f6 100644 --- a/arch/arm/start.S +++ b/arch/arm/start.S @@ -2,13 +2,58 @@ /* * Copyright (c) 2022, Ivaylo Ivanov */ -.global _start +#include "asmdefs.h" -_start: - ldr r0, =dtb - ldr r1, =kernel - b main +.section .text +ENTRY(_start) + /* disable interrupts */ + mrs r0, cpsr + orr r0, r0, #(0x1 << 7) + orr r0, r0, #(0x1 << 6) + msr cpsr_c, r0 + + mrc p15, 0, r12, c1, c0, 0 + /* i/d cache disable, mmu disabled */ + bic r12, #(1<<12) + bic r12, #(1<<2 | 1<<0) + mcr p15, 0, r12, c1, c0, 0 + + ldr sp, =__stack_top + + /* main(void* dt, void* kernel, void* ramdisk) */ + ldr r0, =_dt_start @ Load address of dtb into r0 + ldr r1, =_kernel_start @ Load address of kernel into r1 + ldr r2, =_ramdisk_start @ Load address of ramdisk into r2 + b main +END(_start) + +ENTRY(load_kernel_and_jump) + mov r1, #0 @ machine type = 0 (device tree) + mov r0, #0 @ reserved + bx r3 +END(load_kernel_and_jump) + +/* embedding kernel and dt */ +.section .rodata +ENTRY(_kernel_start) + .incbin "blob/Image" +END(_kernel_start) + +ENTRY_ALIAS(_kernel_end) + +ENTRY_ALIAS(kernel_size) + .word _kernel_end - _kernel_start + +ENTRY(_dt_start) + .incbin "blob/dtb" +END(_dt_start) + +ENTRY(_ramdisk_start) + .incbin "blob/ramdisk" +END(_ramdisk_start) + +ENTRY_ALIAS(_ramdisk_end) + +ENTRY_ALIAS(ramdisk_size) + .word _ramdisk_end - _ramdisk_start -.global load_kernel -load_kernel: - bx r4 diff --git a/board/Kconfig b/board/Kconfig index 8592c43..eae675f 100644 --- a/board/Kconfig +++ b/board/Kconfig @@ -1,4 +1,12 @@ menu "Device Support" + config AMAZON_PW3 + bool "Support for Amazon Kindle Paperwhite 3" + default n + depends on FREESCALE_IMX6SL + help + Say Y if you want to include support for Amaozn Kindle + Paperwhite 3 + config APPLE_N61AP bool "Support for Apple iPhone 6" default n @@ -127,6 +135,7 @@ menu "Device Specific Addresses" config PAYLOAD_ENTRY hex "Payload Entry Address" + default 0x90000000 if AMAZON_PW3 default 0x830000000 if APPLE_N61AP default 0x090000000 if SAMSUNG_A105F default 0x090008000 if SAMSUNG_A127F @@ -147,6 +156,7 @@ menu "Device Specific Addresses" config RAMDISK_ENTRY hex "Ramdisk Entry Address" + default 0x87000000 if AMAZON_PW3 default 0x084000000 if SAMSUNG_A105F default 0x082000000 if SAMSUNG_A127F default 0x084000000 if SAMSUNG_A336B diff --git a/board/Makefile b/board/Makefile index a04f504..1172f8a 100644 --- a/board/Makefile +++ b/board/Makefile @@ -1,4 +1,5 @@ lib-$(CONFIG_APPLE_N61AP) += apple/board-n61ap.o +lib-$(CONFIG_AMAZON_PW3) += amazon/board-pw3.o lib-$(CONFIG_SAMSUNG_A105F) += samsung/board-a105f.o lib-$(CONFIG_SAMSUNG_A127F) += samsung/board-a127f.o lib-$(CONFIG_SAMSUNG_C1S) += samsung/board-c1s.o diff --git a/board/amazon/board-pw3.c b/board/amazon/board-pw3.c new file mode 100644 index 0000000..0855eff --- /dev/null +++ b/board/amazon/board-pw3.c @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2025, Ivaylo Ivanov + */ + +#include +#include +#include + +#define IMX6SL_UART1_BASE_ADDR 0x02020000 +#define URTX0_OFFSET 0x40 +#define IMX_UTS_OFFSET 0xB4 +#define UTS_TXFULL (1 << 4) + +void uart_putc(char ch) +{ + volatile uint32_t *uts_reg = (volatile + uint32_t *)(IMX6SL_UART1_BASE_ADDR + + IMX_UTS_OFFSET); + volatile uint32_t *urtx0_reg = (volatile + uint32_t *)(IMX6SL_UART1_BASE_ADDR + + URTX0_OFFSET); + + while ((*uts_reg) & UTS_TXFULL) { } + + *urtx0_reg = (uint32_t)ch; +} + +void uart_puts(const char *s) +{ + while (*s != '\0') { + uart_putc(*s); + s++; + } +} + +void init_board_funcs(void *board) +{ + /* + * Parsing the struct directly without restructing is + * broken as of Sep 29 2024 + */ + struct { + const char *name; + int ops[BOARD_OP_EXIT]; + } *board_restruct = board; + + board_restruct->name = "PW3"; +} + +int board_init(void) +{ + return 0; +} + +int board_late_init(void) +{ + return 0; +} + +int board_driver_setup(void) +{ + return 0; +} diff --git a/configs/pw3_defconfig b/configs/pw3_defconfig new file mode 100644 index 0000000..6484471 --- /dev/null +++ b/configs/pw3_defconfig @@ -0,0 +1,5 @@ +CONFIG_TEXT_BASE=0x82000000 +CONFIG_AMAZON_PW3=y +CONFIG_FREESCALE_IMX6SL=y +CONFIG_SIMPLE_FB=n +CONFIG_UART_DEBUG=y diff --git a/include/lib/debug.h b/include/lib/debug.h index 429cc3b..68c8305 100644 --- a/include/lib/debug.h +++ b/include/lib/debug.h @@ -17,5 +17,4 @@ #define KERN_DEBUG 7 extern void printk(int loglevel, char *text); - #endif // DEBUG_H_ diff --git a/include/main.h b/include/main.h index 584678e..0481f36 100644 --- a/include/main.h +++ b/include/main.h @@ -10,9 +10,16 @@ extern unsigned long kernel_size; extern unsigned long ramdisk_size; -extern void load_kernel(void* dtb, void* x1, void* x2, void* x3, void* kernel); -extern void soc_init(void); +#ifdef __aarch64__ +extern void load_kernel_and_jump(void* dtb, void* x1, void* x2, void* x3, + void* kernel); +#elif __arm__ +extern void load_kernel_and_jump(unsigned int r0, unsigned int r1, + void* dtb_addr, void* kernel_entry); +#endif + +extern void soc_init(void); extern void writel(unsigned int value, void* address); #endif // MAIN_H_ diff --git a/lib/Kconfig b/lib/Kconfig index 2b7c7b9..13b3da6 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -4,4 +4,10 @@ menu "Libraries" default y help Say Y if you want to have Framebuffer output. + + config UART_DEBUG + bool "Support for UART debugging" + default n + help + Say Y if you want to have UART output. endmenu diff --git a/lib/debug/debug.c b/lib/debug/debug.c index 4c7e730..b605769 100644 --- a/lib/debug/debug.c +++ b/lib/debug/debug.c @@ -11,6 +11,8 @@ long int debug_linecount = 0; +void uart_puts(const char *s); + // Global log level that controls the verbosity static int global_loglevel = CONFIG_LOGLEVEL; @@ -50,6 +52,12 @@ void printk(int log_level, char *text) break; } +#ifdef CONFIG_UART_DEBUG + uart_puts(prefix); + uart_puts(text); + uart_puts("\r"); +#endif + #ifdef CONFIG_SIMPLE_FB // Actually the first line's Y pos. Scales in __simplefb_raw_print int y_pos = 5; diff --git a/lib/unic/string.h b/lib/unic/string.h index becf476..bd76905 100644 --- a/lib/unic/string.h +++ b/lib/unic/string.h @@ -78,43 +78,15 @@ static void *__optimized_memcpy (void *dst0, const void *src0, size_t len0) // Assembly-driven functions #ifdef __aarch64__ + void *memcpy (void *__restrict, const void *__restrict, size_t); void *memmove (void *, const void *, size_t); -#endif -#ifdef __arm__ -void *memcpy (void *s1, const void *s2, size_t n) -{ - char *dest = (char *)s1; - const char *src = (const char *)s2; +#elif __arm__ - while (n--) { - *dest++ = *src++; - } +void *__memcpy_arm (void *__restrict, const void *__restrict, size_t); +#define memcpy __memcpy_arm - return s1; -} - -void *memmove (void *s1, const void *s2, size_t n) -{ - char *dest = (char *)s1; - const char *src = (const char *)s2; - - if (dest <= src) { - while (n--) { - *dest++ = *src++; - } - } else { - src += n; - dest += n; - - while (n--) { - *--dest = *--src; - } - } - - return s1; -} #endif static inline int tolower (int c) diff --git a/main/main.c b/main/main.c index 4a6d64b..52dfa60 100644 --- a/main/main.c +++ b/main/main.c @@ -45,10 +45,15 @@ void main(void* dt, void* kernel, void* ramdisk) /* Copy kernel to memory and boot */ printk(-1, "Booting linux...\n"); +#ifdef __aarch64__ memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) &kernel_size); __optimized_memcpy((void*)CONFIG_RAMDISK_ENTRY, ramdisk, (unsigned long) &ramdisk_size); - load_kernel(dt, 0, 0, 0, (void*)CONFIG_PAYLOAD_ENTRY); - + load_kernel_and_jump(dt, 0, 0, 0, (void*)CONFIG_PAYLOAD_ENTRY); +#elif __arm__ + memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) kernel_size); + memcpy((void*)CONFIG_RAMDISK_ENTRY, ramdisk, (unsigned long) ramdisk_size); + load_kernel_and_jump(0, 0, dt, (void*)CONFIG_PAYLOAD_ENTRY); +#endif /* We shouldn't get there */ printk(KERN_WARNING, "Something wrong happened, we shouldn't be here. Hanging....\n"); while(1) {} diff --git a/soc/Kconfig b/soc/Kconfig index aa93820..2f28071 100644 --- a/soc/Kconfig +++ b/soc/Kconfig @@ -6,6 +6,10 @@ config EXYNOS bool default n +config FREESCALE + bool + default n + config MEDIATEK bool default n @@ -114,4 +118,11 @@ config QUALCOMM select QUALCOMM help Say Y if your device uses this Qualcomm SoC + + config FREESCALE_IMX6SL + bool "Support for Freescale i.MX6SL" + default n + select FREESCALE + help + Say Y if your device uses i.MX6SL endchoice