root/kernel/main.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 #include "types.h"
   2 #include "param.h"
   3 #include "memlayout.h"
   4 #include "riscv.h"
   5 #include "defs.h"
   6 
   7 volatile static int started = 0;
   8 
   9 // start() jumps here in supervisor mode on all CPUs.
  10 void
  11 main()
  12 {
  13   if (cpuid() == 0) {
  14     consoleinit();
  15     printkinit();
  16     printk("\n");
  17     printk("xv6 kernel is booting\n");
  18     printk("\n");
  19     kinit();            // physical page allocator
  20     kvminit();          // create kernel page table
  21     kvminithart();      // turn on paging
  22     procinit();         // process table
  23     trapinit();         // trap vectors
  24     trapinithart();     // install kernel trap vector
  25     plicinit();         // set up interrupt controller
  26     plicinithart();     // ask PLIC for device interrupts
  27     binit();            // buffer cache
  28     iinit();            // inode table
  29     fileinit();         // file table
  30     virtio_disk_init(); // emulated hard disk
  31     userinit();         // first user process
  32 
  33     __atomic_store_n(&started, 1, __ATOMIC_RELEASE);
  34   } else {
  35     while (__atomic_load_n(&started, __ATOMIC_ACQUIRE) == 0)
  36       ;
  37 
  38     printk("hart %d starting\n", cpuid());
  39     kvminithart();  // turn on paging
  40     trapinithart(); // install kernel trap vector
  41     plicinithart(); // ask PLIC for device interrupts
  42   }
  43 
  44   scheduler();
  45 }

/* [<][>][^][v][top][bottom][index][help] */