Sfoglia il codice sorgente

[arm] Add support for 32-bit ARM

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 anni fa
parent
commit
1a16f67a28
43 ha cambiato i file con 1879 aggiunte e 49 eliminazioni
  1. 25
    0
      src/arch/arm/Makefile
  2. 14
    0
      src/arch/arm/Makefile.efi
  3. 102
    0
      src/arch/arm/core/arm_bigint.c
  4. 88
    0
      src/arch/arm/core/arm_io.c
  5. 32
    0
      src/arch/arm/core/setjmp.S
  6. 316
    0
      src/arch/arm/include/bits/bigint.h
  7. 100
    0
      src/arch/arm/include/bits/bitops.h
  8. 52
    0
      src/arch/arm/include/bits/byteswap.h
  9. 16
    0
      src/arch/arm/include/bits/compiler.h
  10. 13
    0
      src/arch/arm/include/bits/endian.h
  11. 12
    0
      src/arch/arm/include/bits/entropy.h
  12. 19
    0
      src/arch/arm/include/bits/errfile.h
  13. 12
    0
      src/arch/arm/include/bits/hyperv.h
  14. 14
    0
      src/arch/arm/include/bits/io.h
  15. 12
    0
      src/arch/arm/include/bits/iomap.h
  16. 14
    0
      src/arch/arm/include/bits/nap.h
  17. 14
    0
      src/arch/arm/include/bits/pci_io.h
  18. 30
    0
      src/arch/arm/include/bits/profile.h
  19. 12
    0
      src/arch/arm/include/bits/reboot.h
  20. 12
    0
      src/arch/arm/include/bits/sanboot.h
  21. 12
    0
      src/arch/arm/include/bits/smbios.h
  22. 23
    0
      src/arch/arm/include/bits/stdint.h
  23. 60
    0
      src/arch/arm/include/bits/string.h
  24. 85
    0
      src/arch/arm/include/bits/strings.h
  25. 19
    0
      src/arch/arm/include/bits/tcpip.h
  26. 12
    0
      src/arch/arm/include/bits/time.h
  27. 12
    0
      src/arch/arm/include/bits/timer.h
  28. 12
    0
      src/arch/arm/include/bits/uaccess.h
  29. 12
    0
      src/arch/arm/include/bits/uart.h
  30. 12
    0
      src/arch/arm/include/bits/umalloc.h
  31. 149
    0
      src/arch/arm/include/bits/xen.h
  32. 46
    0
      src/arch/arm/include/efi/ipxe/dhcp_arch.h
  33. 45
    0
      src/arch/arm/include/gdbmach.h
  34. 89
    0
      src/arch/arm/include/ipxe/arm_io.h
  35. 18
    0
      src/arch/arm/include/ipxe/efi/efiarm_nap.h
  36. 61
    0
      src/arch/arm/include/limits.h
  37. 38
    0
      src/arch/arm/include/setjmp.h
  38. 53
    0
      src/arch/arm/interface/efi/efiarm_nap.c
  39. 50
    0
      src/arch/arm/libgcc/lldivmod.S
  40. 88
    0
      src/arch/arm/libgcc/llshift.S
  41. 10
    2
      src/config/defaults/efi.h
  42. 1
    0
      src/util/efirom.c
  43. 63
    47
      src/util/elf2efi.c

+ 25
- 0
src/arch/arm/Makefile Vedi File

@@ -0,0 +1,25 @@
1
+# Assembler section type character
2
+#
3
+ASM_TCHAR	:= %
4
+ASM_TCHAR_OPS	:= %%
5
+
6
+# ARM-specific directories containing source files
7
+#
8
+SRCDIRS		+= arch/arm/core
9
+SRCDIRS		+= arch/arm/libgcc
10
+SRCDIRS		+= arch/arm/interface/efi
11
+
12
+# ARM-specific flags
13
+#
14
+CFLAGS		+= -mthumb -mcpu=cortex-a15 -mabi=aapcs -mfloat-abi=soft
15
+CFLAGS		+= -mword-relocations
16
+ASFLAGS		+= -mthumb -mcpu=cortex-a15
17
+
18
+# EFI requires -fshort-wchar, and nothing else currently uses wchar_t
19
+#
20
+CFLAGS		+= -fshort-wchar
21
+
22
+# Include platform-specific Makefile
23
+#
24
+MAKEDEPS	+= arch/arm/Makefile.$(PLATFORM)
25
+include arch/arm/Makefile.$(PLATFORM)

+ 14
- 0
src/arch/arm/Makefile.efi Vedi File

@@ -0,0 +1,14 @@
1
+# -*- makefile -*- : Force emacs to use Makefile mode
2
+
3
+# Specify EFI image builder
4
+#
5
+ELF2EFI		= $(ELF2EFI32)
6
+
7
+# Specify EFI boot file
8
+#
9
+EFI_BOOT_FILE	= bootarm.efi
10
+
11
+# Include generic EFI Makefile
12
+#
13
+MAKEDEPS	+= Makefile.efi
14
+include Makefile.efi

+ 102
- 0
src/arch/arm/core/arm_bigint.c Vedi File

@@ -0,0 +1,102 @@
1
+/*
2
+ * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ *
19
+ * You can also choose to distribute this program under the terms of
20
+ * the Unmodified Binary Distribution Licence (as given in the file
21
+ * COPYING.UBDL), provided that you have satisfied its requirements.
22
+ */
23
+
24
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
+
26
+#include <stdint.h>
27
+#include <string.h>
28
+#include <ipxe/bigint.h>
29
+
30
+/** @file
31
+ *
32
+ * Big integer support
33
+ */
34
+
35
+/**
36
+ * Multiply big integers
37
+ *
38
+ * @v multiplicand0	Element 0 of big integer to be multiplied
39
+ * @v multiplier0	Element 0 of big integer to be multiplied
40
+ * @v result0		Element 0 of big integer to hold result
41
+ * @v size		Number of elements
42
+ */
43
+void bigint_multiply_raw ( const uint32_t *multiplicand0,
44
+			   const uint32_t *multiplier0,
45
+			   uint32_t *result0, unsigned int size ) {
46
+	const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand =
47
+		( ( const void * ) multiplicand0 );
48
+	const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier =
49
+		( ( const void * ) multiplier0 );
50
+	bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result =
51
+		( ( void * ) result0 );
52
+	unsigned int i;
53
+	unsigned int j;
54
+	uint32_t multiplicand_element;
55
+	uint32_t multiplier_element;
56
+	uint32_t *result_elements;
57
+	uint32_t discard_low;
58
+	uint32_t discard_high;
59
+	uint32_t discard_temp;
60
+
61
+	/* Zero result */
62
+	memset ( result, 0, sizeof ( *result ) );
63
+
64
+	/* Multiply integers one element at a time */
65
+	for ( i = 0 ; i < size ; i++ ) {
66
+		multiplicand_element = multiplicand->element[i];
67
+		for ( j = 0 ; j < size ; j++ ) {
68
+			multiplier_element = multiplier->element[j];
69
+			result_elements = &result->element[ i + j ];
70
+			/* Perform a single multiply, and add the
71
+			 * resulting double-element into the result,
72
+			 * carrying as necessary.  The carry can
73
+			 * never overflow beyond the end of the
74
+			 * result, since:
75
+			 *
76
+			 *     a < 2^{n}, b < 2^{n} => ab < 2^{2n}
77
+			 */
78
+			__asm__ __volatile__ ( "umull %1, %2, %5, %6\n\t"
79
+					       "ldr %3, [%0]\n\t"
80
+					       "adds %3, %1\n\t"
81
+					       "stmia %0!, {%3}\n\t"
82
+					       "ldr %3, [%0]\n\t"
83
+					       "adcs %3, %2\n\t"
84
+					       "stmia %0!, {%3}\n\t"
85
+					       "bcc 2f\n\t"
86
+					       "\n1:\n\t"
87
+					       "ldr %3, [%0]\n\t"
88
+					       "adcs %3, #0\n\t"
89
+					       "stmia %0!, {%3}\n\t"
90
+					       "bcs 1b\n\t"
91
+					       "\n2:\n\t"
92
+					       : "+l" ( result_elements ),
93
+						 "=l" ( discard_low ),
94
+						 "=l" ( discard_high ),
95
+						 "=l" ( discard_temp ),
96
+						 "+m" ( *result )
97
+					       : "l" ( multiplicand_element ),
98
+						 "l" ( multiplier_element )
99
+					       : "cc" );
100
+		}
101
+	}
102
+}

+ 88
- 0
src/arch/arm/core/arm_io.c Vedi File

