内核代码如何判断是arm还是x86? 用户态代码呢
内核代码如何判断是arm还是x86? 用户态代码呢google不到 获得该信息的方法应该很多,我这里提供一种.
请查看文件 /源码/include/generated/compile.h
里面有一个根据编译生成的宏 UTS_MACHINE ,该宏会提示是 ARM 还是 X86 最初应该是makefile里得到的
# SUBARCH tells the usermode build what the underlying arch is.That is set
# first, and if a usermode build is happening, the "ARCH=um" on the command
# line overrides the setting of ARCH below.If a native build is happening,
# then ARCH is assigned, getting whatever value it gets normally, and
# SUBARCH is subsequently ignored.
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-e s/sh.*/sh/ -e s/aarch64.*/arm64/ )
内核里像字节序这样的东西一定是要根据CPU型号来的,例如下面的ip头定义,始终找不到源头
struct iphdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u8 ihl:4,
version:4;
#elif defined (__BIG_ENDIAN_BITFIELD)
__u8 version:4,
ihl:4;
#else
#error "Please fix <asm/byteorder.h>"
#endif
__u8 tos;
__be16 tot_len;
__be16 id;
__be16 frag_off;
__u8 ttl;
__u8 protocol;
__sum16 check;
__be32 saddr;
__be32 daddr;
/*The options start here. */
};
直接在#if defined(__LITTLE_ENDIAN_BITFIELD) 下面加一个 #error 编译一下就知道了
页:
[1]