teapot9 / cos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hobby operating system

  • Mainly developped in C.
  • Boots with UEFI.
  • Does not do anything meaningful.

This repository

Source code structure

  • arch/*: architecture-specific code
    • boot: early boot (after firmware, before kernel_main)
    • *: same as non-arch
  • dev: device drivers
  • include
  • kernel: core kernel components (task management, core functions)
  • lib: hardware independant code (ELF, string manipulation, generic structures)
  • mm: memory management

Other directories

  • build: directory generated by ./boot script for QEMU
  • scripts: helper scripts
  • third_party: external libraries dependencies

Utilities

  • ./boot: script to boot the kernel
    • ./boot efi ARGS: starts kernel with QEMU (ARGS are passed to QEMU)
    • ./boot egdb ARGS: starts GDB and use the uefi.py lib to debug kernel
  • uefi.py: GDB library to load kernel symbols during boot
    • GDB command efi: automatically called by ./boot egdb:
      • load kernel symbols to 2 positions:
        • the address where EFI has loaded the kernel
        • the address where the kernel relocates
      • read the auto.gdb file
    • GDB command qq: kill kernel and quit
    • GDB command rbreakif: like rbreak but supports a condition
  • auto.gdb: commands to run automatically by uefi.py
    • lines starting with # are ignored
    • lines starting with @ don't produce output to GDB console
    • lines starting with * are executed on when breakpoint is reached (last created breakpoint)
    • other lines are executed normally

Build

Dependencies

  • Linux kernel Kconfig: conf and mconf executables must be in PATH

Compilation

  • Configure with make menuconfig
  • Build with make

Run

Boot with GDB in a single terminal:

Run the following boot shell function:

boot() { ./boot efi ${QEMU_ARGS} & ./boot egdb "$@" ; kill -0 $! 1>/dev/null 2>&1 && kill $! ; killall qemu-system-x86_64; }

Extra args are passed to GDB. QEMU_ARGS environment variable is passed to QEMU as extra args.

Boot with GDB in 2 terminal (for GDB and QEMU console):

  • Terminal 1: ./boot efi -monitor stdio -display none
  • Terminal 2: ./boot egdb

Build system

Each directory has:

  • A Kconfig file
  • A Makefile which lists needed object files:
    • all files in the obj-y variable will be built in the final kernel
    • all files in the bootloader-y variable will be built in the bootloader (stage 1 kernel)
    • Makefile structure (in order):
      • include Makefile.flags
      • define variables (obj-y, ...)
      • include Makefile.rules
      • define build rules specific to this directory

Compilation generates in each directory:

  • *.o files for the final kernel
  • *.bootloader.o for the bootloader
  • modules.o: all *.o files merged
  • bootloader.o: all *.bootloader.o files merged
  • *.d files corresponding to their *.o counterpart

About


Languages

Language:C 92.8%Language:Python 2.3%Language:Makefile 1.7%Language:Shell 1.5%Language:C++ 1.0%Language:Assembly 0.7%Language:GDB 0.1%