Sixty-five headers sat side by side in include/, so `#include "irq.h"` said nothing about where irq.h was or what it belonged to, and errno.h, stat.h and fcntl.h at the top shadowed the system's for any host tool built with -I./include. They are in folders now -- arch/ core/ fs/ dev/ gfx/ net/ uapi/ (and ldls/ for the Linux driver layer) -- and every include names the folder, as Linux's do: "core/proc.h". Done mechanically and checked the hard way: the kernel built from this tree disassembles identically to the one built from the tree before it. The full image boots, and userland is the same set of programs. Paths in docs and comments follow; docs/guides/layout.md has a table of what is where, and tools/fix-includes.py rewrites old-style includes from the folders in the tree, for code written before this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
44 lines
1.8 KiB
C
44 lines
1.8 KiB
C
#pragma once
|
|
|
|
#include "core/types.h"
|
|
|
|
// The kernel log that outlives the kernel.
|
|
//
|
|
// docs/architecture/debugging.md milestone D1. Until this existed, `cprintf` wrote to a
|
|
// serial line and a screen and was then gone: a panic's report could be read
|
|
// only by whoever was watching at the time, and a triple fault left nothing at
|
|
// all. panic.c said so in its own header comment -- *"there is no core dump and
|
|
// no log to go back to"* -- and that sentence is what this deletes.
|
|
//
|
|
// The buffer is a byte ring in a region carved off physical memory *before*
|
|
// kalloc or the DMA arena are given anything, at a fixed distance below
|
|
// PHYSTOP, so its address is a property of the machine rather than of this
|
|
// boot. Nothing allocates it, nothing frees it, and a reboot that leaves DRAM
|
|
// alone leaves it intact -- which is what makes the last words of a crashed
|
|
// kernel readable from the one that comes after.
|
|
|
|
#define KLOG_BYTES (128 * 1024) // ring plus header
|
|
#define KLOG_MAGIC 0x676f4c6bu // "kLog"
|
|
#define KLOG_VERSION 1
|
|
|
|
// Kept at the head of the region. Everything in it has to survive a reboot, so
|
|
// it is all fixed-width and there are no pointers: the only thing that says
|
|
// where the data is, is that it follows.
|
|
struct klog_hdr {
|
|
uint32 magic;
|
|
uint32 version;
|
|
uint32 size; // bytes of data[], = KLOG_BYTES - sizeof(struct klog_hdr)
|
|
uint32 boot; // how many kernels have written here
|
|
uint64 head; // total bytes ever written; the ring is head mod size
|
|
uint64 mark; // head as it stood when this boot started
|
|
uint32 sum; // over the fields above -- see klog.c
|
|
uint32 pad;
|
|
char data[];
|
|
};
|
|
|
|
void klog_init(void *base, uint64 bytes);
|
|
void klog_putc(int c);
|
|
int klog_read(uint64 off, char *dst, int n);
|
|
uint64 klog_len(void);
|
|
uint64 klog_prev_bytes(void);
|
|
int klog_recovered(void);
|