#!/usr/bin/perl
# This file is part of ltrace.
# Copyright (C) 2006 Heiko Carstens, IBM Corporation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA

#
# Generate syscall table for s390/s390x
#
# Use this on arch/s390/kernel/syscall.s after removing the first few
# nonsyscall lines.
#
# cat syscall.s | mksyscallent_s390 > syscalls31.h
# cat syscall.s | mksyscallent_s390 -x > syscalls64.h
#

use Getopt::Std;
use integer;
getopts('x');
$i = 0;
$s390x = 0;
$opt_x and $s390x = 1;

while (<>) {
	chomp;

	if ($s390x==1) {
		   s/^SYSCALL\([^,]*,//;
	} else {
	           s/^SYSCALL\(//;
	}

	s/,.*//;
	s/^sys_//;
	s/^s390[x]*_//;
	s/_glue$//;
	s/^ni_syscall.*/$i/i;
	$len = 32 - length();
	$tab = $len / 8;
	$space = $len % 8;
	print "    \"$_\"," ," " x $space , "\t" x $tab, " \/* $i \*\/\n";
	$i++;
}