@@ -0,0 +1,88 @@
1
+/*
2
+ * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ *
19
+ * You can also choose to distribute this program under the terms of
20
+ * the Unmodified Binary Distribution Licence (as given in the file
21
+ * COPYING.UBDL), provided that you have satisfied its requirements.
22
+ */
23
+
24
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
+
26
+#include <ipxe/io.h>
27
+#include <ipxe/arm_io.h>
28
+
29
+/** @file
30
+ *
31
+ * iPXE I/O API for ARM
32
+ *
33
+ */
34
+
35
+/** An ARM I/O qword */
36
+union arm_io_qword {
37
+	uint64_t qword;
38
+	uint32_t dword[2];
39
+};
40
+
41
+/**
42
+ * Read 64-bit qword from memory-mapped device
43
+ *
44
+ * @v io_addr		I/O address
45
+ * @ret data		Value read
46
+ *
47
+ * This is not atomic for ARM.
48
+ */
49
+static uint64_t arm_readq ( volatile uint64_t *io_addr ) {
50
+	volatile union arm_io_qword *ptr =
51
+		container_of ( io_addr, union arm_io_qword, qword );
52
+	union arm_io_qword tmp;
53
+
54
+	tmp.dword[0] = readl ( &ptr->dword[0] );
55
+	tmp.dword[1] = readl ( &ptr->dword[1] );
56
+	return tmp.qword;
57
+}
58
+
59
+/**
60
+ * Write 64-bit qword to memory-mapped device
61
+ *
62
+ * @v data		Value to write
63
+ * @v io_addr		I/O address
64
+ *
65
+ * This is not atomic for ARM.
66
+ */
67
+static void arm_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
68
+	volatile union arm_io_qword *ptr =
69
+		container_of ( io_addr, union arm_io_qword, qword );
70
+	union arm_io_qword tmp;
71
+
72
+	tmp.qword = data;
73
+	writel ( tmp.dword[0], &ptr->dword[0] );
74
+	writel ( tmp.dword[1], &ptr->dword[1] );
75
+}
76
+
77
+PROVIDE_IOAPI_INLINE ( arm, phys_to_bus );
78
+PROVIDE_IOAPI_INLINE ( arm, bus_to_phys );
79
+PROVIDE_IOAPI_INLINE ( arm, readb );
80
+PROVIDE_IOAPI_INLINE ( arm, readw );
81
+PROVIDE_IOAPI_INLINE ( arm, readl );
82
+PROVIDE_IOAPI_INLINE ( arm, writeb );
83
+PROVIDE_IOAPI_INLINE ( arm, writew );
84
+PROVIDE_IOAPI_INLINE ( arm, writel );
85
+PROVIDE_IOAPI_INLINE ( arm, iodelay );
86
+PROVIDE_IOAPI_INLINE ( arm, mb );
87
+PROVIDE_IOAPI ( arm, readq, arm_readq );
88
+PROVIDE_IOAPI ( arm, writeq, arm_writeq );

+ 32
- 0
src/arch/arm/core/setjmp.S Vedi File

@@ -0,0 +1,32 @@
1
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
2
+
3
+	.text
4
+	.arm
5
+
6
+/*
7
+ * Save stack context for non-local goto
8
+ */
9
+	.globl	setjmp
10
+	.type	setjmp, %function
11
+setjmp:
12
+	/* Store registers */
13
+	stmia	r0, { r4, r5, r6, r7, r8, r9, r10, fp, sp, lr }
14
+	/* Return 0 when returning as setjmp() */
15
+	mov	r0, #0
16
+	bx	lr
17
+	.size	setjmp, . - setjmp
18
+
19
+/*
20
+ * Non-local jump to a saved stack context
21
+ */
22
+	.globl	longjmp
23
+	.type	longjmp, %function
24
+longjmp:
25
+	/* Restore registers */
26
+	ldmia	r0, { r4, r5, r6, r7, r8, r9, r10, fp, sp, lr }
27
+	/* Force result to non-zero */
28
+	movs	r0, r1
29
+	moveq	r0, #1
30
+	/* Return to setjmp() caller */
31
+	bx	lr
32
+	.size	longjmp, . - longjmp

+ 316
- 0
src/arch/arm/include/bits/bigint.h Vedi File

