<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.friendos.dev/index.php?action=history&amp;feed=atom&amp;title=Limine-zig</id>
	<title>Limine-zig - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.friendos.dev/index.php?action=history&amp;feed=atom&amp;title=Limine-zig"/>
	<link rel="alternate" type="text/html" href="https://wiki.friendos.dev/index.php?title=Limine-zig&amp;action=history"/>
	<updated>2026-05-02T08:36:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.4</generator>
	<entry>
		<id>https://wiki.friendos.dev/index.php?title=Limine-zig&amp;diff=32&amp;oldid=prev</id>
		<title>Veloya: Added basic info on code for getting x86 limine with zig working</title>
		<link rel="alternate" type="text/html" href="https://wiki.friendos.dev/index.php?title=Limine-zig&amp;diff=32&amp;oldid=prev"/>
		<updated>2023-09-01T00:48:16Z</updated>

		<summary type="html">&lt;p&gt;Added basic info on code for getting x86 limine with zig working&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Limine is a modern boot protocol developed with the Limine bootloader, this page covers how to take advantage of that protocol in a zig-based kernel. This does not cover making an ISO, just the code required, in the future this will change, but this is it for now.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
This code should work as long as you have zig 0.11.0 installed. As of writing this it is untested, but if you do test it out, and it works, remove this sentence, if it doesn't work please message me (veloya) on the discord server with the error message.&lt;br /&gt;
&lt;br /&gt;
=== src/main.zig ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;zig&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
const limine = @import(&amp;quot;./limine.zig&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
pub export var FRAMEBUF: limine.FramebufferRequest = .{};&lt;br /&gt;
&lt;br /&gt;
export fn _start() void {&lt;br /&gt;
    // Get an array of framebuffer pointers&lt;br /&gt;
    const framebuffers = FRAMEBUF.response.?.framebuffers();&lt;br /&gt;
&lt;br /&gt;
    // Get the first framebuffer provided&lt;br /&gt;
    const framebuffer = framebuffers[0];&lt;br /&gt;
&lt;br /&gt;
    // Height is in pixels, convert it to bytes&lt;br /&gt;
    const byte_height = framebuffer.height * 4;&lt;br /&gt;
&lt;br /&gt;
    // Get total byte size by multiplying the height by the stride (or pitch)&lt;br /&gt;
    const size = byte_height * framebuffer.pitch;&lt;br /&gt;
&lt;br /&gt;
    // Fill the framebuffer with white&lt;br /&gt;
    for (0..size) |index| {&lt;br /&gt;
        framebuffer.address[index] = 0xff;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    while (true) {}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== src/limine.zig ===&lt;br /&gt;
The limine.zig file can be found [https://github.com/limine-bootloader/limine-zig/tree/trunk here]&lt;br /&gt;
&lt;br /&gt;
=== config/linker.ld ===&lt;br /&gt;
TODO: Write a better linker script&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
ENTRY(_start)&lt;br /&gt;
&lt;br /&gt;
SECTIONS&lt;br /&gt;
{&lt;br /&gt;
    . = 0xffffffff80000000;&lt;br /&gt;
&lt;br /&gt;
    .text : ALIGN(4096) { *(.text .text.*) }&lt;br /&gt;
    .rodata : ALIGN(4096) { *(.rodata .rodata.*) }&lt;br /&gt;
    .data : ALIGN(4096) { *(.data .data.*) }&lt;br /&gt;
    .dynamic : ALIGN(4096) { *(.dynamic) }&lt;br /&gt;
    .bss : ALIGN(4096) {&lt;br /&gt;
        *(.bss .bss.*)&lt;br /&gt;
        *(COMMON)&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== config/limine.cfg ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cfg&amp;quot;&amp;gt;&lt;br /&gt;
boot &amp;quot;test-kern&amp;quot; {&lt;br /&gt;
    protocol = &amp;quot;limine&amp;quot;;&lt;br /&gt;
    kernel-path = &amp;quot;boot:///boot/test-kern&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== build.zig ===&lt;br /&gt;
A build.zig file is required to properly customize the target.&amp;lt;syntaxhighlight lang=&amp;quot;zig&amp;quot;&amp;gt;&lt;br /&gt;
const std = @import(&amp;quot;std&amp;quot;);&lt;br /&gt;
const Target = @import(&amp;quot;std&amp;quot;).Target;&lt;br /&gt;
const CrossTarget = @import(&amp;quot;std&amp;quot;).zig.CrossTarget;&lt;br /&gt;
const Feature = @import(&amp;quot;std&amp;quot;).Target.Cpu.Feature;&lt;br /&gt;
&lt;br /&gt;
pub fn build(b: *std.Build) !void {&lt;br /&gt;
    var stdout = std.io.getStdOut();&lt;br /&gt;
&lt;br /&gt;
    const target = CrossTarget{&lt;br /&gt;
        .cpu_arch = Target.Cpu.Arch.x86_64,&lt;br /&gt;
        .os_tag = Target.Os.Tag.freestanding,&lt;br /&gt;
        .abi = Target.Abi.none,&lt;br /&gt;
    };&lt;br /&gt;
    const optimize = b.standardOptimizeOption(.{});&lt;br /&gt;
&lt;br /&gt;
    const kernel = b.addExecutable(.{&lt;br /&gt;
        .name = &amp;quot;test-kern&amp;quot;,&lt;br /&gt;
        .root_source_file = .{ .path = &amp;quot;src/main.zig&amp;quot; },&lt;br /&gt;
        .target = target,&lt;br /&gt;
        .optimize = optimize,&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
    kernel.setLinkerScriptPath(.{ .path = &amp;quot;config/linker.ld&amp;quot; });&lt;br /&gt;
    kernel.code_model = .medium;&lt;br /&gt;
    kernel.rdynamic = true;&lt;br /&gt;
    kernel.pie = true;&lt;br /&gt;
&lt;br /&gt;
    _ = try stdout.write(&amp;quot;Building kernel\n&amp;quot;);&lt;br /&gt;
    b.installArtifact(kernel);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veloya</name></author>
	</entry>
</feed>