0

I am making modification on the kernel files. I want to load one function if it is a 32 bit architecture or load another function if it is a 64 bit architecture. Is it possible to get architecture info in the kernel during build time and load different functions based on it. In which location is the architecture info stored or from where to get the info? Thanks.

1 Answers1

2

If you are compiling on the target machine itself, uname -m will give you what you want on most machines. e.g. on my 64-bit desktop machine:

$ uname -m
x86_64

This won't explicitly tell you whether the machine is 64 or 32 bit. It's just a string that you will have to interpret (e.g. with a series of if/then statements or a case statement).

Here's a (very crude) example in sh:

machine=$(uname -m)
bits=0

case "$machine" in
       *64*) bits=64 ;;
  *[3-6]86*) bits=32 ;;
    *armv7*) bits=32 ;;  # replace with a pattern to match your 32-bit android cpu
    *armv8*) bits=64 ;;  # replace with a pattern to match your 64-bit android cpu
esac

[ "$bits" = 0 ] && echo "Unknown machine type" && exit 1
cas
  • 78,579