1SubDir HAIKU_TOP src tools gensyscalls ; 2 3SubDirHdrs [ FDirName $(SUBDIR) arch $(TARGET_ARCH) ] ; 4 5 6# What want to do here is analyze the <syscalls.h> header and generate headers 7# and sources containing information about the syscalls (like what parameters 8# of what sizes and types they take, etc.) which will be used in other places 9# (e.g. the kernel code or the strace tool). 10# 11# The strategy to achieve this is: 12# * Preprocess the <syscalls.h> header, so that it is easier to parse. 13# * Feed the preprocessed header to the gensyscallinfos tool. It will generate 14# a source file, gensyscalls_infos.cpp, which implements a function that 15# builds a table with all the syscall info information we need. The source 16# file needs specific infos about sizes of types, which aren't easily 17# available. That's why gensyscallinfos also generates a source file which 18# via the CreateAsmStructOffsetsHeader rule is turned into a header with 19# macro definitions for those type size. The header is included by 20# gensyscalls_infos.cpp. 21# * gensyscalls.cpp and the generated gensyscalls_infos.cpp are compiled into 22# the gensyscalls tool. 23# * gensyscalls has options to generate the various output files: 24# - <syscalls>syscalls.S.inc: Used to define the syscall functions in libroot. 25# - <syscalls>syscall_dispatcher.h: Big "switch" statement for the syscall 26# dispatcher in the kernel. 27# - <syscalls>syscall_numbers.h: Macro definitions assigning indices to the 28# syscalls. 29# - <syscalls>syscall_table.h: An array with syscall information in the 30# kernel. Used for dispatching syscalls e.g. for x86. 31# - <syscalls>strace_syscalls.h: Syscall information needed by strace. 32 33 34# preprocess the syscalls header 35 36rule PreprocessSyscalls 37{ 38 # PreprocessSyscalls <preprocessedHeader> : <header> ; 39 40 Depends $(<) : $(>) ; 41 42 local headers = [ on $(1) return $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ; 43 local sysHeaders = 44 $(TARGET_PRIVATE_SYSTEM_HEADERS) 45 [ ArchHeaders $(TARGET_KERNEL_ARCH) ] 46 [ on $(1) return $(SUBDIRSYSHDRS) $(SYSHDRS) ] 47 $(HAIKU_HDRS) ; 48 49 HDRS on $(<) = $(headers) ; 50 SYSHDRS on $(<) = $(sysHeaders) ; 51 52 HDRRULE on $(>) = HdrRule ; 53 HDRSCAN on $(>) = $(HDRPATTERN) ; 54 HDRSEARCH on $(>) = $(headers) $(sysHeaders) $(STDHDRS) ; 55 HDRGRIST on $(>) = $(HDRGRIST) ; 56 57 DEFINES on $(<) += $(HAIKU_DEFINES) GEN_SYSCALL_INFOS_PROCESSING ; 58 59 CCFLAGS on $(<) += $(HAIKU_CCFLAGS) $(SUBDIRCCFLAGS) $(OPTIM) ; 60 CCHDRS on $(<) = [ FIncludes $(headers) : $(HAIKU_LOCAL_INCLUDES_OPTION) ] 61 $(HAIKU_INCLUDES_SEPARATOR) 62 [ FSysIncludes $(sysHeaders) : $(HAIKU_SYSTEM_INCLUDES_OPTION) ] ; 63 CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 64} 65 66actions PreprocessSyscalls 67{ 68 $(HAIKU_C++) -xc++ -E "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 69} 70 71local syscallsHeader = [ FGristFiles syscalls.h ] ; 72SEARCH on $(syscallsHeader) = [ FDirName $(HAIKU_TOP) headers private system ] ; 73 74# Generate the preprocessed syscalls.h header. It will be parsed by 75# gensyscallinfos (it contains marker #pragmas). 76local syscallsHeaderPPParsable = [ FGristFiles syscalls.h.pp.parsable ] ; 77MakeLocateArch $(syscallsHeaderPPParsable) ; 78PreprocessSyscalls $(syscallsHeaderPPParsable) : $(syscallsHeader) ; 79 80 81# build gensyscallinfos 82 83BuildPlatformMain gensyscallinfos 84 : gensyscallinfos.cpp 85 : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) 86; 87 88 89# generate the syscall infos source file and the source for the header it 90# includes 91 92local syscallInfos = [ FGristFiles gensyscalls_infos.cpp ] ; 93local syscallTypesSizesSource = [ FGristFiles syscall_types_sizes.h.cpp ] ; 94local syscallTypesSizes = [ FGristFiles syscall_types_sizes.h ] ; 95MakeLocateArch $(syscallInfos) $(syscallTypesSizesSource) $(syscallTypesSizes) ; 96 97rule GenSyscallInfos 98{ 99 Depends $(1) : gensyscallinfos $(2) ; 100 GenSyscallInfos1 $(1) : gensyscallinfos $(2) ; 101} 102 103actions GenSyscallInfos1 104{ 105 $(2[1]) $(2[2]) $(1) 106} 107 108GenSyscallInfos $(syscallInfos) $(syscallTypesSizesSource) 109 : $(syscallsHeaderPPParsable) ; 110 111TARGET_HDRS on $(syscallTypesSizes) 112 = [ on $(syscallTypesSizes) return $(TARGET_HDRS) ] 113 $(TARGET_PRIVATE_SYSTEM_HEADERS) ; 114CreateAsmStructOffsetsHeader $(syscallTypesSizes) : $(syscallTypesSizesSource) ; 115 116#Includes $(syscallInfos) : $(syscallTypesSizes) ; 117 # explicitly tell jam about the inclusion of the generated header 118Depends $(syscallInfos:S=$(SUFOBJ)) : $(syscallTypesSizes) ; 119 # NOTE: Jam messes up the "Includes" declaration, so we have to declare 120 # the dependency more directly. 121 122 123# build gensyscalls 124 125BuildPlatformMain gensyscalls : gensyscalls.cpp $(syscallInfos) ; 126LinkAgainst gensyscalls : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; 127 128 129# generate the output files 130 131# place them where they are needed 132local dir = $(HAIKU_COMMON_DEBUG_OBJECT_DIR) ; 133MakeLocate <syscalls>syscalls.S.inc : [ FDirName $(dir) system libroot os ] ; 134MakeLocate <syscalls>syscall_dispatcher.h : [ FDirName $(dir) system kernel ] ; 135MakeLocate <syscalls>syscall_numbers.h : [ FDirName $(dir) system kernel ] ; 136MakeLocate <syscalls>syscall_table.h : [ FDirName $(dir) system kernel ] ; 137MakeLocate <syscalls>strace_syscalls.h : [ FDirName $(dir) bin debug strace ] ; 138 139rule GenSyscallsFile file : option 140{ 141 GENSYSCALLS_FILE_OPTION on $(file) = $(option) ; 142 Depends $(file) : gensyscalls ; 143 GenSyscallsFile1 $(file) : gensyscalls ; 144} 145 146actions GenSyscallsFile1 147{ 148 $(2[1]) $(GENSYSCALLS_FILE_OPTION) $(1) 149} 150 151GenSyscallsFile <syscalls>syscalls.S.inc : -c ; 152GenSyscallsFile <syscalls>syscall_dispatcher.h : -d ; 153GenSyscallsFile <syscalls>syscall_numbers.h : -n ; 154GenSyscallsFile <syscalls>syscall_table.h : -t ; 155GenSyscallsFile <syscalls>strace_syscalls.h : -s ; 156