if NCPUS > 1 stuff is not being considered so far.

grub starts the execution at boot_entry

i386/i386at/boothdr.S: boot_entry: sets up C environment, i.e. sets up a basic stack and clears BSS, fixes ifunc.

i386/i386at/model_dep.c: c_boot_entry: gets multiboot parameters

i386/i386at/boothdr.S: discover_x86_cpu_type: detect processor type

i386/i386at/model_dep.c: i386at_init: initialize PC-specific stuff

i386/i386/pic.c: picinit: initialize 8259 PIC

i386/i386at/model_dep.c: mem_size_init: compute memory size

i386/intel/pmap.c: pmap_bootstrap: initialize x86 page table

i386/i386/gdt.c: gdt_init: initialize x86 segmentation

i386/i386/idt.c: idt_init: initialize x86 traps

i386/i386at/int_init.c: int_init: initialize PC interrupts

i386/i386/ldt.c: ldt_init: initialize x86 segmentation

i386/i386/ktss.c: ktss_init: initialize x86 task switching

kern/startup.c: setup_main: set up non-hardware specific stuff

kern/debug.c: panic_init: initialize panic data

kern/printf.c: printf_init: initialize printf

kern/sched_prim.c: sched_init: initialize scheduler

kern/processor.c: pset_sys_bootstrap: initialize processor sets

kern/ast.c: ast_init: initialize Asychronous System Traps

vm/vm_init.c: vm_mem_bootstrap: initialize virtual memory

vm/vm_resident.c: vm_page_bootstrap: turn physical pages into virtually allocatable pages

vm/vm_resident.c: pmap_startup: initialize pages

kern/slab.c: slab_bootstrap: early-initialize SLAB

vm/vm_object.c: vm_object_bootstrap: initialize VM object management

vm/vm_external.c: vm_external_module_initialize: initialize VM external object management

vm/vm_map.c: vm_map_init: initialize VM maps

vm/vm_kern.c: kmem_init: initialize kernel's virtual memory

i386/intel/pmap.c: pmap_init: initialize remainder of x86 page table

kern/slab.c: slab_init: initialize remainder of SLAB

kern/kalloc.c: kalloc_init: initialize kallocator

vm/vm_fault.c: vm_fault_init: initialize VM fault management

vm/vm_resident.c: vm_page_module_init: initialize remainder of virtual memory

vm/memory_object.c: memory_manager_default_init: initialize remainder of VM object management

ipc/ipc_init.c: ipc_bootstrap: initialize IPC

ipc/ipc_table.c: ipc_table_init: initialize IPC tables

ipc/ipc_notify.c: ipc_notify_init: initialize IPC notification

ipc/ipc_hash.c: ipc_hash_init: initialize IPC reverse hash table

ipc/ipc_marequest.c: ipc_marequest_init: initialize msg-accepted request

vm/vm_init.c: vm_mem_init: finish initializing VM

vm/vm_object.c: vm_object_init: finish initializing kernel object

vm/memory_object_proxy: memory_object_proxy_init: initialize memory object proxy

ipc/ipc_init.c: ipc_init: finish initializing IPC

kern/ipc_host.c: ipc_host_init: initialize host IPC

kern/ipc_host.c: ipc_pset_init: initialize processor sets ports

kern/ipc_host.c: ipc_processor_init: initialize processor ports

i386/intel/pmap.h: PMAP_ACTIVATE_KERNEL: activate kernel page table

kern/timer.c: init_timers: initialize timers

kern/mach_clock.c: init_timeout: initialize timeout

kern/xpr.c: xprbootstrap: initialize xpr buffer

kern/time_stamp.c: timestamp_init: initialize tick

kern/mach_clock.c: mapable\ time\ init

i386/i386at/model_dep.c: machine_init: initialize x86 machine

device/cons.c: cninit: initialize console

i386/i386/fpu.c: init_fpu: initialize 8087 FPU

linux/dev/init/main.c: linux_init: initialize linux drivers

linux/dev/arch/i386/kernel/irq.c: init_IRQ: initialize IRQs

linux/dev/arch/i386/kernel/irq.c: reserve_mach_irqs: register IRQs to mach

