Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[arm] Add support for 64-bit ARM (Aarch64)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed May 7, 2016
1 parent edea3a4 commit 17c6f32
Show file tree
Hide file tree
Showing 21 changed files with 1,055 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/arch/arm/core/arm_io.c
Expand Up @@ -84,5 +84,10 @@ PROVIDE_IOAPI_INLINE ( arm, writew );
PROVIDE_IOAPI_INLINE ( arm, writel );
PROVIDE_IOAPI_INLINE ( arm, iodelay );
PROVIDE_IOAPI_INLINE ( arm, mb );
#ifdef __aarch64__
PROVIDE_IOAPI_INLINE ( arm, readq );
PROVIDE_IOAPI_INLINE ( arm, writeq );
#else
PROVIDE_IOAPI ( arm, readq, arm32_readq );
PROVIDE_IOAPI ( arm, writeq, arm32_writeq );
#endif
9 changes: 9 additions & 0 deletions src/arch/arm/include/bits/xen.h
Expand Up @@ -10,12 +10,21 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

/* Hypercall registers */
#ifdef __aarch64__
#define XEN_HC "x16"
#define XEN_REG1 "x0"
#define XEN_REG2 "x1"
#define XEN_REG3 "x2"
#define XEN_REG4 "x3"
#define XEN_REG5 "x4"
#else
#define XEN_HC "r12"
#define XEN_REG1 "r0"
#define XEN_REG2 "r1"
#define XEN_REG3 "r2"
#define XEN_REG4 "r3"
#define XEN_REG5 "r4"
#endif

/**
* Issue hypercall with one argument
Expand Down
44 changes: 30 additions & 14 deletions src/arch/arm/include/ipxe/arm_io.h
Expand Up @@ -43,34 +43,46 @@ IOAPI_INLINE ( arm, bus_to_phys ) ( unsigned long bus_addr ) {
*
*/

