diff options
| author | Simon Rettberg | 2026-01-28 12:53:53 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2026-01-28 12:53:53 +0100 |
| commit | 8e82785c584dc13e20f9229decb95bd17bbe9cd1 (patch) | |
| tree | a8b359e59196be5b2e3862bed189107f4bc9975f /src/arch/loong64/include/bits | |
| parent | Merge branch 'master' into openslx (diff) | |
| parent | [prefix] Make unlzma.S compatible with 386 class CPUs (diff) | |
| download | ipxe-openslx.tar.gz ipxe-openslx.tar.xz ipxe-openslx.zip | |
Merge branch 'master' into openslxopenslx
Diffstat (limited to 'src/arch/loong64/include/bits')
| -rw-r--r-- | src/arch/loong64/include/bits/acpi.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/bigint.h | 138 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/hyperv.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/iomap.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/mp.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/nap.h | 8 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/pci_io.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/profile.h | 2 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/reboot.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/sanboot.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/setjmp.h | 23 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/smbios.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/tcpip.h | 19 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/time.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/uaccess.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/uart.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/umalloc.h | 12 | ||||
| -rw-r--r-- | src/arch/loong64/include/bits/xen.h | 13 |
18 files changed, 109 insertions, 238 deletions
diff --git a/src/arch/loong64/include/bits/acpi.h b/src/arch/loong64/include/bits/acpi.h deleted file mode 100644 index 83dd1df9a..000000000 --- a/src/arch/loong64/include/bits/acpi.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_ACPI_H -#define _BITS_ACPI_H - -/** @file - * - * LoongArch64-specific ACPI API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_ACPI_H */ diff --git a/src/arch/loong64/include/bits/bigint.h b/src/arch/loong64/include/bits/bigint.h index bec748beb..6a879503a 100644 --- a/src/arch/loong64/include/bits/bigint.h +++ b/src/arch/loong64/include/bits/bigint.h @@ -43,8 +43,9 @@ bigint_init_raw ( uint64_t *value0, unsigned int size, * @v addend0 Element 0 of big integer to add * @v value0 Element 0 of big integer to be added to * @v size Number of elements + * @ret carry Carry out */ -static inline __attribute__ (( always_inline )) void +static inline __attribute__ (( always_inline )) int bigint_add_raw ( const uint64_t *addend0, uint64_t *value0, unsigned int size ) { bigint_t ( size ) __attribute__ (( may_alias )) *value = @@ -53,20 +54,20 @@ bigint_add_raw ( const uint64_t *addend0, uint64_t *value0, uint64_t *discard_value; uint64_t discard_addend_i; uint64_t discard_value_i; - uint64_t discard_carry; uint64_t discard_temp; unsigned int discard_size; + uint64_t carry; __asm__ __volatile__ ( "\n1:\n\t" /* Load addend[i] and value[i] */ "ld.d %3, %0, 0\n\t" "ld.d %4, %1, 0\n\t" /* Add carry flag and addend */ - "add.d %4, %4, %5\n\t" - "sltu %6, %4, %5\n\t" + "add.d %4, %4, %6\n\t" + "sltu %5, %4, %6\n\t" "add.d %4, %4, %3\n\t" - "sltu %5, %4, %3\n\t" - "or %5, %5, %6\n\t" + "sltu %6, %4, %3\n\t" + "or %6, %5, %6\n\t" /* Store value[i] */ "st.d %4, %1, 0\n\t" /* Loop */ @@ -79,11 +80,12 @@ bigint_add_raw ( const uint64_t *addend0, uint64_t *value0, "=r" ( discard_size ), "=r" ( discard_addend_i ), "=r" ( discard_value_i ), - "=r" ( discard_carry ), "=r" ( discard_temp ), + "=r" ( carry ), "+m" ( *value ) : "0" ( addend0 ), "1" ( value0 ), - "2" ( size ), "5" ( 0 ) ); + "2" ( size ), "6" ( 0 ) ); + return carry; } /** @@ -92,8 +94,9 @@ bigint_add_raw ( const uint64_t *addend0, uint64_t *value0, * @v subtrahend0 Element 0 of big integer to subtract * @v value0 Element 0 of big integer to be subtracted from * @v size Number of elements + * @ret borrow Borrow out */ -static inline __attribute__ (( always_inline )) void +static inline __attribute__ (( always_inline )) int bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0, unsigned int size ) { bigint_t ( size ) __attribute__ (( may_alias )) *value = @@ -102,20 +105,20 @@ bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0, uint64_t *discard_value; uint64_t discard_subtrahend_i; uint64_t discard_value_i; - uint64_t discard_carry; uint64_t discard_temp; unsigned int discard_size; + uint64_t borrow; __asm__ __volatile__ ( "\n1:\n\t" /* Load subtrahend[i] and value[i] */ "ld.d %3, %0, 0\n\t" "ld.d %4, %1, 0\n\t" /* Subtract carry flag and subtrahend */ - "sltu %6, %4, %5\n\t" - "sub.d %4, %4, %5\n\t" - "sltu %5, %4, %3\n\t" + "sltu %5, %4, %6\n\t" + "sub.d %4, %4, %6\n\t" + "sltu %6, %4, %3\n\t" "sub.d %4, %4, %3\n\t" - "or %5, %5, %6\n\t" + "or %6, %5, %6\n\t" /* Store value[i] */ "st.d %4, %1, 0\n\t" /* Loop */ @@ -128,38 +131,40 @@ bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0, "=r" ( discard_size ), "=r" ( discard_subtrahend_i ), "=r" ( discard_value_i ), - "=r" ( discard_carry ), "=r" ( discard_temp ), + "=r" ( borrow ), "+m" ( *value ) : "0" ( subtrahend0 ), "1" ( value0 ), - "2" ( size ), "5" ( 0 ) ); + "2" ( size ), "6" ( 0 ) ); + return borrow; } /** - * Rotate big integer left + * Shift big integer left * * @v value0 Element 0 of big integer * @v size Number of elements + * @ret out Bit shifted out */ -static inline __attribute__ (( always_inline )) void -bigint_rol_raw ( uint64_t *value0, unsigned int size ) { +static inline __attribute__ (( always_inline )) int +bigint_shl_raw ( uint64_t *value0, unsigned int size ) { bigint_t ( size ) __attribute__ (( may_alias )) *value = ( ( void * ) value0 ); uint64_t *discard_value; uint64_t discard_value_i; - uint64_t discard_carry; uint64_t discard_temp; unsigned int discard_size; + uint64_t carry; __asm__ __volatile__ ( "\n1:\n\t" /* Load value[i] */ "ld.d %2, %0, 0\n\t" /* Shift left */ "rotri.d %2, %2, 63\n\t" - "andi %4, %2, 1\n\t" - "xor %2, %2, %4\n\t" - "or %2, %2, %3\n\t" - "move %3, %4\n\t" + "andi %3, %2, 1\n\t" + "xor %2, %2, %3\n\t" + "or %2, %2, %4\n\t" + "move %4, %3\n\t" /* Store value[i] */ "st.d %2, %0, 0\n\t" /* Loop */ @@ -169,37 +174,39 @@ bigint_rol_raw ( uint64_t *value0, unsigned int size ) { : "=r" ( discard_value ), "=r" ( discard_size ), "=r" ( discard_value_i ), - "=r" ( discard_carry ), "=r" ( discard_temp ), + "=r" ( carry ), "+m" ( *value ) - : "0" ( value0 ), "1" ( size ), "3" ( 0 ) + : "0" ( value0 ), "1" ( size ), "4" ( 0 ) : "cc" ); + return ( carry & 1 ); } /** - * Rotate big integer right + * Shift big integer right * * @v value0 Element 0 of big integer * @v size Number of elements + * @ret out Bit shifted out */ -static inline __attribute__ (( always_inline )) void -bigint_ror_raw ( uint64_t *value0, unsigned int size ) { +static inline __attribute__ (( always_inline )) int +bigint_shr_raw ( uint64_t *value0, unsigned int size ) { bigint_t ( size ) __attribute__ (( may_alias )) *value = ( ( void * ) value0 ); uint64_t *discard_value; uint64_t discard_value_i; - uint64_t discard_carry; uint64_t discard_temp; unsigned int discard_size; + uint64_t carry; __asm__ __volatile__ ( "\n1:\n\t" /* Load value[i] */ "ld.d %2, %0, -8\n\t" /* Shift right */ - "andi %4, %2, 1\n\t" - "xor %2, %2, %4\n\t" - "or %2, %2, %3\n\t" - "move %3, %4\n\t" + "andi %3, %2, 1\n\t" + "xor %2, %2, %3\n\t" + "or %2, %2, %4\n\t" + "move %4, %3\n\t" "rotri.d %2, %2, 1\n\t" /* Store value[i] */ "st.d %2, %0, -8\n\t" @@ -210,11 +217,12 @@ bigint_ror_raw ( uint64_t *value0, unsigned int size ) { : "=r" ( discard_value ), "=r" ( discard_size ), "=r" ( discard_value_i ), - "=r" ( discard_carry ), "=r" ( discard_temp ), + "=r" ( carry ), "+m" ( *value ) - : "0" ( value0 + size ), "1" ( size ), "3" ( 0 ) + : "0" ( value0 + size ), "1" ( size ), "4" ( 0 ) : "cc" ); + return ( carry & 1 ); } /** @@ -265,25 +273,6 @@ bigint_is_geq_raw ( const uint64_t *value0, const uint64_t *reference0, } /** - * Test if bit is set in big integer - * - * @v value0 Element 0 of big integer - * @v size Number of elements - * @v bit Bit to test - * @ret is_set Bit is set - */ -static inline __attribute__ (( always_inline )) int -bigint_bit_is_set_raw ( const uint64_t *value0, unsigned int size, - unsigned int bit ) { - const bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( const void * ) value0 ); - unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) ); - unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) ); - - return ( !! ( value->element[index] & ( 1UL << subindex ) ) ); -} - -/** * Find highest bit set in big integer * * @v value0 Element 0 of big integer @@ -357,10 +346,39 @@ bigint_done_raw ( const uint64_t *value0, unsigned int size __unused, *(--out_byte) = *(value_byte++); } -extern void bigint_multiply_raw ( const uint64_t *multiplicand0, - unsigned int multiplicand_size, - const uint64_t *multiplier0, - unsigned int multiplier_size, - uint64_t *value0 ); +/** + * Multiply big integer elements + * + * @v multiplicand Multiplicand element + * @v multiplier Multiplier element + * @v result Result element + * @v carry Carry element + */ +static inline __attribute__ (( always_inline )) void +bigint_multiply_one ( const uint64_t multiplicand, const uint64_t multiplier, + uint64_t *result, uint64_t *carry ) { + uint64_t discard_low; + uint64_t discard_high; + uint64_t discard_carry; + + __asm__ __volatile__ ( /* Perform multiplication */ + "mul.d %0, %5, %6\n\t" + "mulh.du %1, %5, %6\n\t" + /* Accumulate low half */ + "add.d %3, %3, %0\n\t" + "sltu %2, %3, %0\n\t" + "add.d %1, %1, %2\n\t" + /* Accumulate carry (cannot overflow) */ + "add.d %3, %3, %4\n\t" + "sltu %2, %3, %4\n\t" + "add.d %4, %1, %2\n\t" + : "=&r" ( discard_low ), + "=r" ( discard_high ), + "=r" ( discard_carry ), + "+r" ( *result ), + "+r" ( *carry ) + : "r" ( multiplicand ), + "r" ( multiplier ) ); +} #endif /* _BITS_BIGINT_H */ diff --git a/src/arch/loong64/include/bits/hyperv.h b/src/arch/loong64/include/bits/hyperv.h deleted file mode 100644 index f0e0c8793..000000000 --- a/src/arch/loong64/include/bits/hyperv.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_HYPERV_H -#define _BITS_HYPERV_H - -/** @file - * - * Hyper-V interface - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_HYPERV_H */ diff --git a/src/arch/loong64/include/bits/iomap.h b/src/arch/loong64/include/bits/iomap.h deleted file mode 100644 index 041171d22..000000000 --- a/src/arch/loong64/include/bits/iomap.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_IOMAP_H -#define _BITS_IOMAP_H - -/** @file - * - * LoongArch64-specific I/O mapping API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_IOMAP_H */ diff --git a/src/arch/loong64/include/bits/mp.h b/src/arch/loong64/include/bits/mp.h deleted file mode 100644 index fef2fd59a..000000000 --- a/src/arch/loong64/include/bits/mp.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_MP_H -#define _BITS_MP_H - -/** @file - * - * LoongArch64-specific multiprocessor API implementation - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_MP_H */ diff --git a/src/arch/loong64/include/bits/nap.h b/src/arch/loong64/include/bits/nap.h index 2deba3558..d904db537 100644 --- a/src/arch/loong64/include/bits/nap.h +++ b/src/arch/loong64/include/bits/nap.h @@ -9,6 +9,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); -#include <ipxe/efi/efiloong64_nap.h> +/** + * Sleep until next CPU interrupt + * + */ +static inline __attribute__ (( always_inline )) void cpu_halt ( void ) { + __asm__ __volatile__ ( "idle 0" ); +} #endif /* _BITS_NAP_H */ diff --git a/src/arch/loong64/include/bits/pci_io.h b/src/arch/loong64/include/bits/pci_io.h deleted file mode 100644 index fdc5141cf..000000000 --- a/src/arch/loong64/include/bits/pci_io.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_PCI_IO_H -#define _BITS_PCI_IO_H - -/** @file - * - * LoongArch64-specific PCI I/O API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_PCI_IO_H */ diff --git a/src/arch/loong64/include/bits/profile.h b/src/arch/loong64/include/bits/profile.h index 9f597ce2d..02f8d4b7c 100644 --- a/src/arch/loong64/include/bits/profile.h +++ b/src/arch/loong64/include/bits/profile.h @@ -16,7 +16,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * * @ret timestamp Timestamp */ -static inline __attribute__ (( always_inline )) uint64_t +static inline __attribute__ (( always_inline )) unsigned long profile_timestamp ( void ) { uint64_t cycles; diff --git a/src/arch/loong64/include/bits/reboot.h b/src/arch/loong64/include/bits/reboot.h deleted file mode 100644 index 96a1eb1ce..000000000 --- a/src/arch/loong64/include/bits/reboot.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_REBOOT_H -#define _BITS_REBOOT_H - -/** @file - * - * LoongArch64-specific reboot API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_REBOOT_H */ diff --git a/src/arch/loong64/include/bits/sanboot.h b/src/arch/loong64/include/bits/sanboot.h deleted file mode 100644 index f9205e2ad..000000000 --- a/src/arch/loong64/include/bits/sanboot.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_SANBOOT_H -#define _BITS_SANBOOT_H - -/** @file - * - * LoongArch64-specific sanboot API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_SANBOOT_H */ diff --git a/src/arch/loong64/include/bits/setjmp.h b/src/arch/loong64/include/bits/setjmp.h new file mode 100644 index 000000000..c8d7cef0e --- /dev/null +++ b/src/arch/loong64/include/bits/setjmp.h @@ -0,0 +1,23 @@ +#ifndef _BITS_SETJMP_H +#define _BITS_SETJMP_H + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +/** A jump buffer */ +typedef struct { + uint64_t s0; + uint64_t s1; + uint64_t s2; + uint64_t s3; + uint64_t s4; + uint64_t s5; + uint64_t s6; + uint64_t s7; + uint64_t s8; + + uint64_t fp; + uint64_t sp; + uint64_t ra; +} jmp_buf[1]; + +#endif /* _BITS_SETJMP_H */ diff --git a/src/arch/loong64/include/bits/smbios.h b/src/arch/loong64/include/bits/smbios.h deleted file mode 100644 index 6c87db430..000000000 --- a/src/arch/loong64/include/bits/smbios.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_SMBIOS_H -#define _BITS_SMBIOS_H - -/** @file - * - * LoongArch64-specific SMBIOS API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_SMBIOS_H */ diff --git a/src/arch/loong64/include/bits/tcpip.h b/src/arch/loong64/include/bits/tcpip.h deleted file mode 100644 index fc3c5b3ff..000000000 --- a/src/arch/loong64/include/bits/tcpip.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _BITS_TCPIP_H -#define _BITS_TCPIP_H - -/** @file - * - * Transport-network layer interface - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -static inline __attribute__ (( always_inline )) uint16_t -tcpip_continue_chksum ( uint16_t partial, const void *data, size_t len ) { - - /* Not yet optimised */ - return generic_tcpip_continue_chksum ( partial, data, len ); -} - -#endif /* _BITS_TCPIP_H */ diff --git a/src/arch/loong64/include/bits/time.h b/src/arch/loong64/include/bits/time.h deleted file mode 100644 index 4cd7485cf..000000000 --- a/src/arch/loong64/include/bits/time.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_TIME_H -#define _BITS_TIME_H - -/** @file - * - * LoongArch64-specific time API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_TIME_H */ diff --git a/src/arch/loong64/include/bits/uaccess.h b/src/arch/loong64/include/bits/uaccess.h deleted file mode 100644 index dddd9be04..000000000 --- a/src/arch/loong64/include/bits/uaccess.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_UACCESS_H -#define _BITS_UACCESS_H - -/** @file - * - * LoongArch64-specific user access API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_UACCESS_H */ diff --git a/src/arch/loong64/include/bits/uart.h b/src/arch/loong64/include/bits/uart.h deleted file mode 100644 index 6f85975f7..000000000 --- a/src/arch/loong64/include/bits/uart.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_UART_H -#define _BITS_UART_H - -/** @file - * - * 16550-compatible UART - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_UART_H */ diff --git a/src/arch/loong64/include/bits/umalloc.h b/src/arch/loong64/include/bits/umalloc.h deleted file mode 100644 index f6978b8bd..000000000 --- a/src/arch/loong64/include/bits/umalloc.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_UMALLOC_H -#define _BITS_UMALLOC_H - -/** @file - * - * LoongArch64-specific user memory allocation API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_UMALLOC_H */ diff --git a/src/arch/loong64/include/bits/xen.h b/src/arch/loong64/include/bits/xen.h deleted file mode 100644 index 2a3d7741c..000000000 --- a/src/arch/loong64/include/bits/xen.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _BITS_XEN_H -#define _BITS_XEN_H - -/** @file - * - * Xen interface - * - */ -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/nonxen.h> - -#endif /* _BITS_XEN_H */ |
