Skip to content

Commit

Permalink
Remove implicit pass by ref & improve fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratakor committed Nov 5, 2024
1 parent bb8eb04 commit 266dd2c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 40 deletions.
58 changes: 28 additions & 30 deletions kernel/TTY.zig
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ const ansi_bright_colors = [8]Color{
Color.bright_grey,
};

// zig fmt: off
const col256 = [_]u32{
0x000000, 0x00005f, 0x000087, 0x0000af, 0x0000d7, 0x0000ff, 0x005f00, 0x005f5f,
0x005f87, 0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f, 0x008787, 0x0087af,
Expand Down Expand Up @@ -260,41 +259,40 @@ const col256 = [_]u32{
0xffd7d7, 0xffd7ff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf, 0xffffd7, 0xffffff,
0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e,
0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee
0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee,
};

const control_code = std.ascii.control_code;
const esc = control_code.esc;
const bs = control_code.bs;

const convtab_nomod = [_]u8{
0, esc, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', bs, '\t',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', 's',
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v',
'b', 'n', 'm', ',', '.', '/', 0, 0, 0, ' ',
0, esc, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', bs, '\t',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', 's',
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v',
'b', 'n', 'm', ',', '.', '/', 0, 0, 0, ' ',
};

const convtab_capslock = [_]u8{
0, esc, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', bs, '\t',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', '\n', 0, 'A', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`', 0, '\\', 'Z', 'X', 'C', 'V',
'B', 'N', 'M', ',', '.', '/', 0, 0, 0, ' ',
0, esc, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', bs, '\t',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', '\n', 0, 'A', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`', 0, '\\', 'Z', 'X', 'C', 'V',
'B', 'N', 'M', ',', '.', '/', 0, 0, 0, ' ',
};

const convtab_shift = [_]u8{
0, esc, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', bs, '\t',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0, 'A', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V',
'B', 'N', 'M', '<', '>', '?', 0, 0, 0, ' ',
0, esc, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', bs, '\t',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0, 'A', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V',
'B', 'N', 'M', '<', '>', '?', 0, 0, 0, ' ',
};

const convtab_shift_capslock = [_]u8{
0, esc, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', bs, '\t',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '\n', 0, 'a', 's',
'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"', '~', 0, '|', 'z', 'x', 'c', 'v',
'b', 'n', 'm', '<', '>', '?', 0, 0, 0, ' '
0, esc, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', bs, '\t',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '\n', 0, 'a', 's',
'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"', '~', 0, '|', 'z', 'x', 'c', 'v',
'b', 'n', 'm', '<', '>', '?', 0, 0, 0, ' ',
};
// zig fmt: on

pub fn init(
allocator: std.mem.Allocator,
Expand Down Expand Up @@ -420,7 +418,7 @@ fn plotChar(self: *TTY, c: *const Char, _x: usize, _y: usize) void {
}
}

fn plotCharFast(self: TTY, old: *const Char, c: *const Char, _x: usize, _y: usize) void {
fn plotCharFast(self: *const TTY, old: *const Char, c: *const Char, _x: usize, _y: usize) void {
if (_x >= self.cols or _y >= self.rows) return;

const x = self.offset_x + _x * font_width;
Expand Down Expand Up @@ -1032,12 +1030,12 @@ fn controlSequenceParse(self: *TTY, c: u8) void {
esc_values[0] = @intCast(y);
}
var dest_y = y - esc_values[0];
// zig fmt: off
if ((self.scroll_top_margin >= dest_y and self.scroll_top_margin <= y) or
(self.scroll_bottom_margin >= dest_y and self.scroll_bottom_margin <= y)) {
if (dest_y < self.scroll_top_margin) {
dest_y = self.scroll_top_margin;
}
(self.scroll_bottom_margin >= dest_y and self.scroll_bottom_margin <= y))
{
if (dest_y < self.scroll_top_margin) {
dest_y = self.scroll_top_margin;
}
}
self.setCursorPos(x, dest_y);
},
Expand All @@ -1047,12 +1045,12 @@ fn controlSequenceParse(self: *TTY, c: u8) void {
}
var dest_y = y + esc_values[0];
if ((self.scroll_top_margin >= y and self.scroll_top_margin <= dest_y) or
(self.scroll_bottom_margin >= y and self.scroll_bottom_margin <= dest_y)) {
if (dest_y >= self.scroll_bottom_margin) {
dest_y = self.scroll_bottom_margin - 1;
}
(self.scroll_bottom_margin >= y and self.scroll_bottom_margin <= dest_y))
{
if (dest_y >= self.scroll_bottom_margin) {
dest_y = self.scroll_bottom_margin - 1;
}
}
// zig fmt: on
self.setCursorPos(x, dest_y);
},
'a', 'C' => {
Expand Down
2 changes: 1 addition & 1 deletion kernel/acpi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const RSDP = extern struct {
extended_checksum: u8 align(1),
reserved: [3]u8 align(1),

inline fn useXSDT(self: RSDP) bool {
inline fn useXSDT(self: *const RSDP) bool {
return self.revision >= 2 and self.xsdt_addr != 0;
}
};
Expand Down
7 changes: 1 addition & 6 deletions kernel/arch/x86_64/cpu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub const CpuLocal = extern struct {
}
};

const PAT = packed struct {
const PAT = packed struct(u64) {
// zig fmt: off
pat0: Flags, reserved0: u5,
pat1: Flags, reserved1: u5,
Expand All @@ -123,11 +123,6 @@ const PAT = packed struct {
write_back = 6,
uncached = 7,
};

comptime {
std.debug.assert(@sizeOf(PAT) == @sizeOf(u64));
std.debug.assert(@bitSizeOf(PAT) == @bitSizeOf(u64));
}
};

/// https://en.wikipedia.org/wiki/CPUID#EAX=1:_Processor_Info_and_Feature_Bits
Expand Down
6 changes: 3 additions & 3 deletions kernel/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn log(
.info => "\x1b[32minfo\x1b[m",
.debug => "\x1b[36mdebug\x1b[m",
};
const scope_prefix = (if (scope != .default) "@" ++ @tagName(scope) else "") ++ ": ";
const scope_prefix = if (scope == .default) ": " else "@" ++ @tagName(scope) ++ ": ";
const fmt = level_txt ++ scope_prefix ++ format ++ "\n";

log_lock.lock();
Expand Down Expand Up @@ -141,7 +141,7 @@ fn printSymbolInfo(writer: anytype, address: u64) !void {
symbol.compile_unit_name,
});

if (printLineFromFile(writer, sl)) {
if (printLineFromFile(writer, &sl)) {
if (sl.column > 0) {
try writer.writeByteNTimes(' ', sl.column - 1);
try writer.writeAll("\x1b[32m^\x1b[m");
Expand Down Expand Up @@ -193,7 +193,7 @@ const source_files = [_][]const u8{
};

// TODO: get source files from filesystem instead + zig std lib files
fn printLineFromFile(writer: anytype, source_location: std.debug.SourceLocation) !void {
fn printLineFromFile(writer: anytype, source_location: *const std.debug.SourceLocation) !void {
const content = inline for (source_files) |src_path| {
if (std.mem.endsWith(u8, source_location.file_name, src_path)) {
break @embedFile(src_path);
Expand Down
1 change: 1 addition & 0 deletions kernel/mm/vmm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub const PTE = packed struct(u64) {
protection_key: u4,
execute_disable: bool,

// TODO: remove and replace usage with named decl
const PRESENT: u64 = 1 << 0;
const WRITABLE: u64 = 1 << 1;
const USER: u64 = 1 << 2;
Expand Down

0 comments on commit 266dd2c

Please sign in to comment.