descriptionbootstrap code for a kernel
ownersylvain.bertrand@gmail.com
last changeTue, 31 Jan 2023 15:26:08 +0000 (31 15:26 +0000)
content tags
add:
README
This uses aggressively stripped down/derived and "gcc/clang/icc free" linux based
code. There is not intent to deviate that much from linux internal design.

In this current state, this is minimaly tested bootstrap code, you get:
 - boot cpu core.
 - ring0 in kernel virtual address space.
 - hardware tracer with usb dbc (currently enabled by default, see below for how to use it).
 - 2MiB page allocator properly inited (based on efi memory map, and currently untested).

Development happened on amd zen2 cpu/msi uefi motherboard.
	
Used sdk:
 - c compilers: tcc and cproc (gcc/clang/icc should work, but are not recommended as those are
   filthy toxic).
 - assemblers: binutils as, nasm/yasm, fasmg. Namely intel syntax, you have a vim syntax highlighter
               in $src_dir/vim.
 - linker: binutils ld.

Build scripts are brutally simple and idiotic on purpose:
 1 - run $src_dir/configure in your $build_dir (currently the configuration is hardcoded)
 2 - configure the sdk at the start of $src_dir/arch/x64/kernel/make_vmnyan.sh
 3 - build the kernel running $src_dir/arch/x64/kernel/make_vmnyan.sh in your $build_dir
 4 - configure the sdk at the start of $src_dir/arch/x64/boot/efi/make_os_loader.sh
 5 - build the uefi os loader running $src_dir/arch/x64/boot/efi/make_os_loader.s in your $build_dir

usb dbc hardware tracer: usb dbc requires a modern hardware controller (usually from usb3). You need
another computer with a usb dbc enabled driver, a usb host-to-host cable. Then you need to discover
the "first" default (in pci enumeration order) usb dbc port on the traced computer (or manually
select it, see below, but it is not recommended):
	1 - boot on the nyankernel efi os loader: bootx64.efi (efi shell of efi boot entry). Then it
	    will hang waiting for an handcheck from the tracer computer, see below.
	2 - plug the usb host-to-host cable on the "first" default usb dbc port and the other side
	    on the traced computer and the tracer computer.
	3 - check the traced computer is properly announced on the tracer computer. On elf/linux,
	    dmesg command.
	4 - get ready to download the trace messages on the tracer computer: on elf/linux, it 
	    usually means something like: cat /dev/ttyUSB0 >/tmp/mytracefile
	5 - handcheck: send a random line from the tracer computer to the traced computer. On 
	    elf/linux, it usually means something like: echo "I am ready to trace" >/dev/ttyUSB0
	6 - Flush the file buffers on the tracer computer, then inspect the content of your trace
	    file. On elf/linux, sync;cat /tmp/mytracefile

Manual selection of the usb dbc port on the traced system: on the efi boot command (efi shell or efi
boot entry), use the "dbc=GGGGBBDDFF" command line option, with GGGG being the pci group, BB the bus
number, DD, the device number, FF the function number, all using hexadecimal radix. For example, in
your efi boot command (efi shell or efi boot entry): bootx64.efi dbc=0000a0201

NOTE: It is easier to look for the default usb dbc ports using the tracer computer: once bootx64.efi
runs, plug the usb host-to-host cable on the traced computer until you see it properly detected
and configured on the tracer computer.

WARNING: a nasty usb dbc hardware bug from the amd matisse usb controller (cpu and motheboard) was
         worked around (not idea if it was fixed on Zen3 or Zen4).

Future would go the following ways:
 - using 2MiB pages, not 4KiB pages.
 - only relocatable kernel.
 - initrd only in kernel image.
 - 4lvls and 5lvls are different kernels. 
 - turn on and off, aka no hibernation or suspend to ram.
 - no swap.
 - no hotplug for core components: cpu/ram/etc.
 - physical address mapping of memory from from the hardware should be as low as possible. But
   binary trees may happen for "struct page" from/to pfn mapping.
 - iommu.

Misc:
 - In assembly, we relax the stack alignment from the sysv abi for function calls. The assembly code
   must know if it calls such a function or not (usually generic c code).
shortlog
2023-01-31 Sylvain BERTRANDInitial commitmaster
heads
14 months ago master