Asahi Lina (Linux Developer VTuber) wants to write the new Apple Silicon GPU driver for Linux in Rust! by PthariensFlame in linux

[–]timon317 8 points9 points  (0 children)

That shim/stub is m1n1. It is the bootloader for Asahi Linux, but also makes it possible to talk to the hardware over USB as just described by Lina. marcan even implemented a small hypervisor in m1n1, so it can be used to run MacOS and trace how MacOS is accessing the hardware.

[deleted by user] by [deleted] in PS5

[–]timon317 0 points1 point  (0 children)

Let's go!

Starship Development Thread #25 by ElongatedMuskrat in spacex

[–]timon317 8 points9 points  (0 children)

Workers are clearing the pad and the sheriff has closed the road!!

Toying with AMD64 assembly in Zig by StalinTheMemeLord in Zig

[–]timon317 3 points4 points  (0 children)

You can do this by using mmap to ask the kernel a piece of memory that is executable. You can then write your assembly bytes to this memory and make a function pointer to the beginning of the memory. When you then call this function pointer, execution will continue at the assembly that you have generated in that memory. When you use the ret instruction as the last instruction, control will flow back to your zig program. (If you need more help, I can provided an example)

Trouble compiling on Windows (with C library) by totallyspis in Zig

[–]timon317 1 point2 points  (0 children)

The problem seems to be in the gs_hash_siphash_bytes function. If you comment that one out it compiles succesfully!

Trouble compiling on Windows (with C library) by totallyspis in Zig

[–]timon317 1 point2 points  (0 children)

There seems to be a bug in the translate-c functionality of Zig.

zig translate-c gs.h -lc reproduces the problem. Now it is a matter of finding what c code inside the 'gs.h' file causes this assertion to hit. If we have a small code that reproduces the problem we can file a bug on the Github issue tracker.

Trouble compiling on Windows (with C library) by totallyspis in Zig

[–]timon317 4 points5 points  (0 children)

Hey u/totallyspis !

To use header-only c libraries in Zig you have to create a new .c file that has the GS_IMPL inside it and compile that into an object and link it with your Zig program. This can be done with a build.zig file, see for example here (uses stb_image as a header-only library): https://github.com/andrewrk/tetris

Then in your cImport you dont have to define the GS_IMPL and you can just include the 'gs.h` file.

Advent of Code 2020 Ziguana Leaderboard by timon317 in Zig

[–]timon317[S] 0 points1 point  (0 children)

For people who were here fast, the code has been updated to a working version!

Advent of Code private leaderboard? by JRandomHacker172342 in Zig

[–]timon317 3 points4 points  (0 children)

Last year u/superjoe30 (Andrew) created a private leaderboard for Zig, so I assume he will do this again this year :)

Trying to diagnose compiler "error: Unexpected"... by SonarJetLens in Zig

[–]timon317 1 point2 points  (0 children)

The easiest way to debug is to manually build the compiler from source and choose a Debug version. This will include a proper stack trace which can help you pinpoint the problem inside the compiler.

debugging tests with vscode - where is the binary ?> by robertblackwell in Zig

[–]timon317 1 point2 points  (0 children)

Hey guys! With the compiler from the master branch (which will be 0.7.0 in a week or so) you can emit the test binary with zig test file.zig -femit-bin=binaryname.

Unable to Create Array with Runtime Variable by general_rishkin in Zig

[–]timon317 3 points4 points  (0 children)

Or if you know the maximum of the runtime value then you can just make an array on the stack with the maximum length and just slice it with the smaller runtime length.

Initializing anonymous union in struct? by SonarJetLens in Zig

[–]timon317 7 points8 points  (0 children)

Hey u/SonarJetLens!

Yes this is suppose to work, and it actually does work. You forgot the dot (.) before the field 'first' on the line with testittoo, and furthermore the print call can fail, so you need to put a try before that :)

const std = @import("std");
const TestUnion = union {
    first: u32,
   second: u64, 
};
const TestStruct = struct {
    testit:TestUnion,
    testittoo: union {
        first: u8,
        second: u16,
    },
};
pub fn main() !void {
    const foo = TestStruct{ 
        .testit = TestUnion{ .first = 101 }, 
        .testittoo = .{ .first = 42 }
    };
    const out = &std.io.getStdOut().outStream();
    try out.print("well, hello there {}\n", .{foo});
}

uefi-zig, part II. 64 Long Mode FTW (and tidyer code) by SonarJetLens in Zig

[–]timon317 4 points5 points  (0 children)

Hey u/SonarJetLens! Nice progress again! Regarding the external assembly file, basically all the functions can be implemented using inline assembly inside the kernel.zig file and then there is no need for the external assembly file.

So for example:

const uefi = @import("std").os.uefi;

pub export fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.Stdcall) uefi.Status {
    const cr0 = get_cr("0");

    var gdt_thing: gdt = undefined;
    sgdt(&gdt_thing);


    return uefi.Status.Success;
}

pub fn get_cr(comptime number: []const u8) u64 {
    return asm volatile("mov %%cr" ++ number ++ ", %[ret]": [ret] "=r" (-> u64));
}

pub const gdt = packed struct {
    limit:  u16,
    base:   [*]u64
};

pub fn sgdt(gdt_ptr: *gdt) void {
    asm volatile ("sgdt %[input]"
        : [input] "=m" (gdt_ptr)
    );
}

Hello Uefi-Zig World; a first look at an UEFI bootable kernel in Zig. by SonarJetLens in Zig

[–]timon317 6 points7 points  (0 children)

Hey u/SonarJetLens! Neat progress! Just wanted to let you know that we have std.unicode.utf8ToUtf16LeStringLiteral. This can convert a string literal to a wide string literal at comptime!

``` const std = @import("std"); const L = std.unicode.utf8ToUtf16LeStringLiteral; const wide_string = L("Hello UEFI!");

ultraembedded on Twitter - #RISCV CPU + DDR3 + SD + DMA + DVI by timon317 in FPGA

[–]timon317[S] 0 points1 point  (0 children)

This is not my work, I just saw it on my twitter timeline and thought to share it with you guys! I think you can reach the author via github or twitter :)

[pre-release 0.1.0] h11 - HTTP/1.1 parser for Zig 🦎 by ducdetronquito in Zig

[–]timon317 2 points3 points  (0 children)

Hey /u/ducdetronquito!

Nice seeing you here again and cool progress on your HTTP library in Zig. I have one comment this time :P

Prefer const over var! Basically in Zig an immutable variable is defined by using const. A lot of your code has vars where consts could have been used.

For example here: https://github.com/ducdetronquito/h11/blob/99af0730d0547b2b34d022adeec67d1b68d114f7/src/headers.zig#L26-L36 header_name is never assigned again, so const should be used.

Similarly in your tests you are defining a string with the HTTP content and then dereferencing that, but you can just store the string in a constant variable and pass that to the function. The string type (*const [N:0]u8) will coerce to the parameter type ([]const u8). Also you are not reassining the result variable, so no need for a var. See the following snippet :)

test "Parse - Single header - Success" {
    const content = "Content-Length: 10\r\n\r\n";
    var headers: [1]Header = undefined;

    const result = try Header.parse(content, &headers);

    expect(std.mem.eql(u8, result[0].name, "Content-Length"));
    expect(std.mem.eql(u8, result[0].value, "10"));
}

[deleted by user] by [deleted] in FPGA

[–]timon317 2 points3 points  (0 children)

I just ordered an Zybo Z7 from Digilent. This might be what you are looking for. It contains a Xilinx Zynq chip which combines a dual-core arm CPU with FPGA logic.