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