@@ -0,0 +1,316 @@
1
+#ifndef _BITS_BIGINT_H
2
+#define _BITS_BIGINT_H
3
+
4
+/** @file
5
+ *
6
+ * Big integer support
7
+ */
8
+
9
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
10
+
11
+#include <stdint.h>
12
+#include <string.h>
13
+#include <strings.h>
14
+
15
+/** Element of a big integer */
16
+typedef uint32_t bigint_element_t;
17
+
18
+/**
19
+ * Initialise big integer
20
+ *
21
+ * @v value0		Element 0 of big integer to initialise
22
+ * @v size		Number of elements
23
+ * @v data		Raw data
24
+ * @v len		Length of raw data
25
+ */
26
+static inline __attribute__ (( always_inline )) void
27
+bigint_init_raw ( uint32_t *value0, unsigned int size,
28
+		  const void *data, size_t len ) {
29
+	size_t pad_len = ( sizeof ( bigint_t ( size ) ) - len );
30
+	uint8_t *value_byte = ( ( void * ) value0 );
31
+	const uint8_t *data_byte = ( data + len );
32
+
33
+	/* Copy raw data in reverse order, padding with zeros */
34
+	while ( len-- )
35
+		*(value_byte++) = *(--data_byte);
36
+	while ( pad_len-- )
37
+		*(value_byte++) = 0;
38
+}
39
+
40
+/**
41
+ * Add big integers
42
+ *
43
+ * @v addend0		Element 0 of big integer to add
44
+ * @v value0		Element 0 of big integer to be added to
45
+ * @v size		Number of elements
46
+ */
47
+static inline __attribute__ (( always_inline )) void
48
+bigint_add_raw ( const uint32_t *addend0, uint32_t *value0,
49
+		 unsigned int size ) {
50
+	bigint_t ( size ) __attribute__ (( may_alias )) *value =
51
+		( ( void * ) value0 );
52
+	uint32_t *discard_addend;
53
+	uint32_t *discard_value;
54
+	uint32_t *discard_end;
55
+	uint32_t discard_addend_i;
56
+	uint32_t discard_value_i;
57
+
58
+	__asm__ __volatile__ ( "adds %2, %0, %8, lsl #2\n\t" /* clear CF */
59
+			       "\n1:\n\t"
60
+			       "ldmia %0!, {%3}\n\t"
61
+			       "ldr %4, [%1]\n\t"
62
+			       "adcs %4, %3\n\t"
63
+			       "stmia %1!, {%4}\n\t"
64
+			       "teq %0, %2\n\t"
65
+			       "bne 1b\n\t"
66
+			       : "=l" ( discard_addend ),
67
+				 "=l" ( discard_value ),
68
+				 "=l" ( discard_end ),
69
+				 "=l" ( discard_addend_i ),
70
+				 "=l" ( discard_value_i ),
71
+				 "+m" ( *value )
72
+			       : "0" ( addend0 ), "1" ( value0 ), "l" ( size )
73
+			       : "cc" );
74
+}
75
+
76
+/**
77
+ * Subtract big integers
78
+ *
79
+ * @v subtrahend0	Element 0 of big integer to subtract
80
+ * @v value0		Element 0 of big integer to be subtracted from
81
+ * @v size		Number of elements
82
+ */
83
+static inline __attribute__ (( always_inline )) void
84
+bigint_subtract_raw ( const uint32_t *subtrahend0, uint32_t *value0,
85
+		      unsigned int size ) {
86
+	bigint_t ( size ) __attribute__ (( may_alias )) *value =
87
+		( ( void * ) value0 );
88
+	uint32_t *discard_subtrahend;
89
+	uint32_t *discard_value;
90
+	uint32_t *discard_end;
91
+	uint32_t discard_subtrahend_i;
92
+	uint32_t discard_value_i;
93
+
94
+	__asm__ __volatile__ ( "add %2, %0, %8, lsl #2\n\t"
95
+			       "cmp %2, %0\n\t" /* set CF */
96
+			       "\n1:\n\t"
97
+			       "ldmia %0!, {%3}\n\t"
98
+			       "ldr %4, [%1]\n\t"
99
+			       "sbcs %4, %3\n\t"
100
+			       "stmia %1!, {%4}\n\t"
101
+			       "teq %0, %2\n\t"
102
+			       "bne 1b\n\t"
103
+			       : "=l" ( discard_subtrahend ),
104
+				 "=l" ( discard_value ),
105
+				 "=l" ( discard_end ),
106
+				 "=l" ( discard_subtrahend_i ),
107
+				 "=l" ( discard_value_i ),
108
+				 "+m" ( *value )
109
+			       : "0" ( subtrahend0 ), "1" ( value0 ),
110
+				 "l" ( size )
111
+			       : "cc" );
112
+}
113
+
114
+/**
115
+ * Rotate big integer left
116
+ *
117
+ * @v value0		Element 0 of big integer
118
+ * @v size		Number of elements
119
+ */
120
+static inline __attribute__ (( always_inline )) void
121
+bigint_rol_raw ( uint32_t *value0, unsigned int size ) {
122
+	bigint_t ( size ) __attribute__ (( may_alias )) *value =
123
+		( ( void * ) value0 );
124
+	uint32_t *discard_value;
125
+	uint32_t *discard_end;
126
+	uint32_t discard_value_i;
127
+
128
+	__asm__ __volatile__ ( "adds %1, %0, %5, lsl #2\n\t" /* clear CF */
129
+			       "\n1:\n\t"
130
+			       "ldr %2, [%0]\n\t"
131
+			       "adcs %2, %2\n\t"
132
+			       "stmia %0!, {%2}\n\t"
133
+			       "teq %0, %1\n\t"
134
+			       "bne 1b\n\t"
135
+			       : "=l" ( discard_value ),
136
+				 "=l" ( discard_end ),
137
+				 "=l" ( discard_value_i ),
138
+				 "+m" ( *value )
139
+			       : "0" ( value0 ), "1" ( size )
140
+			       : "cc" );
141
+}
142
+
143
+/**
144
+ * Rotate big integer right
145
+ *
146
+ * @v value0		Element 0 of big integer
147
+ * @v size		Number of elements
148
+ */
149
+static inline __attribute__ (( always_inline )) void
150
+bigint_ror_raw ( uint32_t *value0, unsigned int size ) {
151
+	bigint_t ( size ) __attribute__ (( may_alias )) *value =
152
+		( ( void * ) value0 );
153
+	uint32_t *discard_value;
154
+	uint32_t *discard_end;
155
+	uint32_t discard_value_i;
156
+
157
+	__asm__ __volatile__ ( "adds %1, %0, %5, lsl #2\n\t" /* clear CF */
158
+			       "\n1:\n\t"
159
+			       "ldmdb %1!, {%2}\n\t"
160
+			       "rrxs %2, %2\n\t"
161
+			       "str %2, [%1]\n\t"
162
+			       "teq %0, %1\n\t"
163
+			       "bne 1b\n\t"
164
+			       : "=l" ( discard_value ),
165
+				 "=l" ( discard_end ),
166
+				 "=l" ( discard_value_i ),
167
+				 "+m" ( *value )
168
+			       : "0" ( value0 ), "1" ( size )
169
+			       : "cc" );
170
+}
171
+
172
+/**
173
+ * Test if big integer is equal to zero
174
+ *
175
+ * @v value0		Element 0 of big integer
176
+ * @v size		Number of elements
177
+ * @ret is_zero		Big integer is equal to zero
178
+ */
179
+static inline __attribute__ (( always_inline, pure )) int
180
+bigint_is_zero_raw ( const uint32_t *value0, unsigned int size ) {
181
+	const uint32_t *value = value0;
182
+	uint32_t value_i;
183
+
184
+	do {
185
+		value_i = *(value++);
186
+		if ( value_i )
187
+			break;
188
+	} while ( --size );
189
+
190
+	return ( value_i == 0 );
191
+}
192
+
193
+/**
194
+ * Compare big integers
195
+ *
196
+ * @v value0		Element 0 of big integer
197
+ * @v reference0	Element 0 of reference big integer
198
+ * @v size		Number of elements
199
+ * @ret geq		Big integer is greater than or equal to the reference
200
+ */
201
+static inline __attribute__ (( always_inline, pure )) int
202
+bigint_is_geq_raw ( const uint32_t *value0, const uint32_t *reference0,
203
+		    unsigned int size ) {
204
+	const uint32_t *value = ( value0 + size );
205
+	const uint32_t *reference = ( reference0 + size );
206
+	uint32_t value_i;
207
+	uint32_t reference_i;
208
+
209
+	do {
210
+		value_i = *(--value);
211
+		reference_i = *(--reference);
212
+		if ( value_i != reference_i )
213
+			break;
214
+	} while ( --size );
215
+
216
+	return ( value_i >= reference_i );
217
+}
218
+
219
+/**
220
+ * Test if bit is set in big integer
221
+ *
222
+ * @v value0		Element 0 of big integer
223
+ * @v size		Number of elements
224
+ * @v bit		Bit to test
225
+ * @ret is_set		Bit is set
226
+ */
227
+static inline __attribute__ (( always_inline )) int
228
+bigint_bit_is_set_raw ( const uint32_t *value0, unsigned int size,
229
+			unsigned int bit ) {
230
+	const bigint_t ( size ) __attribute__ (( may_alias )) *value =
231
+		( ( const void * ) value0 );
232
+	unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) );
233
+	unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) );
234
+
235
+	return ( value->element[index] & ( 1 << subindex ) );
236
+}
237
+
238
+/**
239
+ * Find highest bit set in big integer
240
+ *
241
+ * @v value0		Element 0 of big integer
242
+ * @v size		Number of elements
243
+ * @ret max_bit		Highest bit set + 1 (or 0 if no bits set)
244
+ */
245
+static inline __attribute__ (( always_inline )) int
246
+bigint_max_set_bit_raw ( const uint32_t *value0, unsigned int size ) {
247
+	const uint32_t *value = ( value0 + size );
248
+	int max_bit = ( 8 * sizeof ( bigint_t ( size ) ) );
249
+	uint32_t value_i;
250
+
251
+	do {
252
+		value_i = *(--value);
253
+		max_bit -= ( 32 - fls ( value_i ) );
254
+		if ( value_i )
255
+			break;
256
+	} while ( --size );
257
+
258
+	return max_bit;
259
+}
260
+
261
+/**
262
+ * Grow big integer
263
+ *
264
+ * @v source0		Element 0 of source big integer
265
+ * @v source_size	Number of elements in source big integer
266
+ * @v dest0		Element 0 of destination big integer
267
+ * @v dest_size		Number of elements in destination big integer
268
+ */
269
+static inline __attribute__ (( always_inline )) void
270
+bigint_grow_raw ( const uint32_t *source0, unsigned int source_size,
271
+		  uint32_t *dest0, unsigned int dest_size ) {
272
+	unsigned int pad_size = ( dest_size - source_size );
273
+
274
+	memcpy ( dest0, source0, sizeof ( bigint_t ( source_size ) ) );
275
+	memset ( ( dest0 + source_size ), 0, sizeof ( bigint_t ( pad_size ) ) );
276
+}
277
+
278
+/**
279
+ * Shrink big integer
280
+ *
281
+ * @v source0		Element 0 of source big integer
282
+ * @v source_size	Number of elements in source big integer
283
+ * @v dest0		Element 0 of destination big integer
284
+ * @v dest_size		Number of elements in destination big integer
285
+ */
286
+static inline __attribute__ (( always_inline )) void
287
+bigint_shrink_raw ( const uint32_t *source0, unsigned int source_size __unused,
288
+		    uint32_t *dest0, unsigned int dest_size ) {
289
+
290
+	memcpy ( dest0, source0, sizeof ( bigint_t ( dest_size ) ) );
291
+}
292
+
293
+/**
294
+ * Finalise big integer
295
+ *
296
+ * @v value0		Element 0 of big integer to finalise
297
+ * @v size		Number of elements
298
+ * @v out		Output buffer
299
+ * @v len		Length of output buffer
300
+ */
301
+static inline __attribute__ (( always_inline )) void
302
+bigint_done_raw ( const uint32_t *value0, unsigned int size __unused,
303
+		  void *out, size_t len ) {
304
+	const uint8_t *value_byte = ( ( const void * ) value0 );
305
+	uint8_t *out_byte = ( out + len );
306
+
307
+	/* Copy raw data in reverse order */
308
+	while ( len-- )
309
+		*(--out_byte) = *(value_byte++);
310
+}
311
+
312
+extern void bigint_multiply_raw ( const uint32_t *multiplicand0,
313
+				  const uint32_t *multiplier0,
314
+				  uint32_t *value0, unsigned int size );
315
+
316
+#endif /* _BITS_BIGINT_H */

+ 100
- 0
src/arch/arm/include/bits/bitops.h Vedi File

@@ -0,0 +1,100 @@
1
+#ifndef _BITS_BITOPS_H
2
+#define _BITS_BITOPS_H
3
+
4
+/** @file
5
+ *
6
+ * ARM bit operations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#include <stdint.h>
13
+
14
+/**
15
+ * Test and set bit atomically
16
+ *
17
+ * @v bit		Bit to set
18
+ * @v bits		Bit field
19
+ * @ret old		Old value of bit (zero or non-zero)
20
+ */
21
+static inline __attribute__ (( always_inline )) int
22
+test_and_set_bit ( unsigned int bit, volatile void *bits ) {
23
+	unsigned int index = ( bit / 32 );
24
+	unsigned int offset = ( bit % 32 );
25
+	volatile uint32_t *dword = ( ( ( volatile uint32_t * ) bits ) + index );
26
+	uint32_t mask = ( 1UL << offset );
27
+	uint32_t old;
28
+	uint32_t new;
29
+	uint32_t flag;
30
+
31
+	__asm__ __volatile__ ( "\n1:\n\t"
32
+			       "ldrex %0, %3\n\t"
33
+			       "orr %1, %0, %4\n\t"
34
+			       "strex %2, %1, %3\n\t"
35
+			       "tst %2, %2\n\t"
36
+			       "bne 1b\n\t"
37
+			       : "=&r" ( old ), "=&r" ( new ), "=&l" ( flag ),
38
+				 "+Q" ( *dword )
39
+			       : "r" ( mask )
40
+			       : "cc" );
41
+
42
+	return ( old & mask );
43
+}
44
+
45
+/**
46
+ * Test and clear bit atomically
47
+ *
48
+ * @v bit		Bit to set
49
+ * @v bits		Bit field
50
+ * @ret old		Old value of bit (zero or non-zero)
51
+ */
52
+static inline __attribute__ (( always_inline )) int
53
+test_and_clear_bit ( unsigned int bit, volatile void *bits ) {
54
+	unsigned int index = ( bit / 32 );
55
+	unsigned int offset = ( bit % 32 );
56
+	volatile uint32_t *dword = ( ( ( volatile uint32_t * ) bits ) + index );
57
+	uint32_t mask = ( 1UL << offset );
58
+	uint32_t old;
59
+	uint32_t new;
60
+	uint32_t flag;
61
+
62
+	__asm__ __volatile__ ( "\n1:\n\t"
63
+			       "ldrex %0, %3\n\t"
64
+			       "bic %1, %0, %4\n\t"
65
+			       "strex %2, %1, %3\n\t"
66
+			       "tst %2, %2\n\t"
67
+			       "bne 1b\n\t"
68
+			       : "=&r" ( old ), "=&r" ( new ), "=&l" ( flag ),
69
+				 "+Q" ( *dword )
70
+			       : "r" ( mask )
71
+			       : "cc" );
72
+
73
+	return ( old & mask );
74
+}
75
+
76
+/**
77
+ * Set bit atomically
78
+ *
79
+ * @v bit		Bit to set
80
+ * @v bits		Bit field
81
+ */
82
+static inline __attribute__ (( always_inline )) void
83
+set_bit ( unsigned int bit, volatile void *bits ) {
84
+
85
+	test_and_set_bit ( bit, bits );
86
+}
87
+
88
+/**
89
+ * Clear bit atomically
90
+ *
91
+ * @v bit		Bit to set
92
+ * @v bits		Bit field
93
+ */
94
+static inline __attribute__ (( always_inline )) void
95
+clear_bit ( unsigned int bit, volatile void *bits ) {
96
+
97
+	test_and_clear_bit ( bit, bits );
98
+}
99
+
100
+#endif /* _BITS_BITOPS_H */

