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 idx = idx + 1 47 if v:native() and not v.type.NODEF and not v.type.NOLIB then 48 if idx >= size then 49 -- At last system call, no backslash. 50 gen:write(string.format("\t%s.o\n", v:symbol())) 51 else 52 -- Normal behavior. 53 gen:write(string.format("\t%s.o \\\n", v:symbol())) 54 end 55 -- Handle compat (everything >= FREEBSD3): 56 elseif c >= 7 and not v.type.NODEF and not v.type.NOLIB then 57 if idx >= size then 58 -- At last system call, no backslash. 59 gen:write(string.format("\t%s.o\n", v:symbol())) 60 else 61 -- Normal behavior. 62 gen:write(string.format("\t%s.o \\\n", v:symbol())) 63 end 64 end 65 end 66end 67 68-- Entry of script: 69if script then 70 local config = require("config") 71 72 if #arg < 1 or #arg > 2 then 73 error("usage: " .. arg[0] .. " syscall.master") 74 end 75 76 local sysfile, configfile = arg[1], arg[2] 77 78 config.merge(configfile) 79 config.mergeCompat() 80 81 -- The parsed syscall table. 82 local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config} 83 84 syscall_mk.file = config.sysmk -- change file here 85 syscall_mk.generate(tbl, config, syscall_mk.file) 86end 87 88-- Return the module. 89return syscall_mk 90