Merge branch 'master' into indexOfScalarPos

This commit is contained in:
Giuseppe Cesarano 2025-08-18 17:40:53 +02:00 committed by GitHub
commit a4b70f3c49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
351 changed files with 32855 additions and 22465 deletions

View file

@ -612,8 +612,6 @@ set(ZIG_STAGE2_SOURCES
src/link/MachO/synthetic.zig
src/link/MachO/Thunk.zig
src/link/MachO/uuid.zig
src/link/Plan9.zig
src/link/Plan9/aout.zig
src/link/Queue.zig
src/link/StringTable.zig
src/link/Wasm.zig

View file

@ -3,7 +3,6 @@ const builtin = std.builtin;
const tests = @import("test/tests.zig");
const BufMap = std.BufMap;
const mem = std.mem;
const ArrayList = std.ArrayList;
const io = std.io;
const fs = std.fs;
const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
@ -925,7 +924,7 @@ fn addCxxKnownPath(
return error.RequiredLibraryNotFound;
const path_padded = run: {
var args = std.ArrayList([]const u8).init(b.allocator);
var args = std.array_list.Managed([]const u8).init(b.allocator);
try args.append(ctx.cxx_compiler);
var it = std.mem.tokenizeAny(u8, ctx.cxx_compiler_arg1, &std.ascii.whitespace);
while (it.next()) |arg| try args.append(arg);

View file

@ -2469,6 +2469,13 @@ or
</p>
{#code|test_union_method.zig#}
<p>
Unions with inferred enum tag types can also assign ordinal values to their inferred tag.
This requires the tag to specify an explicit integer type.
{#link|@intFromEnum#} can be used to access the ordinal value corresponding to the active field.
</p>
{#code|test_tagged_union_with_tag_values.zig#}
<p>
{#link|@tagName#} can be used to return a {#link|comptime#}
{#syntax#}[:0]const u8{#endsyntax#} value representing the field name:
@ -6077,7 +6084,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_close#}
{#header_open|Exact Left Shift Overflow#}
<p>At compile-time:</p>
{#code|test_comptime_shlExact_overwlow.zig#}
{#code|test_comptime_shlExact_overflow.zig#}
<p>At runtime:</p>
{#code|runtime_shlExact_overflow.zig#}
@ -6241,9 +6248,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
C has a default allocator - <code>malloc</code>, <code>realloc</code>, and <code>free</code>.
When linking against libc, Zig exposes this allocator with {#syntax#}std.heap.c_allocator{#endsyntax#}.
However, by convention, there is no default allocator in Zig. Instead, functions which need to
allocate accept an {#syntax#}Allocator{#endsyntax#} parameter. Likewise, data structures such as
{#syntax#}std.ArrayList{#endsyntax#} accept an {#syntax#}Allocator{#endsyntax#} parameter in
their initialization functions:
allocate accept an {#syntax#}Allocator{#endsyntax#} parameter. Likewise, some data structures
accept an {#syntax#}Allocator{#endsyntax#} parameter in their initialization functions:
</p>
{#code|test_allocator.zig#}

View file

@ -3,4 +3,4 @@ comptime {
_ = x;
}
// test_error=operation caused overflow
// test_error=overflow of integer type 'u8' with value '340'

View file

@ -0,0 +1,17 @@
const std = @import("std");
const expect = std.testing.expect;
const Tagged = union(enum(u32)) {
int: i64 = 123,
boolean: bool = 67,
};
test "tag values" {
const int: Tagged = .{ .int = -40 };
try expect(@intFromEnum(int) == 123);
const boolean: Tagged = .{ .boolean = false };
try expect(@intFromEnum(boolean) == 67);
}
// test

View file

@ -1,7 +1,7 @@
const std = @import("std");
test "detect leak" {
var list = std.ArrayList(u21).init(std.testing.allocator);
var list = std.array_list.Managed(u21).init(std.testing.allocator);
// missing `defer list.deinit();`
try list.append('☔');

View file

@ -105,6 +105,7 @@
<th scope="col">Semantic Analysis</th>
<th scope="col">Code Generation</th>
<th scope="col">Linking</th>
<th scope="col">Total</th>
</tr>
</thead>
<!-- HTML does not allow placing a 'slot' inside of a 'tbody' for backwards-compatibility
@ -125,6 +126,7 @@
<th scope="col">Semantic Analysis</th>
<th scope="col">Code Generation</th>
<th scope="col">Linking</th>
<th scope="col">Total</th>
</tr>
</thead>
<!-- HTML does not allow placing a 'slot' inside of a 'tbody' for backwards-compatibility

View file

@ -175,6 +175,7 @@ pub fn compileResultMessage(msg_bytes: []u8) error{OutOfMemory}!void {
\\ <td>{D}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\</tr>
\\
, .{
@ -182,6 +183,7 @@ pub fn compileResultMessage(msg_bytes: []u8) error{OutOfMemory}!void {
file.ns_sema,
file.ns_codegen,
file.ns_link,
file.ns_sema + file.ns_codegen + file.ns_link,
});
}
if (slowest_files.len > max_table_rows) {
@ -203,6 +205,7 @@ pub fn compileResultMessage(msg_bytes: []u8) error{OutOfMemory}!void {
\\ <td>{D}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\</tr>
\\
, .{
@ -212,6 +215,7 @@ pub fn compileResultMessage(msg_bytes: []u8) error{OutOfMemory}!void {
decl.ns_sema,
decl.ns_codegen,
decl.ns_link,
decl.ns_sema + decl.ns_codegen + decl.ns_link,
});
}
if (slowest_decls.len > max_table_rows) {

View file

@ -533,7 +533,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
pub fn generateBuiltinMacros(comp: *Compilation, system_defines_mode: SystemDefinesMode) !Source {
try comp.generateBuiltinTypes();
var buf = std.ArrayList(u8).init(comp.gpa);
var buf = std.array_list.Managed(u8).init(comp.gpa);
defer buf.deinit();
if (system_defines_mode == .include_system_defines) {
@ -1143,7 +1143,7 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, buf: []u8, path: []const u8,
const duped_path = try comp.gpa.dupe(u8, path);
errdefer comp.gpa.free(duped_path);
var splice_list = std.ArrayList(u32).init(comp.gpa);
var splice_list = std.array_list.Managed(u32).init(comp.gpa);
defer splice_list.deinit();
const source_id: Source.Id = @enumFromInt(comp.sources.count() + 2);
@ -1428,7 +1428,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: ?u32) ![]const u
const file = try comp.cwd.openFile(path, .{});
defer file.close();
var buf = std.ArrayList(u8).init(comp.gpa);
var buf = std.array_list.Managed(u8).init(comp.gpa);
defer buf.deinit();
const max = limit orelse std.math.maxInt(u32);

View file

@ -585,10 +585,12 @@ pub fn errorDescription(e: anyerror) []const u8 {
};
}
var stdout_buffer: [4096]u8 = undefined;
/// The entry point of the Aro compiler.
/// **MAY call `exit` if `fast_exit` is set.**
pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_exit: bool) !void {
var macro_buf = std.ArrayList(u8).init(d.comp.gpa);
var macro_buf = std.array_list.Managed(u8).init(d.comp.gpa);
defer macro_buf.deinit();
const std_out = std.fs.File.stdout().deprecatedWriter();
@ -688,13 +690,13 @@ fn processSource(
else
std.fs.File.stdout();
defer if (d.output_name != null) file.close();
var file_buffer: [1024]u8 = undefined;
var file_writer = file.writer(&file_buffer);
var buf_w = std.io.bufferedWriter(file.deprecatedWriter());
pp.prettyPrintTokens(buf_w.writer(), dump_mode) catch |er|
pp.prettyPrintTokens(&file_writer.interface, dump_mode) catch |er|
return d.fatal("unable to write result: {s}", .{errorDescription(er)});
buf_w.flush() catch |er|
file_writer.interface.flush() catch |er|
return d.fatal("unable to write result: {s}", .{errorDescription(er)});
if (fast_exit) std.process.exit(0); // Not linking, no need for cleanup.
return;
@ -704,10 +706,9 @@ fn processSource(
defer tree.deinit();
if (d.verbose_ast) {
const stdout = std.fs.File.stdout();
var buf_writer = std.io.bufferedWriter(stdout.deprecatedWriter());
tree.dump(d.detectConfig(stdout), buf_writer.writer()) catch {};
buf_writer.flush() catch {};
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
tree.dump(d.detectConfig(.stdout()), &stdout_writer.interface) catch {};
stdout_writer.interface.flush() catch {};
}
const prev_errors = d.comp.diagnostics.errors;
@ -734,10 +735,9 @@ fn processSource(
defer ir.deinit(d.comp.gpa);
if (d.verbose_ir) {
const stdout = std.fs.File.stdout();
var buf_writer = std.io.bufferedWriter(stdout.deprecatedWriter());
ir.dump(d.comp.gpa, d.detectConfig(stdout), buf_writer.writer()) catch {};
buf_writer.flush() catch {};
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
ir.dump(d.comp.gpa, d.detectConfig(.stdout()), &stdout_writer.interface) catch {};
stdout_writer.interface.flush() catch {};
}
var render_errors: Ir.Renderer.ErrorList = .{};
@ -817,7 +817,7 @@ fn dumpLinkerArgs(items: []const []const u8) !void {
/// The entry point of the Aro compiler.
/// **MAY call `exit` if `fast_exit` is set.**
pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) !void {
var argv = std.ArrayList([]const u8).init(d.comp.gpa);
var argv = std.array_list.Managed([]const u8).init(d.comp.gpa);
defer argv.deinit();
var linker_path_buf: [std.fs.max_path_bytes]u8 = undefined;

View file

@ -9,7 +9,7 @@ const TokenIndex = Tree.TokenIndex;
const NodeIndex = Tree.NodeIndex;
const Type = @import("Type.zig");
const Diagnostics = @import("Diagnostics.zig");
const NodeList = std.ArrayList(NodeIndex);
const NodeList = std.array_list.Managed(NodeIndex);
const Parser = @import("Parser.zig");
const Item = struct {

View file

@ -15,7 +15,7 @@ const TokenIndex = Tree.TokenIndex;
const NodeIndex = Tree.NodeIndex;
const Type = @import("Type.zig");
const Diagnostics = @import("Diagnostics.zig");
const NodeList = std.ArrayList(NodeIndex);
const NodeList = std.array_list.Managed(NodeIndex);
const InitList = @import("InitList.zig");
const Attribute = @import("Attribute.zig");
const char_info = @import("char_info.zig");
@ -33,7 +33,7 @@ const target_util = @import("target.zig");
const Switch = struct {
default: ?TokenIndex = null,
ranges: std.ArrayList(Range),
ranges: std.array_list.Managed(Range),
ty: Type,
comp: *Compilation,
@ -101,16 +101,16 @@ value_map: Tree.ValueMap,
// buffers used during compilation
syms: SymbolStack = .{},
strings: std.ArrayListAligned(u8, .@"4"),
labels: std.ArrayList(Label),
strings: std.array_list.AlignedManaged(u8, .@"4"),
labels: std.array_list.Managed(Label),
list_buf: NodeList,
decl_buf: NodeList,
param_buf: std.ArrayList(Type.Func.Param),
enum_buf: std.ArrayList(Type.Enum.Field),
record_buf: std.ArrayList(Type.Record.Field),
param_buf: std.array_list.Managed(Type.Func.Param),
enum_buf: std.array_list.Managed(Type.Enum.Field),
record_buf: std.array_list.Managed(Type.Record.Field),
attr_buf: std.MultiArrayList(TentativeAttribute) = .{},
attr_application_buf: std.ArrayListUnmanaged(Attribute) = .empty,
field_attr_buf: std.ArrayList([]const Attribute),
field_attr_buf: std.array_list.Managed([]const Attribute),
/// type name -> variable name location for tentative definitions (top-level defs with thus-far-incomplete types)
/// e.g. `struct Foo bar;` where `struct Foo` is not defined yet.
/// The key is the StringId of `Foo` and the value is the TokenIndex of `bar`
@ -693,16 +693,16 @@ pub fn parse(pp: *Preprocessor) Compilation.Error!Tree {
.gpa = pp.comp.gpa,
.arena = arena.allocator(),
.tok_ids = pp.tokens.items(.id),
.strings = std.ArrayListAligned(u8, .@"4").init(pp.comp.gpa),
.strings = std.array_list.AlignedManaged(u8, .@"4").init(pp.comp.gpa),
.value_map = Tree.ValueMap.init(pp.comp.gpa),
.data = NodeList.init(pp.comp.gpa),
.labels = std.ArrayList(Label).init(pp.comp.gpa),
.labels = std.array_list.Managed(Label).init(pp.comp.gpa),
.list_buf = NodeList.init(pp.comp.gpa),
.decl_buf = NodeList.init(pp.comp.gpa),
.param_buf = std.ArrayList(Type.Func.Param).init(pp.comp.gpa),
.enum_buf = std.ArrayList(Type.Enum.Field).init(pp.comp.gpa),
.record_buf = std.ArrayList(Type.Record.Field).init(pp.comp.gpa),
.field_attr_buf = std.ArrayList([]const Attribute).init(pp.comp.gpa),
.param_buf = std.array_list.Managed(Type.Func.Param).init(pp.comp.gpa),
.enum_buf = std.array_list.Managed(Type.Enum.Field).init(pp.comp.gpa),
.record_buf = std.array_list.Managed(Type.Record.Field).init(pp.comp.gpa),
.field_attr_buf = std.array_list.Managed([]const Attribute).init(pp.comp.gpa),
.string_ids = .{
.declspec_id = try StrInt.intern(pp.comp, "__declspec"),
.main_id = try StrInt.intern(pp.comp, "main"),
@ -1222,7 +1222,7 @@ fn staticAssertMessage(p: *Parser, cond_node: NodeIndex, message: Result) !?[]co
const cond_tag = p.nodes.items(.tag)[@intFromEnum(cond_node)];
if (cond_tag != .builtin_types_compatible_p and message.node == .none) return null;
var buf = std.ArrayList(u8).init(p.gpa);
var buf = std.array_list.Managed(u8).init(p.gpa);
defer buf.deinit();
if (cond_tag == .builtin_types_compatible_p) {
@ -3994,7 +3994,7 @@ fn msvcAsmStmt(p: *Parser) Error!?NodeIndex {
}
/// asmOperand : ('[' IDENTIFIER ']')? asmStr '(' expr ')'
fn asmOperand(p: *Parser, names: *std.ArrayList(?TokenIndex), constraints: *NodeList, exprs: *NodeList) Error!void {
fn asmOperand(p: *Parser, names: *std.array_list.Managed(?TokenIndex), constraints: *NodeList, exprs: *NodeList) Error!void {
if (p.eatToken(.l_bracket)) |l_bracket| {
const ident = (try p.eatIdentifier()) orelse {
try p.err(.expected_identifier);
@ -4044,7 +4044,7 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex
const allocator = stack_fallback.get();
// TODO: Consider using a TokenIndex of 0 instead of null if we need to store the names in the tree
var names = std.ArrayList(?TokenIndex).initCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded
var names = std.array_list.Managed(?TokenIndex).initCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded
defer names.deinit();
var constraints = NodeList.initCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded
defer constraints.deinit();
@ -4317,7 +4317,7 @@ fn stmt(p: *Parser) Error!NodeIndex {
const old_switch = p.@"switch";
var @"switch" = Switch{
.ranges = std.ArrayList(Switch.Range).init(p.gpa),
.ranges = std.array_list.Managed(Switch.Range).init(p.gpa),
.ty = cond.ty,
.comp = p.comp,
};
@ -8268,7 +8268,7 @@ fn charLiteral(p: *Parser) Error!Result {
const max_chars_expected = 4;
var stack_fallback = std.heap.stackFallback(max_chars_expected * @sizeOf(u32), p.comp.gpa);
var chars = std.ArrayList(u32).initCapacity(stack_fallback.get(), max_chars_expected) catch unreachable; // stack allocation already succeeded
var chars = std.array_list.Managed(u32).initCapacity(stack_fallback.get(), max_chars_expected) catch unreachable; // stack allocation already succeeded
defer chars.deinit();
while (char_literal_parser.next()) |item| switch (item) {

View file

@ -17,7 +17,7 @@ const features = @import("features.zig");
const Hideset = @import("Hideset.zig");
const DefineMap = std.StringHashMapUnmanaged(Macro);
const RawTokenList = std.ArrayList(RawToken);
const RawTokenList = std.array_list.Managed(RawToken);
const max_include_depth = 200;
/// Errors that can be returned when expanding a macro.
@ -84,7 +84,7 @@ tokens: Token.List = .{},
/// Do not directly mutate this; must be kept in sync with `tokens`
expansion_entries: std.MultiArrayList(ExpansionEntry) = .{},
token_buf: RawTokenList,
char_buf: std.ArrayList(u8),
char_buf: std.array_list.Managed(u8),
/// Counter that is incremented each time preprocess() is called
/// Can be used to distinguish multiple preprocessings of the same file
preprocess_count: u32 = 0,
@ -131,7 +131,7 @@ pub fn init(comp: *Compilation) Preprocessor {
.gpa = comp.gpa,
.arena = std.heap.ArenaAllocator.init(comp.gpa),
.token_buf = RawTokenList.init(comp.gpa),
.char_buf = std.ArrayList(u8).init(comp.gpa),
.char_buf = std.array_list.Managed(u8).init(comp.gpa),
.poisoned_identifiers = std.StringHashMap(void).init(comp.gpa),
.top_expansion_buf = ExpandBuf.init(comp.gpa),
.hideset = .{ .comp = comp },
@ -811,10 +811,9 @@ fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args:
const source = pp.comp.getSource(raw.source);
const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });
const stderr = std.fs.File.stderr().deprecatedWriter();
var buf_writer = std.io.bufferedWriter(stderr);
const writer = buf_writer.writer();
defer buf_writer.flush() catch {};
var stderr_buffer: [64]u8 = undefined;
var writer = std.debug.lockStderrWriter(&stderr_buffer);
defer std.debug.unlockStderrWriter();
writer.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;
writer.print(fmt, args) catch return;
writer.writeByte('\n') catch return;
@ -983,7 +982,7 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {
.tok_i = @intCast(token_state.tokens_len),
.arena = pp.arena.allocator(),
.in_macro = true,
.strings = std.ArrayListAligned(u8, .@"4").init(pp.comp.gpa),
.strings = std.array_list.AlignedManaged(u8, .@"4").init(pp.comp.gpa),
.data = undefined,
.value_map = undefined,
@ -1141,7 +1140,7 @@ fn skipToNl(tokenizer: *Tokenizer) void {
}
}
const ExpandBuf = std.ArrayList(TokenWithExpansionLocs);
const ExpandBuf = std.array_list.Managed(TokenWithExpansionLocs);
fn removePlacemarkers(buf: *ExpandBuf) void {
var i: usize = buf.items.len -% 1;
while (i < buf.items.len) : (i -%= 1) {
@ -1152,7 +1151,7 @@ fn removePlacemarkers(buf: *ExpandBuf) void {
}
}
const MacroArguments = std.ArrayList([]const TokenWithExpansionLocs);
const MacroArguments = std.array_list.Managed([]const TokenWithExpansionLocs);
fn deinitMacroArguments(allocator: Allocator, args: *const MacroArguments) void {
for (args.items) |item| {
for (item) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, allocator);
@ -2076,7 +2075,7 @@ fn collectMacroFuncArguments(
var parens: u32 = 0;
var args = MacroArguments.init(pp.gpa);
errdefer deinitMacroArguments(pp.gpa, &args);
var curArgument = std.ArrayList(TokenWithExpansionLocs).init(pp.gpa);
var curArgument = std.array_list.Managed(TokenWithExpansionLocs).init(pp.gpa);
defer curArgument.deinit();
while (true) {
var tok = try nextBufToken(pp, tokenizer, buf, start_idx, end_idx, extend_buf);
@ -2646,7 +2645,7 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!
/// Handle a function like #define directive.
fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macro_name: RawToken, l_paren: RawToken) Error!void {
assert(macro_name.id.isMacroIdentifier());
var params = std.ArrayList([]const u8).init(pp.gpa);
var params = std.array_list.Managed([]const u8).init(pp.gpa);
defer params.deinit();
// Parse the parameter list.
@ -3472,7 +3471,7 @@ test "Preserve pragma tokens sometimes" {
const allocator = std.testing.allocator;
const Test = struct {
fn runPreprocessor(source_text: []const u8) ![]const u8 {
var buf = std.ArrayList(u8).init(allocator);
var buf = std.array_list.Managed(u8).init(allocator);
defer buf.deinit();
var comp = Compilation.init(allocator, std.fs.cwd());
@ -3603,7 +3602,7 @@ test "Include guards" {
_ = try comp.addSourceFromBuffer(path, "int bar = 5;\n");
var buf = std.ArrayList(u8).init(allocator);
var buf = std.array_list.Managed(u8).init(allocator);
defer buf.deinit();
var writer = buf.writer();

View file

@ -157,7 +157,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
return use_linker;
}
} else {
var linker_name = try std.ArrayList(u8).initCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker
var linker_name = try std.array_list.Managed(u8).initCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker
defer linker_name.deinit();
if (tc.getTarget().os.tag.isDarwin()) {
linker_name.appendSliceAssumeCapacity("ld64.");
@ -198,7 +198,7 @@ fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8)
}
/// Add toolchain `file_paths` to argv as `-L` arguments
pub fn addFilePathLibArgs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
pub fn addFilePathLibArgs(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
try argv.ensureUnusedCapacity(tc.file_paths.items.len);
var bytes_needed: usize = 0;
@ -332,7 +332,7 @@ pub fn addPathFromComponents(tc: *Toolchain, components: []const []const u8, des
/// Add linker args to `argv`. Does not add path to linker executable as first item; that must be handled separately
/// Items added to `argv` will be string literals or owned by `tc.arena` so they must not be individually freed
pub fn buildLinkerArgs(tc: *Toolchain, argv: *std.ArrayList([]const u8)) !void {
pub fn buildLinkerArgs(tc: *Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
return switch (tc.inner) {
.uninitialized => unreachable,
.linux => |*linux| linux.buildLinkerArgs(tc, argv),
@ -412,7 +412,7 @@ fn getAsNeededOption(is_solaris: bool, needed: bool) []const u8 {
}
}
fn addUnwindLibrary(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
fn addUnwindLibrary(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
const unw = try tc.getUnwindLibKind();
const target = tc.getTarget();
if ((target.abi.isAndroid() and unw == .libgcc) or
@ -450,7 +450,7 @@ fn addUnwindLibrary(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !voi
}
}
fn addLibGCC(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
fn addLibGCC(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
const libgcc_kind = tc.getLibGCCKind();
if (libgcc_kind == .static or libgcc_kind == .unspecified) {
try argv.append("-lgcc");
@ -461,7 +461,7 @@ fn addLibGCC(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
}
}
pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
const target = tc.getTarget();
const rlt = tc.getRuntimeLibKind();
switch (rlt) {

View file

@ -41,7 +41,7 @@ pub const TokenWithExpansionLocs = struct {
pub fn addExpansionLocation(tok: *TokenWithExpansionLocs, gpa: std.mem.Allocator, new: []const Source.Location) !void {
if (new.len == 0 or tok.id == .whitespace or tok.id == .macro_ws or tok.id == .placemarker) return;
var list = std.ArrayList(Source.Location).init(gpa);
var list = std.array_list.Managed(Source.Location).init(gpa);
defer {
@memset(list.items.ptr[list.items.len..list.capacity], .{});
// Add a sentinel to indicate the end of the list since

View file

@ -162,7 +162,7 @@ pub fn getDefaultLinker(self: *const Linux, target: std.Target) []const u8 {
return "ld";
}
pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.ArrayList([]const u8)) Compilation.Error!void {
pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) Compilation.Error!void {
const d = tc.driver;
const target = tc.getTarget();
@ -465,7 +465,7 @@ test Linux {
try toolchain.discover();
var argv = std.ArrayList([]const u8).init(driver.comp.gpa);
var argv = std.array_list.Managed([]const u8).init(driver.comp.gpa);
defer argv.deinit();
var linker_path_buf: [std.fs.max_path_bytes]u8 = undefined;

View file

@ -30,7 +30,7 @@ pub const Section = union(enum) {
custom: []const u8,
};
pub fn getSection(obj: *Object, section: Section) !*std.ArrayList(u8) {
pub fn getSection(obj: *Object, section: Section) !*std.array_list.Managed(u8) {
switch (obj.format) {
.elf => return @as(*Elf, @alignCast(@fieldParentPtr("obj", obj))).getSection(section),
else => unreachable,

View file

@ -4,7 +4,7 @@ const Target = std.Target;
const Object = @import("../Object.zig");
const Section = struct {
data: std.ArrayList(u8),
data: std.array_list.Managed(u8),
relocations: std.ArrayListUnmanaged(Relocation) = .empty,
flags: u64,
type: u32,
@ -80,12 +80,12 @@ fn sectionString(sec: Object.Section) []const u8 {
};
}
pub fn getSection(elf: *Elf, section_kind: Object.Section) !*std.ArrayList(u8) {
pub fn getSection(elf: *Elf, section_kind: Object.Section) !*std.array_list.Managed(u8) {
const section_name = sectionString(section_kind);
const section = elf.sections.get(section_name) orelse blk: {
const section = try elf.arena.allocator().create(Section);
section.* = .{
.data = std.ArrayList(u8).init(elf.arena.child_allocator),
.data = std.array_list.Managed(u8).init(elf.arena.child_allocator),
.type = std.elf.SHT_PROGBITS,
.flags = switch (section_kind) {
.func, .custom => std.elf.SHF_ALLOC + std.elf.SHF_EXECINSTR,
@ -171,8 +171,9 @@ pub fn addRelocation(elf: *Elf, name: []const u8, section_kind: Object.Section,
/// strtab
/// section headers
pub fn finish(elf: *Elf, file: std.fs.File) !void {
var buf_writer = std.io.bufferedWriter(file.deprecatedWriter());
const w = buf_writer.writer();
var file_buffer: [1024]u8 = undefined;
var file_writer = file.writer(&file_buffer);
const w = &file_writer.interface;
var num_sections: std.elf.Elf64_Half = additional_sections;
var relocations_len: std.elf.Elf64_Off = 0;
@ -374,5 +375,5 @@ pub fn finish(elf: *Elf, file: std.fs.File) !void {
name_offset += @as(u32, @intCast(entry.key_ptr.len + ".\x00".len)) + rela_name_offset;
}
}
try buf_writer.flush();
try w.flush();
}

View file

@ -116,7 +116,7 @@ pub fn translate(
var driver: aro.Driver = .{ .comp = comp };
defer driver.deinit();
var macro_buf = std.ArrayList(u8).init(gpa);
var macro_buf = std.array_list.Managed(u8).init(gpa);
defer macro_buf.deinit();
assert(!try driver.parseArgs(std.io.null_writer, macro_buf.writer(), args));
@ -413,11 +413,11 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_ty: Type) Error!void {
break :blk ZigTag.opaque_literal.init();
}
var fields = try std.ArrayList(ast.Payload.Record.Field).initCapacity(c.gpa, record_decl.fields.len);
var fields = try std.array_list.Managed(ast.Payload.Record.Field).initCapacity(c.gpa, record_decl.fields.len);
defer fields.deinit();
// TODO: Add support for flexible array field functions
var functions = std.ArrayList(ZigNode).init(c.gpa);
var functions = std.array_list.Managed(ZigNode).init(c.gpa);
defer functions.deinit();
var unnamed_field_count: u32 = 0;
@ -1234,7 +1234,7 @@ pub const PatternList = struct {
const source = template[0];
const impl = template[1];
var tok_list = std.ArrayList(CToken).init(allocator);
var tok_list = std.array_list.Managed(CToken).init(allocator);
defer tok_list.deinit();
try tokenizeMacro(source, &tok_list);
const tokens = try allocator.dupe(CToken, tok_list.items);
@ -1349,7 +1349,7 @@ pub const TypeError = Error || error{UnsupportedType};
pub const TransError = TypeError || error{UnsupportedTranslation};
pub const SymbolTable = std.StringArrayHashMap(ast.Node);
pub const AliasList = std.ArrayList(struct {
pub const AliasList = std.array_list.Managed(struct {
alias: []const u8,
name: []const u8,
});
@ -1397,7 +1397,7 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ
/// into the main arena.
pub const Block = struct {
base: ScopeExtraScope,
statements: std.ArrayList(ast.Node),
statements: std.array_list.Managed(ast.Node),
variables: AliasList,
mangle_count: u32 = 0,
label: ?[]const u8 = null,
@ -1429,7 +1429,7 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ
.id = .block,
.parent = parent,
},
.statements = std.ArrayList(ast.Node).init(c.gpa),
.statements = std.array_list.Managed(ast.Node).init(c.gpa),
.variables = AliasList.init(c.gpa),
.variable_discards = std.StringArrayHashMap(*ast.Payload.Discard).init(c.gpa),
};
@ -1557,7 +1557,7 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ
sym_table: SymbolTable,
blank_macros: std.StringArrayHashMap(void),
context: *ScopeExtraContext,
nodes: std.ArrayList(ast.Node),
nodes: std.array_list.Managed(ast.Node),
pub fn init(c: *ScopeExtraContext) Root {
return .{
@ -1568,7 +1568,7 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ
.sym_table = SymbolTable.init(c.gpa),
.blank_macros = std.StringArrayHashMap(void).init(c.gpa),
.context = c,
.nodes = std.ArrayList(ast.Node).init(c.gpa),
.nodes = std.array_list.Managed(ast.Node).init(c.gpa),
};
}
@ -1705,7 +1705,7 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ
};
}
pub fn tokenizeMacro(source: []const u8, tok_list: *std.ArrayList(CToken)) Error!void {
pub fn tokenizeMacro(source: []const u8, tok_list: *std.array_list.Managed(CToken)) Error!void {
var tokenizer: aro.Tokenizer = .{
.buf = source,
.source = .unused,
@ -1732,7 +1732,7 @@ test "Macro matching" {
const helper = struct {
const MacroFunctions = std.zig.c_translation.Macros;
fn checkMacro(allocator: mem.Allocator, pattern_list: PatternList, source: []const u8, comptime expected_match: ?[]const u8) !void {
var tok_list = std.ArrayList(CToken).init(allocator);
var tok_list = std.array_list.Managed(CToken).init(allocator);
defer tok_list.deinit();
try tokenizeMacro(source, &tok_list);
const macro_slicer: MacroSlicer = .{ .source = source, .tokens = tok_list.items };

View file

@ -763,7 +763,7 @@ pub const Payload = struct {
pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast {
var ctx = Context{
.gpa = gpa,
.buf = std.ArrayList(u8).init(gpa),
.buf = std.array_list.Managed(u8).init(gpa),
};
defer ctx.buf.deinit();
defer ctx.nodes.deinit(gpa);
@ -787,7 +787,7 @@ pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast {
});
const root_members = blk: {
var result = std.ArrayList(NodeIndex).init(gpa);
var result = std.array_list.Managed(NodeIndex).init(gpa);
defer result.deinit();
for (nodes) |node| {
@ -825,7 +825,7 @@ const ExtraIndex = std.zig.Ast.ExtraIndex;
const Context = struct {
gpa: Allocator,
buf: std.ArrayList(u8),
buf: std.array_list.Managed(u8),
nodes: std.zig.Ast.NodeList = .{},
extra_data: std.ArrayListUnmanaged(u32) = .empty,
tokens: std.zig.Ast.TokenList = .{},
@ -886,7 +886,7 @@ const Context = struct {
};
fn renderNodes(c: *Context, nodes: []const Node) Allocator.Error!NodeSubRange {
var result = std.ArrayList(NodeIndex).init(c.gpa);
var result = std.array_list.Managed(NodeIndex).init(c.gpa);
defer result.deinit();
for (nodes) |node| {
@ -1622,7 +1622,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
}
const l_brace = try c.addToken(.l_brace, "{");
var stmts = std.ArrayList(NodeIndex).init(c.gpa);
var stmts = std.array_list.Managed(NodeIndex).init(c.gpa);
defer stmts.deinit();
for (payload.stmts) |stmt| {
const res = try renderNode(c, stmt);
@ -2954,9 +2954,9 @@ fn renderMacroFunc(c: *Context, node: Node) !NodeIndex {
});
}
fn renderParams(c: *Context, params: []Payload.Param, is_var_args: bool) !std.ArrayList(NodeIndex) {
fn renderParams(c: *Context, params: []Payload.Param, is_var_args: bool) !std.array_list.Managed(NodeIndex) {
_ = try c.addToken(.l_paren, "(");
var rendered = try std.ArrayList(NodeIndex).initCapacity(c.gpa, params.len);
var rendered = try std.array_list.Managed(NodeIndex).initCapacity(c.gpa, params.len);
errdefer rendered.deinit();
for (params, 0..) |param, i| {

View file

@ -5,7 +5,6 @@ const io = std.io;
const fmt = std.fmt;
const mem = std.mem;
const process = std.process;
const ArrayList = std.ArrayList;
const File = std.fs.File;
const Step = std.Build.Step;
const Watch = std.Build.Watch;
@ -98,8 +97,8 @@ pub fn main() !void {
dependencies.root_deps,
);
var targets = ArrayList([]const u8).init(arena);
var debug_log_scopes = ArrayList([]const u8).init(arena);
var targets = std.array_list.Managed([]const u8).init(arena);
var debug_log_scopes = std.array_list.Managed([]const u8).init(arena);
var thread_pool_options: std.Thread.Pool.Options = .{ .allocator = arena };
var install_prefix: ?[]const u8 = null;
@ -341,9 +340,10 @@ pub fn main() !void {
}
}
if (webui_listen != null and watch) fatal(
\\the build system does not yet support combining '--webui' and '--watch'; consider omitting '--watch' in favour of the web UI "Rebuild" button
, .{});
if (webui_listen != null) {
if (watch) fatal("using '--webui' and '--watch' together is not yet supported; consider omitting '--watch' in favour of the web UI \"Rebuild\" button", .{});
if (builtin.single_threaded) fatal("'--webui' is not yet supported on single-threaded hosts", .{});
}
const stderr: std.fs.File = .stderr();
const ttyconf = get_tty_conf(color, stderr);
@ -450,16 +450,19 @@ pub fn main() !void {
try run.thread_pool.init(thread_pool_options);
defer run.thread_pool.deinit();
run.web_server = if (webui_listen) |listen_address| .init(.{
.gpa = gpa,
.thread_pool = &run.thread_pool,
.graph = &graph,
.all_steps = run.step_stack.keys(),
.ttyconf = run.ttyconf,
.root_prog_node = main_progress_node,
.watch = watch,
.listen_address = listen_address,
}) else null;
run.web_server = if (webui_listen) |listen_address| ws: {
if (builtin.single_threaded) unreachable; // `fatal` above
break :ws .init(.{
.gpa = gpa,
.thread_pool = &run.thread_pool,
.graph = &graph,
.all_steps = run.step_stack.keys(),
.ttyconf = run.ttyconf,
.root_prog_node = main_progress_node,
.watch = watch,
.listen_address = listen_address,
});
} else null;
if (run.web_server) |*ws| {
ws.start() catch |err| fatal("failed to start web server: {s}", .{@errorName(err)});
@ -563,7 +566,7 @@ const Run = struct {
max_rss_mutex: std.Thread.Mutex,
skip_oom_steps: bool,
watch: bool,
web_server: ?WebServer,
web_server: if (!builtin.single_threaded) ?WebServer else ?noreturn,
/// Allocated into `gpa`.
memory_blocked_steps: std.ArrayListUnmanaged(*Step),
/// Allocated into `gpa`.

View file

@ -22,6 +22,8 @@ const usage_libc =
\\
;
var stdout_buffer: [4096]u8 = undefined;
pub fn main() !void {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena_instance.deinit();
@ -34,14 +36,16 @@ pub fn main() !void {
var input_file: ?[]const u8 = null;
var target_arch_os_abi: []const u8 = "native";
var print_includes: bool = false;
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
const stdout = &stdout_writer.interface;
{
var i: usize = 2;
while (i < args.len) : (i += 1) {
const arg = args[i];
if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
const stdout = std.fs.File.stdout().deprecatedWriter();
try stdout.writeAll(usage_libc);
try stdout.flush();
return std.process.cleanExit();
} else if (mem.eql(u8, arg, "-target")) {
if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
@ -97,13 +101,11 @@ pub fn main() !void {
fatal("no include dirs detected for target {s}", .{zig_target});
}
var bw = std.io.bufferedWriter(std.fs.File.stdout().deprecatedWriter());
var writer = bw.writer();
for (libc_dirs.libc_include_dir_list) |include_dir| {
try writer.writeAll(include_dir);
try writer.writeByte('\n');
try stdout.writeAll(include_dir);
try stdout.writeByte('\n');
}
try bw.flush();
try stdout.flush();
return std.process.cleanExit();
}
@ -125,9 +127,8 @@ pub fn main() !void {
};
defer libc.deinit(gpa);
var bw = std.io.bufferedWriter(std.fs.File.stdout().deprecatedWriter());
try libc.render(bw.writer());
try bw.flush();
try libc.render(stdout);
try stdout.flush();
}
}

View file

@ -114,10 +114,10 @@ pub fn main() !void {
interestingness_argv.appendAssumeCapacity(checker_path);
interestingness_argv.appendSliceAssumeCapacity(argv);
var rendered = std.ArrayList(u8).init(gpa);
var rendered = std.array_list.Managed(u8).init(gpa);
defer rendered.deinit();
var astgen_input = std.ArrayList(u8).init(gpa);
var astgen_input = std.array_list.Managed(u8).init(gpa);
defer astgen_input.deinit();
var tree = try parse(gpa, root_source_file_path);
@ -161,7 +161,7 @@ pub fn main() !void {
// result, restart the whole process, reparsing the AST and re-generating the list
// of all possible transformations and shuffling it again.
var transformations = std.ArrayList(Walk.Transformation).init(gpa);
var transformations = std.array_list.Managed(Walk.Transformation).init(gpa);
defer transformations.deinit();
try Walk.findTransformations(arena, &tree, &transformations);
sortTransformations(transformations.items, rng.random());
@ -382,7 +382,7 @@ fn transformationsToFixups(
}
}
var other_source = std.ArrayList(u8).init(gpa);
var other_source = std.array_list.Managed(u8).init(gpa);
defer other_source.deinit();
try other_source.appendSlice("struct {\n");
try other_file_ast.renderToArrayList(&other_source, inlined_fixups);

View file

@ -5,7 +5,7 @@ const assert = std.debug.assert;
const BuiltinFn = std.zig.BuiltinFn;
ast: *const Ast,
transformations: *std.ArrayList(Transformation),
transformations: *std.array_list.Managed(Transformation),
unreferenced_globals: std.StringArrayHashMapUnmanaged(Ast.Node.Index),
in_scope_names: std.StringArrayHashMapUnmanaged(u32),
replace_names: std.StringArrayHashMapUnmanaged(u32),
@ -54,7 +54,7 @@ pub const Error = error{OutOfMemory};
pub fn findTransformations(
arena: std.mem.Allocator,
ast: *const Ast,
transformations: *std.ArrayList(Transformation),
transformations: *std.array_list.Managed(Transformation),
) !void {
transformations.clearRetainingCapacity();

View file

@ -1291,7 +1291,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn
}
pub fn filepathWithExtension(allocator: Allocator, path: []const u8, ext: []const u8) ![]const u8 {
var buf = std.ArrayList(u8).init(allocator);
var buf = std.array_list.Managed(u8).init(allocator);
errdefer buf.deinit();
if (std.fs.path.dirname(path)) |dirname| {
var end_pos = dirname.len;

View file

@ -38,7 +38,7 @@ pub const CompileOptions = struct {
/// Items within the list will be allocated using the allocator of the ArrayList and must be
/// freed by the caller.
/// TODO: Maybe a dedicated struct for this purpose so that it's a bit nicer to work with.
dependencies_list: ?*std.ArrayList([]const u8) = null,
dependencies_list: ?*std.array_list.Managed([]const u8) = null,
default_code_page: SupportedCodePage = .windows1252,
/// If true, the first #pragma code_page directive only sets the input code page, but not the output code page.
/// This check must be done before comments are removed from the file.
@ -74,7 +74,7 @@ pub fn compile(allocator: Allocator, source: []const u8, writer: anytype, option
var tree = try parser.parse(allocator, options.diagnostics);
defer tree.deinit();
var search_dirs = std.ArrayList(SearchDir).init(allocator);
var search_dirs = std.array_list.Managed(SearchDir).init(allocator);
defer {
for (search_dirs.items) |*search_dir| {
search_dir.deinit(allocator);
@ -178,7 +178,7 @@ pub const Compiler = struct {
cwd: std.fs.Dir,
state: State = .{},
diagnostics: *Diagnostics,
dependencies_list: ?*std.ArrayList([]const u8),
dependencies_list: ?*std.array_list.Managed([]const u8),
input_code_pages: *const CodePageLookup,
output_code_pages: *const CodePageLookup,
search_dirs: []SearchDir,
@ -279,7 +279,7 @@ pub const Compiler = struct {
.literal, .number => {
const slice = literal_node.token.slice(self.source);
const code_page = self.input_code_pages.getForToken(literal_node.token);
var buf = try std.ArrayList(u8).initCapacity(self.allocator, slice.len);
var buf = try std.array_list.Managed(u8).initCapacity(self.allocator, slice.len);
errdefer buf.deinit();
var index: usize = 0;
@ -303,7 +303,7 @@ pub const Compiler = struct {
const column = literal_node.token.calculateColumn(self.source, 8, null);
const bytes = SourceBytes{ .slice = slice, .code_page = self.input_code_pages.getForToken(literal_node.token) };
var buf = std.ArrayList(u8).init(self.allocator);
var buf = std.array_list.Managed(u8).init(self.allocator);
errdefer buf.deinit();
// Filenames are sort-of parsed as if they were wide strings, but the max escape width of
@ -421,7 +421,7 @@ pub const Compiler = struct {
const bytes = self.sourceBytesForToken(token);
const output_code_page = self.output_code_pages.getForToken(token);
var buf = try std.ArrayList(u8).initCapacity(self.allocator, bytes.slice.len);
var buf = try std.array_list.Managed(u8).initCapacity(self.allocator, bytes.slice.len);
errdefer buf.deinit();
var iterative_parser = literals.IterativeStringParser.init(bytes, .{
@ -1226,7 +1226,7 @@ pub const Compiler = struct {
}
pub fn writeResourceRawData(self: *Compiler, node: *Node.ResourceRawData, writer: anytype) !void {
var data_buffer = std.ArrayList(u8).init(self.allocator);
var data_buffer = std.array_list.Managed(u8).init(self.allocator);
defer data_buffer.deinit();
// The header's data length field is a u32 so limit the resource's data size so that
// we know we can always specify the real size.
@ -1268,12 +1268,8 @@ pub const Compiler = struct {
try header.write(writer, self.errContext(id_token));
}
pub fn writeResourceDataNoPadding(writer: anytype, data_reader: *std.Io.Reader, data_size: u32) !void {
var adapted = writer.adaptToNewApi();
var buffer: [128]u8 = undefined;
adapted.new_interface.buffer = &buffer;
try data_reader.streamExact(&adapted.new_interface, data_size);
try adapted.new_interface.flush();
pub fn writeResourceDataNoPadding(writer: *std.Io.Writer, data_reader: *std.Io.Reader, data_size: u32) !void {
try data_reader.streamExact(writer, data_size);
}
pub fn writeResourceData(writer: anytype, data_reader: *std.Io.Reader, data_size: u32) !void {
@ -1281,8 +1277,8 @@ pub const Compiler = struct {
try writeDataPadding(writer, data_size);
}
pub fn writeDataPadding(writer: anytype, data_size: u32) !void {
try writer.writeByteNTimes(0, numPaddingBytesNeeded(data_size));
pub fn writeDataPadding(writer: *std.Io.Writer, data_size: u32) !void {
try writer.splatByteAll(0, numPaddingBytesNeeded(data_size));
}
pub fn numPaddingBytesNeeded(data_size: u32) u2 {
@ -1310,7 +1306,7 @@ pub const Compiler = struct {
}
pub fn writeAccelerators(self: *Compiler, node: *Node.Accelerators, writer: anytype) !void {
var data_buffer = std.ArrayList(u8).init(self.allocator);
var data_buffer = std.array_list.Managed(u8).init(self.allocator);
defer data_buffer.deinit();
// The header's data length field is a u32 so limit the resource's data size so that
@ -1409,7 +1405,7 @@ pub const Compiler = struct {
};
pub fn writeDialog(self: *Compiler, node: *Node.Dialog, writer: anytype) !void {
var data_buffer = std.ArrayList(u8).init(self.allocator);
var data_buffer = std.array_list.Managed(u8).init(self.allocator);
defer data_buffer.deinit();
// The header's data length field is a u32 so limit the resource's data size so that
// we know we can always specify the real size.
@ -1977,7 +1973,7 @@ pub const Compiler = struct {
try NameOrOrdinal.writeEmpty(data_writer);
}
var extra_data_buf = std.ArrayList(u8).init(self.allocator);
var extra_data_buf = std.array_list.Managed(u8).init(self.allocator);
defer extra_data_buf.deinit();
// The extra data byte length must be able to fit within a u16.
var limited_extra_data_writer = limitedWriter(extra_data_buf.writer(), std.math.maxInt(u16));
@ -2008,7 +2004,7 @@ pub const Compiler = struct {
}
pub fn writeToolbar(self: *Compiler, node: *Node.Toolbar, writer: anytype) !void {
var data_buffer = std.ArrayList(u8).init(self.allocator);
var data_buffer = std.array_list.Managed(u8).init(self.allocator);
defer data_buffer.deinit();
const data_writer = data_buffer.writer();
@ -2086,7 +2082,7 @@ pub const Compiler = struct {
}
pub fn writeMenu(self: *Compiler, node: *Node.Menu, writer: anytype) !void {
var data_buffer = std.ArrayList(u8).init(self.allocator);
var data_buffer = std.array_list.Managed(u8).init(self.allocator);
defer data_buffer.deinit();
// The header's data length field is a u32 so limit the resource's data size so that
// we know we can always specify the real size.
@ -2100,8 +2096,10 @@ pub const Compiler = struct {
const resource = ResourceType.fromString(type_bytes);
std.debug.assert(resource == .menu or resource == .menuex);
self.writeMenuData(node, data_writer, resource) catch |err| switch (err) {
error.NoSpaceLeft => {
var adapted = data_writer.adaptToNewApi(&.{});
self.writeMenuData(node, &adapted.new_interface, resource) catch |err| switch (err) {
error.WriteFailed => {
return self.addErrorDetailsAndFail(.{
.err = .resource_data_size_exceeds_max,
.token = node.id,
@ -2129,7 +2127,7 @@ pub const Compiler = struct {
/// Expects `data_writer` to be a LimitedWriter limited to u32, meaning all writes to
/// the writer within this function could return error.NoSpaceLeft
pub fn writeMenuData(self: *Compiler, node: *Node.Menu, data_writer: anytype, resource: ResourceType) !void {
pub fn writeMenuData(self: *Compiler, node: *Node.Menu, data_writer: *std.Io.Writer, resource: ResourceType) !void {
// menu header
const version: u16 = if (resource == .menu) 0 else 1;
try data_writer.writeInt(u16, version, .little);
@ -2156,7 +2154,7 @@ pub const Compiler = struct {
}
}
pub fn writeMenuItem(self: *Compiler, node: *Node, writer: anytype, is_last_of_parent: bool) !void {
pub fn writeMenuItem(self: *Compiler, node: *Node, writer: *std.Io.Writer, is_last_of_parent: bool) !void {
switch (node.id) {
.menu_item_separator => {
// This is the 'alternate compability form' of the separator, see
@ -2267,7 +2265,7 @@ pub const Compiler = struct {
}
pub fn writeVersionInfo(self: *Compiler, node: *Node.VersionInfo, writer: anytype) !void {
var data_buffer = std.ArrayList(u8).init(self.allocator);
var data_buffer = std.array_list.Managed(u8).init(self.allocator);
defer data_buffer.deinit();
// The node's length field (which is inclusive of the length of all of its children) is a u16
// so limit the node's data size so that we know we can always specify the real size.
@ -2356,8 +2354,9 @@ pub const Compiler = struct {
try fixed_file_info.write(data_writer);
for (node.block_statements) |statement| {
self.writeVersionNode(statement, data_writer, &data_buffer) catch |err| switch (err) {
error.NoSpaceLeft => {
var adapted = data_writer.adaptToNewApi(&.{});
self.writeVersionNode(statement, &adapted.new_interface, &data_buffer) catch |err| switch (err) {
error.WriteFailed => {
try self.addErrorDetails(.{
.err = .version_node_size_exceeds_max,
.token = node.id,
@ -2395,7 +2394,7 @@ pub const Compiler = struct {
/// Expects writer to be a LimitedWriter limited to u16, meaning all writes to
/// the writer within this function could return error.NoSpaceLeft, and that buf.items.len
/// will never be able to exceed maxInt(u16).
pub fn writeVersionNode(self: *Compiler, node: *Node, writer: anytype, buf: *std.ArrayList(u8)) !void {
pub fn writeVersionNode(self: *Compiler, node: *Node, writer: *std.Io.Writer, buf: *std.array_list.Managed(u8)) !void {
// We can assume that buf.items.len will never be able to exceed the limits of a u16
try writeDataPadding(writer, @as(u16, @intCast(buf.items.len)));
@ -2700,12 +2699,12 @@ pub const Compiler = struct {
return self.writeSizeInfo(writer, size_info);
}
pub fn writeSizeInfo(self: ResourceHeader, writer: anytype, size_info: SizeInfo) !void {
pub fn writeSizeInfo(self: ResourceHeader, writer: *std.Io.Writer, size_info: SizeInfo) !void {
try writer.writeInt(DWORD, self.data_size, .little); // DataSize
try writer.writeInt(DWORD, size_info.bytes, .little); // HeaderSize
try self.type_value.write(writer); // TYPE
try self.name_value.write(writer); // NAME
try writer.writeByteNTimes(0, size_info.padding_after_name);
try writer.splatByteAll(0, size_info.padding_after_name);
try writer.writeInt(DWORD, self.data_version, .little); // DataVersion
try writer.writeInt(WORD, self.memory_flags.value, .little); // MemoryFlags
@ -3120,7 +3119,7 @@ pub const FontDir = struct {
// First, the ID is written, though
try writer.writeInt(u16, font.id, .little);
try writer.writeAll(&font.header_bytes);
try writer.writeByteNTimes(0, 2);
try writer.splatByteAll(0, 2);
}
try Compiler.writeDataPadding(writer, data_size);
}
@ -3247,7 +3246,7 @@ pub const StringTable = struct {
}
pub fn writeResData(self: *Block, compiler: *Compiler, language: res.Language, block_id: u16, writer: anytype) !void {
var data_buffer = std.ArrayList(u8).init(compiler.allocator);
var data_buffer = std.array_list.Managed(u8).init(compiler.allocator);
defer data_buffer.deinit();
const data_writer = data_buffer.writer();

View file

@ -188,7 +188,7 @@ pub const Diagnostics = union {
overflow_resource: usize,
};
pub fn writeCoff(allocator: Allocator, writer: anytype, resources: []const Resource, options: CoffOptions, diagnostics: ?*Diagnostics) !void {
pub fn writeCoff(allocator: Allocator, writer: *std.Io.Writer, resources: []const Resource, options: CoffOptions, diagnostics: ?*Diagnostics) !void {
var resource_tree = ResourceTree.init(allocator, options);
defer resource_tree.deinit();
@ -232,7 +232,7 @@ pub fn writeCoff(allocator: Allocator, writer: anytype, resources: []const Resou
.flags = flags,
};
try writer.writeStructEndian(coff_header, .little);
try writer.writeStruct(coff_header, .little);
const rsrc01_header = std.coff.SectionHeader{
.name = ".rsrc$01".*,
@ -250,7 +250,7 @@ pub fn writeCoff(allocator: Allocator, writer: anytype, resources: []const Resou
.MEM_READ = 1,
},
};
try writer.writeStructEndian(rsrc01_header, .little);
try writer.writeStruct(rsrc01_header, .little);
const rsrc02_header = std.coff.SectionHeader{
.name = ".rsrc$02".*,
@ -268,7 +268,7 @@ pub fn writeCoff(allocator: Allocator, writer: anytype, resources: []const Resou
.MEM_READ = 1,
},
};
try writer.writeStructEndian(rsrc02_header, .little);
try writer.writeStruct(rsrc02_header, .little);
// TODO: test surrogate pairs
try resource_tree.sort();
@ -665,13 +665,13 @@ const ResourceTree = struct {
pub fn writeCoff(
self: *const ResourceTree,
allocator: Allocator,
w: anytype,
w: *std.Io.Writer,
resources_in_data_order: []const Resource,
lengths: Lengths,
coff_string_table: *StringTable,
) ![]const std.coff.Symbol {
if (self.type_to_name_map.count() == 0) {
try w.writeByteNTimes(0, 16);
try w.splatByteAll(0, 16);
return &.{};
}
@ -710,7 +710,7 @@ const ResourceTree = struct {
.number_of_id_entries = counts.ids,
.number_of_name_entries = counts.names,
};
try w.writeStructEndian(table, .little);
try w.writeStruct(table, .little);
var it = self.type_to_name_map.iterator();
while (it.next()) |entry| {
@ -745,7 +745,7 @@ const ResourceTree = struct {
.number_of_id_entries = counts.ids,
.number_of_name_entries = counts.names,
};
try w.writeStructEndian(table, .little);
try w.writeStruct(table, .little);
var it = name_to_lang_map.iterator();
while (it.next()) |entry| {
@ -786,7 +786,7 @@ const ResourceTree = struct {
.number_of_id_entries = counts.ids,
.number_of_name_entries = counts.names,
};
try w.writeStructEndian(table, .little);
try w.writeStruct(table, .little);
var it = lang_to_resources_map.iterator();
while (it.next()) |entry| {
@ -819,7 +819,7 @@ const ResourceTree = struct {
.size = @intCast(orig_resource.data.len),
.codepage = 0,
};
try w.writeStructEndian(data_entry, .little);
try w.writeStruct(data_entry, .little);
}
for (self.rsrc_string_table.keys()) |v| {
@ -828,7 +828,7 @@ const ResourceTree = struct {
try w.writeAll(std.mem.sliceAsBytes(str));
}
try w.writeByteNTimes(0, lengths.padding);
try w.splatByteAll(0, lengths.padding);
for (relocations.list.items) |relocation| {
try writeRelocation(w, std.coff.Relocation{
@ -842,13 +842,13 @@ const ResourceTree = struct {
for (self.deduplicated_data.keys()) |data| {
const padding_bytes: u4 = @intCast((8 -% data.len) % 8);
try w.writeAll(data);
try w.writeByteNTimes(0, padding_bytes);
try w.splatByteAll(0, padding_bytes);
}
} else {
for (resources_in_data_order) |resource| {
const padding_bytes: u4 = @intCast((8 -% resource.data.len) % 8);
try w.writeAll(resource.data);
try w.writeByteNTimes(0, padding_bytes);
try w.splatByteAll(0, padding_bytes);
}
}

View file

@ -56,7 +56,7 @@ pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64
// entries than it actually does, we use an ArrayList with a conservatively
// limited initial capacity instead of allocating the entire slice at once.
const initial_capacity = @min(num_images, 8);
var entries = try std.ArrayList(Entry).initCapacity(allocator, initial_capacity);
var entries = try std.array_list.Managed(Entry).initCapacity(allocator, initial_capacity);
errdefer entries.deinit();
var i: usize = 0;

View file

@ -469,7 +469,7 @@ pub fn parseQuotedString(
const T = if (literal_type == .ascii) u8 else u16;
std.debug.assert(bytes.slice.len >= 2); // must at least have 2 double quote chars
var buf = try std.ArrayList(T).initCapacity(allocator, bytes.slice.len);
var buf = try std.array_list.Managed(T).initCapacity(allocator, bytes.slice.len);
errdefer buf.deinit();
var iterative_parser = IterativeStringParser.init(bytes, options);
@ -564,7 +564,7 @@ pub fn parseQuotedStringAsWideString(allocator: std.mem.Allocator, bytes: Source
// Note: We're only handling the case of parsing an ASCII string into a wide string from here on out.
// TODO: The logic below is similar to that in AcceleratorKeyCodepointTranslator, might be worth merging the two
var buf = try std.ArrayList(u16).initCapacity(allocator, bytes.slice.len);
var buf = try std.array_list.Managed(u16).initCapacity(allocator, bytes.slice.len);
errdefer buf.deinit();
var iterative_parser = IterativeStringParser.init(bytes, options);

View file

@ -97,14 +97,14 @@ pub fn main() !void {
try stdout_writer.writeByte('\n');
}
var dependencies_list = std.ArrayList([]const u8).init(allocator);
var dependencies_list = std.array_list.Managed([]const u8).init(allocator);
defer {
for (dependencies_list.items) |item| {
allocator.free(item);
}
dependencies_list.deinit();
}
const maybe_dependencies_list: ?*std.ArrayList([]const u8) = if (options.depfile_path != null) &dependencies_list else null;
const maybe_dependencies_list: ?*std.array_list.Managed([]const u8) = if (options.depfile_path != null) &dependencies_list else null;
var include_paths = LazyIncludePaths{
.arena = arena,
@ -115,7 +115,7 @@ pub fn main() !void {
const full_input = full_input: {
if (options.input_format == .rc and options.preprocess != .no) {
var preprocessed_buf = std.ArrayList(u8).init(allocator);
var preprocessed_buf = std.array_list.Managed(u8).init(allocator);
errdefer preprocessed_buf.deinit();
// We're going to throw away everything except the final preprocessed output anyway,
@ -127,7 +127,7 @@ pub fn main() !void {
var comp = aro.Compilation.init(aro_arena, std.fs.cwd());
defer comp.deinit();
var argv = std.ArrayList([]const u8).init(comp.gpa);
var argv = std.array_list.Managed([]const u8).init(comp.gpa);
defer argv.deinit();
try argv.append("arocc"); // dummy command name
@ -248,10 +248,11 @@ pub fn main() !void {
var diagnostics = Diagnostics.init(allocator);
defer diagnostics.deinit();
const res_stream_writer = res_stream.source.writer(allocator);
var output_buffered_stream = std.io.bufferedWriter(res_stream_writer);
var output_buffer: [4096]u8 = undefined;
var res_stream_writer = res_stream.source.writer(allocator).adaptToNewApi(&output_buffer);
const output_buffered_stream = &res_stream_writer.new_interface;
compile(allocator, final_input, output_buffered_stream.writer(), .{
compile(allocator, final_input, output_buffered_stream, .{
.cwd = std.fs.cwd(),
.diagnostics = &diagnostics,
.source_mappings = &mapping_results.mappings,
@ -340,10 +341,11 @@ pub fn main() !void {
};
defer coff_stream.deinit(allocator);
var coff_output_buffered_stream = std.io.bufferedWriter(coff_stream.source.writer(allocator));
var coff_output_buffer: [4096]u8 = undefined;
var coff_output_buffered_stream = coff_stream.source.writer(allocator).adaptToNewApi(&coff_output_buffer);
var cvtres_diagnostics: cvtres.Diagnostics = .{ .none = {} };
cvtres.writeCoff(allocator, coff_output_buffered_stream.writer(), resources.list.items, options.coff_options, &cvtres_diagnostics) catch |err| {
cvtres.writeCoff(allocator, &coff_output_buffered_stream.new_interface, resources.list.items, options.coff_options, &cvtres_diagnostics) catch |err| {
switch (err) {
error.DuplicateResource => {
const duplicate_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];
@ -380,7 +382,7 @@ pub fn main() !void {
std.process.exit(1);
};
try coff_output_buffered_stream.flush();
try coff_output_buffered_stream.new_interface.flush();
}
const IoStream = struct {
@ -944,7 +946,7 @@ fn aroDiagnosticsToErrorBundle(
// - Only prints the message itself (no location, source line, error: prefix, etc)
// - Keeps track of source path/line/col instead
const MsgWriter = struct {
buf: std.ArrayList(u8),
buf: std.array_list.Managed(u8),
path: ?[]const u8 = null,
// 1-indexed
line: u32 = undefined,
@ -954,7 +956,7 @@ const MsgWriter = struct {
fn init(allocator: std.mem.Allocator) MsgWriter {
return .{
.buf = std.ArrayList(u8).init(allocator),
.buf = std.array_list.Managed(u8).init(allocator),
};
}

View file

@ -82,7 +82,7 @@ pub const Parser = struct {
}
fn parseRoot(self: *Self) Error!*Node {
var statements = std.ArrayList(*Node).init(self.state.allocator);
var statements = std.array_list.Managed(*Node).init(self.state.allocator);
defer statements.deinit();
try self.parseStatements(&statements);
@ -95,7 +95,7 @@ pub const Parser = struct {
return &node.base;
}
fn parseStatements(self: *Self, statements: *std.ArrayList(*Node)) Error!void {
fn parseStatements(self: *Self, statements: *std.array_list.Managed(*Node)) Error!void {
while (true) {
try self.nextToken(.whitespace_delimiter_only);
if (self.state.token.id == .eof) break;
@ -355,7 +355,7 @@ pub const Parser = struct {
const begin_token = self.state.token;
try self.check(.begin);
var strings = std.ArrayList(*Node).init(self.state.allocator);
var strings = std.array_list.Managed(*Node).init(self.state.allocator);
defer strings.deinit();
while (true) {
const maybe_end_token = try self.lookaheadToken(.normal);
@ -852,7 +852,7 @@ pub const Parser = struct {
/// Expects the current token to be a begin token.
/// After return, the current token will be the end token.
fn parseRawDataBlock(self: *Self) Error![]*Node {
var raw_data = std.ArrayList(*Node).init(self.state.allocator);
var raw_data = std.array_list.Managed(*Node).init(self.state.allocator);
defer raw_data.deinit();
while (true) {
const maybe_end_token = try self.lookaheadToken(.normal);

View file

@ -11,14 +11,14 @@ pub fn preprocess(
writer: anytype,
/// Expects argv[0] to be the command name
argv: []const []const u8,
maybe_dependencies_list: ?*std.ArrayList([]const u8),
maybe_dependencies_list: ?*std.array_list.Managed([]const u8),
) PreprocessError!void {
try comp.addDefaultPragmaHandlers();
var driver: aro.Driver = .{ .comp = comp, .aro_name = "arocc" };
defer driver.deinit();
var macro_buf = std.ArrayList(u8).init(comp.gpa);
var macro_buf = std.array_list.Managed(u8).init(comp.gpa);
defer macro_buf.deinit();
_ = driver.parseArgs(std.io.null_writer, macro_buf.writer(), argv) catch |err| switch (err) {
@ -87,7 +87,7 @@ fn hasAnyErrors(comp: *aro.Compilation) bool {
/// `arena` is used for temporary -D argument strings and the INCLUDE environment variable.
/// The arena should be kept alive at least as long as `argv`.
pub fn appendAroArgs(arena: Allocator, argv: *std.ArrayList([]const u8), options: cli.Options, system_include_paths: []const []const u8) !void {
pub fn appendAroArgs(arena: Allocator, argv: *std.array_list.Managed([]const u8), options: cli.Options, system_include_paths: []const []const u8) !void {
try argv.appendSlice(&.{
"-E",
"--comments",

View file

@ -283,7 +283,7 @@ pub const NameOrOrdinal = union(enum) {
pub fn nameFromString(allocator: Allocator, bytes: SourceBytes) !NameOrOrdinal {
// Names have a limit of 256 UTF-16 code units + null terminator
var buf = try std.ArrayList(u16).initCapacity(allocator, @min(257, bytes.slice.len));
var buf = try std.array_list.Managed(u16).initCapacity(allocator, @min(257, bytes.slice.len));
errdefer buf.deinit();
var i: usize = 0;

View file

@ -574,7 +574,7 @@ fn parseFilename(allocator: Allocator, str: []const u8) error{ OutOfMemory, Inva
escape_u,
};
var filename = try std.ArrayList(u8).initCapacity(allocator, str.len);
var filename = try std.array_list.Managed(u8).initCapacity(allocator, str.len);
errdefer filename.deinit();
var state: State = .string;
var index: usize = 0;

View file

@ -574,7 +574,7 @@ pub fn bestFitFromCodepoint(codepoint: u21) ?u8 {
}
test "windows-1252 to utf8" {
var buf = std.ArrayList(u8).init(std.testing.allocator);
var buf = std.array_list.Managed(u8).init(std.testing.allocator);
defer buf.deinit();
const input_windows1252 = "\x81pqrstuvwxyz{|}~\x80\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8e\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9e\x9f\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";

View file

@ -93,9 +93,12 @@ pub fn main() !void {
fn accept(context: *Context, connection: std.net.Server.Connection) void {
defer connection.stream.close();
var read_buffer: [8000]u8 = undefined;
var server = std.http.Server.init(connection, &read_buffer);
while (server.state == .ready) {
var recv_buffer: [4000]u8 = undefined;
var send_buffer: [4000]u8 = undefined;
var conn_reader = connection.stream.reader(&recv_buffer);
var conn_writer = connection.stream.writer(&send_buffer);
var server = std.http.Server.init(conn_reader.interface(), &conn_writer.interface);
while (server.reader.state == .ready) {
var request = server.receiveHead() catch |err| switch (err) {
error.HttpConnectionClosing => return,
else => {
@ -103,9 +106,19 @@ fn accept(context: *Context, connection: std.net.Server.Connection) void {
return;
},
};
serveRequest(&request, context) catch |err| {
std.log.err("unable to serve {s}: {s}", .{ request.head.target, @errorName(err) });
return;
serveRequest(&request, context) catch |err| switch (err) {
error.WriteFailed => {
if (conn_writer.err) |e| {
std.log.err("unable to serve {s}: {s}", .{ request.head.target, @errorName(e) });
} else {
std.log.err("unable to serve {s}: {s}", .{ request.head.target, @errorName(err) });
}
return;
},
else => {
std.log.err("unable to serve {s}: {s}", .{ request.head.target, @errorName(err) });
return;
},
};
}
}
@ -175,8 +188,7 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {
const gpa = context.gpa;
var send_buffer: [0x4000]u8 = undefined;
var response = request.respondStreaming(.{
.send_buffer = &send_buffer,
var response = try request.respondStreaming(&send_buffer, .{
.respond_options = .{
.extra_headers = &.{
.{ .name = "content-type", .value = "application/x-tar" },
@ -191,11 +203,7 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {
var walker = try std_dir.walk(gpa);
defer walker.deinit();
var adapter_buffer: [500]u8 = undefined;
var response_writer = response.writer().adaptToNewApi();
response_writer.new_interface.buffer = &adapter_buffer;
var archiver: std.tar.Writer = .{ .underlying_writer = &response_writer.new_interface };
var archiver: std.tar.Writer = .{ .underlying_writer = &response.writer };
archiver.prefix = "std";
while (try walker.next()) |entry| {
@ -229,7 +237,6 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {
// intentionally omitting the pointless trailer
//try archiver.finish();
try response_writer.new_interface.flush();
try response.end();
}

View file

@ -443,7 +443,7 @@ fn parse(file_name: []const u8, source: []u8) Oom!Ast {
error.WriteFailed => return error.OutOfMemory,
};
log.err("{s}:{d}:{d}: {s}", .{
file_name, err_loc.line + 1, err_loc.column + 1, rendered_err.getWritten(),
file_name, err_loc.line + 1, err_loc.column + 1, rendered_err.written(),
});
}
return Ast.parse(gpa, "", .zig);

View file

@ -159,9 +159,10 @@ fn mainImpl() !void {
var doc = try parser.endInput();
defer doc.deinit(gpa);
var stdout_buf = std.io.bufferedWriter(std.fs.File.stdout().deprecatedWriter());
try doc.render(stdout_buf.writer());
try stdout_buf.flush();
var stdout_buffer: [1024]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
try doc.render(&stdout_writer.interface);
try stdout_writer.interface.flush();
}
test "empty document" {
@ -1118,7 +1119,7 @@ fn testRender(input: []const u8, expected: []const u8) !void {
var doc = try parser.endInput();
defer doc.deinit(testing.allocator);
var actual = std.ArrayList(u8).init(testing.allocator);
var actual = std.array_list.Managed(u8).init(testing.allocator);
defer actual.deinit();
try doc.render(actual.writer());

View file

@ -8,9 +8,10 @@ pub fn main() !void {
}
test "simple test" {
var list = std.ArrayList(i32).init(std.testing.allocator);
defer list.deinit(); // Try commenting this out and see if zig detects the memory leak!
try list.append(42);
const gpa = std.testing.allocator;
var list: std.ArrayList(i32) = .empty;
defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak!
try list.append(gpa, 42);
try std.testing.expectEqual(@as(i32, 42), list.pop());
}

View file

@ -5,14 +5,13 @@ pub fn bufferedPrint() !void {
// Stdout is for the actual output of your application, for example if you
// are implementing gzip, then only the compressed bytes should be sent to
// stdout, not any debugging messages.
const stdout_file = std.fs.File.stdout().deprecatedWriter();
// Buffering can improve performance significantly in print-heavy programs.
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
var stdout_buffer: [1024]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
const stdout = &stdout_writer.interface;
try stdout.print("Run `zig build test` to run the tests.\n", .{});
try bw.flush(); // Don't forget to flush!
try stdout.flush(); // Don't forget to flush!
}
pub fn add(a: i32, b: i32) i32 {

View file

@ -1,121 +0,0 @@
/* $NetBSD: byte_swap.h,v 1.16 2017/01/17 11:08:50 rin Exp $ */
/*-
* Copyright (c) 1997, 1999, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum, Neil A. Carson, and Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARM_BYTE_SWAP_H_
#define _ARM_BYTE_SWAP_H_
#ifdef _LOCORE
#if defined(_ARM_ARCH_6) || defined(_ARM_ARCH_7)
#define BSWAP16(_src, _dst, _tmp) \
rev16 _dst, _src
#define BSWAP32(_src, _dst, _tmp) \
rev _dst, _src
#else
#define BSWAP16(_src, _dst, _tmp) \
mov _tmp, _src, ror #8 ;\
orr _tmp, _tmp, _tmp, lsr #16 ;\
bic _dst, _tmp, _tmp, lsl #16
#define BSWAP32(_src, _dst, _tmp) \
eor _tmp, _src, _src, ror #16 ;\
bic _tmp, _tmp, #0x00FF0000 ;\
mov _dst, _src, ror #8 ;\
eor _dst, _dst, _tmp, lsr #8
#endif
#else
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t
__byte_swap_u32_variable(uint32_t v)
{
uint32_t t1;
#ifdef _ARM_ARCH_6
if (!__builtin_constant_p(v)) {
__asm("rev\t%0, %1" : "=r" (v) : "0" (v));
return v;
}
#endif
t1 = v ^ ((v << 16) | (v >> 16));
t1 &= 0xff00ffffU;
v = (v >> 8) | (v << 24);
v ^= (t1 >> 8);
return v;
}
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t
__byte_swap_u16_variable(uint16_t v)
{
#ifdef _ARM_ARCH_6
if (!__builtin_constant_p(v)) {
uint32_t v32 = v;
__asm("rev16\t%0, %1" : "=r" (v32) : "0" (v32));
return (uint16_t)v32;
}
#elif !defined(__thumb__) && 0 /* gcc produces decent code for this */
if (!__builtin_constant_p(v)) {
uint32_t v0 = v;
__asm volatile(
"mov %0, %1, ror #8\n"
"orr %0, %0, %0, lsr #16\n"
"bic %0, %0, %0, lsl #16"
: "=&r" (v0)
: "0" (v0));
return (uint16_t)v0;
}
#endif
v &= 0xffff;
v = (uint16_t)((v >> 8) | (v << 8));
return v;
}
__END_DECLS
#endif
#endif /* _LOCORE */
#endif /* _ARM_BYTE_SWAP_H_ */

View file

@ -1,85 +0,0 @@
/* $NetBSD: sysarch.h,v 1.15 2021/10/06 05:33:15 skrll Exp $ */
/*
* Copyright (c) 1996-1997 Mark Brinicombe.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Mark Brinicombe.
* 4. The name of the company nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ARM_SYSARCH_H_
#define _ARM_SYSARCH_H_
#include <sys/cdefs.h>
/*
* Pickup definition of size_t and uintptr_t
*/
#include <machine/ansi.h>
#include <sys/stdint.h>
#ifndef _KERNEL
#include <stdbool.h>
#endif
#ifdef _BSD_SIZE_T_
typedef _BSD_SIZE_T_ size_t;
#undef _BSD_SIZE_T_
#endif
/*
* Architecture specific syscalls (arm)
*/
#define ARM_SYNC_ICACHE 0
#define ARM_DRAIN_WRITEBUF 1
#define ARM_VFP_FPSCR 2
#define ARM_FPU_USED 3
struct arm_sync_icache_args {
uintptr_t addr; /* Virtual start address */
size_t len; /* Region size */
};
struct arm_vfp_fpscr_args {
uint32_t fpscr_clear; /* bits to clear */
uint32_t fpscr_set; /* bits to set */
};
struct arm_unaligned_faults_args {
bool enabled; /* unaligned faults are enabled */
};
#ifndef _KERNEL
__BEGIN_DECLS
int arm_sync_icache(uintptr_t, size_t);
int arm_drain_writebuf(void);
int sysarch(int, void *);
__END_DECLS
#endif
#endif /* !_ARM_SYSARCH_H_ */

View file

@ -0,0 +1,319 @@
/* $NetBSD: lauxlib.h,v 1.8.10.1 2023/08/11 16:22:06 martin Exp $ */
/*
** Id: lauxlib.h
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
#ifndef lauxlib_h
#define lauxlib_h
#ifndef _KERNEL
#include <stddef.h>
#include <stdio.h>
#endif /* _KERNEL */
#include "luaconf.h"
#include "lua.h"
/* global table */
#define LUA_GNAME "_G"
typedef struct luaL_Buffer luaL_Buffer;
/* extra error code for 'luaL_loadfilex' */
#define LUA_ERRFILE (LUA_ERRERR+1)
/* key, in the registry, for table of loaded modules */
#define LUA_LOADED_TABLE "_LOADED"
/* key, in the registry, for table of preloaded loaders */
#define LUA_PRELOAD_TABLE "_PRELOAD"
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
#define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number))
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);
#define luaL_checkversion(L) \
luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);
LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,
size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,
const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);
#ifndef _KERNEL
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,
lua_Integer def);
#else /* _KERNEL */
#define luaL_checkinteger luaL_checknumber
#define luaL_optinteger(L,a,d) luaL_optnumber(L, (a), (lua_Number)(d))
#endif /* _KERNEL */
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int arg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,
const char *const lst[]);
#ifndef _KERNEL
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
#endif /* _KERNEL */
/* predefined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
#ifndef _KERNEL
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
const char *mode);
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
#endif /* _KERNEL */
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
const char *name, const char *mode);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
LUALIB_API void (luaL_addgsub) (luaL_Buffer *b, const char *s,
const char *p, const char *r);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,
const char *p, const char *r);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
lua_CFunction openf, int glb);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define luaL_newlibtable(L,l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
#define luaL_newlib(L,l) \
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
#define luaL_argcheck(L, cond,arg,extramsg) \
((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
#define luaL_argexpected(L,cond,arg,tname) \
((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#ifndef _KERNEL
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#endif /* _KERNEL */
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
/*
** Perform arithmetic operations on lua_Integer values with wrap-around
** semantics, as the Lua core does.
*/
#define luaL_intop(op,v1,v2) \
((lua_Integer)((lua_Unsigned)(v1) op (lua_Unsigned)(v2)))
/* push the value used to represent failure/error */
#define luaL_pushfail(L) lua_pushnil(L)
/*
** Internal assertions for in-house debugging
*/
#if !defined(lua_assert)
#if defined LUAI_ASSERT
#include <assert.h>
#define lua_assert(c) assert(c)
#else
#define lua_assert(c) ((void)0)
#endif
#endif
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
struct luaL_Buffer {
char *b; /* buffer address */
size_t size; /* buffer size */
size_t n; /* number of characters in buffer */
lua_State *L;
union {
LUAI_MAXALIGN; /* ensure maximum alignment for buffer */
char b[LUAL_BUFFERSIZE]; /* initial buffer */
} init;
};
#define luaL_bufflen(bf) ((bf)->n)
#define luaL_buffaddr(bf) ((bf)->b)
#define luaL_addchar(B,c) \
((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
((B)->b[(B)->n++] = (c)))
#define luaL_addsize(B,s) ((B)->n += (s))
#define luaL_buffsub(B,s) ((B)->n -= (s))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
/* }====================================================== */
#ifndef _KERNEL
/*
** {======================================================
** File handles for IO library
** =======================================================
*/
/*
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
** initial structure 'luaL_Stream' (it may contain other fields
** after that initial structure).
*/
#define LUA_FILEHANDLE "FILE*"
typedef struct luaL_Stream {
FILE *f; /* stream (NULL for incompletely created streams) */
lua_CFunction closef; /* to close stream (NULL for closed streams) */
} luaL_Stream;
/* }====================================================== */
#endif /* _KERNEL */
#ifndef _KERNEL
/*
** {==================================================================
** "Abstraction Layer" for basic report of messages and errors
** ===================================================================
*/
/* print a string */
#if !defined(lua_writestring)
#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
#endif
/* print a newline and flush the output */
#if !defined(lua_writeline)
#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
#endif
/* print an error message */
#if !defined(lua_writestringerror)
#define lua_writestringerror(s,p) \
(fprintf(stderr, (s), (p)), fflush(stderr))
#endif
/* }================================================================== */
#endif /* _KERNEL */
/*
** {============================================================
** Compatibility with deprecated conversions
** =============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
#define luaL_optunsigned(L,a,d) \
((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#endif
/* }============================================================ */
#endif

549
lib/libc/include/generic-netbsd/lua.h vendored Normal file
View file

@ -0,0 +1,549 @@
/* $NetBSD: lua.h,v 1.11.10.1 2023/08/11 16:22:07 martin Exp $ */
/*
** Id: lua.h
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
*/
#ifndef lua_h
#define lua_h
#include <stdarg.h>
#ifndef _KERNEL
#include <stddef.h>
#endif /* _KERNEL */
#include "luaconf.h"
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "4"
#define LUA_VERSION_RELEASE "6"
#define LUA_VERSION_NUM 504
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 6)
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2023 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
#define LUA_SIGNATURE "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
#define LUA_MULTRET (-1)
/*
** Pseudo-indices
** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
** space after that to help overflow detection)
*/
#define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
/* thread status */
#define LUA_OK 0
#define LUA_YIELD 1
#define LUA_ERRRUN 2
#define LUA_ERRSYNTAX 3
#define LUA_ERRMEM 4
#define LUA_ERRERR 5
typedef struct lua_State lua_State;
/*
** basic types
*/
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
#define LUA_NUMTYPES 9
/* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20
/* predefined values in the registry */
#define LUA_RIDX_MAINTHREAD 1
#define LUA_RIDX_GLOBALS 2
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
/* unsigned integer type */
typedef LUA_UNSIGNED lua_Unsigned;
/* type for continuation-function contexts */
typedef LUA_KCONTEXT lua_KContext;
/*
** Type for C functions registered with Lua
*/
typedef int (*lua_CFunction) (lua_State *L);
/*
** Type for continuation functions
*/
typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
/*
** Type for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** Type for warning functions
*/
typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);
/*
** Type used by the debug API to collect debug information
*/
typedef struct lua_Debug lua_Debug;
/*
** Functions to be called by the debugger in specific events
*/
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
/*
** generic extra include file
*/
#if defined(LUA_USER_H)
#include LUA_USER_H
#endif
/*
** RCS ident string
*/
extern const char lua_ident[];
/*
** state manipulation
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API int (lua_closethread) (lua_State *L, lua_State *from);
LUA_API int (lua_resetthread) (lua_State *L); /* Deprecated! */
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API lua_Number (lua_version) (lua_State *L);
/*
** basic stack manipulation
*/
LUA_API int (lua_absindex) (lua_State *L, int idx);
LUA_API int (lua_gettop) (lua_State *L);
LUA_API void (lua_settop) (lua_State *L, int idx);
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
LUA_API int (lua_checkstack) (lua_State *L, int n);
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
/*
** access functions (stack -> C)
*/
LUA_API int (lua_isnumber) (lua_State *L, int idx);
LUA_API int (lua_isstring) (lua_State *L, int idx);
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
LUA_API int (lua_isinteger) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
#ifndef _KERNEL
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
#else /* _KERNEL */
#define lua_tonumberx (lua_Integer) lua_tointegerx
#endif /* _KERNEL */
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API lua_Unsigned (lua_rawlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** Comparison and arithmetic functions
*/
#define LUA_OPADD 0 /* ORDER TM, ORDER OP */
#define LUA_OPSUB 1
#define LUA_OPMUL 2
#define LUA_OPMOD 3
#ifndef _KERNEL
#define LUA_OPPOW 4
#define LUA_OPDIV 5
#define LUA_OPIDIV 6
#define LUA_OPBAND 7
#define LUA_OPBOR 8
#define LUA_OPBXOR 9
#define LUA_OPSHL 10
#define LUA_OPSHR 11
#define LUA_OPUNM 12
#define LUA_OPBNOT 13
#else /* _KERNEL */
#define LUA_OPIDIV 4
#define LUA_OPBAND 5
#define LUA_OPBOR 6
#define LUA_OPBXOR 7
#define LUA_OPSHL 8
#define LUA_OPSHR 9
#define LUA_OPUNM 10
#define LUA_OPBNOT 11
#endif /* _KERNEL */
LUA_API void (lua_arith) (lua_State *L, int op);
#define LUA_OPEQ 0
#define LUA_OPLT 1
#define LUA_OPLE 2
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
#ifndef _KERNEL
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
#else /* _KERNEL */
#define lua_pushnumber(L, n) lua_pushinteger(L, (lua_Integer)(n))
#endif /* _KERNEL */
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
/*
** get functions (Lua -> stack)
*/
LUA_API int (lua_getglobal) (lua_State *L, const char *name);
LUA_API int (lua_gettable) (lua_State *L, int idx);
LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawget) (lua_State *L, int idx);
LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n);
/*
** set functions (stack -> Lua)
*/
LUA_API void (lua_setglobal) (lua_State *L, const char *name);
LUA_API void (lua_settable) (lua_State *L, int idx);
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API int (lua_setiuservalue) (lua_State *L, int idx, int n);
/*
** 'load' and 'call' functions (load and run Lua code)
*/
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
lua_KContext ctx, lua_KFunction k);
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
lua_KContext ctx, lua_KFunction k);
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname, const char *mode);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
/*
** coroutine functions
*/
LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
lua_KFunction k);
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg,
int *nres);
LUA_API int (lua_status) (lua_State *L);
LUA_API int (lua_isyieldable) (lua_State *L);
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
/*
** Warning-related functions
*/
LUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f, void *ud);
LUA_API void (lua_warning) (lua_State *L, const char *msg, int tocont);
/*
** garbage-collection function and options
*/
#define LUA_GCSTOP 0
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
#define LUA_GCISRUNNING 9
#define LUA_GCGEN 10
#define LUA_GCINC 11
LUA_API int (lua_gc) (lua_State *L, int what, ...);
/*
** miscellaneous functions
*/
LUA_API int (lua_error) (lua_State *L);
LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API void (lua_len) (lua_State *L, int idx);
LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
LUA_API void (lua_toclose) (lua_State *L, int idx);
LUA_API void (lua_closeslot) (lua_State *L, int idx);
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
#define lua_pushliteral(L, s) lua_pushstring(L, "" s)
#define lua_pushglobaltable(L) \
((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
/* }============================================================== */
/*
** {==============================================================
** compatibility macros
** ===============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
#define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
#endif
#define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1)
#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1)
#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
#define LUA_NUMTAGS LUA_NUMTYPES
/* }============================================================== */
/*
** {======================================================================
** Debug API
** =======================================================================
*/
/*
** Event codes
*/
#define LUA_HOOKCALL 0
#define LUA_HOOKRET 1
#define LUA_HOOKLINE 2
#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILCALL 4
/*
** Event masks
*/
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
#define LUA_MASKRET (1 << LUA_HOOKRET)
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
int fidx2, int n2);
LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook (lua_gethook) (lua_State *L);
LUA_API int (lua_gethookmask) (lua_State *L);
LUA_API int (lua_gethookcount) (lua_State *L);
LUA_API int (lua_setcstacklimit) (lua_State *L, unsigned int limit);
struct lua_Debug {
int event;
const char *name; /* (n) */
const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
const char *source; /* (S) */
size_t srclen; /* (S) */
int currentline; /* (l) */
int linedefined; /* (S) */
int lastlinedefined; /* (S) */
unsigned char nups; /* (u) number of upvalues */
unsigned char nparams;/* (u) number of parameters */
char isvararg; /* (u) */
char istailcall; /* (t) */
unsigned short ftransfer; /* (r) index of first value transferred */
unsigned short ntransfer; /* (r) number of transferred values */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
struct CallInfo *i_ci; /* active function */
};
/* }====================================================================== */
/******************************************************************************
#ifdef _KERNEL
* Copyright (c) 2016-2017, Lourival Vieira Neto <lneto@NetBSD.org>.
#endif
* Copyright (C) 1994-2023 Lua.org, PUC-Rio.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#endif

View file

@ -0,0 +1,873 @@
/* $NetBSD: luaconf.h,v 1.23.10.1 2023/08/11 16:22:07 martin Exp $ */
/*
** Id: luaconf.h
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
#ifndef luaconf_h
#define luaconf_h
#ifndef _KERNEL
#include <limits.h>
#include <stddef.h>
#else /* _KERNEL */
#include <machine/limits.h>
#include <sys/systm.h>
#endif /* _KERNEL */
/*
** ===================================================================
** General Configuration File for Lua
**
** Some definitions here can be changed externally, through the compiler
** (e.g., with '-D' options): They are commented out or protected
** by '#if !defined' guards. However, several other definitions
** should be changed directly here, either because they affect the
** Lua ABI (by making the changes here, you ensure that all software
** connected to Lua, such as C libraries, will be compiled with the same
** configuration); or because they are seldom changed.
**
** Search for "@@" to find all configurable definitions.
** ===================================================================
*/
/*
** {====================================================================
** System Configuration: macros to adapt (if needed) Lua to some
** particular platform, for instance restricting it to C89.
** =====================================================================
*/
/*
@@ LUA_USE_C89 controls the use of non-ISO-C89 features.
** Define it if you want Lua to avoid the use of a few C99 features
** or Windows-specific features on Windows.
*/
/* #define LUA_USE_C89 */
/*
** By default, Lua on Windows use (some) specific Windows features
*/
#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
#define LUA_USE_WINDOWS /* enable goodies for regular Windows */
#endif
#if defined(LUA_USE_WINDOWS)
#define LUA_DL_DLL /* enable support for DLL */
#define LUA_USE_C89 /* broadly, Windows is C89 */
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#endif
#if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* MacOS does not need -ldl */
#endif
#if defined(LUA_USE_IOS)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN
#endif
/*
@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.
*/
#define LUAI_IS32INT ((UINT_MAX >> 30) >= 3)
/* }================================================================== */
/*
** {==================================================================
** Configuration for Number types. These options should not be
** set externally, because any other code connected to Lua must
** use the same configuration.
** ===================================================================
*/
/*
@@ LUA_INT_TYPE defines the type for Lua integers.
@@ LUA_FLOAT_TYPE defines the type for Lua floats.
** Lua should work fine with any mix of these options supported
** by your C compiler. The usual configurations are 64-bit integers
** and 'double' (the default), 32-bit integers and 'float' (for
** restricted platforms), and 'long'/'double' (for C compilers not
** compliant with C99, which may not have support for 'long long').
*/
/* predefined options for LUA_INT_TYPE */
#define LUA_INT_INT 1
#define LUA_INT_LONG 2
#define LUA_INT_LONGLONG 3
/* predefined options for LUA_FLOAT_TYPE */
#define LUA_FLOAT_FLOAT 1
#define LUA_FLOAT_DOUBLE 2
#define LUA_FLOAT_LONGDOUBLE 3
/* Default configuration ('long long' and 'double', for 64-bit Lua) */
#define LUA_INT_DEFAULT LUA_INT_LONGLONG
#define LUA_FLOAT_DEFAULT LUA_FLOAT_DOUBLE
/*
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
*/
#define LUA_32BITS 0
/*
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
** C89 ('long' and 'double'); Windows always has '__int64', so it does
** not need to use this case.
*/
#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
#define LUA_C89_NUMBERS 1
#else
#define LUA_C89_NUMBERS 0
#endif
#if LUA_32BITS /* { */
/*
** 32-bit integers and 'float'
*/
#if LUAI_IS32INT /* use 'int' if big enough */
#define LUA_INT_TYPE LUA_INT_INT
#else /* otherwise use 'long' */
#define LUA_INT_TYPE LUA_INT_LONG
#endif
#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
#elif LUA_C89_NUMBERS /* }{ */
/*
** largest types available for C89 ('long' and 'double')
*/
#define LUA_INT_TYPE LUA_INT_LONG
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#else /* }{ */
/* use defaults */
#define LUA_INT_TYPE LUA_INT_DEFAULT
#define LUA_FLOAT_TYPE LUA_FLOAT_DEFAULT
#endif /* } */
/* }================================================================== */
/*
** {==================================================================
** Configuration for Paths.
** ===================================================================
*/
/*
** LUA_PATH_SEP is the character that separates templates in a path.
** LUA_PATH_MARK is the string that marks the substitution points in a
** template.
** LUA_EXEC_DIR in a Windows path is replaced by the executable's
** directory.
*/
#define LUA_PATH_SEP ";"
#define LUA_PATH_MARK "?"
#define LUA_EXEC_DIR "!"
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
** Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
** C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#if defined(_WIN32) /* { */
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR "!\\lua\\"
#define LUA_CDIR "!\\"
#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
#if !defined(LUA_PATH_DEFAULT)
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
".\\?.lua;" ".\\?\\init.lua"
#endif
#if !defined(LUA_CPATH_DEFAULT)
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" \
LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
LUA_CDIR"loadall.dll;" ".\\?.dll"
#endif
#else /* }{ */
#define LUA_ROOT "/usr/local/"
#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
#if !defined(LUA_PATH_DEFAULT)
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
"./?.lua;" "./?/init.lua"
#endif
#if !defined(LUA_CPATH_DEFAULT)
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
#endif
#endif /* } */
/*
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
*/
#if !defined(LUA_DIRSEP)
#if defined(_WIN32)
#define LUA_DIRSEP "\\"
#else
#define LUA_DIRSEP "/"
#endif
#endif
/* }================================================================== */
/*
** {==================================================================
** Marks for exported symbols in the C code
** ===================================================================
*/
/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
#if defined(LUA_BUILD_AS_DLL) /* { */
#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
#define LUA_API __declspec(dllexport)
#else /* }{ */
#define LUA_API __declspec(dllimport)
#endif /* } */
#else /* }{ */
#define LUA_API extern
#endif /* } */
/*
** More often than not the libs go together with the core.
*/
#define LUALIB_API LUA_API
#define LUAMOD_API LUA_API
/*
@@ LUAI_FUNC is a mark for all extern functions that are not to be
** exported to outside modules.
@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables,
** none of which to be exported to outside modules (LUAI_DDEF for
** definitions and LUAI_DDEC for declarations).
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library. Not all elf targets support
** this attribute. Unfortunately, gcc does not offer a way to check
** whether the target offers that support, and those without support
** give a warning about it. To avoid these warnings, change to the
** default definition.
*/
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__) /* { */
#define LUAI_FUNC __attribute__((visibility("internal"))) extern
#else /* }{ */
#define LUAI_FUNC extern
#endif /* } */
#define LUAI_DDEC(dec) LUAI_FUNC dec
#define LUAI_DDEF /* empty */
/* }================================================================== */
/*
** {==================================================================
** Compatibility with previous versions
** ===================================================================
*/
/*
@@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3.
** You can define it to get all options, or change specific options
** to fit your specific needs.
*/
#if defined(LUA_COMPAT_5_3) /* { */
/*
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library.
** (These functions were already officially removed in 5.3;
** nevertheless they are still available here.)
*/
#define LUA_COMPAT_MATHLIB
/*
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
** luaL_checkint, luaL_checklong, etc.)
** (These macros were also officially removed in 5.3, but they are still
** available here.)
*/
#define LUA_COMPAT_APIINTCASTS
/*
@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
** using '__lt'.
*/
#define LUA_COMPAT_LT_LE
/*
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
** (Once more, these macros were officially removed in 5.3, but they are
** still available here.)
*/
#define lua_strlen(L,i) lua_rawlen(L, (i))
#define lua_objlen(L,i) lua_rawlen(L, (i))
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
#endif /* } */
/* }================================================================== */
/*
** {==================================================================
** Configuration for Numbers (low-level part).
** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
** satisfy your needs.
** ===================================================================
*/
#ifndef _KERNEL
/*
@@ LUAI_UACNUMBER is the result of a 'default argument promotion'
@@ over a floating number.
@@ l_floatatt(x) corrects float attribute 'x' to the proper float type
** by prefixing it with one of FLT/DBL/LDBL.
@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
@@ LUA_NUMBER_FMT is the format for writing floats.
@@ lua_number2str converts a float to a string.
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
@@ l_floor takes the floor of a float.
@@ lua_str2number converts a decimal numeral to a number.
*/
/* The following definitions are good for most cases here */
#define l_floor(x) (l_mathop(floor)(x))
#define lua_number2str(s,sz,n) \
l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
/*
@@ lua_numbertointeger converts a float number with an integral value
** to an integer, or returns 0 if float is not within the range of
** a lua_Integer. (The range comparisons are tricky because of
** rounding. The tests here assume a two-complement representation,
** where MININTEGER always has an exact representation as a float;
** MAXINTEGER may not have one, and therefore its conversion to float
** may have an ill-defined value.)
*/
#define lua_numbertointeger(n,p) \
((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
(n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
(*(p) = (LUA_INTEGER)(n), 1))
/* now the variable definitions */
#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
#define LUA_NUMBER float
#define l_floatatt(n) (FLT_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.7g"
#define l_mathop(op) op##f
#define lua_str2number(s,p) strtof((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
#define LUA_NUMBER long double
#define l_floatatt(n) (LDBL_##n)
#define LUAI_UACNUMBER long double
#define LUA_NUMBER_FRMLEN "L"
#define LUA_NUMBER_FMT "%.19Lg"
#define l_mathop(op) op##l
#define lua_str2number(s,p) strtold((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
#define LUA_NUMBER double
#define l_floatatt(n) (DBL_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.14g"
#define l_mathop(op) op
#define lua_str2number(s,p) strtod((s), (p))
#else /* }{ */
#error "numeric float type not defined"
#endif /* } */
#endif /*_KERNEL */
/*
@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
@@ LUAI_UACINT is the result of a 'default argument promotion'
@@ over a LUA_INTEGER.
@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
@@ LUA_INTEGER_FMT is the format for writing integers.
@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED.
@@ lua_integer2str converts an integer to a string.
*/
/* The following definitions are good for most cases here */
#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
#define LUAI_UACINT LUA_INTEGER
#define lua_integer2str(s,sz,n) \
l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
/*
** use LUAI_UACINT here to avoid problems with promotions (which
** can turn a comparison between unsigneds into a signed comparison)
*/
#define LUA_UNSIGNED unsigned LUAI_UACINT
/* now the variable definitions */
#if LUA_INT_TYPE == LUA_INT_INT /* { int */
#define LUA_INTEGER int
#define LUA_INTEGER_FRMLEN ""
#define LUA_MAXINTEGER INT_MAX
#define LUA_MININTEGER INT_MIN
#define LUA_MAXUNSIGNED UINT_MAX
#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
#define LUA_INTEGER long
#define LUA_INTEGER_FRMLEN "l"
#define LUA_MAXINTEGER LONG_MAX
#define LUA_MININTEGER LONG_MIN
#define LUA_MAXUNSIGNED ULONG_MAX
#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
/* use presence of macro LLONG_MAX as proxy for C99 compliance */
#if defined(LLONG_MAX) /* { */
/* use ISO C99 stuff */
#define LUA_INTEGER long long
#define LUA_INTEGER_FRMLEN "ll"
#define LUA_MAXINTEGER LLONG_MAX
#define LUA_MININTEGER LLONG_MIN
#define LUA_MAXUNSIGNED ULLONG_MAX
#elif defined(LUA_USE_WINDOWS) /* }{ */
/* in Windows, can use specific Windows types */
#define LUA_INTEGER __int64
#define LUA_INTEGER_FRMLEN "I64"
#define LUA_MAXINTEGER _I64_MAX
#define LUA_MININTEGER _I64_MIN
#define LUA_MAXUNSIGNED _UI64_MAX
#else /* }{ */
#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
#endif /* } */
#else /* }{ */
#error "numeric integer type not defined"
#endif /* } */
/* }================================================================== */
/*
** {==================================================================
** Dependencies with C99 and other C details
** ===================================================================
*/
/*
@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
** (All uses in Lua have only one format item.)
*/
#if !defined(LUA_USE_C89)
#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
#else
#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
#endif
/*
@@ lua_strx2number converts a hexadecimal numeral to a number.
** In C99, 'strtod' does that conversion. Otherwise, you can
** leave 'lua_strx2number' undefined and Lua will provide its own
** implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_strx2number(s,p) lua_str2number(s,p)
#endif
/*
@@ lua_pointer2str converts a pointer to a readable string in a
** non-specified way.
*/
#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
/*
@@ lua_number2strx converts a float to a hexadecimal numeral.
** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
** provide its own implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_number2strx(L,b,sz,f,n) \
((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
#endif
/*
** 'strtof' and 'opf' variants for math functions are not valid in
** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
** availability of these variants. ('math.h' is already included in
** all files that use these macros.)
*/
#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))
#undef l_mathop /* variants not available */
#undef lua_str2number
#define l_mathop(op) (lua_Number)op /* no variant */
#define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
#endif
/*
@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation
** functions. It must be a numerical type; Lua will use 'intptr_t' if
** available, otherwise it will use 'ptrdiff_t' (the nearest thing to
** 'intptr_t' in C89)
*/
#define LUA_KCONTEXT ptrdiff_t
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
__STDC_VERSION__ >= 199901L
#include <stdint.h>
#if defined(INTPTR_MAX) /* even in C99 this type is optional */
#undef LUA_KCONTEXT
#define LUA_KCONTEXT intptr_t
#endif
#endif
/*
@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
** Change that if you do not want to use C locales. (Code using this
** macro must include the header 'locale.h'.)
*/
#if !defined(lua_getlocaledecpoint)
#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
#endif
/*
** macros to improve jump prediction, used mostly for error handling
** and debug facilities. (Some macros in the Lua API use these macros.
** Define LUA_NOBUILTIN if you do not want '__builtin_expect' in your
** code.)
*/
#if !defined(luai_likely)
#if defined(__GNUC__) && !defined(LUA_NOBUILTIN)
#define luai_likely(x) (__builtin_expect(((x) != 0), 1))
#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0))
#else
#define luai_likely(x) (x)
#define luai_unlikely(x) (x)
#endif
#endif
#if defined(LUA_CORE) || defined(LUA_LIB)
/* shorter names for Lua's own use */
#define l_likely(x) luai_likely(x)
#define l_unlikely(x) luai_unlikely(x)
#endif
/* }================================================================== */
/*
** {==================================================================
** Language Variations
** =====================================================================
*/
/*
@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
** coercion from strings to numbers.
*/
/* #define LUA_NOCVTN2S */
/* #define LUA_NOCVTS2N */
/*
@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
** Define it as a help when debugging C code.
*/
#if defined(LUA_USE_APICHECK)
#include <assert.h>
#define luai_apicheck(l,e) assert(e)
#endif
/* }================================================================== */
/*
** {==================================================================
** Macros that affect the API and must be stable (that is, must be the
** same when you compile Lua and when you compile code that links to
** Lua).
** =====================================================================
*/
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
** (It must fit into max(size_t)/32 and max(int)/2.)
*/
#if LUAI_IS32INT
#define LUAI_MAXSTACK 1000000
#else
#define LUAI_MAXSTACK 15000
#endif
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
#define LUA_EXTRASPACE (sizeof(void *))
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
** of a function in debug information.
** CHANGE it if you want a different size.
*/
#define LUA_IDSIZE 60
/*
@@ LUAL_BUFFERSIZE is the initial buffer size used by the lauxlib
** buffer system.
*/
#ifdef _KERNEL
#define LUAL_BUFFERSIZE 128
#else
#define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number)))
#endif
/* }================================================================== */
/*
@@ LUAI_MAXALIGN defines fields that, when used in a union, ensure
** maximum alignment for the other items in that union.
*/
#ifndef _KERNEL
#define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l
#else /* _KERNEL */
#define LUAI_MAXALIGN lua_Number n; void *s; lua_Integer i; long l
#endif
/* }================================================================== */
/* =================================================================== */
/*
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
*/
#ifdef __NetBSD__
#define LUA_STRFTIMEOPTIONS "aAbBcCdDeFgGhHIjklmMnprRsStTuUvVwWxXyYzZ%"
/* Integer types */
#undef LUA_INTEGER
#undef LUA_INTEGER_FRMLEN
#undef LUA_UNSIGNED
#undef LUA_MAXUNSIGNED
#undef LUA_MAXINTEGER
#undef LUA_MININTEGER
#define LUA_INTEGER intmax_t
#define LUA_INTEGER_FRMLEN "j"
#define LUA_UNSIGNED uintmax_t
#define LUA_MAXUNSIGNED UINTMAX_MAX
#define LUA_MAXINTEGER INTMAX_MAX
#define LUA_MININTEGER INTMAX_MIN
/* Path */
#undef LUA_ROOT
#undef LUA_PATH_DEFAULT
#undef LUA_CPATH_DEFAULT
#define LUA_ROOT "/usr/"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
#ifndef _KERNEL
#include <stdint.h>
#else /* _KERNEL */
#define LUA_NUMBER LUA_INTEGER
#define LUA_NUMBER_FMT LUA_INTEGER_FMT
#define l_mathlim(n) (0)
#define l_randomizePivot() (~0)
/* setjmp.h */
#define LUAI_THROW(L,c) longjmp(&((c)->b))
#define LUAI_TRY(L,c,a) if (setjmp(&((c)->b)) == 0) { a }
#define luai_jmpbuf label_t
/* time.h */
#include <sys/time.h>
#define time(p) (time_uptime)
/* stdio.h */
#define lua_writestring(s,l) printf("%s", (s))
#define lua_writeline() printf("\n")
/* string.h */
#define strcoll strcmp
/* stdlib.h */
#define abort() panic("Lua has aborted!")
#endif /* _KERNEL */
#endif /* __NetBSD__ */
#endif

View file

@ -0,0 +1,54 @@
/* $NetBSD: lualib.h,v 1.7.10.1 2023/08/11 16:22:07 martin Exp $ */
/*
** Id: lualib.h
** Lua standard libraries
** See Copyright Notice in lua.h
*/
#ifndef lualib_h
#define lualib_h
#include "lua.h"
/* version suffix for environment variable names */
#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
LUAMOD_API int (luaopen_base) (lua_State *L);
#define LUA_COLIBNAME "coroutine"
LUAMOD_API int (luaopen_coroutine) (lua_State *L);
#define LUA_TABLIBNAME "table"
LUAMOD_API int (luaopen_table) (lua_State *L);
#define LUA_IOLIBNAME "io"
LUAMOD_API int (luaopen_io) (lua_State *L);
#define LUA_OSLIBNAME "os"
LUAMOD_API int (luaopen_os) (lua_State *L);
#define LUA_STRLIBNAME "string"
LUAMOD_API int (luaopen_string) (lua_State *L);
#define LUA_UTF8LIBNAME "utf8"
LUAMOD_API int (luaopen_utf8) (lua_State *L);
#define LUA_MATHLIBNAME "math"
LUAMOD_API int (luaopen_math) (lua_State *L);
#define LUA_DBLIBNAME "debug"
LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
#endif

View file

@ -1,3 +1,8 @@
/* $NetBSD: bswap.h,v 1.1 2002/12/09 12:15:58 scw Exp $ */
/* $NetBSD: bswap.h,v 1.2 1999/08/21 05:39:55 simonb Exp $ */
#include <powerpc/bswap.h>
#ifndef _MACHINE_BSWAP_H_
#define _MACHINE_BSWAP_H_
#include <sys/bswap.h>
#endif /* !_MACHINE_BSWAP_H_ */

View file

@ -1,11 +1,11 @@
/* $NetBSD: byte_swap.h,v 1.5 2020/04/04 21:13:20 christos Exp $ */
/* $NetBSD: byte_swap.h,v 1.16 2017/01/17 11:08:50 rin Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* Copyright (c) 1997, 1999, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
* by Charles M. Hannum, Neil A. Carson, and Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -29,57 +29,57 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_BYTE_SWAP_H_
#define _RISCV_BYTE_SWAP_H_
#ifndef _ARM_BYTE_SWAP_H_
#define _ARM_BYTE_SWAP_H_
#ifdef _LOCORE
#define BSWAP16(_src, _dst, _tmp) \
andi _dst, _src, 0xff ;\
slli _dst, _dst, 8 ;\
srli _tmp, _src, 8 ;\
and _tmp, _tmp, 0xff ;\
ori _dst, _dst, _tmp
#if defined(_ARM_ARCH_6) || defined(_ARM_ARCH_7)
#define BSWAP32(_src, _dst, _tmp) \
li v1, 0xff00 ;\
slli _dst, _src, 24 ;\
srli _tmp, _src, 24 ;\
ori _dst, _dst, _tmp ;\
and _tmp, _src, v1 ;\
slli _tmp, _src, 8 ;\
ori _dst, _dst, _tmp ;\
srli _tmp, _src, 8 ;\
and _tmp, _tmp, v1 ;\
ori _dst, _dst, _tmp
#define BSWAP16(_src, _dst, _tmp) \
rev16 _dst, _src
#define BSWAP32(_src, _dst, _tmp) \
rev _dst, _src
#else
#define BSWAP16(_src, _dst, _tmp) \
mov _tmp, _src, ror #8 ;\
orr _tmp, _tmp, _tmp, lsr #16 ;\
bic _dst, _tmp, _tmp, lsl #16
#define BSWAP32(_src, _dst, _tmp) \
eor _tmp, _src, _src, ror #16 ;\
bic _tmp, _tmp, #0x00FF0000 ;\
mov _dst, _src, ror #8 ;\
eor _dst, _dst, _tmp, lsr #8
#endif
#else
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
#define __BYTE_SWAP_U64_VARIABLE __byte_swap_u64_variable
static __inline uint64_t
__byte_swap_u64_variable(uint64_t v)
{
const uint64_t m1 = 0x0000ffff0000ffffull;
const uint64_t m0 = 0x00ff00ff00ff00ffull;
v = (v >> 32) | (v << 32);
v = ((v >> 16) & m1) | ((v & m1) << 16);
v = ((v >> 8) & m0) | ((v & m0) << 8);
return v;
}
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t
__byte_swap_u32_variable(uint32_t v)
{
const uint32_t m = 0xff00ff;
uint32_t t1;
v = (v >> 16) | (v << 16);
v = ((v >> 8) & m) | ((v & m) << 8);
#ifdef _ARM_ARCH_6
if (!__builtin_constant_p(v)) {
__asm("rev\t%0, %1" : "=r" (v) : "0" (v));
return v;
}
#endif
t1 = v ^ ((v << 16) | (v >> 16));
t1 &= 0xff00ffffU;
v = (v >> 8) | (v << 24);
v ^= (t1 >> 8);
return v;
}
@ -88,12 +88,34 @@ __byte_swap_u32_variable(uint32_t v)
static __inline uint16_t
__byte_swap_u16_variable(uint16_t v)
{
/*LINTED*/
return (uint16_t)((v >> 8) | (v << 8));
#ifdef _ARM_ARCH_6
if (!__builtin_constant_p(v)) {
uint32_t v32 = v;
__asm("rev16\t%0, %1" : "=r" (v32) : "0" (v32));
return (uint16_t)v32;
}
#elif !defined(__thumb__) && 0 /* gcc produces decent code for this */
if (!__builtin_constant_p(v)) {
uint32_t v0 = v;
__asm volatile(
"mov %0, %1, ror #8\n"
"orr %0, %0, %0, lsr #16\n"
"bic %0, %0, %0, lsl #16"
: "=&r" (v0)
: "0" (v0));
return (uint16_t)v0;
}
#endif
v &= 0xffff;
v = (uint16_t)((v >> 8) | (v << 8));
return v;
}
__END_DECLS
#endif
#endif /* _LOCORE */
#endif /* _RISCV_BYTE_SWAP_H_ */
#endif /* _ARM_BYTE_SWAP_H_ */

View file

@ -1,3 +1,3 @@
/* $NetBSD: endian_machdep.h,v 1.1 2002/12/09 12:16:02 scw Exp $ */
/* $NetBSD: endian_machdep.h,v 1.1 2000/03/17 00:09:25 mycroft Exp $ */
#include <powerpc/endian_machdep.h>
#define _BYTE_ORDER _BIG_ENDIAN

View file

@ -1,3 +1 @@
/* $NetBSD: rwlock.h,v 1.2 2007/02/09 21:55:03 ad Exp $ */
#include <powerpc/rwlock.h>
/* $NetBSD: rwlock.h,v 1.6 2019/11/29 20:04:53 riastradh Exp $ */

View file

@ -1,3 +1,85 @@
/* $NetBSD: sysarch.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/* $NetBSD: sysarch.h,v 1.15 2021/10/06 05:33:15 skrll Exp $ */
/* nothing */
/*
* Copyright (c) 1996-1997 Mark Brinicombe.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Mark Brinicombe.
* 4. The name of the company nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ARM_SYSARCH_H_
#define _ARM_SYSARCH_H_
#include <sys/cdefs.h>
/*
* Pickup definition of size_t and uintptr_t
*/
#include <machine/ansi.h>
#include <sys/stdint.h>
#ifndef _KERNEL
#include <stdbool.h>
#endif
#ifdef _BSD_SIZE_T_
typedef _BSD_SIZE_T_ size_t;
#undef _BSD_SIZE_T_
#endif
/*
* Architecture specific syscalls (arm)
*/
#define ARM_SYNC_ICACHE 0
#define ARM_DRAIN_WRITEBUF 1
#define ARM_VFP_FPSCR 2
#define ARM_FPU_USED 3
struct arm_sync_icache_args {
uintptr_t addr; /* Virtual start address */
size_t len; /* Region size */
};
struct arm_vfp_fpscr_args {
uint32_t fpscr_clear; /* bits to clear */
uint32_t fpscr_set; /* bits to set */
};
struct arm_unaligned_faults_args {
bool enabled; /* unaligned faults are enabled */
};
#ifndef _KERNEL
__BEGIN_DECLS
int arm_sync_icache(uintptr_t, size_t);
int arm_drain_writebuf(void);
int sysarch(int, void *);
__END_DECLS
#endif
#endif /* !_ARM_SYSARCH_H_ */

View file

@ -1,337 +0,0 @@
/* $NetBSD: sysreg.h,v 1.28 2022/12/03 11:09:59 skrll Exp $ */
/*
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_SYSREG_H_
#define _RISCV_SYSREG_H_
#ifndef _KERNEL
#include <sys/param.h>
#endif
#include <riscv/reg.h>
#define FCSR_FMASK 0 // no exception bits
#define FCSR_FRM __BITS(7, 5)
#define FCSR_FRM_RNE 0b000 // Round Nearest, ties to Even
#define FCSR_FRM_RTZ 0b001 // Round Towards Zero
#define FCSR_FRM_RDN 0b010 // Round DowN (-infinity)
#define FCSR_FRM_RUP 0b011 // Round UP (+infinity)
#define FCSR_FRM_RMM 0b100 // Round to nearest, ties to Max Magnitude
#define FCSR_FRM_DYN 0b111 // Dynamic rounding
#define FCSR_FFLAGS __BITS(4, 0) // Sticky bits
#define FCSR_NV __BIT(4) // iNValid operation
#define FCSR_DZ __BIT(3) // Divide by Zero
#define FCSR_OF __BIT(2) // OverFlow
#define FCSR_UF __BIT(1) // UnderFlow
#define FCSR_NX __BIT(0) // iNeXact
static inline uint32_t
riscvreg_fcsr_read(void)
{
uint32_t __fcsr;
__asm("frcsr %0" : "=r"(__fcsr));
return __fcsr;
}
static inline uint32_t
riscvreg_fcsr_write(uint32_t __new)
{
uint32_t __old;
__asm("fscsr %0, %1" : "=r"(__old) : "r"(__new));
return __old;
}
static inline uint32_t
riscvreg_fcsr_read_fflags(void)
{
uint32_t __old;
__asm("frflags %0" : "=r"(__old));
return __SHIFTOUT(__old, FCSR_FFLAGS);
}
static inline uint32_t
riscvreg_fcsr_write_fflags(uint32_t __new)
{
uint32_t __old;
__new = __SHIFTIN(__new, FCSR_FFLAGS);
__asm("fsflags %0, %1" : "=r"(__old) : "r"(__new));
return __SHIFTOUT(__old, FCSR_FFLAGS);
}
static inline uint32_t
riscvreg_fcsr_read_frm(void)
{
uint32_t __old;
__asm("frrm\t%0" : "=r"(__old));
return __SHIFTOUT(__old, FCSR_FRM);
}
static inline uint32_t
riscvreg_fcsr_write_frm(uint32_t __new)
{
uint32_t __old;
__new = __SHIFTIN(__new, FCSR_FRM);
__asm __volatile("fsrm\t%0, %1" : "=r"(__old) : "r"(__new));
return __SHIFTOUT(__old, FCSR_FRM);
}
#define RISCVREG_READ_INLINE(regname) \
static inline uintptr_t \
csr_##regname##_read(void) \
{ \
uintptr_t __rv; \
asm volatile("csrr %0, " #regname : "=r"(__rv) :: "memory"); \
return __rv; \
}
#define RISCVREG_WRITE_INLINE(regname) \
static inline void \
csr_##regname##_write(uintptr_t __val) \
{ \
asm volatile("csrw " #regname ", %0" :: "r"(__val) : "memory"); \
}
#define RISCVREG_SET_INLINE(regname) \
static inline void \
csr_##regname##_set(uintptr_t __mask) \
{ \
if (__builtin_constant_p(__mask) && __mask < 0x20) { \
asm volatile("csrsi " #regname ", %0" :: "i"(__mask) : \
"memory"); \
} else { \
asm volatile("csrs " #regname ", %0" :: "r"(__mask) : \
"memory"); \
} \
}
#define RISCVREG_CLEAR_INLINE(regname) \
static inline void \
csr_##regname##_clear(uintptr_t __mask) \
{ \
if (__builtin_constant_p(__mask) && __mask < 0x20) { \
asm volatile("csrci " #regname ", %0" :: "i"(__mask) : \
"memory"); \
} else { \
asm volatile("csrc " #regname ", %0" :: "r"(__mask) : \
"memory"); \
} \
}
#define RISCVREG_READ_WRITE_INLINE(regname) \
RISCVREG_READ_INLINE(regname) \
RISCVREG_WRITE_INLINE(regname)
#define RISCVREG_SET_CLEAR_INLINE(regname) \
RISCVREG_SET_INLINE(regname) \
RISCVREG_CLEAR_INLINE(regname)
#define RISCVREG_READ_SET_CLEAR_INLINE(regname) \
RISCVREG_READ_INLINE(regname) \
RISCVREG_SET_CLEAR_INLINE(regname)
#define RISCVREG_READ_WRITE_SET_CLEAR_INLINE(regname) \
RISCVREG_READ_WRITE_INLINE(regname) \
RISCVREG_SET_CLEAR_INLINE(regname)
/* Supervisor Status Register */
RISCVREG_READ_SET_CLEAR_INLINE(sstatus) // supervisor status register
#ifdef _LP64
#define SR_WPRI __BITS(62, 34) | __BITS(31, 20) | \
__BIT(17) | __BITS(12, 11) | __BIT(7) | __BITS(4, 2) | \
__BIT(0)
#define SR_SD __BIT(63) // any of FS or VS or XS dirty
/* Bits 62-34 are WPRI */
#define SR_UXL __BITS(33, 32) // U-mode XLEN
#define SR_UXL_32 1 // XLEN == 32
#define SR_UXL_64 2 // XLEN == 64
#define SR_UXL_128 3 // XLEN == 128
/* Bits 31-20 are WPRI*/
#else
#define SR_WPRI __BITS(30, 20) | \
__BIT(17) | __BITS(12, 11) | __BIT(7) | __BITS(4, 2) | \
__BIT(0)
#define SR_SD __BIT(31) // any of FS or VS or XS dirty
/* Bits 30-20 are WPRI*/
#endif /* _LP64 */
/* Both RV32 and RV64 have the bottom 20 bits shared */
#define SR_MXR __BIT(19) // Make eXecutable Readable
#define SR_SUM __BIT(18) // permit Supervisor User Memory access
/* Bit 17 is WPRI */
#define SR_XS __BITS(16, 15) // Vector extension state
#define SR_XS_OFF 0 // All off
#define SR_XS_SOME_ON 1 // None dirty or clean, some on
#define SR_XS_SOME_CLEAN 2 // None dirty, some clean
#define SR_XS_SOME_DIRTY 3 // Some dirty
#define SR_FS __BITS(14, 13) // Floating-point unit state
#define SR_FS_OFF 0 // Off
#define SR_FS_INITIAL 1 // Initial
#define SR_FS_CLEAN 2 // Clean
#define SR_FS_DIRTY 3 // Dirty
/* Bits 12-11 are WPRI */
#define SR_VS __BITS(10, 9) // User-mode extention state
#define SR_VS_OFF SR_FS_OFF // Off
#define SR_VS_INITIAL SR_FS_INITIAL // Initial
#define SR_VS_CLEAN SR_FS_CLEAN // Clean
#define SR_VS_DIRTY SR_FS_DIRTY // Dirty
#define SR_SPP __BIT(8) // Priv level before supervisor mode
/* Bit 7 is WPRI */
#define SR_UBE __BIT(6) // User-mode endianness
#define SR_SPIE __BIT(5) // S-Mode interrupts enabled before trap
/* Bits 4-2 are WPRI */
#define SR_SIE __BIT(1) // Supervisor mode interrupt enable
/* Bit 0 is WPRI */
/* Supervisor interrupt registers */
/* ... interrupt pending register (sip) */
RISCVREG_READ_SET_CLEAR_INLINE(sip) // supervisor interrupt pending
/* Bit (XLEN-1) - 10 is WIRI */
#define SIP_SEIP __BIT(9) // S-mode interrupt pending
/* Bit 8-6 is WIRI */
#define SIP_STIP __BIT(5) // S-mode timer interrupt pending
/* Bit 4-2 is WIRI */
#define SIP_SSIP __BIT(1) // S-mode software interrupt pending
/* Bit 0 is WIRI */
/* ... interrupt-enable register (sie) */
RISCVREG_READ_SET_CLEAR_INLINE(sie) // supervisor interrupt enable
/* Bit (XLEN-1) - 10 is WIRI */
#define SIE_SEIE __BIT(9) // S-mode interrupt enable
/* Bit 8-6 is WIRI */
#define SIE_STIE __BIT(5) // S-mode timer interrupt enable
/* Bit 4-2 is WIRI */
#define SIE_SSIE __BIT(1) // S-mode software interrupt enable
/* Bit 0 is WIRI */
/* Mask for all interrupts */
#define SIE_IM (SIE_SEI |SIE_STIE | SIE_SSIE)
#ifdef _LP64
#define SR_USER64 (SR_SPIE | SR_UXL_64) // 64-bit U-mode sstatus
#define SR_USER32 (SR_SPIE | SR_UXL_32) // 32-bit U-mode sstatus
#else
#define SR_USER (SR_SPIE) // U-mode sstatus
#endif
// Cause register
#define CAUSE_INTERRUPT_P(cause) ((cause) & __BIT(XLEN - 1))
#define CAUSE_CODE(cause) ((cause) & __BITS(XLEN - 2, 0))
// Cause register - exceptions
#define CAUSE_FETCH_MISALIGNED 0
#define CAUSE_FETCH_ACCESS 1
#define CAUSE_ILLEGAL_INSTRUCTION 2
#define CAUSE_BREAKPOINT 3
#define CAUSE_LOAD_MISALIGNED 4
#define CAUSE_LOAD_ACCESS 5
#define CAUSE_STORE_MISALIGNED 6
#define CAUSE_STORE_ACCESS 7
#define CAUSE_USER_ECALL 8
#define CAUSE_SYSCALL CAUSE_USER_ECALL /* convenience alias */
#define CAUSE_SUPERVISOR_ECALL 9
/* 10 is reserved */
#define CAUSE_MACHINE_ECALL 11
#define CAUSE_FETCH_PAGE_FAULT 12
#define CAUSE_LOAD_PAGE_FAULT 13
/* 14 is Reserved */
#define CAUSE_STORE_PAGE_FAULT 15
/* >= 16 is reserved/custom */
// Cause register - interrupts
#define IRQ_SUPERVISOR_SOFTWARE 1
#define IRQ_MACHINE_SOFTWARE 3
#define IRQ_SUPERVISOR_TIMER 5
#define IRQ_MACHINE_TIMER 7
#define IRQ_SUPERVISOR_EXTERNAL 9
#define IRQ_MACHINE_EXTERNAL 11
RISCVREG_READ_INLINE(time)
#ifdef _LP64
RISCVREG_READ_INLINE(cycle)
#else /* !_LP64 */
static inline uint64_t
csr_cycle_read(void)
{
uint32_t __hi0, __hi1, __lo0;
do {
__asm __volatile(
"csrr\t%[__hi0], cycleh"
"\n\t" "csrr\t%[__lo0], cycle"
"\n\t" "csrr\t%[__hi1], cycleh"
: [__hi0] "=r"(__hi0),
[__lo0] "=r"(__lo0),
[__hi1] "=r"(__hi1));
} while (__hi0 != __hi1);
return
__SHIFTIN(__hi0, __BITS(63, 32)) |
__SHIFTIN(__lo0, __BITS(31, 0));
}
#endif /* !_LP64 */
#ifdef _LP64
#define SATP_MODE __BITS(63, 60) // Translation mode
#define SATP_MODE_BARE 0 // No translation or protection
/* modes 1-7 reserved for standard use */
#define SATP_MODE_SV39 8 // Page-based 39-bit virt addr
#define SATP_MODE_SV48 9 // Page-based 48-bit virt addr
#define SATP_MODE_SV57 10 // Page-based 57-bit virt addr
#define SATP_MODE_SV64 11 // Page-based 64-bit virt addr
/* modes 12-13 reserved for standard use */
/* modes 14-15 designated for custom use */
#define SATP_ASID __BITS(59, 44) // Address Space Identifier
#define SATP_PPN __BITS(43, 0) // Physical Page Number
#else
#define SATP_MODE __BIT(31) // Translation mode
#define SATP_MODE_BARE 0 // No translation or protection
#define SATP_MODE_SV32 1 // Page-based 32-bit virt addr
#define SATP_ASID __BITS(30, 22) // Address Space Identifier
#define SATP_PPN __BITS(21, 0) // Physical Page Number
#endif
RISCVREG_READ_WRITE_INLINE(satp)
/* Fake "ASID" CSR (a field of SATP register) functions */
static inline uint32_t
csr_asid_read(void)
{
uintptr_t satp = csr_satp_read();
return __SHIFTOUT(satp, SATP_ASID);
}
static inline void
csr_asid_write(uint32_t asid)
{
uintptr_t satp = csr_satp_read();
satp &= ~SATP_ASID;
satp |= __SHIFTIN(asid, SATP_ASID);
csr_satp_write(satp);
}
#endif /* _RISCV_SYSREG_H_ */

View file

@ -1,3 +0,0 @@
/* $NetBSD: ansi.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#include <sys/common_ansi.h>

View file

@ -1,40 +0,0 @@
/* $NetBSD: aout_machdep.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_AOUT_MACHDEP_H_
#define _RISCV_AOUT_MACHDEP_H_
#define cpu_exec_aout_makecmds(p, epp) ENOEXEC
/* Size of a page in an object file. */
#define AOUT_LDPGSZ 4096
#endif /* !_RISCV_AOUT_MACHDEP_H_ */

View file

@ -1,266 +0,0 @@
/* $NetBSD: asm.h,v 1.6 2021/05/01 07:05:07 skrll Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_ASM_H
#define _RISCV_ASM_H
#define _C_LABEL(x) x
#define __CONCAT(x,y) x ## y
#define __STRING(x) #x
#define ___CONCAT(x,y) __CONCAT(x,y)
/*
* Define -pg profile entry code.
* Must always be noreorder, must never use a macro instruction
* Final addiu to t9 must always equal the size of this _KERN_MCOUNT
*/
#define _KERN_MCOUNT \
.set push; \
subi sp, sp, CALLFRAME_SIZE; \
REG_S a0, CALLFRAME_S0(sp); \
REG_S ra, CALLFRAME_RA(sp); \
move a0, ra; \
call _mcount \
REG_L ra, CALLFRAME_RA(sp); \
REG_L a0, CALLFRAME_S0(sp); \
addi sp, sp, CALLFRAME_SIZ; \
.set pop;
#ifdef GPROF
#define _PROF_PROLOGUE _KERN_MCOUNT
#else
#define _PROF_PROLOGUE
#endif
#ifdef __PIC__
#define PLT(x) x##@plt
#else
#define PLT(x) x
#endif
/*
* WEAK_ALIAS: create a weak alias.
*/
#define WEAK_ALIAS(alias,sym) \
.weak alias; \
alias = sym
/*
* STRONG_ALIAS: create a strong alias.
*/
#define STRONG_ALIAS(alias,sym) \
.globl alias; \
alias = sym
/*
* WARN_REFERENCES: create a warning if the specified symbol is referenced.
*/
#define WARN_REFERENCES(sym,msg) \
.pushsection __CONCAT(.gnu.warning.,sym); \
.ascii msg; \
.popsection
#define _ENTRY(x) \
.globl _C_LABEL(x); \
.type _C_LABEL(x), @function; \
_C_LABEL(x):
#define ENTRY_NP(x) .text; .align 2; _ENTRY(x)
#define ENTRY(x) ENTRY_NP(x); _PROF_PROLOGUE
#define END(x) .size _C_LABEL(x), . - _C_LABEL(x)
/*
* Macros to panic and printf from assembly language.
*/
#define PANIC(msg) \
la a0, 9f; \
call _C_LABEL(panic); \
MSG(msg)
#define PRINTF(msg) \
la a0, 9f; \
call _C_LABEL(printf); \
MSG(msg)
#define MSG(msg) \
.pushsection .rodata.str1.8,"aMS",@progbits,1; \
9: .asciiz msg; \
.popsection
#define ASMSTR(str) \
.asciiz str; \
.align 3
#define __RCSID(x) .pushsection ".ident","MS",@progbits,1; \
.asciz x; \
.popsection
#define RCSID(name) __RCSID(name)
#if defined(_LP64)
#define SZREG 8
#else
#define SZREG 4
#endif
#define ALSK 15 /* stack alignment */
#define ALMASK -15 /* stack alignment */
#define SZFPREG 8
#define FP_L fld
#define FP_S fsd
/*
* standard callframe {
* register_t cf_sp; frame pointer
* register_t cf_ra; return address
* };
*/
#define CALLFRAME_SIZ (SZREG * 4)
#define CALLFRAME_S1 (CALLFRAME_SIZ - 4 * SZREG)
#define CALLFRAME_S0 (CALLFRAME_SIZ - 3 * SZREG)
#define CALLFRAME_SP (CALLFRAME_SIZ - 2 * SZREG)
#define CALLFRAME_RA (CALLFRAME_SIZ - 1 * SZREG)
/*
* These macros hide the use of rv32 and rv64 instructions from the
* assembler to prevent the assembler from generating 64-bit style
* ABI calls.
*/
#define PTR_ADD add
#define PTR_ADDI addi
#define PTR_SUB sub
#define PTR_SUBI subi
#define PTR_LA la
#define PTR_SLLI slli
#define PTR_SLL sll
#define PTR_SRLI srli
#define PTR_SRL srl
#define PTR_SRAI srai
#define PTR_SRA sra
#if _LP64
#define PTR_L ld
#define PTR_S sd
#define PTR_LR lr.d
#define PTR_SC sc.d
#define PTR_WORD .dword
#define PTR_SCALESHIFT 3
#else
#define PTR_L lw
#define PTR_S sw
#define PTR_LR lr.w
#define PTR_SC sc.w
#define PTR_WORD .word
#define PTR_SCALESHIFT 2
#endif
#define INT_L lw
#define INT_LA la
#define INT_S sw
#define INT_LR lr.w
#define INT_SC sc.w
#define INT_WORD .word
#define INT_SCALESHIFT 2
#ifdef _LP64
#define INT_ADD addw
#define INT_ADDI addwi
#define INT_SUB subw
#define INT_SUBI subwi
#define INT_SLL sllwi
#define INT_SLLV sllw
#define INT_SRL srlwi
#define INT_SRLV srlw
#define INT_SRA srawi
#define INT_SRAV sraw
#else
#define INT_ADD add
#define INT_ADDI addi
#define INT_SUB sub
#define INT_SUBI subi
#define INT_SLLI slli
#define INT_SLL sll
#define INT_SRLI srli
#define INT_SRL srl
#define INT_SRAI srai
#define INT_SRA sra
#endif
#define LONG_LA la
#define LONG_ADD add
#define LONG_ADDI addi
#define LONG_SUB sub
#define LONG_SUBI subi
#define LONG_SLLI slli
#define LONG_SLL sll
#define LONG_SRLI srli
#define LONG_SRL srl
#define LONG_SRAI srai
#define LONG_SRA sra
#ifdef _LP64
#define LONG_L ld
#define LONG_S sd
#define LONG_LR lr.d
#define LONG_SC sc.d
#define LONG_WORD .quad
#define LONG_SCALESHIFT 3
#else
#define LONG_L lw
#define LONG_S sw
#define LONG_LR lr.w
#define LONG_SC sc.w
#define LONG_WORD .word
#define LONG_SCALESHIFT 2
#endif
#define REG_LI li
#define REG_ADD add
#define REG_SLLI slli
#define REG_SLL sll
#define REG_SRLI srli
#define REG_SRL srl
#define REG_SRAI srai
#define REG_SRA sra
#if _LP64
#define REG_L ld
#define REG_S sd
#define REG_LR lr.d
#define REG_SC sc.d
#define REG_SCALESHIFT 3
#else
#define REG_L lw
#define REG_S sw
#define REG_LR lr.w
#define REG_SC sc.w
#define REG_SCALESHIFT 2
#endif
#define CPUVAR(off) _C_LABEL(cpu_info_store)+__CONCAT(CPU_INFO_,off)
#endif /* _RISCV_ASM_H */

View file

@ -1,11 +0,0 @@
/* $NetBSD: bswap.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#ifndef _RISCV_BSWAP_H_
#define _RISCV_BSWAP_H_
#include <riscv/byte_swap.h>
#define __BSWAP_RENAME
#include <sys/bswap.h>
#endif /* _RISCV_BSWAP_H_ */

View file

@ -1,99 +0,0 @@
/* $NetBSD: byte_swap.h,v 1.5 2020/04/04 21:13:20 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_BYTE_SWAP_H_
#define _RISCV_BYTE_SWAP_H_
#ifdef _LOCORE
#define BSWAP16(_src, _dst, _tmp) \
andi _dst, _src, 0xff ;\
slli _dst, _dst, 8 ;\
srli _tmp, _src, 8 ;\
and _tmp, _tmp, 0xff ;\
ori _dst, _dst, _tmp
#define BSWAP32(_src, _dst, _tmp) \
li v1, 0xff00 ;\
slli _dst, _src, 24 ;\
srli _tmp, _src, 24 ;\
ori _dst, _dst, _tmp ;\
and _tmp, _src, v1 ;\
slli _tmp, _src, 8 ;\
ori _dst, _dst, _tmp ;\
srli _tmp, _src, 8 ;\
and _tmp, _tmp, v1 ;\
ori _dst, _dst, _tmp
#else
#include <sys/types.h>
__BEGIN_DECLS
#define __BYTE_SWAP_U64_VARIABLE __byte_swap_u64_variable
static __inline uint64_t
__byte_swap_u64_variable(uint64_t v)
{
const uint64_t m1 = 0x0000ffff0000ffffull;
const uint64_t m0 = 0x00ff00ff00ff00ffull;
v = (v >> 32) | (v << 32);
v = ((v >> 16) & m1) | ((v & m1) << 16);
v = ((v >> 8) & m0) | ((v & m0) << 8);
return v;
}
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t
__byte_swap_u32_variable(uint32_t v)
{
const uint32_t m = 0xff00ff;
v = (v >> 16) | (v << 16);
v = ((v >> 8) & m) | ((v & m) << 8);
return v;
}
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t
__byte_swap_u16_variable(uint16_t v)
{
/*LINTED*/
return (uint16_t)((v >> 8) | (v << 8));
}
__END_DECLS
#endif /* _LOCORE */
#endif /* _RISCV_BYTE_SWAP_H_ */

View file

@ -1,8 +0,0 @@
/* $NetBSD: cdefs.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#ifndef _RISCV_CDEFS_H_
#define _RISCV_CDEFS_H_
#define __ALIGNBYTES (__BIGGEST_ALIGNMENT__ - 1U)
#endif /* _RISCV_CDEFS_H_ */

View file

@ -1,153 +0,0 @@
/* $NetBSD: cpu.h,v 1.9 2022/11/17 09:50:23 simonb Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_CPU_H_
#define _RISCV_CPU_H_
#if defined(_KERNEL) || defined(_KMEMUSER)
struct clockframe {
vaddr_t cf_epc;
register_t cf_status;
int cf_intr_depth;
};
#define CLKF_USERMODE(cf) (((cf)->cf_status & SR_SPP) == 0)
#define CLKF_PC(cf) ((cf)->cf_epc)
#define CLKF_INTR(cf) ((cf)->cf_intr_depth > 0)
#include <sys/cpu_data.h>
#include <sys/device_if.h>
#include <sys/evcnt.h>
#include <sys/intr.h>
struct cpu_info {
struct cpu_data ci_data;
device_t ci_dev;
cpuid_t ci_cpuid;
struct lwp *ci_curlwp;
struct lwp *ci_onproc; /* current user LWP / kthread */
struct lwp *ci_softlwps[SOFTINT_COUNT];
struct trapframe *ci_ddb_regs;
uint64_t ci_lastintr;
int ci_mtx_oldspl;
int ci_mtx_count;
int ci_want_resched;
int ci_cpl;
u_int ci_softints;
volatile u_int ci_intr_depth;
tlb_asid_t ci_pmap_asid_cur;
union pmap_segtab *ci_pmap_user_segtab;
#ifdef _LP64
union pmap_segtab *ci_pmap_user_seg0tab;
#endif
struct evcnt ci_ev_fpu_saves;
struct evcnt ci_ev_fpu_loads;
struct evcnt ci_ev_fpu_reenables;
#if defined(GPROF) && defined(MULTIPROCESSOR)
struct gmonparam *ci_gmon; /* MI per-cpu GPROF */
#endif
};
#endif /* _KERNEL || _KMEMUSER */
#ifdef _KERNEL
extern struct cpu_info cpu_info_store;
// This is also in <sys/lwp.h>
struct lwp;
static inline struct cpu_info *lwp_getcpu(struct lwp *);
register struct lwp *riscv_curlwp __asm("tp");
#define curlwp riscv_curlwp
#define curcpu() lwp_getcpu(curlwp)
static inline cpuid_t
cpu_number(void)
{
#ifdef MULTIPROCESSOR
return curcpu()->ci_cpuid;
#else
return 0;
#endif
}
void cpu_proc_fork(struct proc *, struct proc *);
void cpu_signotify(struct lwp *);
void cpu_need_proftick(struct lwp *l);
void cpu_boot_secondary_processors(void);
#define CPU_INFO_ITERATOR cpuid_t
#ifdef MULTIPROCESSOR
#define CPU_INFO_FOREACH(cii, ci) \
(cii) = 0; ((ci) = cpu_infos[cii]) != NULL; (cii)++
#else
#define CPU_INFO_FOREACH(cii, ci) \
(cii) = 0, (ci) = curcpu(); (cii) == 0; (cii)++
#endif
#define CPU_INFO_CURPMAP(ci) (curlwp->l_proc->p_vmspace->vm_map.pmap)
static inline void
cpu_dosoftints(void)
{
extern void dosoftints(void);
struct cpu_info * const ci = curcpu();
if (ci->ci_intr_depth == 0
&& (ci->ci_data.cpu_softints >> ci->ci_cpl) > 0)
dosoftints();
}
static inline bool
cpu_intr_p(void)
{
return curcpu()->ci_intr_depth > 0;
}
#define LWP_PC(l) cpu_lwp_pc(l)
vaddr_t cpu_lwp_pc(struct lwp *);
static inline void
cpu_idle(void)
{
}
#endif /* _KERNEL */
#endif /* _RISCV_CPU_H_ */

View file

@ -1,68 +0,0 @@
/* $NetBSD: disklabel.h,v 1.2 2022/05/24 19:37:39 andvar Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_DISKLABEL_H_
#define _RISCV_DISKLABEL_H_
#define LABELUSESMBR 1 /* use MBR partitionning */
#define LABELSECTOR 1 /* sector containing label */
#define LABELOFFSET 0 /* offset of label in sector */
#define MAXPARTITIONS 16 /* number of partitions */
#define RAW_PART 2 /* raw partition: XX?c */
#if HAVE_NBTOOL_CONFIG_H
#include <nbinclude/sys/dkbad.h>
#include <nbinclude/sys/bootblock.h>
#else
#include <sys/dkbad.h>
#include <sys/bootblock.h>
#endif /* HAVE_NBTOOL_CONFIG_H */
struct cpu_disklabel {
struct mbr_partition mbrparts[MBR_PART_COUNT];
#define __HAVE_DISKLABEL_DKBAD
struct dkbad bad;
};
#ifdef _KERNEL
struct buf;
struct disklabel;
/* for readdisklabel. rv != 0 -> matches, msg == NULL -> success */
int mbr_label_read(dev_t, void (*)(struct buf *), struct disklabel *,
struct cpu_disklabel *, const char **, int *, int *);
/* for writedisklabel. rv == 0 -> doesn't match, rv > 0 -> success */
int mbr_label_locate(dev_t, void (*)(struct buf *),
struct disklabel *, struct cpu_disklabel *, int *, int *);
#endif /* _KERNEL */
#endif /* _RISCV_DISKLABEL_H_ */

View file

@ -1,144 +0,0 @@
/* $NetBSD: elf_machdep.h,v 1.9 2022/12/03 08:54:38 skrll Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_ELF_MACHDEP_H_
#define _RISCV_ELF_MACHDEP_H_
#define ELF32_MACHDEP_ID EM_RISCV
#define ELF64_MACHDEP_ID EM_RISCV
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
#define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB
#define ELF32_MACHDEP_ID_CASES \
case EM_RISCV: \
break;
#define ELF64_MACHDEP_ID_CASES \
case EM_RISCV: \
break;
#ifdef _LP64
#define KERN_ELFSIZE 64
#define ARCH_ELFSIZE 64 /* MD native binary size */
#else
#define KERN_ELFSIZE 32
#define ARCH_ELFSIZE 32 /* MD native binary size */
#endif
/* Processor specific flags for the ELF header e_flags field. */
/* Processor specific relocation types */
#define R_RISCV_NONE 0
#define R_RISCV_32 1 // A
#define R_RISCV_64 2
#define R_RISCV_RELATIVE 3
#define R_RISCV_COPY 4
#define R_RISCV_JMP_SLOT 5
#define R_RISCV_TLS_DTPMOD32 6
#define R_RISCV_TLS_DTPMOD64 7
#define R_RISCV_TLS_DTPREL32 8
#define R_RISCV_TLS_DTPREL64 9
#define R_RISCV_TLS_TPREL32 10
#define R_RISCV_TLS_TPREL64 11
/* The rest are not used by the dynamic linker */
#define R_RISCV_BRANCH 16 // (A - P) & 0xffff
#define R_RISCV_JAL 17 // A & 0xff
#define R_RISCV_CALL 18 // (A - P) & 0xff
#define R_RISCV_CALL_PLT 19
#define R_RISCV_GOT_HI20 20
#define R_RISCV_TLS_GOT_HI20 21
#define R_RISCV_TLS_GD_HI20 22
#define R_RISCV_PCREL_HI20 23
#define R_RISCV_PCREL_LO12_I 24
#define R_RISCV_PCREL_LO12_S 25
#define R_RISCV_HI20 26 // A & 0xffff
#define R_RISCV_LO12_I 27 // (A >> 16) & 0xffff
#define R_RISCV_LO12_S 28 // (S + A - P) >> 2
#define R_RISCV_TPREL_HI20 29
#define R_RISCV_TPREL_LO12_I 30
#define R_RISCV_TPREL_LO12_S 31
#define R_RISCV_TPREL_ADD 32
#define R_RISCV_ADD8 33
#define R_RISCV_ADD16 34
#define R_RISCV_ADD32 35
#define R_RISCV_ADD64 36
#define R_RISCV_SUB8 37
#define R_RISCV_SUB16 38
#define R_RISCV_SUB32 39
#define R_RISCV_SUB64 40
#define R_RISCV_GNU_VTINHERIT 41 // A & 0xffff
#define R_RISCV_GNU_VTENTRY 42
#define R_RISCV_ALIGN 43
#define R_RISCV_RVC_BRANCH 44
#define R_RISCV_RVC_JUMP 45
#define R_RISCV_RVC_LUI 46
#define R_RISCV_GPREL_I 47
#define R_RISCV_GPREL_S 48
#define R_RISCV_TPREL_I 49
#define R_RISCV_TPREL_S 50
#define R_RISCV_RELAX 51
#define R_RISCV_SUB6 52
#define R_RISCV_SET6 53
#define R_RISCV_SET8 54
#define R_RISCV_SET16 55
#define R_RISCV_SET32 56
#define R_RISCV_32_PCREL 57
/* These are aliases we can use R_TYPESZ */
#define R_RISCV_ADDR32 R_RISCV_32
#define R_RISCV_ADDR64 R_RISCV_64
#define R_TYPE(name) R_RISCV_ ## name
#if ELFSIZE == 32
#define R_TYPESZ(name) R_RISCV_ ## name ## 32
#else
#define R_TYPESZ(name) R_RISCV_ ## name ## 64
#endif
#ifdef _KERNEL
#ifdef ELFSIZE
#define ELF_MD_PROBE_FUNC ELFNAME2(cpu_netbsd,probe)
#endif
struct exec_package;
int cpu_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
vaddr_t *);
int cpu_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *,
vaddr_t *);
#endif /* _KERNEL */
#endif /* _RISCV_ELF_MACHDEP_H_ */

View file

@ -1,3 +0,0 @@
/* $NetBSD: endian.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#include <sys/endian.h>

View file

@ -1,3 +0,0 @@
/* $NetBSD: endian_machdep.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#define _BYTE_ORDER _LITTLE_ENDIAN

View file

@ -1,35 +0,0 @@
/* $NetBSD: fenv.h,v 1.3 2020/03/14 16:12:16 skrll Exp $ */
/*
* Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995
* Public domain.
*/
#ifndef _RISCV_FENV_H_
#define _RISCV_FENV_H_
typedef int fenv_t; /* FPSCR */
typedef int fexcept_t;
#define FE_INEXACT 0x00 /* Result inexact */
#define FE_UNDERFLOW 0x02 /* Result underflowed */
#define FE_OVERFLOW 0x04 /* Result overflowed */
#define FE_DIVBYZERO 0x08 /* divide-by-zero */
#define FE_INVALID 0x10 /* Result invalid */
#define FE_ALL_EXCEPT 0x1f
#define FE_TONEAREST 0 /* round to nearest representable number */
#define FE_TOWARDZERO 1 /* round to zero (truncate) */
#define FE_DOWNWARD 2 /* round toward negative infinity */
#define FE_UPWARD 3 /* round toward positive infinity */
__BEGIN_DECLS
/* Default floating-point environment */
extern const fenv_t __fe_dfl_env;
#define FE_DFL_ENV (&__fe_dfl_env)
__END_DECLS
#endif /* _RISCV_FENV_H_ */

View file

@ -1,58 +0,0 @@
/* $NetBSD: float.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_FLOAT_H_
#define _RISCV_FLOAT_H_
#include <sys/cdefs.h>
#define LDBL_MANT_DIG __LDBL_MANT_DIG__
#define LDBL_DIG __LDBL_DIG__
#define LDBL_MIN_EXP __LDBL_MIN_EXP__
#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
#define LDBL_MAX_EXP __LDBL_MAX_EXP__
#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
#define LDBL_EPSILON __LDBL_EPSILON__
#define LDBL_MIN __LDBL_MIN__
#define LDBL_MAX __LDBL_MAX__
#include <sys/float_ieee754.h>
#if (!defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) \
&& !defined(_XOPEN_SOURCE)) \
|| (__STDC_VERSION__ - 0) >= 199901L \
|| (_POSIX_C_SOURCE - 0) >= 200112L \
|| ((_XOPEN_SOURCE - 0) >= 600) \
|| defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
#define DECIMAL_DIG __DECIMAL_DIG__
#endif
#endif /* !_RISCV_FLOAT_H_ */

View file

@ -1,4 +0,0 @@
/* $NetBSD: ieee.h,v 1.2 2019/04/13 15:57:31 maya Exp $ */
#include <riscv/math.h> /* for #define __HAVE_LONG_DOUBLE 128 */
#include <sys/ieee754.h>

View file

@ -1,44 +0,0 @@
/* $NetBSD: ieeefp.h,v 1.2 2020/03/14 16:12:16 skrll Exp $ */
/*
* Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995
* Public domain.
*/
#ifndef _RISCV_IEEEFP_H_
#define _RISCV_IEEEFP_H_
#include <sys/featuretest.h>
#if defined(_NETBSD_SOURCE) || defined(_ISOC99_SOURCE)
#include <riscv/fenv.h>
#if !defined(_ISOC99_SOURCE)
/* Exception type (used by fpsetmask() et al.) */
typedef int fp_except;
/* Bit defines for fp_except */
#define FP_X_INV FE_INVALID /* invalid operation exception */
#define FP_X_DZ FE_DIVBYZERO /* divide-by-zero exception */
#define FP_X_OFL FE_OVERFLOW /* overflow exception */
#define FP_X_UFL FE_UNDERFLOW /* underflow exception */
#define FP_X_IMP FE_INEXACT /* imprecise (prec. loss; "inexact") */
/* Rounding modes */
typedef enum {
FP_RN=FE_TONEAREST, /* round to nearest representable number */
FP_RP=FE_UPWARD, /* round toward positive infinity */
FP_RM=FE_DOWNWARD, /* round toward negative infinity */
FP_RZ=FE_TOWARDZERO /* round to zero (truncate) */
} fp_rnd;
#endif /* !_ISOC99_SOURCE */
#endif /* _NETBSD_SOURCE || _ISOC99_SOURCE */
#endif /* _RISCV_IEEEFP_H_ */

View file

@ -1,20 +0,0 @@
/* $NetBSD: int_const.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#ifndef __INTMAX_C_SUFFIX__
#define __INT8_C_SUFFIX__
#define __INT16_C_SUFFIX__
#define __INT32_C_SUFFIX__
#define __INT64_C_SUFFIX__ LL
#define __UINT8_C_SUFFIX__
#define __UINT16_C_SUFFIX__
#define __UINT32_C_SUFFIX__
#define __UINT64_C_SUFFIX__ ULL
#define __INTMAX_C_SUFFIX__ LL
#define __UINTMAX_C_SUFFIX__ ULL
#endif
#include <sys/common_int_const.h>

View file

@ -1,381 +0,0 @@
/* $NetBSD: int_fmtio.h,v 1.4 2019/04/17 11:01:19 mrg Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Klaus Klein.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_INT_FMTIO_H_
#define _RISCV_INT_FMTIO_H_
#ifdef __INTPTR_FMTd__
#include <sys/common_int_fmtio.h>
#else
/*
* 7.8.1 Macros for format specifiers
*/
/* fprintf macros for signed integers */
#define PRId8 "hhd" /* int8_t */
#define PRId16 "hd" /* int16_t */
#define PRId32 "d" /* int32_t */
#ifdef _LP64
#define PRId64 "ld" /* int64_t */
#else
#define PRId64 "lld" /* int64_t */
#endif
#define PRIdLEAST8 "hhd" /* int_least8_t */
#define PRIdLEAST16 "hd" /* int_least16_t */
#define PRIdLEAST32 "d" /* int_least32_t */
#ifdef _LP64
#define PRIdLEAST64 "ld" /* int_least64_t */
#define PRIdFAST8 "d" /* int_fast8_t */
#define PRIdFAST16 "d" /* int_fast16_t */
#else
#define PRIdLEAST64 "lld" /* int_least64_t */
#define PRIdFAST8 "hhd" /* int_fast8_t */
#define PRIdFAST16 "hd" /* int_fast16_t */
#endif
#define PRIdFAST32 "d" /* int_fast32_t */
#ifdef _LP64
#define PRIdFAST64 "ld" /* int_fast64_t */
#define PRIdMAX "ld" /* intmax_t */
#else
#define PRIdFAST64 "lld" /* int_fast64_t */
#define PRIdMAX "lld" /* intmax_t */
#endif
#define PRIdPTR "ld" /* intptr_t */
#define PRIi8 "hhi" /* int8_t */
#define PRIi16 "hi" /* int16_t */
#define PRIi32 "i" /* int32_t */
#ifdef _LP64
#define PRIi64 "li" /* int64_t */
#else
#define PRIi64 "lli" /* int64_t */
#endif
#define PRIiLEAST8 "hhi" /* int_least8_t */
#define PRIiLEAST16 "hi" /* int_least16_t */
#define PRIiLEAST32 "i" /* int_least32_t */
#ifdef _LP64
#define PRIiLEAST64 "li" /* int_least64_t */
#define PRIiFAST8 "i" /* int_fast8_t */
#define PRIiFAST16 "i" /* int_fast16_t */
#else
#define PRIiLEAST64 "lli" /* int_least64_t */
#define PRIiFAST8 "hhi" /* int_fast8_t */
#define PRIiFAST16 "hi" /* int_fast16_t */
#endif
#define PRIiFAST32 "i" /* int_fast32_t */
#ifdef _LP64
#define PRIiFAST64 "li" /* int_fast64_t */
#define PRIiMAX "li" /* intmax_t */
#else
#define PRIiFAST64 "lli" /* int_fast64_t */
#define PRIiMAX "lli" /* intmax_t */
#endif
#define PRIiPTR "li" /* intptr_t */
/* fprintf macros for unsigned integers */
#define PRIo8 "hho" /* uint8_t */
#define PRIo16 "ho" /* uint16_t */
#define PRIo32 "o" /* uint32_t */
#ifdef _LP64
#define PRIo64 "lo" /* uint64_t */
#else
#define PRIo64 "llo" /* uint64_t */
#endif
#define PRIoLEAST8 "o" /* uint_least8_t */
#define PRIoLEAST16 "hho" /* uint_least16_t */
#define PRIoLEAST32 "ho" /* uint_least32_t */
#ifdef _LP64
#define PRIoLEAST64 "lo" /* uint_least64_t */
#define PRIoFAST8 "o" /* uint_fast8_t */
#define PRIoFAST16 "o" /* uint_fast16_t */
#else
#define PRIoLEAST64 "llo" /* uint_least64_t */
#define PRIoFAST8 "hho" /* uint_fast8_t */
#define PRIoFAST16 "ho" /* uint_fast16_t */
#endif
#define PRIoFAST32 "o" /* uint_fast32_t */
#ifdef _LP64
#define PRIoFAST64 "lo" /* uint_fast64_t */
#define PRIoMAX "lo" /* uintmax_t */
#else
#define PRIoFAST64 "llo" /* uint_fast64_t */
#define PRIoMAX "llo" /* uintmax_t */
#endif
#define PRIoPTR "lo" /* uintptr_t */
#define PRIu8 "hhu" /* uint8_t */
#define PRIu16 "hu" /* uint16_t */
#define PRIu32 "u" /* uint32_t */
#ifdef _LP64
#define PRIu64 "lu" /* uint64_t */
#else
#define PRIu64 "llu" /* uint64_t */
#endif
#define PRIuLEAST8 "hhu" /* uint_least8_t */
#define PRIuLEAST16 "hu" /* uint_least16_t */
#define PRIuLEAST32 "u" /* uint_least32_t */
#ifdef _LP64
#define PRIuLEAST64 "lu" /* uint_least64_t */
#define PRIuFAST8 "u" /* uint_fast8_t */
#define PRIuFAST16 "u" /* uint_fast16_t */
#else
#define PRIuLEAST64 "llu" /* uint_least64_t */
#define PRIuFAST8 "hhu" /* uint_fast8_t */
#define PRIuFAST16 "hu" /* uint_fast16_t */
#endif
#define PRIuFAST32 "u" /* uint_fast32_t */
#ifdef _LP64
#define PRIuFAST64 "lu" /* uint_fast64_t */
#define PRIuMAX "lu" /* uintmax_t */
#else
#define PRIuFAST64 "llu" /* uint_fast64_t */
#define PRIuMAX "llu" /* uintmax_t */
#endif
#define PRIuPTR "lu" /* uintptr_t */
#define PRIx8 "hhx" /* uint8_t */
#define PRIx16 "hx" /* uint16_t */
#define PRIx32 "x" /* uint32_t */
#ifdef _LP64
#define PRIx64 "lx" /* uint64_t */
#else
#define PRIx64 "llx" /* uint64_t */
#endif
#define PRIxLEAST8 "x" /* uint_least8_t */
#define PRIxLEAST16 "x" /* uint_least16_t */
#define PRIxLEAST32 "x" /* uint_least32_t */
#ifdef _LP64
#define PRIxLEAST64 "lx" /* uint_least64_t */
#define PRIxFAST8 "x" /* uint_fast8_t */
#define PRIxFAST16 "x" /* uint_fast16_t */
#else
#define PRIxLEAST64 "llx" /* uint_least64_t */
#define PRIxFAST8 "hhx" /* uint_fast8_t */
#define PRIxFAST16 "hx" /* uint_fast16_t */
#endif
#define PRIxFAST32 "x" /* uint_fast32_t */
#ifdef _LP64
#define PRIxFAST64 "lx" /* uint_fast64_t */
#define PRIxMAX "lx" /* uintmax_t */
#else
#define PRIxFAST64 "llx" /* uint_fast64_t */
#define PRIxMAX "llx" /* uintmax_t */
#endif
#define PRIxPTR "lx" /* uintptr_t */
#define PRIX8 "hhX" /* uint8_t */
#define PRIX16 "hX" /* uint16_t */
#define PRIX32 "X" /* uint32_t */
#ifdef _LP64
#define PRIX64 "lX" /* uint64_t */
#else
#define PRIX64 "llX" /* uint64_t */
#endif
#define PRIXLEAST8 "X" /* uint_least8_t */
#define PRIXLEAST16 "X" /* uint_least16_t */
#define PRIXLEAST32 "X" /* uint_least32_t */
#ifdef _LP64
#define PRIXLEAST64 "lX" /* uint_least64_t */
#define PRIXFAST8 "X" /* uint_fast8_t */
#define PRIXFAST16 "X" /* uint_fast16_t */
#else
#define PRIXLEAST64 "llX" /* uint_least64_t */
#define PRIXFAST8 "hhX" /* uint_fast8_t */
#define PRIXFAST16 "hX" /* uint_fast16_t */
#endif
#define PRIXFAST32 "X" /* uint_fast32_t */
#ifdef _LP64
#define PRIXFAST64 "lX" /* uint_fast64_t */
#define PRIXMAX "lX" /* uintmax_t */
#else
#define PRIXFAST64 "llX" /* uint_fast64_t */
#define PRIXMAX "llX" /* uintmax_t */
#endif
#define PRIXPTR "lX" /* uintptr_t */
/* fscanf macros for signed integers */
#define SCNd8 "hhd" /* int8_t */
#define SCNd16 "hd" /* int16_t */
#define SCNd32 "d" /* int32_t */
#ifdef _LP64
#define SCNd64 "ld" /* int64_t */
#else
#define SCNd64 "lld" /* int64_t */
#endif
#define SCNdLEAST8 "hhd" /* int_least8_t */
#define SCNdLEAST16 "hd" /* int_least16_t */
#define SCNdLEAST32 "d" /* int_least32_t */
#ifdef _LP64
#define SCNdLEAST64 "ld" /* int_least64_t */
#define SCNdFAST8 "d" /* int_fast8_t */
#define SCNdFAST16 "d" /* int_fast16_t */
#else
#define SCNdLEAST64 "lld" /* int_least64_t */
#define SCNdFAST8 "hhd" /* int_fast8_t */
#define SCNdFAST16 "hd" /* int_fast16_t */
#endif
#define SCNdFAST32 "d" /* int_fast32_t */
#ifdef _LP64
#define SCNdFAST64 "ld" /* int_fast64_t */
#define SCNdMAX "ld" /* intmax_t */
#else
#define SCNdFAST64 "lld" /* int_fast64_t */
#define SCNdMAX "lld" /* intmax_t */
#endif
#define SCNdPTR "ld" /* intptr_t */
#define SCNi8 "hhi" /* int8_t */
#define SCNi16 "hi" /* int16_t */
#define SCNi32 "i" /* int32_t */
#ifdef _LP64
#define SCNi64 "li" /* int64_t */
#else
#define SCNi64 "lli" /* int64_t */
#endif
#define SCNiLEAST8 "hhi" /* int_least8_t */
#define SCNiLEAST16 "hi" /* int_least16_t */
#define SCNiLEAST32 "i" /* int_least32_t */
#ifdef _LP64
#define SCNiLEAST64 "li" /* int_least64_t */
#define SCNiFAST8 "i" /* int_fast8_t */
#define SCNiFAST16 "i" /* int_fast16_t */
#else
#define SCNiLEAST64 "lli" /* int_least64_t */
#define SCNiFAST8 "hhi" /* int_fast8_t */
#define SCNiFAST16 "hi" /* int_fast16_t */
#endif
#define SCNiFAST32 "i" /* int_fast32_t */
#ifdef _LP64
#define SCNiFAST64 "li" /* int_fast64_t */
#define SCNiMAX "li" /* intmax_t */
#else
#define SCNiFAST64 "lli" /* int_fast64_t */
#define SCNiMAX "lli" /* intmax_t */
#endif
#define SCNiPTR "li" /* intptr_t */
/* fscanf macros for unsigned integers */
#define SCNo8 "hho" /* uint8_t */
#define SCNo16 "ho" /* uint16_t */
#define SCNo32 "o" /* uint32_t */
#ifdef _LP64
#define SCNo64 "lo" /* uint64_t */
#else
#define SCNo64 "llo" /* uint64_t */
#endif
#define SCNoLEAST8 "hho" /* uint_least8_t */
#define SCNoLEAST16 "ho" /* uint_least16_t */
#define SCNoLEAST32 "o" /* uint_least32_t */
#ifdef _LP64
#define SCNoLEAST64 "lo" /* uint_least64_t */
#define SCNoFAST8 "o" /* uint_fast8_t */
#define SCNoFAST16 "o" /* uint_fast16_t */
#else
#define SCNoLEAST64 "llo" /* uint_least64_t */
#define SCNoFAST8 "hho" /* uint_fast8_t */
#define SCNoFAST16 "ho" /* uint_fast16_t */
#endif
#define SCNoFAST32 "o" /* uint_fast32_t */
#ifdef _LP64
#define SCNoFAST64 "lo" /* uint_fast64_t */
#define SCNoMAX "lo" /* uintmax_t */
#else
#define SCNoFAST64 "llo" /* uint_fast64_t */
#define SCNoMAX "llo" /* uintmax_t */
#endif
#define SCNoPTR "lo" /* uintptr_t */
#define SCNu8 "hhu" /* uint8_t */
#define SCNu16 "hu" /* uint16_t */
#define SCNu32 "u" /* uint32_t */
#ifdef _LP64
#define SCNu64 "lu" /* uint64_t */
#else
#define SCNu64 "llu" /* uint64_t */
#endif
#define SCNuLEAST8 "hhu" /* uint_least8_t */
#define SCNuLEAST16 "hu" /* uint_least16_t */
#define SCNuLEAST32 "u" /* uint_least32_t */
#ifdef _LP64
#define SCNuLEAST64 "lu" /* uint_least64_t */
#define SCNuFAST8 "u" /* uint_fast8_t */
#define SCNuFAST16 "u" /* uint_fast16_t */
#else
#define SCNuLEAST64 "llu" /* uint_least64_t */
#define SCNuFAST8 "hhu" /* uint_fast8_t */
#define SCNuFAST16 "hu" /* uint_fast16_t */
#endif
#define SCNuFAST32 "u" /* uint_fast32_t */
#ifdef _LP64
#define SCNuFAST64 "lu" /* uint_fast64_t */
#define SCNuMAX "lu" /* uintmax_t */
#else
#define SCNuFAST64 "llu" /* uint_fast64_t */
#define SCNuMAX "llu" /* uintmax_t */
#endif
#define SCNuPTR "lu" /* uintptr_t */
#define SCNx8 "hhx" /* uint8_t */
#define SCNx16 "hx" /* uint16_t */
#define SCNx32 "x" /* uint32_t */
#ifdef _LP64
#define SCNx64 "lx" /* uint64_t */
#else
#define SCNx64 "llx" /* uint64_t */
#endif
#define SCNxLEAST8 "hhx" /* uint_least8_t */
#define SCNxLEAST16 "hx" /* uint_least16_t */
#define SCNxLEAST32 "x" /* uint_least32_t */
#ifdef _LP64
#define SCNxLEAST64 "lx" /* uint_least64_t */
#define SCNxFAST8 "x" /* uint_fast8_t */
#define SCNxFAST16 "x" /* uint_fast16_t */
#else
#define SCNxLEAST64 "llx" /* uint_least64_t */
#define SCNxFAST8 "hhx" /* uint_fast8_t */
#define SCNxFAST16 "hx" /* uint_fast16_t */
#endif
#define SCNxFAST32 "x" /* uint_fast32_t */
#ifdef _LP64
#define SCNxFAST64 "lx" /* uint_fast64_t */
#define SCNxMAX "lx" /* uintmax_t */
#else
#define SCNxFAST64 "llx" /* uint_fast64_t */
#define SCNxMAX "llx" /* uintmax_t */
#endif
#define SCNxPTR "lx" /* uintptr_t */
#endif /* !__INTPTR_FMTd__ */
#endif /* !_RISCV_INT_FMTIO_H_ */

View file

@ -1,3 +0,0 @@
/* $NetBSD: int_limits.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#include <sys/common_int_limits.h>

View file

@ -1,3 +0,0 @@
/* $NetBSD: int_mwgwtypes.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#include <sys/common_int_mwgwtypes.h>

View file

@ -1,3 +0,0 @@
/* $NetBSD: int_types.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#include <sys/common_int_types.h>

View file

@ -1,40 +0,0 @@
/* $NetBSD: kcore.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_KCORE_H_
#define _RISCV_KCORE_H_
typedef struct cpu_kcore_hdr {
uint64_t kh_misc[8];
phys_ram_seg_t kh_ramsegs[0];
} cpu_kcore_hdr_t;
#endif /* _RISCV_KCORE_H_ */

View file

@ -1,3 +0,0 @@
/* $NetBSD: limits.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#include <sys/common_limits.h>

View file

@ -1,3 +0,0 @@
/* $NetBSD: lock.h,v 1.4 2015/06/26 14:27:35 matt Exp $ */
#include <sys/common_lock.h>

View file

@ -1,4 +0,0 @@
/* $NetBSD: math.h,v 1.3 2019/04/16 07:40:02 maya Exp $ */
#define __HAVE_NANF
#define __HAVE_LONG_DOUBLE 128

View file

@ -1,170 +0,0 @@
/* $NetBSD: mcontext.h,v 1.6 2020/03/14 16:12:16 skrll Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_MCONTEXT_H_
#define _RISCV_MCONTEXT_H_
/*
*/
#define _NGREG 32 /* GR1-31 */
#define _NFREG 33 /* F0-31, FCSR */
/*
* This fragment is common to <riscv/mcontext.h> and <riscv/reg.h>
*/
#ifndef _BSD_FPREG_T_
union __fpreg {
__uint64_t u_u64;
double u_d;
};
#define _BSD_FPREG_T_ union __fpreg
#endif
typedef __uint64_t __greg_t;
typedef __greg_t __gregset_t[_NGREG];
typedef __uint32_t __greg32_t;
typedef __greg32_t __gregset32_t[_NGREG];
typedef _BSD_FPREG_T_ __fregset_t[_NFREG];
#define _REG_X1 0
#define _REG_X2 1
#define _REG_X3 2
#define _REG_X4 3
#define _REG_X5 4
#define _REG_X6 5
#define _REG_X7 6
#define _REG_X8 7
#define _REG_X9 8
#define _REG_X10 9
#define _REG_X11 10
#define _REG_X12 11
#define _REG_X13 12
#define _REG_X14 13
#define _REG_X15 14
#define _REG_X16 15
#define _REG_X17 16
#define _REG_X18 17
#define _REG_X19 18
#define _REG_X20 19
#define _REG_X21 20
#define _REG_X22 21
#define _REG_X23 22
#define _REG_X24 23
#define _REG_X25 24
#define _REG_X26 25
#define _REG_X27 26
#define _REG_X28 27
#define _REG_X29 28
#define _REG_X30 29
#define _REG_X31 30
#define _REG_PC 31
#define _REG_RA _REG_X1
#define _REG_SP _REG_X2
#define _REG_GP _REG_X3
#define _REG_TP _REG_X4
#define _REG_S0 _REG_X8
#define _REG_RV _REG_X10
#define _REG_A0 _REG_X10
#define _REG_F0 0
#define _REG_FPCSR 32
typedef struct {
__gregset_t __gregs; /* General Purpose Register set */
__fregset_t __fregs; /* Floating Point Register set */
__greg_t __private; /* copy of l_private */
__greg_t __spare[8]; /* future proof */
} mcontext_t;
typedef struct {
__gregset32_t __gregs; /* General Purpose Register set */
__fregset_t __fregs; /* Floating Point Register set */
__greg32_t __private; /* copy of l_private */
__greg32_t __spare[8]; /* future proof */
} mcontext32_t;
/* Machine-dependent uc_flags */
#define _UC_SETSTACK 0x00010000 /* see <sys/ucontext.h> */
#define _UC_CLRSTACK 0x00020000 /* see <sys/ucontext.h> */
#define _UC_TLSBASE 0x00080000 /* see <sys/ucontext.h> */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S0])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_RV])
#define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc)
#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || defined(__LIBPTHREAD_SOURCE__)
#include <sys/tls.h>
/*
* On RISCV, since displacements are signed 12-bit values, the TCB pointer is
* not and points to the first static entry.
*/
#define TLS_TP_OFFSET 0x0
#define TLS_DTV_OFFSET 0x800
__CTASSERT(TLS_TP_OFFSET + sizeof(struct tls_tcb) < 0x800);
static __inline void *
__lwp_getprivate_fast(void)
{
void *__tp;
__asm("move %0,tp" : "=r"(__tp));
return __tp;
}
static __inline void *
__lwp_gettcb_fast(void)
{
void *__tcb;
__asm __volatile(
"addi %[__tcb],tp,%[__offset]"
: [__tcb] "=r" (__tcb)
: [__offset] "n" (-(TLS_TP_OFFSET + sizeof(struct tls_tcb))));
return __tcb;
}
static __inline void
__lwp_settcb(void *__tcb)
{
__asm __volatile(
"addi tp,%[__tcb],%[__offset]"
:
: [__tcb] "r" (__tcb),
[__offset] "n" (TLS_TP_OFFSET + sizeof(struct tls_tcb)));
}
#endif /* _RTLD_SOURCE || _LIBC_SOURCE || __LIBPTHREAD_SOURCE__ */
#endif /* !_RISCV_MCONTEXT_H_ */

View file

@ -1,124 +0,0 @@
/* $NetBSD: mutex.h,v 1.4.4.1 2023/08/09 17:42:03 martin Exp $ */
/*-
* Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe and Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_MUTEX_H_
#define _RISCV_MUTEX_H_
#include <sys/types.h>
#ifndef __MUTEX_PRIVATE
struct kmutex {
uintptr_t mtx_pad1;
};
#else /* __MUTEX_PRIVATE */
#include <sys/cdefs.h>
#include <sys/param.h>
#include <machine/intr.h>
struct kmutex {
volatile uintptr_t mtx_owner;
};
#ifdef _LP64
#define MTX_ASMOP_SFX ".d" // doubleword atomic op
#else
#define MTX_ASMOP_SFX ".w" // word atomic op
#endif
#define MTX_LOCK __BIT(8) // just one bit
#define MTX_IPL __BITS(7,4) // only need 4 bits
#undef MUTEX_SPIN_IPL // override <sys/mutex.h>
#define MUTEX_SPIN_IPL(a) riscv_mutex_spin_ipl(a)
#define MUTEX_INITIALIZE_SPIN_IPL(a,b) riscv_mutex_initialize_spin_ipl(a,b)
#define MUTEX_SPINBIT_LOCK_INIT(a) riscv_mutex_spinbit_lock_init(a)
#define MUTEX_SPINBIT_LOCK_TRY(a) riscv_mutex_spinbit_lock_try(a)
#define MUTEX_SPINBIT_LOCKED_P(a) riscv_mutex_spinbit_locked_p(a)
#define MUTEX_SPINBIT_LOCK_UNLOCK(a) riscv_mutex_spinbit_lock_unlock(a)
static inline ipl_cookie_t
riscv_mutex_spin_ipl(kmutex_t *__mtx)
{
return (ipl_cookie_t){._spl = __SHIFTOUT(__mtx->mtx_owner, MTX_IPL)};
}
static inline void
riscv_mutex_initialize_spin_ipl(kmutex_t *__mtx, int ipl)
{
__mtx->mtx_owner = (__mtx->mtx_owner & ~MTX_IPL)
| __SHIFTIN(ipl, MTX_IPL);
}
static inline void
riscv_mutex_spinbit_lock_init(kmutex_t *__mtx)
{
__mtx->mtx_owner &= ~MTX_LOCK;
}
static inline bool
riscv_mutex_spinbit_locked_p(const kmutex_t *__mtx)
{
return (__mtx->mtx_owner & MTX_LOCK) != 0;
}
static inline bool
riscv_mutex_spinbit_lock_try(kmutex_t *__mtx)
{
uintptr_t __old;
__asm __volatile(
"amoor" MTX_ASMOP_SFX ".aq\t%0, %1, (%2)"
: "=r"(__old)
: "r"(MTX_LOCK), "r"(__mtx));
return (__old & MTX_LOCK) == 0;
}
static inline void
riscv_mutex_spinbit_lock_unlock(kmutex_t *__mtx)
{
__asm __volatile(
"amoand" MTX_ASMOP_SFX ".rl\tx0, %0, (%1)"
:: "r"(~MTX_LOCK), "r"(__mtx));
}
#if 0
#define __HAVE_MUTEX_STUBS 1
#define __HAVE_SPIN_MUTEX_STUBS 1
#endif
#define __HAVE_SIMPLE_MUTEXES 1
#endif /* __MUTEX_PRIVATE */
#endif /* _RISCV_MUTEX_H_ */

View file

@ -1,106 +0,0 @@
/* $NetBSD: param.h,v 1.7 2022/10/12 07:50:00 simonb Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_PARAM_H_
#define _RISCV_PARAM_H_
#ifdef _KERNEL_OPT
#include "opt_param.h"
#endif
/*
* Machine dependent constants for all OpenRISC processors
*/
/*
* For KERNEL code:
* MACHINE must be defined by the individual port. This is so that
* uname returns the correct thing, etc.
*
* For non-KERNEL code:
* If ELF, MACHINE and MACHINE_ARCH are forced to "or1k/or1k".
*/
#ifdef _LP64
#define _MACHINE_ARCH riscv64
#define MACHINE_ARCH "riscv64"
#define _MACHINE_ARCH32 riscv32
#define MACHINE_ARCH32 "riscv32"
#else
#define _MACHINE_ARCH riscv32
#define MACHINE_ARCH "riscv32"
#endif
#define _MACHINE riscv
#define MACHINE "riscv"
#define MID_MACHINE MID_RISCV
/* RISCV-specific macro to align a stack pointer (downwards). */
#define STACK_ALIGNBYTES (__BIGGEST_ALIGNMENT__ - 1)
#define ALIGNBYTES32 __BIGGEST_ALIGNMENT__
#define NKMEMPAGES_MIN_DEFAULT ((128UL * 1024 * 1024) >> PAGE_SHIFT)
#define NKMEMPAGES_MAX_UNLIMITED 1
#define PGSHIFT 12
#define NBPG (1 << PGSHIFT)
#define PGOFSET (NBPG - 1)
#define UPAGES 2
#define USPACE (UPAGES << PGSHIFT)
#define USPACE_ALIGN NBPG
/*
* Constants related to network buffer management.
* MCLBYTES must be no larger than NBPG (the software page size), and
* NBPG % MCLBYTES must be zero.
*/
#define MSIZE 512 /* size of an mbuf */
#ifndef MCLSHIFT
#define MCLSHIFT 11 /* convert bytes to m_buf clusters */
/* 2K cluster can hold Ether frame */
#endif /* MCLSHIFT */
#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
#ifndef MSGBUFSIZE
#define MSGBUFSIZE 65536 /* default message buffer size */
#endif
#define MAXCPUS 32
#ifdef _KERNEL
void delay(unsigned long);
#define DELAY(x) delay(x)
#endif
#endif /* _RISCV_PARAM_H_ */

View file

@ -1,46 +0,0 @@
/* $NetBSD: pcb.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_PCB_H_
#define _RISCV_PCB_H_
#include <riscv/reg.h>
struct pcb {
struct fpreg pcb_fpregs;
};
struct md_coredump {
struct reg reg;
struct fpreg fpreg;
};
#endif /* _RISCV_PCB_H_ */

View file

@ -1,213 +0,0 @@
/* $NetBSD: pmap.h,v 1.13 2022/10/20 07:18:11 skrll Exp $ */
/*
* Copyright (c) 2014, 2019, 2021 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas (of 3am Software Foundry), Maxime Villard, and
* Nick Hudson.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_PMAP_H_
#define _RISCV_PMAP_H_
#ifdef _KERNEL_OPT
#include "opt_modular.h"
#endif
#if !defined(_MODULE)
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/pool.h>
#include <sys/evcnt.h>
#include <uvm/uvm_physseg.h>
#include <uvm/pmap/vmpagemd.h>
#include <riscv/pte.h>
#include <riscv/sysreg.h>
#define PMAP_SEGTABSIZE NPTEPG
#define PMAP_PDETABSIZE NPTEPG
#ifdef _LP64
#define PTPSHIFT 3
/* This is SV48. */
//#define SEGLENGTH + SEGSHIFT + SEGSHIFT */
/* This is SV39. */
#define XSEGSHIFT (SEGSHIFT + SEGLENGTH)
#define NBXSEG (1ULL << XSEGSHIFT)
#define XSEGOFSET (NBXSEG - 1) /* byte offset into xsegment */
#define XSEGLENGTH (PGSHIFT - 3)
#define NXSEGPG (1 << XSEGLENGTH)
#else
#define PTPSHIFT 2
#define XSEGSHIFT SEGSHIFT
#endif
#define SEGLENGTH (PGSHIFT - PTPSHIFT)
#define SEGSHIFT (SEGLENGTH + PGSHIFT)
#define NBSEG (1 << SEGSHIFT) /* bytes/segment */
#define SEGOFSET (NBSEG - 1) /* byte offset into segment */
#define KERNEL_PID 0
#define PMAP_HWPAGEWALKER 1
#define PMAP_TLB_MAX 1
#ifdef _LP64
#define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
#define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
#else
#define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)0xdeadbeef)
#define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)0xdeadbeef)
#endif
#define PMAP_TLB_NUM_PIDS (__SHIFTOUT_MASK(SATP_ASID) + 1)
#define PMAP_TLB_BITMAP_LENGTH PMAP_TLB_NUM_PIDS
#define PMAP_TLB_FLUSH_ASID_ON_RESET false
#define pmap_phys_address(x) (x)
#ifndef __BSD_PTENTRY_T__
#define __BSD_PTENTRY_T__
#ifdef _LP64
#define PRIxPTE PRIx64
#else
#define PRIxPTE PRIx32
#endif
#endif /* __BSD_PTENTRY_T__ */
#define PMAP_NEED_PROCWR
static inline void
pmap_procwr(struct proc *p, vaddr_t va, vsize_t len)
{
__asm __volatile("fence\trw,rw; fence.i" ::: "memory");
}
#include <uvm/pmap/tlb.h>
#include <uvm/pmap/pmap_tlb.h>
#define PMAP_GROWKERNEL
#define PMAP_STEAL_MEMORY
#ifdef _KERNEL
#define __HAVE_PMAP_MD
struct pmap_md {
paddr_t md_ppn;
pd_entry_t *md_pdetab;
};
struct vm_page *
pmap_md_alloc_poolpage(int flags);
vaddr_t pmap_md_map_poolpage(paddr_t, vsize_t);
void pmap_md_unmap_poolpage(vaddr_t, vsize_t);
bool pmap_md_direct_mapped_vaddr_p(vaddr_t);
bool pmap_md_io_vaddr_p(vaddr_t);
paddr_t pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t);
vaddr_t pmap_md_direct_map_paddr(paddr_t);
void pmap_md_init(void);
void pmap_md_xtab_activate(struct pmap *, struct lwp *);
void pmap_md_xtab_deactivate(struct pmap *);
void pmap_md_pdetab_init(struct pmap *);
bool pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
void pmap_bootstrap(vaddr_t kstart, vaddr_t kend);
extern vaddr_t pmap_direct_base;
extern vaddr_t pmap_direct_end;
#define PMAP_DIRECT_MAP(pa) (pmap_direct_base + (pa))
#define PMAP_DIRECT_UNMAP(va) ((paddr_t)(va) - pmap_direct_base)
#define MEGAPAGE_TRUNC(x) ((x) & ~SEGOFSET)
#define MEGAPAGE_ROUND(x) MEGAPAGE_TRUNC((x) + SEGOFSET)
#ifdef __PMAP_PRIVATE
static inline bool
pmap_md_tlb_check_entry(void *ctx, vaddr_t va, tlb_asid_t asid, pt_entry_t pte)
{
// TLB not walked and so not called.
return false;
}
static inline void
pmap_md_page_syncicache(struct vm_page_md *mdpg, const kcpuset_t *kc)
{
__asm __volatile("fence\trw,rw; fence.i" ::: "memory");
}
/*
* Virtual Cache Alias helper routines. Not a problem for RISCV CPUs.
*/
static inline bool
pmap_md_vca_add(struct vm_page_md *mdpg, vaddr_t va, pt_entry_t *nptep)
{
return false;
}
static inline void
pmap_md_vca_remove(struct vm_page_md *mdpg, vaddr_t va)
{
}
static inline void
pmap_md_vca_clean(struct vm_page_md *mdpg, vaddr_t va, int op)
{
}
static inline size_t
pmap_md_tlb_asid_max(void)
{
return PMAP_TLB_NUM_PIDS - 1;
}
#endif /* __PMAP_PRIVATE */
#endif /* _KERNEL */
#include <uvm/pmap/pmap.h>
#endif /* !_MODULE */
#if defined(MODULAR) || defined(_MODULE)
/*
* Define a compatible vm_page_md so that struct vm_page is the same size
* whether we are using modules or not.
*/
#ifndef __HAVE_VM_PAGE_MD
#define __HAVE_VM_PAGE_MD
struct vm_page_md {
uintptr_t mdpg_dummy[3];
};
__CTASSERT(sizeof(struct vm_page_md) == sizeof(uintptr_t)*3);
#endif /* !__HAVE_VM_PAGE_MD */
#endif /* MODULAR || _MODULE */
#endif /* !_RISCV_PMAP_H_ */

View file

@ -1,71 +0,0 @@
/* $NetBSD: proc.h,v 1.3 2015/03/31 06:47:47 matt Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_PROC_H_
#define _RISCV_PROC_H_
#include <sys/param.h>
#include <riscv/vmparam.h>
struct lwp;
/*
* Machine-dependent part of the lwp structure for RISCV
*/
struct trapframe;
struct mdlwp {
struct trapframe *md_utf; /* trapframe from userspace */
struct trapframe *md_ktf; /* trapframe from userspace */
struct faultbuf *md_onfault; /* registers to store on fault */
register_t md_usp; /* for locore.S */
vaddr_t md_ss_addr; /* single step address for ptrace */
int md_ss_instr; /* single step instruction for ptrace */
volatile int md_astpending; /* AST pending on return to userland */
#if 0
#if USPACE > PAGE_SIZE
int md_upte[USPACE/4096]; /* ptes for mapping u page */
#else
int md_dpte[USPACE/4096]; /* dummy ptes to keep the same */
#endif
#endif
};
struct mdproc {
/* syscall entry for this process */
void (*md_syscall)(struct trapframe *);
};
#ifdef _KERNEL
#define LWP0_CPU_INFO &cpu_info_store /* staticly set in lwp0 */
#endif /* _KERNEL */
#endif /* _RISCV_PROC_H_ */

View file

@ -1,91 +0,0 @@
/* $NetBSD: profile.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_PROFILE_H_
#define _RISCV_PROFILE_H_
#define _MCOUNT_DECL void _mcount
/*
* Cannot implement mcount in C as GCC will trash the ip register when it
* pushes a trapframe. Pity we cannot insert assembly before the function
* prologue.
*/
#define MCOUNT_ASM_NAME "__mcount"
#define PLTSYM
#if 0
#define MCOUNT \
__asm(".text"); \
__asm(".align 0"); \
__asm(".type " MCOUNT_ASM_NAME ",@function"); \
__asm(".global " MCOUNT_ASM_NAME); \
__asm(MCOUNT_ASM_NAME ":"); \
/* \
* Preserve registers that are trashed during mcount \
*/ \
__asm("sub sp, sp, #80"); \
__asm("stp x29, x30, [sp, #64]"); \
__asm("add x29, sp, #64"); \
__asm("stp x0, x1, [x29, #0]"); \
__asm("stp x2, x3, [x29, #16]"); \
__asm("stp x4, x5, [x29, #32]"); \
__asm("stp x6, x7, [x29, #48]"); \
/* \
* find the return address for mcount, \
* and the return address for mcount's caller. \
* \
* frompcindex = pc pushed by call into self. \
*/ \
__asm("mov x0, x19"); \
/* \
* selfpc = pc pushed by mcount call \
*/ \
__asm("mov x1, x30"); \
/* \
* Call the real mcount code \
*/ \
__asm("bl " ___STRING(_C_LABEL(_mcount))); \
/* \
* Restore registers that were trashed during mcount \
*/ \
__asm("ldp x0, x1, [x29, #0]"); \
__asm("ldp x2, x3, [x29, #16]"); \
__asm("ldp x4, x5, [x29, #32]"); \
__asm("ldp x6, x7, [x29, #48]"); \
__asm("ldp x29, x30, [x29, #64]"); \
__asm("add sp, sp, #80"); \
__asm("ret"); \
__asm(".size " MCOUNT_ASM_NAME ", .-" MCOUNT_ASM_NAME);
#endif
#endif /* _RISCV_PROFILE_H_ */

View file

@ -1,57 +0,0 @@
/* $NetBSD: ptrace.h,v 1.3 2019/06/18 21:18:12 kamil Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_PTRACE_H_
#define _RISCV_PTRACE_H_
/*
* RISCV-dependent ptrace definitions.
* Note that PT_STEP is _not_ supported.
*/
#define PT_GETREGS (PT_FIRSTMACH + 0)
#define PT_SETREGS (PT_FIRSTMACH + 1)
#define PT_GETFPREGS (PT_FIRSTMACH + 2)
#define PT_SETFPREGS (PT_FIRSTMACH + 3)
#define PT_MACHDEP_STRINGS \
"PT_GETREGS", \
"PT_SETREGS", \
"PT_GETFPREGS", \
"PT_SETFPREGS"
#include <machine/reg.h>
#define PTRACE_REG_PC(r) (r)->r_pc
#define PTRACE_REG_FP(r) (r)->r_reg[7]
#define PTRACE_REG_SET_PC(r, v) (r)->r_pc = (v)
#define PTRACE_REG_SP(r) (r)->r_reg[1]
#define PTRACE_REG_INTRV(r) (r)->r_reg[9]
#endif /* _RISCV_PTRACE_H_ */

View file

@ -1,125 +0,0 @@
/* $NetBSD: reg.h,v 1.10 2022/12/13 22:25:08 skrll Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_REG_H_
#define _RISCV_REG_H_
// x0 = 0
// x1 = ra (return address) Caller
// x2 = sp (stack pointer) Callee
// x3 = gp (global pointer)
// x4 = tp (thread pointer)
// x5 - x7 = t0 - t2 (temporary) Caller
// x8 = s0/fp (saved register / frame pointer) Callee
// x9 = s1 (saved register) Callee
// x10 - x11 = a0 - a1 (arguments/return values) Caller
// x12 - x17 = a2 - a7 (arguments) Caller
// x18 - x27 = s2 - s11 (saved registers) Callee
// x28 - x31 = t3 - t6 (temporaries) Caller
struct reg { // synced with register_t in <riscv/types.h>
#ifdef _LP64
__uint64_t r_reg[31]; /* x0 is always 0 */
__uint64_t r_pc;
#else
__uint32_t r_reg[31]; /* x0 is always 0 */
__uint32_t r_pc;
#endif
};
#ifdef _LP64
struct reg32 { // synced with register_t in <riscv/types.h>
__uint32_t r_reg[31]; /* x0 is always 0 */
__uint32_t r_pc;
};
#endif
#define _XREG(n) ((n) - 1)
#define _X_RA _XREG(1)
#define _X_SP _XREG(2)
#define _X_GP _XREG(3)
#define _X_TP _XREG(4)
#define _X_T0 _XREG(5)
#define _X_T1 _XREG(6)
#define _X_T2 _XREG(7)
#define _X_S0 _XREG(8)
#define _X_S1 _XREG(9)
#define _X_A0 _XREG(10)
#define _X_A1 _XREG(11)
#define _X_A2 _XREG(12)
#define _X_A3 _XREG(13)
#define _X_A4 _XREG(14)
#define _X_A5 _XREG(15)
#define _X_A6 _XREG(16)
#define _X_A7 _XREG(17)
#define _X_S2 _XREG(18)
#define _X_S3 _XREG(19)
#define _X_S4 _XREG(20)
#define _X_S5 _XREG(21)
#define _X_S6 _XREG(22)
#define _X_S7 _XREG(23)
#define _X_S8 _XREG(24)
#define _X_S9 _XREG(25)
#define _X_S10 _XREG(26)
#define _X_S11 _XREG(27)
#define _X_T3 _XREG(28)
#define _X_T4 _XREG(29)
#define _X_T5 _XREG(30)
#define _X_T6 _XREG(31)
// f0 - f7 = ft0 - ft7 (FP temporaries) Caller
// following layout is similar to integer registers above
// f8 - f9 = fs0 - fs1 (FP saved registers) Callee
// f10 - f11 = fa0 - fa1 (FP arguments/return values) Caller
// f12 - f17 = fa2 - fa7 (FP arguments) Caller
// f18 - f27 = fs2 - fa11 (FP saved registers) Callee
// f28 - f31 = ft8 - ft11 (FP temporaries) Caller
/*
* This fragment is common to <riscv/mcontext.h> and <riscv/reg.h>
*/
#ifndef _BSD_FPREG_T_
union __fpreg {
__uint64_t u_u64;
double u_d;
};
#define _BSD_FPREG_T_ union __fpreg
#endif
/*
* 32 double precision floating point, 1 CSR
*/
struct fpreg {
_BSD_FPREG_T_ r_fpreg[33];
};
#define r_fcsr r_fpreg[32].u_u64
#endif /* _RISCV_REG_H_ */

View file

@ -1 +0,0 @@
/* $NetBSD: rwlock.h,v 1.2 2019/11/29 20:04:53 riastradh Exp $ */

View file

@ -1,70 +0,0 @@
/* $NetBSD: setjmp.h,v 1.2 2015/03/27 06:57:21 matt Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* magic + 16 reg + 1 fcsr + 12 fp + 4 sigmask + 8 spare */
#define _JBLEN (_JB_SIGMASK + 4 + 8)
#define _JB_MAGIC 0
#define _JB_RA 1
#define _JB_SP 2
#define _JB_GP 3
#define _JB_TP 4
#define _JB_S0 5
#define _JB_S1 6
#define _JB_S2 7
#define _JB_S3 8
#define _JB_S4 9
#define _JB_S5 10
#define _JB_S6 11
#define _JB_S7 12
#define _JB_S8 13
#define _JB_S9 14
#define _JB_S10 15
#define _JB_S11 16
#define _JB_FCSR 17
#define _JB_FS0 18
#define _JB_FS1 (_JB_FS0 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS2 (_JB_FS1 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS3 (_JB_FS2 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS4 (_JB_FS3 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS5 (_JB_FS4 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS6 (_JB_FS5 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS7 (_JB_FS6 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS8 (_JB_FS7 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS9 (_JB_FS8 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS10 (_JB_FS9 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_FS11 (_JB_FS10 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#define _JB_SIGMASK (_JB_FS11 + sizeof(double) / sizeof(_BSD_JBSLOT_T_))
#ifndef _BSD_JBSLOT_T_
#define _BSD_JBSLOT_T_ long long
#endif

View file

@ -1,39 +0,0 @@
/* $NetBSD: signal.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_SIGNAL_H_
#define _RISCV_SIGNAL_H_
#ifndef _LOCORE
typedef __SIG_ATOMIC_TYPE__ sig_atomic_t;
#endif
#endif /* _RISCV_SIGNAL_H_ */

View file

@ -1,3 +0,0 @@
/* $NetBSD: sysarch.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/* nothing */

View file

@ -1,337 +0,0 @@
/* $NetBSD: sysreg.h,v 1.28 2022/12/03 11:09:59 skrll Exp $ */
/*
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_SYSREG_H_
#define _RISCV_SYSREG_H_
#ifndef _KERNEL
#include <sys/param.h>
#endif
#include <riscv/reg.h>
#define FCSR_FMASK 0 // no exception bits
#define FCSR_FRM __BITS(7, 5)
#define FCSR_FRM_RNE 0b000 // Round Nearest, ties to Even
#define FCSR_FRM_RTZ 0b001 // Round Towards Zero
#define FCSR_FRM_RDN 0b010 // Round DowN (-infinity)
#define FCSR_FRM_RUP 0b011 // Round UP (+infinity)
#define FCSR_FRM_RMM 0b100 // Round to nearest, ties to Max Magnitude
#define FCSR_FRM_DYN 0b111 // Dynamic rounding
#define FCSR_FFLAGS __BITS(4, 0) // Sticky bits
#define FCSR_NV __BIT(4) // iNValid operation
#define FCSR_DZ __BIT(3) // Divide by Zero
#define FCSR_OF __BIT(2) // OverFlow
#define FCSR_UF __BIT(1) // UnderFlow
#define FCSR_NX __BIT(0) // iNeXact
static inline uint32_t
riscvreg_fcsr_read(void)
{
uint32_t __fcsr;
__asm("frcsr %0" : "=r"(__fcsr));
return __fcsr;
}
static inline uint32_t
riscvreg_fcsr_write(uint32_t __new)
{
uint32_t __old;
__asm("fscsr %0, %1" : "=r"(__old) : "r"(__new));
return __old;
}
static inline uint32_t
riscvreg_fcsr_read_fflags(void)
{
uint32_t __old;
__asm("frflags %0" : "=r"(__old));
return __SHIFTOUT(__old, FCSR_FFLAGS);
}
static inline uint32_t
riscvreg_fcsr_write_fflags(uint32_t __new)
{
uint32_t __old;
__new = __SHIFTIN(__new, FCSR_FFLAGS);
__asm("fsflags %0, %1" : "=r"(__old) : "r"(__new));
return __SHIFTOUT(__old, FCSR_FFLAGS);
}
static inline uint32_t
riscvreg_fcsr_read_frm(void)
{
uint32_t __old;
__asm("frrm\t%0" : "=r"(__old));
return __SHIFTOUT(__old, FCSR_FRM);
}
static inline uint32_t
riscvreg_fcsr_write_frm(uint32_t __new)
{
uint32_t __old;
__new = __SHIFTIN(__new, FCSR_FRM);
__asm __volatile("fsrm\t%0, %1" : "=r"(__old) : "r"(__new));
return __SHIFTOUT(__old, FCSR_FRM);
}
#define RISCVREG_READ_INLINE(regname) \
static inline uintptr_t \
csr_##regname##_read(void) \
{ \
uintptr_t __rv; \
asm volatile("csrr %0, " #regname : "=r"(__rv) :: "memory"); \
return __rv; \
}
#define RISCVREG_WRITE_INLINE(regname) \
static inline void \
csr_##regname##_write(uintptr_t __val) \
{ \
asm volatile("csrw " #regname ", %0" :: "r"(__val) : "memory"); \
}
#define RISCVREG_SET_INLINE(regname) \
static inline void \
csr_##regname##_set(uintptr_t __mask) \
{ \
if (__builtin_constant_p(__mask) && __mask < 0x20) { \
asm volatile("csrsi " #regname ", %0" :: "i"(__mask) : \
"memory"); \
} else { \
asm volatile("csrs " #regname ", %0" :: "r"(__mask) : \
"memory"); \
} \
}
#define RISCVREG_CLEAR_INLINE(regname) \
static inline void \
csr_##regname##_clear(uintptr_t __mask) \
{ \
if (__builtin_constant_p(__mask) && __mask < 0x20) { \
asm volatile("csrci " #regname ", %0" :: "i"(__mask) : \
"memory"); \
} else { \
asm volatile("csrc " #regname ", %0" :: "r"(__mask) : \
"memory"); \
} \
}
#define RISCVREG_READ_WRITE_INLINE(regname) \
RISCVREG_READ_INLINE(regname) \
RISCVREG_WRITE_INLINE(regname)
#define RISCVREG_SET_CLEAR_INLINE(regname) \
RISCVREG_SET_INLINE(regname) \
RISCVREG_CLEAR_INLINE(regname)
#define RISCVREG_READ_SET_CLEAR_INLINE(regname) \
RISCVREG_READ_INLINE(regname) \
RISCVREG_SET_CLEAR_INLINE(regname)
#define RISCVREG_READ_WRITE_SET_CLEAR_INLINE(regname) \
RISCVREG_READ_WRITE_INLINE(regname) \
RISCVREG_SET_CLEAR_INLINE(regname)
/* Supervisor Status Register */
RISCVREG_READ_SET_CLEAR_INLINE(sstatus) // supervisor status register
#ifdef _LP64
#define SR_WPRI __BITS(62, 34) | __BITS(31, 20) | \
__BIT(17) | __BITS(12, 11) | __BIT(7) | __BITS(4, 2) | \
__BIT(0)
#define SR_SD __BIT(63) // any of FS or VS or XS dirty
/* Bits 62-34 are WPRI */
#define SR_UXL __BITS(33, 32) // U-mode XLEN
#define SR_UXL_32 1 // XLEN == 32
#define SR_UXL_64 2 // XLEN == 64
#define SR_UXL_128 3 // XLEN == 128
/* Bits 31-20 are WPRI*/
#else
#define SR_WPRI __BITS(30, 20) | \
__BIT(17) | __BITS(12, 11) | __BIT(7) | __BITS(4, 2) | \
__BIT(0)
#define SR_SD __BIT(31) // any of FS or VS or XS dirty
/* Bits 30-20 are WPRI*/
#endif /* _LP64 */
/* Both RV32 and RV64 have the bottom 20 bits shared */
#define SR_MXR __BIT(19) // Make eXecutable Readable
#define SR_SUM __BIT(18) // permit Supervisor User Memory access
/* Bit 17 is WPRI */
#define SR_XS __BITS(16, 15) // Vector extension state
#define SR_XS_OFF 0 // All off
#define SR_XS_SOME_ON 1 // None dirty or clean, some on
#define SR_XS_SOME_CLEAN 2 // None dirty, some clean
#define SR_XS_SOME_DIRTY 3 // Some dirty
#define SR_FS __BITS(14, 13) // Floating-point unit state
#define SR_FS_OFF 0 // Off
#define SR_FS_INITIAL 1 // Initial
#define SR_FS_CLEAN 2 // Clean
#define SR_FS_DIRTY 3 // Dirty
/* Bits 12-11 are WPRI */
#define SR_VS __BITS(10, 9) // User-mode extention state
#define SR_VS_OFF SR_FS_OFF // Off
#define SR_VS_INITIAL SR_FS_INITIAL // Initial
#define SR_VS_CLEAN SR_FS_CLEAN // Clean
#define SR_VS_DIRTY SR_FS_DIRTY // Dirty
#define SR_SPP __BIT(8) // Priv level before supervisor mode
/* Bit 7 is WPRI */
#define SR_UBE __BIT(6) // User-mode endianness
#define SR_SPIE __BIT(5) // S-Mode interrupts enabled before trap
/* Bits 4-2 are WPRI */
#define SR_SIE __BIT(1) // Supervisor mode interrupt enable
/* Bit 0 is WPRI */
/* Supervisor interrupt registers */
/* ... interrupt pending register (sip) */
RISCVREG_READ_SET_CLEAR_INLINE(sip) // supervisor interrupt pending
/* Bit (XLEN-1) - 10 is WIRI */
#define SIP_SEIP __BIT(9) // S-mode interrupt pending
/* Bit 8-6 is WIRI */
#define SIP_STIP __BIT(5) // S-mode timer interrupt pending
/* Bit 4-2 is WIRI */
#define SIP_SSIP __BIT(1) // S-mode software interrupt pending
/* Bit 0 is WIRI */
/* ... interrupt-enable register (sie) */
RISCVREG_READ_SET_CLEAR_INLINE(sie) // supervisor interrupt enable
/* Bit (XLEN-1) - 10 is WIRI */
#define SIE_SEIE __BIT(9) // S-mode interrupt enable
/* Bit 8-6 is WIRI */
#define SIE_STIE __BIT(5) // S-mode timer interrupt enable
/* Bit 4-2 is WIRI */
#define SIE_SSIE __BIT(1) // S-mode software interrupt enable
/* Bit 0 is WIRI */
/* Mask for all interrupts */
#define SIE_IM (SIE_SEI |SIE_STIE | SIE_SSIE)
#ifdef _LP64
#define SR_USER64 (SR_SPIE | SR_UXL_64) // 64-bit U-mode sstatus
#define SR_USER32 (SR_SPIE | SR_UXL_32) // 32-bit U-mode sstatus
#else
#define SR_USER (SR_SPIE) // U-mode sstatus
#endif
// Cause register
#define CAUSE_INTERRUPT_P(cause) ((cause) & __BIT(XLEN - 1))
#define CAUSE_CODE(cause) ((cause) & __BITS(XLEN - 2, 0))
// Cause register - exceptions
#define CAUSE_FETCH_MISALIGNED 0
#define CAUSE_FETCH_ACCESS 1
#define CAUSE_ILLEGAL_INSTRUCTION 2
#define CAUSE_BREAKPOINT 3
#define CAUSE_LOAD_MISALIGNED 4
#define CAUSE_LOAD_ACCESS 5
#define CAUSE_STORE_MISALIGNED 6
#define CAUSE_STORE_ACCESS 7
#define CAUSE_USER_ECALL 8
#define CAUSE_SYSCALL CAUSE_USER_ECALL /* convenience alias */
#define CAUSE_SUPERVISOR_ECALL 9
/* 10 is reserved */
#define CAUSE_MACHINE_ECALL 11
#define CAUSE_FETCH_PAGE_FAULT 12
#define CAUSE_LOAD_PAGE_FAULT 13
/* 14 is Reserved */
#define CAUSE_STORE_PAGE_FAULT 15
/* >= 16 is reserved/custom */
// Cause register - interrupts
#define IRQ_SUPERVISOR_SOFTWARE 1
#define IRQ_MACHINE_SOFTWARE 3
#define IRQ_SUPERVISOR_TIMER 5
#define IRQ_MACHINE_TIMER 7
#define IRQ_SUPERVISOR_EXTERNAL 9
#define IRQ_MACHINE_EXTERNAL 11
RISCVREG_READ_INLINE(time)
#ifdef _LP64
RISCVREG_READ_INLINE(cycle)
#else /* !_LP64 */
static inline uint64_t
csr_cycle_read(void)
{
uint32_t __hi0, __hi1, __lo0;
do {
__asm __volatile(
"csrr\t%[__hi0], cycleh"
"\n\t" "csrr\t%[__lo0], cycle"
"\n\t" "csrr\t%[__hi1], cycleh"
: [__hi0] "=r"(__hi0),
[__lo0] "=r"(__lo0),
[__hi1] "=r"(__hi1));
} while (__hi0 != __hi1);
return
__SHIFTIN(__hi0, __BITS(63, 32)) |
__SHIFTIN(__lo0, __BITS(31, 0));
}
#endif /* !_LP64 */
#ifdef _LP64
#define SATP_MODE __BITS(63, 60) // Translation mode
#define SATP_MODE_BARE 0 // No translation or protection
/* modes 1-7 reserved for standard use */
#define SATP_MODE_SV39 8 // Page-based 39-bit virt addr
#define SATP_MODE_SV48 9 // Page-based 48-bit virt addr
#define SATP_MODE_SV57 10 // Page-based 57-bit virt addr
#define SATP_MODE_SV64 11 // Page-based 64-bit virt addr
/* modes 12-13 reserved for standard use */
/* modes 14-15 designated for custom use */
#define SATP_ASID __BITS(59, 44) // Address Space Identifier
#define SATP_PPN __BITS(43, 0) // Physical Page Number
#else
#define SATP_MODE __BIT(31) // Translation mode
#define SATP_MODE_BARE 0 // No translation or protection
#define SATP_MODE_SV32 1 // Page-based 32-bit virt addr
#define SATP_ASID __BITS(30, 22) // Address Space Identifier
#define SATP_PPN __BITS(21, 0) // Physical Page Number
#endif
RISCVREG_READ_WRITE_INLINE(satp)
/* Fake "ASID" CSR (a field of SATP register) functions */
static inline uint32_t
csr_asid_read(void)
{
uintptr_t satp = csr_satp_read();
return __SHIFTOUT(satp, SATP_ASID);
}
static inline void
csr_asid_write(uint32_t asid)
{
uintptr_t satp = csr_satp_read();
satp &= ~SATP_ASID;
satp |= __SHIFTIN(asid, SATP_ASID);
csr_satp_write(satp);
}
#endif /* _RISCV_SYSREG_H_ */

View file

@ -1,116 +0,0 @@
/* $NetBSD: types.h,v 1.15 2022/11/08 13:34:17 simonb Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_TYPES_H_
#define _RISCV_TYPES_H_
#include <sys/cdefs.h>
#include <sys/featuretest.h>
#include <riscv/int_types.h>
#if defined(_KERNEL) || defined(_KMEMUSER) || defined(_KERNTYPES) || defined(_STANDALONE)
/* XLEN is the native base integer ISA width */
#define XLEN (sizeof(long) * NBBY)
typedef __uint64_t paddr_t;
typedef __uint64_t psize_t;
#define PRIxPADDR PRIx64
#define PRIxPSIZE PRIx64
#define PRIuPSIZE PRIu64
typedef __UINTPTR_TYPE__ vaddr_t;
typedef __UINTPTR_TYPE__ vsize_t;
#define PRIxVADDR PRIxPTR
#define PRIxVSIZE PRIxPTR
#define PRIuVSIZE PRIuPTR
#ifdef _LP64 // match <riscv/reg.h>
#define PRIxREGISTER PRIx64
typedef __int64_t register_t;
typedef __uint64_t uregister_t;
#else
#define PRIxREGISTER PRIx32
typedef __int32_t register_t;
typedef __uint32_t uregister_t;
#endif
typedef signed int register32_t;
typedef unsigned int uregister32_t;
#define PRIxREGISTER32 "x"
typedef unsigned int tlb_asid_t;
#endif
#if defined(_KERNEL)
typedef struct label_t { /* Used by setjmp & longjmp */
register_t lb_reg[16]; /* */
__uint32_t lb_sr;
} label_t;
#endif
typedef unsigned int __cpu_simple_lock_nv_t;
#ifdef _LP64
typedef __int64_t __register_t;
#else
typedef __int32_t __register_t;
#endif
#define __SIMPLELOCK_LOCKED 1
#define __SIMPLELOCK_UNLOCKED 0
#define __HAVE_COMMON___TLS_GET_ADDR
#define __HAVE_COMPAT_NETBSD32
#define __HAVE_CPU_COUNTER
#define __HAVE_CPU_DATA_FIRST
#define __HAVE_FAST_SOFTINTS
#define __HAVE_MM_MD_DIRECT_MAPPED_PHYS
#define __HAVE_NEW_STYLE_BUS_H
#define __HAVE_SYSCALL_INTERN
#define __HAVE_TLS_VARIANT_I
/* XXX temporary */
#define __HAVE_UNLOCKED_PMAP
#define __HAVE___LWP_GETPRIVATE_FAST
#ifdef __LP64
#define __HAVE_ATOMIC64_OPS
#define __HAVE_CPU_UAREA_ROUTINES
#endif
//#if defined(_KERNEL)
//#define __HAVE_RAS
//#endif
#if defined(_KERNEL) || defined(_KMEMUSER)
#define PCU_FPU 0
#define PCU_UNIT_COUNT 1
#endif
#endif /* _RISCV_TYPES_H_ */

View file

@ -1,203 +0,0 @@
/* $NetBSD: vmparam.h,v 1.13 2022/10/16 06:14:53 skrll Exp $ */
/*-
* Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry, and Nick Hudson.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RISCV_VMPARAM_H_
#define _RISCV_VMPARAM_H_
#include <riscv/param.h>
#ifdef _KERNEL_OPT
#include "opt_multiprocessor.h"
#endif
/*
* Machine dependent VM constants for RISCV.
*/
/*
* We use a 4K page on both RV64 and RV32 systems.
* Override PAGE_* definitions to compile-time constants.
*/
#define PAGE_SHIFT PGSHIFT
#define PAGE_SIZE (1 << PAGE_SHIFT)
#define PAGE_MASK (PAGE_SIZE - 1)
/*
* USRSTACK is the top (end) of the user stack.
*
* USRSTACK needs to start a page below the maxuser address so that a memory
* access with a maximum displacement (0x7ff) won't cross into the kernel's
* address space. We use PAGE_SIZE instead of 0x800 since these need to be
* page-aligned.
*/
#define USRSTACK (VM_MAXUSER_ADDRESS-PAGE_SIZE) /* Start of user stack */
#define USRSTACK32 ((uint32_t)VM_MAXUSER_ADDRESS32-PAGE_SIZE)
/*
* Virtual memory related constants, all in bytes
*/
#ifndef MAXTSIZ
#define MAXTSIZ (128*1024*1024) /* max text size */
#endif
#ifndef DFLDSIZ
#define DFLDSIZ (256*1024*1024) /* initial data size limit */
#endif
#ifndef MAXDSIZ
#define MAXDSIZ (1536*1024*1024) /* max data size */
#endif
#ifndef DFLSSIZ
#define DFLSSIZ (4*1024*1024) /* initial stack size limit */
#endif
#ifndef MAXSSIZ
#define MAXSSIZ (120*1024*1024) /* max stack size */
#endif
/*
* Virtual memory related constants, all in bytes
*/
#ifndef DFLDSIZ32
#define DFLDSIZ32 DFLDSIZ /* initial data size limit */
#endif
#ifndef MAXDSIZ32
#define MAXDSIZ32 MAXDSIZ /* max data size */
#endif
#ifndef DFLSSIZ32
#define DFLSSIZ32 DFLTSIZ /* initial stack size limit */
#endif
#ifndef MAXSSIZ32
#define MAXSSIZ32 MAXSSIZ /* max stack size */
#endif
/*
* PTEs for mapping user space into the kernel for phyio operations.
* The default PTE number is enough to cover 8 disks * MAXBSIZE.
*/
#ifndef USRIOSIZE
#define USRIOSIZE (MAXBSIZE/PAGE_SIZE * 8)
#endif
/*
* User/kernel map constants.
*/
#define VM_MIN_ADDRESS ((vaddr_t)0x00000000)
#ifdef _LP64 /* Sv39 / Sv48 / Sv57 */
/*
* kernel virtual space layout:
* 0xffff_ffc0_0000_0000 - 64GiB KERNEL VM Space (inc. text/data/bss)
* (0xffff_ffc0_4000_0000 +1GiB) KERNEL VM start of KVA
* (0xffff_ffd0_0000_0000 64GiB) reserved
* 0xffff_ffe0_0000_0000 - 128GiB direct mapping
*/
#define VM_MAXUSER_ADDRESS ((vaddr_t)0x0000004000000000 - 16 * PAGE_SIZE)
#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)0xffffffc000000000)
#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)0xffffffd000000000)
#else /* Sv32 */
#define VM_MAXUSER_ADDRESS ((vaddr_t)-0x7fffffff-1)/* 0xffffffff80000000 */
#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)-0x7fffffff-1)/* 0xffffffff80000000 */
#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)-0x40000000) /* 0xffffffffc0000000 */
#endif
#define VM_KERNEL_BASE VM_MIN_KERNEL_ADDRESS
#define VM_KERNEL_SIZE 0x2000000 /* 32 MiB (8 / 16 megapages) */
#define VM_KERNEL_DTB_BASE (VM_KERNEL_BASE + VM_KERNEL_SIZE)
#define VM_KERNEL_DTB_SIZE 0x1000000 /* 16 MiB (4 / 8 megapages) */
#define VM_KERNEL_IO_BASE (VM_KERNEL_DTB_BASE + VM_KERNEL_DTB_SIZE)
#define VM_KERNEL_IO_SIZE 0x1000000 /* 16 MiB (4 / 8 megapages) */
#define VM_KERNEL_RESERVED (VM_KERNEL_SIZE + VM_KERNEL_DTB_SIZE + VM_KERNEL_IO_SIZE)
#define VM_KERNEL_VM_BASE (VM_MIN_KERNEL_ADDRESS + VM_KERNEL_RESERVED)
#define VM_KERNEL_VM_SIZE (VM_MAX_KERNEL_ADDRESS - VM_KERNEL_VM_BASE)
#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS
#define VM_MAXUSER_ADDRESS32 ((vaddr_t)(1UL << 31))/* 0x0000000080000000 */
#ifdef _LP64
/*
* Since we have the address space, we map all of physical memory (RAM)
* using gigapages on SV39, terapages on SV48 and petapages on SV57.
*/
#define RISCV_DIRECTMAP_MASK ((vaddr_t) 0xffffffe000000000L)
#define RISCV_DIRECTMAP_SIZE (-RISCV_DIRECTMAP_MASK - PAGE_SIZE) /* 128GiB */
#define RISCV_DIRECTMAP_START RISCV_DIRECTMAP_MASK
#define RISCV_DIRECTMAP_END (RISCV_DIRECTMAP_START + RISCV_DIRECTMAP_SIZE)
#define RISCV_KVA_P(va) (((vaddr_t) (va) & RISCV_DIRECTMAP_MASK) != 0)
#define RISCV_PA_TO_KVA(pa) ((vaddr_t) ((pa) | RISCV_DIRECTMAP_START))
#define RISCV_KVA_TO_PA(va) ((paddr_t) ((va) & ~RISCV_DIRECTMAP_MASK))
#endif
/*
* The address to which unspecified mapping requests default
*/
#define __USE_TOPDOWN_VM
#define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
trunc_page(USRSTACK - MAXSSIZ - (sz) - user_stack_guard_size)
#define VM_DEFAULT_ADDRESS_BOTTOMUP(da, sz) \
round_page((vaddr_t)(da) + (vsize_t)maxdmap)
#define VM_DEFAULT_ADDRESS32_TOPDOWN(da, sz) \
trunc_page(USRSTACK32 - MAXSSIZ32 - (sz) - user_stack_guard_size)
#define VM_DEFAULT_ADDRESS32_BOTTOMUP(da, sz) \
round_page((vaddr_t)(da) + (vsize_t)MAXDSIZ32)
/* virtual sizes (bytes) for various kernel submaps */
#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE)
/* VM_PHYSSEG_MAX defined by platform-dependent code. */
#ifndef VM_PHYSSEG_MAX
#define VM_PHYSSEG_MAX 16
#endif
#if VM_PHYSSEG_MAX == 1
#define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST
#else
#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH
#endif
#define VM_PHYSSEG_NOADD /* can add RAM after vm_mem_init */
#ifndef VM_NFREELIST
#define VM_NFREELIST 2 /* 2 distinct memory segments */
#define VM_FREELIST_DEFAULT 0
#define VM_FREELIST_DIRECTMAP 1
#endif
#ifdef _KERNEL
#define UVM_KM_VMFREELIST riscv_poolpage_vmfreelist
extern int riscv_poolpage_vmfreelist;
#ifdef _LP64
void * cpu_uarea_alloc(bool);
bool cpu_uarea_free(void *);
#endif
#endif
#endif /* ! _RISCV_VMPARAM_H_ */

View file

@ -1,3 +0,0 @@
/* $NetBSD: wchar_limits.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
#include <sys/common_wchar_limits.h>

View file

@ -0,0 +1,664 @@
/* $NetBSD: soundcard.h,v 1.34 2021/05/09 11:28:25 nia Exp $ */
/*-
* Copyright (c) 1997, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Lennart Augustsson and Nia Alarie.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* WARNING! WARNING!
* This is an Open Sound System compatibility layer.
* Use the Native NetBSD API in <sys/audioio.h> for developing new code,
* and this only for compiling programs written for other operating systems.
*/
#ifndef _SOUNDCARD_H_
#define _SOUNDCARD_H_
#ifndef SOUND_VERSION
#define SOUND_VERSION 0x030001
#endif
#define SNDCTL_DSP_RESET _IO ('P', 0)
#define SNDCTL_DSP_SYNC _IO ('P', 1)
#define SNDCTL_DSP_SPEED _IOWR('P', 2, int)
#define SOUND_PCM_READ_RATE _IOR ('P', 2, int)
#define SNDCTL_DSP_STEREO _IOWR('P', 3, int)
#define SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int)
#define SNDCTL_DSP_SETFMT _IOWR('P', 5, int)
#define AFMT_QUERY 0x00000000
#define AFMT_MU_LAW 0x00000001
#define AFMT_A_LAW 0x00000002
#define AFMT_IMA_ADPCM 0x00000004
#define AFMT_U8 0x00000008
#define AFMT_S16_LE 0x00000010
#define AFMT_S16_BE 0x00000020
#define AFMT_S8 0x00000040
#define AFMT_U16_LE 0x00000080
#define AFMT_U16_BE 0x00000100
#define AFMT_MPEG 0x00000200 /* Not supported */
#define AFMT_AC3 0x00000400
#define AFMT_S24_LE 0x00000800 /* Not supported */
#define AFMT_S24_BE 0x00001000 /* Not supported */
#define AFMT_S32_LE 0x00002000
#define AFMT_S32_BE 0x00004000
#define AFMT_FLOAT 0x00010000 /* Not supported */
#define AFMT_SPDIF_RAW 0x00020000 /* Not supported */
#define AFMT_S24_PACKED 0x00040000 /* Not supported */
#define AFMT_VORBIS 0x00080000 /* Not supported */
#define SNDCTL_DSP_SAMPLESIZE SNDCTL_DSP_SETFMT
#define SOUND_PCM_READ_BITS _IOR ('P', 5, int)
#define SNDCTL_DSP_CHANNELS _IOWR('P', 6, int)
#define SOUND_PCM_WRITE_CHANNELS SNDCTL_DSP_CHANNELS
#define SOUND_PCM_READ_CHANNELS _IOR ('P', 6, int)
#define SOUND_PCM_WRITE_FILTER _IOWR('P', 7, int)
#define SOUND_PCM_READ_FILTER _IOR ('P', 7, int)
#define SNDCTL_DSP_POST _IO ('P', 8)
#define SNDCTL_DSP_SUBDIVIDE _IOWR('P', 9, int)
#define SNDCTL_DSP_SETFRAGMENT _IOWR('P', 10, int)
#define SNDCTL_DSP_GETFMTS _IOR ('P', 11, int)
#define SNDCTL_DSP_GETOSPACE _IOR ('P',12, struct audio_buf_info)
#define SNDCTL_DSP_GETISPACE _IOR ('P',13, struct audio_buf_info)
#define SNDCTL_DSP_NONBLOCK _IO ('P',14)
#define SNDCTL_DSP_GETCAPS _IOR ('P',15, int)
/* PCM_CAP_* were known as DSP_CAP_ before OSS 4.0 */
# define DSP_CAP_REVISION PCM_CAP_REVISION
# define DSP_CAP_DUPLEX PCM_CAP_DUPLEX
# define DSP_CAP_REALTIME PCM_CAP_REALTIME
# define DSP_CAP_BATCH PCM_CAP_BATCH
# define DSP_CAP_COPROC PCM_CAP_COPROC
# define DSP_CAP_TRIGGER PCM_CAP_TRIGGER
# define DSP_CAP_MMAP PCM_CAP_MMAP
# define DSP_CAP_INPUT PCM_CAP_INPUT
# define DSP_CAP_OUTPUT PCM_CAP_OUTPUT
# define DSP_CAP_MODEM PCM_CAP_MODEM
# define DSP_CAP_HIDDEN PCM_CAP_HIDDEN
# define DSP_CAP_VIRTUAL PCM_CAP_VIRTUAL
# define DSP_CAP_ANALOGOUT PCM_CAP_ANALOGOUT
# define DSP_CAP_ANALOGIN PCM_CAP_ANALOGIN
# define DSP_CAP_DIGITALOUT PCM_CAP_DIGITALOUT
# define DSP_CAP_DIGITALIN PCM_CAP_DIGITALIN
# define DSP_CAP_ADMASK PCM_CAP_ADMASK
# define DSP_CAP_FREERATE PCM_CAP_FREERATE
# define DSP_CAP_MULTI PCM_CAP_MULTI
# define DSP_CAP_BIND PCM_CAP_BIND
# define DSP_CAP_SHADOW PCM_CAP_SHADOW
# define PCM_CAP_REVISION 0x000000ff /* Unused in NetBSD */
# define PCM_CAP_DUPLEX 0x00000100 /* Full duplex */
# define PCM_CAP_REALTIME 0x00000200 /* Unused in NetBSD */
# define PCM_CAP_BATCH 0x00000400 /* Unused in NetBSD */
# define PCM_CAP_COPROC 0x00000800 /* Unused in NetBSD */
# define PCM_CAP_TRIGGER 0x00001000 /* Supports SETTRIGGER */
# define PCM_CAP_MMAP 0x00002000 /* Supports mmap() */
# define PCM_CAP_INPUT 0x00004000 /* Recording device */
# define PCM_CAP_OUTPUT 0x00008000 /* Playback device */
# define PCM_CAP_MODEM 0x00010000 /* Unused in NetBSD */
# define PCM_CAP_HIDDEN 0x00020000 /* Unused in NetBSD */
# define PCM_CAP_VIRTUAL 0x00040000 /* Unused in NetBSD */
# define PCM_CAP_MULTI 0x00080000 /* Simultaneous open() */
# define PCM_CAP_ANALOGOUT 0x00100000 /* Unused in NetBSD */
# define PCM_CAP_ANALOGIN 0x00200000 /* Unused in NetBSD */
# define PCM_CAP_DIGITALOUT 0x00400000 /* Unused in NetBSD */
# define PCM_CAP_DIGITALIN 0x00800000 /* Unused in NetBSD */
# define PCM_CAP_ADMASK 0x00f00000 /* Unused in NetBSD */
# define PCM_CAP_SPECIAL 0x01000000 /* Unused in NetBSD */
# define PCM_CAP_FREERATE 0x10000000 /* Freely set rate */
# define PCM_CAP_SHADOW 0x40000000 /* Unused in NetBSD */
# define PCM_CAP_BIND 0x80000000 /* Unused in NetBSD */
# define DSP_CH_ANY 0x00000000 /* No preferred mode */
# define DSP_CH_MONO 0x02000000
# define DSP_CH_STEREO 0x04000000
# define DSP_CH_MULTI 0x06000000
# define DSP_CH_MASK 0x06000000
#define SNDCTL_DSP_GETTRIGGER _IOR ('P', 16, int)
#define SNDCTL_DSP_SETTRIGGER _IOW ('P', 16, int)
# define PCM_ENABLE_INPUT 0x00000001
# define PCM_ENABLE_OUTPUT 0x00000002
#define SNDCTL_DSP_GETIPTR _IOR ('P', 17, struct count_info)
#define SNDCTL_DSP_GETOPTR _IOR ('P', 18, struct count_info)
#define SNDCTL_DSP_MAPINBUF _IOR ('P', 19, struct buffmem_desc)
#define SNDCTL_DSP_MAPOUTBUF _IOR ('P', 20, struct buffmem_desc)
#define SNDCTL_DSP_SETSYNCRO _IO ('P', 21)
#define SNDCTL_DSP_SETDUPLEX _IO ('P', 22)
#define SNDCTL_DSP_PROFILE _IOW ('P', 23, int)
#define SNDCTL_DSP_GETODELAY _IOR ('P', 23, int)
#define APF_NORMAL 0
#define APF_NETWORK 1
#define APF_CPUINTENS 2
/* Need native 16 bit format which depends on byte order */
#include <machine/endian_machdep.h>
#if _BYTE_ORDER == _LITTLE_ENDIAN
#define AFMT_U16_NE AFMT_U16_LE
#define AFMT_U16_OE AFMT_U16_BE
#define AFMT_S16_NE AFMT_S16_LE
#define AFMT_S16_OE AFMT_S16_BE
#define AFMT_S24_NE AFMT_S24_LE
#define AFMT_S24_OE AFMT_S24_BE
#define AFMT_S32_NE AFMT_S32_LE
#define AFMT_S32_OE AFMT_S32_BE
#else
#define AFMT_U16_NE AFMT_U16_BE
#define AFMT_U16_OE AFMT_U16_LE
#define AFMT_S16_NE AFMT_S16_BE
#define AFMT_S16_OE AFMT_S16_LE
#define AFMT_S24_NE AFMT_S24_BE
#define AFMT_S24_OE AFMT_S24_LE
#define AFMT_S32_NE AFMT_S32_BE
#define AFMT_S32_OE AFMT_S32_LE
#endif
/* Aliases */
#define SOUND_PCM_WRITE_BITS SNDCTL_DSP_SETFMT
#define SOUND_PCM_WRITE_RATE SNDCTL_DSP_SPEED
#define SOUND_PCM_POST SNDCTL_DSP_POST
#define SOUND_PCM_RESET SNDCTL_DSP_RESET
#define SOUND_PCM_SYNC SNDCTL_DSP_SYNC
#define SOUND_PCM_SUBDIVIDE SNDCTL_DSP_SUBDIVIDE
#define SOUND_PCM_SETFRAGMENT SNDCTL_DSP_SETFRAGMENT
#define SOUND_PCM_GETFMTS SNDCTL_DSP_GETFMTS
#define SOUND_PCM_SETFMT SNDCTL_DSP_SETFMT
#define SOUND_PCM_GETOSPACE SNDCTL_DSP_GETOSPACE
#define SOUND_PCM_GETISPACE SNDCTL_DSP_GETISPACE
#define SOUND_PCM_NONBLOCK SNDCTL_DSP_NONBLOCK
#define SOUND_PCM_GETCAPS SNDCTL_DSP_GETCAPS
#define SOUND_PCM_GETTRIGGER SNDCTL_DSP_GETTRIGGER
#define SOUND_PCM_SETTRIGGER SNDCTL_DSP_SETTRIGGER
#define SOUND_PCM_SETSYNCRO SNDCTL_DSP_SETSYNCRO
#define SOUND_PCM_GETIPTR SNDCTL_DSP_GETIPTR
#define SOUND_PCM_GETOPTR SNDCTL_DSP_GETOPTR
#define SOUND_PCM_MAPINBUF SNDCTL_DSP_MAPINBUF
#define SOUND_PCM_MAPOUTBUF SNDCTL_DSP_MAPOUTBUF
/* Mixer defines */
#define SOUND_MIXER_FIRST 0
#define SOUND_MIXER_NRDEVICES 25
#define SOUND_MIXER_VOLUME 0
#define SOUND_MIXER_BASS 1
#define SOUND_MIXER_TREBLE 2
#define SOUND_MIXER_SYNTH 3
#define SOUND_MIXER_PCM 4
#define SOUND_MIXER_SPEAKER 5
#define SOUND_MIXER_LINE 6
#define SOUND_MIXER_MIC 7
#define SOUND_MIXER_CD 8
#define SOUND_MIXER_IMIX 9
#define SOUND_MIXER_ALTPCM 10
#define SOUND_MIXER_RECLEV 11
#define SOUND_MIXER_IGAIN 12
#define SOUND_MIXER_OGAIN 13
#define SOUND_MIXER_LINE1 14
#define SOUND_MIXER_LINE2 15
#define SOUND_MIXER_LINE3 16
#define SOUND_MIXER_DIGITAL1 17
#define SOUND_MIXER_DIGITAL2 18
#define SOUND_MIXER_DIGITAL3 19
#define SOUND_MIXER_PHONEIN 20
#define SOUND_MIXER_PHONEOUT 21
#define SOUND_MIXER_VIDEO 22
#define SOUND_MIXER_RADIO 23
#define SOUND_MIXER_MONITOR 24
#define SOUND_ONOFF_MIN 28
#define SOUND_ONOFF_MAX 30
#define SOUND_MIXER_NONE 31
#define SOUND_DEVICE_LABELS {"Vol ", "Bass ", "Trebl", "Synth", "Pcm ", "Spkr ", "Line ", \
"Mic ", "CD ", "Mix ", "Pcm2 ", "Rec ", "IGain", "OGain", \
"Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \
"PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"}
#define SOUND_DEVICE_NAMES {"vol", "bass", "treble", "synth", "pcm", "speaker", "line", \
"mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \
"line1", "line2", "line3", "dig1", "dig2", "dig3", \
"phin", "phout", "video", "radio", "monitor"}
#define SOUND_MIXER_RECSRC 0xff
#define SOUND_MIXER_DEVMASK 0xfe
#define SOUND_MIXER_RECMASK 0xfd
#define SOUND_MIXER_CAPS 0xfc
#define SOUND_CAP_EXCL_INPUT 1
#define SOUND_MIXER_STEREODEVS 0xfb
#define MIXER_READ(dev) _IOR('M', dev, int)
#define SOUND_MIXER_READ_RECSRC MIXER_READ(SOUND_MIXER_RECSRC)
#define SOUND_MIXER_READ_DEVMASK MIXER_READ(SOUND_MIXER_DEVMASK)
#define SOUND_MIXER_READ_RECMASK MIXER_READ(SOUND_MIXER_RECMASK)
#define SOUND_MIXER_READ_STEREODEVS MIXER_READ(SOUND_MIXER_STEREODEVS)
#define SOUND_MIXER_READ_CAPS MIXER_READ(SOUND_MIXER_CAPS)
#define SOUND_MIXER_READ_VOLUME MIXER_READ(SOUND_MIXER_VOLUME)
#define SOUND_MIXER_READ_BASS MIXER_READ(SOUND_MIXER_BASS)
#define SOUND_MIXER_READ_TREBLE MIXER_READ(SOUND_MIXER_TREBLE)
#define SOUND_MIXER_READ_SYNTH MIXER_READ(SOUND_MIXER_SYNTH)
#define SOUND_MIXER_READ_PCM MIXER_READ(SOUND_MIXER_PCM)
#define SOUND_MIXER_READ_SPEAKER MIXER_READ(SOUND_MIXER_SPEAKER)
#define SOUND_MIXER_READ_LINE MIXER_READ(SOUND_MIXER_LINE)
#define SOUND_MIXER_READ_MIC MIXER_READ(SOUND_MIXER_MIC)
#define SOUND_MIXER_READ_CD MIXER_READ(SOUND_MIXER_CD)
#define SOUND_MIXER_READ_IMIX MIXER_READ(SOUND_MIXER_IMIX)
#define SOUND_MIXER_READ_ALTPCM MIXER_READ(SOUND_MIXER_ALTPCM)
#define SOUND_MIXER_READ_RECLEV MIXER_READ(SOUND_MIXER_RECLEV)
#define SOUND_MIXER_READ_IGAIN MIXER_READ(SOUND_MIXER_IGAIN)
#define SOUND_MIXER_READ_OGAIN MIXER_READ(SOUND_MIXER_OGAIN)
#define SOUND_MIXER_READ_LINE1 MIXER_READ(SOUND_MIXER_LINE1)
#define SOUND_MIXER_READ_LINE2 MIXER_READ(SOUND_MIXER_LINE2)
#define SOUND_MIXER_READ_LINE3 MIXER_READ(SOUND_MIXER_LINE3)
#define MIXER_WRITE(dev) _IOW ('M', dev, int)
#define MIXER_WRITE_R(dev) _IOWR('M', dev, int)
#define SOUND_MIXER_WRITE_RECSRC MIXER_WRITE(SOUND_MIXER_RECSRC)
#define SOUND_MIXER_WRITE_R_RECSRC MIXER_WRITE_R(SOUND_MIXER_RECSRC)
#define SOUND_MIXER_WRITE_VOLUME MIXER_WRITE(SOUND_MIXER_VOLUME)
#define SOUND_MIXER_WRITE_BASS MIXER_WRITE(SOUND_MIXER_BASS)
#define SOUND_MIXER_WRITE_TREBLE MIXER_WRITE(SOUND_MIXER_TREBLE)
#define SOUND_MIXER_WRITE_SYNTH MIXER_WRITE(SOUND_MIXER_SYNTH)
#define SOUND_MIXER_WRITE_PCM MIXER_WRITE(SOUND_MIXER_PCM)
#define SOUND_MIXER_WRITE_SPEAKER MIXER_WRITE(SOUND_MIXER_SPEAKER)
#define SOUND_MIXER_WRITE_LINE MIXER_WRITE(SOUND_MIXER_LINE)
#define SOUND_MIXER_WRITE_MIC MIXER_WRITE(SOUND_MIXER_MIC)
#define SOUND_MIXER_WRITE_CD MIXER_WRITE(SOUND_MIXER_CD)
#define SOUND_MIXER_WRITE_IMIX MIXER_WRITE(SOUND_MIXER_IMIX)
#define SOUND_MIXER_WRITE_ALTPCM MIXER_WRITE(SOUND_MIXER_ALTPCM)
#define SOUND_MIXER_WRITE_RECLEV MIXER_WRITE(SOUND_MIXER_RECLEV)
#define SOUND_MIXER_WRITE_IGAIN MIXER_WRITE(SOUND_MIXER_IGAIN)
#define SOUND_MIXER_WRITE_OGAIN MIXER_WRITE(SOUND_MIXER_OGAIN)
#define SOUND_MIXER_WRITE_LINE1 MIXER_WRITE(SOUND_MIXER_LINE1)
#define SOUND_MIXER_WRITE_LINE2 MIXER_WRITE(SOUND_MIXER_LINE2)
#define SOUND_MIXER_WRITE_LINE3 MIXER_WRITE(SOUND_MIXER_LINE3)
#define SOUND_MASK_VOLUME (1 << SOUND_MIXER_VOLUME)
#define SOUND_MASK_BASS (1 << SOUND_MIXER_BASS)
#define SOUND_MASK_TREBLE (1 << SOUND_MIXER_TREBLE)
#define SOUND_MASK_SYNTH (1 << SOUND_MIXER_SYNTH)
#define SOUND_MASK_PCM (1 << SOUND_MIXER_PCM)
#define SOUND_MASK_SPEAKER (1 << SOUND_MIXER_SPEAKER)
#define SOUND_MASK_LINE (1 << SOUND_MIXER_LINE)
#define SOUND_MASK_MIC (1 << SOUND_MIXER_MIC)
#define SOUND_MASK_CD (1 << SOUND_MIXER_CD)
#define SOUND_MASK_IMIX (1 << SOUND_MIXER_IMIX)
#define SOUND_MASK_ALTPCM (1 << SOUND_MIXER_ALTPCM)
#define SOUND_MASK_RECLEV (1 << SOUND_MIXER_RECLEV)
#define SOUND_MASK_IGAIN (1 << SOUND_MIXER_IGAIN)
#define SOUND_MASK_OGAIN (1 << SOUND_MIXER_OGAIN)
#define SOUND_MASK_LINE1 (1 << SOUND_MIXER_LINE1)
#define SOUND_MASK_LINE2 (1 << SOUND_MIXER_LINE2)
#define SOUND_MASK_LINE3 (1 << SOUND_MIXER_LINE3)
#define SOUND_MASK_DIGITAL1 (1 << SOUND_MIXER_DIGITAL1)
#define SOUND_MASK_DIGITAL2 (1 << SOUND_MIXER_DIGITAL2)
#define SOUND_MASK_DIGITAL3 (1 << SOUND_MIXER_DIGITAL3)
#define SOUND_MASK_PHONEIN (1 << SOUND_MIXER_PHONEIN)
#define SOUND_MASK_PHONEOUT (1 << SOUND_MIXER_PHONEOUT)
#define SOUND_MASK_VIDEO (1 << SOUND_MIXER_VIDEO)
#define SOUND_MASK_RADIO (1 << SOUND_MIXER_RADIO)
#define SOUND_MASK_MONITOR (1 << SOUND_MIXER_MONITOR)
typedef struct mixer_info {
char id[16];
char name[32];
int modify_counter;
int fillers[10];
} mixer_info;
typedef struct _old_mixer_info {
char id[16];
char name[32];
} _old_mixer_info;
#define SOUND_MIXER_INFO _IOR('M', 101, mixer_info)
#define SOUND_OLD_MIXER_INFO _IOR('M', 101, _old_mixer_info)
#define OSS_GETVERSION _IOR ('M', 118, int)
typedef struct audio_buf_info {
int fragments;
int fragstotal;
int fragsize;
int bytes;
} audio_buf_info;
typedef struct count_info {
int bytes;
int blocks;
int ptr;
} count_info;
typedef struct buffmem_desc {
unsigned int *buffer;
int size;
} buffmem_desc;
/* Some OSSv4 calls. */
/* Why is yet more duplication necessary? Sigh. */
#define OSS_OPEN_READ PCM_ENABLE_INPUT
#define OSS_OPEN_WRITE PCM_ENABLE_OUTPUT
#define OSS_OPEN_READWRITE (OSS_OPEN_READ|OSS_OPEN_WRITE)
#define OSS_DEVNODE_SIZE 32
#define OSS_LABEL_SIZE 16
#define OSS_LONGNAME_SIZE 64
#define OSS_MAX_AUDIO_DEVS 64
#define SNDCTL_DSP_GETPLAYVOL _IOR ('P',27, uint)
#define SNDCTL_DSP_SETPLAYVOL _IOW ('P',28, uint)
#define SNDCTL_DSP_GETRECVOL _IOR ('P',29, uint)
#define SNDCTL_DSP_SETRECVOL _IOW ('P',30, uint)
#define SNDCTL_DSP_SKIP _IO ('P',31)
#define SNDCTL_DSP_SILENCE _IO ('P',32)
#define SNDCTL_DSP_COOKEDMODE _IOW ('P',33, int)
#define SNDCTL_DSP_GETERROR _IOR ('P',34, struct audio_errinfo)
#define SNDCTL_DSP_CURRENT_IPTR _IOR ('P',35, oss_count_t)
#define SNDCTL_DSP_CURRENT_OPTR _IOR ('P',36, oss_count_t)
#define SNDCTL_DSP_GET_RECSRC_NAMES _IOR ('P',37, oss_mixer_enuminfo)
#define SNDCTL_DSP_GET_RECSRC _IOR ('P',38, int)
#define SNDCTL_DSP_SET_RECSRC _IOWR ('P',38, int)
#define SNDCTL_DSP_GET_PLAYTGT_NAMES _IOR ('P',39, oss_mixer_enuminfo)
#define SNDCTL_DSP_GET_PLAYTGT _IOR ('P',40, int)
#define SNDCTL_DSP_SET_PLAYTGT _IOWR ('P',40, int)
#define SNDCTL_DSP_GET_CHNORDER _IOR ('P',42, unsigned long long)
#define SNDCTL_DSP_SET_CHNORDER _IOWR ('P',42, unsigned long long)
#define SNDCTL_DSP_HALT_OUTPUT _IO ('P',70)
#define SNDCTL_DSP_RESET_OUTPUT SNDCTL_DSP_HALT_OUTPUT /* Old name */
#define SNDCTL_DSP_HALT_INPUT _IO ('P',71)
#define SNDCTL_DSP_RESET_INPUT SNDCTL_DSP_HALT_INPUT /* Old name */
#define CHID_UNDEF 0
#define CHID_L 1
#define CHID_R 2
#define CHID_C 3
#define CHID_LFE 4
#define CHID_LS 5
#define CHID_RS 6
#define CHID_LR 7
#define CHID_RR 8
#define CHNORDER_UNDEF 0x0000000000000000ULL
#define CHNORDER_NORMAL 0x0000000087654321ULL
typedef struct {
long long samples;
int fifo_samples;
int filler[32]; /* "Future use" */
} oss_count_t;
typedef struct audio_errinfo {
int play_underruns;
int rec_overruns;
unsigned int play_ptradjust; /* Obsolete */
unsigned int rec_ptradjust; /* Obsolete */
int play_errorcount; /* Unused */
int rec_errorcount; /* Unused */
int play_lasterror; /* Unused */
int rec_lasterror; /* Unused */
int play_errorparm; /* Unused */
int rec_errorparm; /* Unused */
int filler[16]; /* Unused */
} audio_errinfo;
typedef struct oss_sysinfo {
char product[32];
char version[32];
int versionnum;
char options[128]; /* Future use */
int numaudios;
int openedaudio[8]; /* Obsolete */
int numsynths; /* Obsolete */
int nummidis;
int numtimers;
int nummixers;
int openedmidi[8];
int numcards;
int numaudioengines;
char license[16];
char revision_info[256]; /* Internal Use */
int filler[172]; /* For expansion */
} oss_sysinfo;
typedef struct oss_audioinfo {
int dev; /* Set by caller */
char name[OSS_LONGNAME_SIZE];
int busy;
int pid;
int caps;
int iformats;
int oformats;
int magic; /* Unused */
char cmd[OSS_LONGNAME_SIZE];
int card_number;
int port_number;
int mixer_dev;
int legacy_device; /* Obsolete */
int enabled;
int flags; /* Reserved */
int min_rate;
int max_rate;
int min_channels;
int max_channels;
int binding; /* Reserved */
int rate_source;
char handle[32];
#define OSS_MAX_SAMPLE_RATES 20
int nrates;
int rates[OSS_MAX_SAMPLE_RATES];
char song_name[OSS_LONGNAME_SIZE];
char label[OSS_LABEL_SIZE];
int latency; /* In usecs -1 = unknown */
char devnode[OSS_DEVNODE_SIZE];
int next_play_engine;
int next_rec_engine;
int filler[184]; /* For expansion */
} oss_audioinfo;
typedef struct oss_card_info {
int card;
char shortname[16];
char longname[128];
int flags;
char hw_info[400];
int intr_count;
int ack_count;
int filler[154];
} oss_card_info;
#define SNDCTL_SYSINFO _IOR ('X', 1, oss_sysinfo)
#define OSS_SYSINFO SNDCTL_SYSINFO /* Old name */
#define SNDCTL_MIX_NRMIX _IOR ('X',2, int)
#define SNDCTL_MIX_NREXT _IOWR ('X',3, int)
#define SNDCTL_MIX_EXTINFO _IOWR ('X',4, oss_mixext)
#define SNDCTL_MIX_READ _IOWR ('X',5, oss_mixer_value)
#define SNDCTL_MIX_WRITE _IOWR ('X',6, oss_mixer_value)
#define SNDCTL_AUDIOINFO _IOWR ('X',7, oss_audioinfo)
#define SNDCTL_MIX_ENUMINFO _IOWR ('X',8, oss_mixer_enuminfo)
#define SNDCTL_MIXERINFO _IOWR ('X',10, oss_mixerinfo)
#define SNDCTL_CARDINFO _IOWR ('X',11, oss_card_info)
#define SNDCTL_ENGINEINFO _IOWR ('X',12, oss_audioinfo)
#define SNDCTL_AUDIOINFO_EX _IOWR ('X',13, oss_audioinfo)
#define SNDCTL_MIX_DESCRIPTION _IOWR ('X',14, oss_mixer_enuminfo)
#define MIXT_DEVROOT 0 /* Used for default classes */
#define MIXT_GROUP 1 /* Used for classes */
#define MIXT_ONOFF 2 /* Used for mute controls */
#define MIXT_ENUM 3 /* Used for enum controls */
#define MIXT_MONOSLIDER 4 /* Used for mono and surround controls */
#define MIXT_STEREOSLIDER 5 /* Used for stereo controls */
#define MIXT_MESSAGE 6 /* OSS compat, unused on NetBSD */
#define MIXT_MONOVU 7 /* OSS compat, unused on NetBSD */
#define MIXT_STEREOVU 8 /* OSS compat, unused on NetBSD */
#define MIXT_MONOPEAK 9 /* OSS compat, unused on NetBSD */
#define MIXT_STEREOPEAK 10 /* OSS compat, unused on NetBSD */
#define MIXT_RADIOGROUP 11 /* OSS compat, unused on NetBSD */
#define MIXT_MARKER 12 /* OSS compat, unused on NetBSD */
#define MIXT_VALUE 13 /* OSS compat, unused on NetBSD */
#define MIXT_HEXVALUE 14 /* OSS compat, unused on NetBSD */
#define MIXT_MONODB 15 /* OSS compat, unused on NetBSD */
#define MIXT_STEREODB 16 /* OSS compat, unused on NetBSD */
#define MIXT_SLIDER 17 /* OSS compat, unused on NetBSD */
#define MIXT_3D 18 /* OSS compat, unused on NetBSD */
#define MIXT_MONOSLIDER16 19 /* OSS compat, unused on NetBSD */
#define MIXT_STEREOSLIDER16 20 /* OSS compat, unused on NetBSD */
#define MIXT_MUTE 21 /* OSS compat, unused on NetBSD */
/*
* Should be used for Set controls.
* In practice nothing uses this because it's "reserved for Sun's
* implementation".
*/
#define MIXT_ENUM_MULTI 22
#define MIXF_READABLE 0x00000001 /* Value is readable: always true */
#define MIXF_WRITEABLE 0x00000002 /* Value is writable: always true */
#define MIXF_POLL 0x00000004 /* Can change between reads: always true */
#define MIXF_HZ 0x00000008 /* OSS compat, unused on NetBSD */
#define MIXF_STRING 0x00000010 /* OSS compat, unused on NetBSD */
#define MIXF_DYNAMIC 0x00000010 /* OSS compat, unused on NetBSD */
#define MIXF_OKFAIL 0x00000020 /* OSS compat, unused on NetBSD */
#define MIXF_FLAT 0x00000040 /* OSS compat, unused on NetBSD */
#define MIXF_LEGACY 0x00000080 /* OSS compat, unused on NetBSD */
#define MIXF_CENTIBEL 0x00000100 /* OSS compat, unused on NetBSD */
#define MIXF_DECIBEL 0x00000200 /* OSS compat, unused on NetBSD */
#define MIXF_MAINVOL 0x00000400 /* OSS compat, unused on NetBSD */
#define MIXF_PCMVOL 0x00000800 /* OSS compat, unused on NetBSD */
#define MIXF_RECVOL 0x00001000 /* OSS compat, unused on NetBSD */
#define MIXF_MONVOL 0x00002000 /* OSS compat, unused on NetBSD */
#define MIXF_WIDE 0x00004000 /* OSS compat, unused on NetBSD */
#define MIXF_DESCR 0x00008000 /* OSS compat, unused on NetBSD */
#define MIXF_DISABLED 0x00010000 /* OSS compat, unused on NetBSD */
/* None of the mixer capabilities are set on NetBSD. */
#define MIXER_CAP_VIRTUAL 0x00000001 /* Virtual device */
#define MIXER_CAP_LAYOUT_B 0x00000002 /* "Internal use only" */
#define MIXER_CAP_NARROW 0x00000004 /* "Conserve screen space" */
#define OSS_ID_SIZE 16
typedef char oss_id_t[OSS_ID_SIZE];
#define OSS_DEVNODE_SIZE 32
typedef char oss_devnode_t[OSS_DEVNODE_SIZE];
#define OSS_HANDLE_SIZE 32
typedef char oss_handle_t[OSS_HANDLE_SIZE];
#define OSS_LONGNAME_SIZE 64
typedef char oss_longname_t[OSS_LONGNAME_SIZE];
#define OSS_LABEL_SIZE 16
typedef char oss_label_t[OSS_LABEL_SIZE];
typedef struct oss_mixext_root {
oss_id_t id;
char name[48];
} oss_mixext_root;
typedef struct oss_mixerinfo {
int dev;
oss_id_t id;
char name[32];
int modify_counter;
int card_number;
int port_number;
oss_handle_t handle;
int magic; /* "Reserved for internal use" */
int enabled;
int caps;
int flags; /* "Reserved for internal use" */
int nrext;
int priority;
oss_devnode_t devnode;
int legacy_device;
int filler[245];
} oss_mixerinfo;
typedef struct oss_mixer_value {
int dev; /* Set by caller */
int ctrl; /* Set by caller */
int value;
int flags; /* Reserved for "future use" */
int timestamp;
int filler[8]; /* Reserved for "future use" */
} oss_mixer_value;
#define OSS_ENUM_MAXVALUE 255
#define OSS_ENUM_STRINGSIZE 3000
typedef struct oss_mixer_enuminfo {
int dev; /* Set by caller */
int ctrl; /* Set by caller */
int nvalues;
int version;
short strindex[OSS_ENUM_MAXVALUE];
char strings[OSS_ENUM_STRINGSIZE];
} oss_mixer_enuminfo;
typedef struct oss_mixext {
int dev;
int ctrl;
int type;
int maxvalue;
int minvalue;
int flags;
oss_id_t id;
int parent;
int dummy;
int timestamp;
char data[64];
unsigned char enum_present[32];
int control_no;
unsigned int desc;
char extname[32];
int update_counter;
int rgbcolor;
int filler[6];
} oss_mixext;
/*
* These are no-ops on FreeBSD, NetBSD, and Solaris,
* but are defined for compatibility with OSSv4.
*/
#define SNDCTL_SETSONG _IOW ('Y',2, oss_longname_t)
#define SNDCTL_GETSONG _IOR ('Y',2, oss_longname_t)
#define SNDCTL_SETNAME _IOW ('Y',3, oss_longname_t)
#define SNDCTL_SETLABEL _IOW ('Y',4, oss_label_t)
#define SNDCTL_GETLABEL _IOR ('Y',4, oss_label_t)
#define ioctl _oss_ioctl
/*
* If we already included <sys/ioctl.h>, then we define our own prototype,
* else we depend on <sys/ioctl.h> to do it for us. We do it this way, so
* that we don't define the prototype twice.
*/
#ifndef _SYS_IOCTL_H_
#include <sys/ioctl.h>
#else
__BEGIN_DECLS
int _oss_ioctl(int, unsigned long, ...);
__END_DECLS
#endif
#endif /* !_SOUNDCARD_H_ */

View file

@ -0,0 +1,664 @@
/* $NetBSD: soundcard.h,v 1.34 2021/05/09 11:28:25 nia Exp $ */
/*-
* Copyright (c) 1997, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Lennart Augustsson and Nia Alarie.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* WARNING! WARNING!
* This is an Open Sound System compatibility layer.
* Use the Native NetBSD API in <sys/audioio.h> for developing new code,
* and this only for compiling programs written for other operating systems.
*/
#ifndef _SOUNDCARD_H_
#define _SOUNDCARD_H_
#ifndef SOUND_VERSION
#define SOUND_VERSION 0x030001
#endif
#define SNDCTL_DSP_RESET _IO ('P', 0)
#define SNDCTL_DSP_SYNC _IO ('P', 1)
#define SNDCTL_DSP_SPEED _IOWR('P', 2, int)
#define SOUND_PCM_READ_RATE _IOR ('P', 2, int)
#define SNDCTL_DSP_STEREO _IOWR('P', 3, int)
#define SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int)
#define SNDCTL_DSP_SETFMT _IOWR('P', 5, int)
#define AFMT_QUERY 0x00000000
#define AFMT_MU_LAW 0x00000001
#define AFMT_A_LAW 0x00000002
#define AFMT_IMA_ADPCM 0x00000004
#define AFMT_U8 0x00000008
#define AFMT_S16_LE 0x00000010
#define AFMT_S16_BE 0x00000020
#define AFMT_S8 0x00000040
#define AFMT_U16_LE 0x00000080
#define AFMT_U16_BE 0x00000100
#define AFMT_MPEG 0x00000200 /* Not supported */
#define AFMT_AC3 0x00000400
#define AFMT_S24_LE 0x00000800 /* Not supported */
#define AFMT_S24_BE 0x00001000 /* Not supported */
#define AFMT_S32_LE 0x00002000
#define AFMT_S32_BE 0x00004000
#define AFMT_FLOAT 0x00010000 /* Not supported */
#define AFMT_SPDIF_RAW 0x00020000 /* Not supported */
#define AFMT_S24_PACKED 0x00040000 /* Not supported */
#define AFMT_VORBIS 0x00080000 /* Not supported */
#define SNDCTL_DSP_SAMPLESIZE SNDCTL_DSP_SETFMT
#define SOUND_PCM_READ_BITS _IOR ('P', 5, int)
#define SNDCTL_DSP_CHANNELS _IOWR('P', 6, int)
#define SOUND_PCM_WRITE_CHANNELS SNDCTL_DSP_CHANNELS
#define SOUND_PCM_READ_CHANNELS _IOR ('P', 6, int)
#define SOUND_PCM_WRITE_FILTER _IOWR('P', 7, int)
#define SOUND_PCM_READ_FILTER _IOR ('P', 7, int)
#define SNDCTL_DSP_POST _IO ('P', 8)
#define SNDCTL_DSP_SUBDIVIDE _IOWR('P', 9, int)
#define SNDCTL_DSP_SETFRAGMENT _IOWR('P', 10, int)
#define SNDCTL_DSP_GETFMTS _IOR ('P', 11, int)
#define SNDCTL_DSP_GETOSPACE _IOR ('P',12, struct audio_buf_info)
#define SNDCTL_DSP_GETISPACE _IOR ('P',13, struct audio_buf_info)
#define SNDCTL_DSP_NONBLOCK _IO ('P',14)
#define SNDCTL_DSP_GETCAPS _IOR ('P',15, int)
/* PCM_CAP_* were known as DSP_CAP_ before OSS 4.0 */
# define DSP_CAP_REVISION PCM_CAP_REVISION
# define DSP_CAP_DUPLEX PCM_CAP_DUPLEX
# define DSP_CAP_REALTIME PCM_CAP_REALTIME
# define DSP_CAP_BATCH PCM_CAP_BATCH
# define DSP_CAP_COPROC PCM_CAP_COPROC
# define DSP_CAP_TRIGGER PCM_CAP_TRIGGER
# define DSP_CAP_MMAP PCM_CAP_MMAP
# define DSP_CAP_INPUT PCM_CAP_INPUT
# define DSP_CAP_OUTPUT PCM_CAP_OUTPUT
# define DSP_CAP_MODEM PCM_CAP_MODEM
# define DSP_CAP_HIDDEN PCM_CAP_HIDDEN
# define DSP_CAP_VIRTUAL PCM_CAP_VIRTUAL
# define DSP_CAP_ANALOGOUT PCM_CAP_ANALOGOUT
# define DSP_CAP_ANALOGIN PCM_CAP_ANALOGIN
# define DSP_CAP_DIGITALOUT PCM_CAP_DIGITALOUT
# define DSP_CAP_DIGITALIN PCM_CAP_DIGITALIN
# define DSP_CAP_ADMASK PCM_CAP_ADMASK
# define DSP_CAP_FREERATE PCM_CAP_FREERATE
# define DSP_CAP_MULTI PCM_CAP_MULTI
# define DSP_CAP_BIND PCM_CAP_BIND
# define DSP_CAP_SHADOW PCM_CAP_SHADOW
# define PCM_CAP_REVISION 0x000000ff /* Unused in NetBSD */
# define PCM_CAP_DUPLEX 0x00000100 /* Full duplex */
# define PCM_CAP_REALTIME 0x00000200 /* Unused in NetBSD */
# define PCM_CAP_BATCH 0x00000400 /* Unused in NetBSD */
# define PCM_CAP_COPROC 0x00000800 /* Unused in NetBSD */
# define PCM_CAP_TRIGGER 0x00001000 /* Supports SETTRIGGER */
# define PCM_CAP_MMAP 0x00002000 /* Supports mmap() */
# define PCM_CAP_INPUT 0x00004000 /* Recording device */
# define PCM_CAP_OUTPUT 0x00008000 /* Playback device */
# define PCM_CAP_MODEM 0x00010000 /* Unused in NetBSD */
# define PCM_CAP_HIDDEN 0x00020000 /* Unused in NetBSD */
# define PCM_CAP_VIRTUAL 0x00040000 /* Unused in NetBSD */
# define PCM_CAP_MULTI 0x00080000 /* Simultaneous open() */
# define PCM_CAP_ANALOGOUT 0x00100000 /* Unused in NetBSD */
# define PCM_CAP_ANALOGIN 0x00200000 /* Unused in NetBSD */
# define PCM_CAP_DIGITALOUT 0x00400000 /* Unused in NetBSD */
# define PCM_CAP_DIGITALIN 0x00800000 /* Unused in NetBSD */
# define PCM_CAP_ADMASK 0x00f00000 /* Unused in NetBSD */
# define PCM_CAP_SPECIAL 0x01000000 /* Unused in NetBSD */
# define PCM_CAP_FREERATE 0x10000000 /* Freely set rate */
# define PCM_CAP_SHADOW 0x40000000 /* Unused in NetBSD */
# define PCM_CAP_BIND 0x80000000 /* Unused in NetBSD */
# define DSP_CH_ANY 0x00000000 /* No preferred mode */
# define DSP_CH_MONO 0x02000000
# define DSP_CH_STEREO 0x04000000
# define DSP_CH_MULTI 0x06000000
# define DSP_CH_MASK 0x06000000
#define SNDCTL_DSP_GETTRIGGER _IOR ('P', 16, int)
#define SNDCTL_DSP_SETTRIGGER _IOW ('P', 16, int)
# define PCM_ENABLE_INPUT 0x00000001
# define PCM_ENABLE_OUTPUT 0x00000002
#define SNDCTL_DSP_GETIPTR _IOR ('P', 17, struct count_info)
#define SNDCTL_DSP_GETOPTR _IOR ('P', 18, struct count_info)
#define SNDCTL_DSP_MAPINBUF _IOR ('P', 19, struct buffmem_desc)
#define SNDCTL_DSP_MAPOUTBUF _IOR ('P', 20, struct buffmem_desc)
#define SNDCTL_DSP_SETSYNCRO _IO ('P', 21)
#define SNDCTL_DSP_SETDUPLEX _IO ('P', 22)
#define SNDCTL_DSP_PROFILE _IOW ('P', 23, int)
#define SNDCTL_DSP_GETODELAY _IOR ('P', 23, int)
#define APF_NORMAL 0
#define APF_NETWORK 1
#define APF_CPUINTENS 2
/* Need native 16 bit format which depends on byte order */
#include <machine/endian_machdep.h>
#if _BYTE_ORDER == _LITTLE_ENDIAN
#define AFMT_U16_NE AFMT_U16_LE
#define AFMT_U16_OE AFMT_U16_BE
#define AFMT_S16_NE AFMT_S16_LE
#define AFMT_S16_OE AFMT_S16_BE
#define AFMT_S24_NE AFMT_S24_LE
#define AFMT_S24_OE AFMT_S24_BE
#define AFMT_S32_NE AFMT_S32_LE
#define AFMT_S32_OE AFMT_S32_BE
#else
#define AFMT_U16_NE AFMT_U16_BE
#define AFMT_U16_OE AFMT_U16_LE
#define AFMT_S16_NE AFMT_S16_BE
#define AFMT_S16_OE AFMT_S16_LE
#define AFMT_S24_NE AFMT_S24_BE
#define AFMT_S24_OE AFMT_S24_LE
#define AFMT_S32_NE AFMT_S32_BE
#define AFMT_S32_OE AFMT_S32_LE
#endif
/* Aliases */
#define SOUND_PCM_WRITE_BITS SNDCTL_DSP_SETFMT
#define SOUND_PCM_WRITE_RATE SNDCTL_DSP_SPEED
#define SOUND_PCM_POST SNDCTL_DSP_POST
#define SOUND_PCM_RESET SNDCTL_DSP_RESET
#define SOUND_PCM_SYNC SNDCTL_DSP_SYNC
#define SOUND_PCM_SUBDIVIDE SNDCTL_DSP_SUBDIVIDE
#define SOUND_PCM_SETFRAGMENT SNDCTL_DSP_SETFRAGMENT
#define SOUND_PCM_GETFMTS SNDCTL_DSP_GETFMTS
#define SOUND_PCM_SETFMT SNDCTL_DSP_SETFMT
#define SOUND_PCM_GETOSPACE SNDCTL_DSP_GETOSPACE
#define SOUND_PCM_GETISPACE SNDCTL_DSP_GETISPACE
#define SOUND_PCM_NONBLOCK SNDCTL_DSP_NONBLOCK
#define SOUND_PCM_GETCAPS SNDCTL_DSP_GETCAPS
#define SOUND_PCM_GETTRIGGER SNDCTL_DSP_GETTRIGGER
#define SOUND_PCM_SETTRIGGER SNDCTL_DSP_SETTRIGGER
#define SOUND_PCM_SETSYNCRO SNDCTL_DSP_SETSYNCRO
#define SOUND_PCM_GETIPTR SNDCTL_DSP_GETIPTR
#define SOUND_PCM_GETOPTR SNDCTL_DSP_GETOPTR
#define SOUND_PCM_MAPINBUF SNDCTL_DSP_MAPINBUF
#define SOUND_PCM_MAPOUTBUF SNDCTL_DSP_MAPOUTBUF
/* Mixer defines */
#define SOUND_MIXER_FIRST 0
#define SOUND_MIXER_NRDEVICES 25
#define SOUND_MIXER_VOLUME 0
#define SOUND_MIXER_BASS 1
#define SOUND_MIXER_TREBLE 2
#define SOUND_MIXER_SYNTH 3
#define SOUND_MIXER_PCM 4
#define SOUND_MIXER_SPEAKER 5
#define SOUND_MIXER_LINE 6
#define SOUND_MIXER_MIC 7
#define SOUND_MIXER_CD 8
#define SOUND_MIXER_IMIX 9
#define SOUND_MIXER_ALTPCM 10
#define SOUND_MIXER_RECLEV 11
#define SOUND_MIXER_IGAIN 12
#define SOUND_MIXER_OGAIN 13
#define SOUND_MIXER_LINE1 14
#define SOUND_MIXER_LINE2 15
#define SOUND_MIXER_LINE3 16
#define SOUND_MIXER_DIGITAL1 17
#define SOUND_MIXER_DIGITAL2 18
#define SOUND_MIXER_DIGITAL3 19
#define SOUND_MIXER_PHONEIN 20
#define SOUND_MIXER_PHONEOUT 21
#define SOUND_MIXER_VIDEO 22
#define SOUND_MIXER_RADIO 23
#define SOUND_MIXER_MONITOR 24
#define SOUND_ONOFF_MIN 28
#define SOUND_ONOFF_MAX 30
#define SOUND_MIXER_NONE 31
#define SOUND_DEVICE_LABELS {"Vol ", "Bass ", "Trebl", "Synth", "Pcm ", "Spkr ", "Line ", \
"Mic ", "CD ", "Mix ", "Pcm2 ", "Rec ", "IGain", "OGain", \
"Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \
"PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"}
#define SOUND_DEVICE_NAMES {"vol", "bass", "treble", "synth", "pcm", "speaker", "line", \
"mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \
"line1", "line2", "line3", "dig1", "dig2", "dig3", \
"phin", "phout", "video", "radio", "monitor"}
#define SOUND_MIXER_RECSRC 0xff
#define SOUND_MIXER_DEVMASK 0xfe
#define SOUND_MIXER_RECMASK 0xfd
#define SOUND_MIXER_CAPS 0xfc
#define SOUND_CAP_EXCL_INPUT 1
#define SOUND_MIXER_STEREODEVS 0xfb
#define MIXER_READ(dev) _IOR('M', dev, int)
#define SOUND_MIXER_READ_RECSRC MIXER_READ(SOUND_MIXER_RECSRC)
#define SOUND_MIXER_READ_DEVMASK MIXER_READ(SOUND_MIXER_DEVMASK)
#define SOUND_MIXER_READ_RECMASK MIXER_READ(SOUND_MIXER_RECMASK)
#define SOUND_MIXER_READ_STEREODEVS MIXER_READ(SOUND_MIXER_STEREODEVS)
#define SOUND_MIXER_READ_CAPS MIXER_READ(SOUND_MIXER_CAPS)
#define SOUND_MIXER_READ_VOLUME MIXER_READ(SOUND_MIXER_VOLUME)
#define SOUND_MIXER_READ_BASS MIXER_READ(SOUND_MIXER_BASS)
#define SOUND_MIXER_READ_TREBLE MIXER_READ(SOUND_MIXER_TREBLE)
#define SOUND_MIXER_READ_SYNTH MIXER_READ(SOUND_MIXER_SYNTH)
#define SOUND_MIXER_READ_PCM MIXER_READ(SOUND_MIXER_PCM)
#define SOUND_MIXER_READ_SPEAKER MIXER_READ(SOUND_MIXER_SPEAKER)
#define SOUND_MIXER_READ_LINE MIXER_READ(SOUND_MIXER_LINE)
#define SOUND_MIXER_READ_MIC MIXER_READ(SOUND_MIXER_MIC)
#define SOUND_MIXER_READ_CD MIXER_READ(SOUND_MIXER_CD)
#define SOUND_MIXER_READ_IMIX MIXER_READ(SOUND_MIXER_IMIX)
#define SOUND_MIXER_READ_ALTPCM MIXER_READ(SOUND_MIXER_ALTPCM)
#define SOUND_MIXER_READ_RECLEV MIXER_READ(SOUND_MIXER_RECLEV)
#define SOUND_MIXER_READ_IGAIN MIXER_READ(SOUND_MIXER_IGAIN)
#define SOUND_MIXER_READ_OGAIN MIXER_READ(SOUND_MIXER_OGAIN)
#define SOUND_MIXER_READ_LINE1 MIXER_READ(SOUND_MIXER_LINE1)
#define SOUND_MIXER_READ_LINE2 MIXER_READ(SOUND_MIXER_LINE2)
#define SOUND_MIXER_READ_LINE3 MIXER_READ(SOUND_MIXER_LINE3)
#define MIXER_WRITE(dev) _IOW ('M', dev, int)
#define MIXER_WRITE_R(dev) _IOWR('M', dev, int)
#define SOUND_MIXER_WRITE_RECSRC MIXER_WRITE(SOUND_MIXER_RECSRC)
#define SOUND_MIXER_WRITE_R_RECSRC MIXER_WRITE_R(SOUND_MIXER_RECSRC)
#define SOUND_MIXER_WRITE_VOLUME MIXER_WRITE(SOUND_MIXER_VOLUME)
#define SOUND_MIXER_WRITE_BASS MIXER_WRITE(SOUND_MIXER_BASS)
#define SOUND_MIXER_WRITE_TREBLE MIXER_WRITE(SOUND_MIXER_TREBLE)
#define SOUND_MIXER_WRITE_SYNTH MIXER_WRITE(SOUND_MIXER_SYNTH)
#define SOUND_MIXER_WRITE_PCM MIXER_WRITE(SOUND_MIXER_PCM)
#define SOUND_MIXER_WRITE_SPEAKER MIXER_WRITE(SOUND_MIXER_SPEAKER)
#define SOUND_MIXER_WRITE_LINE MIXER_WRITE(SOUND_MIXER_LINE)
#define SOUND_MIXER_WRITE_MIC MIXER_WRITE(SOUND_MIXER_MIC)
#define SOUND_MIXER_WRITE_CD MIXER_WRITE(SOUND_MIXER_CD)
#define SOUND_MIXER_WRITE_IMIX MIXER_WRITE(SOUND_MIXER_IMIX)
#define SOUND_MIXER_WRITE_ALTPCM MIXER_WRITE(SOUND_MIXER_ALTPCM)
#define SOUND_MIXER_WRITE_RECLEV MIXER_WRITE(SOUND_MIXER_RECLEV)
#define SOUND_MIXER_WRITE_IGAIN MIXER_WRITE(SOUND_MIXER_IGAIN)
#define SOUND_MIXER_WRITE_OGAIN MIXER_WRITE(SOUND_MIXER_OGAIN)
#define SOUND_MIXER_WRITE_LINE1 MIXER_WRITE(SOUND_MIXER_LINE1)
#define SOUND_MIXER_WRITE_LINE2 MIXER_WRITE(SOUND_MIXER_LINE2)
#define SOUND_MIXER_WRITE_LINE3 MIXER_WRITE(SOUND_MIXER_LINE3)
#define SOUND_MASK_VOLUME (1 << SOUND_MIXER_VOLUME)
#define SOUND_MASK_BASS (1 << SOUND_MIXER_BASS)
#define SOUND_MASK_TREBLE (1 << SOUND_MIXER_TREBLE)
#define SOUND_MASK_SYNTH (1 << SOUND_MIXER_SYNTH)
#define SOUND_MASK_PCM (1 << SOUND_MIXER_PCM)
#define SOUND_MASK_SPEAKER (1 << SOUND_MIXER_SPEAKER)
#define SOUND_MASK_LINE (1 << SOUND_MIXER_LINE)
#define SOUND_MASK_MIC (1 << SOUND_MIXER_MIC)
#define SOUND_MASK_CD (1 << SOUND_MIXER_CD)
#define SOUND_MASK_IMIX (1 << SOUND_MIXER_IMIX)
#define SOUND_MASK_ALTPCM (1 << SOUND_MIXER_ALTPCM)
#define SOUND_MASK_RECLEV (1 << SOUND_MIXER_RECLEV)
#define SOUND_MASK_IGAIN (1 << SOUND_MIXER_IGAIN)
#define SOUND_MASK_OGAIN (1 << SOUND_MIXER_OGAIN)
#define SOUND_MASK_LINE1 (1 << SOUND_MIXER_LINE1)
#define SOUND_MASK_LINE2 (1 << SOUND_MIXER_LINE2)
#define SOUND_MASK_LINE3 (1 << SOUND_MIXER_LINE3)
#define SOUND_MASK_DIGITAL1 (1 << SOUND_MIXER_DIGITAL1)
#define SOUND_MASK_DIGITAL2 (1 << SOUND_MIXER_DIGITAL2)
#define SOUND_MASK_DIGITAL3 (1 << SOUND_MIXER_DIGITAL3)
#define SOUND_MASK_PHONEIN (1 << SOUND_MIXER_PHONEIN)
#define SOUND_MASK_PHONEOUT (1 << SOUND_MIXER_PHONEOUT)
#define SOUND_MASK_VIDEO (1 << SOUND_MIXER_VIDEO)
#define SOUND_MASK_RADIO (1 << SOUND_MIXER_RADIO)
#define SOUND_MASK_MONITOR (1 << SOUND_MIXER_MONITOR)
typedef struct mixer_info {
char id[16];
char name[32];
int modify_counter;
int fillers[10];
} mixer_info;
typedef struct _old_mixer_info {
char id[16];
char name[32];
} _old_mixer_info;
#define SOUND_MIXER_INFO _IOR('M', 101, mixer_info)
#define SOUND_OLD_MIXER_INFO _IOR('M', 101, _old_mixer_info)
#define OSS_GETVERSION _IOR ('M', 118, int)
typedef struct audio_buf_info {
int fragments;
int fragstotal;
int fragsize;
int bytes;
} audio_buf_info;
typedef struct count_info {
int bytes;
int blocks;
int ptr;
} count_info;
typedef struct buffmem_desc {
unsigned int *buffer;
int size;
} buffmem_desc;
/* Some OSSv4 calls. */
/* Why is yet more duplication necessary? Sigh. */
#define OSS_OPEN_READ PCM_ENABLE_INPUT
#define OSS_OPEN_WRITE PCM_ENABLE_OUTPUT
#define OSS_OPEN_READWRITE (OSS_OPEN_READ|OSS_OPEN_WRITE)
#define OSS_DEVNODE_SIZE 32
#define OSS_LABEL_SIZE 16
#define OSS_LONGNAME_SIZE 64
#define OSS_MAX_AUDIO_DEVS 64
#define SNDCTL_DSP_GETPLAYVOL _IOR ('P',27, uint)
#define SNDCTL_DSP_SETPLAYVOL _IOW ('P',28, uint)
#define SNDCTL_DSP_GETRECVOL _IOR ('P',29, uint)
#define SNDCTL_DSP_SETRECVOL _IOW ('P',30, uint)
#define SNDCTL_DSP_SKIP _IO ('P',31)
#define SNDCTL_DSP_SILENCE _IO ('P',32)
#define SNDCTL_DSP_COOKEDMODE _IOW ('P',33, int)
#define SNDCTL_DSP_GETERROR _IOR ('P',34, struct audio_errinfo)
#define SNDCTL_DSP_CURRENT_IPTR _IOR ('P',35, oss_count_t)
#define SNDCTL_DSP_CURRENT_OPTR _IOR ('P',36, oss_count_t)
#define SNDCTL_DSP_GET_RECSRC_NAMES _IOR ('P',37, oss_mixer_enuminfo)
#define SNDCTL_DSP_GET_RECSRC _IOR ('P',38, int)
#define SNDCTL_DSP_SET_RECSRC _IOWR ('P',38, int)
#define SNDCTL_DSP_GET_PLAYTGT_NAMES _IOR ('P',39, oss_mixer_enuminfo)
#define SNDCTL_DSP_GET_PLAYTGT _IOR ('P',40, int)
#define SNDCTL_DSP_SET_PLAYTGT _IOWR ('P',40, int)
#define SNDCTL_DSP_GET_CHNORDER _IOR ('P',42, unsigned long long)
#define SNDCTL_DSP_SET_CHNORDER _IOWR ('P',42, unsigned long long)
#define SNDCTL_DSP_HALT_OUTPUT _IO ('P',70)
#define SNDCTL_DSP_RESET_OUTPUT SNDCTL_DSP_HALT_OUTPUT /* Old name */
#define SNDCTL_DSP_HALT_INPUT _IO ('P',71)
#define SNDCTL_DSP_RESET_INPUT SNDCTL_DSP_HALT_INPUT /* Old name */
#define CHID_UNDEF 0
#define CHID_L 1
#define CHID_R 2
#define CHID_C 3
#define CHID_LFE 4
#define CHID_LS 5
#define CHID_RS 6
#define CHID_LR 7
#define CHID_RR 8
#define CHNORDER_UNDEF 0x0000000000000000ULL
#define CHNORDER_NORMAL 0x0000000087654321ULL
typedef struct {
long long samples;
int fifo_samples;
int filler[32]; /* "Future use" */
} oss_count_t;
typedef struct audio_errinfo {
int play_underruns;
int rec_overruns;
unsigned int play_ptradjust; /* Obsolete */
unsigned int rec_ptradjust; /* Obsolete */
int play_errorcount; /* Unused */
int rec_errorcount; /* Unused */
int play_lasterror; /* Unused */
int rec_lasterror; /* Unused */
int play_errorparm; /* Unused */
int rec_errorparm; /* Unused */
int filler[16]; /* Unused */
} audio_errinfo;
typedef struct oss_sysinfo {
char product[32];
char version[32];
int versionnum;
char options[128]; /* Future use */
int numaudios;
int openedaudio[8]; /* Obsolete */
int numsynths; /* Obsolete */
int nummidis;
int numtimers;
int nummixers;
int openedmidi[8];
int numcards;
int numaudioengines;
char license[16];
char revision_info[256]; /* Internal Use */
int filler[172]; /* For expansion */
} oss_sysinfo;
typedef struct oss_audioinfo {
int dev; /* Set by caller */
char name[OSS_LONGNAME_SIZE];
int busy;
int pid;
int caps;
int iformats;
int oformats;
int magic; /* Unused */
char cmd[OSS_LONGNAME_SIZE];
int card_number;
int port_number;
int mixer_dev;
int legacy_device; /* Obsolete */
int enabled;
int flags; /* Reserved */
int min_rate;
int max_rate;
int min_channels;
int max_channels;
int binding; /* Reserved */
int rate_source;
char handle[32];
#define OSS_MAX_SAMPLE_RATES 20
int nrates;
int rates[OSS_MAX_SAMPLE_RATES];
char song_name[OSS_LONGNAME_SIZE];
char label[OSS_LABEL_SIZE];
int latency; /* In usecs -1 = unknown */
char devnode[OSS_DEVNODE_SIZE];
int next_play_engine;
int next_rec_engine;
int filler[184]; /* For expansion */
} oss_audioinfo;
typedef struct oss_card_info {
int card;
char shortname[16];
char longname[128];
int flags;
char hw_info[400];
int intr_count;
int ack_count;
int filler[154];
} oss_card_info;
#define SNDCTL_SYSINFO _IOR ('X', 1, oss_sysinfo)
#define OSS_SYSINFO SNDCTL_SYSINFO /* Old name */
#define SNDCTL_MIX_NRMIX _IOR ('X',2, int)
#define SNDCTL_MIX_NREXT _IOWR ('X',3, int)
#define SNDCTL_MIX_EXTINFO _IOWR ('X',4, oss_mixext)
#define SNDCTL_MIX_READ _IOWR ('X',5, oss_mixer_value)
#define SNDCTL_MIX_WRITE _IOWR ('X',6, oss_mixer_value)
#define SNDCTL_AUDIOINFO _IOWR ('X',7, oss_audioinfo)
#define SNDCTL_MIX_ENUMINFO _IOWR ('X',8, oss_mixer_enuminfo)
#define SNDCTL_MIXERINFO _IOWR ('X',10, oss_mixerinfo)
#define SNDCTL_CARDINFO _IOWR ('X',11, oss_card_info)
#define SNDCTL_ENGINEINFO _IOWR ('X',12, oss_audioinfo)
#define SNDCTL_AUDIOINFO_EX _IOWR ('X',13, oss_audioinfo)
#define SNDCTL_MIX_DESCRIPTION _IOWR ('X',14, oss_mixer_enuminfo)
#define MIXT_DEVROOT 0 /* Used for default classes */
#define MIXT_GROUP 1 /* Used for classes */
#define MIXT_ONOFF 2 /* Used for mute controls */
#define MIXT_ENUM 3 /* Used for enum controls */
#define MIXT_MONOSLIDER 4 /* Used for mono and surround controls */
#define MIXT_STEREOSLIDER 5 /* Used for stereo controls */
#define MIXT_MESSAGE 6 /* OSS compat, unused on NetBSD */
#define MIXT_MONOVU 7 /* OSS compat, unused on NetBSD */
#define MIXT_STEREOVU 8 /* OSS compat, unused on NetBSD */
#define MIXT_MONOPEAK 9 /* OSS compat, unused on NetBSD */
#define MIXT_STEREOPEAK 10 /* OSS compat, unused on NetBSD */
#define MIXT_RADIOGROUP 11 /* OSS compat, unused on NetBSD */
#define MIXT_MARKER 12 /* OSS compat, unused on NetBSD */
#define MIXT_VALUE 13 /* OSS compat, unused on NetBSD */
#define MIXT_HEXVALUE 14 /* OSS compat, unused on NetBSD */
#define MIXT_MONODB 15 /* OSS compat, unused on NetBSD */
#define MIXT_STEREODB 16 /* OSS compat, unused on NetBSD */
#define MIXT_SLIDER 17 /* OSS compat, unused on NetBSD */
#define MIXT_3D 18 /* OSS compat, unused on NetBSD */
#define MIXT_MONOSLIDER16 19 /* OSS compat, unused on NetBSD */
#define MIXT_STEREOSLIDER16 20 /* OSS compat, unused on NetBSD */
#define MIXT_MUTE 21 /* OSS compat, unused on NetBSD */
/*
* Should be used for Set controls.
* In practice nothing uses this because it's "reserved for Sun's
* implementation".
*/
#define MIXT_ENUM_MULTI 22
#define MIXF_READABLE 0x00000001 /* Value is readable: always true */
#define MIXF_WRITEABLE 0x00000002 /* Value is writable: always true */
#define MIXF_POLL 0x00000004 /* Can change between reads: always true */
#define MIXF_HZ 0x00000008 /* OSS compat, unused on NetBSD */
#define MIXF_STRING 0x00000010 /* OSS compat, unused on NetBSD */
#define MIXF_DYNAMIC 0x00000010 /* OSS compat, unused on NetBSD */
#define MIXF_OKFAIL 0x00000020 /* OSS compat, unused on NetBSD */
#define MIXF_FLAT 0x00000040 /* OSS compat, unused on NetBSD */
#define MIXF_LEGACY 0x00000080 /* OSS compat, unused on NetBSD */
#define MIXF_CENTIBEL 0x00000100 /* OSS compat, unused on NetBSD */
#define MIXF_DECIBEL 0x00000200 /* OSS compat, unused on NetBSD */
#define MIXF_MAINVOL 0x00000400 /* OSS compat, unused on NetBSD */
#define MIXF_PCMVOL 0x00000800 /* OSS compat, unused on NetBSD */
#define MIXF_RECVOL 0x00001000 /* OSS compat, unused on NetBSD */
#define MIXF_MONVOL 0x00002000 /* OSS compat, unused on NetBSD */
#define MIXF_WIDE 0x00004000 /* OSS compat, unused on NetBSD */
#define MIXF_DESCR 0x00008000 /* OSS compat, unused on NetBSD */
#define MIXF_DISABLED 0x00010000 /* OSS compat, unused on NetBSD */
/* None of the mixer capabilities are set on NetBSD. */
#define MIXER_CAP_VIRTUAL 0x00000001 /* Virtual device */
#define MIXER_CAP_LAYOUT_B 0x00000002 /* "Internal use only" */
#define MIXER_CAP_NARROW 0x00000004 /* "Conserve screen space" */
#define OSS_ID_SIZE 16
typedef char oss_id_t[OSS_ID_SIZE];
#define OSS_DEVNODE_SIZE 32
typedef char oss_devnode_t[OSS_DEVNODE_SIZE];
#define OSS_HANDLE_SIZE 32
typedef char oss_handle_t[OSS_HANDLE_SIZE];
#define OSS_LONGNAME_SIZE 64
typedef char oss_longname_t[OSS_LONGNAME_SIZE];
#define OSS_LABEL_SIZE 16
typedef char oss_label_t[OSS_LABEL_SIZE];
typedef struct oss_mixext_root {
oss_id_t id;
char name[48];
} oss_mixext_root;
typedef struct oss_mixerinfo {
int dev;
oss_id_t id;
char name[32];
int modify_counter;
int card_number;
int port_number;
oss_handle_t handle;
int magic; /* "Reserved for internal use" */
int enabled;
int caps;
int flags; /* "Reserved for internal use" */
int nrext;
int priority;
oss_devnode_t devnode;
int legacy_device;
int filler[245];
} oss_mixerinfo;
typedef struct oss_mixer_value {
int dev; /* Set by caller */
int ctrl; /* Set by caller */
int value;
int flags; /* Reserved for "future use" */
int timestamp;
int filler[8]; /* Reserved for "future use" */
} oss_mixer_value;
#define OSS_ENUM_MAXVALUE 255
#define OSS_ENUM_STRINGSIZE 3000
typedef struct oss_mixer_enuminfo {
int dev; /* Set by caller */
int ctrl; /* Set by caller */
int nvalues;
int version;
short strindex[OSS_ENUM_MAXVALUE];
char strings[OSS_ENUM_STRINGSIZE];
} oss_mixer_enuminfo;
typedef struct oss_mixext {
int dev;
int ctrl;
int type;
int maxvalue;
int minvalue;
int flags;
oss_id_t id;
int parent;
int dummy;
int timestamp;
char data[64];
unsigned char enum_present[32];
int control_no;
unsigned int desc;
char extname[32];
int update_counter;
int rgbcolor;
int filler[6];
} oss_mixext;
/*
* These are no-ops on FreeBSD, NetBSD, and Solaris,
* but are defined for compatibility with OSSv4.
*/
#define SNDCTL_SETSONG _IOW ('Y',2, oss_longname_t)
#define SNDCTL_GETSONG _IOR ('Y',2, oss_longname_t)
#define SNDCTL_SETNAME _IOW ('Y',3, oss_longname_t)
#define SNDCTL_SETLABEL _IOW ('Y',4, oss_label_t)
#define SNDCTL_GETLABEL _IOR ('Y',4, oss_label_t)
#define ioctl _oss_ioctl
/*
* If we already included <sys/ioctl.h>, then we define our own prototype,
* else we depend on <sys/ioctl.h> to do it for us. We do it this way, so
* that we don't define the prototype twice.
*/
#ifndef _SYS_IOCTL_H_
#include <sys/ioctl.h>
#else
__BEGIN_DECLS
int _oss_ioctl(int, unsigned long, ...);
__END_DECLS
#endif
#endif /* !_SOUNDCARD_H_ */

View file

@ -0,0 +1,3 @@
/* $NetBSD: bswap.h,v 1.1 2002/12/09 12:15:58 scw Exp $ */
#include <powerpc/bswap.h>

View file

@ -0,0 +1,3 @@
/* $NetBSD: endian_machdep.h,v 1.1 2002/12/09 12:16:02 scw Exp $ */
#include <powerpc/endian_machdep.h>

View file

@ -0,0 +1,3 @@
/* $NetBSD: rwlock.h,v 1.2 2007/02/09 21:55:03 ad Exp $ */
#include <powerpc/rwlock.h>

View file

@ -1,8 +0,0 @@
/* $NetBSD: bswap.h,v 1.2 1999/08/21 05:39:55 simonb Exp $ */
#ifndef _MACHINE_BSWAP_H_
#define _MACHINE_BSWAP_H_
#include <sys/bswap.h>
#endif /* !_MACHINE_BSWAP_H_ */

View file

@ -1,3 +0,0 @@
/* $NetBSD: endian_machdep.h,v 1.1 2000/03/17 00:09:25 mycroft Exp $ */
#define _BYTE_ORDER _BIG_ENDIAN

Some files were not shown because too many files have changed in this diff Show more