+ 52
- 0
src/arch/arm/include/bits/byteswap.h Vedi File

@@ -0,0 +1,52 @@
1
+#ifndef _BITS_BYTESWAP_H
2
+#define _BITS_BYTESWAP_H
3
+
4
+/** @file
5
+ *
6
+ * Byte-order swapping functions
7
+ *
8
+ */
9
+
10
+#include <stdint.h>
11
+
12
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13
+
14
+static inline __attribute__ (( always_inline, const )) uint16_t
15
+__bswap_variable_16 ( uint16_t x ) {
16
+	__asm__ ( "rev16 %0, %1" : "=l" ( x ) : "l" ( x ) );
17
+	return x;
18
+}
19
+
20
+static inline __attribute__ (( always_inline )) void
21
+__bswap_16s ( uint16_t *x ) {
22
+	*x = __bswap_variable_16 ( *x );
23
+}
24
+
25
+static inline __attribute__ (( always_inline, const )) uint32_t
26
+__bswap_variable_32 ( uint32_t x ) {
27
+	__asm__ ( "rev %0, %1" : "=l" ( x ) : "l" ( x ) );
28
+	return x;
29
+}
30
+
31
+static inline __attribute__ (( always_inline )) void
32
+__bswap_32s ( uint32_t *x ) {
33
+	*x = __bswap_variable_32 ( *x );
34
+}
35
+
36
+static inline __attribute__ (( always_inline, const )) uint64_t
37
+__bswap_variable_64 ( uint64_t x ) {
38
+	uint32_t in_high = ( x >> 32 );
39
+	uint32_t in_low = ( x & 0xffffffffUL );
40
+	uint32_t out_high = __bswap_variable_32 ( in_low );
41
+	uint32_t out_low = __bswap_variable_32 ( in_high );
42
+
43
+	return ( ( ( ( uint64_t ) out_high ) << 32 ) |
44
+		 ( ( uint64_t ) out_low ) );
45
+}
46
+
47
+static inline __attribute__ (( always_inline )) void
48
+__bswap_64s ( uint64_t *x ) {
49
+	*x = __bswap_variable_64 ( *x );
50
+}
51
+
52
+#endif

+ 16
- 0
src/arch/arm/include/bits/compiler.h Vedi File

@@ -0,0 +1,16 @@
1
+#ifndef _BITS_COMPILER_H
2
+#define _BITS_COMPILER_H
3
+
4
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
+
6
+/** Dummy relocation type */
7
+#define RELOC_TYPE_NONE R_ARM_NONE
8
+
9
+#ifndef ASSEMBLY
10
+
11
+#define __asmcall
12
+#define __libgcc
13
+
14
+#endif /* ASSEMBLY */
15
+
16
+#endif /*_BITS_COMPILER_H */

+ 13
- 0
src/arch/arm/include/bits/endian.h Vedi File

@@ -0,0 +1,13 @@
1
+#ifndef _BITS_ENDIAN_H
2
+#define _BITS_ENDIAN_H
3
+
4
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
+
6
+/* ARM may be either little-endian or big-endian */
7
+#ifdef __ARM_BIG_ENDIAN
8
+#define __BYTE_ORDER __BIG_ENDIAN
9
+#else
10
+#define __BYTE_ORDER __LITTLE_ENDIAN
11
+#endif
12
+
13
+#endif /* _BITS_ENDIAN_H */

+ 12
- 0
src/arch/arm/include/bits/entropy.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_ENTROPY_H
2
+#define _BITS_ENTROPY_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific entropy API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_ENTROPY_H */

+ 19
- 0
src/arch/arm/include/bits/errfile.h Vedi File

@@ -0,0 +1,19 @@
1
+#ifndef _BITS_ERRFILE_H
2
+#define _BITS_ERRFILE_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific error file identifiers
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+/**
13
+ * @addtogroup errfile Error file identifiers
14
+ * @{
15
+ */
16
+
17
+/** @} */
18
+
19
+#endif /* _BITS_ERRFILE_H */

+ 12
- 0
src/arch/arm/include/bits/hyperv.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_HYPERV_H
2
+#define _BITS_HYPERV_H
3
+
4
+/** @file
5
+ *
6
+ * Hyper-V interface
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_HYPERV_H */

+ 14
- 0
src/arch/arm/include/bits/io.h Vedi File

@@ -0,0 +1,14 @@
1
+#ifndef _BITS_IO_H
2
+#define _BITS_IO_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific I/O API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#include <ipxe/arm_io.h>
13
+
14
+#endif /* _BITS_IO_H */

+ 12
- 0
src/arch/arm/include/bits/iomap.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_IOMAP_H
2
+#define _BITS_IOMAP_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific I/O mapping API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_IOMAP_H */

+ 14
- 0
src/arch/arm/include/bits/nap.h Vedi File

@@ -0,0 +1,14 @@
1
+#ifndef _BITS_NAP_H
2
+#define _BITS_NAP_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific CPU sleeping API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#include <ipxe/efi/efiarm_nap.h>
13
+
14
+#endif /* _BITS_MAP_H */

+ 14
- 0
src/arch/arm/include/bits/pci_io.h Vedi File

@@ -0,0 +1,14 @@
1
+#ifndef _BITS_PCI_IO_H
2
+#define _BITS_PCI_IO_H
3
+
4
+/** @file
5
+ *
6
+ * ARM PCI I/O API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#include <ipxe/io.h>
13
+
14
+#endif /* _BITS_PCI_IO_H */

+ 30
- 0
src/arch/arm/include/bits/profile.h Vedi File

@@ -0,0 +1,30 @@
1
+#ifndef _BITS_PROFILE_H
2
+#define _BITS_PROFILE_H
3
+
4
+/** @file
5
+ *
6
+ * Profiling
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#include <stdint.h>
13
+
14
+/**
15
+ * Get profiling timestamp
16
+ *
17
+ * @ret timestamp	Timestamp
18
+ */
19
+static inline __attribute__ (( always_inline )) uint64_t
20
+profile_timestamp ( void ) {
21
+	uint32_t cycles;
22
+
23
+	/* Read cycle counter */
24
+	__asm__ __volatile__ ( "mcr p15, 0, %1, c9, c12, 0\n\t"
25
+			       "mrc p15, 0, %0, c9, c13, 0\n\t"
26
+			       : "=r" ( cycles ) : "r" ( 1 ) );
27
+	return cycles;
28
+}
29
+
30
+#endif /* _BITS_PROFILE_H */

+ 12
- 0
src/arch/arm/include/bits/reboot.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_REBOOT_H
2
+#define _BITS_REBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific reboot API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_REBOOT_H */

+ 12
- 0
src/arch/arm/include/bits/sanboot.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_SANBOOT_H
2
+#define _BITS_SANBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific sanboot API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_SANBOOT_H */

+ 12
- 0
src/arch/arm/include/bits/smbios.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_SMBIOS_H
2
+#define _BITS_SMBIOS_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific SMBIOS API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_SMBIOS_H */

+ 23
- 0
src/arch/arm/include/bits/stdint.h Vedi File

@@ -0,0 +1,23 @@
1
+#ifndef _BITS_STDINT_H
2
+#define _BITS_STDINT_H
3
+
4
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
+
6
+typedef __SIZE_TYPE__		size_t;
7
+typedef signed long		ssize_t;
8
+typedef signed long		off_t;
9
+
10
+typedef unsigned char		uint8_t;
11
+typedef unsigned short		uint16_t;
12
+typedef unsigned int		uint32_t;
13
+typedef unsigned long long	uint64_t;
14
+
15
+typedef signed char		int8_t;
16
+typedef signed short		int16_t;
17
+typedef signed int		int32_t;
18
+typedef signed long long	int64_t;
19
+
20
+typedef unsigned long		physaddr_t;
21
+typedef unsigned long		intptr_t;
22
+
23
+#endif /* _BITS_STDINT_H */

+ 60
- 0
src/arch/arm/include/bits/string.h Vedi File

