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) ; 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 $(TARGET_HDRS_$(architecture)) ; 47 48 HDRS on $(preprocessedHeader) = $(headers) ; 49 SYSHDRS on $(preprocessedHeader) = $(sysHeaders) ; 50 51 HDRRULE on $(header) = HdrRule ; 52 HDRSCAN on $(header) = $(HDRPATTERN) ; 53 HDRSEARCH on $(header) = $(headers) $(sysHeaders) $(STDHDRS) ; 54 HDRGRIST on $(header) = $(HDRGRIST) ; 55 56 DEFINES on $(preprocessedHeader) += $(TARGET_DEFINES_$(architecture)) 57 $(TARGET_DEFINES) GEN_SYSCALL_INFOS_PROCESSING ; 58 59 CC on $(preprocessedHeader) = $(TARGET_C++_$(architecture)) ; 60 CCFLAGS on $(preprocessedHeader) += $(TARGET_CCFLAGS_$(architecture)) 61 $(SUBDIRCCFLAGS) $(OPTIM) ; 62 CCHDRS on $(preprocessedHeader) = 63 [ FIncludes $(headers) 64 : $(TARGET_LOCAL_INCLUDES_OPTION_$(architecture)) ] 65 $(TARGET_INCLUDES_SEPARATOR_$(architecture)) 66 [ FSysIncludes $(sysHeaders) 67 : $(TARGET_SYSTEM_INCLUDES_OPTION_$(architecture)) ] ; 68 CCDEFS on $(preprocessedHeader) 69 = [ on $(preprocessedHeader) FDefines $(DEFINES) ] ; 70} 71 72 73actions PreprocessSyscalls 74{ 75 $(CC) -xc++ -E "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 76} 77 78 79rule GenSyscallInfos targets : sources : gensyscallinfos 80{ 81 Depends $(targets) : $(gensyscallinfos) $(sources) ; 82 GenSyscallInfos1 $(targets) : $(gensyscallinfos) $(sources) ; 83} 84 85 86actions GenSyscallInfos1 87{ 88 $(2[1]) $(2[2]) $(1) 89} 90 91 92rule GenSyscallsFile file : gensyscalls : option 93{ 94 GENSYSCALLS_FILE_OPTION on $(file) = $(option) ; 95 Depends $(file) : $(gensyscalls) ; 96 GenSyscallsFile1 $(file) : $(gensyscalls) ; 97} 98 99 100actions GenSyscallsFile1 101{ 102 $(2[1]) $(GENSYSCALLS_FILE_OPTION) $(1) 103} 104 105 106local syscallsHeader = [ FGristFiles syscalls.h ] ; 107SEARCH on $(syscallsHeader) = [ FDirName $(HAIKU_TOP) headers private system ] ; 108 109local architectureObject ; 110for architectureObject in [ MultiArchSubDirSetup ] { 111 on $(architectureObject) { 112 local architecture = $(TARGET_PACKAGING_ARCH) ; 113 114 # Generate the preprocessed syscalls.h header. It will be parsed by 115 # gensyscallinfos (it contains marker #pragmas). 116 local syscallsHeaderPPParsable 117 = [ FGristFiles syscalls.h.pp.parsable ] ; 118 MakeLocateArch $(syscallsHeaderPPParsable) ; 119 PreprocessSyscalls $(syscallsHeaderPPParsable) : $(syscallsHeader) 120 : $(architecture) ; 121 122 # build gensyscallinfos 123 124 local gensyscallinfos = gensyscallinfos_$(architecture) ; 125 SourceHdrs gensyscallinfos.cpp 126 : [ FDirName $(SUBDIR) arch $(TARGET_ARCH_$(architecture)) ] ; 127 BuildPlatformMain $(gensyscallinfos) 128 : gensyscallinfos.cpp 129 : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) 130 ; 131 132 # generate the syscall infos source file and the source for the header 133 # it includes 134 135 local syscallInfos = [ FGristFiles gensyscalls_infos.cpp ] ; 136 local syscallTypesSizesSource 137 = [ FGristFiles syscall_types_sizes.h.cpp ] ; 138 local syscallTypesSizes = [ FGristFiles syscall_types_sizes.h ] ; 139 MakeLocateArch $(syscallInfos) $(syscallTypesSizesSource) 140 $(syscallTypesSizes) ; 141 142 GenSyscallInfos $(syscallInfos) $(syscallTypesSizesSource) 143 : $(syscallsHeaderPPParsable) : $(gensyscallinfos) ; 144 145 TARGET_HDRS_$(architecture) on $(syscallTypesSizes) 146 = [ on $(syscallTypesSizes) return $(TARGET_HDRS_$(architecture)) ] 147 [ FDirName $(SUBDIR) arch $(TARGET_ARCH_$(architecture)) ] 148 $(TARGET_PRIVATE_SYSTEM_HEADERS_$(architecture)) ; 149 CreateAsmStructOffsetsHeader $(syscallTypesSizes) 150 : $(syscallTypesSizesSource) ; 151 152 #Includes $(syscallInfos) : $(syscallTypesSizes) ; 153 # explicitly tell jam about the inclusion of the generated header 154 Depends $(syscallInfos:S=$(SUFOBJ)) : $(syscallTypesSizes) ; 155 # NOTE: Jam messes up the "Includes" declaration, so we have to declare 156 # the dependency more directly. 157 158 # build gensyscalls 159 160 local gensyscalls = gensyscalls_$(architecture) ; 161 BuildPlatformMain $(gensyscalls) 162 : gensyscalls.cpp $(syscallInfos) ; 163 LinkAgainst $(gensyscalls) : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; 164 165 # generate the output files 166 167 # place them where they are needed 168 local dir = $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(architecture)) ; 169 MakeLocate <syscalls!$(architecture)>syscalls.S.inc 170 : [ FDirName $(dir) system libroot os ] ; 171 MakeLocate <syscalls!$(architecture)>syscall_dispatcher.h 172 : [ FDirName $(dir) system kernel ] ; 173 MakeLocate <syscalls!$(architecture)>syscall_numbers.h 174 : [ FDirName $(dir) system kernel ] ; 175 MakeLocate <syscalls!$(architecture)>syscall_table.h 176 : [ FDirName $(dir) system kernel ] ; 177 MakeLocate <syscalls!$(architecture)>strace_syscalls.h 178 : [ FDirName $(dir) bin debug strace ] ; 179 180 GenSyscallsFile <syscalls!$(architecture)>syscalls.S.inc 181 : $(gensyscalls) : -c ; 182 GenSyscallsFile <syscalls!$(architecture)>syscall_dispatcher.h 183 : $(gensyscalls) : -d ; 184 GenSyscallsFile <syscalls!$(architecture)>syscall_numbers.h 185 : $(gensyscalls) : -n ; 186 GenSyscallsFile <syscalls!$(architecture)>syscall_table.h 187 : $(gensyscalls) : -t ; 188 GenSyscallsFile <syscalls!$(architecture)>strace_syscalls.h 189 : $(gensyscalls) : -s ; 190 } 191} 192