include: one folder per subsystem, and includes that name it
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
This commit is contained in:
parent
0e39e711f1
commit
a1c965da1e
267 changed files with 1560 additions and 1440 deletions
|
|
@ -25,7 +25,7 @@
|
|||
// It is the same bargain as kpi_io_ok() in ldls/kpi/io.c, one level down and
|
||||
// enforced by hardware rather than by the driver's host being polite.
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
struct proc;
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ stosb(void *addr, int data, int cnt)
|
|||
// 64-bit-only helpers. `rep stosq` and `xchgq` do not exist in 32-bit mode, so
|
||||
// these must not even be parsed by the -m32 bootloader build -- they compiled
|
||||
// there before only because uint64 was accidentally 32 bits wide, which is the
|
||||
// bug include/types.h now asserts against.
|
||||
// bug include/core/types.h now asserts against.
|
||||
#ifdef __x86_64__
|
||||
static inline void
|
||||
stosq(void *addr, uint64 data, int cnt)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
struct sbuf;
|
||||
|
||||
|
|
@ -371,7 +371,7 @@ void ioapicmask(int irq);
|
|||
extern uchar ioapicid;
|
||||
void ioapicinit(void);
|
||||
|
||||
// dma.c — see include/dma.h for the full contract
|
||||
// dma.c — see include/core/dma.h for the full contract
|
||||
void dma_init(void*, void*);
|
||||
|
||||
// watch.c -- hardware watchpoints on DR0-DR3. See docs/architecture/debugging.md, D4.
|
||||
|
|
@ -388,13 +388,13 @@ int netuser_ready(struct inode*);
|
|||
int netuser_ioctl(uint64 request, uint64 argp);
|
||||
void netuser_release_all(struct proc*);
|
||||
|
||||
// dbg.c -- /dev/dbg, the introspection registry. See include/dbg.h.
|
||||
// dbg.c -- /dev/dbg, the introspection registry. See include/core/dbg.h.
|
||||
int dbg_read(struct inode*, uint64, char*, int);
|
||||
void dbg_request_dump(void);
|
||||
void dbg_thread_start(void);
|
||||
int dbg_write(struct inode*, uint64, char*, int);
|
||||
|
||||
// klog.c -- the kernel log that outlives the kernel. See include/klog.h.
|
||||
// klog.c -- the kernel log that outlives the kernel. See include/core/klog.h.
|
||||
void klog_init(void *base, uint64 bytes);
|
||||
void klog_putc(int c);
|
||||
int klog_read(uint64 off, char *dst, int n);
|
||||
|
|
@ -608,8 +608,8 @@ void uartintr(void);
|
|||
void uartputc(int);
|
||||
|
||||
// Drawing, the text console and the framebuffer geometry are NOT declared
|
||||
// here: they live in include/gfx.h, and the display drivers that back them in
|
||||
// include/display.h. Declaring vga_fill_rect() here is what let the crash
|
||||
// here: they live in include/gfx/gfx.h, and the display drivers that back them in
|
||||
// include/gfx/display.h. Declaring vga_fill_rect() here is what let the crash
|
||||
// screen draw on one named driver.
|
||||
|
||||
// fb.c -- /dev/fb0, major 2.
|
||||
|
|
@ -618,7 +618,7 @@ void fbclose(struct inode*);
|
|||
// further syscalls, so it is the last the kernel hears about it.
|
||||
void fb_mapped(void);
|
||||
|
||||
// AudioEngine and /dev/dsp. kernel/dev/audio.c, include/audio.h.
|
||||
// AudioEngine and /dev/dsp. kernel/dev/audio.c, include/dev/audio.h.
|
||||
int dspread(struct inode*, uint64, char*, int);
|
||||
int dspwrite(struct inode*, uint64, char*, int);
|
||||
void dspclose(struct inode*);
|
||||
|
|
@ -644,7 +644,7 @@ int fb_ioctl(int request, addr_t arg);
|
|||
int diskread(struct inode*, uint64, char*, int);
|
||||
int diskwrite(struct inode*, uint64, char*, int);
|
||||
// Network *drivers* are not declared here at all. They are reached through the
|
||||
// netdev class in include/netdev.h -- a driver publishes a vtable and nothing
|
||||
// netdev class in include/dev/netdev.h -- a driver publishes a vtable and nothing
|
||||
// above it ever learns its name. Declaring e1000_transmit() here was what let
|
||||
// the protocol stack call it directly.
|
||||
|
||||
|
|
@ -684,7 +684,7 @@ struct device *net_eth_device(int i);
|
|||
// the loader handed over, because bringing that up is the first thing it does.
|
||||
void platform_register_devices(uint64 fb_addr);
|
||||
// drivers/gpu/vga -- the VBE framebuffer the loader programmed. Called only
|
||||
// from registry.c; everything else draws through include/gfx.h.
|
||||
// from registry.c; everything else draws through include/gfx/gfx.h.
|
||||
void vga_fb_init(uint64 phys_addr);
|
||||
uint64 vga_fb_phys(void);
|
||||
int vga_fb_restore(void); // 0 = there is no fallback
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
// The kernel log that outlives the kernel.
|
||||
//
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
// gets here, and types.h collides with glibc's -- same reason kernel/dev/ttf.c
|
||||
// guards its includes.
|
||||
#ifndef KMEM_HOST
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
#endif
|
||||
|
||||
struct kmem_cache;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "traps.h"
|
||||
#include "ioperm.h"
|
||||
#include "core/types.h"
|
||||
#include "arch/traps.h"
|
||||
#include "arch/ioperm.h"
|
||||
|
||||
// Simultaneous mmap() regions per process.
|
||||
//
|
||||
|
|
@ -215,7 +215,7 @@ struct proc {
|
|||
|
||||
// Ports this process may use directly, from the I/O BARs of the PCI devices
|
||||
// it has claimed. Empty for everything that is not hosting a driver, which is
|
||||
// everything. See include/ioperm.h.
|
||||
// everything. See include/arch/ioperm.h.
|
||||
struct ioport_range ioport[NIOPORT];
|
||||
int nioport;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
// A bounded string builder, because there is no snprintf in this kernel.
|
||||
//
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
// sees the output, so emit .set directives instead of an enum.
|
||||
#define SYSCALL(nr, lnr, name) .set SYS_##name, nr
|
||||
#define SYSCALL_ALIAS(lnr, name)
|
||||
#include "../kernel/sys/table.inc"
|
||||
#include "../../kernel/sys/table.inc"
|
||||
#undef SYSCALL
|
||||
#undef SYSCALL_ALIAS
|
||||
#else
|
||||
|
|
@ -31,7 +31,7 @@ enum syscall_nr {
|
|||
_SYS_RESERVED = 0,
|
||||
#define SYSCALL(nr, lnr, name) SYS_##name = (nr),
|
||||
#define SYSCALL_ALIAS(lnr, name)
|
||||
#include "../kernel/sys/table.inc"
|
||||
#include "../../kernel/sys/table.inc"
|
||||
#undef SYSCALL
|
||||
#undef SYSCALL_ALIAS
|
||||
};
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
#ifndef SCHOS_UACCESS_H
|
||||
#define SCHOS_UACCESS_H
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
// Nonzero if [uaddr, uaddr+size) is entirely mapped, user-accessible
|
||||
// memory in the current process. size == 0 is always ok.
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
// Raw input events -- Linux's evdev interface.
|
||||
//
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef KEYMAP_H
|
||||
#define KEYMAP_H
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
// Which of a layout's four tables a set of modifiers selects. Plain, Shift,
|
||||
// AltGr, and Shift+AltGr -- Ctrl is not one of them, because a control
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
// Without this the first driver's name spreads: kernel/net/net.c called
|
||||
// e1000_present(), the lwIP glue was named netif_e1000.c and called
|
||||
// e1000_transmit(), and adding a second NIC would have meant editing the
|
||||
// protocol stack to add it. That is the mistake include/device.h was written
|
||||
// protocol stack to add it. That is the mistake include/dev/device.h was written
|
||||
// to prevent, made once anyway because the net class did not exist yet --
|
||||
// kernel/drivers/net/e1000/e1000.c even said so, with `.ops = 0, // no class
|
||||
// vtable yet`.
|
||||
|
|
@ -17,9 +17,9 @@
|
|||
// forever: it never mentions lwIP, and the stack never mentions it.
|
||||
//
|
||||
// Found with device_find_class(DEVCLASS_NET) or, when there may be more than
|
||||
// one, netdev_at(); see include/device.h.
|
||||
// one, netdev_at(); see include/dev/device.h.
|
||||
|
||||
#include "device.h"
|
||||
#include "dev/device.h"
|
||||
|
||||
struct netdev_ops {
|
||||
// Queue one frame for transmission. Returns 0, or -1 if the ring is full --
|
||||
|
|
@ -107,7 +107,7 @@ struct pci_match {
|
|||
// only this header defines. See kernel/dev/device.c for the model they feed.
|
||||
// device.h is included rather than forward-declaring `enum dev_class`, which
|
||||
// is a compiler extension and warns.
|
||||
#include "device.h"
|
||||
#include "dev/device.h"
|
||||
|
||||
enum dev_class pci_class_of(const struct pci_dev *);
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ enum dev_class pci_class_of(const struct pci_dev *);
|
|||
// one, MSI-X if allowed and it has that instead, and its INTx line otherwise.
|
||||
// Returns the line, or -1 if there is no way to interrupt at all -- which is
|
||||
// not fatal; a driver with a poll path should say so and carry on.
|
||||
#include "irq.h"
|
||||
#include "core/irq.h"
|
||||
int pci_irq_attach(struct pci_dev *, irq_handler_t, void *arg,
|
||||
const char *name, int flags);
|
||||
void pci_irq_detach(struct pci_dev *, irq_handler_t, void *arg);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "device.h"
|
||||
#include "dev/device.h"
|
||||
|
||||
// USB, the parts that are the same whatever host controller you have.
|
||||
//
|
||||
|
|
@ -22,9 +22,9 @@
|
|||
#ifndef VT_H
|
||||
#define VT_H
|
||||
|
||||
#include "types.h"
|
||||
#include "param.h"
|
||||
#include "posix.h"
|
||||
#include "core/types.h"
|
||||
#include "core/param.h"
|
||||
#include "uapi/posix.h"
|
||||
|
||||
// Six, and Linux's numbering: /dev/tty1 through /dev/tty6, reached with
|
||||
// Alt+1..Alt+6. A seventh is deliberately not bound -- that is where a
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
// A cell.
|
||||
//
|
||||
// `ch` is the glyph the font draws, not a codepoint: the console maps UTF-8
|
||||
// to CP437 before it gets here, because that is what include/font.h contains.
|
||||
// to CP437 before it gets here, because that is what include/gfx/font.h contains.
|
||||
// Storing the codepoint would mean re-running that mapping on every repaint
|
||||
// and getting a different answer for anything the font cannot draw.
|
||||
//
|
||||
|
|
@ -61,7 +61,7 @@ struct vtcell {
|
|||
uint8 pad; // the glyph and so can be added without touching a grid
|
||||
};
|
||||
|
||||
#define VT_FG_DEFAULT 16 // SCH_FG from include/theme.h
|
||||
#define VT_FG_DEFAULT 16 // SCH_FG from include/gfx/theme.h
|
||||
#define VT_BG_DEFAULT 17 // SCH_BG
|
||||
#define VT_NCOLOUR 18
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ int sysfs_mount(const char *target);
|
|||
char *proc_genbuf_get(int *cap);
|
||||
void proc_genbuf_put(void);
|
||||
|
||||
// Mounted FAT volumes, FAT_DEV onward. See include/fat.h.
|
||||
// Mounted FAT volumes, FAT_DEV onward. See include/fs/fat.h.
|
||||
|
||||
// Linux's limits, for every filesystem behind the VFS. A path component can be
|
||||
// NAME_MAX bytes and a whole path PATH_MAX including its NUL. Each filesystem
|
||||
|
|
@ -236,5 +236,5 @@ extern struct devsw devsw[];
|
|||
#define CONSOLE 1
|
||||
// Major number of /dev/input/eventN. The minor is the device index.
|
||||
#define INPUT_MAJOR 7
|
||||
// Major number of /dev/dsp. See include/audio.h.
|
||||
// Major number of /dev/dsp. See include/dev/audio.h.
|
||||
#define AUDIO_MAJOR 12
|
||||
|
|
@ -82,7 +82,7 @@ extern struct superblock sb;
|
|||
// of BSIZE/sizeof(struct fsv1_extent) = 85 additional extents.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Renamed from "schfs_extent". The new format in include/schfs.h has its own,
|
||||
// Renamed from "schfs_extent". The new format in include/fs/schfs.h has its own,
|
||||
// completely different, struct of that name -- 64-bit fields and a refcount --
|
||||
// and any file including both headers hit a redefinition error. Two structs
|
||||
// with one name and two layouts is a trap worth removing rather than working
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
// them. That is not hypothetical here: the framebuffer's physical address was
|
||||
// once hardcoded in three separate places.
|
||||
//
|
||||
// Found with device_find_class(DEVCLASS_DISPLAY); see include/device.h.
|
||||
// Found with device_find_class(DEVCLASS_DISPLAY); see include/dev/device.h.
|
||||
|
||||
struct device;
|
||||
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
// each one we ever port, and -- worse -- a Linux-ABI binary calling
|
||||
// FBIOGET_VSCREENINFO would have gotten a *differently shaped* answer to a
|
||||
// request it thought it understood, which is the failure mode that made
|
||||
// `>>` truncate back when include/fcntl.h held xv6's open flags instead of
|
||||
// `>>` truncate back when include/uapi/fcntl.h held xv6's open flags instead of
|
||||
// Linux's. Same lesson, applied before it bites rather than after.
|
||||
//
|
||||
// Plain C types throughout (no types.h) so userspace can include this
|
||||
|
|
@ -11,9 +11,9 @@
|
|||
// So the driver pushes its scanout in here (gfx_attach_scanout) and everything
|
||||
// above draws through these calls. A second display driver becomes a second
|
||||
// caller of one function rather than an edit to the crash screen. This is the
|
||||
// same arrangement as include/netdev.h, for the same reason.
|
||||
// same arrangement as include/dev/netdev.h, for the same reason.
|
||||
//
|
||||
// Not the same thing as the display class in include/display.h. That is the
|
||||
// Not the same thing as the display class in include/gfx/display.h. That is the
|
||||
// compositor's interface -- acquire a back buffer, present a rectangle, wait
|
||||
// for vblank -- and it is about *frames*. This is the kernel's own drawing
|
||||
// surface, used by the console and the crash screen, which do not double
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
//
|
||||
// An ink-coverage mask, not colour: 0 is background and full scale is
|
||||
// solid logo. Whoever draws it picks the colour, so the palette stays in
|
||||
// include/theme.h and can change without regenerating anything.
|
||||
// include/gfx/theme.h and can change without regenerating anything.
|
||||
//
|
||||
// Two pixels per byte, high nibble first. Included by boot/stage2main.c
|
||||
// as well as kernel/dev/vga.c, and stage2 must fit below the 0x10000
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
// TrueType outlines, as a font provider for include/text.h.
|
||||
// TrueType outlines, as a font provider for include/gfx/text.h.
|
||||
//
|
||||
// Scope, and why it is this and not "TTF and OTF":
|
||||
//
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
// the kernel. This is what joins the two.
|
||||
//
|
||||
// It is the exact analogue of what `display_ops` is for the GPU, and
|
||||
// include/netdev.h's own opening comment already anticipated the shape:
|
||||
// include/dev/netdev.h's own opening comment already anticipated the shape:
|
||||
//
|
||||
// "the stack should ask for the network interfaces and get whatever is
|
||||
// bound -- today an e1000, tomorrow a virtio-net or an rtl8139 -- exactly
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
// LDLS-hosted Linux driver and equally by a test program with no hardware at
|
||||
// all -- and the second one is how the first is debugged.
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
#define NETUSER_MAJOR 11
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
// Unix domain sockets.
|
||||
//
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// SchOS — POSIX-compatibility types used by kernel syscall handlers.
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
#include "date.h"
|
||||
#include "core/types.h"
|
||||
#include "core/date.h"
|
||||
|
||||
// struct iovec is declared in two headers on purpose, and guarded so that
|
||||
// including both is not an error.
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include "types.h"
|
||||
#include "core/types.h"
|
||||
|
||||
#define T_DIR 1 // Directory
|
||||
#define T_FILE 2 // File
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
#ifndef USER_H
|
||||
#define USER_H
|
||||
|
||||
#include "types.h"
|
||||
#include "date.h"
|
||||
#include "core/types.h"
|
||||
#include "core/date.h"
|
||||
|
||||
struct stat;
|
||||
struct rtcdate;
|
||||
Loading…
Reference in a new issue