@@ -0,0 +1,60 @@
1
+#ifndef BITS_STRING_H
2
+#define BITS_STRING_H
3
+
4
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
+
6
+/** @file
7
+ *
8
+ * String functions
9
+ *
10
+ */
11
+
12
+/**
13
+ * Fill memory region
14
+ *
15
+ * @v dest		Destination region
16
+ * @v character		Fill character
17
+ * @v len		Length
18
+ * @ret dest		Destination region
19
+ */
20
+static inline __attribute__ (( always_inline )) void *
21
+memset ( void *dest, int character, size_t len ) {
22
+
23
+	/* Not yet optimised */
24
+	generic_memset ( dest, character, len );
25
+	return dest;
26
+}
27
+
28
+/**
29
+ * Copy memory region
30
+ *
31
+ * @v dest		Destination region
32
+ * @v src		Source region
33
+ * @v len		Length
34
+ * @ret dest		Destination region
35
+ */
36
+static inline __attribute__ (( always_inline )) void *
37
+memcpy ( void *dest, const void *src, size_t len ) {
38
+
39
+	/* Not yet optimised */
40
+	generic_memcpy ( dest, src, len );
41
+	return dest;
42
+}
43
+
44
+/**
45
+ * Copy (possibly overlapping) memory region
46
+ *
47
+ * @v dest		Destination region
48
+ * @v src		Source region
49
+ * @v len		Length
50
+ * @ret dest		Destination region
51
+ */
52
+static inline __attribute__ (( always_inline )) void *
53
+memmove ( void *dest, const void *src, size_t len ) {
54
+
55
+	/* Not yet optimised */
56
+	generic_memmove ( dest, src, len );
57
+	return dest;
58
+}
59
+
60
+#endif /* BITS_STRING_H */

+ 85
- 0
src/arch/arm/include/bits/strings.h Vedi File

@@ -0,0 +1,85 @@
1
+#ifndef _BITS_STRINGS_H
2
+#define _BITS_STRINGS_H
3
+
4
+/** @file
5
+ *
6
+ * String functions
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+/**
13
+ * Find first (i.e. least significant) set bit
14
+ *
15
+ * @v value		Value
16
+ * @ret lsb		Least significant bit set in value (LSB=1), or zero
17
+ */
18
+static inline __attribute__ (( always_inline )) int __ffsl ( long value ) {
19
+	unsigned long bits = value;
20
+	unsigned long lsb;
21
+	unsigned int lz;
22
+
23
+	/* Extract least significant set bit */
24
+	lsb = ( bits & -bits );
25
+
26
+	/* Count number of leading zeroes before LSB */
27
+	__asm__ ( "clz %0, %1" : "=r" ( lz ) : "r" ( lsb ) );
28
+
29
+	return ( 32 - lz );
30
+}
31
+
32
+/**
33
+ * Find first (i.e. least significant) set bit
34
+ *
35
+ * @v value		Value
36
+ * @ret lsb		Least significant bit set in value (LSB=1), or zero
37
+ */
38
+static inline __attribute__ (( always_inline )) int __ffsll ( long long value ){
39
+	unsigned long high = ( value >> 32 );
40
+	unsigned long low = ( value >> 0 );
41
+
42
+	if ( low ) {
43
+		return ( __ffsl ( low ) );
44
+	} else if ( high ) {
45
+		return ( 32 + __ffsl ( high ) );
46
+	} else {
47
+		return 0;
48
+	}
49
+}
50
+
51
+/**
52
+ * Find last (i.e. most significant) set bit
53
+ *
54
+ * @v value		Value
55
+ * @ret msb		Most significant bit set in value (LSB=1), or zero
56
+ */
57
+static inline __attribute__ (( always_inline )) int __flsl ( long value ) {
58
+	unsigned int lz;
59
+
60
+	/* Count number of leading zeroes */
61
+	__asm__ ( "clz %0, %1" : "=r" ( lz ) : "r" ( value ) );
62
+
63
+	return ( 32 - lz );
64
+}
65
+
66
+/**
67
+ * Find last (i.e. most significant) set bit
68
+ *
69
+ * @v value		Value
70
+ * @ret msb		Most significant bit set in value (LSB=1), or zero
71
+ */
72
+static inline __attribute__ (( always_inline )) int __flsll ( long long value ){
73
+	unsigned long high = ( value >> 32 );
74
+	unsigned long low = ( value >> 0 );
75
+
76
+	if ( high ) {
77
+		return ( 32 + __flsl ( high ) );
78
+	} else if ( low ) {
79
+		return ( __flsl ( low ) );
80
+	} else {
81
+		return 0;
82
+	}
83
+}
84
+
85
+#endif /* _BITS_STRINGS_H */

+ 19
- 0
src/arch/arm/include/bits/tcpip.h Vedi File

@@ -0,0 +1,19 @@
1
+#ifndef _BITS_TCPIP_H
2
+#define _BITS_TCPIP_H
3
+
4
+/** @file
5
+ *
6
+ * Transport-network layer interface
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+static inline __attribute__ (( always_inline )) uint16_t
13
+tcpip_continue_chksum ( uint16_t partial, const void *data, size_t len ) {
14
+
15
+	/* Not yet optimised */
16
+	return generic_tcpip_continue_chksum ( partial, data, len );
17
+}
18
+
19
+#endif /* _BITS_TCPIP_H */

+ 12
- 0
src/arch/arm/include/bits/time.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_TIME_H
2
+#define _BITS_TIME_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific time API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_TIME_H */

+ 12
- 0
src/arch/arm/include/bits/timer.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_TIMER_H
2
+#define _BITS_TIMER_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific timer API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_TIMER_H */

+ 12
- 0
src/arch/arm/include/bits/uaccess.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_UACCESS_H
2
+#define _BITS_UACCESS_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific user access API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_UACCESS_H */

+ 12
- 0
src/arch/arm/include/bits/uart.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_UART_H
2
+#define _BITS_UART_H
3
+
4
+/** @file
5
+ *
6
+ * 16550-compatible UART
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_UART_H */

+ 12
- 0
src/arch/arm/include/bits/umalloc.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_UMALLOC_H
2
+#define _BITS_UMALLOC_H
3
+
4
+/** @file
5
+ *
6
+ * ARM-specific user memory allocation API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_UMALLOC_H */

+ 149
- 0
src/arch/arm/include/bits/xen.h Vedi File

@@ -0,0 +1,149 @@
1
+#ifndef _BITS_XEN_H
2
+#define _BITS_XEN_H
3
+
4
+/** @file
5
+ *
6
+ * Xen interface
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+/* Hypercall registers */
13
+#define XEN_HC "r12"
14
+#define XEN_REG1 "r0"
15
+#define XEN_REG2 "r1"
16
+#define XEN_REG3 "r2"
17
+#define XEN_REG4 "r3"
18
+#define XEN_REG5 "r4"
19
+
20
+/**
21
+ * Issue hypercall with one argument
22
+ *
23
+ * @v xen		Xen hypervisor
24
+ * @v hypercall		Hypercall number
25
+ * @v arg1		First argument
26
+ * @ret retval		Return value
27
+ */
28
+static inline __attribute__ (( always_inline )) unsigned long
29
+xen_hypercall_1 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
30
+		  unsigned long arg1 ) {
31
+	register unsigned long hc asm ( XEN_HC ) = hypercall;
32
+	register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
33
+
34
+	__asm__ __volatile__ ( "hvc %1"
35
+			       : "+r" ( reg1 )
36
+			       : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
37
+			       : "memory", "cc" );
38
+	return reg1;
39
+}
40
+
41
+/**
42
+ * Issue hypercall with two arguments
43
+ *
44
+ * @v xen		Xen hypervisor
45
+ * @v hypercall		Hypercall number
46
+ * @v arg1		First argument
47
+ * @v arg2		Second argument
48
+ * @ret retval		Return value
49
+ */
50
+static inline __attribute__ (( always_inline )) unsigned long
51
+xen_hypercall_2 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
52
+		  unsigned long arg1, unsigned long arg2 ) {
53
+	register unsigned long hc asm ( XEN_HC ) = hypercall;
54
+	register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
55
+	register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
56
+
57
+	__asm__ __volatile__ ( "hvc %2"
58
+			       : "+r" ( reg1 ), "+r" ( reg2 )
59
+			       : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
60
+			       : "memory", "cc" );
61
+	return reg1;
62
+}
63
+
64
+/**
65
+ * Issue hypercall with three arguments
66
+ *
67
+ * @v xen		Xen hypervisor
68
+ * @v hypercall		Hypercall number
69
+ * @v arg1		First argument
70
+ * @v arg2		Second argument
71
+ * @v arg3		Third argument
72
+ * @ret retval		Return value
73
+ */
74
+static inline __attribute__ (( always_inline )) unsigned long
75
+xen_hypercall_3 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
76
+		  unsigned long arg1, unsigned long arg2, unsigned long arg3 ) {
77
+	register unsigned long hc asm ( XEN_HC ) = hypercall;
78
+	register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
79
+	register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
80
+	register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
81
+
82
+	__asm__ __volatile__ ( "hvc %3"
83
+			       : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 )
84
+			       : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
85
+			       : "memory", "cc" );
86
+	return reg1;
87
+}
88
+
89
+/**
90
+ * Issue hypercall with four arguments
91
+ *
92
+ * @v xen		Xen hypervisor
93
+ * @v hypercall		Hypercall number
94
+ * @v arg1		First argument
95
+ * @v arg2		Second argument
96
+ * @v arg3		Third argument
97
+ * @v arg4		Fourth argument
98
+ * @ret retval		Return value
99
+ */
100
+static inline __attribute__ (( always_inline )) unsigned long
101
+xen_hypercall_4 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
102
+		  unsigned long arg1, unsigned long arg2, unsigned long arg3,
103
+		  unsigned long arg4 ) {
104
+	register unsigned long hc asm ( XEN_HC ) = hypercall;
105
+	register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
106
+	register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
107
+	register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
108
+	register unsigned long reg4 asm ( XEN_REG4 ) = arg4;
109
+
110
+	__asm__ __volatile__ ( "hvc %4"
111
+			       : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 ),
112
+				 "+r" ( reg4 )
113
+			       : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
114
+			       : "memory", "cc" );
115
+	return reg1;
116
+}
117
+
118
+/**
119
+ * Issue hypercall with five arguments
120
+ *
121
+ * @v xen		Xen hypervisor
122
+ * @v hypercall		Hypercall number
123
+ * @v arg1		First argument
124
+ * @v arg2		Second argument
125
+ * @v arg3		Third argument
126
+ * @v arg4		Fourth argument
127
+ * @v arg5		Fifth argument
128
+ * @ret retval		Return value
129
+ */
130
+static inline __attribute__ (( always_inline )) unsigned long
131
+xen_hypercall_5 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
132
+		  unsigned long arg1, unsigned long arg2, unsigned long arg3,
133
+		  unsigned long arg4, unsigned long arg5 ) {
134
+	register unsigned long hc asm ( XEN_HC ) = hypercall;
135
+	register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
136
+	register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
137
+	register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
138
+	register unsigned long reg4 asm ( XEN_REG4 ) = arg4;
139
+	register unsigned long reg5 asm ( XEN_REG5 ) = arg5;
140
+
141
+	__asm__ __volatile__ ( "hvc %5"
142
+			       : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 ),
143
+				 "+r" ( reg4 ), "+r" ( reg5 )
144
+			       : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
145
+			       : "memory", "cc" );
146
+	return reg1;
147
+}
148
+
149
+#endif /* _BITS_XEN_H */

