in 2008 James Molloy wrote a free tutorial that taught people how to build a UNIX like operating system from scratch in C and assembly
it is called "Roll Your Own Toy UNIX Clone OS" and walks through building a real kernel step by step
bootloader, GDT, IDT, interrupts, paging, heap management, filesystems, multitasking and user mode are all covered
this is not just theory every chapter includes code you can compile run and experiment with in QEMU