xv6

kalloc.c

xv6

// Physical memory allocator, intended to allocate // memory for user processes, kernel stacks, page table pages, // and pipe buffers. Allocates 4096-byte pages. #include "types.h" #include "defs.h" #include "param.h" #include "memlayout.h…

swtch.S

xv6

# Context switch # # void swtch(struct context **old, struct context *new); # # Save current register context in old # and then load register context from new. .globl swtch swtch: movl 4(%esp), %eax movl 8(%esp), %edx # Save old callee-sav…

proc.c

xv6

#include "types.h" #include "defs.h" #include "param.h" #include "memlayout.h" #include "mmu.h" #include "x86.h" #include "proc.h" #include "spinlock.h" struct { struct spinlock lock; struct proc proc[NPROC]; } ptable; static struct proc *…

proc.h

xv6

// Per-CPU state struct cpu { uchar apicid; // Local APIC ID struct context *scheduler; // swtch() here to enter scheduler struct taskstate ts; // Used by x86 to find stack for interrupt struct segdesc gdt[NSEGS]; // x86 global descriptor …

vm.c

xv6

#include "param.h" #include "types.h" #include "defs.h" #include "x86.h" #include "memlayout.h" #include "mmu.h" #include "proc.h" #include "elf.h" extern char data[]; // defined by kernel.ld pde_t *kpgdir; // for use in scheduler() // Set…

spinlock.c

xv6

// Mutual exclusion spin locks. #include "types.h" #include "defs.h" #include "param.h" #include "x86.h" #include "memlayout.h" #include "mmu.h" #include "proc.h" #include "spinlock.h" void initlock(struct spinlock *lk, char *name) { lk->n…

spinlock.h

xv6

// Mutual exclusion lock. struct spinlock { uint locked; // Is the lock held? // For debugging: char *name; // Name of lock. struct cpu *cpu; // The cpu holding the lock. uint pcs[10]; // The call stack (an array of program counters) // th…

main.c

xv6

#include "types.h" #include "defs.h" #include "param.h" #include "memlayout.h" #include "mmu.h" #include "proc.h" #include "x86.h" static void startothers(void); static void mpmain(void) __attribute__((noreturn)); extern pde_t *kpgdir; ext…

entryother.S

xv6

#include "asm.h" #include "memlayout.h" #include "mmu.h" # Each non-boot CPU ("AP") is started up in response to a STARTUP # IPI from the boot CPU. Section B.4.2 of the Multi-Processor # Specification says that the AP will start in real mo…

entry.S

xv6

# The xv6 kernel starts executing in this file. This file is linked with # the kernel C code, so it can refer to kernel symbols such as main(). # The boot block (bootasm.S and bootmain.c) jumps to entry below. # Multiboot header, for multi…

elf.h

xv6

// Format of an ELF executable file #define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian // File header struct elfhdr { uint magic; // must equal ELF_MAGIC uchar elf[12]; ushort type; ushort machine; uint version; uint entry; uint p…

mmu.h

xv6

// This file contains definitions for the // x86 memory management unit (MMU). // Eflags register #define FL_CF 0x00000001 // Carry Flag #define FL_PF 0x00000004 // Parity Flag #define FL_AF 0x00000010 // Auxiliary carry Flag #define FL_ZF…

asm.h

xv6

// // assembler macros to create x86 segments // #define SEG_NULLASM \ .word 0, 0; \ .byte 0, 0, 0, 0 // The 0xC0 means the limit is in 4096-byte units // and (for executable segments) 32-bit mode. #define SEG_ASM(type,base,lim) \ .word ((…

x86.h

xv6

// Routines to let C code use special x86 instructions. static inline uchar inb(ushort port) { uchar data; asm volatile("in %1,%0" : "=a" (data) : "d" (port)); return data; } static inline void insl(int port, void *addr, int cnt) { asm vol…

defs.h

xv6

struct buf; struct context; struct file; struct inode; struct pipe; struct proc; struct rtcdate; struct spinlock; struct sleeplock; struct stat; struct superblock; // bio.c void binit(void); struct buf* bread(uint, uint); void brelse(struc…

memlayout.h

xv6

// メモリのレイアウト #define EXTMEM 0x100000 // extended memoryの開始アドレス #define PHYSTOP 0xE000000 // 物理メモリの先頭 #define DEVSPACE 0xFE000000 // 他のデバイスは、より高いアドレスにある // Key addresses for address space layout (s…

param.h

xv6

#define NPROC 64 // プロセスの最大の個数 #define KSTACKSIZE 4096 // プロセスごとのカーネルスタックのサイズ #define NCPU 8 // CPUの最大の個数 #define NOFILE 16 // プロセスごとのオープンできるファイルの個数 #define NFILE 100 // システムご…

types.h

xv6

typedef unsigned int uint; typedef unsigned short ushort; typedef unsigned char uchar; typedef uint pde_t;