import time
+from datetime import datetime, date
include("kernel")
include("arch")
type(str)
- seq_num = int(time.time() / 3600)
- default("%s dev-2024_%d"%(v(arch), seq_num))
+ today = date.today()
+ year = today.year
+ start_of_year = datetime(year, 1, 1).date()
+ seq_num = (today - start_of_year).days
+
+ default("%s v0.%d%d"%(v(arch), year - 2000, seq_num))
@Collection("Kernel Debug and Testing")
def debug_and_testing():
--- /dev/null
+#ifndef __LUNAIX_FLIPBUF_H
+#define __LUNAIX_FLIPBUF_H
+
+#include <lunaix/types.h>
+#include <lunaix/spike.h>
+
+struct flipbuf
+{
+ void* buf;
+ void* top;
+ unsigned long half_size;
+};
+
+#define DEFINE_FLIPBUF(name, halfsz, buf_) \
+ struct flipbuf name = { .buf=buf_, .top=buf_, .half_size=halfsz }
+
+static inline void*
+flipbuf_under(struct flipbuf* fbuf)
+{
+ ptr_t off;
+
+ off = __ptr(fbuf->top);
+ off += fbuf->half_size;
+ off %= fbuf->half_size;
+ off += __ptr(fbuf->buf);
+
+ return (void*)off;
+}
+
+static inline void*
+flipbuf_top(struct flipbuf* fbuf)
+{
+ return fbuf->top;
+}
+
+static inline void*
+flipbuf_flip(struct flipbuf* fbuf)
+{
+ fbuf->top = flipbuf_under(fbuf);
+ return fbuf->top;
+}
+
+#endif /* __LUNAIX_FLIPBUF_H */
#define NB_TRACEBACK 16
-LOG_MODULE("TRACE")
+LOG_MODULE("lkdbg")
extern_autogen(ksymtable);
trace_modksyms_init(struct boot_handoff* bhctx)
{
trace_ctx.ksym_table = autogen(struct ksyms, ksymtable);
+
+ INFO("symbols loaded: %d @0x%lx",
+ trace_ctx.ksym_table->ksym_count, trace_ctx.ksym_table->syms);
}
struct ksym_entry*
llist_append(&dev_registry_flat, &devdef->dev_list);
}
+
+ INFO("%d drivers registered", idx + 1);
}
static int
{
struct extractor ctx = { .cmdline = cmd_line, .pos = 0 };
- while(extract_next_option(&ctx)) {
+ INFO("active kcmds");
+
+ // first option is always kernel itself
+ extract_next_option(&ctx);
+
+ while (extract_next_option(&ctx)) {
if (!ctx.key.len) {
continue;
}
memcpy(kopt->buf, &cmd_line[ctx.key.pos], ctx.key.len);
+ kopt->hashkey = HSTR(kopt->buf, ctx.key.len);
+ hstr_rehash(&kopt->hashkey, HSTR_FULL_HASH);
+
if (ctx.val.len) {
kopt->value = &kopt->buf[ctx.key.len + 1];
size_t max_val_len = maxlen - ctx.key.len;
}
memcpy(kopt->value, &cmd_line[ctx.val.pos], ctx.val.len);
+ INFO(" %-10s =%s", kopt->hashkey.value, kopt->value);
+ }
+ else {
+ INFO(" %s", kopt->hashkey.value);
}
- kopt->hashkey = HSTR(kopt->buf, ctx.key.len);
- hstr_rehash(&kopt->hashkey, HSTR_FULL_HASH);
-
hashtable_hash_in(options, &kopt->node, kopt->hashkey.hash);
}
}
return;
}
+static void
+log_bootup_time()
+{
+ datetime_t dt;
+
+ clock_walltime(&dt);
+ INFO("kernel boot at: %d/%d/%d %d:%d:%d",
+ dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
+}
+
void
kernel_bootstrap(struct boot_handoff* bhctx)
{
/* Setup kernel memory layout and services */
kmem_init(bhctx);
+ INFO();
+ INFO("Lunaix " CONFIG_LUNAIX_VER " (c) Lunaixsky 2022-2025");
boot_parse_cmdline(bhctx);
clock_init();
timer_init();
+ log_bootup_time();
initfn_invoke_earlyboot();
#include <lunaix/syslog.h>
#include <lunaix/device.h>
#include <lunaix/owloysius.h>
+#include <lunaix/ds/flipbuf.h>
#include <hal/term.h>
#include "kp_records.h"
-#define MAX_BUFSZ 512
#define MAX_BUFSZ_HLF 256
#define MAX_KPENT_NUM 1024
-static char tmp_buf[MAX_BUFSZ];
+static char tmp_buf[MAX_BUFSZ_HLF * 2];
+static DEFINE_FLIPBUF(fmtbuf, MAX_BUFSZ_HLF, tmp_buf);
static struct kp_records kprecs = {
.kp_ents = { .ents = { .next = &kprecs.kp_ents.ents,
}
static inline void
-kprintf_put(int level, const char* buf, size_t sz)
+__put_console(const struct kp_entry* ent)
{
- kprec_put(&kprecs, level, buf, sz);
+ char* buf;
+ time_t s, ms;
+ size_t sz;
- if (likely(sysconsole)) {
- sysconsole->ops.write(sysconsole, buf, 0, sz);
+ if (unlikely(!sysconsole)) {
+ return;
}
+
+ s = ent->time / 1000;
+ ms = ent->time % 1000;
+ buf = flipbuf_flip(&fmtbuf);
+ sz = ksnprintf(buf, MAX_BUFSZ_HLF,
+ "[%04d.%03d] %s", s, ms, ent->content);
+
+ sysconsole->ops.write(sysconsole, buf, 0, sz);
+}
+
+static inline void
+kprintf_put(int level, const char* buf, size_t sz)
+{
+ __put_console(kprec_put(&kprecs, level, buf, sz));
}
static inline void
kprintf_ml(const char* component, int level, const char* fmt, va_list args)
{
- char* buf = &tmp_buf[MAX_BUFSZ_HLF];
+ char* buf;
+ size_t sz;
+
+ buf = flipbuf_top(&fmtbuf);
ksnprintf(buf, MAX_BUFSZ_HLF, "%s: %s\n", component, fmt);
- size_t sz = ksnprintfv(tmp_buf, buf, MAX_BUFSZ_HLF, args);
- kprintf_put(level, tmp_buf, sz);
+ sz = ksnprintfv(flipbuf_flip(&fmtbuf), buf, MAX_BUFSZ_HLF, args);
+
+ kprintf_put(level, flipbuf_top(&fmtbuf), sz);
}
void
struct kp_entry *pos, *n;
llist_for_each(pos, n, kprecs.kp_ent_wp, ents)
{
- sysconsole->ops.write(sysconsole, pos->content, 0, pos->len);
+ __put_console(pos);
}
}
#include <lunaix/status.h>
#include <lunaix/mm/pagetable.h>
#include <lunaix/spike.h>
+#include <lunaix/owloysius.h>
+#include <lunaix/syslog.h>
#include "pmm_internal.h"
+LOG_MODULE("pmm")
+
static inline bool
__check_typemask(struct ppage* page, ppage_type_t typemask)
{
_pool->pool_start = ppage(start);
return _pool;
-}
\ No newline at end of file
+}
+
+static void
+pmm_log_summary()
+{
+ pfn_t len;
+ struct pmem_pool* _pool;
+
+ INFO("init: nr_pages=%ld, gran=0x%lx", memory.list_len, 1 << PAGE_SHIFT);
+
+ for (int i = 0; i < POOL_COUNT; i++)
+ {
+ _pool = &memory.pool[i];
+ len = ppfn(_pool->pool_end) - ppfn(_pool->pool_start) + 1;
+
+ INFO("pool #%d (%d), %ld-%ld(0x%lx)",
+ i , _pool->type,
+ ppfn(_pool->pool_start), ppfn(_pool->pool_end), len);
+ }
+}
+owloysius_fetch_init(pmm_log_summary, on_sysconf);
\ No newline at end of file