+ 46
- 0
src/arch/arm/include/efi/ipxe/dhcp_arch.h Vedi File

@@ -0,0 +1,46 @@
1
+/*
2
+ * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ *
19
+ * You can also choose to distribute this program under the terms of
20
+ * the Unmodified Binary Distribution Licence (as given in the file
21
+ * COPYING.UBDL), provided that you have satisfied its requirements.
22
+ */
23
+
24
+#ifndef _DHCP_ARCH_H
25
+#define _DHCP_ARCH_H
26
+
27
+/** @file
28
+ *
29
+ * Architecture-specific DHCP options
30
+ */
31
+
32
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
33
+
34
+#include <ipxe/dhcp.h>
35
+
36
+#define DHCP_ARCH_VENDOR_CLASS_ID \
37
+	DHCP_STRING ( 'P', 'X', 'E', 'C', 'l', 'i', 'e', 'n', 't', ':',      \
38
+		      'A', 'r', 'c', 'h', ':', '0', '0', '0', '0', '7', ':', \
39
+		      'U', 'N', 'D', 'I', ':', '0', '0', '3', '0', '1', '0' )
40
+
41
+#define DHCP_ARCH_CLIENT_ARCHITECTURE \
42
+	DHCP_WORD ( DHCP_CLIENT_ARCHITECTURE_EFI )
43
+
44
+#define DHCP_ARCH_CLIENT_NDI DHCP_OPTION ( 1 /* UNDI */ , 3, 10 /* v3.10 */ )
45
+
46
+#endif

+ 45
- 0
src/arch/arm/include/gdbmach.h Vedi File

@@ -0,0 +1,45 @@
1
+#ifndef GDBMACH_H
2
+#define GDBMACH_H
3
+
4
+/** @file
5
+ *
6
+ * GDB architecture specifics
7
+ *
8
+ * This file declares functions for manipulating the machine state and
9
+ * debugging context.
10
+ *
11
+ */
12
+
13
+#include <stdint.h>
14
+
15
+typedef unsigned long gdbreg_t;
16
+
17
+/* Register snapshot */
18
+enum {
19
+	/* Not yet implemented */
20
+	GDBMACH_NREGS,
21
+};
22
+
23
+#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) )
24
+
25
+static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) {
26
+	/* Not yet implemented */
27
+	( void ) regs;
28
+	( void ) pc;
29
+}
30
+
31
+static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) {
32
+	/* Not yet implemented */
33
+	( void ) regs;
34
+	( void ) step;
35
+}
36
+
37
+static inline void gdbmach_breakpoint ( void ) {
38
+	/* Not yet implemented */
39
+}
40
+
41
+extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len,
42
+				    int enable );
43
+extern void gdbmach_init ( void );
44
+
45
+#endif /* GDBMACH_H */

+ 89
- 0
src/arch/arm/include/ipxe/arm_io.h Vedi File

@@ -0,0 +1,89 @@
1
+#ifndef _IPXE_ARM_IO_H
2
+#define _IPXE_ARM_IO_H
3
+
4
+/** @file
5
+ *
6
+ * iPXE I/O API for ARM
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#ifdef IOAPI_ARM
13
+#define IOAPI_PREFIX_arm
14
+#else
15
+#define IOAPI_PREFIX_arm __arm_
16
+#endif
17
+
18
+/*
19
+ * Memory space mappings
20
+ *
21
+ */
22
+
23
+/** Page shift */
24
+#define PAGE_SHIFT 12
25
+
26
+/*
27
+ * Physical<->Bus address mappings
28
+ *
29
+ */
30
+
31
+static inline __always_inline unsigned long
32
+IOAPI_INLINE ( arm, phys_to_bus ) ( unsigned long phys_addr ) {
33
+	return phys_addr;
34
+}
35
+
36
+static inline __always_inline unsigned long
37
+IOAPI_INLINE ( arm, bus_to_phys ) ( unsigned long bus_addr ) {
38
+	return bus_addr;
39
+}
40
+
41
+/*
42
+ * MMIO reads and writes up to native word size
43
+ *
44
+ */
45
+
46
+#define ARM_READX( _api_func, _type, _insn_suffix )			      \
47
+static inline __always_inline _type					      \
48
+IOAPI_INLINE ( arm, _api_func ) ( volatile _type *io_addr ) {		      \
49
+	_type data;							      \
50
+	__asm__ __volatile__ ( "ldr" _insn_suffix " %0, %1"		      \
51
+			       : "=r" ( data ) : "Qo" ( *io_addr ) );	      \
52
+	return data;							      \
53
+}
54
+ARM_READX ( readb, uint8_t, "b" );
55
+ARM_READX ( readw, uint16_t, "h" );
56
+ARM_READX ( readl, uint32_t, "" );
57
+
58
+#define ARM_WRITEX( _api_func, _type, _insn_suffix )			      \
59
+static inline __always_inline void					      \
60
+IOAPI_INLINE ( arm, _api_func ) ( _type data,				      \
61
+				  volatile _type *io_addr ) {		      \
62
+	__asm__ __volatile__ ( "str" _insn_suffix " %0, %1"		      \
63
+			       : : "r" ( data ), "Qo" ( *io_addr ) );	      \
64
+}
65
+ARM_WRITEX ( writeb, uint8_t, "b" );
66
+ARM_WRITEX ( writew, uint16_t, "h" );
67
+ARM_WRITEX ( writel, uint32_t, "" );
68
+
69
+/*
70
+ * Slow down I/O
71
+ *
72
+ */
73
+
74
+static inline __always_inline void
75
+IOAPI_INLINE ( arm, iodelay ) ( void ) {
76
+	/* Nothing to do */
77
+}
78
+
79
+/*
80
+ * Memory barrier
81
+ *
82
+ */
83
+
84
+static inline __always_inline void
85
+IOAPI_INLINE ( arm, mb ) ( void ) {
86
+	__asm__ __volatile__ ( "dmb" );
87
+}
88
+
89
+#endif /* _IPXE_ARM_IO_H */

+ 18
- 0
src/arch/arm/include/ipxe/efi/efiarm_nap.h Vedi File

@@ -0,0 +1,18 @@
1
+#ifndef _IPXE_EFIARM_NAP_H
2
+#define _IPXE_EFIARM_NAP_H
3
+
4
+/** @file
5
+ *
6
+ * EFI CPU sleeping
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#ifdef NAP_EFIARM
13
+#define NAP_PREFIX_efiarm
14
+#else
15
+#define NAP_PREFIX_efiarm __efiarm_
16
+#endif
17
+
18
+#endif /* _IPXE_EFIARM_NAP_H */

+ 61
- 0
src/arch/arm/include/limits.h Vedi File

@@ -0,0 +1,61 @@
1
+#ifndef LIMITS_H
2
+#define LIMITS_H	1
3
+
4
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
+
6
+/* Number of bits in a `char' */
7
+#define CHAR_BIT	8
8
+
9
+/* Minimum and maximum values a `signed char' can hold */
10
+#define SCHAR_MIN	(-128)
11
+#define SCHAR_MAX	127
12
+
13
+/* Maximum value an `unsigned char' can hold. (Minimum is 0.) */
14
+#define UCHAR_MAX	255
15
+
16
+/* Minimum and maximum values a `char' can hold */
17
+#define CHAR_MIN	SCHAR_MIN
18
+#define CHAR_MAX	SCHAR_MAX
19
+
20
+/* Minimum and maximum values a `signed short int' can hold */
21
+#define SHRT_MIN	(-32768)
22
+#define SHRT_MAX	32767
23
+
24
+/* Maximum value an `unsigned short' can hold. (Minimum is 0.) */
25
+#define USHRT_MAX	65535
26
+
27
+
28
+/* Minimum and maximum values a `signed int' can hold */
29
+#define INT_MIN		(-INT_MAX - 1)
30
+#define INT_MAX		2147483647
31
+
32
+/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
33
+#define UINT_MAX	4294967295U
34
+
35
+
36
+/* Minimum and maximum values a `signed int' can hold */
37
+#define INT_MAX		2147483647
38
+#define INT_MIN		(-INT_MAX - 1)
39
+
40
+
41
+/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
42
+#define UINT_MAX	4294967295U
43
+
44
+
45
+/* Minimum and maximum values a `signed long' can hold */
46
+#define LONG_MAX	2147483647
47
+#define LONG_MIN	(-LONG_MAX - 1L)
48
+
49
+/* Maximum value an `unsigned long' can hold. (Minimum is 0.) */
50
+#define ULONG_MAX	4294967295UL
51
+
52
+/* Minimum and maximum values a `signed long long' can hold */
53
+#define LLONG_MAX	9223372036854775807LL
54
+#define LLONG_MIN	(-LONG_MAX - 1LL)
55
+
56
+
57
+/* Maximum value an `unsigned long long' can hold. (Minimum is 0.) */
58
+#define ULLONG_MAX	18446744073709551615ULL
59
+
60
+
61
+#endif /* LIMITS_H */

