-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10ea022
commit d096792
Showing
15 changed files
with
318 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -521,4 +521,4 @@ pub const FileSystemVolumeLabel = extern struct { | |
|
||
test { | ||
std.testing.refAllDecls(@This()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const uefi = @import("std").os.uefi; | ||
const Status = uefi.Status; | ||
const Handle = uefi.bits.Handle; | ||
const Guid = uefi.bits.Guid; | ||
const cc = uefi.bits.cc; | ||
|
||
pub const Shell = extern struct { | ||
execute: *const fn (parent_img_hndl: Handle, cmdline: ?[*:0]const u16, env: ?[*:null]const ?[*:0]const u16, status: *Status) callconv(cc) Status, | ||
getEnv: *const fn (name: ?[*:0]const u16) callconv(cc) ?[*:0]const u16, | ||
setEnv: *const fn (name: [*:0]const u16, value: [*:0]const u16, voltlie: bool) callconv(cc) Status, | ||
getAlias: *const fn (alias: [*:0]const u16, voltlie: *bool) callconv(cc) ?[*:0]const u16, | ||
setAlias: *const fn (cmd: [*:0]const u16, alias: [*:0]const u16, replace: bool, voltlie: bool) callconv(cc) Status, | ||
getHelpText: *const fn (cmd: [*:0]const u16, sections: ?[*:0]const u16, helpText: *[*:0]u16) callconv(cc) Status, | ||
getDevicePathFromMap: *const fn (mapping: [*:0]const u16) callconv(cc) ?*uefi.protocol.DevicePath, | ||
getMapFromDevicePath: *const fn (devicePath: **const uefi.protocol.DevicePath) callconv(cc) ?[*:0]const u16, | ||
getDevicePathFromFilePath: *const fn (path: [*:0]const u16) callconv(cc) *uefi.protocol.DevicePath, | ||
getFilePathFromDevicePath: *const fn (devicePath: *uefi.protocol.DevicePath) callconv(cc) [*:0]const u16, | ||
setMap: *const fn (devicePath: *uefi.protocol.DevicePath, mapping: [*:0]const u16) callconv(cc) Status, | ||
getCurDir: *const fn (fsmap: ?[*:0]const u16) callconv(cc) ?[*:0]const u16, | ||
setCurDir: *const fn (fs: ?[*:0]const u16, dir: [*:0]const u16) callconv(cc) Status, | ||
openFileList: *const fn (path: [*:0]const u16, openMode: u64, fileList: **FileInfo) callconv(cc) Status, | ||
freeFileList: *const fn (fileList: **FileInfo) callconv(cc) Status, | ||
removeDupInFileList: *const fn (fileList: **FileInfo) callconv(cc) Status, | ||
batchIsActive: *const fn () callconv(cc) bool, | ||
isRootShell: *const fn () callconv(cc) bool, | ||
enablePageBreak: *const fn () callconv(cc) void, | ||
disablePageBreak: *const fn () callconv(cc) void, | ||
getPageBreak: *const fn () callconv(cc) bool, | ||
getDeviceName: *const fn (handle: Handle, flags: u32, lang: [*:0]const u8, bestDeviceName: *?[*:0]u16) callconv(cc) Status, | ||
getFileInfo: *const fn (handle: FileHandle) callconv(cc) ?*uefi.bits.FileInfo, | ||
setFileInfo: *const fn (handle: FileHandle, info: *const uefi.bits.FileInfo) callconv(cc) Status, | ||
openFileByName: *const fn (filename: [*:0]const u16, handle: *FileHandle, mode: u64) callconv(cc) Status, | ||
closeFile: *const fn (handle: FileHandle) callconv(cc) Status, | ||
createFile: *const fn (filename: [*:0]const u16, attribs: u64, handle: *FileHandle) callconv(cc) Status, | ||
readFile: *const fn (handle: FileHandle, size: *usize, buff: [*]u8) callconv(cc) Status, | ||
writeFile: *const fn (handle: FileHandle, size: *usize, buff: [*]const u8) callconv(cc) Status, | ||
deleteFile: *const fn (handle: FileHandle) callconv(cc) Status, | ||
deleteFileByName: *const fn (filename: [*:0]const u16) callconv(cc) Status, | ||
getFilePosition: *const fn (handle: FileHandle, pos: *u64) callconv(cc) Status, | ||
setFilePosition: *const fn (handle: FileHandle, pos: u64) callconv(cc) Status, | ||
flushFile: *const fn (handle: FileHandle) callconv(cc) Status, | ||
findFiles: *const fn (pattern: [*:0]const u16, fileList: *?*FileInfo) callconv(cc) Status, | ||
findFilesInDir: *const fn (handle: FileHandle, fileList: *?*FileInfo) callconv(cc) Status, | ||
getFileSize: *const fn (handle: FileHandle, size: *u64) callconv(cc) Status, | ||
openRoot: *const fn (devicePath: *uefi.protocol.DevicePath, handle: *FileHandle) callconv(cc) Status, | ||
openRootByHandle: *const fn (deviceHandle: *Handle, fileHandle: *FileHandle) callconv(cc) Status, | ||
executionBreak: uefi.bits.Event, | ||
majorVersion: u32, | ||
minorVersion: u32, | ||
|
||
pub const FileHandle = *opaque {}; | ||
|
||
pub const FileInfo = struct { | ||
link: uefi.ListEntry, | ||
status: Status, | ||
fullname: [*:0]const u16, | ||
filename: [*:0]const u16, | ||
handle: FileHandle, | ||
info: *uefi.bits.FileInfo, | ||
}; | ||
|
||
pub const guid align(8) = Guid{ | ||
.time_low = 0x6302d008, | ||
.time_mid = 0x7f9b, | ||
.time_high_and_version = 0x4f30, | ||
.clock_seq_high_and_reserved = 0x87, | ||
.clock_seq_low = 0xac, | ||
.node = [_]u8{ 0x60, 0xc9, 0xfe, 0xf5, 0xda, 0x4e }, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
const builtin = @import("builtin"); | ||
const std = @import("../../std.zig"); | ||
|
||
pub const REG = switch (builtin.cpu.arch) { | ||
.x86_64 => struct { | ||
pub const RAX = 0; | ||
pub const RBX = 1; | ||
pub const RCX = 2; | ||
pub const RDX = 3; | ||
pub const RSI = 4; | ||
pub const RDI = 5; | ||
pub const RBP = 6; | ||
pub const RSP = 7; | ||
pub const R8 = 8; | ||
pub const R9 = 9; | ||
pub const R10 = 10; | ||
pub const R11 = 11; | ||
pub const R12 = 12; | ||
pub const R13 = 13; | ||
pub const R14 = 14; | ||
pub const R15 = 15; | ||
pub const RIP = 16; | ||
pub const EFL = 17; | ||
}, | ||
else => @compileError("arch not supported"), | ||
}; | ||
|
||
pub const fpregset = struct { | ||
fcw: u16, | ||
fsw: u16, | ||
ftw: u8, | ||
reserved1: u8, | ||
fop: u16, | ||
fip: u64, | ||
fdp: u64, | ||
mxcsr: u32, | ||
mxcsr_mask: u32, | ||
st: [8]u128, | ||
xmm: [16]u128, | ||
reserved2: [96]u8, | ||
}; | ||
|
||
pub const mcontext_t = struct { | ||
gregs: [18]usize, | ||
fpregs: fpregset, | ||
}; | ||
|
||
pub const ucontext_t = struct { | ||
mcontext: mcontext_t, | ||
}; | ||
|
||
fn gpRegisterOffset(comptime reg_index: comptime_int) usize { | ||
return @offsetOf(ucontext_t, "mcontext") + @offsetOf(mcontext_t, "gregs") + @sizeOf(usize) * reg_index; | ||
} | ||
|
||
pub inline fn getcontext(context: *ucontext_t) usize { | ||
switch (builtin.cpu.arch) { | ||
.x86_64 => { | ||
asm volatile ( | ||
\\ movq %%r8, %[r8_offset:c](%[context]) | ||
\\ movq %%r9, %[r9_offset:c](%[context]) | ||
\\ movq %%r10, %[r10_offset:c](%[context]) | ||
\\ movq %%r11, %[r11_offset:c](%[context]) | ||
\\ movq %%r12, %[r12_offset:c](%[context]) | ||
\\ movq %%r13, %[r13_offset:c](%[context]) | ||
\\ movq %%r14, %[r14_offset:c](%[context]) | ||
\\ movq %%r15, %[r15_offset:c](%[context]) | ||
\\ movq %%rdi, %[rdi_offset:c](%[context]) | ||
\\ movq %%rsi, %[rsi_offset:c](%[context]) | ||
\\ movq %%rbx, %[rbx_offset:c](%[context]) | ||
\\ movq %%rdx, %[rdx_offset:c](%[context]) | ||
\\ movq %%rax, %[rax_offset:c](%[context]) | ||
\\ movq %%rcx, %[rcx_offset:c](%[context]) | ||
\\ movq %%rbp, %[rbp_offset:c](%[context]) | ||
\\ movq %%rsp, %[rsp_offset:c](%[context]) | ||
\\ leaq (%%rip), %%rcx | ||
\\ movq %%rcx, %[rip_offset:c](%[context]) | ||
\\ pushfq | ||
\\ popq %[efl_offset:c](%[context]) | ||
: | ||
: [context] "{rdi}" (context), | ||
[r8_offset] "i" (comptime gpRegisterOffset(REG.R8)), | ||
[r9_offset] "i" (comptime gpRegisterOffset(REG.R9)), | ||
[r10_offset] "i" (comptime gpRegisterOffset(REG.R10)), | ||
[r11_offset] "i" (comptime gpRegisterOffset(REG.R11)), | ||
[r12_offset] "i" (comptime gpRegisterOffset(REG.R12)), | ||
[r13_offset] "i" (comptime gpRegisterOffset(REG.R13)), | ||
[r14_offset] "i" (comptime gpRegisterOffset(REG.R14)), | ||
[r15_offset] "i" (comptime gpRegisterOffset(REG.R15)), | ||
[rax_offset] "i" (comptime gpRegisterOffset(REG.RAX)), | ||
[rbx_offset] "i" (comptime gpRegisterOffset(REG.RBX)), | ||
[rcx_offset] "i" (comptime gpRegisterOffset(REG.RCX)), | ||
[rdx_offset] "i" (comptime gpRegisterOffset(REG.RDX)), | ||
[rsi_offset] "i" (comptime gpRegisterOffset(REG.RSI)), | ||
[rdi_offset] "i" (comptime gpRegisterOffset(REG.RDI)), | ||
[rsp_offset] "i" (comptime gpRegisterOffset(REG.RSP)), | ||
[rbp_offset] "i" (comptime gpRegisterOffset(REG.RBP)), | ||
[rip_offset] "i" (comptime gpRegisterOffset(REG.RIP)), | ||
[efl_offset] "i" (comptime gpRegisterOffset(REG.EFL)), | ||
: "cc", "memory", "rcx" | ||
); | ||
}, | ||
else => {}, | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.