diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h index 9b79506..cfc359a 100644 --- a/arch/arm/include/asm/atomic.h +++ b/arch/arm/include/asm/atomic.h @@ -1,111 +1,9 @@ -/* - * linux/include/asm-arm/atomic.h - * - * Copyright (c) 1996 Russell King. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Changelog: - * 27-06-1996 RMK Created - * 13-04-1997 RMK Made functions atomic! - * 07-12-1997 RMK Upgraded for v2.1. - * 26-08-1998 PJB Added #ifdef __KERNEL__ - */ +// SPDX-License-Identifier: GPL-2.0-only + #ifndef __ASM_ARM_ATOMIC_H #define __ASM_ARM_ATOMIC_H -#ifdef CONFIG_SMP -#error SMP not supported -#endif - -typedef struct { volatile int counter; } atomic_t; - -#define ATOMIC_INIT(i) { (i) } - -#ifdef __KERNEL__ #include +#include -#define atomic_read(v) ((v)->counter) -#define atomic_set(v,i) (((v)->counter) = (i)) - -static inline void atomic_add(int i, volatile atomic_t *v) -{ - unsigned long flags = 0; - - local_irq_save(flags); - v->counter += i; - local_irq_restore(flags); -} - -static inline void atomic_sub(int i, volatile atomic_t *v) -{ - unsigned long flags = 0; - - local_irq_save(flags); - v->counter -= i; - local_irq_restore(flags); -} - -static inline void atomic_inc(volatile atomic_t *v) -{ - unsigned long flags = 0; - - local_irq_save(flags); - v->counter += 1; - local_irq_restore(flags); -} - -static inline void atomic_dec(volatile atomic_t *v) -{ - unsigned long flags = 0; - - local_irq_save(flags); - v->counter -= 1; - local_irq_restore(flags); -} - -static inline int atomic_dec_and_test(volatile atomic_t *v) -{ - unsigned long flags = 0; - int val; - - local_irq_save(flags); - val = v->counter; - v->counter = val -= 1; - local_irq_restore(flags); - - return val == 0; -} - -static inline int atomic_add_negative(int i, volatile atomic_t *v) -{ - unsigned long flags = 0; - int val; - - local_irq_save(flags); - val = v->counter; - v->counter = val += i; - local_irq_restore(flags); - - return val < 0; -} - -static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) -{ - unsigned long flags = 0; - - local_irq_save(flags); - *addr &= ~mask; - local_irq_restore(flags); -} - -/* Atomic operations are already serializing on ARM */ -#define smp_mb__before_atomic_dec() barrier() -#define smp_mb__after_atomic_dec() barrier() -#define smp_mb__before_atomic_inc() barrier() -#define smp_mb__after_atomic_inc() barrier() - -#endif #endif diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h index 56db546..072b473 100644 --- a/arch/arm/include/asm/io.h +++ b/arch/arm/include/asm/io.h @@ -4,6 +4,7 @@ #define IO_SPACE_LIMIT 0 #include +#include /* * String version of IO memory access ops: @@ -12,63 +13,6 @@ extern void memcpy_toio(volatile void __iomem *, const void *, size_t); extern void memset_io(volatile void __iomem *, int, size_t); -/* - * Clear and set bits in one shot. These macros can be used to clear and - * set multiple bits in a register using a single call. These macros can - * also be used to set a multiple-bit bit pattern using a mask, by - * specifying the mask in the 'clear' parameter and the new bit pattern - * in the 'set' parameter. - */ - -#define out_arch(type,endian,a,v) __raw_write##type(cpu_to_##endian(v),a) -#define in_arch(type,endian,a) endian##_to_cpu(__raw_read##type(a)) - -#define out_le64(a,v) out_arch(q,le64,a,v) -#define out_le32(a,v) out_arch(l,le32,a,v) -#define out_le16(a,v) out_arch(w,le16,a,v) - -#define in_le64(a) in_arch(q,le64,a) -#define in_le32(a) in_arch(l,le32,a) -#define in_le16(a) in_arch(w,le16,a) - -#define out_be32(a,v) out_arch(l,be32,a,v) -#define out_be16(a,v) out_arch(w,be16,a,v) - -#define in_be32(a) in_arch(l,be32,a) -#define in_be16(a) in_arch(w,be16,a) - -#define out_8(a,v) __raw_writeb(v,a) -#define in_8(a) __raw_readb(a) - -#define clrbits(type, addr, clear) \ - out_##type((addr), in_##type(addr) & ~(clear)) - -#define setbits(type, addr, set) \ - out_##type((addr), in_##type(addr) | (set)) - -#define clrsetbits(type, addr, clear, set) \ - out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) - -#define clrbits_be32(addr, clear) clrbits(be32, addr, clear) -#define setbits_be32(addr, set) setbits(be32, addr, set) -#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) - -#define clrbits_le32(addr, clear) clrbits(le32, addr, clear) -#define setbits_le32(addr, set) setbits(le32, addr, set) -#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) - -#define clrbits_be16(addr, clear) clrbits(be16, addr, clear) -#define setbits_be16(addr, set) setbits(be16, addr, set) -#define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) - -#define clrbits_le16(addr, clear) clrbits(le16, addr, clear) -#define setbits_le16(addr, set) setbits(le16, addr, set) -#define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) - -#define clrbits_8(addr, clear) clrbits(8, addr, clear) -#define setbits_8(addr, set) setbits(8, addr, set) -#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) - static inline void *phys_to_virt(unsigned long phys) { return (void *)phys; diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig index 6ec71a9..3f10709 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -1,9 +1,12 @@ +source "scripts/Kconfig.include" + config SANDBOX bool select OFTREE select GPIOLIB select ARCH_HAS_UBSAN_SANITIZE_ALL select HAVE_ARCH_KASAN + select HAS_DMA default y config ARCH_TEXT_BASE @@ -20,3 +23,17 @@ default y select ARCH_HAS_STACK_DUMP depends on UBSAN || KASAN + +config CC_IS_64BIT + def_bool $(success,$(srctree)/scripts/gcc-64bitptr.sh $(CC)) + +config CC_HAS_LINUX_I386_SUPPORT + def_bool $(cc-option,-m32) && $(ld-option,-m elf_i386) + +config 64BIT + bool + default n if SANDBOX_LINUX_I386 + default CC_IS_64BIT + +config SANDBOX_LINUX_I386 + bool "32-bit x86 barebox" if CC_HAS_LINUX_I386_SUPPORT diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile index 3917cad..c08ea0c 100644 --- a/arch/sandbox/Makefile +++ b/arch/sandbox/Makefile @@ -52,11 +52,21 @@ SANITIZER_LIBS += -fsanitize=undefined endif -cmd_barebox__ = $(CC) -o $@ -Wl,-T,$(BAREBOX_LDS) \ +ifeq ($(CONFIG_SANDBOX_LINUX_I386),y) +KBUILD_CFLAGS += -m32 +KBUILD_LDFLAGS += -m elf_i386 +KBUILD_AFLAGS += -m32 +BAREBOX_LDFLAGS += -m32 +endif + +BAREBOX_LDFLAGS += \ + -Wl,-T,$(BAREBOX_LDS) \ -Wl,--whole-archive $(BAREBOX_OBJS) -Wl,--no-whole-archive \ -lrt -lpthread $(SDL_LIBS) $(FTDI1_LIBS) \ $(SANITIZER_LIBS) +cmd_barebox__ = $(CC) -o $@ $(BAREBOX_LDFLAGS) + common-y += $(BOARD) arch/sandbox/os/ arch/sandbox/lib/ common-$(CONFIG_OFTREE) += arch/sandbox/dts/ diff --git a/arch/sandbox/include/asm/atomic.h b/arch/sandbox/include/asm/atomic.h new file mode 100644 index 0000000..af12dee --- /dev/null +++ b/arch/sandbox/include/asm/atomic.h @@ -0,0 +1,2 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include diff --git a/arch/sandbox/include/asm/bitsperlong.h b/arch/sandbox/include/asm/bitsperlong.h index 00c1fc2..6dc0bb0 100644 --- a/arch/sandbox/include/asm/bitsperlong.h +++ b/arch/sandbox/include/asm/bitsperlong.h @@ -1,10 +1 @@ -#ifndef __ASM_BITSPERLONG_H -#define __ASM_BITSPERLONG_H - -#ifdef __x86_64__ -#define BITS_PER_LONG 64 -#else -#define BITS_PER_LONG 32 -#endif - -#endif /* __ASM_BITSPERLONG_H */ +#include diff --git a/arch/sandbox/include/asm/dma.h b/arch/sandbox/include/asm/dma.h index 4595367..5e72d8e 100644 --- a/arch/sandbox/include/asm/dma.h +++ b/arch/sandbox/include/asm/dma.h @@ -8,6 +8,57 @@ #ifndef __ASM_DMA_H #define __ASM_DMA_H -/* empty*/ +#include +#include +#include + +#define dma_alloc dma_alloc +static inline void *dma_alloc(size_t size) +{ + return xmemalign(64, ALIGN(size, 64)); +} + +static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle) +{ + void *ret = xmemalign(4096, size); + if (dma_handle) + *dma_handle = (dma_addr_t)ret; + + memset(ret, 0, size); + + return ret; +} + +static inline void *dma_alloc_writecombine(size_t size, dma_addr_t *dma_handle) +{ + return dma_alloc_coherent(size, dma_handle); +} + +static inline void dma_free_coherent(void *mem, dma_addr_t dma_handle, + size_t size) +{ + free(mem); +} + +static inline dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size, + enum dma_data_direction dir) +{ + return (dma_addr_t)ptr; +} + +static inline void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size, + enum dma_data_direction dir) +{ +} + +static inline void dma_sync_single_for_cpu(dma_addr_t address, size_t size, + enum dma_data_direction dir) +{ +} + +static inline void dma_sync_single_for_device(dma_addr_t address, size_t size, + enum dma_data_direction dir) +{ +} #endif /* __ASM_DMA_H */ diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index cb891df..6a0e77a 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -4,5 +4,16 @@ #define IO_SPACE_LIMIT 0 #include +#include + +static inline void *phys_to_virt(unsigned long phys) +{ + return (void *)phys; +} + +static inline unsigned long virt_to_phys(volatile void *mem) +{ + return (unsigned long)mem; +} #endif /* __ASM_SANDBOX_IO_H */ diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile index c012c9c..ed92144 100644 --- a/arch/sandbox/os/Makefile +++ b/arch/sandbox/os/Makefile @@ -6,7 +6,7 @@ KBUILD_CPPFLAGS += -DCONFIG_MALLOC_SIZE=$(CONFIG_MALLOC_SIZE) -KBUILD_CFLAGS := -Wall +KBUILD_CFLAGS += -Wall NOSTDINC_FLAGS := obj-y = common.o tap.o diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c index e67ea14..382a923 100644 --- a/arch/sandbox/os/common.c +++ b/arch/sandbox/os/common.c @@ -236,7 +236,7 @@ filename = devname; snprintf(tmp, sizeof(tmp), devname_template, (*devname_number)++); - devname = strdup(tmp); + devname = tmp; } printf("add %s backed by file %s%s\n", devname, diff --git a/commands/test.c b/commands/test.c index 505b7c5..c845cec 100644 --- a/commands/test.c +++ b/commands/test.c @@ -86,7 +86,6 @@ if (argc < 2) return 1; - last_expr = 0; left = argc - 1; ap = argv + 1; diff --git a/commands/tftp.c b/commands/tftp.c index 1569819..48ff00c 100644 --- a/commands/tftp.c +++ b/commands/tftp.c @@ -20,7 +20,6 @@ { char *source, *dest, *freep; int opt; - unsigned long flags; int tftp_push = 0; int ret; IPaddr_t ip; @@ -46,13 +45,10 @@ else dest = argv[optind]; - if (tftp_push) { + if (tftp_push) dest = freep = basprintf("%s/%s", TFTP_MOUNT_PATH, dest); - flags = O_RDONLY; - } else { + else source = freep = basprintf("%s/%s", TFTP_MOUNT_PATH, source); - flags = O_WRONLY | O_CREAT; - } if (!freep) return -ENOMEM; diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c index 44e3a3c..78cd72d 100644 --- a/drivers/clocksource/arm_global_timer.c +++ b/drivers/clocksource/arm_global_timer.c @@ -20,7 +20,6 @@ #include #include #include -#include #define GT_COUNTER0 0x00 #define GT_COUNTER1 0x04 diff --git a/drivers/ddr/fsl/Kconfig b/drivers/ddr/fsl/Kconfig index 09920bb..b12bf8f 100644 --- a/drivers/ddr/fsl/Kconfig +++ b/drivers/ddr/fsl/Kconfig @@ -1,5 +1,6 @@ config DDR_FSL bool "Freescale DDR support" if COMPILE_TEST + depends on ARM if DDR_FSL diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig index fff9903..b81e72d 100644 --- a/drivers/mtd/nand/Kconfig +++ b/drivers/mtd/nand/Kconfig @@ -98,7 +98,7 @@ config NAND_ORION bool prompt "Marvell Orion NAND driver" - depends on ARCH_KIRKWOOD || COMPILE_TEST + depends on ARM && (ARCH_KIRKWOOD || COMPILE_TEST) help Support for the Orion NAND controller, present in Kirkwood SoCs. diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 00f0f75..3f4c787 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -1688,6 +1688,7 @@ nand_get_device(mtd, FL_READING); ops.len = len; ops.datbuf = buf; + ops.ooblen = 0; ops.oobbuf = NULL; ops.mode = MTD_OPS_PLACE_OOB; ret = nand_do_read_ops(mtd, from, &ops); diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 9bb4985..76509a5 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -155,6 +155,7 @@ config DRIVER_NET_FEC_IMX bool "i.MX FEC Ethernet driver" depends on ARCH_HAS_FEC_IMX || COMPILE_TEST + depends on HAS_DMA select PHYLIB config DRIVER_NET_FSL_FMAN @@ -180,6 +181,7 @@ config DRIVER_NET_MACB bool "macb Ethernet driver" depends on HAS_MACB || COMPILE_TEST + depends on HAS_DMA select PHYLIB config DRIVER_NET_MICREL diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 886cbef..9ffbb10 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -17,8 +17,8 @@ #define HOST_XHCI_H_ #include -#include #include +#include #include #define MAX_EP_CTX_NUM 31 @@ -1113,10 +1113,7 @@ #if BITS_PER_LONG == 64 return readq(regs); #else - __u32 *ptr = (__u32 *)regs; - u64 val_lo = readl(ptr); - u64 val_hi = readl(ptr + 1); - return val_lo + (val_hi << 32); + return lo_hi_readq(regs); #endif } @@ -1125,12 +1122,7 @@ #if BITS_PER_LONG == 64 writeq(val, regs); #else - __u32 *ptr = (__u32 *)regs; - u32 val_lo = lower_32_bits(val); - /* FIXME */ - u32 val_hi = upper_32_bits(val); - writel(val_lo, ptr); - writel(val_hi, ptr + 1); + lo_hi_writeq(val, regs); #endif } diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h new file mode 100644 index 0000000..449ceca --- /dev/null +++ b/include/asm-generic/atomic.h @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * based on linux/include/asm-arm/atomic.h + * + * Copyright (c) 1996 Russell King. + */ + +#ifndef __ASM_GENERIC_ATOMIC_H +#define __ASM_GENERIC_ATOMIC_H + +#ifdef CONFIG_SMP +#error SMP not supported +#endif + +typedef struct { volatile int counter; } atomic_t; + +#define ATOMIC_INIT(i) { (i) } + +#define atomic_read(v) ((v)->counter) +#define atomic_set(v,i) (((v)->counter) = (i)) + +static inline void atomic_add(int i, volatile atomic_t *v) +{ + v->counter += i; +} + +static inline void atomic_sub(int i, volatile atomic_t *v) +{ + v->counter -= i; +} + +static inline void atomic_inc(volatile atomic_t *v) +{ + v->counter += 1; +} + +static inline void atomic_dec(volatile atomic_t *v) +{ + v->counter -= 1; +} + +static inline int atomic_dec_and_test(volatile atomic_t *v) +{ + int val; + + val = v->counter; + v->counter = val -= 1; + + return val == 0; +} + +static inline int atomic_add_negative(int i, volatile atomic_t *v) +{ + int val; + + val = v->counter; + v->counter = val += i; + + return val < 0; +} + +static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) +{ + *addr &= ~mask; +} + +/* Atomic operations are already serializing on ARM */ +#define smp_mb__before_atomic_dec() barrier() +#define smp_mb__after_atomic_dec() barrier() +#define smp_mb__before_atomic_inc() barrier() +#define smp_mb__after_atomic_inc() barrier() + +#endif diff --git a/include/asm-generic/bitio.h b/include/asm-generic/bitio.h new file mode 100644 index 0000000..e88dbd7 --- /dev/null +++ b/include/asm-generic/bitio.h @@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#ifndef __ASM_GENERIC_BITIO_H +#define __ASM_GENERIC_BITIO_H + +#include + +/* + * Clear and set bits in one shot. These macros can be used to clear and + * set multiple bits in a register using a single call. These macros can + * also be used to set a multiple-bit bit pattern using a mask, by + * specifying the mask in the 'clear' parameter and the new bit pattern + * in the 'set' parameter. + */ + +#ifndef out_arch +#define out_arch(type,endian,a,v) __raw_write##type(cpu_to_##endian(v),a) +#endif + +#ifndef in_arch +#define in_arch(type,endian,a) endian##_to_cpu(__raw_read##type(a)) +#endif + +#ifndef out_le64 +#define out_le64(a,v) out_arch(q,le64,a,v) +#endif + +#ifndef out_le32 +#define out_le32(a,v) out_arch(l,le32,a,v) +#endif + +#ifndef out_le16 +#define out_le16(a,v) out_arch(w,le16,a,v) +#endif + +#ifndef in_le64 +#define in_le64(a) in_arch(q,le64,a) +#endif + +#ifndef in_le32 +#define in_le32(a) in_arch(l,le32,a) +#endif + +#ifndef in_le16 +#define in_le16(a) in_arch(w,le16,a) +#endif + +#ifndef out_be32 +#define out_be32(a,v) out_arch(l,be32,a,v) +#endif + +#ifndef out_be16 +#define out_be16(a,v) out_arch(w,be16,a,v) +#endif + +#ifndef in_be32 +#define in_be32(a) in_arch(l,be32,a) +#endif + +#ifndef in_be16 +#define in_be16(a) in_arch(w,be16,a) +#endif + +#ifndef out_8 +#define out_8(a,v) __raw_writeb(v,a) +#endif + +#ifndef in_8 +#define in_8(a) __raw_readb(a) +#endif + +#ifndef clrbits +#define clrbits(type, addr, clear) \ + out_##type((addr), in_##type(addr) & ~(clear)) +#endif + +#ifndef setbits +#define setbits(type, addr, set) \ + out_##type((addr), in_##type(addr) | (set)) +#endif + +#define clrsetbits(type, addr, clear, set) \ + out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) + +#ifndef clrbits_be32 +#define clrbits_be32(addr, clear) clrbits(be32, addr, clear) +#endif + +#ifndef setbits_be32 +#define setbits_be32(addr, set) setbits(be32, addr, set) +#endif + +#ifndef clrsetbits_be32 +#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) +#endif + +#ifndef clrbits_le32 +#define clrbits_le32(addr, clear) clrbits(le32, addr, clear) +#endif + +#ifndef setbits_le32 +#define setbits_le32(addr, set) setbits(le32, addr, set) +#endif + +#ifndef clrsetbits_le32 +#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) +#endif + +#ifndef clrbits_be16 +#define clrbits_be16(addr, clear) clrbits(be16, addr, clear) +#endif + +#ifndef setbits_be16 +#define setbits_be16(addr, set) setbits(be16, addr, set) +#endif + +#ifndef clrsetbits_be16 +#define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) +#endif + +#ifndef clrbits_le16 +#define clrbits_le16(addr, clear) clrbits(le16, addr, clear) +#endif + +#ifndef setbits_le16 +#define setbits_le16(addr, set) setbits(le16, addr, set) +#endif + +#ifndef clrsetbits_le16 +#define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) +#endif + +#ifndef clrbits_8 +#define clrbits_8(addr, clear) clrbits(8, addr, clear) +#endif + +#ifndef setbits_8 +#define setbits_8(addr, set) setbits(8, addr, set) +#endif + +#ifndef clrsetbits_8 +#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) +#endif + +#endif /* __ASM_GENERIC_IO_H */ diff --git a/include/asm-generic/bitops/ffs.h b/include/asm-generic/bitops/ffs.h index fbbb43a..0ff1b8b 100644 --- a/include/asm-generic/bitops/ffs.h +++ b/include/asm-generic/bitops/ffs.h @@ -31,10 +31,8 @@ x >>= 2; r += 2; } - if (!(x & 1)) { - x >>= 1; + if (!(x & 1)) r += 1; - } return r; } diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h index 850859b..cc0d3ca 100644 --- a/include/asm-generic/bitops/fls.h +++ b/include/asm-generic/bitops/fls.h @@ -31,10 +31,8 @@ x <<= 2; r -= 2; } - if (!(x & 0x80000000u)) { - x <<= 1; + if (!(x & 0x80000000u)) r -= 1; - } return r; } diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include new file mode 100644 index 0000000..496d11c --- /dev/null +++ b/scripts/Kconfig.include @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Kconfig helper macros + +# Convenient variables +comma := , +quote := " +squote := ' +empty := +space := $(empty) $(empty) +dollar := $ +right_paren := ) +left_paren := ( + +# $(if-success,,,) +# Return if exits with 0, otherwise. +if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") + +# $(success,) +# Return y if exits with 0, n otherwise +success = $(if-success,$(1),y,n) + +# $(failure,) +# Return n if exits with 0, y otherwise +failure = $(if-success,$(1),n,y) + +# $(cc-option,) +# Return y if the compiler supports , n otherwise +cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null) + +# $(ld-option,) +# Return y if the linker supports , n otherwise +ld-option = $(success,$(LD) -v $(1)) + +# $(as-instr,) +# Return y if the assembler supports , n otherwise +as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -) + +# check if $(CC) and $(LD) exist +$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found) +$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found) + +# Fail if the linker is gold as it's not capable of linking the kernel proper +$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported) + +# gcc version including patch level +gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh $(CC)) + +# machine bit flags +# $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. +# $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise. +cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1)) +m32-flag := $(cc-option-bit,-m32) +m64-flag := $(cc-option-bit,-m64) diff --git a/scripts/gcc-64bitptr.sh b/scripts/gcc-64bitptr.sh new file mode 100755 index 0000000..7fb0570 --- /dev/null +++ b/scripts/gcc-64bitptr.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only + +cat << "END" | $@ -x c - -c -o /dev/null +int main(void) +{ + return sizeof(struct { int:-!(sizeof(void *) == 8); }); +} +END diff --git a/scripts/gcc-version.sh b/scripts/gcc-version.sh new file mode 100755 index 0000000..ae35343 --- /dev/null +++ b/scripts/gcc-version.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# gcc-version gcc-command +# +# Print the gcc version of `gcc-command' in a 5 or 6-digit form +# such as `29503' for gcc-2.95.3, `30301' for gcc-3.3.1, etc. + +compiler="$*" + +if [ ${#compiler} -eq 0 ]; then + echo "Error: No compiler specified." >&2 + printf "Usage:\n\t$0 \n" >&2 + exit 1 +fi + +MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1) +MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1) +PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1) +printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL