add basic and highly inaccurate time support
This commit is contained in:
parent
8b4bd0610b
commit
7398da9662
|
|
@ -13,6 +13,7 @@ void kmain() {
|
|||
}
|
||||
printf("Kernel initialized! Platform: %s\n", arch);
|
||||
printf("Bootloader type: %s (%s %s)\n", boot_info.boot_protocol, boot_info.bootloader_name, boot_info.bootloader_ver);
|
||||
setEpoch(boot_info.epoch);
|
||||
printf("System time: %d\n", boot_info.epoch);
|
||||
printf("Usable memory: %h (at %x)\n", boot_info.usable.len, boot_info.usable.start);
|
||||
printf("Cmdline: %s\n", boot_info.cmdline);
|
||||
|
|
@ -23,8 +24,6 @@ void kmain() {
|
|||
// memcpy(PRINTBUF, TESTBUF, 32);
|
||||
// puts(PRINTBUF);
|
||||
|
||||
kalloc_init(boot_info.usable.start, boot_info.usable.len);
|
||||
|
||||
vga_setcolor(VGA_DARK_GRAY);
|
||||
vga_write_elsewhere("(c) Quinten Kock 2020 (MIT License)", 24, 0);
|
||||
halt_catch_fire();
|
||||
|
|
|
|||
|
|
@ -2,11 +2,14 @@ const std = @import("std");
|
|||
const builtin = @import("builtin");
|
||||
const debug = @import("debug.zig");
|
||||
const kalloc = @import("allocator/kalloc.zig");
|
||||
const time = @import("time.zig");
|
||||
|
||||
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
|
||||
debug.zigpanic(msg, error_return_trace);
|
||||
}
|
||||
|
||||
pub var alloc: *std.mem.Allocator = &kalloc.KAlloc.allocator;
|
||||
|
||||
pub const log_level = .debug;
|
||||
pub fn log(
|
||||
comptime level: std.log.Level,
|
||||
|
|
@ -19,6 +22,7 @@ pub fn log(
|
|||
|
||||
comptime {
|
||||
_ = debug;
|
||||
_ = time;
|
||||
}
|
||||
|
||||
const c = @cImport({
|
||||
|
|
@ -26,6 +30,7 @@ const c = @cImport({
|
|||
@cInclude("hal/print.h");
|
||||
@cInclude("print/print.h");
|
||||
@cInclude("hal/ops.h");
|
||||
@cInclude("hal/info.h");
|
||||
if( builtin.cpu.arch == .x86_64 or builtin.cpu.arch == .i386) {
|
||||
@cInclude("arch/x86/vga.h");
|
||||
}
|
||||
|
|
@ -35,10 +40,18 @@ export fn zigmain() void {
|
|||
// // const message: [*:0]const u8 = "hello, zig!\n";
|
||||
std.log.info("All your codebase are belong to us.", .{});
|
||||
|
||||
std.log.debug("CPU info: {}", .{builtin.cpu});
|
||||
std.log.debug("CPU info: {} ({})", .{builtin.cpu.arch, builtin.cpu.model.name});
|
||||
c.puts("zig ee\n");
|
||||
|
||||
kalloc.kallocNop();
|
||||
const msg = std.fmt.allocPrint(alloc, "Hello {}!", .{"ziguser"});
|
||||
std.log.debug("message: {}", .{msg});
|
||||
|
||||
// time.displayTime(debug.AWriter) catch unreachable;
|
||||
|
||||
const cmdline = std.mem.span(c.boot_info.cmdline);
|
||||
|
||||
std.log.info("cmdline: {}", .{cmdline});
|
||||
|
||||
|
||||
// @panic("ee");
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
const std = @import("std");
|
||||
|
||||
var boot_epoch: u64 = undefined;
|
||||
var epoch: u64 = 0;
|
||||
|
||||
fn year_is_leap(y: u16) bool {
|
||||
return (y%4) == 0;
|
||||
}
|
||||
|
||||
pub const DateTime = struct {
|
||||
year: u16,
|
||||
month: u8,
|
||||
day: u16,
|
||||
hours: u8,
|
||||
mins: u8,
|
||||
secs: u8,
|
||||
|
||||
fn fromEpoch(e: u64) DateTime {
|
||||
// const year = 1970;
|
||||
// var yearlen = if(year_is_leap(year))
|
||||
|
||||
const year = 1970 + (e / 31556926);
|
||||
const days = (e % 31556926) / 86400;
|
||||
return .{
|
||||
.secs = @intCast(u8, e % 60),
|
||||
.mins = @intCast(u8, (e/60) % 60),
|
||||
.hours = @intCast(u8, (e /3600) % 60),
|
||||
.day = @intCast(u16, days),
|
||||
.month = 0,
|
||||
.year = @intCast(u16, year),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export fn setEpoch(e: u64) void {
|
||||
boot_epoch = e;
|
||||
}
|
||||
|
||||
pub fn displayTime(w: anytype) !void {
|
||||
try w.print("{}", .{DateTime.fromEpoch(boot_epoch)});
|
||||
}
|
||||
Loading…
Reference in New Issue