1#!/usr/libexec/flua 2-- 3-- SPDX-License-Identifier: BSD-2-Clause 4-- 5-- Copyright (c) 2024 Tyler Baxter <agge@FreeBSD.org> 6-- Copyright (c) 2023 Warner Losh <imp@bsdimp.com> 7-- Copyright (c) 2019 Kyle Evans <kevans@FreeBSD.org> 8-- 9 10-- Setup to be a module, or ran as its own script. 11local syscall_mk = {} 12local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script. 13if script then 14 -- Add library root to the package path. 15 local path = arg[0]:gsub("/[^/]+.lua$", "") 16 package.path = package.path .. ";" .. path .. "/../?.lua" 17end 18 19local FreeBSDSyscall = require("core.freebsd-syscall") 20local generator = require("tools.generator") 21 22-- File has not been decided yet; config will decide file. Default defined as 23-- /dev/null. 24syscall_mk.file = "/dev/null" 25 26-- Libc has all the STD, NOSTD and SYSMUX system calls in it, as well as 27-- replaced system calls dating back to FreeBSD 7. We are lucky that the 28-- system call filename is just the base symbol name for it. 29function syscall_mk.generate(tbl, config, fh) 30 -- Grab the master system calls table. 31 local s = tbl.syscalls 32 -- Bookkeeping for keeping track of when we're at the last system 33 -- call (no backslash). 34 local size = #s 35 local idx = 0 36 37 -- Bind the generator to the parameter file. 38 local gen = generator:new({}, fh) 39 40 -- Write the generated preamble. 41 gen:preamble("FreeBSD system call object files.", "#") 42 43 gen:write("MIASM = \\\n") -- preamble 44 for _, v in pairs(s) do 45 local c = v:compatLevel() 46 local bs = " \\" 47 idx = idx + 1 48 if (v:native() or c >= 7) and not v.type.NODEF and not v.type.NOLIB then 49 if idx >= size then 50 -- At last system call, no backslash. 51 bs = "" 52 end 53 gen:write(string.format("\t%s.o%s\n", v:symbol(), bs)) 54 end 55 end 56end 57 58-- Entry of script: 59if script then 60 local config = require("config") 61 62 if #arg < 1 or #arg > 2 then 63 error("usage: " .. arg[0] .. " syscall.master") 64 end 65 66 local sysfile, configfile = arg[1], arg[2] 67 68 config.merge(configfile) 69 config.mergeCompat() 70 71 -- The parsed syscall table. 72 local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config} 73 74 syscall_mk.file = config.sysmk -- change file here 75 syscall_mk.generate(tbl, config, syscall_mk.file) 76end 77 78-- Return the module. 79return syscall_mk 80