-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating libk, working compile time kprintf, adding toString functions
- Loading branch information
Showing
14 changed files
with
267 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const builtin = @import("builtin"); | ||
const is_test = builtin.is_test; | ||
|
||
comptime | ||
{ | ||
if(!is_test) | ||
{ | ||
switch(builtin.cpu.arch) | ||
{ | ||
.x86 => _ = @import("arch/x86/boot.zig"), | ||
else => unreachable, | ||
} | ||
} | ||
} | ||
|
||
const drivers = @import("drivers"); | ||
const libk = @import("libk"); | ||
|
||
pub const logs = @import("log.zig"); | ||
pub const kpanic = @import("panic.zig").kpanic; | ||
|
||
pub const arch = if(!is_test) switch(builtin.cpu.arch) | ||
{ | ||
.x86 => @import("arch/x86/arch.zig"), | ||
else => unreachable, | ||
}; | ||
|
||
export fn kmain() void | ||
{ | ||
@setCold(true); | ||
arch.init(); | ||
drivers.initDrivers(); | ||
logs.klogln("Welcome to RatiOS !"); | ||
const caca: i32 = 1048; | ||
const caca2: i32 = 1048; | ||
const caca3: i32 = 1048; | ||
libk.io.kprintf("caca ;{};, ;{};, ;{};\n", .{ &caca, &caca2, &caca3 }); | ||
drivers.shutdownDrivers(); | ||
} |
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 was deleted.
Oops, something went wrong.
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,3 @@ | ||
pub const memory = @import("memory/memory.zig"); | ||
pub const io = @import("io/io.zig"); | ||
pub const strings = @import("strings/strings.zig"); |
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,3 @@ | ||
pub const kputs = @import("out.zig").kputs; | ||
pub const kputNb = @import("out.zig").kputNb; | ||
pub const kprintf = @import("out.zig").kprintf; |
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,126 @@ | ||
const vga = @import("drivers").vga; | ||
const string = @import("../strings/strings.zig"); | ||
|
||
pub fn kputs(message: []const u8) void | ||
{ | ||
vga.putString(message); | ||
} | ||
|
||
const ArgTypes = enum | ||
{ | ||
Int, | ||
Float, | ||
Char, | ||
String, | ||
Pointer, | ||
Null | ||
}; | ||
|
||
pub fn kprintf(comptime fmt: []const u8, args: anytype) void | ||
{ | ||
comptime var arg_idx: usize = 0; | ||
comptime var arg_insert: bool = false; | ||
comptime var arg_type: ArgTypes = .Null; | ||
|
||
inline for(fmt) |c| | ||
{ | ||
if(c == '{') | ||
{ | ||
arg_insert = true; | ||
continue; | ||
} | ||
|
||
if(arg_insert) | ||
{ | ||
if(c == '}') | ||
{ | ||
if(arg_type == .Null) | ||
{ | ||
if(@TypeOf(args[arg_idx]) == comptime_int) | ||
{ | ||
if(args[arg_idx] > 0 and args[arg_idx] < 256) | ||
vga.putChar(args[arg_idx]) | ||
else | ||
putNb(args[arg_idx]); | ||
} | ||
else if(@typeInfo(@TypeOf(args[arg_idx])) == .Array and @typeInfo(@TypeOf(args[arg_idx])).Array.child == u8) | ||
kputs(args[arg_idx]) | ||
else if(@typeInfo(@TypeOf(args[arg_idx])) == .Pointer) | ||
{ | ||
const T = @typeInfo(@TypeOf(args[arg_idx])).Pointer; | ||
if(@typeInfo(T.child) == .Array and @typeInfo(T.child).Array.child == u8) | ||
kputs(args[arg_idx]) | ||
else | ||
{ | ||
kputs("0x"); | ||
kputs(string.toStringBase(@intFromPtr(args[arg_idx]), 16)); | ||
} | ||
} | ||
else switch(@TypeOf(args[arg_idx])) | ||
{ | ||
i8, u8, => vga.putChar(args[arg_idx]), | ||
i16, u16, i32, u32, i64, u64, isize, usize => putNb(args[arg_idx]), | ||
f16, f32, f64, comptime_float => {}, | ||
else => @compileError("could not manage auto detected type : " ++ @typeName(@TypeOf(args[arg_idx])) ++ "; please add type identifier between brackets"), | ||
} | ||
} | ||
switch(arg_type) | ||
{ | ||
.Char => vga.putChar(args[arg_idx]), | ||
.Int => putNb(args[arg_idx]), | ||
.Float => {}, | ||
.String => kputs(args[arg_idx]), | ||
.Pointer => { kputs("0x"); kputs(string.toStringBase(@intFromPtr(args[arg_idx]), 16)); }, | ||
else => {}, | ||
} | ||
|
||
arg_insert = false; | ||
arg_idx += 1; | ||
arg_type = .Null; | ||
} | ||
else if(arg_type != .Null) | ||
@compileError("too much type identifiers between the brackets") | ||
else | ||
{ | ||
switch(c) | ||
{ | ||
'c' => arg_type = .Char, | ||
'i' => arg_type = .Int, | ||
'f' => arg_type = .Float, | ||
'p' => arg_type = .Pointer, | ||
's' => arg_type = .String, | ||
|
||
else => @compileError("invalid type identifier between the brackets"), | ||
} | ||
} | ||
} | ||
else | ||
vga.putChar(c); | ||
} | ||
|
||
comptime | ||
{ | ||
if(args.len != arg_idx) | ||
@compileError("unused arguments"); | ||
} | ||
} | ||
|
||
pub fn putNb(nbr: i64) void | ||
{ | ||
if(nbr <= -2147483648) | ||
vga.putString("-2147483648") | ||
else if(nbr >= 2147483647) | ||
vga.putString("2147483647") | ||
else if(nbr < 0) | ||
{ | ||
vga.putChar('-'); | ||
putNb(-nbr); | ||
} | ||
else if(nbr >= 10) | ||
{ | ||
putNb(@divFloor(nbr, 10)); | ||
vga.putChar(@intCast(@mod(nbr, 10) + @as(u8, 48))); | ||
} | ||
else | ||
vga.putChar(@intCast(nbr + 48)); | ||
} |
File renamed without changes.
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,4 @@ | ||
pub const toString = @import("to_string.zig").toString; | ||
pub const toStringBase = @import("to_string.zig").toStringBase; | ||
pub const toStringBuffer = @import("to_string.zig").toStringBuffer; | ||
pub const toStringBufferBase = @import("to_string.zig").toStringBufferBase; |
Oops, something went wrong.