Remove sciter and tcc packages
This commit is contained in:
1
packages/sciter/.gitignore
vendored
1
packages/sciter/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/sciter-js-sdk
|
||||
19
packages/sciter/.vscode/launch.json
vendored
19
packages/sciter/.vscode/launch.json
vendored
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch",
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/zig-out/bin/sciter",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/zig-out/bin",
|
||||
},
|
||||
{
|
||||
"name": "Attach",
|
||||
"type": "lldb",
|
||||
"request": "attach",
|
||||
"program": "${workspaceFolder}/zig-out/bin/sciter",
|
||||
},
|
||||
]
|
||||
}
|
||||
6
packages/sciter/.vscode/settings.json
vendored
6
packages/sciter/.vscode/settings.json
vendored
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"lldb.displayFormat": "auto",
|
||||
"lldb.showDisassembly": "always",
|
||||
"lldb.dereferencePointers": true,
|
||||
"lldb.consoleMode": "commands"
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{
|
||||
.whitelist = &.{
|
||||
.{
|
||||
.cpu_arch = .x86_64,
|
||||
.os_tag = .windows,
|
||||
.abi = .msvc,
|
||||
},
|
||||
.{
|
||||
.cpu_arch = .aarch64,
|
||||
.os_tag = .windows,
|
||||
.abi = .msvc,
|
||||
},
|
||||
.{
|
||||
.cpu_arch = .x86_64,
|
||||
.os_tag = .linux,
|
||||
.abi = .gnu,
|
||||
},
|
||||
.{
|
||||
.cpu_arch = .aarch64,
|
||||
.os_tag = .linux,
|
||||
.abi = .gnu,
|
||||
},
|
||||
},
|
||||
});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const llvm = b.option(bool, "llvm", "Use LLVM and LLD") orelse false;
|
||||
|
||||
const exe_mod = b.createModule(.{
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "sciter",
|
||||
.root_module = exe_mod,
|
||||
.use_llvm = llvm,
|
||||
.use_lld = llvm,
|
||||
});
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
switch (target.result.os.tag) {
|
||||
.windows => {
|
||||
const zigwin32 = b.dependency("zigwin32", .{});
|
||||
const zigwin32_mod = zigwin32.module("win32");
|
||||
zigwin32_mod.resolved_target = target;
|
||||
zigwin32_mod.optimize = optimize;
|
||||
|
||||
exe_mod.addImport("win32", zigwin32_mod);
|
||||
|
||||
const dll_source_path = b.path(b.fmt("vendor/windows/{s}/sciter.dll", .{@tagName(target.result.cpu.arch)}));
|
||||
const dll_dest_path = "sciter.dll";
|
||||
|
||||
b.getInstallStep().dependOn(&b.addInstallBinFile(dll_source_path, dll_dest_path).step);
|
||||
},
|
||||
.linux => {
|
||||
exe_mod.linkSystemLibrary("c", .{});
|
||||
exe_mod.linkSystemLibrary("X11", .{});
|
||||
|
||||
const so_source_path = b.path(b.fmt("vendor/linux/{s}/libsciter.so", .{@tagName(target.result.cpu.arch)}));
|
||||
const so_dest_path = "libsciter.so";
|
||||
|
||||
b.getInstallStep().dependOn(&b.addInstallBinFile(so_source_path, so_dest_path).step);
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
// TODO It does not look like the cleanest solution, however, the build
|
||||
// system code is too cryptic to come up with a better solution and the
|
||||
// Internet is surprisingly silent about this very basic use case.
|
||||
run_cmd.setCwd(.{ .cwd_relative = b.exe_dir });
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
.{
|
||||
.name = .sciter,
|
||||
.version = "0.0.0",
|
||||
.minimum_zig_version = "0.15.2",
|
||||
.paths = .{
|
||||
"src",
|
||||
"vendor",
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
},
|
||||
.fingerprint = 0x51b124a630f074d7,
|
||||
.dependencies = .{
|
||||
.zigwin32 = .{
|
||||
.url = "https://github.com/marlersoft/zigwin32/archive/5587b16fa040573846a6bf531301f6206d31a6bf.zip",
|
||||
.hash = "zigwin32-25.0.28-preview-AAAAAICM5AMResOGQnQ85mfe60TTOQeMtt7GRATUOKoP",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Sciter Demo</title>
|
||||
<style>
|
||||
html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: white;
|
||||
color: black;
|
||||
}
|
||||
|
||||
#hello {
|
||||
width: 120px;
|
||||
height: 32px;
|
||||
|
||||
margin: 1*;
|
||||
padding: 0;
|
||||
|
||||
border: 1px solid black;
|
||||
|
||||
text-align: center;
|
||||
line-height: 32px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p id="hello">Hello, World!</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,226 +0,0 @@
|
||||
const sciter = @import("sciter.zig");
|
||||
const std = @import("std");
|
||||
const x11 = @import("x11.zig");
|
||||
const wam = @import("win32").ui.windows_and_messaging;
|
||||
const win32 = @import("win32").foundation;
|
||||
|
||||
const L = std.unicode.utf8ToUtf16LeStringLiteral;
|
||||
const WINAPI = @import("std").builtin.CallingConvention.winapi;
|
||||
|
||||
const html = @embedFile("index.html");
|
||||
|
||||
const min_track_size: win32.POINT = .{ .x = 640, .y = 480 };
|
||||
|
||||
var sciter_api: *sciter.API = undefined;
|
||||
|
||||
pub fn wWinMain(
|
||||
hInstance: std.os.windows.HINSTANCE,
|
||||
hPrevInstance: ?std.os.windows.HINSTANCE,
|
||||
lpCmdLine: [*:0]u16,
|
||||
nCmdShow: i32,
|
||||
) i32 {
|
||||
_ = hPrevInstance;
|
||||
_ = lpCmdLine;
|
||||
|
||||
const sciter_module = std.os.windows.LoadLibraryW(L("sciter.dll")) catch |err| {
|
||||
_ = wam.MessageBoxW(
|
||||
null,
|
||||
switch (err) {
|
||||
error.FileNotFound => L("Couldn't find sciter.dll."),
|
||||
else => L("An unknown error occured while trying to load sciter.dll."),
|
||||
},
|
||||
L("Critical error"),
|
||||
wam.MB_ICONHAND,
|
||||
);
|
||||
std.posix.exit(1);
|
||||
};
|
||||
|
||||
const sciter_api_fn: *const fn () ?*sciter.API = @ptrCast(std.os.windows.kernel32.GetProcAddress(sciter_module, "SciterAPI") orelse {
|
||||
_ = wam.MessageBoxW(null, L("Couldn't load Sciter API."), L("Critical error"), wam.MB_ICONHAND);
|
||||
std.posix.exit(1);
|
||||
});
|
||||
|
||||
sciter_api = sciter_api_fn() orelse {
|
||||
_ = wam.MessageBoxW(null, L("Couldn't load Sciter API."), L("Critical error"), wam.MB_ICONHAND);
|
||||
std.posix.exit(1);
|
||||
};
|
||||
|
||||
std.debug.print("Sciter API version is: 0x{X:0>8}\n", .{sciter_api.version});
|
||||
|
||||
const wc = std.mem.zeroInit(wam.WNDCLASSEXW, .{
|
||||
.cbSize = @sizeOf(wam.WNDCLASSEXW),
|
||||
.lpfnWndProc = &WindowProc,
|
||||
.hInstance = hInstance,
|
||||
.hIcon = wam.LoadIconW(null, wam.IDI_APPLICATION),
|
||||
.hCursor = wam.LoadCursorW(null, wam.IDC_ARROW),
|
||||
.lpszClassName = L("SCITER_WINDOW"),
|
||||
});
|
||||
|
||||
const atom = wam.RegisterClassExW(&wc);
|
||||
std.debug.assert(atom != 0);
|
||||
|
||||
const hwnd = wam.CreateWindowExW(
|
||||
wam.WS_EX_APPWINDOW,
|
||||
wc.lpszClassName,
|
||||
L("Sciter Demo"),
|
||||
wam.WS_OVERLAPPEDWINDOW,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
wc.hInstance,
|
||||
null,
|
||||
) orelse {
|
||||
_ = wam.MessageBoxW(null, L("Couldn't create window."), L("Critical error"), wam.MB_ICONHAND);
|
||||
std.posix.exit(1);
|
||||
};
|
||||
|
||||
_ = sciter_api.SciterSetOption(null, 10, 1);
|
||||
sciter_api.SciterSetupDebugOutput(hwnd, null, &sciterDebugOutputProc);
|
||||
_ = sciter_api.SciterLoadHtml(hwnd, html, html.len, L("/"));
|
||||
_ = wam.ShowWindow(hwnd, @bitCast(nCmdShow));
|
||||
|
||||
var msg = std.mem.zeroes(wam.MSG);
|
||||
while (wam.GetMessageW(&msg, null, 0, 0) > 0) {
|
||||
_ = wam.TranslateMessage(&msg);
|
||||
_ = wam.DispatchMessageW(&msg);
|
||||
}
|
||||
|
||||
return @bitCast(@as(u32, @truncate(msg.wParam)));
|
||||
}
|
||||
|
||||
fn WindowProc(
|
||||
hwnd: win32.HWND,
|
||||
uMsg: u32,
|
||||
wParam: win32.WPARAM,
|
||||
lParam: win32.LPARAM,
|
||||
) callconv(WINAPI) win32.LRESULT {
|
||||
switch (uMsg) {
|
||||
wam.WM_DESTROY => {
|
||||
wam.PostQuitMessage(0);
|
||||
},
|
||||
wam.WM_GETMINMAXINFO => {
|
||||
const mmi: *wam.MINMAXINFO = @ptrFromInt(@as(usize, @bitCast(lParam)));
|
||||
mmi.ptMinTrackSize = min_track_size;
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
||||
var handled: sciter.Bool = .FALSE;
|
||||
const result = sciter_api.SciterProcND(hwnd, uMsg, wParam, lParam, &handled);
|
||||
if (handled != .FALSE) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return wam.DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
pub fn main() void {
|
||||
const sciter_module = std.c.dlopen("./libsciter.so", .{ .LAZY = true }) orelse {
|
||||
const err = std.c.dlerror();
|
||||
const nl = "\n";
|
||||
_ = std.posix.writev(std.posix.STDERR_FILENO, &.{
|
||||
.{ .base = err.?, .len = std.mem.indexOfSentinel(u8, 0, err.?) },
|
||||
.{ .base = nl, .len = nl.len },
|
||||
}) catch {};
|
||||
std.posix.exit(1);
|
||||
};
|
||||
|
||||
const sciter_api_fn: *const fn () ?*sciter.API = @ptrCast(std.c.dlsym(sciter_module, "SciterAPI") orelse {
|
||||
_ = std.posix.write(std.posix.STDERR_FILENO, "Couldn't load Sciter API.\n") catch {};
|
||||
std.posix.exit(1);
|
||||
});
|
||||
|
||||
sciter_api = sciter_api_fn() orelse {
|
||||
_ = std.posix.write(std.posix.STDERR_FILENO, "Couldn't load Sciter API.\n") catch {};
|
||||
std.posix.exit(1);
|
||||
};
|
||||
|
||||
std.debug.print("Sciter API version is: 0x{X:0>8}\n", .{sciter_api.version});
|
||||
|
||||
const display = x11.Display.openDisplay(null) orelse {
|
||||
_ = std.posix.write(std.posix.STDERR_FILENO, "Couldn't open connection to X server.\n") catch {};
|
||||
std.posix.exit(1);
|
||||
};
|
||||
defer _ = display.closeDisplay();
|
||||
|
||||
const screen = display.defaultScreen();
|
||||
|
||||
var attributes: x11.XSetWindowAttributes = .{
|
||||
.background_pixel = display.blackPixel(screen),
|
||||
.event_mask = .{
|
||||
.exposure = true,
|
||||
.key_press = true,
|
||||
},
|
||||
};
|
||||
|
||||
const window = display.createWindow(
|
||||
display.rootWindow(screen),
|
||||
0,
|
||||
0,
|
||||
720,
|
||||
480,
|
||||
0,
|
||||
display.defaultDepth(screen),
|
||||
x11.InputOutput,
|
||||
display.defaultVisual(screen),
|
||||
.{
|
||||
.background_pixel = true,
|
||||
.event_mask = true,
|
||||
},
|
||||
&attributes,
|
||||
);
|
||||
defer _ = display.destroyWindow(window);
|
||||
|
||||
_ = display.storeName(window, "Sciter Demo");
|
||||
|
||||
const gc = display.createGC(@enumFromInt(@intFromEnum(window)), .{}, null);
|
||||
_ = display.freeGC(gc);
|
||||
|
||||
const wm_delete_window = display.internAtom("WM_DELETE_WINDOW", false);
|
||||
var protocols = [_]x11.Atom{wm_delete_window};
|
||||
_ = display.setWMProtocols(window, &protocols);
|
||||
|
||||
_ = display.mapWindow(window);
|
||||
defer _ = display.unmapWindow(window);
|
||||
|
||||
//var rect: sciter.Rect = .{ .left = -1, .right = -1, .top = -1, .bottom = -1 };
|
||||
//const window2 = sciter_api.SciterCreateWindow(0, &rect, null, null, .null_handle);
|
||||
|
||||
_ = sciter_api.SciterSetOption(.null_handle, 10, 1);
|
||||
sciter_api.SciterSetupDebugOutput(.null_handle, null, &sciterDebugOutputProc);
|
||||
_ = sciter_api.SciterLoadHtml(window, html, html.len, L("/"));
|
||||
|
||||
var running = true;
|
||||
while (running) {
|
||||
const event = display.nextEvent();
|
||||
switch (event.type) {
|
||||
x11.ClientMessage => {
|
||||
const atom: x11.Atom = @enumFromInt(event.xclient.data.l[0]);
|
||||
if (atom == wm_delete_window) {
|
||||
running = false;
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn sciterDebugOutputProc(
|
||||
_: ?*anyopaque,
|
||||
subsystem: sciter.OutputSubsystems,
|
||||
severity: u32,
|
||||
text: [*]const u16,
|
||||
text_length: u32,
|
||||
) callconv(.c) void {
|
||||
var utf8_buf: [4096]u8 = undefined;
|
||||
|
||||
const text_utf16 = text[0..text_length];
|
||||
const len = std.unicode.wtf16LeToWtf8(&utf8_buf, text_utf16);
|
||||
|
||||
const text_utf8 = utf8_buf[0..len];
|
||||
|
||||
std.debug.print("subsystem: {} | severity: {} | {s}\n", .{ subsystem, severity, text_utf8 });
|
||||
}
|
||||
@@ -1,649 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const CStr = [*:0]const u8;
|
||||
pub const CWStr = [*:0]const u16;
|
||||
|
||||
pub const Element = opaque {};
|
||||
pub const HElement = *Element;
|
||||
|
||||
pub const Node = opaque {};
|
||||
pub const HNode = *Node;
|
||||
|
||||
pub const SArchive = opaque {};
|
||||
pub const HSArchive = *SArchive;
|
||||
|
||||
pub const HWindow = switch (@import("builtin").os.tag) {
|
||||
.windows => @import("win32").foundation.HWND,
|
||||
.linux => @import("x11.zig").Window,
|
||||
else => @compileError("System not supported"),
|
||||
};
|
||||
|
||||
pub const HWindowOptional = switch (@typeInfo(HWindow)) {
|
||||
.pointer => @Type(.{ .optional = .{ .child = HWindow } }),
|
||||
else => HWindow,
|
||||
};
|
||||
|
||||
pub const BehaviorEventParams = extern struct {
|
||||
cmd: BehaviorEvents,
|
||||
he_target: ?HElement,
|
||||
he: ?HElement,
|
||||
reason: extern union {
|
||||
click: enum(usize) { BY_MOUSE_CLICK, BY_KEY_CLICK, SYNTHESIZED, BY_MOUSE_ON_ICON },
|
||||
edit_changed: enum(usize) { BY_INS_CHAR, BY_INS_CHARS, BY_DEL_CHAR, BY_DEL_CHARS, BY_UNDO_REDO },
|
||||
custom: usize,
|
||||
},
|
||||
data: Value,
|
||||
name: ?CWStr,
|
||||
};
|
||||
|
||||
const BehaviorEvents = enum(u32) {
|
||||
BUTTON_CLICK = 0,
|
||||
BUTTON_PRESS = 1,
|
||||
|
||||
VALUE_CHANGED = 2,
|
||||
VALUE_CHANGING = 3,
|
||||
|
||||
SELECTION_CHANGED = 5,
|
||||
SELECTION_CHANGING = 0xC,
|
||||
|
||||
POPUP_REQUEST = 7,
|
||||
POPUP_READY = 8,
|
||||
POPUP_DISMISSED = 9,
|
||||
|
||||
MENU_ITEM_ACTIVE = 0xA,
|
||||
MENU_ITEM_CLICK = 0xB,
|
||||
|
||||
CONTEXT_MENU_REQUEST = 0x10,
|
||||
|
||||
VISUAL_STATUS_CHANGED = 0x11,
|
||||
DISABLED_STATUS_CHANGED = 0x12,
|
||||
|
||||
POPUP_DISMISSING = 0x13,
|
||||
|
||||
CONTENT_CHANGED = 0x15,
|
||||
|
||||
HYPERLINK_CLICK = 0x80,
|
||||
|
||||
ELEMENT_COLLAPSED = 0x90,
|
||||
ELEMENT_EXPANDED = 0x91,
|
||||
|
||||
ACTIVATE_CHILD = 0x92,
|
||||
|
||||
FORM_SUBMIT = 0x96,
|
||||
FORM_RESET = 0x97,
|
||||
|
||||
DOCUMENT_COMPLETE = 0x98,
|
||||
|
||||
HISTORY_PUSH = 0x99,
|
||||
HISTORY_DROP = 0x9A,
|
||||
HISTORY_PRIOR = 0x9B,
|
||||
HISTORY_NEXT = 0x9C,
|
||||
HISTORY_STATE_CHANGED = 0x9D,
|
||||
|
||||
CLOSE_POPUP = 0x9E,
|
||||
REQUEST_TOOLTIP = 0x9F,
|
||||
|
||||
ANIMATION = 0xA0,
|
||||
TRANSITION = 0xA1,
|
||||
SWIPE = 0xB0,
|
||||
|
||||
DOCUMENT_CREATED = 0xC0,
|
||||
DOCUMENT_CLOSE_REQUEST = 0xC1,
|
||||
DOCUMENT_CLOSE = 0xC2,
|
||||
DOCUMENT_READY = 0xC3,
|
||||
DOCUMENT_PARSED = 0xC4,
|
||||
//DOCUMENT_RELOAD = 0xC5,
|
||||
DOCUMENT_CLOSING = 0xC6,
|
||||
CONTAINER_CLOSE_REQUEST = 0xC7,
|
||||
CONTAINER_CLOSING = 0xC8,
|
||||
|
||||
VIDEO_INITIALIZED = 0xD1,
|
||||
VIDEO_STARTED = 0xD2,
|
||||
VIDEO_STOPPED = 0xD3,
|
||||
VIDEO_BIND_RQ = 0xD4,
|
||||
|
||||
VIDEO_FRAME_REQUEST = 0xD8,
|
||||
|
||||
PAGINATION_STARTS = 0xE0,
|
||||
PAGINATION_PAGE = 0xE1,
|
||||
PAGINATION_ENDS = 0xE2,
|
||||
|
||||
CUSTOM = 0xF0,
|
||||
|
||||
EGL_RENDER = 0x20,
|
||||
|
||||
/// All custom event codes shall be greater than this number. All codes
|
||||
/// below this will be used solely by application - Sciter will not
|
||||
/// intrepret it and will do just dispatching. To send event notifications
|
||||
/// with these codes use SciterSend/PostEvent API.
|
||||
FIRST_APPLICATION_EVENT_CODE = 0x100,
|
||||
_,
|
||||
};
|
||||
|
||||
pub const Bool = enum(u32) {
|
||||
FALSE = 0,
|
||||
TRUE = 1,
|
||||
_,
|
||||
};
|
||||
|
||||
pub const DomResult = enum(i32) {
|
||||
OK = 0,
|
||||
INVALID_HWND = 1,
|
||||
INVALID_HANDLE = 2,
|
||||
PASSIVE_HANDLE = 3,
|
||||
INVALID_PARAMETER = 4,
|
||||
OPERATION_FAILED = 5,
|
||||
OK_NOT_HANDLED = -1,
|
||||
};
|
||||
|
||||
pub const CtlType = enum(u32) {
|
||||
NO = 0,
|
||||
UNKNOWN = 1,
|
||||
|
||||
EDIT = 2,
|
||||
NUMERIC = 3,
|
||||
CLICKABLE = 4,
|
||||
BUTTON = 5,
|
||||
CHECKBOX = 6,
|
||||
RADIO = 7,
|
||||
SELECT_SINGLE = 8,
|
||||
SELECT_MULTIPLE = 9,
|
||||
DD_SELECT = 10,
|
||||
TEXTAREA = 11,
|
||||
HTMLAREA = 12,
|
||||
PASSWORD = 13,
|
||||
PROGRESS = 14,
|
||||
SLIDER = 15,
|
||||
DECIMAL = 16,
|
||||
CURRENCY = 17,
|
||||
SCROLLBAR = 18,
|
||||
LIST = 19,
|
||||
RICHTEXT = 20,
|
||||
CALENDAR = 21,
|
||||
DATE = 22,
|
||||
TIME = 23,
|
||||
FILE = 24,
|
||||
PATH = 25,
|
||||
|
||||
HYPERLINK = 26,
|
||||
FORM = 27,
|
||||
|
||||
MENUBAR = 28,
|
||||
MENU = 29,
|
||||
MENUBUTTON = 30,
|
||||
|
||||
FRAME = 31,
|
||||
FRAMESET = 32,
|
||||
|
||||
TOOLTIP = 33,
|
||||
|
||||
HIDDEN = 34,
|
||||
URL = 35,
|
||||
TOOLBAR = 36,
|
||||
|
||||
WINDOW = 37,
|
||||
|
||||
LABEL = 38,
|
||||
IMAGE = 39,
|
||||
PLAINTEXT = 40,
|
||||
|
||||
SELECT_TREE = 41,
|
||||
};
|
||||
|
||||
pub const ElementAreas = packed struct {
|
||||
relative: enum(u4) {
|
||||
ROOT = 0x1,
|
||||
SELF = 0x2,
|
||||
CONTAINER = 0x3,
|
||||
VIEW = 0x4,
|
||||
_,
|
||||
} = @enumFromInt(0x0),
|
||||
|
||||
area: enum(u4) {
|
||||
CONTENT_BOX = 0x0,
|
||||
PADDING_BOX = 0x1,
|
||||
BORDER_BOX = 0x2,
|
||||
MARGIN_BOX = 0x3,
|
||||
|
||||
BACK_IMAGE_AREA = 0x4,
|
||||
FORE_IMAGE_AREA = 0x5,
|
||||
|
||||
SCROLLABLE_AREA = 0x6,
|
||||
_,
|
||||
} = .CONTENT_BOX,
|
||||
|
||||
_pad8: u8 = 0,
|
||||
|
||||
as_ppx: bool = false,
|
||||
|
||||
_pad17: u15 = 0,
|
||||
};
|
||||
|
||||
pub const MethodParams = extern struct {
|
||||
method_id: u32,
|
||||
};
|
||||
|
||||
pub const NodeType = enum(u32) { ELEMENT, TEXT, COMMENT };
|
||||
|
||||
pub const NodeInsTarget = enum(u32) { BEFORE, AFTER, APPEND, PREPEND };
|
||||
|
||||
pub const Point = extern struct {
|
||||
x: i32,
|
||||
y: i32,
|
||||
};
|
||||
|
||||
pub const Rect = extern struct {
|
||||
left: i32,
|
||||
top: i32,
|
||||
right: i32,
|
||||
bottom: i32,
|
||||
};
|
||||
|
||||
pub const RequestParam = extern struct {
|
||||
name: CWStr,
|
||||
value: CWStr,
|
||||
};
|
||||
|
||||
pub const RequestType = enum(u32) {
|
||||
GET_ASYNC,
|
||||
POST_ASYNC,
|
||||
GET_SYNC,
|
||||
POST_SYNC,
|
||||
};
|
||||
|
||||
pub const ResourceType = enum(u32) {
|
||||
HTML = 0,
|
||||
IMAGE = 1,
|
||||
STYLE = 2,
|
||||
CURSOR = 3,
|
||||
SCRIPT = 4,
|
||||
RAW = 5,
|
||||
FONT,
|
||||
SOUND,
|
||||
FORCE_DWORD = 0xFFFFFFFF,
|
||||
};
|
||||
|
||||
pub const SetElementHtml = enum(u32) {
|
||||
SIH_REPLACE_CONTENT = 0,
|
||||
SIH_INSERT_AT_START = 1,
|
||||
SIH_APPEND_AFTER_LAST = 2,
|
||||
SOH_REPLACE = 3,
|
||||
SOH_INSERT_BEFORE = 4,
|
||||
SOH_INSERT_AFTER = 5,
|
||||
};
|
||||
|
||||
pub const Size = extern struct {
|
||||
cx: i32,
|
||||
cy: i32,
|
||||
};
|
||||
|
||||
pub const Value = extern struct {
|
||||
type: ValueType,
|
||||
unit: extern union {
|
||||
value: ValueUnit,
|
||||
/// For when `Value.type == .OBJECT`
|
||||
object: ValueUnitObject,
|
||||
},
|
||||
data: u64,
|
||||
};
|
||||
|
||||
pub const ValueType = enum(u32) {
|
||||
UNDEFINED = 0,
|
||||
NULL = 1,
|
||||
BOOL = 2,
|
||||
i32 = 3,
|
||||
FLOAT = 4,
|
||||
STRING = 5,
|
||||
DATE = 6,
|
||||
BIG_INT = 7,
|
||||
LENGTH = 8,
|
||||
ARRAY = 9,
|
||||
MAP = 10,
|
||||
FUNCTION = 11,
|
||||
BYTES = 12,
|
||||
OBJECT = 13,
|
||||
RESOURCE = 15,
|
||||
DURATION = 17,
|
||||
ANGLE = 18,
|
||||
COLOR = 19,
|
||||
ASSET = 21,
|
||||
};
|
||||
|
||||
pub const ValueUnit = enum(u32) {
|
||||
EM = 1,
|
||||
EX = 2,
|
||||
PR = 3,
|
||||
SP = 4,
|
||||
|
||||
PX = 7,
|
||||
IN = 8,
|
||||
CM = 9,
|
||||
MM = 10,
|
||||
PT = 11,
|
||||
PC = 12,
|
||||
DIP = 13,
|
||||
|
||||
PR_WIDTH = 16,
|
||||
PR_HEIGHT = 17,
|
||||
PR_VIEW_WIDTH = 18,
|
||||
PR_VIEW_HEIGHT = 19,
|
||||
PR_VIEW_MIN = 20,
|
||||
PR_VIEW_MAX = 21,
|
||||
|
||||
REM = 22,
|
||||
PPX = 23,
|
||||
CH = 24,
|
||||
};
|
||||
|
||||
pub const ValueUnitObject = enum(u32) {
|
||||
ARRAY = 0,
|
||||
OBJECT = 1,
|
||||
CLASS = 2,
|
||||
NATIVE = 3,
|
||||
FUNCTION = 4,
|
||||
ERROR = 5,
|
||||
BUFFER = 6,
|
||||
};
|
||||
|
||||
pub const ValueResult = enum(i32) {
|
||||
OK_TRUE = -1,
|
||||
OK = 0,
|
||||
BAD_PARAMETER = 1,
|
||||
INCOMPATIBLE_TYPE = 2,
|
||||
};
|
||||
|
||||
pub const OutputSubsystems = enum(u32) {
|
||||
DOM = 0,
|
||||
CSSS,
|
||||
CSS,
|
||||
TIS,
|
||||
};
|
||||
|
||||
pub const CallbackNotification = extern struct {
|
||||
code: u32,
|
||||
hwnd: HWindow,
|
||||
};
|
||||
|
||||
pub const XMsgCode = enum(u32) {
|
||||
CREATE = 0,
|
||||
DESTROY = 1,
|
||||
SIZE = 2,
|
||||
PAINT = 3,
|
||||
RESOLUTION = 4,
|
||||
HEARTBIT = 5,
|
||||
MOUSE = 6,
|
||||
KEY = 7,
|
||||
FOCUS = 8,
|
||||
};
|
||||
|
||||
pub const XMsg = extern struct {
|
||||
msg: XMsgCode,
|
||||
};
|
||||
|
||||
pub const OmAsset = extern struct {
|
||||
isa: *OmAssetClass,
|
||||
};
|
||||
|
||||
pub const OmAssetClass = extern struct {
|
||||
asset_add_ref: *const fn (thing: *OmAsset) callconv(.c) c_long,
|
||||
asset_release: *const fn (thing: *OmAsset) callconv(.c) c_long,
|
||||
asset_get_interface: *const fn (thing: *OmAsset, name: CStr, out: *?*anyopaque) callconv(.c) c_long,
|
||||
asset_get_passport: *const fn (thins: *OmAsset) callconv(.c) ?*OmPassport,
|
||||
};
|
||||
|
||||
pub const OmPassport = opaque {};
|
||||
|
||||
pub const ValueStringCvtType = enum(u32) {
|
||||
CVT_SIMPLE,
|
||||
CVT_JSON_LITERAL,
|
||||
CVT_JSON_MAP,
|
||||
CVT_XJSON_LITERAL,
|
||||
};
|
||||
|
||||
const ByteReceiver = fn (str: [*]const u8, num_bytes: u32, param: ?*anyopaque) callconv(.c) void;
|
||||
const DebugOutputProc = fn (param: ?*anyopaque, subsystem: OutputSubsystems, severity: u32, text: [*]const u16, text_length: u32) callconv(.c) void;
|
||||
const ElementCallback = fn (he: HElement, param: ?*anyopaque) callconv(.c) Bool;
|
||||
const ElementComparator = fn (he1: HElement, he2: HElement, param: ?*anyopaque) callconv(.c) i32;
|
||||
const ElementEventProc = fn (tag: ?*anyopaque, he: HElement, evtg: u32, prms: ?*anyopaque) callconv(.c) Bool;
|
||||
const HostCallback = fn (pns: *CallbackNotification, callback_param: ?*anyopaque) callconv(.c) u32;
|
||||
const KeyValueCallback = fn (param: ?*anyopaque, pkey: *const Value, pval: *const Value) callconv(.c) Bool;
|
||||
const NativeFunctorInvoke = fn (tag: ?*anyopaque, argc: u32, argv: [*]const Value, retval: *Value) callconv(.c) void;
|
||||
const NativeFunctorRelease = fn (tag: ?*anyopaque) callconv(.c) void;
|
||||
const StrReceiver = fn (str: [*]const u8, num_bytes: u32, param: ?*anyopaque) callconv(.c) void;
|
||||
const WindowDelegate = fn (hwnd: HWindow, msg: u32, wParam: usize, lParam: isize, pbHandled: *Bool) callconv(.c) isize;
|
||||
const WStrReceiver = fn (str: [*]const u16, num_bytes: u32, param: ?*anyopaque) callconv(.c) void;
|
||||
|
||||
pub const API = extern struct {
|
||||
version: u32,
|
||||
|
||||
SciterClassName: *const fn () callconv(.c) CWStr,
|
||||
SciterVersion: *const fn (n: u32) callconv(.c) u32,
|
||||
SciterDataReady: *const fn (hwnd: HWindow, uri: CWStr, data: [*]const u8, dataLength: u32) callconv(.c) Bool,
|
||||
SciterDataReadyAsync: *const fn (hwnd: HWindow, uri: CWStr, data: [*]const u8, dataLength: u32, requestId: ?*anyopaque) callconv(.c) Bool,
|
||||
|
||||
SciterProc: *const fn (hwnd: HWindow, msg: u32, wParam: usize, lParam: isize) callconv(.c) isize,
|
||||
SciterProcND: *const fn (hwnd: HWindow, msg: u32, wParam: usize, lParam: isize, pbHandled: *Bool) callconv(.c) isize,
|
||||
|
||||
SciterLoadFile: *const fn (hwnd: HWindow, filename: CWStr) callconv(.c) Bool,
|
||||
SciterLoadHtml: *const fn (hwnd: HWindow, html: [*]const u8, htmlSize: u32, baseUrl: CWStr) callconv(.c) Bool,
|
||||
|
||||
SciterSetCallback: *const fn (hwnd: HWindow, cb: ?*HostCallback, cbParam: ?*anyopaque) callconv(.c) void,
|
||||
SciterSetMasterCSS: *const fn (utf8: [*]const u8, numBytes: u32) callconv(.c) Bool,
|
||||
SciterAppendMasterCSS: *const fn (utf8: [*]const u8, numBytes: u32) callconv(.c) Bool,
|
||||
SciterSetCSS: *const fn (hwnd: HWindow, utf8: [*]const u8, numBytes: u32, baseUrl: CWStr, mediaType: CWStr) callconv(.c) Bool,
|
||||
SciterSetMediaType: *const fn (hwnd: HWindow, mediaType: CWStr) callconv(.c) Bool,
|
||||
SciterSetMediaVars: *const fn (hwnd: HWindow, mediaVars: *const Value) callconv(.c) Bool,
|
||||
SciterGetMinWidth: *const fn (hwnd: HWindow) callconv(.c) u32,
|
||||
SciterGetMinHeight: *const fn (hwnd: HWindow, width: u32) callconv(.c) u32,
|
||||
SciterCall: *const fn (hWnd: HWindow, functionName: CStr, argc: u32, argv: [*]const Value, retval: *Value) callconv(.c) Bool,
|
||||
SciterEval: *const fn (hwnd: HWindow, script: [*]const u16, scriptLength: u32, pretval: *Value) callconv(.c) Bool,
|
||||
SciterUpdateWindow: *const fn (hwnd: HWindow) callconv(.c) void,
|
||||
/// Win32 MSG
|
||||
SciterTranslateMessage: *const fn (lpMsg: *anyopaque) callconv(.c) Bool,
|
||||
SciterSetOption: *const fn (hWnd: HWindow, option: u32, value: usize) callconv(.c) Bool,
|
||||
SciterGetPPI: *const fn (hwnd: HWindow, px: *u32, py: *u32) callconv(.c) void,
|
||||
SciterGetViewExpando: *const fn (hwnd: HWindow, pval: *Value) callconv(.c) Bool,
|
||||
/// ID2D1RenderTarget
|
||||
SciterRenderD2D: *const fn (hwnd: HWindow, prt: *anyopaque) callconv(.c) Bool,
|
||||
/// ID2D1Factory
|
||||
SciterD2DFactory: *const fn (ppf: *anyopaque) callconv(.c) Bool,
|
||||
/// IDWriteFactory
|
||||
SciterDWFactory: *const fn (ppf: *anyopaque) callconv(.c) Bool,
|
||||
SciterGraphicsCaps: *const fn (pcaps: *u32) callconv(.c) Bool,
|
||||
SciterSetHomeURL: *const fn (hwnd: HWindow, baseUrl: CWStr) callconv(.c) Bool,
|
||||
SciterCreateNSView: *anyopaque,
|
||||
SciterCreateWidget: *anyopaque,
|
||||
SciterCreateWindow: *const fn (creationFlags: u32, frame: *Rect, _: ?*anyopaque, _: ?*anyopaque, parent: HWindowOptional) callconv(.c) HWindow,
|
||||
|
||||
SciterSetupDebugOutput: *const fn (hwndOrNull: HWindowOptional, param: ?*anyopaque, pfOutput: ?*const DebugOutputProc) callconv(.c) void,
|
||||
|
||||
// --- DOM API --------------------------------------------------------------
|
||||
|
||||
Sciter_UseElement: *const fn (he: HElement) callconv(.c) DomResult,
|
||||
Sciter_UnuseElement: *const fn (he: HElement) callconv(.c) DomResult,
|
||||
SciterGetRootElement: *const fn (hwnd: HWindow, phe: *HElement) callconv(.c) DomResult,
|
||||
SciterGetFocusElement: *const fn (hwnd: HWindow, phe: *HElement) callconv(.c) DomResult,
|
||||
SciterFindElement: *const fn (hwnd: HWindow, pt: Point, phe: *HElement) callconv(.c) DomResult,
|
||||
SciterGetChildrenCount: *const fn (he: HElement, count: *u32) callconv(.c) DomResult,
|
||||
SciterGetNthChild: *const fn (he: HElement, n: u32, phe: *HElement) callconv(.c) DomResult,
|
||||
SciterGetParentElement: *const fn (he: HElement, p_parent_he: *HElement) callconv(.c) DomResult,
|
||||
SciterGetElementHtmlCB: *const fn (he: HElement, outer: Bool, rcv: *const ByteReceiver, rcv_param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterGetElementTextCB: *const fn (he: HElement, rcv: *const WStrReceiver, rcv_param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterSetElementText: *const fn (he: HElement, utf16: [*]const u16, length: u32) callconv(.c) DomResult,
|
||||
SciterGetAttributeCount: *const fn (he: HElement, p_count: *u32) callconv(.c) DomResult,
|
||||
SciterGetNthAttributeNameCB: *const fn (he: HElement, n: u32, rcv: *const StrReceiver, rcv_param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterGetNthAttributeValueCB: *const fn (he: HElement, n: u32, rcv: *const WStrReceiver, rcv_param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterGetAttributeByNameCB: *const fn (he: HElement, name: CStr, rcv: *const WStrReceiver, rcv_param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterSetAttributeByName: *const fn (he: HElement, name: CStr, value: CWStr) callconv(.c) DomResult,
|
||||
SciterClearAttributes: *const fn (he: HElement) callconv(.c) DomResult,
|
||||
SciterGetElementIndex: *const fn (he: HElement, p_index: *u32) callconv(.c) DomResult,
|
||||
SciterGetElementType: *const fn (he: HElement, p_type: *CStr) callconv(.c) DomResult,
|
||||
SciterGetElementTypeCB: *const fn (he: HElement, rcv: *const StrReceiver, rcv_param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterGetStyleAttributeCB: *const fn (he: HElement, name: CStr, rcv: *const WStrReceiver, rcv_param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterSetStyleAttribute: *const fn (he: HElement, name: CStr, value: CWStr) callconv(.c) DomResult,
|
||||
SciterGetElementLocation: *const fn (he: HElement, p_location: *Rect, areas: ElementAreas) callconv(.c) DomResult,
|
||||
SciterScrollToView: *const fn (he: HElement, SciterScrollFlags: u32) callconv(.c) DomResult,
|
||||
SciterUpdateElement: *const fn (he: HElement, andForceRender: Bool) callconv(.c) DomResult,
|
||||
SciterRefreshElementArea: *const fn (he: HElement, rc: Rect) callconv(.c) DomResult,
|
||||
SciterSetCapture: *const fn (he: HElement) callconv(.c) DomResult,
|
||||
SciterReleaseCapture: *const fn (he: HElement) callconv(.c) DomResult,
|
||||
SciterGetElementHwnd: *const fn (he: HElement, p_hwnd: *HWindow, rootWindow: Bool) callconv(.c) DomResult,
|
||||
SciterCombineURL: *const fn (he: HElement, szUrlBuffer: [*]u16, UrlBufferSize: u32) callconv(.c) DomResult,
|
||||
SciterSelectElements: *const fn (he: HElement, CSS_selectors: CStr, callback: *const ElementCallback, param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterSelectElementsW: *const fn (he: HElement, CSS_selectors: CWStr, callback: *const ElementCallback, param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterSelectParent: *const fn (he: HElement, selector: CStr, depth: u32, heFound: *HElement) callconv(.c) DomResult,
|
||||
SciterSelectParentW: *const fn (he: HElement, selector: CWStr, depth: u32, heFound: *HElement) callconv(.c) DomResult,
|
||||
SciterSetElementHtml: *const fn (he: HElement, html: [*]const u8, htmlLength: u32, where: SetElementHtml) callconv(.c) DomResult,
|
||||
SciterGetElementUID: *const fn (he: HElement, puid: *u32) callconv(.c) DomResult,
|
||||
SciterGetElementByUID: *const fn (hwnd: HWindow, uid: u32, phe: *HElement) callconv(.c) DomResult,
|
||||
SciterShowPopup: *const fn (hePopup: HElement, heAnchor: HElement, placement: u32) callconv(.c) DomResult,
|
||||
SciterShowPopupAt: *const fn (hePopup: HElement, pos: Point, placement: u32) callconv(.c) DomResult,
|
||||
SciterHidePopup: *const fn (he: HElement) callconv(.c) DomResult,
|
||||
SciterGetElementState: *const fn (he: HElement, pstateBits: *u32) callconv(.c) DomResult,
|
||||
SciterSetElementState: *const fn (he: HElement, stateBitsToSet: u32, stateBitsToClear: u32, updateView: Bool) callconv(.c) DomResult,
|
||||
SciterCreateElement: *const fn (tagname: CStr, textOrNull: ?CWStr, phe: *HElement) callconv(.c) DomResult,
|
||||
SciterCloneElement: *const fn (he: HElement, phe: *HElement) callconv(.c) DomResult,
|
||||
SciterInsertElement: *const fn (he: HElement, hparent: HElement, index: u32) callconv(.c) DomResult,
|
||||
SciterDetachElement: *const fn (he: HElement) callconv(.c) DomResult,
|
||||
SciterDeleteElement: *const fn (he: HElement) callconv(.c) DomResult,
|
||||
SciterSetTimer: *const fn (he: HElement, milliseconds: u32, timer_id: usize) callconv(.c) DomResult,
|
||||
SciterDetachEventHandler: *const fn (he: HElement, pep: *const ElementEventProc, tag: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterAttachEventHandler: *const fn (he: HElement, pep: *const ElementEventProc, tag: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterWindowAttachEventHandler: *const fn (hwndLayout: HWindow, pep: *const ElementEventProc, tag: ?*anyopaque, subscription: u32) callconv(.c) DomResult,
|
||||
SciterWindowDetachEventHandler: *const fn (hwndLayout: HWindow, pep: *const ElementEventProc, tag: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterSendEvent: *const fn (he: HElement, appEventCode: u32, heSource: HElement, reason: usize, handled: *Bool) callconv(.c) DomResult,
|
||||
SciterPostEvent: *const fn (he: HElement, appEventCode: u32, heSource: HElement, reason: usize) callconv(.c) DomResult,
|
||||
SciterCallBehaviorMethod: *const fn (he: HElement, params: *MethodParams) callconv(.c) DomResult,
|
||||
SciterRequestElementData: *const fn (he: HElement, url: CWStr, dataType: u32, initiator: HElement) callconv(.c) DomResult,
|
||||
SciterHttpRequest: *const fn (he: HElement, url: CWStr, dataType: ResourceType, requestType: RequestType, requestParams: [*]RequestParam, nParams: u32) callconv(.c) DomResult,
|
||||
SciterGetScrollInfo: *const fn (he: HElement, scrollPos: *Point, viewRect: *Rect, contentSize: *Size) callconv(.c) DomResult,
|
||||
SciterSetScrollPos: *const fn (he: HElement, scrollPos: Point, smooth: Bool) callconv(.c) DomResult,
|
||||
SciterGetElementIntrinsicWidths: *const fn (he: HElement, pMinWidth: *i32, pMaxWidth: *i32) callconv(.c) DomResult,
|
||||
SciterGetElementIntrinsicHeight: *const fn (he: HElement, forWidth: i32, pHeight: *i32) callconv(.c) DomResult,
|
||||
SciterIsElementVisible: *const fn (he: HElement, pVisible: *Bool) callconv(.c) DomResult,
|
||||
SciterIsElementEnabled: *const fn (he: HElement, pEnabled: *Bool) callconv(.c) DomResult,
|
||||
SciterSortElements: *const fn (he: HElement, firstIndex: u32, lastIndex: u32, cmpFunc: *const ElementComparator, cmpFuncParam: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterSwapElements: *const fn (he1: HElement, he2: HElement) callconv(.c) DomResult,
|
||||
SciterTraverseUIEvent: *const fn (evt: u32, eventCtlStruct: ?*anyopaque, bOutProcessed: *Bool) callconv(.c) DomResult,
|
||||
SciterCallScriptingMethod: *const fn (he: HElement, name: CStr, argv: [*]const Value, argc: u32, retval: *Value) callconv(.c) DomResult,
|
||||
SciterCallScriptingFunction: *const fn (he: HElement, name: CStr, argv: [*]const Value, argc: u32, retval: *Value) callconv(.c) DomResult,
|
||||
SciterEvalElementScript: *const fn (he: HElement, script: [*]const u16, scriptLength: u32, retval: *Value) callconv(.c) DomResult,
|
||||
SciterAttachHwndToElement: *const fn (he: HElement, hwnd: HWindow) callconv(.c) DomResult,
|
||||
SciterControlGetType: *const fn (he: HElement, pType: *CtlType) callconv(.c) DomResult,
|
||||
SciterGetValue: *const fn (he: HElement, pval: *Value) callconv(.c) DomResult,
|
||||
SciterSetValue: *const fn (he: HElement, pval: *const Value) callconv(.c) DomResult,
|
||||
SciterGetExpando: *const fn (he: HElement, pval: *Value, forceCreation: Bool) callconv(.c) DomResult,
|
||||
SciterGetObject: *const fn (he: HElement, pval: *void, forceCreation: Bool) callconv(.c) DomResult,
|
||||
SciterGetElementNamespace: *const fn (he: HElement, pval: *void) callconv(.c) DomResult,
|
||||
SciterGetHighlightedElement: *const fn (hwnd: HWindow, phe: *HElement) callconv(.c) DomResult,
|
||||
SciterSetHighlightedElement: *const fn (hwnd: HWindow, he: HElement) callconv(.c) DomResult,
|
||||
|
||||
// --- DOM NODE API --------------------------------------------------------
|
||||
|
||||
SciterNodeAddRef: *const fn (hn: HNode) callconv(.c) DomResult,
|
||||
SciterNodeRelease: *const fn (hn: HNode) callconv(.c) DomResult,
|
||||
SciterNodeCastFromElement: *const fn (he: HElement, phn: *HNode) callconv(.c) DomResult,
|
||||
SciterNodeCastToElement: *const fn (hn: HNode, he: *HElement) callconv(.c) DomResult,
|
||||
SciterNodeFirstChild: *const fn (hn: HNode, phn: *HNode) callconv(.c) DomResult,
|
||||
SciterNodeLastChild: *const fn (hn: HNode, phn: *HNode) callconv(.c) DomResult,
|
||||
SciterNodeNextSibling: *const fn (hn: HNode, phn: *HNode) callconv(.c) DomResult,
|
||||
SciterNodePrevSibling: *const fn (hn: HNode, phn: *HNode) callconv(.c) DomResult,
|
||||
SciterNodeParent: *const fn (hnode: HNode, pheParent: *HElement) callconv(.c) DomResult,
|
||||
SciterNodeNthChild: *const fn (hnode: HNode, n: u32, phn: *HNode) callconv(.c) DomResult,
|
||||
SciterNodeChildrenCount: *const fn (hnode: HNode, pn: *u32) callconv(.c) DomResult,
|
||||
SciterNodeType: *const fn (hnode: HNode, pNodeType: *NodeType) callconv(.c) DomResult,
|
||||
SciterNodeGetText: *const fn (hnode: HNode, rcv: *const WStrReceiver, rcv_param: ?*anyopaque) callconv(.c) DomResult,
|
||||
SciterNodeSetText: *const fn (hnode: HNode, text: [*]const u16, textLength: u32) callconv(.c) DomResult,
|
||||
SciterNodeInsert: *const fn (hnode: HNode, where: NodeInsTarget, what: HNode) callconv(.c) DomResult,
|
||||
SciterNodeRemove: *const fn (hnode: HNode, finalize: Bool) callconv(.c) DomResult,
|
||||
SciterCreateTextNode: *const fn (text: [*]const u16, textLength: u32, phnode: *HNode) callconv(.c) DomResult,
|
||||
SciterCreateCommentNode: *const fn (text: [*]const u16, textLength: u32, phnode: *HNode) callconv(.c) DomResult,
|
||||
|
||||
// --- Value API -----------------------------------------------------------
|
||||
|
||||
ValueInit: *const fn (pval: *Value) callconv(.c) u32,
|
||||
ValueClear: *const fn (pval: *Value) callconv(.c) u32,
|
||||
ValueCompare: *const fn (pval1: *const Value, pval2: *const Value) callconv(.c) u32,
|
||||
ValueCopy: *const fn (pdst: *Value, psrc: *const Value) callconv(.c) u32,
|
||||
ValueIsolate: *const fn (pdst: *Value) callconv(.c) u32,
|
||||
ValueType: *const fn (pval: *const Value, pType: *u32, pUnits: *u32) callconv(.c) u32,
|
||||
ValueStringData: *const fn (pval: *const Value, pChars: *[*]const u16, pNumChars: *u32) callconv(.c) u32,
|
||||
ValueStringDataSet: *const fn (pval: *Value, chars: [*]const u16, numChars: u32, units: u32) callconv(.c) u32,
|
||||
ValueIntData: *const fn (pval: *const Value, pData: *i32) callconv(.c) u32,
|
||||
ValueIntDataSet: *const fn (pval: *Value, data: i32, type: u32, units: u32) callconv(.c) u32,
|
||||
ValueInt64Data: *const fn (pval: *const Value, pData: *i64) callconv(.c) u32,
|
||||
ValueInt64DataSet: *const fn (pval: *Value, data: i64, type: u32, units: u32) callconv(.c) u32,
|
||||
ValueFloatData: *const fn (pval: *const Value, pData: *f64) callconv(.c) u32,
|
||||
ValueFloatDataSet: *const fn (pval: *Value, data: f64, type: u32, units: u32) callconv(.c) u32,
|
||||
ValueBinaryData: *const fn (pval: *const Value, pBytes: *[*]const u8, pnBytes: *u32) callconv(.c) u32,
|
||||
ValueBinaryDataSet: *const fn (pval: *Value, pBytes: [*]const u8, nBytes: u32, type: u32, units: u32) callconv(.c) u32,
|
||||
ValueElementsCount: *const fn (pval: *const Value, pn: *i32) callconv(.c) u32,
|
||||
ValueNthElementValue: *const fn (pval: *const Value, n: i32, pretval: *Value) callconv(.c) u32,
|
||||
ValueNthElementValueSet: *const fn (pval: *Value, n: i32, pval_to_set: *const Value) callconv(.c) u32,
|
||||
ValueNthElementKey: *const fn (pval: *const Value, n: i32, pretval: *Value) callconv(.c) u32,
|
||||
ValueEnumElements: *const fn (pval: *const Value, penum: *const KeyValueCallback, param: ?*anyopaque) callconv(.c) u32,
|
||||
ValueSetValueToKey: *const fn (pval: *Value, pkey: *const Value, pval_to_set: *const Value) callconv(.c) u32,
|
||||
ValueGetValueOfKey: *const fn (pval: *const Value, pkey: *const Value, pretval: *Value) callconv(.c) u32,
|
||||
ValueToString: *const fn (pval: *Value, how: ValueStringCvtType) callconv(.c) u32,
|
||||
ValueFromString: *const fn (pval: *Value, str: [*]const u16, strLength: u32, how: ValueStringCvtType) callconv(.c) u32,
|
||||
ValueInvoke: *const fn (pval: *const Value, pthis: *Value, argc: u32, argv: *const Value, pretval: *Value, url: CWStr) callconv(.c) u32,
|
||||
ValueNativeFunctorSet: *const fn (pval: *Value, pinvoke: *const NativeFunctorInvoke, prelease: *const NativeFunctorRelease, tag: *void) callconv(.c) u32,
|
||||
ValueIsNativeFunctor: *const fn (pval: *const Value) callconv(.c) Bool,
|
||||
|
||||
// Used to be script VM API
|
||||
|
||||
reserved1: *anyopaque,
|
||||
reserved2: *anyopaque,
|
||||
reserved3: *anyopaque,
|
||||
reserved4: *anyopaque,
|
||||
|
||||
SciterOpenArchive: *const fn (archiveData: [*]const u8, archiveDataLength: u32) callconv(.c) HSArchive,
|
||||
SciterGetArchiveItem: *const fn (harc: HSArchive, path: CWStr, pdata: *[*]const u8, pdataLength: *u32) callconv(.c) Bool,
|
||||
SciterCloseArchive: *const fn (harc: HSArchive) callconv(.c) Bool,
|
||||
|
||||
SciterFireEvent: *const fn (evt: *const BehaviorEventParams, post: Bool, handled: *Bool) callconv(.c) DomResult,
|
||||
|
||||
SciterGetCallbackParam: *const fn (hwnd: HWindow) callconv(.c) ?*anyopaque,
|
||||
SciterPostCallback: *const fn (hwnd: HWindow, wparam: isize, lparam: usize, timeoutms: u32) callconv(.c) isize,
|
||||
|
||||
GetSciterGraphicsAPI: *const fn () callconv(.c) *GraphicsAPI,
|
||||
GetSciterRequestAPI: *const fn () callconv(.c) *RequestAPI,
|
||||
|
||||
/// IDXGISwapChain
|
||||
SciterCreateOnDirectXWindow: *const fn (hwnd: HWindow, pSwapChain: *anyopaque) callconv(.c) Bool,
|
||||
SciterRenderOnDirectXWindow: *const fn (hwnd: HWindow, elementToRenderOrNull: HElement, frontLayer: Bool) callconv(.c) Bool,
|
||||
/// IDXGISurface
|
||||
SciterRenderOnDirectXTexture: *const fn (hwnd: HWindow, elementToRenderOrNull: HElement, surface: *anyopaque) callconv(.c) Bool,
|
||||
|
||||
SciterProcX: *const fn (hwnd: HWindow, pMsg: *XMsg) callconv(.c) Bool,
|
||||
|
||||
SciterAtomValue: *const fn (name: CStr) callconv(.c) u64,
|
||||
SciterAtomNameCB: *const fn (atomv: u64, rcv: *const StrReceiver, rcv_param: ?*anyopaque) callconv(.c) Bool,
|
||||
|
||||
SciterSetGlobalAsset: *const fn (pass: *OmAsset) callconv(.c) Bool,
|
||||
SciterGetElementAsset: *const fn (el: HElement, nameAtom: u64, ppass: *?*OmAsset) callconv(.c) DomResult,
|
||||
|
||||
SciterSetVariable: *const fn (hwndOrNull: HWindow, name: CStr, pvalToSet: *const Value) callconv(.c) u32,
|
||||
SciterGetVariable: *const fn (hwndOrNull: HWindow, name: CStr, pvalToGet: *Value) callconv(.c) u32,
|
||||
|
||||
SciterElementUnwrap: *const fn (pval: *const Value, ppElement: *HElement) callconv(.c) u32,
|
||||
SciterElementWrap: *const fn (pval: *Value, pElement: HElement) callconv(.c) u32,
|
||||
|
||||
SciterNodeUnwrap: *const fn (pval: *const Value, ppNode: *HNode) callconv(.c) u32,
|
||||
SciterNodeWrap: *const fn (pval: *Value, pNode: HNode) callconv(.c) u32,
|
||||
|
||||
SciterReleaseGlobalAsset: *const fn (pass: *OmAsset) callconv(.c) Bool,
|
||||
|
||||
SciterExec: *const fn (appCmd: u32, p1: usize, p2: usize) callconv(.c) isize,
|
||||
SciterWindowExec: *const fn (hwnd: HWindow, windowCmd: u32, p1: usize, p2: usize) callconv(.c) isize,
|
||||
|
||||
SciterEGLGetProcAddress: *const fn (procName: CStr) callconv(.c) ?*anyopaque,
|
||||
SciterEGLSendEvent: *const fn (he: HElement, eventCode: u32, reason: usize) callconv(.c) DomResult,
|
||||
SciterRequestAnimationFrameEvent: *const fn (he: HElement, eventCode: u32, reason: usize) callconv(.c) DomResult,
|
||||
};
|
||||
|
||||
// TODO These APIs are actually well-known structs with function pointers in
|
||||
// them, which may provide useful functionality
|
||||
|
||||
pub const GraphicsAPI = opaque {};
|
||||
pub const RequestAPI = opaque {};
|
||||
File diff suppressed because it is too large
Load Diff
BIN
packages/sciter/vendor/linux/aarch64/libsciter.so
(Stored with Git LFS)
vendored
BIN
packages/sciter/vendor/linux/aarch64/libsciter.so
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
packages/sciter/vendor/linux/x86_64/libsciter.so
(Stored with Git LFS)
vendored
BIN
packages/sciter/vendor/linux/x86_64/libsciter.so
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
packages/sciter/vendor/windows/aarch64/sciter.dll
(Stored with Git LFS)
vendored
BIN
packages/sciter/vendor/windows/aarch64/sciter.dll
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
packages/sciter/vendor/windows/x86_64/sciter.dll
(Stored with Git LFS)
vendored
BIN
packages/sciter/vendor/windows/x86_64/sciter.dll
(Stored with Git LFS)
vendored
Binary file not shown.
@@ -1,73 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
const version_file = @embedFile("vendor/VERSION");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{
|
||||
.whitelist = &.{
|
||||
.{
|
||||
.cpu_arch = .x86_64,
|
||||
.os_tag = .windows,
|
||||
.abi = .msvc,
|
||||
},
|
||||
.{
|
||||
.cpu_arch = .aarch64,
|
||||
.os_tag = .windows,
|
||||
.abi = .msvc,
|
||||
},
|
||||
.{
|
||||
.cpu_arch = .x86_64,
|
||||
.os_tag = .linux,
|
||||
.abi = .gnu,
|
||||
},
|
||||
.{
|
||||
.cpu_arch = .aarch64,
|
||||
.os_tag = .linux,
|
||||
.abi = .gnu,
|
||||
},
|
||||
},
|
||||
});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const version_string = b.fmt("\"{s}\"", .{std.mem.trim(u8, version_file, " \n\t")});
|
||||
|
||||
const mod = b.addModule("tcc", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
.link_libc = true,
|
||||
});
|
||||
|
||||
mod.addCSourceFiles(.{
|
||||
.files = &.{
|
||||
"vendor/libtcc.c",
|
||||
},
|
||||
.flags = &.{
|
||||
"-Wno-string-plus-int",
|
||||
"-fno-sanitize=alignment",
|
||||
"-fno-sanitize=shift",
|
||||
"-funsigned-char",
|
||||
},
|
||||
});
|
||||
|
||||
mod.addCMacro("TCC_VERSION", version_string);
|
||||
switch (target.result.cpu.arch) {
|
||||
.aarch64 => {
|
||||
mod.addCMacro("TCC_TARGET_ARM64", "");
|
||||
},
|
||||
.x86_64 => {
|
||||
mod.addCMacro("TCC_TARGET_X86_64", "");
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
// --- TESTS ---
|
||||
|
||||
const mod_tests = b.addTest(.{
|
||||
.root_module = mod,
|
||||
});
|
||||
|
||||
const run_mod_tests = b.addRunArtifact(mod_tests);
|
||||
|
||||
const test_step = b.step("test", "Run tests");
|
||||
test_step.dependOn(&run_mod_tests.step);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
.{
|
||||
.name = .tcc,
|
||||
.version = "0.0.0",
|
||||
.minimum_zig_version = "0.15.2",
|
||||
.paths = .{
|
||||
"src",
|
||||
"vendor",
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
},
|
||||
.fingerprint = 0x36d21118d39414a0,
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
const std = @import("std");
|
||||
const Self = @This();
|
||||
|
||||
const Sym = @import("Sym.zig");
|
||||
|
||||
const Type = packed struct(u32) {
|
||||
basic_type: enum(u4) {
|
||||
void,
|
||||
byte,
|
||||
short,
|
||||
int,
|
||||
llong,
|
||||
ptr,
|
||||
func,
|
||||
@"struct",
|
||||
float,
|
||||
double,
|
||||
ldouble,
|
||||
bool,
|
||||
qlong,
|
||||
qfloat,
|
||||
},
|
||||
unsigned: bool = false,
|
||||
defsign: bool = false,
|
||||
array: bool = false,
|
||||
bitfield: bool = false,
|
||||
constant: bool = false,
|
||||
@"volatile": bool = false,
|
||||
vla: bool = false,
|
||||
long: bool = false,
|
||||
@"extern": bool = false,
|
||||
static: bool = false,
|
||||
typedef: bool = false,
|
||||
@"inline": bool = false,
|
||||
_unused: u4 = 0,
|
||||
extra: Extra = .empty,
|
||||
|
||||
pub const Extra = packed struct(u12) {
|
||||
bit_pos: u6,
|
||||
bit_size: u6,
|
||||
|
||||
pub const empty: Extra = @bitCast(0);
|
||||
pub const @"union": Extra = @bitCast(1);
|
||||
pub const @"enum": Extra = @bitCast(2);
|
||||
pub const enum_val: Extra = @bitCast(3);
|
||||
};
|
||||
|
||||
pub fn isFloat(self: Type) bool {
|
||||
const bt = self.basic_type;
|
||||
return bt == .ldouble or bt == .double or bt == .float or bt == .qfloat;
|
||||
}
|
||||
};
|
||||
|
||||
t: Type,
|
||||
ref: *Sym,
|
||||
@@ -1,50 +0,0 @@
|
||||
const std = @import("std");
|
||||
const Self = @This();
|
||||
|
||||
const Section = @import("Section.zig");
|
||||
|
||||
cur_text_section: *Section,
|
||||
|
||||
// --- x86_64 RELOCATIONS ---
|
||||
|
||||
pub const R_X86_64_NONE = 0;
|
||||
pub const R_X86_64_64 = 1;
|
||||
pub const R_X86_64_PC32 = 2;
|
||||
pub const R_X86_64_GOT32 = 3;
|
||||
pub const R_X86_64_PLT32 = 4;
|
||||
pub const R_X86_64_COPY = 5;
|
||||
pub const R_X86_64_GLOB_DAT = 6;
|
||||
pub const R_X86_64_JUMP_SLOT = 7;
|
||||
pub const R_X86_64_RELATIVE = 8;
|
||||
pub const R_X86_64_GOTPCREL = 9;
|
||||
pub const R_X86_64_32 = 10;
|
||||
pub const R_X86_64_32S = 11;
|
||||
pub const R_X86_64_16 = 12;
|
||||
pub const R_X86_64_PC16 = 13;
|
||||
pub const R_X86_64_8 = 14;
|
||||
pub const R_X86_64_PC8 = 15;
|
||||
pub const R_X86_64_DTPMOD64 = 16;
|
||||
pub const R_X86_64_DTPOFF64 = 17;
|
||||
pub const R_X86_64_TPOFF64 = 18;
|
||||
pub const R_X86_64_TLSGD = 19;
|
||||
pub const R_X86_64_TLSLD = 20;
|
||||
pub const R_X86_64_DTPOFF32 = 21;
|
||||
pub const R_X86_64_GOTTPOFF = 22;
|
||||
pub const R_X86_64_TPOFF32 = 23;
|
||||
pub const R_X86_64_PC64 = 24;
|
||||
pub const R_X86_64_GOTOFF64 = 25;
|
||||
pub const R_X86_64_GOTPC32 = 26;
|
||||
pub const R_X86_64_GOT64 = 27;
|
||||
pub const R_X86_64_GOTPCREL64 = 28;
|
||||
pub const R_X86_64_GOTPC64 = 29;
|
||||
pub const R_X86_64_GOTPLT64 = 30;
|
||||
pub const R_X86_64_PLTOFF64 = 31;
|
||||
pub const R_X86_64_SIZE32 = 32;
|
||||
pub const R_X86_64_SIZE64 = 33;
|
||||
pub const R_X86_64_GOTPC32_TLSDESC = 34;
|
||||
pub const R_X86_64_TLSDESC_CALL = 35;
|
||||
pub const R_X86_64_TLSDESC = 36;
|
||||
pub const R_X86_64_IRELATIVE = 37;
|
||||
pub const R_X86_64_RELATIVE64 = 38;
|
||||
pub const R_X86_64_GOTPCRELX = 41;
|
||||
pub const R_X86_64_REX_GOTPCRELX = 42;
|
||||
@@ -1,17 +0,0 @@
|
||||
const std = @import("std");
|
||||
const Self = @This();
|
||||
|
||||
const Elf = @import("Elf.zig");
|
||||
const Section = @import("Section.zig");
|
||||
const Sym = @import("Sym.zig");
|
||||
|
||||
nocode_wanted: u32,
|
||||
ind: u32,
|
||||
|
||||
pub fn greloca(self: *Self, elf: *Elf, section: *Section, maybe_sym: ?*Sym, offset: u64, relocation: u32, addend: i64) void {
|
||||
if (self.nocode_wanted > 0 and section == elf.cur_text_section) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
const std = @import("std");
|
||||
const Self = @This();
|
||||
|
||||
const CType = @import("CType.zig");
|
||||
const Sym = @import("Sym.zig");
|
||||
|
||||
type: CType,
|
||||
r: Register,
|
||||
r2: Register = .{ .register = Register.@"const" },
|
||||
c: CValue = std.mem.zeroes(CValue),
|
||||
sym: ?*Sym = null,
|
||||
|
||||
pub const Register = packed struct(u16) {
|
||||
location: Location = .{},
|
||||
_unused: u2 = 0,
|
||||
flags: Flags = .{},
|
||||
|
||||
pub const Location = packed struct(u6) {
|
||||
value: u6 = 0,
|
||||
|
||||
pub inline fn isRegister(self: @This()) bool {
|
||||
return self.value < @"const".value;
|
||||
}
|
||||
|
||||
pub const @"const": @This() = .{ .value = 0x30 };
|
||||
pub const llocal: @This() = .{ .value = 0x31 };
|
||||
pub const local: @This() = .{ .value = 0x32 };
|
||||
pub const cmp: @This() = .{ .value = 0x33 };
|
||||
pub const jmp: @This() = .{ .value = 0x34 };
|
||||
pub const jmpi: @This() = .{ .value = 0x35 };
|
||||
};
|
||||
|
||||
pub const Flags = packed struct(u8) {
|
||||
lval: bool = false,
|
||||
sym: bool = false,
|
||||
mustcast: bool = false,
|
||||
mustbound: bool = false,
|
||||
lval_type: packed struct(u3) {
|
||||
byte: bool = false,
|
||||
short: bool = false,
|
||||
unsigned: bool = false,
|
||||
} = .{},
|
||||
bounded: bool = false,
|
||||
};
|
||||
};
|
||||
|
||||
pub const CValue = extern union {
|
||||
ld: c_longdouble,
|
||||
d: f64,
|
||||
f: f32,
|
||||
i: u64,
|
||||
str: extern struct {
|
||||
size: u32,
|
||||
data: ?*anyopaque,
|
||||
},
|
||||
tab: [4]u32,
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
const std = @import("std");
|
||||
const Self = @This();
|
||||
|
||||
const Sym = @import("Sym.zig");
|
||||
|
||||
/// Current data offset.
|
||||
data_offset: usize,
|
||||
/// Allocated section data.
|
||||
data: []u8,
|
||||
|
||||
pub fn realloc(self: *Self, new_size: usize) void {
|
||||
var size = self.data.len;
|
||||
if (size == 0) {
|
||||
size = 1;
|
||||
}
|
||||
while (size < new_size) {
|
||||
size *= 2;
|
||||
}
|
||||
const data: [*]u8 = std.c.realloc(self.data.ptr, size).?;
|
||||
@memset(data[self.data.len..size], 0);
|
||||
self.data = data[0..size];
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
const std = @import("std");
|
||||
const Self = @This();
|
||||
|
||||
const CType = @import("CType.zig");
|
||||
const SValue = @import("SValue.zig");
|
||||
|
||||
v: u32,
|
||||
r: SValue.Register,
|
||||
a: SymAttr,
|
||||
u: extern union {
|
||||
s: extern struct {
|
||||
c: u32,
|
||||
u: extern union {
|
||||
sym_scope: u32,
|
||||
jnext: u32,
|
||||
f: FuncAttr,
|
||||
auxtype: u32,
|
||||
},
|
||||
},
|
||||
enum_val: u64,
|
||||
d: ?*u32,
|
||||
},
|
||||
type: CType,
|
||||
w: extern union {
|
||||
next: ?*Self,
|
||||
asm_label: u32,
|
||||
},
|
||||
prev: ?*Self,
|
||||
prev_tok: ?*Self,
|
||||
|
||||
pub const SymAttr = packed struct(u16) {
|
||||
/// log2(align) + 1 (0 means unspecified)
|
||||
aligned: u5 = 0,
|
||||
@"packed": bool = false,
|
||||
weak: bool = 0,
|
||||
visibility: Visibility = .default,
|
||||
dllexport: bool = false,
|
||||
dllimport: bool = false,
|
||||
_unused: u5 = 0,
|
||||
};
|
||||
|
||||
pub const Visibility = enum(u2) {
|
||||
default = 0,
|
||||
internal = 1,
|
||||
hidden = 2,
|
||||
protected = 3,
|
||||
};
|
||||
|
||||
pub const FuncAttr = packed struct(u32) {
|
||||
func_call: enum(u3) {
|
||||
cdecl = 0,
|
||||
stdcall = 1,
|
||||
fastcall1 = 2,
|
||||
fastcall2 = 3,
|
||||
fastcall3 = 4,
|
||||
fastcallw = 5,
|
||||
},
|
||||
func_type: enum(u2) {
|
||||
new = 1,
|
||||
old = 2,
|
||||
ellipsis = 3,
|
||||
},
|
||||
func_args: u8,
|
||||
_unused: u19,
|
||||
};
|
||||
@@ -1,264 +0,0 @@
|
||||
pub const std = @import("std");
|
||||
|
||||
pub const State = opaque {
|
||||
pub fn init() !*State {
|
||||
return import.tcc_new() orelse error.OutOfMemory;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *State) void {
|
||||
import.tcc_delete(self);
|
||||
}
|
||||
|
||||
/// Set TCC's private include and library path. Equivalent to
|
||||
/// `CONFIG_TCCDIR` define or `-B` option.
|
||||
pub fn setLibPath(self: *State, path: [*:0]const u8) void {
|
||||
import.tcc_set_lib_path(self, path);
|
||||
}
|
||||
|
||||
pub fn setErrorCallback(self: *State, context: ?*anyopaque, callback: ?*const ErrorCallbackFn) void {
|
||||
import.tcc_set_error_func(self, context, callback);
|
||||
}
|
||||
|
||||
/// Set TCC options using command line arguments syntax. You can specify
|
||||
/// multiple options.
|
||||
pub fn setOptions(self: *State, options: [*:0]const u8) void {
|
||||
import.tcc_set_options(self, options);
|
||||
}
|
||||
|
||||
// --- PREPROCESSOR ---
|
||||
|
||||
/// Add include path. Equivalent to `-I` option.
|
||||
pub fn addIncludePath(self: *State, path: [*:0]const u8) void {
|
||||
_ = import.tcc_add_include_path(self, path);
|
||||
}
|
||||
|
||||
/// Add system include path. Equivalent to `-isystem` option.
|
||||
pub fn addSystemIncludePath(self: *State, path: [*:0]const u8) void {
|
||||
_ = import.tcc_add_sysinclude_path(self, path);
|
||||
}
|
||||
|
||||
/// Add a preprocessor define. Defaults to `1`.
|
||||
pub fn addDefine(self: *State, symbol: [*:0]const u8, value: ?[*:0]const u8) void {
|
||||
import.tcc_define_symbol(self, symbol, value);
|
||||
}
|
||||
|
||||
/// Remove a preprocessor define, if exists.
|
||||
pub fn removeDefine(self: *State, symbol: [*:0]const u8) void {
|
||||
import.tcc_undefine_symbol(self, symbol);
|
||||
}
|
||||
|
||||
// --- COMPILING ---
|
||||
|
||||
/// Add a file (C source file, assembly, object file, library, DLL or an ld
|
||||
/// script).
|
||||
pub fn addFile(self: *State, filename: ?[*:0]const u8) !void {
|
||||
const result = import.tcc_add_file(self, filename);
|
||||
if (result < 0) return error.FileError;
|
||||
}
|
||||
|
||||
/// Compile a C source string.
|
||||
pub fn compileString(self: *State, source: [*:0]const u8) !void {
|
||||
const result = import.tcc_compile_string(self, source);
|
||||
if (result < 0) return error.CompileError;
|
||||
}
|
||||
|
||||
// --- LINKING COMMANDS ---
|
||||
|
||||
/// Set output type. Must be called before any compilation.
|
||||
pub fn setOutputType(self: *State, output_type: OutputType) void {
|
||||
_ = import.tcc_set_output_type(self, output_type);
|
||||
}
|
||||
|
||||
/// Add library search path. Equivalent to `-L` option.
|
||||
pub fn addLibraryPath(self: *State, path: [*:0]const u8) void {
|
||||
_ = import.tcc_add_library_path(self, path);
|
||||
}
|
||||
|
||||
/// Link library. Equivalent to `-l` option. The library name should be the
|
||||
/// same as if provided to the command line option, i.e. with "lib" prefix
|
||||
/// and the extension possibly omitted.
|
||||
pub fn addLibrary(self: *State, library: ?[*:0]const u8) !void {
|
||||
const result = import.tcc_add_library(self, library);
|
||||
if (result < 0) return error.AddLibraryError;
|
||||
}
|
||||
|
||||
/// Add a symbol to the compiled program (like an extern function or data).
|
||||
pub fn addSymbol(self: *State, name: [*:0]const u8, value: ?*anyopaque) void {
|
||||
_ = import.tcc_add_symbol(self, name, value);
|
||||
}
|
||||
|
||||
/// Output an executable, library or object file. Must not call
|
||||
/// `tcc_relocate` beforehand.
|
||||
pub fn outputFile(self: *State, filename: [*:0]const u8) !void {
|
||||
const result = import.tcc_output_file(self, filename);
|
||||
if (result < 0) return error.OutputFileError;
|
||||
}
|
||||
|
||||
/// Link and run `main` function and return its value. Must not call
|
||||
/// `tcc_relocate` beforehand.
|
||||
pub fn run(self: *State, args: [:null][*:0]u8) c_int {
|
||||
return import.tcc_run(self, @intCast(args.len), args.ptr);
|
||||
}
|
||||
|
||||
/// Do all relocations necessary before calling `State.getSymbol`. Use
|
||||
/// internal memory management.
|
||||
pub fn relocateAuto(self: *State) !void {
|
||||
const result = import.tcc_relocate(self, RELOCATE_AUTO);
|
||||
if (result < 0) return error.RelocateError;
|
||||
}
|
||||
|
||||
/// Do all relocations necessary before calling `State.getSymbol`. Use
|
||||
/// provided `allocator` for allocating the result.
|
||||
///
|
||||
/// If the function returns without an error, the user is responsible for
|
||||
/// calling `allocator.free` on the returned memory to free it.
|
||||
pub fn relocateAlloc(self: *State, allocator: std.mem.Allocator) ![]const u8 {
|
||||
const size = import.tcc_relocate(self, null);
|
||||
if (size < 0) return error.RelocateError;
|
||||
|
||||
const memory = try allocator.alignedAlloc(u8, .fromByteUnits(16), @intCast(size));
|
||||
errdefer allocator.free(memory);
|
||||
|
||||
const result = import.tcc_relocate(self, memory.ptr);
|
||||
if (result < 0) return error.RelocateError;
|
||||
|
||||
return memory;
|
||||
}
|
||||
|
||||
/// Get a pointer to a symbol value. Returns `null` if not found.
|
||||
pub fn getSymbol(self: *State, name: [*:0]const u8) ?*anyopaque {
|
||||
return import.tcc_get_symbol(self, name);
|
||||
}
|
||||
};
|
||||
|
||||
pub const ErrorCallbackFn = fn (context: ?*anyopaque, message: ?[*:0]const u8) callconv(.c) void;
|
||||
|
||||
pub const OutputType = enum(c_int) {
|
||||
/// Output will be run in memory (default).
|
||||
memory = 1,
|
||||
/// Executable file.
|
||||
exe = 2,
|
||||
/// Dynamic library.
|
||||
dll = 3,
|
||||
/// Object file.
|
||||
obj = 4,
|
||||
/// Only preprocess (used internally).
|
||||
preprocess = 5,
|
||||
};
|
||||
|
||||
/// Magic constant for `tcc_relocate`.
|
||||
pub const RELOCATE_AUTO: ?*anyopaque = @ptrFromInt(1);
|
||||
|
||||
pub const import = struct {
|
||||
/// Create a new TCC compilation context.
|
||||
pub extern fn tcc_new() ?*State;
|
||||
|
||||
/// Free a TCC compilation context.
|
||||
pub extern fn tcc_delete(state: *State) void;
|
||||
|
||||
/// Set CONFIG_TCCDIR at runtime.
|
||||
pub extern fn tcc_set_lib_path(state: *State, path: [*:0]const u8) void;
|
||||
|
||||
/// Set error/warning display callback.
|
||||
pub extern fn tcc_set_error_func(state: *State, context: ?*anyopaque, callback: ?*const ErrorCallbackFn) void;
|
||||
|
||||
/// Set options as from command line (multiple supported).
|
||||
pub extern fn tcc_set_options(state: *State, options: [*:0]const u8) void;
|
||||
|
||||
// --- PREPROCESSOR ---
|
||||
|
||||
/// Add include path.
|
||||
///
|
||||
/// NOTE Always returns `0`.
|
||||
pub extern fn tcc_add_include_path(state: *State, path: [*:0]const u8) c_int;
|
||||
|
||||
/// Add in system include path.
|
||||
///
|
||||
/// NOTE Always returns `0`.
|
||||
pub extern fn tcc_add_sysinclude_path(state: *State, path: [*:0]const u8) c_int;
|
||||
|
||||
/// Define preprocessor symbol `symbol`. Can put optional value.
|
||||
///
|
||||
/// NOTE Defaults to `1`.
|
||||
pub extern fn tcc_define_symbol(state: *State, symbol: [*:0]const u8, value: ?[*:0]const u8) void;
|
||||
|
||||
/// Undefine preprocess symbol `symbol`.
|
||||
pub extern fn tcc_undefine_symbol(state: *State, symbol: [*:0]const u8) void;
|
||||
|
||||
// --- COMPILING ---
|
||||
|
||||
/// Add a file (C file, dll, object, library, ld script). Return -1 if error.
|
||||
///
|
||||
/// NOTE Returns only either `0` or `-1`.
|
||||
pub extern fn tcc_add_file(state: *State, filename: [*:0]const u8) c_int;
|
||||
|
||||
/// Compile a string containing a C source. Return -1 if error.
|
||||
///
|
||||
/// NOTE Returns only either `0` or `-1`.
|
||||
pub extern fn tcc_compile_string(state: *State, source: [*:0]const u8) c_int;
|
||||
|
||||
// --- LINKING COMMANDS ---
|
||||
|
||||
/// Set output type. MUST BE CALLED before any compilation.
|
||||
///
|
||||
/// NOTE Always returns `0`.
|
||||
pub extern fn tcc_set_output_type(state: *State, output_type: OutputType) c_int;
|
||||
|
||||
/// Equivalent to -Lpath option.
|
||||
///
|
||||
/// NOTE Always returns `0`.
|
||||
pub extern fn tcc_add_library_path(state: *State, path: [*:0]const u8) c_int;
|
||||
|
||||
/// The library name is the same as the argument of the `-l` option.
|
||||
pub extern fn tcc_add_library(state: *State, library: [*:0]const u8) c_int;
|
||||
|
||||
/// Add a symbol to the compiled program.
|
||||
///
|
||||
/// NOTE Always returns `0`.
|
||||
pub extern fn tcc_add_symbol(state: *State, name: [*:0]const u8, value: ?*anyopaque) c_int;
|
||||
|
||||
/// Output an executable, library or object file. DO NOT call tcc_relocate()
|
||||
/// before.
|
||||
pub extern fn tcc_output_file(state: *State, filename: [*:0]const u8) c_int;
|
||||
|
||||
/// Link and run main() function and return its value. DO NOT call
|
||||
/// tcc_relocate() before.
|
||||
pub extern fn tcc_run(state: *State, argc: c_int, argv: [*:null][*:0]u8) c_int;
|
||||
|
||||
/// Do all relocations (needed before using tcc_get_symbol()).
|
||||
///
|
||||
/// Possible values for `ptr`:
|
||||
/// * `RELOCATE_AUTO`: Allocate and manage memory internally
|
||||
/// * `null`: return required memory size for the step below
|
||||
/// * memory address: copy code to memory passed by the caller
|
||||
///
|
||||
/// Returns -1 if error.
|
||||
pub extern fn tcc_relocate(state: *State, ptr: ?*anyopaque) c_int;
|
||||
|
||||
/// Return symbol value or NULL if not found.
|
||||
pub extern fn tcc_get_symbol(state: *State, name: [*:0]const u8) ?*anyopaque;
|
||||
};
|
||||
|
||||
test {
|
||||
const add = &struct {
|
||||
pub fn add(a: c_int, b: c_int) callconv(.c) c_int {
|
||||
return a + b;
|
||||
}
|
||||
}.add;
|
||||
|
||||
var tcc: *State = try .init();
|
||||
tcc.setOutputType(.memory);
|
||||
tcc.setOptions("-nostdlib");
|
||||
try tcc.compileString(
|
||||
\\int add(int a, int b);
|
||||
\\int add_one(int a) { return add(a, 1); }
|
||||
);
|
||||
|
||||
tcc.addSymbol("add", @constCast(add));
|
||||
try tcc.relocateAuto();
|
||||
const add_one: *const fn (a: c_int) callconv(.c) c_int = @ptrCast(tcc.getSymbol("add_one").?);
|
||||
|
||||
try std.testing.expectEqual(0, add_one(-1));
|
||||
try std.testing.expectEqual(1, add_one(0));
|
||||
try std.testing.expectEqual(2, add_one(1));
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const include_stack_size = 32;
|
||||
pub const ifdef_stack_size = 64;
|
||||
pub const vstack_size = 256;
|
||||
pub const string_max_size = 1024;
|
||||
pub const pack_stack_size = 8;
|
||||
|
||||
pub const tok_hash_size = 16384;
|
||||
pub const tok_alloc_incr = 512;
|
||||
pub const tok_max_size = 4;
|
||||
|
||||
pub fn err(comptime fmt: []const u8, args: anytype) noreturn {
|
||||
// TODO Full implementation of original tcc_error
|
||||
std.log.err(fmt, args);
|
||||
std.posix.exit(1);
|
||||
}
|
||||
@@ -1,339 +0,0 @@
|
||||
const std = @import("std");
|
||||
const Self = @This();
|
||||
|
||||
const tcc = @import("tcc.zig");
|
||||
|
||||
const CType = @import("CType.zig");
|
||||
const Elf = @import("Elf.zig");
|
||||
const Gen = @import("Gen.zig");
|
||||
const SValue = @import("SValue.zig");
|
||||
const Sym = @import("Sym.zig");
|
||||
|
||||
/// Number of available registers.
|
||||
pub const register_count = 25;
|
||||
/// Whether function parameters must be evaluated in reverse order.
|
||||
pub const invert_function_parameters = true;
|
||||
/// Pointer size in bytes
|
||||
pub const pointer_size = 8;
|
||||
/// `long double` size in bytes
|
||||
pub const long_double_size = 16;
|
||||
/// `long double` alignment in bytes
|
||||
pub const long_double_alignment = 16;
|
||||
/// Maximum alignment for `aligned` attribute
|
||||
pub const max_align = 16;
|
||||
|
||||
pub const RegisterClass = packed struct(u32) {
|
||||
/// Generic int register.
|
||||
int: bool = false,
|
||||
/// Generic float register.
|
||||
float: bool = false,
|
||||
rax: bool = false,
|
||||
rcx: bool = false,
|
||||
rdx: bool = false,
|
||||
/// Only for long double.
|
||||
st0: bool = false,
|
||||
r8: bool = false,
|
||||
r9: bool = false,
|
||||
r10: bool = false,
|
||||
r11: bool = false,
|
||||
xmm0: bool = false,
|
||||
xmm1: bool = false,
|
||||
xmm2: bool = false,
|
||||
xmm3: bool = false,
|
||||
xmm4: bool = false,
|
||||
xmm5: bool = false,
|
||||
xmm6: bool = false,
|
||||
xmm7: bool = false,
|
||||
_pad: u14 = 0,
|
||||
|
||||
pub const empty: RegisterClass = .{};
|
||||
/// Function return: integer register.
|
||||
pub const iret: RegisterClass = .{ .rax = true };
|
||||
/// Function return: second integer register.
|
||||
pub const lret: RegisterClass = .{ .rdx = true };
|
||||
/// Function return: float register.
|
||||
pub const fret: RegisterClass = .{ .xmm0 = true };
|
||||
/// Function return: second float register.
|
||||
pub const qret: RegisterClass = .{ .xmm0 = true };
|
||||
};
|
||||
|
||||
pub const Register = packed struct(u8) {
|
||||
r: enum(u5) {
|
||||
rax = 0,
|
||||
rcx = 1,
|
||||
rdx = 2,
|
||||
rsp = 4,
|
||||
rsi = 6,
|
||||
rdi = 7,
|
||||
|
||||
r8 = 8,
|
||||
r9 = 9,
|
||||
r10 = 10,
|
||||
r11 = 11,
|
||||
|
||||
xmm0 = 16,
|
||||
xmm1 = 17,
|
||||
xmm2 = 18,
|
||||
xmm3 = 19,
|
||||
xmm4 = 20,
|
||||
xmm5 = 21,
|
||||
xmm6 = 22,
|
||||
xmm7 = 23,
|
||||
|
||||
st0 = 24,
|
||||
},
|
||||
mem: bool = false,
|
||||
_unused: u2 = 0,
|
||||
|
||||
/// Function return: integer register.
|
||||
pub const iret: Register = .{ .r = .rax };
|
||||
/// Function return: second integer register.
|
||||
pub const lret: Register = .{ .r = .rdx };
|
||||
/// Function return: float register.
|
||||
pub const fret: Register = .{ .r = .xmm0 };
|
||||
/// Function return: second float register.
|
||||
pub const qret: Register = .{ .r = .xmm1 };
|
||||
|
||||
pub inline fn fromInt(value: u8) Register {
|
||||
return @bitCast(value);
|
||||
}
|
||||
|
||||
pub const mem_mask = 0x20;
|
||||
};
|
||||
|
||||
pub inline fn rexBase(value: u8) u8 {
|
||||
return (value >> 3) & 0b1;
|
||||
}
|
||||
|
||||
pub inline fn regValue(value: u8) u8 {
|
||||
return value & 0b111;
|
||||
}
|
||||
|
||||
pub const register_classes = [register_count]RegisterClass{
|
||||
.{ .int = true, .rax = true },
|
||||
.{ .int = true, .rcx = true },
|
||||
.{ .int = true, .rdx = true },
|
||||
.empty,
|
||||
.empty,
|
||||
.empty,
|
||||
.empty,
|
||||
.empty,
|
||||
.{ .r8 = true },
|
||||
.{ .r9 = true },
|
||||
.{ .r10 = true },
|
||||
.{ .r11 = true },
|
||||
.empty,
|
||||
.empty,
|
||||
.empty,
|
||||
.empty,
|
||||
.{ .float = true, .xmm0 = true },
|
||||
.{ .float = true, .xmm1 = true },
|
||||
.{ .float = true, .xmm2 = true },
|
||||
.{ .float = true, .xmm3 = true },
|
||||
.{ .float = true, .xmm4 = true },
|
||||
.{ .float = true, .xmm5 = true },
|
||||
.{ .xmm6 = true },
|
||||
.{ .xmm7 = true },
|
||||
.{ .st0 = true },
|
||||
};
|
||||
|
||||
func_sub_sp_offset: u64,
|
||||
func_ret_seb: i32,
|
||||
|
||||
pub fn g(gen: *Gen, elf: *Elf, c: u8) void {
|
||||
if (gen.nocode_wanted > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ind1 = gen.ind + 1;
|
||||
if (ind1 > elf.cur_text_section.data.len) {
|
||||
elf.cur_text_section.realloc(ind1);
|
||||
}
|
||||
elf.cur_text_section.data[gen.ind] = c;
|
||||
gen.ind = ind1;
|
||||
}
|
||||
|
||||
pub fn o(gen: *Gen, elf: *Elf, c: u32) void {
|
||||
while (c > 0) {
|
||||
g(gen, elf, @truncate(c));
|
||||
c >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn genLE16(gen: *Gen, elf: *Elf, v: u16) void {
|
||||
g(gen, elf, @truncate(v));
|
||||
g(gen, elf, @truncate(v >> 8));
|
||||
}
|
||||
|
||||
pub fn genLE32(gen: *Gen, elf: *Elf, v: u32) void {
|
||||
g(gen, elf, @truncate(v));
|
||||
g(gen, elf, @truncate(v >> 8));
|
||||
g(gen, elf, @truncate(v >> 16));
|
||||
g(gen, elf, @truncate(v >> 24));
|
||||
}
|
||||
|
||||
pub fn genLE64(gen: *Gen, elf: *Elf, v: u64) void {
|
||||
g(gen, elf, @truncate(v));
|
||||
g(gen, elf, @truncate(v >> 8));
|
||||
g(gen, elf, @truncate(v >> 16));
|
||||
g(gen, elf, @truncate(v >> 24));
|
||||
g(gen, elf, @truncate(v >> 32));
|
||||
g(gen, elf, @truncate(v >> 40));
|
||||
g(gen, elf, @truncate(v >> 48));
|
||||
g(gen, elf, @truncate(v >> 56));
|
||||
}
|
||||
|
||||
pub fn orex(gen: *Gen, elf: *Elf, ll: u8, _r: SValue.Register, _r2: SValue.Register, b: u32) void {
|
||||
const r: u8 = if (_r.location.isRegister()) _r.location.value else 0;
|
||||
const r2: u8 = if (_r2.location.isRegister()) _r2.location.value else 0;
|
||||
if (ll > 0 or rexBase(r) > 0 or rexBase(r2) > 0) {
|
||||
o(gen, elf, 0x40 | rexBase(r) | (rexBase(r2) << 2) | (ll << 3));
|
||||
}
|
||||
o(b);
|
||||
}
|
||||
|
||||
/// Output a symbol and patch all calls to it.
|
||||
pub fn gsymAddr(elf: *Elf, _t: u32, a: u32) void {
|
||||
var t = _t;
|
||||
while (t > 0) {
|
||||
const ptr = (elf.cur_text_section.data.ptr + t)[0..4];
|
||||
const n = std.mem.readInt(u32, ptr, .little);
|
||||
std.mem.writeInt(u32, ptr, a - t - 4);
|
||||
t = n;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gsym(gen: *Gen, elf: *Elf, t: u32) void {
|
||||
gsymAddr(elf, t, gen.ind);
|
||||
}
|
||||
|
||||
pub fn is64Type(t: CType.Type) bool {
|
||||
return t.basic_type == .ptr or t.basic_type == .func or t.basic_type == .llong;
|
||||
}
|
||||
|
||||
/// Instruction + 4 bytes of data. Return the address of the data. */
|
||||
pub fn oad(gen: *Gen, elf: *Elf, c: u32, s: u32) u32 {
|
||||
if (gen.nocode_wanted) {
|
||||
return s;
|
||||
}
|
||||
|
||||
o(gen, elf, c);
|
||||
const t = gen.ind;
|
||||
genLE32(gen, elf, s);
|
||||
return t;
|
||||
}
|
||||
|
||||
/// Generate jmp to a label.
|
||||
pub inline fn gjmp2(gen: *Gen, elf: *Elf, instr: u32, lbl: u32) void {
|
||||
oad(gen, elf, instr, lbl);
|
||||
}
|
||||
|
||||
pub fn genAddr32(gen: *Gen, elf: *Elf, r: SValue.Register, sym: ?*Sym, _c: u32) void {
|
||||
var c = _c;
|
||||
if (r.flags.sym) {
|
||||
gen.greloca(elf, elf.cur_text_section, sym, gen.ind, Elf.R_X86_64_32S, c);
|
||||
c = 0;
|
||||
}
|
||||
genLE32(gen, elf, c);
|
||||
}
|
||||
|
||||
pub fn genAddr64(gen: *Gen, elf: *Elf, r: SValue.Register, sym: ?*Sym, _c: u64) void {
|
||||
var c = _c;
|
||||
if (r.flags.sym) {
|
||||
gen.greloca(elf, elf.cur_text_section, sym, gen.ind, Elf.R_X86_64_64, c);
|
||||
c = 0;
|
||||
}
|
||||
genLE64(gen, elf, c);
|
||||
}
|
||||
|
||||
pub fn genAddrPC32(gen: *Gen, elf: *Elf, r: SValue.Register, sym: ?*Sym, _c: u32) void {
|
||||
var c = _c;
|
||||
if (r.flags.sym) {
|
||||
gen.greloca(elf, elf.cur_text_section, sym, gen.ind, Elf.R_X86_64_PC32, c - 4);
|
||||
c = 4;
|
||||
}
|
||||
genLE32(gen, elf, c - 4);
|
||||
}
|
||||
|
||||
pub fn genGotPCRel(gen: *Gen, elf: *Elf, r: SValue.Register, sym: ?*Sym, c: u32) void {
|
||||
gen.greloca(elf, elf.cur_text_section, sym, gen.ind, Elf.R_X86_64_GOTPCREL, -4);
|
||||
genLE32(gen, elf, 0);
|
||||
if (c > 0) {
|
||||
orex(gen, elf, 1, r, .{}, 0x81);
|
||||
o(0xC0 + regValue(r.location.value));
|
||||
genLE32(gen, elf, c);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn genModRMImpl(gen: *Gen, elf: *Elf, _op_reg: u8, r: SValue.Register, sym: ?*Sym, c: u32, is_got: bool) void {
|
||||
const op_reg = regValue(_op_reg) << 3;
|
||||
if (r.location == .@"const") {
|
||||
// constant memory reference
|
||||
if (!r.flags.sym) {
|
||||
o(gen, elf, 0x04 | op_reg); // [sib] | destreg
|
||||
_ = oad(gen, elf, 0x25, c); // disp32
|
||||
} else {
|
||||
o(0x05 | op_reg); // (%rip)+disp32 | destreg
|
||||
if (is_got) {
|
||||
genGotPCRel(gen, elf, r, sym, c);
|
||||
} else {
|
||||
genAddrPC32(gen, elf, r, sym, c);
|
||||
}
|
||||
}
|
||||
} else if (r.location == .local) {
|
||||
const c_byte: u8 = @truncate(c);
|
||||
if (@as(i32, @bitCast(c)) == @as(i32, @as(i8, @bitCast(c_byte)))) {
|
||||
// short reference
|
||||
o(gen, elf, 0x45 | op_reg);
|
||||
g(gen, elf, c_byte);
|
||||
} else {
|
||||
oad(gen, elf, 0x85 | op_reg, c);
|
||||
}
|
||||
} else if (Register.fromInt(r.location.value).mem) {
|
||||
if (c > 0) {
|
||||
g(gen, elf, 0x80 | op_reg | regValue(r.location.value));
|
||||
genLE32(gen, elf, c);
|
||||
} else {
|
||||
g(gen, elf, 0x00 | op_reg | regValue(r.location.value));
|
||||
}
|
||||
} else {
|
||||
g(gen, elf, 0x00 | op_reg | regValue(r.location.value));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn genModRM(gen: *Gen, elf: *Elf, op_reg: u8, r: SValue.Register, sym: ?*Sym, c: u32) void {
|
||||
genModRMImpl(gen, elf, op_reg, r, sym, c, false);
|
||||
}
|
||||
|
||||
pub fn genModRM64(gen: *Gen, elf: *Elf, opcode: u32, op_reg: u8, r: SValue.Register, sym: ?*Sym, c: u32) void {
|
||||
const is_got = (op_reg & @intFromEnum(Register.mem)) != 0 and !sym.?.type.t.static;
|
||||
orex(gen, elf, 1, r, op_reg, opcode);
|
||||
genModRMImpl(gen, elf, op_reg, r, sym, c, is_got);
|
||||
}
|
||||
|
||||
pub fn load(r: SValue.Register, sv: *SValue) void {
|
||||
var fr = sv.r;
|
||||
var ft = sv.type.t;
|
||||
var fc: u32 = @truncate(sv.c.i);
|
||||
|
||||
if (fc != sv.c.i and fr.flags.sym) {
|
||||
tcc.err("64-bit addend in load", .{});
|
||||
}
|
||||
|
||||
ft.defsign = false;
|
||||
ft.@"volatile" = false;
|
||||
ft.constant = false;
|
||||
|
||||
if (fr.location == .@"const" and fr.flags.sym and fr.flags.lval and !sv.sym.?.type.t.static) {
|
||||
var tr = r;
|
||||
tr.location.value |= Register.mem_mask;
|
||||
if (ft.isFloat()) {
|
||||
tr = get_reg(.int);
|
||||
tr.location.value |= Register.mem_mask;
|
||||
}
|
||||
genModRM64(gen, elf, 0x8b, tr, fr, sv.sym, 0);
|
||||
|
||||
fr = tr;
|
||||
fr.flags.lval = true;
|
||||
}
|
||||
}
|
||||
504
packages/tcc/vendor/COPYING
vendored
504
packages/tcc/vendor/COPYING
vendored
@@ -1,504 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
||||
1
packages/tcc/vendor/VERSION
vendored
1
packages/tcc/vendor/VERSION
vendored
@@ -1 +0,0 @@
|
||||
0.9.27
|
||||
1837
packages/tcc/vendor/arm64-gen.c
vendored
1837
packages/tcc/vendor/arm64-gen.c
vendored
File diff suppressed because it is too large
Load Diff
256
packages/tcc/vendor/arm64-link.c
vendored
256
packages/tcc/vendor/arm64-link.c
vendored
@@ -1,256 +0,0 @@
|
||||
#ifdef TARGET_DEFS_ONLY
|
||||
|
||||
#define EM_TCC_TARGET EM_AARCH64
|
||||
|
||||
#define R_DATA_32 R_AARCH64_ABS32
|
||||
#define R_DATA_PTR R_AARCH64_ABS64
|
||||
#define R_JMP_SLOT R_AARCH64_JUMP_SLOT
|
||||
#define R_GLOB_DAT R_AARCH64_GLOB_DAT
|
||||
#define R_COPY R_AARCH64_COPY
|
||||
#define R_RELATIVE R_AARCH64_RELATIVE
|
||||
|
||||
#define R_NUM R_AARCH64_NUM
|
||||
|
||||
#define ELF_START_ADDR 0x00400000
|
||||
#define ELF_PAGE_SIZE 0x1000
|
||||
|
||||
#define PCRELATIVE_DLLPLT 1
|
||||
#define RELOCATE_DLLPLT 1
|
||||
|
||||
#else /* !TARGET_DEFS_ONLY */
|
||||
|
||||
#include "tcc.h"
|
||||
|
||||
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
|
||||
relocations, returns -1. */
|
||||
int code_reloc (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_ABS32:
|
||||
case R_AARCH64_ABS64:
|
||||
case R_AARCH64_PREL32:
|
||||
case R_AARCH64_MOVW_UABS_G0_NC:
|
||||
case R_AARCH64_MOVW_UABS_G1_NC:
|
||||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
case R_AARCH64_ADR_PREL_PG_HI21:
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
case R_AARCH64_ADR_GOT_PAGE:
|
||||
case R_AARCH64_LD64_GOT_LO12_NC:
|
||||
case R_AARCH64_GLOB_DAT:
|
||||
case R_AARCH64_COPY:
|
||||
return 0;
|
||||
|
||||
case R_AARCH64_JUMP26:
|
||||
case R_AARCH64_CALL26:
|
||||
case R_AARCH64_JUMP_SLOT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns an enumerator to describe whether and when the relocation needs a
|
||||
GOT and/or PLT entry to be created. See tcc.h for a description of the
|
||||
different values. */
|
||||
int gotplt_entry_type (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_PREL32:
|
||||
case R_AARCH64_MOVW_UABS_G0_NC:
|
||||
case R_AARCH64_MOVW_UABS_G1_NC:
|
||||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
case R_AARCH64_ADR_PREL_PG_HI21:
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
case R_AARCH64_GLOB_DAT:
|
||||
case R_AARCH64_JUMP_SLOT:
|
||||
case R_AARCH64_COPY:
|
||||
return NO_GOTPLT_ENTRY;
|
||||
|
||||
case R_AARCH64_ABS32:
|
||||
case R_AARCH64_ABS64:
|
||||
case R_AARCH64_JUMP26:
|
||||
case R_AARCH64_CALL26:
|
||||
return AUTO_GOTPLT_ENTRY;
|
||||
|
||||
case R_AARCH64_ADR_GOT_PAGE:
|
||||
case R_AARCH64_LD64_GOT_LO12_NC:
|
||||
return ALWAYS_GOTPLT_ENTRY;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
|
||||
{
|
||||
Section *plt = s1->plt;
|
||||
uint8_t *p;
|
||||
unsigned plt_offset;
|
||||
|
||||
if (s1->output_type == TCC_OUTPUT_DLL)
|
||||
tcc_error("DLLs unimplemented!");
|
||||
|
||||
if (plt->data_offset == 0) {
|
||||
section_ptr_add(plt, 32);
|
||||
}
|
||||
plt_offset = plt->data_offset;
|
||||
|
||||
p = section_ptr_add(plt, 16);
|
||||
write32le(p, got_offset);
|
||||
write32le(p + 4, (uint64_t) got_offset >> 32);
|
||||
return plt_offset;
|
||||
}
|
||||
|
||||
/* relocate the PLT: compute addresses and offsets in the PLT now that final
|
||||
address for PLT and GOT are known (see fill_program_header) */
|
||||
ST_FUNC void relocate_plt(TCCState *s1)
|
||||
{
|
||||
uint8_t *p, *p_end;
|
||||
|
||||
if (!s1->plt)
|
||||
return;
|
||||
|
||||
p = s1->plt->data;
|
||||
p_end = p + s1->plt->data_offset;
|
||||
|
||||
if (p < p_end) {
|
||||
uint64_t plt = s1->plt->sh_addr;
|
||||
uint64_t got = s1->got->sh_addr;
|
||||
uint64_t off = (got >> 12) - (plt >> 12);
|
||||
if ((off + ((uint32_t)1 << 20)) >> 21)
|
||||
tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", off, got, plt);
|
||||
write32le(p, 0xa9bf7bf0); // stp x16,x30,[sp,#-16]!
|
||||
write32le(p + 4, (0x90000010 | // adrp x16,...
|
||||
(off & 0x1ffffc) << 3 | (off & 3) << 29));
|
||||
write32le(p + 8, (0xf9400211 | // ldr x17,[x16,#...]
|
||||
(got & 0xff8) << 7));
|
||||
write32le(p + 12, (0x91000210 | // add x16,x16,#...
|
||||
(got & 0xfff) << 10));
|
||||
write32le(p + 16, 0xd61f0220); // br x17
|
||||
write32le(p + 20, 0xd503201f); // nop
|
||||
write32le(p + 24, 0xd503201f); // nop
|
||||
write32le(p + 28, 0xd503201f); // nop
|
||||
p += 32;
|
||||
while (p < p_end) {
|
||||
uint64_t pc = plt + (p - s1->plt->data);
|
||||
uint64_t addr = got + read64le(p);
|
||||
uint64_t off = (addr >> 12) - (pc >> 12);
|
||||
if ((off + ((uint32_t)1 << 20)) >> 21)
|
||||
tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", off, addr, pc);
|
||||
write32le(p, (0x90000010 | // adrp x16,...
|
||||
(off & 0x1ffffc) << 3 | (off & 3) << 29));
|
||||
write32le(p + 4, (0xf9400211 | // ldr x17,[x16,#...]
|
||||
(addr & 0xff8) << 7));
|
||||
write32le(p + 8, (0x91000210 | // add x16,x16,#...
|
||||
(addr & 0xfff) << 10));
|
||||
write32le(p + 12, 0xd61f0220); // br x17
|
||||
p += 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void relocate_init(Section *sr) {}
|
||||
|
||||
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
{
|
||||
int sym_index = ELFW(R_SYM)(rel->r_info);
|
||||
#ifdef DEBUG_RELOC
|
||||
ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
#endif
|
||||
|
||||
switch(type) {
|
||||
case R_AARCH64_ABS64:
|
||||
write64le(ptr, val);
|
||||
return;
|
||||
case R_AARCH64_ABS32:
|
||||
write32le(ptr, val);
|
||||
return;
|
||||
case R_AARCH64_PREL32:
|
||||
write32le(ptr, val - addr);
|
||||
return;
|
||||
case R_AARCH64_MOVW_UABS_G0_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffe0001f) |
|
||||
(val & 0xffff) << 5));
|
||||
return;
|
||||
case R_AARCH64_MOVW_UABS_G1_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffe0001f) |
|
||||
(val >> 16 & 0xffff) << 5));
|
||||
return;
|
||||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffe0001f) |
|
||||
(val >> 32 & 0xffff) << 5));
|
||||
return;
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffe0001f) |
|
||||
(val >> 48 & 0xffff) << 5));
|
||||
return;
|
||||
case R_AARCH64_ADR_PREL_PG_HI21: {
|
||||
uint64_t off = (val >> 12) - (addr >> 12);
|
||||
if ((off + ((uint64_t)1 << 20)) >> 21)
|
||||
tcc_error("R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
|
||||
write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
|
||||
(off & 0x1ffffc) << 3 | (off & 3) << 29));
|
||||
return;
|
||||
}
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffc003ff) |
|
||||
(val & 0xfff) << 10));
|
||||
return;
|
||||
case R_AARCH64_JUMP26:
|
||||
case R_AARCH64_CALL26:
|
||||
#ifdef DEBUG_RELOC
|
||||
printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val,
|
||||
(char *) symtab_section->link->data + sym->st_name);
|
||||
#endif
|
||||
if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc)
|
||||
tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed"
|
||||
" (val=%lx, addr=%lx)", val, addr);
|
||||
write32le(ptr, (0x14000000 |
|
||||
(uint32_t)(type == R_AARCH64_CALL26) << 31 |
|
||||
((val - addr) >> 2 & 0x3ffffff)));
|
||||
return;
|
||||
case R_AARCH64_ADR_GOT_PAGE: {
|
||||
uint64_t off =
|
||||
(((s1->got->sh_addr +
|
||||
s1->sym_attrs[sym_index].got_offset) >> 12) - (addr >> 12));
|
||||
if ((off + ((uint64_t)1 << 20)) >> 21)
|
||||
tcc_error("R_AARCH64_ADR_GOT_PAGE relocation failed");
|
||||
write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
|
||||
(off & 0x1ffffc) << 3 | (off & 3) << 29));
|
||||
return;
|
||||
}
|
||||
case R_AARCH64_LD64_GOT_LO12_NC:
|
||||
write32le(ptr,
|
||||
((read32le(ptr) & 0xfff803ff) |
|
||||
((s1->got->sh_addr +
|
||||
s1->sym_attrs[sym_index].got_offset) & 0xff8) << 7));
|
||||
return;
|
||||
case R_AARCH64_COPY:
|
||||
return;
|
||||
case R_AARCH64_GLOB_DAT:
|
||||
case R_AARCH64_JUMP_SLOT:
|
||||
/* They don't need addend */
|
||||
#ifdef DEBUG_RELOC
|
||||
printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr,
|
||||
val - rel->r_addend,
|
||||
(char *) symtab_section->link->data + sym->st_name);
|
||||
#endif
|
||||
write64le(ptr, val - rel->r_addend);
|
||||
return;
|
||||
case R_AARCH64_RELATIVE:
|
||||
#ifdef TCC_TARGET_PE
|
||||
add32le(ptr, val - s1->pe_imagebase);
|
||||
#endif
|
||||
/* do nothing */
|
||||
return;
|
||||
default:
|
||||
fprintf(stderr, "FIXME: handle reloc type %x at %x [%p] to %x\n",
|
||||
type, (unsigned)addr, ptr, (unsigned)val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !TARGET_DEFS_ONLY */
|
||||
1
packages/tcc/vendor/config.h
vendored
1
packages/tcc/vendor/config.h
vendored
@@ -1 +0,0 @@
|
||||
/* Manually created dummy configure file */
|
||||
3237
packages/tcc/vendor/elf.h
vendored
3237
packages/tcc/vendor/elf.h
vendored
File diff suppressed because it is too large
Load Diff
1723
packages/tcc/vendor/i386-asm.c
vendored
1723
packages/tcc/vendor/i386-asm.c
vendored
File diff suppressed because it is too large
Load Diff
253
packages/tcc/vendor/i386-tok.h
vendored
253
packages/tcc/vendor/i386-tok.h
vendored
@@ -1,253 +0,0 @@
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* WARNING: relative order of tokens is important. */
|
||||
|
||||
/* register */
|
||||
DEF_ASM(al)
|
||||
DEF_ASM(cl)
|
||||
DEF_ASM(dl)
|
||||
DEF_ASM(bl)
|
||||
DEF_ASM(ah)
|
||||
DEF_ASM(ch)
|
||||
DEF_ASM(dh)
|
||||
DEF_ASM(bh)
|
||||
DEF_ASM(ax)
|
||||
DEF_ASM(cx)
|
||||
DEF_ASM(dx)
|
||||
DEF_ASM(bx)
|
||||
DEF_ASM(sp)
|
||||
DEF_ASM(bp)
|
||||
DEF_ASM(si)
|
||||
DEF_ASM(di)
|
||||
DEF_ASM(eax)
|
||||
DEF_ASM(ecx)
|
||||
DEF_ASM(edx)
|
||||
DEF_ASM(ebx)
|
||||
DEF_ASM(esp)
|
||||
DEF_ASM(ebp)
|
||||
DEF_ASM(esi)
|
||||
DEF_ASM(edi)
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
DEF_ASM(rax)
|
||||
DEF_ASM(rcx)
|
||||
DEF_ASM(rdx)
|
||||
DEF_ASM(rbx)
|
||||
DEF_ASM(rsp)
|
||||
DEF_ASM(rbp)
|
||||
DEF_ASM(rsi)
|
||||
DEF_ASM(rdi)
|
||||
#endif
|
||||
DEF_ASM(mm0)
|
||||
DEF_ASM(mm1)
|
||||
DEF_ASM(mm2)
|
||||
DEF_ASM(mm3)
|
||||
DEF_ASM(mm4)
|
||||
DEF_ASM(mm5)
|
||||
DEF_ASM(mm6)
|
||||
DEF_ASM(mm7)
|
||||
DEF_ASM(xmm0)
|
||||
DEF_ASM(xmm1)
|
||||
DEF_ASM(xmm2)
|
||||
DEF_ASM(xmm3)
|
||||
DEF_ASM(xmm4)
|
||||
DEF_ASM(xmm5)
|
||||
DEF_ASM(xmm6)
|
||||
DEF_ASM(xmm7)
|
||||
DEF_ASM(cr0)
|
||||
DEF_ASM(cr1)
|
||||
DEF_ASM(cr2)
|
||||
DEF_ASM(cr3)
|
||||
DEF_ASM(cr4)
|
||||
DEF_ASM(cr5)
|
||||
DEF_ASM(cr6)
|
||||
DEF_ASM(cr7)
|
||||
DEF_ASM(tr0)
|
||||
DEF_ASM(tr1)
|
||||
DEF_ASM(tr2)
|
||||
DEF_ASM(tr3)
|
||||
DEF_ASM(tr4)
|
||||
DEF_ASM(tr5)
|
||||
DEF_ASM(tr6)
|
||||
DEF_ASM(tr7)
|
||||
DEF_ASM(db0)
|
||||
DEF_ASM(db1)
|
||||
DEF_ASM(db2)
|
||||
DEF_ASM(db3)
|
||||
DEF_ASM(db4)
|
||||
DEF_ASM(db5)
|
||||
DEF_ASM(db6)
|
||||
DEF_ASM(db7)
|
||||
DEF_ASM(dr0)
|
||||
DEF_ASM(dr1)
|
||||
DEF_ASM(dr2)
|
||||
DEF_ASM(dr3)
|
||||
DEF_ASM(dr4)
|
||||
DEF_ASM(dr5)
|
||||
DEF_ASM(dr6)
|
||||
DEF_ASM(dr7)
|
||||
DEF_ASM(es)
|
||||
DEF_ASM(cs)
|
||||
DEF_ASM(ss)
|
||||
DEF_ASM(ds)
|
||||
DEF_ASM(fs)
|
||||
DEF_ASM(gs)
|
||||
DEF_ASM(st)
|
||||
DEF_ASM(rip)
|
||||
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
/* The four low parts of sp/bp/si/di that exist only on
|
||||
x86-64 (encoding aliased to ah,ch,dh,dh when not using REX). */
|
||||
DEF_ASM(spl)
|
||||
DEF_ASM(bpl)
|
||||
DEF_ASM(sil)
|
||||
DEF_ASM(dil)
|
||||
#endif
|
||||
/* generic two operands */
|
||||
DEF_BWLX(mov)
|
||||
|
||||
DEF_BWLX(add)
|
||||
DEF_BWLX(or)
|
||||
DEF_BWLX(adc)
|
||||
DEF_BWLX(sbb)
|
||||
DEF_BWLX(and)
|
||||
DEF_BWLX(sub)
|
||||
DEF_BWLX(xor)
|
||||
DEF_BWLX(cmp)
|
||||
|
||||
/* unary ops */
|
||||
DEF_BWLX(inc)
|
||||
DEF_BWLX(dec)
|
||||
DEF_BWLX(not)
|
||||
DEF_BWLX(neg)
|
||||
DEF_BWLX(mul)
|
||||
DEF_BWLX(imul)
|
||||
DEF_BWLX(div)
|
||||
DEF_BWLX(idiv)
|
||||
|
||||
DEF_BWLX(xchg)
|
||||
DEF_BWLX(test)
|
||||
|
||||
/* shifts */
|
||||
DEF_BWLX(rol)
|
||||
DEF_BWLX(ror)
|
||||
DEF_BWLX(rcl)
|
||||
DEF_BWLX(rcr)
|
||||
DEF_BWLX(shl)
|
||||
DEF_BWLX(shr)
|
||||
DEF_BWLX(sar)
|
||||
|
||||
DEF_WLX(shld)
|
||||
DEF_WLX(shrd)
|
||||
|
||||
DEF_ASM(pushw)
|
||||
DEF_ASM(pushl)
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
DEF_ASM(pushq)
|
||||
#endif
|
||||
DEF_ASM(push)
|
||||
|
||||
DEF_ASM(popw)
|
||||
DEF_ASM(popl)
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
DEF_ASM(popq)
|
||||
#endif
|
||||
DEF_ASM(pop)
|
||||
|
||||
DEF_BWL(in)
|
||||
DEF_BWL(out)
|
||||
|
||||
DEF_WLX(movzb)
|
||||
DEF_ASM(movzwl)
|
||||
DEF_ASM(movsbw)
|
||||
DEF_ASM(movsbl)
|
||||
DEF_ASM(movswl)
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
DEF_ASM(movsbq)
|
||||
DEF_ASM(movswq)
|
||||
DEF_ASM(movzwq)
|
||||
DEF_ASM(movslq)
|
||||
#endif
|
||||
|
||||
DEF_WLX(lea)
|
||||
|
||||
DEF_ASM(les)
|
||||
DEF_ASM(lds)
|
||||
DEF_ASM(lss)
|
||||
DEF_ASM(lfs)
|
||||
DEF_ASM(lgs)
|
||||
|
||||
DEF_ASM(call)
|
||||
DEF_ASM(jmp)
|
||||
DEF_ASM(lcall)
|
||||
DEF_ASM(ljmp)
|
||||
|
||||
DEF_ASMTEST(j,)
|
||||
|
||||
DEF_ASMTEST(set,)
|
||||
DEF_ASMTEST(set,b)
|
||||
DEF_ASMTEST(cmov,)
|
||||
|
||||
DEF_WLX(bsf)
|
||||
DEF_WLX(bsr)
|
||||
DEF_WLX(bt)
|
||||
DEF_WLX(bts)
|
||||
DEF_WLX(btr)
|
||||
DEF_WLX(btc)
|
||||
|
||||
DEF_WLX(lar)
|
||||
DEF_WLX(lsl)
|
||||
|
||||
/* generic FP ops */
|
||||
DEF_FP(add)
|
||||
DEF_FP(mul)
|
||||
|
||||
DEF_ASM(fcom)
|
||||
DEF_ASM(fcom_1) /* non existent op, just to have a regular table */
|
||||
DEF_FP1(com)
|
||||
|
||||
DEF_FP(comp)
|
||||
DEF_FP(sub)
|
||||
DEF_FP(subr)
|
||||
DEF_FP(div)
|
||||
DEF_FP(divr)
|
||||
|
||||
DEF_BWLX(xadd)
|
||||
DEF_BWLX(cmpxchg)
|
||||
|
||||
/* string ops */
|
||||
DEF_BWLX(cmps)
|
||||
DEF_BWLX(scmp)
|
||||
DEF_BWL(ins)
|
||||
DEF_BWL(outs)
|
||||
DEF_BWLX(lods)
|
||||
DEF_BWLX(slod)
|
||||
DEF_BWLX(movs)
|
||||
DEF_BWLX(smov)
|
||||
DEF_BWLX(scas)
|
||||
DEF_BWLX(ssca)
|
||||
DEF_BWLX(stos)
|
||||
DEF_BWLX(ssto)
|
||||
|
||||
/* generic asm ops */
|
||||
#define ALT(x)
|
||||
#define DEF_ASM_OP0(name, opcode) DEF_ASM(name)
|
||||
#define DEF_ASM_OP0L(name, opcode, group, instr_type)
|
||||
#define DEF_ASM_OP1(name, opcode, group, instr_type, op0)
|
||||
#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1)
|
||||
#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2)
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
# include "x86_64-asm.h"
|
||||
#else
|
||||
# include "i386-asm.h"
|
||||
#endif
|
||||
|
||||
#define ALT(x)
|
||||
#define DEF_ASM_OP0(name, opcode)
|
||||
#define DEF_ASM_OP0L(name, opcode, group, instr_type) DEF_ASM(name)
|
||||
#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) DEF_ASM(name)
|
||||
#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) DEF_ASM(name)
|
||||
#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) DEF_ASM(name)
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
# include "x86_64-asm.h"
|
||||
#else
|
||||
# include "i386-asm.h"
|
||||
#endif
|
||||
1981
packages/tcc/vendor/libtcc.c
vendored
1981
packages/tcc/vendor/libtcc.c
vendored
File diff suppressed because it is too large
Load Diff
100
packages/tcc/vendor/libtcc.h
vendored
100
packages/tcc/vendor/libtcc.h
vendored
@@ -1,100 +0,0 @@
|
||||
#ifndef LIBTCC_H
|
||||
#define LIBTCC_H
|
||||
|
||||
#ifndef LIBTCCAPI
|
||||
# define LIBTCCAPI
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct TCCState;
|
||||
|
||||
typedef struct TCCState TCCState;
|
||||
|
||||
/* create a new TCC compilation context */
|
||||
LIBTCCAPI TCCState *tcc_new(void);
|
||||
|
||||
/* free a TCC compilation context */
|
||||
LIBTCCAPI void tcc_delete(TCCState *s);
|
||||
|
||||
/* set CONFIG_TCCDIR at runtime */
|
||||
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
|
||||
|
||||
/* set error/warning display callback */
|
||||
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
|
||||
void (*error_func)(void *opaque, const char *msg));
|
||||
|
||||
/* set options as from command line (multiple supported) */
|
||||
LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
|
||||
|
||||
/*****************************/
|
||||
/* preprocessor */
|
||||
|
||||
/* add include path */
|
||||
LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
|
||||
|
||||
/* add in system include path */
|
||||
LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
|
||||
|
||||
/* define preprocessor symbol 'sym'. Can put optional value */
|
||||
LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
|
||||
|
||||
/* undefine preprocess symbol 'sym' */
|
||||
LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
|
||||
|
||||
/*****************************/
|
||||
/* compiling */
|
||||
|
||||
/* add a file (C file, dll, object, library, ld script). Return -1 if error. */
|
||||
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
|
||||
|
||||
/* compile a string containing a C source. Return -1 if error. */
|
||||
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
|
||||
|
||||
/*****************************/
|
||||
/* linking commands */
|
||||
|
||||
/* set output type. MUST BE CALLED before any compilation */
|
||||
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
|
||||
#define TCC_OUTPUT_MEMORY 1 /* output will be run in memory (default) */
|
||||
#define TCC_OUTPUT_EXE 2 /* executable file */
|
||||
#define TCC_OUTPUT_DLL 3 /* dynamic library */
|
||||
#define TCC_OUTPUT_OBJ 4 /* object file */
|
||||
#define TCC_OUTPUT_PREPROCESS 5 /* only preprocess (used internally) */
|
||||
|
||||
/* equivalent to -Lpath option */
|
||||
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
|
||||
|
||||
/* the library name is the same as the argument of the '-l' option */
|
||||
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
|
||||
|
||||
/* add a symbol to the compiled program */
|
||||
LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
|
||||
|
||||
/* output an executable, library or object file. DO NOT call
|
||||
tcc_relocate() before. */
|
||||
LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
|
||||
|
||||
/* link and run main() function and return its value. DO NOT call
|
||||
tcc_relocate() before. */
|
||||
LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
|
||||
|
||||
/* do all relocations (needed before using tcc_get_symbol()) */
|
||||
LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
|
||||
/* possible values for 'ptr':
|
||||
- TCC_RELOCATE_AUTO : Allocate and manage memory internally
|
||||
- NULL : return required memory size for the step below
|
||||
- memory address : copy code to memory passed by the caller
|
||||
returns -1 if error. */
|
||||
#define TCC_RELOCATE_AUTO (void*)1
|
||||
|
||||
/* return symbol value or NULL if not found */
|
||||
LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
234
packages/tcc/vendor/stab.def
vendored
234
packages/tcc/vendor/stab.def
vendored
@@ -1,234 +0,0 @@
|
||||
/* Table of DBX symbol codes for the GNU system.
|
||||
Copyright (C) 1988, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* This contains contribution from Cygnus Support. */
|
||||
|
||||
/* Global variable. Only the name is significant.
|
||||
To find the address, look in the corresponding external symbol. */
|
||||
__define_stab (N_GSYM, 0x20, "GSYM")
|
||||
|
||||
/* Function name for BSD Fortran. Only the name is significant.
|
||||
To find the address, look in the corresponding external symbol. */
|
||||
__define_stab (N_FNAME, 0x22, "FNAME")
|
||||
|
||||
/* Function name or text-segment variable for C. Value is its address.
|
||||
Desc is supposedly starting line number, but GCC doesn't set it
|
||||
and DBX seems not to miss it. */
|
||||
__define_stab (N_FUN, 0x24, "FUN")
|
||||
|
||||
/* Data-segment variable with internal linkage. Value is its address.
|
||||
"Static Sym". */
|
||||
__define_stab (N_STSYM, 0x26, "STSYM")
|
||||
|
||||
/* BSS-segment variable with internal linkage. Value is its address. */
|
||||
__define_stab (N_LCSYM, 0x28, "LCSYM")
|
||||
|
||||
/* Name of main routine. Only the name is significant.
|
||||
This is not used in C. */
|
||||
__define_stab (N_MAIN, 0x2a, "MAIN")
|
||||
|
||||
/* Global symbol in Pascal.
|
||||
Supposedly the value is its line number; I'm skeptical. */
|
||||
__define_stab (N_PC, 0x30, "PC")
|
||||
|
||||
/* Number of symbols: 0, files,,funcs,lines according to Ultrix V4.0. */
|
||||
__define_stab (N_NSYMS, 0x32, "NSYMS")
|
||||
|
||||
/* "No DST map for sym: name, ,0,type,ignored" according to Ultrix V4.0. */
|
||||
__define_stab (N_NOMAP, 0x34, "NOMAP")
|
||||
|
||||
/* New stab from Solaris. I don't know what it means, but it
|
||||
don't seem to contain useful information. */
|
||||
__define_stab (N_OBJ, 0x38, "OBJ")
|
||||
|
||||
/* New stab from Solaris. I don't know what it means, but it
|
||||
don't seem to contain useful information. Possibly related to the
|
||||
optimization flags used in this module. */
|
||||
__define_stab (N_OPT, 0x3c, "OPT")
|
||||
|
||||
/* Register variable. Value is number of register. */
|
||||
__define_stab (N_RSYM, 0x40, "RSYM")
|
||||
|
||||
/* Modula-2 compilation unit. Can someone say what info it contains? */
|
||||
__define_stab (N_M2C, 0x42, "M2C")
|
||||
|
||||
/* Line number in text segment. Desc is the line number;
|
||||
value is corresponding address. */
|
||||
__define_stab (N_SLINE, 0x44, "SLINE")
|
||||
|
||||
/* Similar, for data segment. */
|
||||
__define_stab (N_DSLINE, 0x46, "DSLINE")
|
||||
|
||||
/* Similar, for bss segment. */
|
||||
__define_stab (N_BSLINE, 0x48, "BSLINE")
|
||||
|
||||
/* Sun's source-code browser stabs. ?? Don't know what the fields are.
|
||||
Supposedly the field is "path to associated .cb file". THIS VALUE
|
||||
OVERLAPS WITH N_BSLINE! */
|
||||
__define_stab (N_BROWS, 0x48, "BROWS")
|
||||
|
||||
/* GNU Modula-2 definition module dependency. Value is the modification time
|
||||
of the definition file. Other is non-zero if it is imported with the
|
||||
GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
|
||||
are enough empty fields? */
|
||||
__define_stab(N_DEFD, 0x4a, "DEFD")
|
||||
|
||||
/* THE FOLLOWING TWO STAB VALUES CONFLICT. Happily, one is for Modula-2
|
||||
and one is for C++. Still,... */
|
||||
/* GNU C++ exception variable. Name is variable name. */
|
||||
__define_stab (N_EHDECL, 0x50, "EHDECL")
|
||||
/* Modula2 info "for imc": name,,0,0,0 according to Ultrix V4.0. */
|
||||
__define_stab (N_MOD2, 0x50, "MOD2")
|
||||
|
||||
/* GNU C++ `catch' clause. Value is its address. Desc is nonzero if
|
||||
this entry is immediately followed by a CAUGHT stab saying what exception
|
||||
was caught. Multiple CAUGHT stabs means that multiple exceptions
|
||||
can be caught here. If Desc is 0, it means all exceptions are caught
|
||||
here. */
|
||||
__define_stab (N_CATCH, 0x54, "CATCH")
|
||||
|
||||
/* Structure or union element. Value is offset in the structure. */
|
||||
__define_stab (N_SSYM, 0x60, "SSYM")
|
||||
|
||||
/* Name of main source file.
|
||||
Value is starting text address of the compilation. */
|
||||
__define_stab (N_SO, 0x64, "SO")
|
||||
|
||||
/* Automatic variable in the stack. Value is offset from frame pointer.
|
||||
Also used for type descriptions. */
|
||||
__define_stab (N_LSYM, 0x80, "LSYM")
|
||||
|
||||
/* Beginning of an include file. Only Sun uses this.
|
||||
In an object file, only the name is significant.
|
||||
The Sun linker puts data into some of the other fields. */
|
||||
__define_stab (N_BINCL, 0x82, "BINCL")
|
||||
|
||||
/* Name of sub-source file (#include file).
|
||||
Value is starting text address of the compilation. */
|
||||
__define_stab (N_SOL, 0x84, "SOL")
|
||||
|
||||
/* Parameter variable. Value is offset from argument pointer.
|
||||
(On most machines the argument pointer is the same as the frame pointer. */
|
||||
__define_stab (N_PSYM, 0xa0, "PSYM")
|
||||
|
||||
/* End of an include file. No name.
|
||||
This and N_BINCL act as brackets around the file's output.
|
||||
In an object file, there is no significant data in this entry.
|
||||
The Sun linker puts data into some of the fields. */
|
||||
__define_stab (N_EINCL, 0xa2, "EINCL")
|
||||
|
||||
/* Alternate entry point. Value is its address. */
|
||||
__define_stab (N_ENTRY, 0xa4, "ENTRY")
|
||||
|
||||
/* Beginning of lexical block.
|
||||
The desc is the nesting level in lexical blocks.
|
||||
The value is the address of the start of the text for the block.
|
||||
The variables declared inside the block *precede* the N_LBRAC symbol. */
|
||||
__define_stab (N_LBRAC, 0xc0, "LBRAC")
|
||||
|
||||
/* Place holder for deleted include file. Replaces a N_BINCL and everything
|
||||
up to the corresponding N_EINCL. The Sun linker generates these when
|
||||
it finds multiple identical copies of the symbols from an include file.
|
||||
This appears only in output from the Sun linker. */
|
||||
__define_stab (N_EXCL, 0xc2, "EXCL")
|
||||
|
||||
/* Modula-2 scope information. Can someone say what info it contains? */
|
||||
__define_stab (N_SCOPE, 0xc4, "SCOPE")
|
||||
|
||||
/* End of a lexical block. Desc matches the N_LBRAC's desc.
|
||||
The value is the address of the end of the text for the block. */
|
||||
__define_stab (N_RBRAC, 0xe0, "RBRAC")
|
||||
|
||||
/* Begin named common block. Only the name is significant. */
|
||||
__define_stab (N_BCOMM, 0xe2, "BCOMM")
|
||||
|
||||
/* End named common block. Only the name is significant
|
||||
(and it should match the N_BCOMM). */
|
||||
__define_stab (N_ECOMM, 0xe4, "ECOMM")
|
||||
|
||||
/* End common (local name): value is address.
|
||||
I'm not sure how this is used. */
|
||||
__define_stab (N_ECOML, 0xe8, "ECOML")
|
||||
|
||||
/* These STAB's are used on Gould systems for Non-Base register symbols
|
||||
or something like that. FIXME. I have assigned the values at random
|
||||
since I don't have a Gould here. Fixups from Gould folk welcome... */
|
||||
__define_stab (N_NBTEXT, 0xF0, "NBTEXT")
|
||||
__define_stab (N_NBDATA, 0xF2, "NBDATA")
|
||||
__define_stab (N_NBBSS, 0xF4, "NBBSS")
|
||||
__define_stab (N_NBSTS, 0xF6, "NBSTS")
|
||||
__define_stab (N_NBLCS, 0xF8, "NBLCS")
|
||||
|
||||
/* Second symbol entry containing a length-value for the preceding entry.
|
||||
The value is the length. */
|
||||
__define_stab (N_LENG, 0xfe, "LENG")
|
||||
|
||||
/* The above information, in matrix format.
|
||||
|
||||
STAB MATRIX
|
||||
_________________________________________________
|
||||
| 00 - 1F are not dbx stab symbols |
|
||||
| In most cases, the low bit is the EXTernal bit|
|
||||
|
||||
| 00 UNDEF | 02 ABS | 04 TEXT | 06 DATA |
|
||||
| 01 |EXT | 03 |EXT | 05 |EXT | 07 |EXT |
|
||||
|
||||
| 08 BSS | 0A INDR | 0C FN_SEQ | 0E |
|
||||
| 09 |EXT | 0B | 0D | 0F |
|
||||
|
||||
| 10 | 12 COMM | 14 SETA | 16 SETT |
|
||||
| 11 | 13 | 15 | 17 |
|
||||
|
||||
| 18 SETD | 1A SETB | 1C SETV | 1E WARNING|
|
||||
| 19 | 1B | 1D | 1F FN |
|
||||
|
||||
|_______________________________________________|
|
||||
| Debug entries with bit 01 set are unused. |
|
||||
| 20 GSYM | 22 FNAME | 24 FUN | 26 STSYM |
|
||||
| 28 LCSYM | 2A MAIN | 2C | 2E |
|
||||
| 30 PC | 32 NSYMS | 34 NOMAP | 36 |
|
||||
| 38 OBJ | 3A | 3C OPT | 3E |
|
||||
| 40 RSYM | 42 M2C | 44 SLINE | 46 DSLINE |
|
||||
| 48 BSLINE*| 4A DEFD | 4C | 4E |
|
||||
| 50 EHDECL*| 52 | 54 CATCH | 56 |
|
||||
| 58 | 5A | 5C | 5E |
|
||||
| 60 SSYM | 62 | 64 SO | 66 |
|
||||
| 68 | 6A | 6C | 6E |
|
||||
| 70 | 72 | 74 | 76 |
|
||||
| 78 | 7A | 7C | 7E |
|
||||
| 80 LSYM | 82 BINCL | 84 SOL | 86 |
|
||||
| 88 | 8A | 8C | 8E |
|
||||
| 90 | 92 | 94 | 96 |
|
||||
| 98 | 9A | 9C | 9E |
|
||||
| A0 PSYM | A2 EINCL | A4 ENTRY | A6 |
|
||||
| A8 | AA | AC | AE |
|
||||
| B0 | B2 | B4 | B6 |
|
||||
| B8 | BA | BC | BE |
|
||||
| C0 LBRAC | C2 EXCL | C4 SCOPE | C6 |
|
||||
| C8 | CA | CC | CE |
|
||||
| D0 | D2 | D4 | D6 |
|
||||
| D8 | DA | DC | DE |
|
||||
| E0 RBRAC | E2 BCOMM | E4 ECOMM | E6 |
|
||||
| E8 ECOML | EA | EC | EE |
|
||||
| F0 | F2 | F4 | F6 |
|
||||
| F8 | FA | FC | FE LENG |
|
||||
+-----------------------------------------------+
|
||||
* 50 EHDECL is also MOD2.
|
||||
* 48 BSLINE is also BROWS.
|
||||
*/
|
||||
17
packages/tcc/vendor/stab.h
vendored
17
packages/tcc/vendor/stab.h
vendored
@@ -1,17 +0,0 @@
|
||||
#ifndef __GNU_STAB__
|
||||
|
||||
/* Indicate the GNU stab.h is in use. */
|
||||
|
||||
#define __GNU_STAB__
|
||||
|
||||
#define __define_stab(NAME, CODE, STRING) NAME=CODE,
|
||||
|
||||
enum __stab_debug_code
|
||||
{
|
||||
#include "stab.def"
|
||||
LAST_UNUSED_STAB_CODE
|
||||
};
|
||||
|
||||
#undef __define_stab
|
||||
|
||||
#endif /* __GNU_STAB_ */
|
||||
1660
packages/tcc/vendor/tcc.h
vendored
1660
packages/tcc/vendor/tcc.h
vendored
File diff suppressed because it is too large
Load Diff
1277
packages/tcc/vendor/tccasm.c
vendored
1277
packages/tcc/vendor/tccasm.c
vendored
File diff suppressed because it is too large
Load Diff
3058
packages/tcc/vendor/tccelf.c
vendored
3058
packages/tcc/vendor/tccelf.c
vendored
File diff suppressed because it is too large
Load Diff
7386
packages/tcc/vendor/tccgen.c
vendored
7386
packages/tcc/vendor/tccgen.c
vendored
File diff suppressed because it is too large
Load Diff
3903
packages/tcc/vendor/tccpp.c
vendored
3903
packages/tcc/vendor/tccpp.c
vendored
File diff suppressed because it is too large
Load Diff
844
packages/tcc/vendor/tccrun.c
vendored
844
packages/tcc/vendor/tccrun.c
vendored
@@ -1,844 +0,0 @@
|
||||
/*
|
||||
* TCC - Tiny C Compiler - Support for -run switch
|
||||
*
|
||||
* Copyright (c) 2001-2004 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "tcc.h"
|
||||
|
||||
/* only native compiler supports -run */
|
||||
#ifdef TCC_IS_NATIVE
|
||||
|
||||
#ifndef _WIN32
|
||||
# include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TCC_BACKTRACE
|
||||
# ifndef _WIN32
|
||||
# include <signal.h>
|
||||
# ifndef __OpenBSD__
|
||||
# include <sys/ucontext.h>
|
||||
# endif
|
||||
# else
|
||||
# define ucontext_t CONTEXT
|
||||
# endif
|
||||
ST_DATA int rt_num_callers = 6;
|
||||
ST_DATA const char **rt_bound_error_msg;
|
||||
ST_DATA void *rt_prog_main;
|
||||
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level);
|
||||
static void rt_error(ucontext_t *uc, const char *fmt, ...);
|
||||
static void set_exception_handler(void);
|
||||
#endif
|
||||
|
||||
static void set_pages_executable(void *ptr, unsigned long length);
|
||||
static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff);
|
||||
|
||||
#ifdef _WIN64
|
||||
static void *win64_add_function_table(TCCState *s1);
|
||||
static void win64_del_function_table(void *);
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Do all relocations (needed before using tcc_get_symbol())
|
||||
Returns -1 on error. */
|
||||
|
||||
LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
|
||||
{
|
||||
int size;
|
||||
addr_t ptr_diff = 0;
|
||||
|
||||
if (TCC_RELOCATE_AUTO != ptr)
|
||||
return tcc_relocate_ex(s1, ptr, 0);
|
||||
|
||||
size = tcc_relocate_ex(s1, NULL, 0);
|
||||
if (size < 0)
|
||||
return -1;
|
||||
|
||||
#ifdef HAVE_SELINUX
|
||||
{
|
||||
/* Using mmap instead of malloc */
|
||||
void *prx;
|
||||
char tmpfname[] = "/tmp/.tccrunXXXXXX";
|
||||
int fd = mkstemp(tmpfname);
|
||||
unlink(tmpfname);
|
||||
ftruncate(fd, size);
|
||||
|
||||
ptr = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
prx = mmap (NULL, size, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
|
||||
if (ptr == MAP_FAILED || prx == MAP_FAILED)
|
||||
tcc_error("tccrun: could not map memory");
|
||||
dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, (void*)(addr_t)size);
|
||||
dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, prx);
|
||||
ptr_diff = (char*)prx - (char*)ptr;
|
||||
}
|
||||
#else
|
||||
ptr = tcc_malloc(size);
|
||||
#endif
|
||||
tcc_relocate_ex(s1, ptr, ptr_diff); /* no more errors expected */
|
||||
dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ST_FUNC void tcc_run_free(TCCState *s1)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < s1->nb_runtime_mem; ++i) {
|
||||
#ifdef HAVE_SELINUX
|
||||
unsigned size = (unsigned)(addr_t)s1->runtime_mem[i++];
|
||||
munmap(s1->runtime_mem[i++], size);
|
||||
munmap(s1->runtime_mem[i], size);
|
||||
#else
|
||||
#ifdef _WIN64
|
||||
win64_del_function_table(*(void**)s1->runtime_mem[i]);
|
||||
#endif
|
||||
tcc_free(s1->runtime_mem[i]);
|
||||
#endif
|
||||
}
|
||||
tcc_free(s1->runtime_mem);
|
||||
}
|
||||
|
||||
/* launch the compiled program with the given arguments */
|
||||
LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
|
||||
{
|
||||
int (*prog_main)(int, char **);
|
||||
|
||||
s1->runtime_main = "main";
|
||||
if ((s1->dflag & 16) && !find_elf_sym(s1->symtab, s1->runtime_main))
|
||||
return 0;
|
||||
if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0)
|
||||
return -1;
|
||||
prog_main = tcc_get_symbol_err(s1, s1->runtime_main);
|
||||
|
||||
#ifdef CONFIG_TCC_BACKTRACE
|
||||
if (s1->do_debug) {
|
||||
set_exception_handler();
|
||||
rt_prog_main = prog_main;
|
||||
}
|
||||
#endif
|
||||
|
||||
errno = 0; /* clean errno value */
|
||||
|
||||
#ifdef CONFIG_TCC_BCHECK
|
||||
if (s1->do_bounds_check) {
|
||||
void (*bound_init)(void);
|
||||
void (*bound_exit)(void);
|
||||
void (*bound_new_region)(void *p, addr_t size);
|
||||
int (*bound_delete_region)(void *p);
|
||||
int i, ret;
|
||||
|
||||
/* set error function */
|
||||
rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");
|
||||
/* XXX: use .init section so that it also work in binary ? */
|
||||
bound_init = tcc_get_symbol_err(s1, "__bound_init");
|
||||
bound_exit = tcc_get_symbol_err(s1, "__bound_exit");
|
||||
bound_new_region = tcc_get_symbol_err(s1, "__bound_new_region");
|
||||
bound_delete_region = tcc_get_symbol_err(s1, "__bound_delete_region");
|
||||
|
||||
bound_init();
|
||||
/* mark argv area as valid */
|
||||
bound_new_region(argv, argc*sizeof(argv[0]));
|
||||
for (i=0; i<argc; ++i)
|
||||
bound_new_region(argv[i], strlen(argv[i]) + 1);
|
||||
|
||||
ret = (*prog_main)(argc, argv);
|
||||
|
||||
/* unmark argv area */
|
||||
for (i=0; i<argc; ++i)
|
||||
bound_delete_region(argv[i]);
|
||||
bound_delete_region(argv);
|
||||
bound_exit();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return (*prog_main)(argc, argv);
|
||||
}
|
||||
|
||||
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
||||
#define RUN_SECTION_ALIGNMENT 63
|
||||
#else
|
||||
#define RUN_SECTION_ALIGNMENT 15
|
||||
#endif
|
||||
|
||||
/* relocate code. Return -1 on error, required size if ptr is NULL,
|
||||
otherwise copy code into buffer passed by the caller */
|
||||
static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff)
|
||||
{
|
||||
Section *s;
|
||||
unsigned offset, length, fill, i, k;
|
||||
addr_t mem;
|
||||
|
||||
if (NULL == ptr) {
|
||||
s1->nb_errors = 0;
|
||||
#ifdef TCC_TARGET_PE
|
||||
pe_output_file(s1, NULL);
|
||||
#else
|
||||
tcc_add_runtime(s1);
|
||||
resolve_common_syms(s1);
|
||||
build_got_entries(s1);
|
||||
#endif
|
||||
if (s1->nb_errors)
|
||||
return -1;
|
||||
}
|
||||
|
||||
offset = 0, mem = (addr_t)ptr;
|
||||
fill = -mem & RUN_SECTION_ALIGNMENT;
|
||||
#ifdef _WIN64
|
||||
offset += sizeof (void*);
|
||||
#endif
|
||||
for (k = 0; k < 2; ++k) {
|
||||
for(i = 1; i < s1->nb_sections; i++) {
|
||||
s = s1->sections[i];
|
||||
if (0 == (s->sh_flags & SHF_ALLOC))
|
||||
continue;
|
||||
if (k != !(s->sh_flags & SHF_EXECINSTR))
|
||||
continue;
|
||||
offset += fill;
|
||||
if (!mem)
|
||||
s->sh_addr = 0;
|
||||
else if (s->sh_flags & SHF_EXECINSTR)
|
||||
s->sh_addr = mem + offset + ptr_diff;
|
||||
else
|
||||
s->sh_addr = mem + offset;
|
||||
#if 0
|
||||
if (mem)
|
||||
printf("%-16s +%02lx %p %04x\n",
|
||||
s->name, fill, (void*)s->sh_addr, (unsigned)s->data_offset);
|
||||
#endif
|
||||
offset += s->data_offset;
|
||||
fill = -(mem + offset) & 15;
|
||||
}
|
||||
#if RUN_SECTION_ALIGNMENT > 15
|
||||
/* To avoid that x86 processors would reload cached instructions each time
|
||||
when data is written in the near, we need to make sure that code and data
|
||||
do not share the same 64 byte unit */
|
||||
fill = -(mem + offset) & RUN_SECTION_ALIGNMENT;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* relocate symbols */
|
||||
relocate_syms(s1, s1->symtab, 1);
|
||||
if (s1->nb_errors)
|
||||
return -1;
|
||||
|
||||
if (0 == mem)
|
||||
return offset + RUN_SECTION_ALIGNMENT;
|
||||
|
||||
#ifdef TCC_TARGET_PE
|
||||
s1->pe_imagebase = mem;
|
||||
#endif
|
||||
|
||||
/* relocate each section */
|
||||
for(i = 1; i < s1->nb_sections; i++) {
|
||||
s = s1->sections[i];
|
||||
if (s->reloc)
|
||||
relocate_section(s1, s);
|
||||
}
|
||||
relocate_plt(s1);
|
||||
|
||||
for(i = 1; i < s1->nb_sections; i++) {
|
||||
s = s1->sections[i];
|
||||
if (0 == (s->sh_flags & SHF_ALLOC))
|
||||
continue;
|
||||
length = s->data_offset;
|
||||
ptr = (void*)s->sh_addr;
|
||||
if (s->sh_flags & SHF_EXECINSTR)
|
||||
ptr = (char*)ptr - ptr_diff;
|
||||
if (NULL == s->data || s->sh_type == SHT_NOBITS)
|
||||
memset(ptr, 0, length);
|
||||
else
|
||||
memcpy(ptr, s->data, length);
|
||||
/* mark executable sections as executable in memory */
|
||||
if (s->sh_flags & SHF_EXECINSTR)
|
||||
set_pages_executable((char*)ptr + ptr_diff, length);
|
||||
}
|
||||
|
||||
#ifdef _WIN64
|
||||
*(void**)mem = win64_add_function_table(s1);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* allow to run code in memory */
|
||||
|
||||
static void set_pages_executable(void *ptr, unsigned long length)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
unsigned long old_protect;
|
||||
VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
#else
|
||||
void __clear_cache(void *beginning, void *end);
|
||||
# ifndef HAVE_SELINUX
|
||||
addr_t start, end;
|
||||
# ifndef PAGESIZE
|
||||
# define PAGESIZE 4096
|
||||
# endif
|
||||
start = (addr_t)ptr & ~(PAGESIZE - 1);
|
||||
end = (addr_t)ptr + length;
|
||||
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
|
||||
if (mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC))
|
||||
tcc_error("mprotect failed: did you mean to configure --with-selinux?");
|
||||
# endif
|
||||
# if defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64
|
||||
__clear_cache(ptr, (char *)ptr + length);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN64
|
||||
static void *win64_add_function_table(TCCState *s1)
|
||||
{
|
||||
void *p = NULL;
|
||||
if (s1->uw_pdata) {
|
||||
p = (void*)s1->uw_pdata->sh_addr;
|
||||
RtlAddFunctionTable(
|
||||
(RUNTIME_FUNCTION*)p,
|
||||
s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
|
||||
s1->pe_imagebase
|
||||
);
|
||||
s1->uw_pdata = NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static void win64_del_function_table(void *p)
|
||||
{
|
||||
if (p) {
|
||||
RtlDeleteFunctionTable((RUNTIME_FUNCTION*)p);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#ifdef CONFIG_TCC_BACKTRACE
|
||||
|
||||
ST_FUNC void tcc_set_num_callers(int n)
|
||||
{
|
||||
rt_num_callers = n;
|
||||
}
|
||||
|
||||
/* print the position in the source file of PC value 'pc' by reading
|
||||
the stabs debug information */
|
||||
static addr_t rt_printline(addr_t wanted_pc, const char *msg)
|
||||
{
|
||||
char func_name[128], last_func_name[128];
|
||||
addr_t func_addr, last_pc, pc;
|
||||
const char *incl_files[INCLUDE_STACK_SIZE];
|
||||
int incl_index, len, last_line_num, i;
|
||||
const char *str, *p;
|
||||
|
||||
Stab_Sym *stab_sym = NULL, *stab_sym_end, *sym;
|
||||
int stab_len = 0;
|
||||
char *stab_str = NULL;
|
||||
|
||||
if (stab_section) {
|
||||
stab_len = stab_section->data_offset;
|
||||
stab_sym = (Stab_Sym *)stab_section->data;
|
||||
stab_str = (char *) stabstr_section->data;
|
||||
}
|
||||
|
||||
func_name[0] = '\0';
|
||||
func_addr = 0;
|
||||
incl_index = 0;
|
||||
last_func_name[0] = '\0';
|
||||
last_pc = (addr_t)-1;
|
||||
last_line_num = 1;
|
||||
|
||||
if (!stab_sym)
|
||||
goto no_stabs;
|
||||
|
||||
stab_sym_end = (Stab_Sym*)((char*)stab_sym + stab_len);
|
||||
for (sym = stab_sym + 1; sym < stab_sym_end; ++sym) {
|
||||
switch(sym->n_type) {
|
||||
/* function start or end */
|
||||
case N_FUN:
|
||||
if (sym->n_strx == 0) {
|
||||
/* we test if between last line and end of function */
|
||||
pc = sym->n_value + func_addr;
|
||||
if (wanted_pc >= last_pc && wanted_pc < pc)
|
||||
goto found;
|
||||
func_name[0] = '\0';
|
||||
func_addr = 0;
|
||||
} else {
|
||||
str = stab_str + sym->n_strx;
|
||||
p = strchr(str, ':');
|
||||
if (!p) {
|
||||
pstrcpy(func_name, sizeof(func_name), str);
|
||||
} else {
|
||||
len = p - str;
|
||||
if (len > sizeof(func_name) - 1)
|
||||
len = sizeof(func_name) - 1;
|
||||
memcpy(func_name, str, len);
|
||||
func_name[len] = '\0';
|
||||
}
|
||||
func_addr = sym->n_value;
|
||||
}
|
||||
break;
|
||||
/* line number info */
|
||||
case N_SLINE:
|
||||
pc = sym->n_value + func_addr;
|
||||
if (wanted_pc >= last_pc && wanted_pc < pc)
|
||||
goto found;
|
||||
last_pc = pc;
|
||||
last_line_num = sym->n_desc;
|
||||
/* XXX: slow! */
|
||||
strcpy(last_func_name, func_name);
|
||||
break;
|
||||
/* include files */
|
||||
case N_BINCL:
|
||||
str = stab_str + sym->n_strx;
|
||||
add_incl:
|
||||
if (incl_index < INCLUDE_STACK_SIZE) {
|
||||
incl_files[incl_index++] = str;
|
||||
}
|
||||
break;
|
||||
case N_EINCL:
|
||||
if (incl_index > 1)
|
||||
incl_index--;
|
||||
break;
|
||||
case N_SO:
|
||||
if (sym->n_strx == 0) {
|
||||
incl_index = 0; /* end of translation unit */
|
||||
} else {
|
||||
str = stab_str + sym->n_strx;
|
||||
/* do not add path */
|
||||
len = strlen(str);
|
||||
if (len > 0 && str[len - 1] != '/')
|
||||
goto add_incl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
no_stabs:
|
||||
/* second pass: we try symtab symbols (no line number info) */
|
||||
incl_index = 0;
|
||||
if (symtab_section)
|
||||
{
|
||||
ElfW(Sym) *sym, *sym_end;
|
||||
int type;
|
||||
|
||||
sym_end = (ElfW(Sym) *)(symtab_section->data + symtab_section->data_offset);
|
||||
for(sym = (ElfW(Sym) *)symtab_section->data + 1;
|
||||
sym < sym_end;
|
||||
sym++) {
|
||||
type = ELFW(ST_TYPE)(sym->st_info);
|
||||
if (type == STT_FUNC || type == STT_GNU_IFUNC) {
|
||||
if (wanted_pc >= sym->st_value &&
|
||||
wanted_pc < sym->st_value + sym->st_size) {
|
||||
pstrcpy(last_func_name, sizeof(last_func_name),
|
||||
(char *) symtab_section->link->data + sym->st_name);
|
||||
func_addr = sym->st_value;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* did not find any info: */
|
||||
fprintf(stderr, "%s %p ???\n", msg, (void*)wanted_pc);
|
||||
fflush(stderr);
|
||||
return 0;
|
||||
found:
|
||||
i = incl_index;
|
||||
if (i > 0)
|
||||
fprintf(stderr, "%s:%d: ", incl_files[--i], last_line_num);
|
||||
fprintf(stderr, "%s %p", msg, (void*)wanted_pc);
|
||||
if (last_func_name[0] != '\0')
|
||||
fprintf(stderr, " %s()", last_func_name);
|
||||
if (--i >= 0) {
|
||||
fprintf(stderr, " (included from ");
|
||||
for (;;) {
|
||||
fprintf(stderr, "%s", incl_files[i]);
|
||||
if (--i < 0)
|
||||
break;
|
||||
fprintf(stderr, ", ");
|
||||
}
|
||||
fprintf(stderr, ")");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stderr);
|
||||
return func_addr;
|
||||
}
|
||||
|
||||
/* emit a run time error at position 'pc' */
|
||||
static void rt_error(ucontext_t *uc, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
addr_t pc;
|
||||
int i;
|
||||
|
||||
fprintf(stderr, "Runtime error: ");
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
for(i=0;i<rt_num_callers;i++) {
|
||||
if (rt_get_caller_pc(&pc, uc, i) < 0)
|
||||
break;
|
||||
pc = rt_printline(pc, i ? "by" : "at");
|
||||
if (pc == (addr_t)rt_prog_main && pc)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#ifndef _WIN32
|
||||
|
||||
/* signal handler for fatal errors */
|
||||
static void sig_error(int signum, siginfo_t *siginf, void *puc)
|
||||
{
|
||||
ucontext_t *uc = puc;
|
||||
|
||||
switch(signum) {
|
||||
case SIGFPE:
|
||||
switch(siginf->si_code) {
|
||||
case FPE_INTDIV:
|
||||
case FPE_FLTDIV:
|
||||
rt_error(uc, "division by zero");
|
||||
break;
|
||||
default:
|
||||
rt_error(uc, "floating point exception");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SIGBUS:
|
||||
case SIGSEGV:
|
||||
if (rt_bound_error_msg && *rt_bound_error_msg)
|
||||
rt_error(uc, *rt_bound_error_msg);
|
||||
else
|
||||
rt_error(uc, "dereferencing invalid pointer");
|
||||
break;
|
||||
case SIGILL:
|
||||
rt_error(uc, "illegal instruction");
|
||||
break;
|
||||
case SIGABRT:
|
||||
rt_error(uc, "abort() called");
|
||||
break;
|
||||
default:
|
||||
rt_error(uc, "caught signal %d", signum);
|
||||
break;
|
||||
}
|
||||
exit(255);
|
||||
}
|
||||
|
||||
#ifndef SA_SIGINFO
|
||||
# define SA_SIGINFO 0x00000004u
|
||||
#endif
|
||||
|
||||
/* Generate a stack backtrace when a CPU exception occurs. */
|
||||
static void set_exception_handler(void)
|
||||
{
|
||||
struct sigaction sigact;
|
||||
/* install TCC signal handlers to print debug info on fatal
|
||||
runtime errors */
|
||||
sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
|
||||
sigact.sa_sigaction = sig_error;
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigaction(SIGFPE, &sigact, NULL);
|
||||
sigaction(SIGILL, &sigact, NULL);
|
||||
sigaction(SIGSEGV, &sigact, NULL);
|
||||
sigaction(SIGBUS, &sigact, NULL);
|
||||
sigaction(SIGABRT, &sigact, NULL);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#ifdef __i386__
|
||||
|
||||
/* fix for glibc 2.1 */
|
||||
#ifndef REG_EIP
|
||||
#define REG_EIP EIP
|
||||
#define REG_EBP EBP
|
||||
#endif
|
||||
|
||||
/* return the PC at frame level 'level'. Return negative if not found */
|
||||
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
|
||||
{
|
||||
addr_t fp;
|
||||
int i;
|
||||
|
||||
if (level == 0) {
|
||||
#if defined(__APPLE__)
|
||||
*paddr = uc->uc_mcontext->__ss.__eip;
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
||||
*paddr = uc->uc_mcontext.mc_eip;
|
||||
#elif defined(__dietlibc__)
|
||||
*paddr = uc->uc_mcontext.eip;
|
||||
#elif defined(__NetBSD__)
|
||||
*paddr = uc->uc_mcontext.__gregs[_REG_EIP];
|
||||
#elif defined(__OpenBSD__)
|
||||
*paddr = uc->sc_eip;
|
||||
#else
|
||||
*paddr = uc->uc_mcontext.gregs[REG_EIP];
|
||||
#endif
|
||||
return 0;
|
||||
} else {
|
||||
#if defined(__APPLE__)
|
||||
fp = uc->uc_mcontext->__ss.__ebp;
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
||||
fp = uc->uc_mcontext.mc_ebp;
|
||||
#elif defined(__dietlibc__)
|
||||
fp = uc->uc_mcontext.ebp;
|
||||
#elif defined(__NetBSD__)
|
||||
fp = uc->uc_mcontext.__gregs[_REG_EBP];
|
||||
#elif defined(__OpenBSD__)
|
||||
*paddr = uc->sc_ebp;
|
||||
#else
|
||||
fp = uc->uc_mcontext.gregs[REG_EBP];
|
||||
#endif
|
||||
for(i=1;i<level;i++) {
|
||||
/* XXX: check address validity with program info */
|
||||
if (fp <= 0x1000 || fp >= 0xc0000000)
|
||||
return -1;
|
||||
fp = ((addr_t *)fp)[0];
|
||||
}
|
||||
*paddr = ((addr_t *)fp)[1];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#elif defined(__x86_64__)
|
||||
|
||||
/* return the PC at frame level 'level'. Return negative if not found */
|
||||
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
|
||||
{
|
||||
addr_t fp;
|
||||
int i;
|
||||
|
||||
if (level == 0) {
|
||||
/* XXX: only support linux */
|
||||
#if defined(__APPLE__)
|
||||
*paddr = uc->uc_mcontext->__ss.__rip;
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
||||
*paddr = uc->uc_mcontext.mc_rip;
|
||||
#elif defined(__NetBSD__)
|
||||
*paddr = uc->uc_mcontext.__gregs[_REG_RIP];
|
||||
#else
|
||||
*paddr = uc->uc_mcontext.gregs[REG_RIP];
|
||||
#endif
|
||||
return 0;
|
||||
} else {
|
||||
#if defined(__APPLE__)
|
||||
fp = uc->uc_mcontext->__ss.__rbp;
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
||||
fp = uc->uc_mcontext.mc_rbp;
|
||||
#elif defined(__NetBSD__)
|
||||
fp = uc->uc_mcontext.__gregs[_REG_RBP];
|
||||
#else
|
||||
fp = uc->uc_mcontext.gregs[REG_RBP];
|
||||
#endif
|
||||
for(i=1;i<level;i++) {
|
||||
/* XXX: check address validity with program info */
|
||||
if (fp <= 0x1000)
|
||||
return -1;
|
||||
fp = ((addr_t *)fp)[0];
|
||||
}
|
||||
*paddr = ((addr_t *)fp)[1];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#elif defined(__arm__)
|
||||
|
||||
/* return the PC at frame level 'level'. Return negative if not found */
|
||||
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
|
||||
{
|
||||
addr_t fp, sp;
|
||||
int i;
|
||||
|
||||
if (level == 0) {
|
||||
/* XXX: only supports linux */
|
||||
#if defined(__linux__)
|
||||
*paddr = uc->uc_mcontext.arm_pc;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return 0;
|
||||
} else {
|
||||
#if defined(__linux__)
|
||||
fp = uc->uc_mcontext.arm_fp;
|
||||
sp = uc->uc_mcontext.arm_sp;
|
||||
if (sp < 0x1000)
|
||||
sp = 0x1000;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
/* XXX: specific to tinycc stack frames */
|
||||
if (fp < sp + 12 || fp & 3)
|
||||
return -1;
|
||||
for(i = 1; i < level; i++) {
|
||||
sp = ((addr_t *)fp)[-2];
|
||||
if (sp < fp || sp - fp > 16 || sp & 3)
|
||||
return -1;
|
||||
fp = ((addr_t *)fp)[-3];
|
||||
if (fp <= sp || fp - sp < 12 || fp & 3)
|
||||
return -1;
|
||||
}
|
||||
/* XXX: check address validity with program info */
|
||||
*paddr = ((addr_t *)fp)[-1];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
|
||||
{
|
||||
if (level < 0)
|
||||
return -1;
|
||||
else if (level == 0) {
|
||||
*paddr = uc->uc_mcontext.pc;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
addr_t *fp = (addr_t *)uc->uc_mcontext.regs[29];
|
||||
int i;
|
||||
for (i = 1; i < level; i++)
|
||||
fp = (addr_t *)fp[0];
|
||||
*paddr = fp[1];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#else
|
||||
|
||||
#warning add arch specific rt_get_caller_pc()
|
||||
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* !__i386__ */
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#else /* WIN32 */
|
||||
|
||||
static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info)
|
||||
{
|
||||
EXCEPTION_RECORD *er = ex_info->ExceptionRecord;
|
||||
CONTEXT *uc = ex_info->ContextRecord;
|
||||
switch (er->ExceptionCode) {
|
||||
case EXCEPTION_ACCESS_VIOLATION:
|
||||
if (rt_bound_error_msg && *rt_bound_error_msg)
|
||||
rt_error(uc, *rt_bound_error_msg);
|
||||
else
|
||||
rt_error(uc, "access violation");
|
||||
break;
|
||||
case EXCEPTION_STACK_OVERFLOW:
|
||||
rt_error(uc, "stack overflow");
|
||||
break;
|
||||
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
||||
rt_error(uc, "division by zero");
|
||||
break;
|
||||
default:
|
||||
rt_error(uc, "exception caught");
|
||||
break;
|
||||
}
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
/* Generate a stack backtrace when a CPU exception occurs. */
|
||||
static void set_exception_handler(void)
|
||||
{
|
||||
SetUnhandledExceptionFilter(cpu_exception_handler);
|
||||
}
|
||||
|
||||
/* return the PC at frame level 'level'. Return non zero if not found */
|
||||
static int rt_get_caller_pc(addr_t *paddr, CONTEXT *uc, int level)
|
||||
{
|
||||
addr_t fp, pc;
|
||||
int i;
|
||||
#ifdef _WIN64
|
||||
pc = uc->Rip;
|
||||
fp = uc->Rbp;
|
||||
#else
|
||||
pc = uc->Eip;
|
||||
fp = uc->Ebp;
|
||||
#endif
|
||||
if (level > 0) {
|
||||
for(i=1;i<level;i++) {
|
||||
/* XXX: check address validity with program info */
|
||||
if (fp <= 0x1000 || fp >= 0xc0000000)
|
||||
return -1;
|
||||
fp = ((addr_t*)fp)[0];
|
||||
}
|
||||
pc = ((addr_t*)fp)[1];
|
||||
}
|
||||
*paddr = pc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
#endif /* CONFIG_TCC_BACKTRACE */
|
||||
/* ------------------------------------------------------------- */
|
||||
#ifdef CONFIG_TCC_STATIC
|
||||
|
||||
/* dummy function for profiling */
|
||||
ST_FUNC void *dlopen(const char *filename, int flag)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ST_FUNC void dlclose(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
ST_FUNC const char *dlerror(void)
|
||||
{
|
||||
return "error";
|
||||
}
|
||||
|
||||
typedef struct TCCSyms {
|
||||
char *str;
|
||||
void *ptr;
|
||||
} TCCSyms;
|
||||
|
||||
|
||||
/* add the symbol you want here if no dynamic linking is done */
|
||||
static TCCSyms tcc_syms[] = {
|
||||
#if !defined(CONFIG_TCCBOOT)
|
||||
#define TCCSYM(a) { #a, &a, },
|
||||
TCCSYM(printf)
|
||||
TCCSYM(fprintf)
|
||||
TCCSYM(fopen)
|
||||
TCCSYM(fclose)
|
||||
#undef TCCSYM
|
||||
#endif
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
ST_FUNC void *dlsym(void *handle, const char *symbol)
|
||||
{
|
||||
TCCSyms *p;
|
||||
p = tcc_syms;
|
||||
while (p->str != NULL) {
|
||||
if (!strcmp(p->str, symbol))
|
||||
return p->ptr;
|
||||
p++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TCC_STATIC */
|
||||
#endif /* TCC_IS_NATIVE */
|
||||
/* ------------------------------------------------------------- */
|
||||
350
packages/tcc/vendor/tcctok.h
vendored
350
packages/tcc/vendor/tcctok.h
vendored
@@ -1,350 +0,0 @@
|
||||
/* keywords */
|
||||
DEF(TOK_INT, "int")
|
||||
DEF(TOK_VOID, "void")
|
||||
DEF(TOK_CHAR, "char")
|
||||
DEF(TOK_IF, "if")
|
||||
DEF(TOK_ELSE, "else")
|
||||
DEF(TOK_WHILE, "while")
|
||||
DEF(TOK_BREAK, "break")
|
||||
DEF(TOK_RETURN, "return")
|
||||
DEF(TOK_FOR, "for")
|
||||
DEF(TOK_EXTERN, "extern")
|
||||
DEF(TOK_STATIC, "static")
|
||||
DEF(TOK_UNSIGNED, "unsigned")
|
||||
DEF(TOK_GOTO, "goto")
|
||||
DEF(TOK_DO, "do")
|
||||
DEF(TOK_CONTINUE, "continue")
|
||||
DEF(TOK_SWITCH, "switch")
|
||||
DEF(TOK_CASE, "case")
|
||||
|
||||
DEF(TOK_CONST1, "const")
|
||||
DEF(TOK_CONST2, "__const") /* gcc keyword */
|
||||
DEF(TOK_CONST3, "__const__") /* gcc keyword */
|
||||
DEF(TOK_VOLATILE1, "volatile")
|
||||
DEF(TOK_VOLATILE2, "__volatile") /* gcc keyword */
|
||||
DEF(TOK_VOLATILE3, "__volatile__") /* gcc keyword */
|
||||
DEF(TOK_LONG, "long")
|
||||
DEF(TOK_REGISTER, "register")
|
||||
DEF(TOK_SIGNED1, "signed")
|
||||
DEF(TOK_SIGNED2, "__signed") /* gcc keyword */
|
||||
DEF(TOK_SIGNED3, "__signed__") /* gcc keyword */
|
||||
DEF(TOK_AUTO, "auto")
|
||||
DEF(TOK_INLINE1, "inline")
|
||||
DEF(TOK_INLINE2, "__inline") /* gcc keyword */
|
||||
DEF(TOK_INLINE3, "__inline__") /* gcc keyword */
|
||||
DEF(TOK_RESTRICT1, "restrict")
|
||||
DEF(TOK_RESTRICT2, "__restrict")
|
||||
DEF(TOK_RESTRICT3, "__restrict__")
|
||||
DEF(TOK_EXTENSION, "__extension__") /* gcc keyword */
|
||||
|
||||
DEF(TOK_GENERIC, "_Generic")
|
||||
|
||||
DEF(TOK_FLOAT, "float")
|
||||
DEF(TOK_DOUBLE, "double")
|
||||
DEF(TOK_BOOL, "_Bool")
|
||||
DEF(TOK_SHORT, "short")
|
||||
DEF(TOK_STRUCT, "struct")
|
||||
DEF(TOK_UNION, "union")
|
||||
DEF(TOK_TYPEDEF, "typedef")
|
||||
DEF(TOK_DEFAULT, "default")
|
||||
DEF(TOK_ENUM, "enum")
|
||||
DEF(TOK_SIZEOF, "sizeof")
|
||||
DEF(TOK_ATTRIBUTE1, "__attribute")
|
||||
DEF(TOK_ATTRIBUTE2, "__attribute__")
|
||||
DEF(TOK_ALIGNOF1, "__alignof")
|
||||
DEF(TOK_ALIGNOF2, "__alignof__")
|
||||
DEF(TOK_TYPEOF1, "typeof")
|
||||
DEF(TOK_TYPEOF2, "__typeof")
|
||||
DEF(TOK_TYPEOF3, "__typeof__")
|
||||
DEF(TOK_LABEL, "__label__")
|
||||
DEF(TOK_ASM1, "asm")
|
||||
DEF(TOK_ASM2, "__asm")
|
||||
DEF(TOK_ASM3, "__asm__")
|
||||
|
||||
#ifdef TCC_TARGET_ARM64
|
||||
DEF(TOK_UINT128, "__uint128_t")
|
||||
#endif
|
||||
|
||||
/*********************************************************************/
|
||||
/* the following are not keywords. They are included to ease parsing */
|
||||
/* preprocessor only */
|
||||
DEF(TOK_DEFINE, "define")
|
||||
DEF(TOK_INCLUDE, "include")
|
||||
DEF(TOK_INCLUDE_NEXT, "include_next")
|
||||
DEF(TOK_IFDEF, "ifdef")
|
||||
DEF(TOK_IFNDEF, "ifndef")
|
||||
DEF(TOK_ELIF, "elif")
|
||||
DEF(TOK_ENDIF, "endif")
|
||||
DEF(TOK_DEFINED, "defined")
|
||||
DEF(TOK_UNDEF, "undef")
|
||||
DEF(TOK_ERROR, "error")
|
||||
DEF(TOK_WARNING, "warning")
|
||||
DEF(TOK_LINE, "line")
|
||||
DEF(TOK_PRAGMA, "pragma")
|
||||
DEF(TOK___LINE__, "__LINE__")
|
||||
DEF(TOK___FILE__, "__FILE__")
|
||||
DEF(TOK___DATE__, "__DATE__")
|
||||
DEF(TOK___TIME__, "__TIME__")
|
||||
DEF(TOK___FUNCTION__, "__FUNCTION__")
|
||||
DEF(TOK___VA_ARGS__, "__VA_ARGS__")
|
||||
DEF(TOK___COUNTER__, "__COUNTER__")
|
||||
|
||||
/* special identifiers */
|
||||
DEF(TOK___FUNC__, "__func__")
|
||||
|
||||
/* special floating point values */
|
||||
DEF(TOK___NAN__, "__nan__")
|
||||
DEF(TOK___SNAN__, "__snan__")
|
||||
DEF(TOK___INF__, "__inf__")
|
||||
|
||||
/* attribute identifiers */
|
||||
/* XXX: handle all tokens generically since speed is not critical */
|
||||
DEF(TOK_SECTION1, "section")
|
||||
DEF(TOK_SECTION2, "__section__")
|
||||
DEF(TOK_ALIGNED1, "aligned")
|
||||
DEF(TOK_ALIGNED2, "__aligned__")
|
||||
DEF(TOK_PACKED1, "packed")
|
||||
DEF(TOK_PACKED2, "__packed__")
|
||||
DEF(TOK_WEAK1, "weak")
|
||||
DEF(TOK_WEAK2, "__weak__")
|
||||
DEF(TOK_ALIAS1, "alias")
|
||||
DEF(TOK_ALIAS2, "__alias__")
|
||||
DEF(TOK_UNUSED1, "unused")
|
||||
DEF(TOK_UNUSED2, "__unused__")
|
||||
DEF(TOK_CDECL1, "cdecl")
|
||||
DEF(TOK_CDECL2, "__cdecl")
|
||||
DEF(TOK_CDECL3, "__cdecl__")
|
||||
DEF(TOK_STDCALL1, "stdcall")
|
||||
DEF(TOK_STDCALL2, "__stdcall")
|
||||
DEF(TOK_STDCALL3, "__stdcall__")
|
||||
DEF(TOK_FASTCALL1, "fastcall")
|
||||
DEF(TOK_FASTCALL2, "__fastcall")
|
||||
DEF(TOK_FASTCALL3, "__fastcall__")
|
||||
DEF(TOK_REGPARM1, "regparm")
|
||||
DEF(TOK_REGPARM2, "__regparm__")
|
||||
|
||||
DEF(TOK_MODE, "__mode__")
|
||||
DEF(TOK_MODE_QI, "__QI__")
|
||||
DEF(TOK_MODE_DI, "__DI__")
|
||||
DEF(TOK_MODE_HI, "__HI__")
|
||||
DEF(TOK_MODE_SI, "__SI__")
|
||||
DEF(TOK_MODE_word, "__word__")
|
||||
|
||||
DEF(TOK_DLLEXPORT, "dllexport")
|
||||
DEF(TOK_DLLIMPORT, "dllimport")
|
||||
DEF(TOK_NORETURN1, "noreturn")
|
||||
DEF(TOK_NORETURN2, "__noreturn__")
|
||||
DEF(TOK_VISIBILITY1, "visibility")
|
||||
DEF(TOK_VISIBILITY2, "__visibility__")
|
||||
|
||||
DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
|
||||
DEF(TOK_builtin_choose_expr, "__builtin_choose_expr")
|
||||
DEF(TOK_builtin_constant_p, "__builtin_constant_p")
|
||||
DEF(TOK_builtin_frame_address, "__builtin_frame_address")
|
||||
DEF(TOK_builtin_return_address, "__builtin_return_address")
|
||||
DEF(TOK_builtin_expect, "__builtin_expect")
|
||||
/*DEF(TOK_builtin_va_list, "__builtin_va_list")*/
|
||||
#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64
|
||||
DEF(TOK_builtin_va_start, "__builtin_va_start")
|
||||
#elif defined TCC_TARGET_X86_64
|
||||
DEF(TOK_builtin_va_arg_types, "__builtin_va_arg_types")
|
||||
#elif defined TCC_TARGET_ARM64
|
||||
DEF(TOK___va_start, "__va_start")
|
||||
DEF(TOK___va_arg, "__va_arg")
|
||||
#endif
|
||||
|
||||
/* pragma */
|
||||
DEF(TOK_pack, "pack")
|
||||
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64)
|
||||
/* already defined for assembler */
|
||||
DEF(TOK_ASM_push, "push")
|
||||
DEF(TOK_ASM_pop, "pop")
|
||||
#endif
|
||||
DEF(TOK_comment, "comment")
|
||||
DEF(TOK_lib, "lib")
|
||||
DEF(TOK_push_macro, "push_macro")
|
||||
DEF(TOK_pop_macro, "pop_macro")
|
||||
DEF(TOK_once, "once")
|
||||
DEF(TOK_option, "option")
|
||||
|
||||
/* builtin functions or variables */
|
||||
#ifndef TCC_ARM_EABI
|
||||
DEF(TOK_memcpy, "memcpy")
|
||||
DEF(TOK_memmove, "memmove")
|
||||
DEF(TOK_memset, "memset")
|
||||
DEF(TOK___divdi3, "__divdi3")
|
||||
DEF(TOK___moddi3, "__moddi3")
|
||||
DEF(TOK___udivdi3, "__udivdi3")
|
||||
DEF(TOK___umoddi3, "__umoddi3")
|
||||
DEF(TOK___ashrdi3, "__ashrdi3")
|
||||
DEF(TOK___lshrdi3, "__lshrdi3")
|
||||
DEF(TOK___ashldi3, "__ashldi3")
|
||||
DEF(TOK___floatundisf, "__floatundisf")
|
||||
DEF(TOK___floatundidf, "__floatundidf")
|
||||
# ifndef TCC_ARM_VFP
|
||||
DEF(TOK___floatundixf, "__floatundixf")
|
||||
DEF(TOK___fixunsxfdi, "__fixunsxfdi")
|
||||
# endif
|
||||
DEF(TOK___fixunssfdi, "__fixunssfdi")
|
||||
DEF(TOK___fixunsdfdi, "__fixunsdfdi")
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_ARM
|
||||
# ifdef TCC_ARM_EABI
|
||||
DEF(TOK_memcpy, "__aeabi_memcpy")
|
||||
DEF(TOK_memcpy4, "__aeabi_memcpy4")
|
||||
DEF(TOK_memcpy8, "__aeabi_memcpy8")
|
||||
DEF(TOK_memmove, "__aeabi_memmove")
|
||||
DEF(TOK_memset, "__aeabi_memset")
|
||||
DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod")
|
||||
DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod")
|
||||
DEF(TOK___aeabi_idivmod, "__aeabi_idivmod")
|
||||
DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod")
|
||||
DEF(TOK___divsi3, "__aeabi_idiv")
|
||||
DEF(TOK___udivsi3, "__aeabi_uidiv")
|
||||
DEF(TOK___floatdisf, "__aeabi_l2f")
|
||||
DEF(TOK___floatdidf, "__aeabi_l2d")
|
||||
DEF(TOK___fixsfdi, "__aeabi_f2lz")
|
||||
DEF(TOK___fixdfdi, "__aeabi_d2lz")
|
||||
DEF(TOK___ashrdi3, "__aeabi_lasr")
|
||||
DEF(TOK___lshrdi3, "__aeabi_llsr")
|
||||
DEF(TOK___ashldi3, "__aeabi_llsl")
|
||||
DEF(TOK___floatundisf, "__aeabi_ul2f")
|
||||
DEF(TOK___floatundidf, "__aeabi_ul2d")
|
||||
DEF(TOK___fixunssfdi, "__aeabi_f2ulz")
|
||||
DEF(TOK___fixunsdfdi, "__aeabi_d2ulz")
|
||||
# else
|
||||
DEF(TOK___modsi3, "__modsi3")
|
||||
DEF(TOK___umodsi3, "__umodsi3")
|
||||
DEF(TOK___divsi3, "__divsi3")
|
||||
DEF(TOK___udivsi3, "__udivsi3")
|
||||
DEF(TOK___floatdisf, "__floatdisf")
|
||||
DEF(TOK___floatdidf, "__floatdidf")
|
||||
# ifndef TCC_ARM_VFP
|
||||
DEF(TOK___floatdixf, "__floatdixf")
|
||||
DEF(TOK___fixunssfsi, "__fixunssfsi")
|
||||
DEF(TOK___fixunsdfsi, "__fixunsdfsi")
|
||||
DEF(TOK___fixunsxfsi, "__fixunsxfsi")
|
||||
DEF(TOK___fixxfdi, "__fixxfdi")
|
||||
# endif
|
||||
DEF(TOK___fixsfdi, "__fixsfdi")
|
||||
DEF(TOK___fixdfdi, "__fixdfdi")
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_C67
|
||||
DEF(TOK__divi, "_divi")
|
||||
DEF(TOK__divu, "_divu")
|
||||
DEF(TOK__divf, "_divf")
|
||||
DEF(TOK__divd, "_divd")
|
||||
DEF(TOK__remi, "_remi")
|
||||
DEF(TOK__remu, "_remu")
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_I386
|
||||
DEF(TOK___fixsfdi, "__fixsfdi")
|
||||
DEF(TOK___fixdfdi, "__fixdfdi")
|
||||
DEF(TOK___fixxfdi, "__fixxfdi")
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
||||
DEF(TOK_alloca, "alloca")
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_PE
|
||||
DEF(TOK___chkstk, "__chkstk")
|
||||
#endif
|
||||
#ifdef TCC_TARGET_ARM64
|
||||
DEF(TOK___arm64_clear_cache, "__arm64_clear_cache")
|
||||
DEF(TOK___addtf3, "__addtf3")
|
||||
DEF(TOK___subtf3, "__subtf3")
|
||||
DEF(TOK___multf3, "__multf3")
|
||||
DEF(TOK___divtf3, "__divtf3")
|
||||
DEF(TOK___extendsftf2, "__extendsftf2")
|
||||
DEF(TOK___extenddftf2, "__extenddftf2")
|
||||
DEF(TOK___trunctfsf2, "__trunctfsf2")
|
||||
DEF(TOK___trunctfdf2, "__trunctfdf2")
|
||||
DEF(TOK___fixtfsi, "__fixtfsi")
|
||||
DEF(TOK___fixtfdi, "__fixtfdi")
|
||||
DEF(TOK___fixunstfsi, "__fixunstfsi")
|
||||
DEF(TOK___fixunstfdi, "__fixunstfdi")
|
||||
DEF(TOK___floatsitf, "__floatsitf")
|
||||
DEF(TOK___floatditf, "__floatditf")
|
||||
DEF(TOK___floatunsitf, "__floatunsitf")
|
||||
DEF(TOK___floatunditf, "__floatunditf")
|
||||
DEF(TOK___eqtf2, "__eqtf2")
|
||||
DEF(TOK___netf2, "__netf2")
|
||||
DEF(TOK___lttf2, "__lttf2")
|
||||
DEF(TOK___letf2, "__letf2")
|
||||
DEF(TOK___gttf2, "__gttf2")
|
||||
DEF(TOK___getf2, "__getf2")
|
||||
#endif
|
||||
|
||||
/* bound checking symbols */
|
||||
#ifdef CONFIG_TCC_BCHECK
|
||||
DEF(TOK___bound_ptr_add, "__bound_ptr_add")
|
||||
DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1")
|
||||
DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2")
|
||||
DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4")
|
||||
DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8")
|
||||
DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12")
|
||||
DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
|
||||
DEF(TOK___bound_main_arg, "__bound_main_arg")
|
||||
DEF(TOK___bound_local_new, "__bound_local_new")
|
||||
DEF(TOK___bound_local_delete, "__bound_local_delete")
|
||||
# ifdef TCC_TARGET_PE
|
||||
DEF(TOK_malloc, "malloc")
|
||||
DEF(TOK_free, "free")
|
||||
DEF(TOK_realloc, "realloc")
|
||||
DEF(TOK_memalign, "memalign")
|
||||
DEF(TOK_calloc, "calloc")
|
||||
# endif
|
||||
DEF(TOK_strlen, "strlen")
|
||||
DEF(TOK_strcpy, "strcpy")
|
||||
#endif
|
||||
|
||||
/* Tiny Assembler */
|
||||
DEF_ASMDIR(byte) /* must be first directive */
|
||||
DEF_ASMDIR(word)
|
||||
DEF_ASMDIR(align)
|
||||
DEF_ASMDIR(balign)
|
||||
DEF_ASMDIR(p2align)
|
||||
DEF_ASMDIR(set)
|
||||
DEF_ASMDIR(skip)
|
||||
DEF_ASMDIR(space)
|
||||
DEF_ASMDIR(string)
|
||||
DEF_ASMDIR(asciz)
|
||||
DEF_ASMDIR(ascii)
|
||||
DEF_ASMDIR(file)
|
||||
DEF_ASMDIR(globl)
|
||||
DEF_ASMDIR(global)
|
||||
DEF_ASMDIR(weak)
|
||||
DEF_ASMDIR(hidden)
|
||||
DEF_ASMDIR(ident)
|
||||
DEF_ASMDIR(size)
|
||||
DEF_ASMDIR(type)
|
||||
DEF_ASMDIR(text)
|
||||
DEF_ASMDIR(data)
|
||||
DEF_ASMDIR(bss)
|
||||
DEF_ASMDIR(previous)
|
||||
DEF_ASMDIR(pushsection)
|
||||
DEF_ASMDIR(popsection)
|
||||
DEF_ASMDIR(fill)
|
||||
DEF_ASMDIR(rept)
|
||||
DEF_ASMDIR(endr)
|
||||
DEF_ASMDIR(org)
|
||||
DEF_ASMDIR(quad)
|
||||
#if defined(TCC_TARGET_I386)
|
||||
DEF_ASMDIR(code16)
|
||||
DEF_ASMDIR(code32)
|
||||
#elif defined(TCC_TARGET_X86_64)
|
||||
DEF_ASMDIR(code64)
|
||||
#endif
|
||||
DEF_ASMDIR(short)
|
||||
DEF_ASMDIR(long)
|
||||
DEF_ASMDIR(int)
|
||||
DEF_ASMDIR(section) /* must be last directive */
|
||||
|
||||
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
||||
#include "i386-tok.h"
|
||||
#endif
|
||||
525
packages/tcc/vendor/x86_64-asm.h
vendored
525
packages/tcc/vendor/x86_64-asm.h
vendored
@@ -1,525 +0,0 @@
|
||||
DEF_ASM_OP0(clc, 0xf8) /* must be first OP0 */
|
||||
DEF_ASM_OP0(cld, 0xfc)
|
||||
DEF_ASM_OP0(cli, 0xfa)
|
||||
DEF_ASM_OP0(clts, 0x0f06)
|
||||
DEF_ASM_OP0(cmc, 0xf5)
|
||||
DEF_ASM_OP0(lahf, 0x9f)
|
||||
DEF_ASM_OP0(sahf, 0x9e)
|
||||
DEF_ASM_OP0(pushfq, 0x9c)
|
||||
DEF_ASM_OP0(popfq, 0x9d)
|
||||
DEF_ASM_OP0(pushf, 0x9c)
|
||||
DEF_ASM_OP0(popf, 0x9d)
|
||||
DEF_ASM_OP0(stc, 0xf9)
|
||||
DEF_ASM_OP0(std, 0xfd)
|
||||
DEF_ASM_OP0(sti, 0xfb)
|
||||
DEF_ASM_OP0(aaa, 0x37)
|
||||
DEF_ASM_OP0(aas, 0x3f)
|
||||
DEF_ASM_OP0(daa, 0x27)
|
||||
DEF_ASM_OP0(das, 0x2f)
|
||||
DEF_ASM_OP0(aad, 0xd50a)
|
||||
DEF_ASM_OP0(aam, 0xd40a)
|
||||
DEF_ASM_OP0(cbw, 0x6698)
|
||||
DEF_ASM_OP0(cwd, 0x6699)
|
||||
DEF_ASM_OP0(cwde, 0x98)
|
||||
DEF_ASM_OP0(cdq, 0x99)
|
||||
DEF_ASM_OP0(cbtw, 0x6698)
|
||||
DEF_ASM_OP0(cwtl, 0x98)
|
||||
DEF_ASM_OP0(cwtd, 0x6699)
|
||||
DEF_ASM_OP0(cltd, 0x99)
|
||||
DEF_ASM_OP0(cqto, 0x4899)
|
||||
DEF_ASM_OP0(int3, 0xcc)
|
||||
DEF_ASM_OP0(into, 0xce)
|
||||
DEF_ASM_OP0(iret, 0xcf)
|
||||
DEF_ASM_OP0(rsm, 0x0faa)
|
||||
DEF_ASM_OP0(hlt, 0xf4)
|
||||
DEF_ASM_OP0(wait, 0x9b)
|
||||
DEF_ASM_OP0(nop, 0x90)
|
||||
DEF_ASM_OP0(pause, 0xf390)
|
||||
DEF_ASM_OP0(xlat, 0xd7)
|
||||
|
||||
/* strings */
|
||||
ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWLX))
|
||||
ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWLX))
|
||||
|
||||
ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL))
|
||||
ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL))
|
||||
|
||||
ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWLX))
|
||||
ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWLX))
|
||||
|
||||
ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWLX))
|
||||
ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWLX))
|
||||
|
||||
ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWLX))
|
||||
ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWLX))
|
||||
|
||||
ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWLX))
|
||||
ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWLX))
|
||||
|
||||
/* bits */
|
||||
|
||||
ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))
|
||||
|
||||
ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA))
|
||||
ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA))
|
||||
|
||||
ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA))
|
||||
ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA))
|
||||
|
||||
ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA))
|
||||
ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA))
|
||||
|
||||
ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA))
|
||||
ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA))
|
||||
|
||||
/* prefixes */
|
||||
DEF_ASM_OP0(lock, 0xf0)
|
||||
DEF_ASM_OP0(rep, 0xf3)
|
||||
DEF_ASM_OP0(repe, 0xf3)
|
||||
DEF_ASM_OP0(repz, 0xf3)
|
||||
DEF_ASM_OP0(repne, 0xf2)
|
||||
DEF_ASM_OP0(repnz, 0xf2)
|
||||
|
||||
DEF_ASM_OP0(invd, 0x0f08)
|
||||
DEF_ASM_OP0(wbinvd, 0x0f09)
|
||||
DEF_ASM_OP0(cpuid, 0x0fa2)
|
||||
DEF_ASM_OP0(wrmsr, 0x0f30)
|
||||
DEF_ASM_OP0(rdtsc, 0x0f31)
|
||||
DEF_ASM_OP0(rdmsr, 0x0f32)
|
||||
DEF_ASM_OP0(rdpmc, 0x0f33)
|
||||
|
||||
DEF_ASM_OP0(syscall, 0x0f05)
|
||||
DEF_ASM_OP0(sysret, 0x0f07)
|
||||
DEF_ASM_OP0L(sysretq, 0x480f07, 0, 0)
|
||||
DEF_ASM_OP0(ud2, 0x0f0b)
|
||||
|
||||
/* NOTE: we took the same order as gas opcode definition order */
|
||||
/* Right now we can't express the fact that 0xa1/0xa3 can't use $eax and a
|
||||
32 bit moffset as operands.
|
||||
ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWLX, OPT_ADDR, OPT_EAX))
|
||||
ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWLX, OPT_EAX, OPT_ADDR)) */
|
||||
ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG))
|
||||
ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG))
|
||||
/* The moves are special: the 0xb8 form supports IM64 (the only insn that
|
||||
does) with REG64. It doesn't support IM32 with REG64, it would use
|
||||
the full movabs form (64bit immediate). For IM32->REG64 we prefer
|
||||
the 0xc7 opcode. So disallow all 64bit forms and code the rest by hand. */
|
||||
ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWLX, OPT_IM, OPT_REG))
|
||||
ALT(DEF_ASM_OP2(mov, 0xb8, 0, OPC_REG, OPT_IM64, OPT_REG64))
|
||||
ALT(DEF_ASM_OP2(movq, 0xb8, 0, OPC_REG, OPT_IM64, OPT_REG64))
|
||||
ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWLX, OPT_IM, OPT_REG | OPT_EA))
|
||||
|
||||
ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WLX, OPT_SEG, OPT_EA | OPT_REG))
|
||||
ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WLX, OPT_EA | OPT_REG, OPT_SEG))
|
||||
|
||||
ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WLX, OPT_CR, OPT_REG64))
|
||||
ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WLX, OPT_DB, OPT_REG64))
|
||||
ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WLX, OPT_REG64, OPT_CR))
|
||||
ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WLX, OPT_REG64, OPT_DB))
|
||||
|
||||
ALT(DEF_ASM_OP2(movsbw, 0x660fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG16))
|
||||
ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32))
|
||||
ALT(DEF_ASM_OP2(movsbq, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
|
||||
ALT(DEF_ASM_OP2(movswq, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG))
|
||||
ALT(DEF_ASM_OP2(movslq, 0x63, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG))
|
||||
ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WLX, OPT_REG8 | OPT_EA, OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
|
||||
ALT(DEF_ASM_OP2(movzwq, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG))
|
||||
|
||||
ALT(DEF_ASM_OP1(pushq, 0x6a, 0, 0, OPT_IM8S))
|
||||
ALT(DEF_ASM_OP1(push, 0x6a, 0, 0, OPT_IM8S))
|
||||
ALT(DEF_ASM_OP1(pushw, 0x666a, 0, 0, OPT_IM8S))
|
||||
ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WLX, OPT_REG64))
|
||||
ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WLX, OPT_REG16))
|
||||
ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WLX, OPT_REG64 | OPT_EA))
|
||||
ALT(DEF_ASM_OP1(pushw, 0x6668, 0, 0, OPT_IM16))
|
||||
ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WLX, OPT_IM32))
|
||||
ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WLX, OPT_SEG))
|
||||
|
||||
ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WLX, OPT_REG64))
|
||||
ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WLX, OPT_REG16))
|
||||
ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA))
|
||||
ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WLX, OPT_SEG))
|
||||
|
||||
ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLX, OPT_REGW, OPT_EAX))
|
||||
ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLX, OPT_EAX, OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG))
|
||||
ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG))
|
||||
|
||||
ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX))
|
||||
ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8))
|
||||
ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX))
|
||||
ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX))
|
||||
|
||||
ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8))
|
||||
ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8))
|
||||
ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX))
|
||||
ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX))
|
||||
|
||||
ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WLX, OPT_EA, OPT_REG))
|
||||
|
||||
ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
|
||||
ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
|
||||
ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32))
|
||||
ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
|
||||
ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
|
||||
|
||||
/* arith */
|
||||
ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
|
||||
ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG))
|
||||
ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLX, OPT_IM, OPT_EAX))
|
||||
ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_EA | OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG))
|
||||
|
||||
ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG))
|
||||
ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG))
|
||||
ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWLX, OPT_IM, OPT_EAX))
|
||||
ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG))
|
||||
|
||||
ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA))
|
||||
ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA))
|
||||
|
||||
ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA))
|
||||
ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA))
|
||||
|
||||
ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA))
|
||||
ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA))
|
||||
|
||||
ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WLX, OPT_REG | OPT_EA, OPT_REG))
|
||||
ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_REGW))
|
||||
ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WLX, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WLX, OPT_IMW, OPT_REGW))
|
||||
|
||||
ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA))
|
||||
ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA, OPT_EAX))
|
||||
ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA))
|
||||
ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLX, OPT_REG | OPT_EA, OPT_EAX))
|
||||
|
||||
/* shifts */
|
||||
ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG))
|
||||
ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG))
|
||||
ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWLX | OPC_SHIFT, OPT_EA | OPT_REG))
|
||||
|
||||
ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
|
||||
ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLX, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_EA | OPT_REGW))
|
||||
ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
|
||||
ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLX, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_EA | OPT_REGW))
|
||||
|
||||
ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR))
|
||||
ALT(DEF_ASM_OP1(call, 0xe8, 0, 0, OPT_DISP))
|
||||
ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))
|
||||
ALT(DEF_ASM_OP1(jmp, 0xeb, 0, 0, OPT_DISP8))
|
||||
|
||||
ALT(DEF_ASM_OP1(lcall, 0xff, 3, OPC_MODRM, OPT_EA))
|
||||
ALT(DEF_ASM_OP1(ljmp, 0xff, 5, OPC_MODRM, OPT_EA))
|
||||
DEF_ASM_OP1(ljmpw, 0x66ff, 5, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(ljmpl, 0xff, 5, OPC_MODRM, OPT_EA)
|
||||
|
||||
ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8))
|
||||
ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
|
||||
ALT(DEF_ASM_OP1(setob, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
|
||||
DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8)
|
||||
DEF_ASM_OP0(leave, 0xc9)
|
||||
DEF_ASM_OP0(ret, 0xc3)
|
||||
DEF_ASM_OP0(retq, 0xc3)
|
||||
ALT(DEF_ASM_OP1(retq, 0xc2, 0, 0, OPT_IM16))
|
||||
ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16))
|
||||
DEF_ASM_OP0(lret, 0xcb)
|
||||
ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16))
|
||||
|
||||
ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_TEST, OPT_DISP8))
|
||||
DEF_ASM_OP1(loopne, 0xe0, 0, 0, OPT_DISP8)
|
||||
DEF_ASM_OP1(loopnz, 0xe0, 0, 0, OPT_DISP8)
|
||||
DEF_ASM_OP1(loope, 0xe1, 0, 0, OPT_DISP8)
|
||||
DEF_ASM_OP1(loopz, 0xe1, 0, 0, OPT_DISP8)
|
||||
DEF_ASM_OP1(loop, 0xe2, 0, 0, OPT_DISP8)
|
||||
DEF_ASM_OP1(jecxz, 0x67e3, 0, 0, OPT_DISP8)
|
||||
|
||||
/* float */
|
||||
/* specific fcomp handling */
|
||||
ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0))
|
||||
|
||||
ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST))
|
||||
ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
|
||||
ALT(DEF_ASM_OP2(fadd, 0xdcc0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
|
||||
ALT(DEF_ASM_OP2(fmul, 0xdcc8, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
|
||||
ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH))
|
||||
ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST))
|
||||
ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
|
||||
ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
|
||||
ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH))
|
||||
ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
|
||||
ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
|
||||
ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
|
||||
ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
|
||||
|
||||
DEF_ASM_OP0(fucompp, 0xdae9)
|
||||
DEF_ASM_OP0(ftst, 0xd9e4)
|
||||
DEF_ASM_OP0(fxam, 0xd9e5)
|
||||
DEF_ASM_OP0(fld1, 0xd9e8)
|
||||
DEF_ASM_OP0(fldl2t, 0xd9e9)
|
||||
DEF_ASM_OP0(fldl2e, 0xd9ea)
|
||||
DEF_ASM_OP0(fldpi, 0xd9eb)
|
||||
DEF_ASM_OP0(fldlg2, 0xd9ec)
|
||||
DEF_ASM_OP0(fldln2, 0xd9ed)
|
||||
DEF_ASM_OP0(fldz, 0xd9ee)
|
||||
|
||||
DEF_ASM_OP0(f2xm1, 0xd9f0)
|
||||
DEF_ASM_OP0(fyl2x, 0xd9f1)
|
||||
DEF_ASM_OP0(fptan, 0xd9f2)
|
||||
DEF_ASM_OP0(fpatan, 0xd9f3)
|
||||
DEF_ASM_OP0(fxtract, 0xd9f4)
|
||||
DEF_ASM_OP0(fprem1, 0xd9f5)
|
||||
DEF_ASM_OP0(fdecstp, 0xd9f6)
|
||||
DEF_ASM_OP0(fincstp, 0xd9f7)
|
||||
DEF_ASM_OP0(fprem, 0xd9f8)
|
||||
DEF_ASM_OP0(fyl2xp1, 0xd9f9)
|
||||
DEF_ASM_OP0(fsqrt, 0xd9fa)
|
||||
DEF_ASM_OP0(fsincos, 0xd9fb)
|
||||
DEF_ASM_OP0(frndint, 0xd9fc)
|
||||
DEF_ASM_OP0(fscale, 0xd9fd)
|
||||
DEF_ASM_OP0(fsin, 0xd9fe)
|
||||
DEF_ASM_OP0(fcos, 0xd9ff)
|
||||
DEF_ASM_OP0(fchs, 0xd9e0)
|
||||
DEF_ASM_OP0(fabs, 0xd9e1)
|
||||
DEF_ASM_OP0(fninit, 0xdbe3)
|
||||
DEF_ASM_OP0(fnclex, 0xdbe2)
|
||||
DEF_ASM_OP0(fnop, 0xd9d0)
|
||||
DEF_ASM_OP0(fwait, 0x9b)
|
||||
|
||||
/* fp load */
|
||||
DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST)
|
||||
DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST)
|
||||
DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA)
|
||||
ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA))
|
||||
DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA)
|
||||
DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA)
|
||||
|
||||
/* fp store */
|
||||
DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST)
|
||||
DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST)
|
||||
DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA)
|
||||
ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA))
|
||||
DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA)
|
||||
|
||||
DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST)
|
||||
DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA)
|
||||
|
||||
/* exchange */
|
||||
DEF_ASM_OP0(fxch, 0xd9c9)
|
||||
ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST))
|
||||
|
||||
/* misc FPU */
|
||||
DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST )
|
||||
DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST )
|
||||
|
||||
DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT)
|
||||
DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA )
|
||||
DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA )
|
||||
DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )
|
||||
DEF_ASM_OP0(fnstsw, 0xdfe0)
|
||||
ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX ))
|
||||
ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA ))
|
||||
DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX )
|
||||
ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT))
|
||||
ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ))
|
||||
DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT)
|
||||
DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA )
|
||||
DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
|
||||
DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA )
|
||||
DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA )
|
||||
DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
|
||||
DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA )
|
||||
DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST )
|
||||
DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST )
|
||||
DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA )
|
||||
DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA )
|
||||
/* The *q forms of fxrstor/fxsave use a REX prefix.
|
||||
If the operand would use extended registers we would have to modify
|
||||
it instead of generating a second one. Currently that's no
|
||||
problem with TCC, we don't use extended registers. */
|
||||
DEF_ASM_OP1(fxsaveq, 0x0fae, 0, OPC_MODRM | OPC_48, OPT_EA )
|
||||
DEF_ASM_OP1(fxrstorq, 0x0fae, 1, OPC_MODRM | OPC_48, OPT_EA )
|
||||
|
||||
/* segments */
|
||||
DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA)
|
||||
ALT(DEF_ASM_OP2(larw, 0x0f02, 0, OPC_MODRM | OPC_WLX, OPT_REG | OPT_EA, OPT_REG))
|
||||
DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(lgdtq, 0x0f01, 2, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(lidtq, 0x0f01, 3, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG)
|
||||
DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG)
|
||||
ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WLX, OPT_EA | OPT_REG, OPT_REG))
|
||||
DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG16)
|
||||
DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(sgdtq, 0x0f01, 0, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(sidtq, 0x0f01, 1, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA)
|
||||
DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA)
|
||||
DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG32 | OPT_EA)
|
||||
ALT(DEF_ASM_OP1(str, 0x660f00, 1, OPC_MODRM, OPT_REG16))
|
||||
ALT(DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM | OPC_48, OPT_REG64))
|
||||
DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA)
|
||||
DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA)
|
||||
DEF_ASM_OP0L(swapgs, 0x0f01, 7, OPC_MODRM)
|
||||
|
||||
/* 486 */
|
||||
/* bswap can't be applied to 16bit regs */
|
||||
DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 )
|
||||
DEF_ASM_OP1(bswapl, 0x0fc8, 0, OPC_REG, OPT_REG32 )
|
||||
DEF_ASM_OP1(bswapq, 0x0fc8, 0, OPC_REG | OPC_48, OPT_REG64 )
|
||||
|
||||
ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_REG | OPT_EA ))
|
||||
ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_REG | OPT_EA ))
|
||||
DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA )
|
||||
|
||||
/* pentium */
|
||||
DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA )
|
||||
|
||||
/* AMD 64 */
|
||||
DEF_ASM_OP1(cmpxchg16b, 0x0fc7, 1, OPC_MODRM | OPC_48, OPT_EA )
|
||||
|
||||
/* pentium pro */
|
||||
ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))
|
||||
|
||||
DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
|
||||
DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 )
|
||||
|
||||
/* mmx */
|
||||
DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */
|
||||
DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMXSSE )
|
||||
/* movd shouldn't accept REG64, but AMD64 spec uses it for 32 and 64 bit
|
||||
moves, so let's be compatible. */
|
||||
ALT(DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG64, OPT_MMXSSE ))
|
||||
ALT(DEF_ASM_OP2(movq, 0x0f6e, 0, OPC_MODRM | OPC_48, OPT_REG64, OPT_MMXSSE ))
|
||||
ALT(DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX ))
|
||||
ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMXSSE, OPT_EA | OPT_REG32 ))
|
||||
ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMXSSE, OPT_EA | OPT_REG64 ))
|
||||
ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX ))
|
||||
ALT(DEF_ASM_OP2(movq, 0x660fd6, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_SSE ))
|
||||
ALT(DEF_ASM_OP2(movq, 0xf30f7e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE ))
|
||||
ALT(DEF_ASM_OP2(movq, 0x0f7e, 0, OPC_MODRM, OPT_MMXSSE, OPT_EA | OPT_REG64 ))
|
||||
|
||||
DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
|
||||
/* sse */
|
||||
DEF_ASM_OP2(movups, 0x0f10, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
|
||||
ALT(DEF_ASM_OP2(movups, 0x0f11, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
|
||||
DEF_ASM_OP2(movaps, 0x0f28, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
|
||||
ALT(DEF_ASM_OP2(movaps, 0x0f29, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
|
||||
DEF_ASM_OP2(movhps, 0x0f16, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
|
||||
ALT(DEF_ASM_OP2(movhps, 0x0f17, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
|
||||
DEF_ASM_OP2(addps, 0x0f58, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(cvtpi2ps, 0x0f2a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_SSE )
|
||||
DEF_ASM_OP2(cvtps2pi, 0x0f2d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX )
|
||||
DEF_ASM_OP2(cvttps2pi, 0x0f2c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX )
|
||||
DEF_ASM_OP2(divps, 0x0f5e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(maxps, 0x0f5f, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(minps, 0x0f5d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(mulps, 0x0f59, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(pavgb, 0x0fe0, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(pavgw, 0x0fe3, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(pmaxsw, 0x0fee, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pmaxub, 0x0fde, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pminsw, 0x0fea, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(pminub, 0x0fda, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
DEF_ASM_OP2(rcpss, 0x0f53, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(rsqrtps, 0x0f52, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(sqrtps, 0x0f51, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
DEF_ASM_OP2(subps, 0x0f5c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
|
||||
|
||||
DEF_ASM_OP1(prefetchnta, 0x0f18, 0, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(prefetcht0, 0x0f18, 1, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(prefetcht1, 0x0f18, 2, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(prefetcht2, 0x0f18, 3, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(prefetchw, 0x0f0d, 1, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP0L(lfence, 0x0fae, 5, OPC_MODRM)
|
||||
DEF_ASM_OP0L(mfence, 0x0fae, 6, OPC_MODRM)
|
||||
DEF_ASM_OP0L(sfence, 0x0fae, 7, OPC_MODRM)
|
||||
DEF_ASM_OP1(clflush, 0x0fae, 7, OPC_MODRM, OPT_EA)
|
||||
#undef ALT
|
||||
#undef DEF_ASM_OP0
|
||||
#undef DEF_ASM_OP0L
|
||||
#undef DEF_ASM_OP1
|
||||
#undef DEF_ASM_OP2
|
||||
#undef DEF_ASM_OP3
|
||||
2258
packages/tcc/vendor/x86_64-gen.c
vendored
2258
packages/tcc/vendor/x86_64-gen.c
vendored
File diff suppressed because it is too large
Load Diff
298
packages/tcc/vendor/x86_64-link.c
vendored
298
packages/tcc/vendor/x86_64-link.c
vendored
@@ -1,298 +0,0 @@
|
||||
#ifdef TARGET_DEFS_ONLY
|
||||
|
||||
#define EM_TCC_TARGET EM_X86_64
|
||||
|
||||
/* relocation type for 32 bit data relocation */
|
||||
#define R_DATA_32 R_X86_64_32S
|
||||
#define R_DATA_PTR R_X86_64_64
|
||||
#define R_JMP_SLOT R_X86_64_JUMP_SLOT
|
||||
#define R_GLOB_DAT R_X86_64_GLOB_DAT
|
||||
#define R_COPY R_X86_64_COPY
|
||||
#define R_RELATIVE R_X86_64_RELATIVE
|
||||
|
||||
#define R_NUM R_X86_64_NUM
|
||||
|
||||
#define ELF_START_ADDR 0x400000
|
||||
#define ELF_PAGE_SIZE 0x200000
|
||||
|
||||
#define PCRELATIVE_DLLPLT 1
|
||||
#define RELOCATE_DLLPLT 1
|
||||
|
||||
#else /* !TARGET_DEFS_ONLY */
|
||||
|
||||
#include "tcc.h"
|
||||
|
||||
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
|
||||
relocations, returns -1. */
|
||||
int code_reloc (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_X86_64_32:
|
||||
case R_X86_64_32S:
|
||||
case R_X86_64_64:
|
||||
case R_X86_64_GOTPC32:
|
||||
case R_X86_64_GOTPC64:
|
||||
case R_X86_64_GOTPCREL:
|
||||
case R_X86_64_GOTPCRELX:
|
||||
case R_X86_64_REX_GOTPCRELX:
|
||||
case R_X86_64_GOTTPOFF:
|
||||
case R_X86_64_GOT32:
|
||||
case R_X86_64_GOT64:
|
||||
case R_X86_64_GLOB_DAT:
|
||||
case R_X86_64_COPY:
|
||||
case R_X86_64_RELATIVE:
|
||||
case R_X86_64_GOTOFF64:
|
||||
return 0;
|
||||
|
||||
case R_X86_64_PC32:
|
||||
case R_X86_64_PC64:
|
||||
case R_X86_64_PLT32:
|
||||
case R_X86_64_PLTOFF64:
|
||||
case R_X86_64_JUMP_SLOT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns an enumerator to describe whether and when the relocation needs a
|
||||
GOT and/or PLT entry to be created. See tcc.h for a description of the
|
||||
different values. */
|
||||
int gotplt_entry_type (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_X86_64_GLOB_DAT:
|
||||
case R_X86_64_JUMP_SLOT:
|
||||
case R_X86_64_COPY:
|
||||
case R_X86_64_RELATIVE:
|
||||
return NO_GOTPLT_ENTRY;
|
||||
|
||||
/* The following relocs wouldn't normally need GOT or PLT
|
||||
slots, but we need them for simplicity in the link
|
||||
editor part. See our caller for comments. */
|
||||
case R_X86_64_32:
|
||||
case R_X86_64_32S:
|
||||
case R_X86_64_64:
|
||||
case R_X86_64_PC32:
|
||||
case R_X86_64_PC64:
|
||||
return AUTO_GOTPLT_ENTRY;
|
||||
|
||||
case R_X86_64_GOTTPOFF:
|
||||
return BUILD_GOT_ONLY;
|
||||
|
||||
case R_X86_64_GOT32:
|
||||
case R_X86_64_GOT64:
|
||||
case R_X86_64_GOTPC32:
|
||||
case R_X86_64_GOTPC64:
|
||||
case R_X86_64_GOTOFF64:
|
||||
case R_X86_64_GOTPCREL:
|
||||
case R_X86_64_GOTPCRELX:
|
||||
case R_X86_64_REX_GOTPCRELX:
|
||||
case R_X86_64_PLT32:
|
||||
case R_X86_64_PLTOFF64:
|
||||
return ALWAYS_GOTPLT_ENTRY;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
|
||||
{
|
||||
Section *plt = s1->plt;
|
||||
uint8_t *p;
|
||||
int modrm;
|
||||
unsigned plt_offset, relofs;
|
||||
|
||||
modrm = 0x25;
|
||||
|
||||
/* empty PLT: create PLT0 entry that pushes the library identifier
|
||||
(GOT + PTR_SIZE) and jumps to ld.so resolution routine
|
||||
(GOT + 2 * PTR_SIZE) */
|
||||
if (plt->data_offset == 0) {
|
||||
p = section_ptr_add(plt, 16);
|
||||
p[0] = 0xff; /* pushl got + PTR_SIZE */
|
||||
p[1] = modrm + 0x10;
|
||||
write32le(p + 2, PTR_SIZE);
|
||||
p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */
|
||||
p[7] = modrm;
|
||||
write32le(p + 8, PTR_SIZE * 2);
|
||||
}
|
||||
plt_offset = plt->data_offset;
|
||||
|
||||
/* The PLT slot refers to the relocation entry it needs via offset.
|
||||
The reloc entry is created below, so its offset is the current
|
||||
data_offset */
|
||||
relofs = s1->got->reloc ? s1->got->reloc->data_offset : 0;
|
||||
|
||||
/* Jump to GOT entry where ld.so initially put the address of ip + 4 */
|
||||
p = section_ptr_add(plt, 16);
|
||||
p[0] = 0xff; /* jmp *(got + x) */
|
||||
p[1] = modrm;
|
||||
write32le(p + 2, got_offset);
|
||||
p[6] = 0x68; /* push $xxx */
|
||||
/* On x86-64, the relocation is referred to by _index_ */
|
||||
write32le(p + 7, relofs / sizeof (ElfW_Rel));
|
||||
p[11] = 0xe9; /* jmp plt_start */
|
||||
write32le(p + 12, -(plt->data_offset));
|
||||
return plt_offset;
|
||||
}
|
||||
|
||||
/* relocate the PLT: compute addresses and offsets in the PLT now that final
|
||||
address for PLT and GOT are known (see fill_program_header) */
|
||||
ST_FUNC void relocate_plt(TCCState *s1)
|
||||
{
|
||||
uint8_t *p, *p_end;
|
||||
|
||||
if (!s1->plt)
|
||||
return;
|
||||
|
||||
p = s1->plt->data;
|
||||
p_end = p + s1->plt->data_offset;
|
||||
|
||||
if (p < p_end) {
|
||||
int x = s1->got->sh_addr - s1->plt->sh_addr - 6;
|
||||
add32le(p + 2, x);
|
||||
add32le(p + 8, x - 6);
|
||||
p += 16;
|
||||
while (p < p_end) {
|
||||
add32le(p + 2, x + s1->plt->data - p);
|
||||
p += 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ElfW_Rel *qrel; /* ptr to next reloc entry reused */
|
||||
|
||||
void relocate_init(Section *sr)
|
||||
{
|
||||
qrel = (ElfW_Rel *) sr->data;
|
||||
}
|
||||
|
||||
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
{
|
||||
int sym_index, esym_index;
|
||||
|
||||
sym_index = ELFW(R_SYM)(rel->r_info);
|
||||
|
||||
switch (type) {
|
||||
case R_X86_64_64:
|
||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||
esym_index = s1->sym_attrs[sym_index].dyn_index;
|
||||
qrel->r_offset = rel->r_offset;
|
||||
if (esym_index) {
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64);
|
||||
qrel->r_addend = rel->r_addend;
|
||||
qrel++;
|
||||
break;
|
||||
} else {
|
||||
qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
|
||||
qrel->r_addend = read64le(ptr) + val;
|
||||
qrel++;
|
||||
}
|
||||
}
|
||||
add64le(ptr, val);
|
||||
break;
|
||||
case R_X86_64_32:
|
||||
case R_X86_64_32S:
|
||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||
/* XXX: this logic may depend on TCC's codegen
|
||||
now TCC uses R_X86_64_32 even for a 64bit pointer */
|
||||
qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
|
||||
/* Use sign extension! */
|
||||
qrel->r_addend = (int)read32le(ptr) + val;
|
||||
qrel++;
|
||||
}
|
||||
add32le(ptr, val);
|
||||
break;
|
||||
|
||||
case R_X86_64_PC32:
|
||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||
/* DLL relocation */
|
||||
esym_index = s1->sym_attrs[sym_index].dyn_index;
|
||||
if (esym_index) {
|
||||
qrel->r_offset = rel->r_offset;
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC32);
|
||||
/* Use sign extension! */
|
||||
qrel->r_addend = (int)read32le(ptr) + rel->r_addend;
|
||||
qrel++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
goto plt32pc32;
|
||||
|
||||
case R_X86_64_PLT32:
|
||||
/* fallthrough: val already holds the PLT slot address */
|
||||
|
||||
plt32pc32:
|
||||
{
|
||||
long long diff;
|
||||
diff = (long long)val - addr;
|
||||
if (diff < -2147483648LL || diff > 2147483647LL) {
|
||||
tcc_error("internal error: relocation failed");
|
||||
}
|
||||
add32le(ptr, diff);
|
||||
}
|
||||
break;
|
||||
|
||||
case R_X86_64_PLTOFF64:
|
||||
add64le(ptr, val - s1->got->sh_addr + rel->r_addend);
|
||||
break;
|
||||
|
||||
case R_X86_64_PC64:
|
||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||
/* DLL relocation */
|
||||
esym_index = s1->sym_attrs[sym_index].dyn_index;
|
||||
if (esym_index) {
|
||||
qrel->r_offset = rel->r_offset;
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC64);
|
||||
qrel->r_addend = read64le(ptr) + rel->r_addend;
|
||||
qrel++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
add64le(ptr, val - addr);
|
||||
break;
|
||||
|
||||
case R_X86_64_GLOB_DAT:
|
||||
case R_X86_64_JUMP_SLOT:
|
||||
/* They don't need addend */
|
||||
write64le(ptr, val - rel->r_addend);
|
||||
break;
|
||||
case R_X86_64_GOTPCREL:
|
||||
case R_X86_64_GOTPCRELX:
|
||||
case R_X86_64_REX_GOTPCRELX:
|
||||
add32le(ptr, s1->got->sh_addr - addr +
|
||||
s1->sym_attrs[sym_index].got_offset - 4);
|
||||
break;
|
||||
case R_X86_64_GOTPC32:
|
||||
add32le(ptr, s1->got->sh_addr - addr + rel->r_addend);
|
||||
break;
|
||||
case R_X86_64_GOTPC64:
|
||||
add64le(ptr, s1->got->sh_addr - addr + rel->r_addend);
|
||||
break;
|
||||
case R_X86_64_GOTTPOFF:
|
||||
add32le(ptr, val - s1->got->sh_addr);
|
||||
break;
|
||||
case R_X86_64_GOT32:
|
||||
/* we load the got offset */
|
||||
add32le(ptr, s1->sym_attrs[sym_index].got_offset);
|
||||
break;
|
||||
case R_X86_64_GOT64:
|
||||
/* we load the got offset */
|
||||
add64le(ptr, s1->sym_attrs[sym_index].got_offset);
|
||||
break;
|
||||
case R_X86_64_GOTOFF64:
|
||||
add64le(ptr, val - s1->got->sh_addr);
|
||||
break;
|
||||
case R_X86_64_RELATIVE:
|
||||
#ifdef TCC_TARGET_PE
|
||||
add32le(ptr, val - s1->pe_imagebase);
|
||||
#endif
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !TARGET_DEFS_ONLY */
|
||||
Reference in New Issue
Block a user