1*4b9c6d91SCole Faust#!/bin/sh 2*4b9c6d91SCole Faust 3*4b9c6d91SCole Faust# Copyright 2012 The ChromiumOS Authors 4*4b9c6d91SCole Faust# Use of this source code is governed by a BSD-style license that can be 5*4b9c6d91SCole Faust# found in the LICENSE file. 6*4b9c6d91SCole Faust 7*4b9c6d91SCole Faust# Generates a header file with a system call table made up of "name", 8*4b9c6d91SCole Faust# syscall_nr entries by including the build target <asm/unistd.h> and 9*4b9c6d91SCole Faust# emitting the list of defines. Use of the compiler is needed to 10*4b9c6d91SCole Faust# dereference the actual provider of syscall definitions. 11*4b9c6d91SCole Faust# E.g., asm/unistd_32.h or asm/unistd_64.h, etc. 12*4b9c6d91SCole Faust 13*4b9c6d91SCole Faustset -e 14*4b9c6d91SCole Faust 15*4b9c6d91SCole Faustif [ $# -ne 1 ] && [ $# -ne 2 ]; then 16*4b9c6d91SCole Faust echo "Usage: $(basename "$0") OUTFILE" 17*4b9c6d91SCole Faust echo "Usage: $(basename "$0") INFILE OUTFILE" 18*4b9c6d91SCole Faust exit 1 19*4b9c6d91SCole Faustfi 20*4b9c6d91SCole Faust 21*4b9c6d91SCole FaustBUILD="${CC} -dD ${SRC:-.}/gen_syscalls.c -E" 22*4b9c6d91SCole FaustGEN_DEPS=1 23*4b9c6d91SCole Faust 24*4b9c6d91SCole Faustif [ $# -eq 2 ]; then 25*4b9c6d91SCole Faust BUILD="cat $1" 26*4b9c6d91SCole Faust GEN_DEPS=0 27*4b9c6d91SCole Faust shift 28*4b9c6d91SCole Faustfi 29*4b9c6d91SCole FaustOUTFILE="$1" 30*4b9c6d91SCole Faust 31*4b9c6d91SCole Faustif [ ${GEN_DEPS} -eq 1 ]; then 32*4b9c6d91SCole Faust # Generate a dependency file which helps the build tool to see when it 33*4b9c6d91SCole Faust # should regenerate ${OUTFILE}. 34*4b9c6d91SCole Faust ${BUILD} -M -MF "${OUTFILE}.d" 35*4b9c6d91SCole Faustfi 36*4b9c6d91SCole Faust 37*4b9c6d91SCole Faust# sed expression which extracts system calls that are 38*4b9c6d91SCole Faust# defined via asm/unistd.h. It converts them from: 39*4b9c6d91SCole Faust# #define __NR_read foo 40*4b9c6d91SCole Faust# to: 41*4b9c6d91SCole Faust# #ifdef __NR_read 42*4b9c6d91SCole Faust# { "read", __NR_read }, 43*4b9c6d91SCole Faust# #endif 44*4b9c6d91SCole FaustSED_MULTILINE='s/#define __(ARM_)?(NR_)([[:lower:]0-9_]*) (.*)$/#ifdef __\1\2\3\ 45*4b9c6d91SCole Faust{ "\1\3", __\1\2\3 },\ 46*4b9c6d91SCole Faust#endif/g p;' 47*4b9c6d91SCole Faust 48*4b9c6d91SCole Faustcat <<-EOF > "${OUTFILE}" 49*4b9c6d91SCole Faust/* GENERATED BY MAKEFILE */ 50*4b9c6d91SCole Faust#include <stddef.h> 51*4b9c6d91SCole Faust#include "gen_syscalls-inl.h" 52*4b9c6d91SCole Faust#include "libsyscalls.h" 53*4b9c6d91SCole Faustconst struct syscall_entry syscall_table[] = { 54*4b9c6d91SCole Faust$(${BUILD} | sed -Ene "${SED_MULTILINE}") 55*4b9c6d91SCole Faust { NULL, -1 }, 56*4b9c6d91SCole Faust}; 57*4b9c6d91SCole Faust 58*4b9c6d91SCole Faustconst size_t syscall_table_size = 59*4b9c6d91SCole Faust sizeof(syscall_table) / sizeof(syscall_table[0]); 60*4b9c6d91SCole FaustEOF 61