diff options
Diffstat (limited to 'roms/ipxe/src/arch/i386/include/bits')
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/byteswap.h | 70 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/compiler.h | 38 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/endian.h | 8 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/entropy.h | 14 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/linux_api.h | 6 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/nap.h | 15 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/profile.h | 28 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/reboot.h | 14 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/sanboot.h | 14 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/smbios.h | 14 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/stdint.h | 23 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/strings.h | 50 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/time.h | 14 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/timer.h | 15 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/uaccess.h | 14 | ||||
-rw-r--r-- | roms/ipxe/src/arch/i386/include/bits/umalloc.h | 14 |
16 files changed, 351 insertions, 0 deletions
diff --git a/roms/ipxe/src/arch/i386/include/bits/byteswap.h b/roms/ipxe/src/arch/i386/include/bits/byteswap.h new file mode 100644 index 00000000..0d9cb967 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/byteswap.h @@ -0,0 +1,70 @@ +#ifndef _BITS_BYTESWAP_H +#define _BITS_BYTESWAP_H + +/** @file + * + * Byte-order swapping functions + * + */ + +#include <stdint.h> + +FILE_LICENCE ( GPL2_OR_LATER ); + +static inline __attribute__ (( always_inline, const )) uint16_t +__bswap_variable_16 ( uint16_t x ) { + __asm__ ( "xchgb %b0,%h0" : "=q" ( x ) : "0" ( x ) ); + return x; +} + +static inline __attribute__ (( always_inline )) void +__bswap_16s ( uint16_t *x ) { + __asm__ ( "rorw $8, %0" : "+m" ( *x ) ); +} + +static inline __attribute__ (( always_inline, const )) uint32_t +__bswap_variable_32 ( uint32_t x ) { + __asm__ ( "bswapl %0" : "=r" ( x ) : "0" ( x ) ); + return x; +} + +static inline __attribute__ (( always_inline )) void +__bswap_32s ( uint32_t *x ) { + __asm__ ( "bswapl %0" : "=r" ( *x ) : "0" ( *x ) ); +} + +static inline __attribute__ (( always_inline, const )) uint64_t +__bswap_variable_64 ( uint64_t x ) { + uint32_t in_high = ( x >> 32 ); + uint32_t in_low = ( x & 0xffffffffUL ); + uint32_t out_high; + uint32_t out_low; + + __asm__ ( "bswapl %0\n\t" + "bswapl %1\n\t" + "xchgl %0,%1\n\t" + : "=r" ( out_high ), "=r" ( out_low ) + : "0" ( in_high ), "1" ( in_low ) ); + + return ( ( ( ( uint64_t ) out_high ) << 32 ) | + ( ( uint64_t ) out_low ) ); +} + +static inline __attribute__ (( always_inline )) void +__bswap_64s ( uint64_t *x ) { + struct { + uint32_t __attribute__ (( may_alias )) low; + uint32_t __attribute__ (( may_alias )) high; + } __attribute__ (( may_alias )) *dwords = ( ( void * ) x ); + uint32_t discard; + + __asm__ ( "movl %0,%2\n\t" + "bswapl %2\n\t" + "xchgl %2,%1\n\t" + "bswapl %2\n\t" + "movl %2,%0\n\t" + : "+m" ( dwords->low ), "+m" ( dwords->high ), + "=r" ( discard ) ); +} + +#endif /* _BITS_BYTESWAP_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/compiler.h b/roms/ipxe/src/arch/i386/include/bits/compiler.h new file mode 100644 index 00000000..d48b4b38 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/compiler.h @@ -0,0 +1,38 @@ +#ifndef _BITS_COMPILER_H +#define _BITS_COMPILER_H + +FILE_LICENCE ( GPL2_OR_LATER ); + +#ifndef ASSEMBLY + +/** Declare a function with standard calling conventions */ +#define __asmcall __attribute__ (( cdecl, regparm(0) )) + +/** + * Declare a function with libgcc implicit linkage + * + * It seems as though gcc expects its implicit arithmetic functions to + * be cdecl, even if -mrtd is specified. This is somewhat + * inconsistent; for example, if -mregparm=3 is used then the implicit + * functions do become regparm(3). + * + * The implicit calls to memcpy() and memset() which gcc can generate + * do not seem to have this inconsistency; -mregparm and -mrtd affect + * them in the same way as any other function. + * + * Update (25/4/14): it appears that more recent gcc versions do allow + * -mrtd to affect calls to the implicit arithmetic functions. There + * is nothing obvious in the gcc changelogs to indicate precisely when + * this happened. From experimentation with available gcc versions, + * the change occurred sometime between v4.6.3 and v4.7.2. We assume + * that only versions up to v4.6.x require the special treatment. + */ +#if ( __GNUC__ < 4 ) || ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ <= 6 ) ) +#define __libgcc __attribute__ (( cdecl )) +#else +#define __libgcc +#endif + +#endif /* ASSEMBLY */ + +#endif /* _BITS_COMPILER_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/endian.h b/roms/ipxe/src/arch/i386/include/bits/endian.h new file mode 100644 index 00000000..84188542 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/endian.h @@ -0,0 +1,8 @@ +#ifndef ETHERBOOT_BITS_ENDIAN_H +#define ETHERBOOT_BITS_ENDIAN_H + +FILE_LICENCE ( GPL2_OR_LATER ); + +#define __BYTE_ORDER __LITTLE_ENDIAN + +#endif /* ETHERBOOT_BITS_ENDIAN_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/entropy.h b/roms/ipxe/src/arch/i386/include/bits/entropy.h new file mode 100644 index 00000000..6dcceec6 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/entropy.h @@ -0,0 +1,14 @@ +#ifndef _BITS_ENTROPY_H +#define _BITS_ENTROPY_H + +/** @file + * + * i386-specific entropy API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <ipxe/rtc_entropy.h> + +#endif /* _BITS_ENTROPY_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/linux_api.h b/roms/ipxe/src/arch/i386/include/bits/linux_api.h new file mode 100644 index 00000000..dc6e7416 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/linux_api.h @@ -0,0 +1,6 @@ +#ifndef _I386_LINUX_API_H +#define _I386_LINUX_API_H + +#define __SYSCALL_mmap __NR_mmap2 + +#endif /* _I386_LINUX_API_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/nap.h b/roms/ipxe/src/arch/i386/include/bits/nap.h new file mode 100644 index 00000000..64066e6a --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/nap.h @@ -0,0 +1,15 @@ +#ifndef _BITS_NAP_H +#define _BITS_NAP_H + +/** @file + * + * i386-specific CPU sleeping API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <ipxe/bios_nap.h> +#include <ipxe/efi/efix86_nap.h> + +#endif /* _BITS_MAP_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/profile.h b/roms/ipxe/src/arch/i386/include/bits/profile.h new file mode 100644 index 00000000..f3ee54ae --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/profile.h @@ -0,0 +1,28 @@ +#ifndef _BITS_PROFILE_H +#define _BITS_PROFILE_H + +/** @file + * + * Profiling + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <stdint.h> + +/** + * Get profiling timestamp + * + * @ret timestamp Timestamp + */ +static inline __attribute__ (( always_inline )) uint64_t +profile_timestamp ( void ) { + uint64_t tsc; + + /* Read timestamp counter */ + __asm__ __volatile__ ( "rdtsc" : "=A" ( tsc ) ); + return tsc; +} + +#endif /* _BITS_PROFILE_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/reboot.h b/roms/ipxe/src/arch/i386/include/bits/reboot.h new file mode 100644 index 00000000..5b09e95f --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/reboot.h @@ -0,0 +1,14 @@ +#ifndef _BITS_REBOOT_H +#define _BITS_REBOOT_H + +/** @file + * + * i386-specific reboot API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <ipxe/bios_reboot.h> + +#endif /* _BITS_REBOOT_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/sanboot.h b/roms/ipxe/src/arch/i386/include/bits/sanboot.h new file mode 100644 index 00000000..9c77a4d4 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/sanboot.h @@ -0,0 +1,14 @@ +#ifndef _BITS_SANBOOT_H +#define _BITS_SANBOOT_H + +/** @file + * + * i386-specific sanboot API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <ipxe/bios_sanboot.h> + +#endif /* _BITS_SANBOOT_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/smbios.h b/roms/ipxe/src/arch/i386/include/bits/smbios.h new file mode 100644 index 00000000..cc79eec5 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/smbios.h @@ -0,0 +1,14 @@ +#ifndef _BITS_SMBIOS_H +#define _BITS_SMBIOS_H + +/** @file + * + * i386-specific SMBIOS API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <ipxe/bios_smbios.h> + +#endif /* _BITS_SMBIOS_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/stdint.h b/roms/ipxe/src/arch/i386/include/bits/stdint.h new file mode 100644 index 00000000..8edf1319 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/stdint.h @@ -0,0 +1,23 @@ +#ifndef _BITS_STDINT_H +#define _BITS_STDINT_H + +FILE_LICENCE ( GPL2_OR_LATER ); + +typedef __SIZE_TYPE__ size_t; +typedef signed long ssize_t; +typedef signed long off_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long long int64_t; + +typedef unsigned long physaddr_t; +typedef unsigned long intptr_t; + +#endif /* _BITS_STDINT_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/strings.h b/roms/ipxe/src/arch/i386/include/bits/strings.h new file mode 100644 index 00000000..092bcb59 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/strings.h @@ -0,0 +1,50 @@ +#ifndef _BITS_STRINGS_H +#define _BITS_STRINGS_H + +FILE_LICENCE ( GPL2_OR_LATER ); + +/** + * Find last (i.e. most significant) set bit + * + * @v value Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ +static inline __attribute__ (( always_inline )) int __flsl ( long value ) { + long msb_minus_one; + + /* If the input value is zero, the BSR instruction returns + * ZF=1 and leaves an undefined value in the output register. + * Perform this check in C rather than asm so that it can be + * omitted in cases where the compiler is able to prove that + * the input is non-zero. + */ + if ( value ) { + __asm__ ( "bsrl %1, %0" + : "=r" ( msb_minus_one ) + : "rm" ( value ) ); + return ( msb_minus_one + 1 ); + } else { + return 0; + } +} + +/** + * Find last (i.e. most significant) set bit + * + * @v value Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ +static inline __attribute__ (( always_inline )) int __flsll ( long long value ){ + unsigned long high = ( value >> 32 ); + unsigned long low = ( value >> 0 ); + + if ( high ) { + return ( 32 + __flsl ( high ) ); + } else if ( low ) { + return ( __flsl ( low ) ); + } else { + return 0; + } +} + +#endif /* _BITS_STRINGS_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/time.h b/roms/ipxe/src/arch/i386/include/bits/time.h new file mode 100644 index 00000000..24dd020e --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/time.h @@ -0,0 +1,14 @@ +#ifndef _BITS_TIME_H +#define _BITS_TIME_H + +/** @file + * + * i386-specific time API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <ipxe/rtc_time.h> + +#endif /* _BITS_TIME_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/timer.h b/roms/ipxe/src/arch/i386/include/bits/timer.h new file mode 100644 index 00000000..50b676b7 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/timer.h @@ -0,0 +1,15 @@ +#ifndef _BITS_TIMER_H +#define _BITS_TIMER_H + +/** @file + * + * i386-specific timer API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <ipxe/bios_timer.h> +#include <ipxe/rdtsc_timer.h> + +#endif /* _BITS_TIMER_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/uaccess.h b/roms/ipxe/src/arch/i386/include/bits/uaccess.h new file mode 100644 index 00000000..2bb52e02 --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/uaccess.h @@ -0,0 +1,14 @@ +#ifndef _BITS_UACCESS_H +#define _BITS_UACCESS_H + +/** @file + * + * i386-specific user access API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <librm.h> + +#endif /* _BITS_UACCESS_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/umalloc.h b/roms/ipxe/src/arch/i386/include/bits/umalloc.h new file mode 100644 index 00000000..54fb006f --- /dev/null +++ b/roms/ipxe/src/arch/i386/include/bits/umalloc.h @@ -0,0 +1,14 @@ +#ifndef _BITS_UMALLOC_H +#define _BITS_UMALLOC_H + +/** @file + * + * i386-specific user memory allocation API implementations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <ipxe/memtop_umalloc.h> + +#endif /* _BITS_UMALLOC_H */ |