+ 38
- 0
src/arch/arm/include/setjmp.h Vedi File

@@ -0,0 +1,38 @@
1
+#ifndef _SETJMP_H
2
+#define _SETJMP_H
3
+
4
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5
+
6
+#include <stdint.h>
7
+
8
+/** A jump buffer */
9
+typedef struct {
10
+	/** Saved r4 */
11
+	uint32_t r4;
12
+	/** Saved r5 */
13
+	uint32_t r5;
14
+	/** Saved r6 */
15
+	uint32_t r6;
16
+	/** Saved r7 */
17
+	uint32_t r7;
18
+	/** Saved r8 */
19
+	uint32_t r8;
20
+	/** Saved r9 */
21
+	uint32_t r9;
22
+	/** Saved r10 */
23
+	uint32_t r10;
24
+	/** Saved frame pointer (r11) */
25
+	uint32_t fp;
26
+	/** Saved stack pointer (r13) */
27
+	uint32_t sp;
28
+	/** Saved link register (r14) */
29
+	uint32_t lr;
30
+} jmp_buf[1];
31
+
32
+extern int __asmcall __attribute__ (( returns_twice ))
33
+setjmp ( jmp_buf env );
34
+
35
+extern void __asmcall __attribute__ (( noreturn ))
36
+longjmp ( jmp_buf env, int val );
37
+
38
+#endif /* _SETJMP_H */

+ 53
- 0
src/arch/arm/interface/efi/efiarm_nap.c Vedi File

@@ -0,0 +1,53 @@
1
+/*
2
+ * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ *
19
+ * You can also choose to distribute this program under the terms of
20
+ * the Unmodified Binary Distribution Licence (as given in the file
21
+ * COPYING.UBDL), provided that you have satisfied its requirements.
22
+ */
23
+
24
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
+
26
+#include <ipxe/nap.h>
27
+#include <ipxe/efi/efi.h>
28
+
29
+/** @file
30
+ *
31
+ * iPXE CPU sleeping API for EFI
32
+ *
33
+ */
34
+
35
+/**
36
+ * Sleep until next interrupt
37
+ *
38
+ */
39
+static void efiarm_cpu_nap ( void ) {
40
+	/*
41
+	 * I can't find any EFI API that allows us to put the CPU to
42
+	 * sleep.  The CpuSleep() function is defined in CpuLib.h, but
43
+	 * isn't part of any exposed protocol so we have no way to
44
+	 * call it.
45
+	 *
46
+	 * The EFI shell doesn't seem to bother sleeping the CPU; it
47
+	 * just sits there idly burning power.
48
+	 *
49
+	 */
50
+	__asm__ __volatile__ ( "wfi" );
51
+}
52
+
53
+PROVIDE_NAP ( efiarm, cpu_nap, efiarm_cpu_nap );

+ 50
- 0
src/arch/arm/libgcc/lldivmod.S Vedi File

@@ -0,0 +1,50 @@
1
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
2
+
3
+	.text
4
+	.thumb
5
+
6
+/**
7
+ * Unsigned long long division
8
+ *
9
+ * @v r1:r0		Dividend
10
+ * @v r3:r2		Divisor
11
+ * @ret r1:r0		Quotient
12
+ * @ret r3:r2		Remainder
13
+ */
14
+	.section ".text.__aeabi_uldivmod", "ax", %progbits
15
+	.globl	__aeabi_uldivmod
16
+	.type	__aeabi_uldivmod, %function
17
+__aeabi_uldivmod:
18
+	/* Allocate stack space for remainder and pointer to remainder */
19
+	push	{r0, r1, r2, r3, r4, lr}
20
+	/* Call __udivmoddi4() */
21
+	add	r4, sp, #8
22
+	str	r4, [sp]
23
+	bl	__udivmoddi4
24
+	/* Retrieve remainder and return */
25
+	add	sp, sp, #8
26
+	pop	{r2, r3, r4, pc}
27
+	.size	__aeabi_uldivmod, . - __aeabi_uldivmod
28
+
29
+/**
30
+ * Signed long long division
31
+ *
32
+ * @v r1:r0		Dividend
33
+ * @v r3:r2		Divisor
34
+ * @ret r1:r0		Quotient
35
+ * @ret r3:r2		Remainder
36
+ */
37
+	.section ".text.__aeabi_ldivmod", "ax", %progbits
38
+	.globl	__aeabi_ldivmod
39
+	.type	__aeabi_ldivmod, %function
40
+__aeabi_ldivmod:
41
+	/* Allocate stack space for remainder and pointer to remainder */
42
+	push	{r0, r1, r2, r3, r4, lr}
43
+	/* Call __divmoddi4() */
44
+	add	r4, sp, #8
45
+	str	r4, [sp]
46
+	bl	__divmoddi4
47
+	/* Retrieve remainder and return */
48
+	add	sp, sp, #8
49
+	pop	{r2, r3, r4, pc}
50
+	.size	__aeabi_ldivmod, . - __aeabi_ldivmod

+ 88
- 0
src/arch/arm/libgcc/llshift.S Vedi File

@@ -0,0 +1,88 @@
1
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
2
+
3
+	.text
4
+	.arm
5
+
6
+/**
7
+ * Logical shift left
8
+ *
9
+ * @v r1:r0		Value to shift
10
+ * @v r2		Shift amount
11
+ * @ret r1:r0		Shifted value
12
+ */
13
+	.section ".text.__aeabi_llsl", "ax", %progbits
14
+	.globl	__aeabi_llsl
15
+	.type	__aeabi_llsl, %function
16
+__aeabi_llsl:
17
+	/* r3 = ( shift - 32 ) */
18
+	subs	r3, r2, #32
19
+	/* If shift >= 32, then
20
+	 *   high = ( low << ( shift - 32 ) )
21
+	 */
22
+	movpl	r1, r0, lsl r3
23
+	/* If shift < 32, then
24
+	 *   high = ( ( high << shift ) | ( low >> ( 32 - shift ) ) )
25
+	 */
26
+	movmi	r1, r1, lsl r2
27
+	rsbmi	r3, r2, #32
28
+	orrmi	r1, r1, r0, lsr r3
29
+	/* low = ( low << shift ) */
30
+	mov	r0, r0, lsl r2
31
+	bx	lr
32
+	.size	__aeabi_llsl, . - __aeabi_llsl
33
+
34
+/**
35
+ * Logical shift right
36
+ *
37
+ * @v r1:r0		Value to shift
38
+ * @v r2		Shift amount
39
+ * @ret r1:r0		Shifted value
40
+ */
41
+	.section ".text.__aeabi_llsr", "ax", %progbits
42
+	.globl	__aeabi_llsr
43
+	.type	__aeabi_llsr, %function
44
+__aeabi_llsr:
45
+	/* r3 = ( shift - 32 ) */
46
+	subs	r3, r2, #32
47
+	/* If shift >= 32, then
48
+	 *   low = ( high >> ( shift - 32 ) )
49
+	 */
50
+	movpl	r0, r1, lsr r3
51
+	/* If shift < 32, then
52
+	 *   low = ( ( low >> shift ) | ( high << ( 32 - shift ) ) )
53
+	 */
54
+	movmi	r0, r0, lsr r2
55
+	rsbmi	r3, r2, #32
56
+	orrmi	r0, r0, r1, lsl r3
57
+	/* high = ( high >> shift ) */
58
+	mov	r1, r1, lsr r2
59
+	bx	lr
60
+	.size	__aeabi_llsr, . - __aeabi_llsr
61
+
62
+/**
63
+ * Arithmetic shift right
64
+ *
65
+ * @v r1:r0		Value to shift
66
+ * @v r2		Shift amount
67
+ * @ret r1:r0		Shifted value
68
+ */
69
+	.section ".text.__aeabi_lasr", "ax", %progbits
70
+	.globl	__aeabi_lasr
71
+	.type	__aeabi_lasr, %function
72
+__aeabi_lasr:
73
+	/* r3 = ( shift - 32 ) */
74
+	subs	r3, r2, #32
75
+	/* If shift >= 32, then
76
+	 *   low = ( high >> ( shift - 32 ) )
77
+	 */
78
+	movpl	r0, r1, asr r3
79
+	/* If shift < 32, then
80
+	 *   low = ( ( low >> shift ) | ( high << ( 32 - shift ) ) )
81
+	 */
82
+	movmi	r0, r0, lsr r2
83
+	rsbmi	r3, r2, #32
84
+	orrmi	r0, r0, r1, lsl r3
85
+	/* high = ( high >> shift ) */
86
+	mov	r1, r1, asr r2
87
+	bx	lr
88
+	.size	__aeabi_lasr, . - __aeabi_lasr

+ 10
- 2
src/config/defaults/efi.h Vedi File

