Path: blob/main/sys/tools/syscalls/scripts/syscall_mk.lua
39530 views
#!/usr/libexec/flua1--2-- SPDX-License-Identifier: BSD-2-Clause3--4-- Copyright (c) 2024 Tyler Baxter <[email protected]>5-- Copyright (c) 2023 Warner Losh <[email protected]>6-- Copyright (c) 2019 Kyle Evans <[email protected]>7--89-- Setup to be a module, or ran as its own script.10local syscall_mk = {}11local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script.12if script then13-- Add library root to the package path.14local path = arg[0]:gsub("/[^/]+.lua$", "")15package.path = package.path .. ";" .. path .. "/../?.lua"16end1718local FreeBSDSyscall = require("core.freebsd-syscall")19local generator = require("tools.generator")2021-- File has not been decided yet; config will decide file. Default defined as22-- /dev/null.23syscall_mk.file = "/dev/null"2425-- Libc has all the STD, NOSTD and SYSMUX system calls in it, as well as26-- replaced system calls dating back to FreeBSD 7. We are lucky that the27-- system call filename is just the base symbol name for it.28function syscall_mk.generate(tbl, config, fh)29-- Grab the master system calls table.30local s = tbl.syscalls31-- Bookkeeping for keeping track of when we're at the last system32-- call (no backslash).33local size = #s34local idx = 03536-- Bind the generator to the parameter file.37local gen = generator:new({}, fh)3839-- Write the generated preamble.40gen:preamble("FreeBSD system call object files.", "#")4142gen:write("MIASM = \\\n") -- preamble43for _, v in pairs(s) do44local c = v:compatLevel()45local bs = " \\"46idx = idx + 147if (v:native() or c >= 7) and not v.type.NODEF and not v.type.NOLIB then48if idx >= size then49-- At last system call, no backslash.50bs = ""51end52gen:write(string.format("\t%s.o%s\n", v:symbol(), bs))53end54end55end5657-- Entry of script:58if script then59local config = require("config")6061if #arg < 1 or #arg > 2 then62error("usage: " .. arg[0] .. " syscall.master")63end6465local sysfile, configfile = arg[1], arg[2]6667config.merge(configfile)68config.mergeCompat()6970-- The parsed syscall table.71local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}7273syscall_mk.file = config.sysmk -- change file here74syscall_mk.generate(tbl, config, syscall_mk.file)75end7677-- Return the module.78return syscall_mk798081