#define ARM_READX( _api_func, _type, _insn_suffix ) \
#define ARM_READX( _api_func, _type, _insn_suffix, _reg_prefix ) \
static inline __always_inline _type \
IOAPI_INLINE ( arm, _api_func ) ( volatile _type *io_addr ) { \
_type data; \
__asm__ __volatile__ ( "ldr" _insn_suffix " %0, %1" \
__asm__ __volatile__ ( "ldr" _insn_suffix " %" _reg_prefix "0, %1" \
: "=r" ( data ) : "Qo" ( *io_addr ) ); \
return data; \
}
ARM_READX ( readb, uint8_t, "b" );
ARM_READX ( readw, uint16_t, "h" );
ARM_READX ( readl, uint32_t, "" );
#ifdef __aarch64__
ARM_READX ( readb, uint8_t, "b", "w" );
ARM_READX ( readw, uint16_t, "h", "w" );
ARM_READX ( readl, uint32_t, "", "w" );
ARM_READX ( readq, uint64_t, "", "" );
#else
ARM_READX ( readb, uint8_t, "b", "" );
ARM_READX ( readw, uint16_t, "h", "" );
ARM_READX ( readl, uint32_t, "", "" );
#endif

#define ARM_WRITEX( _api_func, _type, _insn_suffix ) \
#define ARM_WRITEX( _api_func, _type, _insn_suffix, _reg_prefix ) \
static inline __always_inline void \
IOAPI_INLINE ( arm, _api_func ) ( _type data, \
volatile _type *io_addr ) { \
__asm__ __volatile__ ( "str" _insn_suffix " %0, %1" \
IOAPI_INLINE ( arm, _api_func ) ( _type data, volatile _type *io_addr ) { \
__asm__ __volatile__ ( "str" _insn_suffix " %" _reg_prefix "0, %1" \
: : "r" ( data ), "Qo" ( *io_addr ) ); \
}
ARM_WRITEX ( writeb, uint8_t, "b" );
ARM_WRITEX ( writew, uint16_t, "h" );
ARM_WRITEX ( writel, uint32_t, "" );
#ifdef __aarch64__
ARM_WRITEX ( writeb, uint8_t, "b", "w" );
ARM_WRITEX ( writew, uint16_t, "h", "w" );
ARM_WRITEX ( writel, uint32_t, "", "w" );
ARM_WRITEX ( writeq, uint64_t, "", "" );
#else
ARM_WRITEX ( writeb, uint8_t, "b", "" );
ARM_WRITEX ( writew, uint16_t, "h", "" );
ARM_WRITEX ( writel, uint32_t, "", "" );
#endif

/*
* Slow down I/O
*
*/

static inline __always_inline void
IOAPI_INLINE ( arm, iodelay ) ( void ) {
/* Nothing to do */
Expand All @@ -80,10 +92,14 @@ IOAPI_INLINE ( arm, iodelay ) ( void ) {
* Memory barrier
*
*/

static inline __always_inline void
IOAPI_INLINE ( arm, mb ) ( void ) {

#ifdef __aarch64__
__asm__ __volatile__ ( "dmb sy" );
#else
__asm__ __volatile__ ( "dmb" );
#endif
}

#endif /* _IPXE_ARM_IO_H */
22 changes: 22 additions & 0 deletions src/arch/arm64/Makefile
@@ -0,0 +1,22 @@
# ARM64-specific directories containing source files
#
SRCDIRS += arch/arm64/core

# ARM64-specific flags
#
CFLAGS += -mabi=lp64 -mlittle-endian -mcmodel=small
CFLAGS += -fomit-frame-pointer
ASFLAGS += -mabi=lp64 -EL

# EFI requires -fshort-wchar, and nothing else currently uses wchar_t
#
CFLAGS += -fshort-wchar

# Include common ARM Makefile
MAKEDEPS += arch/arm/Makefile
include arch/arm/Makefile

# Include platform-specific Makefile
#
MAKEDEPS += arch/arm64/Makefile.$(PLATFORM)
include arch/arm64/Makefile.$(PLATFORM)
14 changes: 14 additions & 0 deletions src/arch/arm64/Makefile.efi
@@ -0,0 +1,14 @@
# -*- makefile -*- : Force emacs to use Makefile mode

# Specify EFI image builder
#
ELF2EFI = $(ELF2EFI64)

# Specify EFI boot file
#
EFI_BOOT_FILE = bootaa64.efi

# Include generic EFI Makefile
#
MAKEDEPS += arch/arm/Makefile.efi
include arch/arm/Makefile.efi
103 changes: 103 additions & 0 deletions src/arch/arm64/core/arm64_bigint.c
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
* You can also choose to distribute this program under the terms of
* the Unmodified Binary Distribution Licence (as given in the file
* COPYING.UBDL), provided that you have satisfied its requirements.
*/

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <stdint.h>
#include <string.h>
#include <ipxe/bigint.h>

/** @file
*
* Big integer support
*/

/**
* Multiply big integers
*
* @v multiplicand0 Element 0 of big integer to be multiplied
* @v multiplier0 Element 0 of big integer to be multiplied
* @v result0 Element 0 of big integer to hold result
* @v size Number of elements
*/
void bigint_multiply_raw ( const uint64_t *multiplicand0,
const uint64_t *multiplier0,
uint64_t *result0, unsigned int size ) {
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand =
( ( const void * ) multiplicand0 );
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier =
( ( const void * ) multiplier0 );
bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result =
( ( void * ) result0 );
unsigned int i;
unsigned int j;
uint64_t multiplicand_element;
uint64_t multiplier_element;
uint64_t *result_elements;
uint64_t discard_low;
uint64_t discard_high;
uint64_t discard_temp_low;
uint64_t discard_temp_high;

/* Zero result */
memset ( result, 0, sizeof ( *result ) );

/* Multiply integers one element at a time */
for ( i = 0 ; i < size ; i++ ) {
multiplicand_element = multiplicand->element[i];
for ( j = 0 ; j < size ; j++ ) {
multiplier_element = multiplier->element[j];
result_elements = &result->element[ i + j ];
/* Perform a single multiply, and add the
* resulting double-element into the result,
* carrying as necessary. The carry can
* never overflow beyond the end of the
* result, since:
*
* a < 2^{n}, b < 2^{n} => ab < 2^{2n}
*/
__asm__ __volatile__ ( "mul %1, %6, %7\n\t"
"umulh %2, %6, %7\n\t"
"ldp %3, %4, [%0]\n\t"
"adds %3, %3, %1\n\t"
"adcs %4, %4, %2\n\t"
"stp %3, %4, [%0], #16\n\t"
"bcc 2f\n\t"
"\n1:\n\t"
"ldr %3, [%0]\n\t"
"adcs %3, %3, xzr\n\t"
"str %3, [%0], #8\n\t"
"bcs 1b\n\t"
"\n2:\n\t"
: "+r" ( result_elements ),
"=&r" ( discard_low ),
"=&r" ( discard_high ),
"=r" ( discard_temp_low ),
"=r" ( discard_temp_high ),
"+m" ( *result )
: "r" ( multiplicand_element ),
"r" ( multiplier_element )
: "cc" );
}
}
}
56 changes: 56 additions & 0 deletions src/arch/arm64/core/setjmp.S
@@ -0,0 +1,56 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

.text

/* Must match jmp_buf structure layout */
.struct 0
env_x19_x20: .quad 0, 0
env_x21_x22: .quad 0, 0
env_x23_x24: .quad 0, 0
env_x25_x26: .quad 0, 0
env_x27_x28: .quad 0, 0
env_x29_x30: .quad 0, 0
env_sp: .quad 0
.previous

/*
* Save stack context for non-local goto
*/
.globl setjmp
.type setjmp, %function
setjmp:
/* Store registers */
stp x19, x20, [x0, #env_x19_x20]
stp x21, x22, [x0, #env_x21_x22]
stp x23, x24, [x0, #env_x23_x24]
stp x25, x26, [x0, #env_x25_x26]
stp x27, x28, [x0, #env_x27_x28]
stp x29, x30, [x0, #env_x29_x30]
mov x16, sp
str x16, [x0, #env_sp]
/* Return 0 when returning as setjmp() */
mov x0, #0
ret
.size setjmp, . - setjmp

/*
* Non-local jump to a saved stack context
*/
.globl longjmp
.type longjmp, %function
longjmp:
/* Restore registers */
ldp x19, x20, [x0, #env_x19_x20]
ldp x21, x22, [x0, #env_x21_x22]
ldp x23, x24, [x0, #env_x23_x24]
ldp x25, x26, [x0, #env_x25_x26]
ldp x27, x28, [x0, #env_x27_x28]
ldp x29, x30, [x0, #env_x29_x30]
ldr x16, [x0, #env_sp]
mov sp, x16
/* Force result to non-zero */
cmp w1, #0
csinc w0, w1, w1, ne
/* Return to setjmp() caller */
br x30
.size longjmp, . - longjmp

0 comments on commit 17c6f32

Please sign in to comment.