@@ -10,12 +10,10 @@
10 10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 11
 
12 12
 #define UACCESS_EFI
13
-#define IOAPI_X86
14 13
 #define IOMAP_VIRT
15 14
 #define PCIAPI_EFI
16 15
 #define CONSOLE_EFI
17 16
 #define TIMER_EFI
18
-#define NAP_EFIX86
19 17
 #define UMALLOC_EFI
20 18
 #define SMBIOS_EFI
21 19
 #define SANBOOT_NULL
@@ -35,6 +33,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
35 33
 #define	USB_EFI			/* Provide EFI_USB_IO_PROTOCOL interface */
36 34
 
37 35
 #define	REBOOT_CMD		/* Reboot command */
36
+
37
+#if defined ( __i386__ ) || defined ( __x86_64__ )
38
+#define IOAPI_X86
39
+#define NAP_EFIX86
38 40
 #define	CPUID_CMD		/* x86 CPU feature detection command */
41
+#endif
42
+
43
+#if defined ( __arm__ )
44
+#define IOAPI_ARM
45
+#define NAP_EFIARM
46
+#endif
39 47
 
40 48
 #endif /* CONFIG_DEFAULTS_EFI_H */

+ 1
- 0
src/util/efirom.c Vedi File

@@ -81,6 +81,7 @@ static void read_pe_info ( void *pe, uint16_t *machine,
81 81
 	*machine = nt->nt32.FileHeader.Machine;
82 82
 	switch ( *machine ) {
83 83
 	case EFI_IMAGE_MACHINE_IA32:
84
+	case EFI_IMAGE_MACHINE_ARMTHUMB_MIXED:
84 85
 		*subsystem = nt->nt32.OptionalHeader.Subsystem;
85 86
 		break;
86 87
 	case EFI_IMAGE_MACHINE_X64:

+ 63
- 47
src/util/elf2efi.c Vedi File

@@ -70,20 +70,14 @@
70 70
 
71 71
 #endif
72 72
 
73
-#define EFI_FILE_ALIGN 0x20
73
+#define ELF_MREL( mach, type ) ( (mach) | ( (type) << 16 ) )
74 74
 
75
-struct elf_machine {
76
-	unsigned int pe_machine;
77
-	unsigned int r_none;
78
-	unsigned int r_abs;
79
-	unsigned int r_pcrel;
80
-};
75
+#define EFI_FILE_ALIGN 0x20
81 76
 
82 77
 struct elf_file {
83 78
 	void *data;
84 79
 	size_t len;
85 80
 	const Elf_Ehdr *ehdr;
86
-	struct elf_machine *machine;
87 81
 };
88 82
 
89 83
 struct pe_section {
@@ -136,20 +130,6 @@ static struct pe_header efi_pe_header = {
136 130
 	},
137 131
 };
138 132
 
139
-static struct elf_machine machine_i386 = {
140
-	.pe_machine = EFI_IMAGE_MACHINE_IA32,
141
-	.r_none = R_386_NONE,
142
-	.r_abs = R_386_32,
143
-	.r_pcrel = R_386_PC32,
144
-};
145
-
146
-static struct elf_machine machine_x86_64 = {
147
-	.pe_machine = EFI_IMAGE_MACHINE_X64,
148
-	.r_none = R_X86_64_NONE,
149
-	.r_abs = R_X86_64_64,
150
-	.r_pcrel = R_X86_64_PC32,
151
-};
152
-
153 133
 /** Command-line options */
154 134
 struct options {
155 135
 	unsigned int subsystem;
@@ -355,19 +335,6 @@ static void read_elf_file ( const char *name, struct elf_file *elf ) {
355 335
 			exit ( 1 );
356 336
 		}
357 337
 	}
358
-
359
-	/* Identify architecture */
360
-	switch ( ehdr->e_machine ) {
361
-	case EM_386:
362
-		elf->machine = &machine_i386;
363
-		break;
364
-	case EM_X86_64:
365
-		elf->machine = &machine_x86_64;
366
-		break;
367
-	default:
368
-		eprintf ( "Unknown ELF architecture %d\n", ehdr->e_machine );
369
-		exit ( 1 );
370
-	}
371 338
 }
372 339
 
373 340
 /**
@@ -415,6 +382,36 @@ static const char * elf_string ( struct elf_file *elf, unsigned int section,
415 382
 	return string;
416 383
 }
417 384
 
385
+/**
386
+ * Set machine architecture
387
+ *
388
+ * @v elf		ELF file
389
+ * @v pe_header		PE file header
390
+ */
391
+static void set_machine ( struct elf_file *elf, struct pe_header *pe_header ) {
392
+	const Elf_Ehdr *ehdr = elf->ehdr;
393
+	uint16_t machine;
394
+
395
+	/* Identify machine architecture */
396
+	switch ( ehdr->e_machine ) {
397
+	case EM_386:
398
+		machine = EFI_IMAGE_MACHINE_IA32;
399
+		break;
400
+	case EM_X86_64:
401
+		machine = EFI_IMAGE_MACHINE_X64;
402
+		break;
403
+	case EM_ARM:
404
+		machine = EFI_IMAGE_MACHINE_ARMTHUMB_MIXED;
405
+		break;
406
+	default:
407
+		eprintf ( "Unknown ELF architecture %d\n", ehdr->e_machine );
408
+		exit ( 1 );
409
+	}
410
+
411
+	/* Set machine architecture */
412
+	pe_header->nt.FileHeader.Machine = machine;
413
+}
414
+
418 415
 /**
419 416
  * Process section
420 417
  *
@@ -568,6 +565,7 @@ static void process_reloc ( struct elf_file *elf, const Elf_Shdr *shdr,
568 565
 			    const Elf_Rel *rel, struct pe_relocs **pe_reltab ) {
569 566
 	unsigned int type = ELF_R_TYPE ( rel->r_info );
570 567
 	unsigned int sym = ELF_R_SYM ( rel->r_info );
568
+	unsigned int mrel = ELF_MREL ( elf->ehdr->e_machine, type );
571 569
 	size_t offset = ( shdr->sh_addr + rel->r_offset );
572 570
 
573 571
 	/* Look up symbol and process relocation */
@@ -579,18 +577,36 @@ static void process_reloc ( struct elf_file *elf, const Elf_Shdr *shdr,
579 577
 		/* Skip absolute symbols; the symbol value won't
580 578
 		 * change when the object is loaded.
581 579
 		 */
582
-	} else if ( type == elf->machine->r_none ) {
583
-		/* Ignore dummy relocations used by REQUIRE_SYMBOL() */
584
-	} else if ( type == elf->machine->r_abs ) {
585
-		/* Generate an 8-byte or 4-byte PE relocation */
586
-		generate_pe_reloc ( pe_reltab, offset, sizeof ( Elf_Addr ) );
587
-	} else if ( type == elf->machine->r_pcrel ) {
588
-		/* Skip PC-relative relocations; all relative offsets
589
-		 * remain unaltered when the object is loaded.
590
-		 */
591 580
 	} else {
592
-		eprintf ( "Unrecognised relocation type %d\n", type );
593
-		exit ( 1 );
581
+		switch ( mrel ) {
582
+		case ELF_MREL ( EM_386, R_386_NONE ) :
583
+		case ELF_MREL ( EM_ARM, R_ARM_NONE ) :
584
+		case ELF_MREL ( EM_X86_64, R_X86_64_NONE ) :
585
+			/* Ignore dummy relocations used by REQUIRE_SYMBOL() */
586
+			break;
587
+		case ELF_MREL ( EM_386, R_386_32 ) :
588
+		case ELF_MREL ( EM_ARM, R_ARM_ABS32 ) :
589
+			/* Generate a 4-byte PE relocation */
590
+			generate_pe_reloc ( pe_reltab, offset, 4 );
591
+			break;
592
+		case ELF_MREL ( EM_X86_64, R_X86_64_64 ) :
593
+			/* Generate an 8-byte PE relocation */
594
+			generate_pe_reloc ( pe_reltab, offset, 8 );
595
+			break;
596
+		case ELF_MREL ( EM_386, R_386_PC32 ) :
597
+		case ELF_MREL ( EM_ARM, R_ARM_CALL ) :
598
+		case ELF_MREL ( EM_ARM, R_ARM_THM_PC22 ) :
599
+		case ELF_MREL ( EM_ARM, R_ARM_THM_JUMP24 ) :
600
+		case ELF_MREL ( EM_X86_64, R_X86_64_PC32 ) :
601
+			/* Skip PC-relative relocations; all relative
602
+			 * offsets remain unaltered when the object is
603
+			 * loaded.
604
+			 */
605
+			break;
606
+		default:
607
+			eprintf ( "Unrecognised relocation type %d\n", type );
608
+			exit ( 1 );
609
+		}
594 610
 	}
595 611
 }
596 612
 
@@ -835,7 +851,7 @@ static void elf2pe ( const char *elf_name, const char *pe_name,
835 851
 
836 852
 	/* Initialise the PE header */
837 853
 	memcpy ( &pe_header, &efi_pe_header, sizeof ( pe_header ) );
838
-	pe_header.nt.FileHeader.Machine = elf.machine->pe_machine;
854
+	set_machine ( &elf, &pe_header );
839 855
 	pe_header.nt.OptionalHeader.AddressOfEntryPoint = elf.ehdr->e_entry;
840 856
 	pe_header.nt.OptionalHeader.Subsystem = opts->subsystem;
841 857
 

Loading…
Annulla
Salva