linux/dev/kernel/sched.c: linux_sched_init: initialize dumb scheduler

linux/dev/init/main.c: calibrate_delay: calibrate delay loop

linux/dev/glue/kmem.c: linux_kmem_init: initialize memory management

linux/src/drivers/pci/pci.c: pci_init: initialize PCI bus

linux/src/arch/i386/kernel/bios32.c: pcibios_init: call PCI BIOS32 initialization

linux/src/drivers/pci/pci.c: scan_bus: enumerate PCI devices

linux/src/arch/i386/kernel/bios32.c: pcibios_fixup: apply platform-specific fixes

linux/dev/glue/net.c: linux_net_emulation_init: initialize network glue

linux/dev/drivers/block/genhd.c: device_setup: initialize block devices

linux/dev/glue/block.c: blk_dev_init: initialize linux block devices

linux/src/drivers/block/ide.c: ide_init: initialize IDE driver

linux/dev/drivers/block/floppy.c: floppy_init: initialize floppy driver

linux/src/drivers/scsi/scsi.c: scsi_dev_init: initialize SCSI drivers

linux/dev/net/core/dev.c: net_dev_init: initialize network drivers

linux/pcmcia-cs/glue/pcmcia.c: pcmcia_init: initialize PCMCIA drivers

i386/i386at/autoconf.c: probeio: probe mach-managed devices (com, lpr)

i386/i386at/model_dep.c: inittodr: get RTC time

i386/intel/pmap.c: pmap_unmap_page_zero: unmap address 0

kern/mach_clock.c: mapable_time_init: initialize mappable time

kern/task.c: task_init: initialize gnuamch atsk

kern/syscall_emulation.c: eml_init: initialize user space emulation code

kern/thread.c: thread_init: initialize thread management

i386/i386/pcb.c: pcb_module_init: initialize PCB management

i386/i386/fpu.c: fpu_module_init: initialize FPU management

kern/thread_swap.c: swapper_init: initialize thread swapper

kern/sched_prim.c: recompute_priorities: initial priorities computation

kern/mach_factor.c: compute_mach_factor: initial mach factor computation

kern/startup.c: thread_start: create initial kernel thread

kern/startup.c: cpu_launch_first_thread: start first user thread

i386/intel/pmap.h: PMAP_ACTIVATE_KERNEL: activate kernel page table

i386/i386at/model_dep.c: startrtclock: start clock

i386/i386/pit.c: clkstart: start 8254 PIT

i386/intel/pmap.h: PMAP_ACTIVATE_KERNEL: activate user page table

i386/i386/pcb.c: load_context: load first context


kern/startup.c: start_kernel_threads

Threads get created.

kern/sched_prim.c: idle_thread

One for each CPU.

kern/thread.c: reaper_thread

kern/thread_swap.c: swapin_thread

kern/sched_prim.c: sched_thread


kern/bootstrap.c: bootstrap_create

The ?multiboot modules have been put somewhere into memory by GRUB. The boot scripts are parsed. The modules' ELF image's PT_LOAD sections are ``read'' (that is, vm_allocate and copyout) and turned into real tasks. The multiboot modules' memory regions can be deallocated then.


vm_pageout: run the paging out daemon

Does not return.

IRC, freenode, #hurd, 2013-10-07

<cureOS> look, where should i dig or where from should i start from, if i
  have desire to know how the kernel was written from baremetal? Can it be
  ever done nowadays?
<youpi> cureOS: the boot entry of the kernel is i386/i386at/boothdr.S ,
<youpi> that's what grub jumps to
<youpi> then that jumps to c_boot_entry
<youpi> and everything else is C
<cureOS> grub loads it somehow. how does it prepare cpu and memoty, cpu
  cache control if any... segments for stack..
<youpi> see the grub documentation
<youpi> basically it's all flat linear space
<cureOS> does kernel transform it after that?
<youpi> see the ldt/gdt initialization
<youpi> from i386at_init and children
<youpi> nothing much fancy, a kernel cs/ds, and user cs/ds
<braunr> and paging, naturally
<youpi> sure