### Launch GRUB install application Source: https://osdev.wiki/wiki/GRUB_Legacy?action=edit Start the GRUB installation utility. ```bash sudo grub ``` -------------------------------- ### Building and Installing Source: https://osdev.wiki/wiki/Porting_Newlib?section=1&veaction=edit Commands to compile and install the configured software. ```bash make && make install ``` -------------------------------- ### QEMU GDB Connection Setup Source: https://osdev.wiki/wiki/Kernel_Debugging?action=edit Commands to start QEMU in debug mode and connect via GDB. ```bash qemu -s -S ``` ```bash (gdb) target remote localhost:1234 ``` -------------------------------- ### Complete GRUB installation from shell Source: https://osdev.wiki/wiki/GRUB_Legacy?action=edit Run the install command within the GRUB shell to finalize the boot setup. ```bash install (fd0)/boot/stage1 (fd0) (fd0)/boot/stage2 (fd0)/boot/menu.cfg ``` -------------------------------- ### Setup Environment for Platforms Source: https://osdev.wiki/wiki/EDK2?action=edit Sources the setup script and builds the base tools for the platforms workspace. ```bash . edk2/edksetup.sh make -C edk2/BaseTools ``` -------------------------------- ### Install Specific Dependency Source: https://osdev.wiki/wiki/Building_GCC Example command for installing the GMP development library on Debian-based systems. ```bash sudo apt install libgmp3-dev ``` -------------------------------- ### Install and Start VFD Driver Source: https://osdev.wiki/wiki/Virtual_Floppy_Disk Commands to install and initialize the VFD device driver on Windows. ```bash vfd.exe install /AUTO vfd.exe start ``` -------------------------------- ### Task Definitions and Initialization Source: https://osdev.wiki/wiki/ARM_Integrator-CP_IRQTimerAndPICAndTaskSwitch?action=edit§ion=6 Example thread functions and the start routine that configures the scheduler state, thread stacks, and hardware peripherals. ```c void thread2() { int x; for (;;) { for (x = 0; x < 0xfffff; ++x); kserdbg_putc('B'); } } void thread1() { int x; for (;;) { for (x = 0; x < 0xfffff; ++x); kserdbg_putc('A'); asm("swi #4"); } } void start() { uint32 *t0mmio; uint32 *picmmio; KSTATE *ks; int x; ks = (KSTATE*)KSTATEADDR; kserdbg_putc('Y'); /* ============ SCHEDULER TASK SETUP ============= */ /* lets scheduler know this is going to be the first switch */ ks->iswitch = 1; for (x = 0; x < 0x10; ++x) { ks->threads[x].valid = 0; } /* this currently executing thread and stack will be discarded when these run */ ks->threads[0].pc = (uint32)&thread1; ks->threads[0].valid = 1; ks->threads[0].cpsr = 0x60000000 | ARM4_MODE_USER; ks->threads[0].sp = 0x5000; ks->threads[0].ksp = 0x6000; ks->threads[1].pc = (uint32)&thread2; ks->threads[1].valid = 1; ks->threads[1].cpsr = 0x60000000 | ARM4_MODE_USER; ks->threads[1].sp = 0x7000; ks->threads[1].ksp = 0x8000; /* the first thread to run */ ks->threadndx = 0x0; arm4_xrqinstall(ARM4_XRQ_RESET, &k_exphandler_reset_entry); arm4_xrqinstall(ARM4_XRQ_UNDEF, &k_exphandler_undef_entry); arm4_xrqinstall(ARM4_XRQ_SWINT, &k_exphandler_swi_entry); arm4_xrqinstall(ARM4_XRQ_ABRTP, &k_exphandler_abrtp_entry); arm4_xrqinstall(ARM4_XRQ_ABRTD, &k_exphandler_abrtd_entry); arm4_xrqinstall(ARM4_XRQ_IRQ, &k_exphandler_irq_entry); arm4_xrqinstall(ARM4_XRQ_FIQ, &k_exphandler_fiq_entry); kserdbg_putc('Z'); /* enable IRQ */ arm4_cpsrset(arm4_cpsrget() & ~(1 << 7)); /* initialize timer and PIC The timer interrupt line connects to the PIC. You can make the timer interrupt an IRQ or FIQ just by enabling the bit needed in either the IRQ or FIQ registers. Here I use the IRQ register. If you enable both IRQ and FIQ then FIQ will take priority and be used. */ picmmio = (uint32*)0x14000000; picmmio[PIC_IRQ_ENABLESET] = (1<<5) | (1<<6) | (1<<7); /* See datasheet for timer initialization details. */ t0mmio = (uint32*)0x13000000; t0mmio[REG_LOAD] = 0xffffff; t0mmio[REG_BGLOAD] = 0xffffff; t0mmio[REG_CTRL] = CTRL_ENABLE | CTRL_MODE_PERIODIC | CTRL_SIZE_32 | CTRL_DIV_NONE | CTRL_INT_ENABLE; t0mmio[REG_INTCLR] = ~0; /* make sure interrupt is clear (might not be mandatory) */ kserdbg_putc('K'); kserdbg_putc('\n'); /* infinite loop */ for(;;); } ``` -------------------------------- ### Build and Install Libsupc++ Source: https://osdev.wiki/wiki/Libsupcxx Configure, build, and install the libsupc++ library components. ```bash CPP=i686-elf-cpp ./configure --host=i686-elf --prefix=/usr/local/cross --disable-hosted-libstdcxx \ --disable-nls cd include make make install cd ../libsupc++ make make install ``` -------------------------------- ### Headers Installation Script Source: https://osdev.wiki/wiki/Meaty_Skeleton?action=edit§ion=42 Creates the system root and installs headers for required projects. ```bash #!/bin/sh set -e . ./config.sh mkdir -p "$SYSROOT" for PROJECT in $SYSTEM_HEADER_PROJECTS; do (cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install-headers) done ``` -------------------------------- ### Install dependencies via package managers Source: https://osdev.wiki/wiki/GCC_Cross-Compiler Example command for installing a specific dependency on Debian-based systems. ```bash sudo apt install libgmp3-dev ``` -------------------------------- ### Build and install mkgpt Source: https://osdev.wiki/wiki/UEFI_App_Bare_Bones?action=edit§ion=1 Compiles and installs the mkgpt utility from source. ```bash git clone https://github.com/jncronin/mkgpt.git cd mkgpt automake --add-missing autoreconf ./configure make sudo make install ``` -------------------------------- ### View Setup Help Output Source: https://osdev.wiki/wiki/Cygwin_Issues?section=3&veaction=edit Accesses the setup utility help output, which is redirected to a log file rather than standard output. ```bash setup --help; tail setup.log ``` -------------------------------- ### Initialize GCC Build Source: https://osdev.wiki/wiki/GCC_Cross-Compiler?action=edit Starts the GCC build process after ensuring the installation prefix is in the system PATH. ```bash cd ~/src # The $PREFIX/bin dir _must_ be in the PATH. We did that above. ``` -------------------------------- ### Configuring and Installing Automake Source: https://osdev.wiki/wiki/Porting_Newlib?action=edit§ion=3 Configure Automake with a custom prefix and install it. ```bash ../automake-1.11/configure --prefix="~/bin" ``` ```bash make && make install ``` -------------------------------- ### Execute GRUB setup commands Source: https://osdev.wiki/wiki/GRUB_Legacy?action=edit Run the root and setup commands within the GRUB utility. ```bash root (hd1,1) setup (hd1) quit ``` -------------------------------- ### Build and install GRUB with network support Source: https://osdev.wiki/wiki/GRUB_Legacy?action=edit Configures GRUB with specific driver support, compiles the source, and installs the binaries. ```bash ./configure --enable-tulip make make install ``` -------------------------------- ### Install GRUB Source: https://osdev.wiki/wiki/GRUB?action=edit§ion=9 Installs GRUB to the MBR loop device. ```bash sudo grub-install --root-directory=/mnt --no-floppy --modules="normal part_msdos ext2 multiboot" /dev/loop0 ``` -------------------------------- ### Initialize Kernel and Hardware Source: https://osdev.wiki/wiki/ARM_Integrator-CP_IRQTimerAndPICAndTaskSwitch?mobileaction=toggle_view_desktop Configures the scheduler, installs exception handlers, and initializes the timer and PIC hardware. This function serves as the entry point for the kernel setup. ```c void start() { uint32 *t0mmio; uint32 *picmmio; KSTATE *ks; int x; ks = (KSTATE*)KSTATEADDR; kserdbg_putc('Y'); /* ============ SCHEDULER TASK SETUP ============= */ /* lets scheduler know this is going to be the first switch */ ks->iswitch = 1; for (x = 0; x < 0x10; ++x) { ks->threads[x].valid = 0; } /* this currently executing thread and stack will be discarded when these run */ ks->threads[0].pc = (uint32)&thread1; ks->threads[0].valid = 1; ks->threads[0].cpsr = 0x60000000 | ARM4_MODE_USER; ks->threads[0].sp = 0x5000; ks->threads[0].ksp = 0x6000; ks->threads[1].pc = (uint32)&thread2; ks->threads[1].valid = 1; ks->threads[1].cpsr = 0x60000000 | ARM4_MODE_USER; ks->threads[1].sp = 0x7000; ks->threads[1].ksp = 0x8000; /* the first thread to run */ ks->threadndx = 0x0; arm4_xrqinstall(ARM4_XRQ_RESET, &k_exphandler_reset_entry); arm4_xrqinstall(ARM4_XRQ_UNDEF, &k_exphandler_undef_entry); arm4_xrqinstall(ARM4_XRQ_SWINT, &k_exphandler_swi_entry); arm4_xrqinstall(ARM4_XRQ_ABRTP, &k_exphandler_abrtp_entry); arm4_xrqinstall(ARM4_XRQ_ABRTD, &k_exphandler_abrtd_entry); arm4_xrqinstall(ARM4_XRQ_IRQ, &k_exphandler_irq_entry); arm4_xrqinstall(ARM4_XRQ_FIQ, &k_exphandler_fiq_entry); kserdbg_putc('Z'); /* enable IRQ */ arm4_cpsrset(arm4_cpsrget() & ~(1 << 7)); /* initialize timer and PIC The timer interrupt line connects to the PIC. You can make the timer interrupt an IRQ or FIQ just by enabling the bit needed in either the IRQ or FIQ registers. Here I use the IRQ register. If you enable both IRQ and FIQ then FIQ will take priority and be used. */ picmmio = (uint32*)0x14000000; picmmio[PIC_IRQ_ENABLESET] = (1<<5) | (1<<6) | (1<<7); /* See datasheet for timer initialization details. */ t0mmio = (uint32*)0x13000000; t0mmio[REG_LOAD] = 0xffffff; t0mmio[REG_BGLOAD] = 0xffffff; t0mmio[REG_CTRL] = CTRL_ENABLE | CTRL_MODE_PERIODIC | CTRL_SIZE_32 | CTRL_DIV_NONE | CTRL_INT_ENABLE; t0mmio[REG_INTCLR] = ~0; /* make sure interrupt is clear (might not be mandatory) */ kserdbg_putc('K'); kserdbg_putc('\n'); /* infinite loop */ for(;;); } ``` -------------------------------- ### Build and Install GDB Source: https://osdev.wiki/wiki/RISC-V_Meaty_Skeleton_with_QEMU_virt_board?action=edit Compiles the source code and installs the resulting binary. ```bash make -j$(nproc) ``` ```bash make -C gdb install ``` -------------------------------- ### Install GDB Source: https://osdev.wiki/wiki/RISC-V_Meaty_Skeleton_with_QEMU_virt_board Install the compiled binaries to the prefix directory. ```bash make -C gdb install ``` -------------------------------- ### Example boot output Source: https://osdev.wiki/wiki/PowerPC_Bare_Bones Expected console output from OpenBIOS during the boot process. ```text Welcome to OpenBIOS v1.1 built on Mar 7 2023 22:21 Trying hd:,\\:tbxi... Trying hd:,\ppc\bootinfo.txt... test string >> switching to new context: ``` -------------------------------- ### Configuring and Installing Autoconf Source: https://osdev.wiki/wiki/Porting_Newlib?action=edit§ion=3 Configure Autoconf with a custom prefix and install it. ```bash ../autoconf-2.65/configure --prefix=~/bin ``` ```bash make && make install ``` -------------------------------- ### Kernel Initialization Example Source: https://osdev.wiki/wiki/User%3AZesterer/Bare_Bones?action=edit A basic snippet demonstrating terminal initialization and printing. ```c // Initiate terminal term_init(); // Display some messages term_print("Hello, World!\n"); term_print("Welcome to the kernel.\n"); } ``` -------------------------------- ### GRUB2 Configuration Source: https://osdev.wiki/wiki/Creating_a_64-bit_kernel?action=edit§ion=11 Example menuentry for loading a kernel via GRUB2. ```text menuentry "My Kernel" { multiboot } ``` -------------------------------- ### Install SysLinux on a Linux Device Source: https://osdev.wiki/wiki/SysLinux Example command for installing SysLinux on a floppy device. ```text syslinux /dev/fd0 ``` -------------------------------- ### Invoke QEMU with standard configuration Source: https://osdev.wiki/wiki/QEMU Example command to launch a guest system with specific CPU, memory, and drive settings. ```bash qemu-system-i386 \ -accel tcg,thread=single \ -cpu core2duo \ -m 128 \ -no-reboot \ -drive format=raw,media=cdrom,file=myos.iso \ -serial stdio \ -smp 1 \ -usb \ -vga std ``` -------------------------------- ### Build and install Newlib Source: https://osdev.wiki/wiki/Porting_Newlib Commands to configure, build, and install Newlib into a specified system root directory. ```bash mkdir build-newlib cd build-newlib ../newlib-x.y.z/configure --prefix=/usr --target=i686-myos make all make DESTDIR=${SYSROOT} install ``` -------------------------------- ### Start OS in QEMU Source: https://osdev.wiki/wiki/Multiboot2_Bare_Bones?action=edit Launch a virtual machine using the generated ISO file. ```bash qemu-system-i386 -cdrom myos.iso ``` -------------------------------- ### Prepare Environment and Download Sources Source: https://osdev.wiki/wiki/Cannot_perform_PE_operations_on_non-PE_file Sets up the installation prefix, updates the PATH, and downloads the required source archives for the toolchain. ```bash export PREFIX="$HOME/.local/cross" export TARGET=i686-elf echo "export PATH=\"$PREFIX/bin:\$PATH\"" >> ~/.bashrc source ~/.bashrc # you can set the following variable if you know how to get the amount of cpus on your system. Linux is shown below MAKEFLAGS="-j$(nproc)" mkdir ~/src cd ~/src # Download and prepare the source directories curl -LO https://ftp.gnu.org/gnu/binutils/binutils-X.Y.Z.tar.xz curl -LO https://ftp.gnu.org/gnu/gcc/gcc-X.Y.Z/gcc-X.Y.Z.tar.xz curl -LO https://ftp.gnu.org/gnu/gmp/gmp-X.Y.Z.tar.xz curl -LO https://ftp.gnu.org/gnu/mpfr/mpfr-X.Y.Z.tar.xz curl -LO https://ftp.gnu.org/gnu/mpc/mpc-X.Y.Z.tar.gz curl -LO https://libisl.sourceforge.io/isl-X.Y.Z.tar.xz for i in *.xz; do xz -d $i done for i in *.gz; do gzip -d $i done for i in *.tar; do tar -xf $i done ``` -------------------------------- ### Build and Install BMFS Source: https://osdev.wiki/wiki/BMFS?action=edit§ion=8 Commands to clone the repository and install the utility on the development machine. ```bash git clone https://github.com/ReturnInfinity/BMFS cd BMFS make sudo make install ``` -------------------------------- ### Install ARM Exception Handlers and Initialize Hardware Source: https://osdev.wiki/wiki/ARM_Integrator-CP_IRQTimerAndPIC?action=edit§ion=3 Defines naked exception handler entry points and installs them into the vector table, followed by PIC and Timer configuration. ```c */ k_serdbg_putc('!'); for(;;); } return; } void __attribute__((naked)) k_exphandler_irq_entry() { KEXP_TOP3; k_exphandler(lr, ARM4_XRQ_IRQ); KEXP_BOT3; } void __attribute__((naked)) k_exphandler_fiq_entry() { KEXP_TOP3; k_exphandler(lr, ARM4_XRQ_FIQ); KEXP_BOT3; } void __attribute__((naked)) k_exphandler_reset_entry() { KEXP_TOP3; k_exphandler(lr, ARM4_XRQ_RESET); KEXP_BOT3; } void __attribute__((naked)) k_exphandler_undef_entry() { KEXP_TOP3; k_exphandler(lr, ARM4_XRQ_UNDEF); KEXP_BOT3; } void __attribute__((naked)) k_exphandler_abrtp_entry() { KEXP_TOP3; k_exphandler(lr, ARM4_XRQ_ABRTP); KEXP_BOT3; } void __attribute__((naked)) k_exphandler_abrtd_entry() { KEXP_TOP3; k_exphandler(lr, ARM4_XRQ_ABRTD); KEXP_BOT3; } void __attribute__((naked)) k_exphandler_swi_entry() { KEXP_TOPSWI; k_exphandler(lr, ARM4_XRQ_SWINT); KEXP_BOT3; } void arm4_xrqinstall(uint32 ndx, void *addr) { char buf[32]; uint32 *v; v = (uint32*)0x0; v[ndx] = 0xEA000000 | (((uintptr)addr - (8 + (4 * ndx))) >> 2); } void start() { uint32 *t0mmio; uint32 *picmmio; arm4_xrqinstall(ARM4_XRQ_RESET, &k_exphandler_reset_entry); arm4_xrqinstall(ARM4_XRQ_UNDEF, &k_exphandler_undef_entry); arm4_xrqinstall(ARM4_XRQ_SWINT, &k_exphandler_swi_entry); arm4_xrqinstall(ARM4_XRQ_ABRTP, &k_exphandler_abrtp_entry); arm4_xrqinstall(ARM4_XRQ_ABRTD, &k_exphandler_abrtd_entry); arm4_xrqinstall(ARM4_XRQ_IRQ, &k_exphandler_irq_entry); arm4_xrqinstall(ARM4_XRQ_FIQ, &k_exphandler_fiq_entry); k_serdbg_putc('Z'); asm("swi #4"); /* enable IRQ */ arm4_cpsrset(arm4_cpsrget() & ~(1 << 7)); /* initialize timer and PIC The timer interrupt line connects to the PIC. You can make the timer interrupt an IRQ or FIQ just by enabling the bit needed in either the IRQ or FIQ registers. Here I use the IRQ register. If you enable both IRQ and FIQ then FIQ will take priority and be used. */ picmmio = (uint32*)0x14000000; picmmio[PIC_IRQ_ENABLESET] = (1<<5) | (1<<6) | (1<<7); /* See datasheet for timer initialization details. */ t0mmio = (uint32*)0x13000000; t0mmio[REG_LOAD] = 0xffffff; t0mmio[REG_BGLOAD] = 0xffffff; t0mmio[REG_CTRL] = CTRL_ENABLE | CTRL_MODE_PERIODIC | CTRL_SIZE_32 | CTRL_DIV_NONE | CTRL_INT_ENABLE; t0mmio[REG_INTCLR] = ~0; /* make sure interrupt is clear (might not be mandatory) */ k_serdbg_putc('K'); k_serdbg_putc('\n'); /* infinite loop */ for(;;); } ``` -------------------------------- ### Booting an OS with QEMU Source: https://osdev.wiki/wiki/Multiboot1_Bare_Bones?action=edit§ion=13 Commands to launch a virtual machine with a kernel image or ISO. ```bash qemu-system-i386 -cdrom myos.iso ``` ```bash qemu-system-i386 -kernel myos.bin ``` -------------------------------- ### Sample grub.cfg configuration Source: https://osdev.wiki/wiki/GRUB_2 Example configuration file for GRUB 2, defining the timeout and a kernel boot entry. ```text set timeout=15 set default=0 # Set the default menu entry menuentry "OS Name" { # The multiboot command replaces the kernel command # For multiboot v2, use the multiboot2 command multiboot /boot/kernel-file boot } ``` -------------------------------- ### Calling Get Cached Information Source: https://osdev.wiki/wiki/PXE?action=edit Example of invoking the Get Cached Information function using the generic API wrapper. ```asm mov di, t_PXENV_GET_CACHED mov bx, GET_CACHED_INFO ; 0x0071. call UsePXEAPI ; Ask for the cached info. or ax, [t_PXENV_GET_CACHED] ; Get the status into AX. test ax, ax jnz .Error ``` -------------------------------- ### Prepare Environment and Download Source Files Source: https://osdev.wiki/wiki/GCC_Cross-Compiler?action=edit&mobileaction=toggle_view_desktop§ion=10 Sets up installation prefixes, updates the shell configuration, and downloads the required GNU toolchain components. ```bash export PREFIX="$HOME/.local/cross" export TARGET=i686-elf echo "export PATH=\"$PREFIX/bin:\$PATH\"" >> ~/.bashrc source ~/.bashrc # you can set the following variable if you know how to get the amount of cpus on your system. Linux is shown below MAKEFLAGS="-j$(nproc)" mkdir ~/src cd ~/src # Download and prepare the source directories curl -LO https://ftp.gnu.org/gnu/binutils/binutils-X.Y.Z.tar.xz curl -LO https://ftp.gnu.org/gnu/gcc/gcc-X.Y.Z/gcc-X.Y.Z.tar.xz curl -LO https://ftp.gnu.org/gnu/gmp/gmp-X.Y.Z.tar.xz curl -LO https://ftp.gnu.org/gnu/mpfr/mpfr-X.Y.Z.tar.xz curl -LO https://ftp.gnu.org/gnu/mpc/mpc-X.Y.Z.tar.gz curl -LO https://libisl.sourceforge.io/isl-X.Y.Z.tar.xz for i in *.xz; do xz -d $i done for i in *.gz; do gzip -d $i done for i in *.tar; do tar -xf $i done ``` -------------------------------- ### TSS Initialization and GDT Setup Source: https://osdev.wiki/wiki/Getting_to_Ring_3?action=edit§ion=3 Configures the TSS entry and installs it into the Global Descriptor Table (GDT). ```c // Note: some of the GDT entry struct field names may not match perfectly to the TSS entries. tss_entry_t tss_entry; void write_tss(gdt_entry_bits *g) { // Compute the base and limit of the TSS for use in the GDT entry. uint32_t base = (uint32_t) &tss_entry; uint32_t limit = sizeof tss_entry; // Add a TSS descriptor to the GDT. g->limit_low = limit; g->base_low = base; g->accessed = 1; // With a system entry (`code_data_segment` = 0), 1 indicates TSS and 0 indicates LDT g->read_write = 0; // For a TSS, indicates busy (1) or not busy (0). g->conforming_expand_down = 0; // always 0 for TSS g->code = 1; // For a TSS, 1 indicates 32-bit (1) or 16-bit (0). g->code_data_segment=0; // indicates TSS/LDT (see also `accessed`) g->DPL = 0; // ring 0, see the comments below g->present = 1; g->limit_high = (limit & (0xf << 16)) >> 16; // isolate top nibble g->available = 0; // 0 for a TSS g->long_mode = 0; g->big = 0; // should leave zero according to manuals. g->gran = 0; // limit is in bytes, not pages g->base_high = (base & (0xff << 24)) >> 24; //isolate top byte // Ensure the TSS is initially zero'd. memset(&tss_entry, 0, sizeof tss_entry); tss_entry.ss0 = REPLACE_KERNEL_DATA_SEGMENT; // Set the kernel stack segment. tss_entry.esp0 = REPLACE_KERNEL_STACK_ADDRESS; // Set the kernel stack pointer. //note that CS is loaded from the IDT entry and should be the regular kernel code segment } void set_kernel_stack(uint32_t stack) { // Used when an interrupt occurs tss_entry.esp0 = stack; } ``` -------------------------------- ### Download and Prepare Build Environment Source: https://osdev.wiki/wiki/GCC_and_Libc%2B%2B?action=edit Commands to fetch newlib, libcxxabi, and libcxx sources and prepare the directory structure. ```bash wget ftp://sourceware.org/pub/newlib/newlib-2.3.0.20160104.tar.gz git clone http://llvm.org/git/libcxxabi git clone http://llvm.org/git/libcxx tar xvf newlib*.tar.gz mv newlib-*/ newlib/ mkdir build-newlib ``` -------------------------------- ### Interrupt Handler Installation and Removal Source: https://osdev.wiki/wiki/ACPICA?mobileaction=toggle_view_desktop Functions for managing ACPI interrupt handlers, including a custom implementation example. ```c ACPI_STATUS AcpiOsInstallInterruptHandler(UINT32 InterruptLevel, ACPI_OSD_HANDLER Handler, void *Context) ``` ```c uint32_t handler(void *); ``` ```c #include ACPI_OSD_HANDLER ServiceRout; InterruptState *AcpiInt(InterruptState *ctx, void *Context) { ServiceRout(Context); return ctx; } UINT32 AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine, void *Context) { ServiceRout = ServiceRoutine; RegisterIrq(InterruptNumber, AcpiInt, Contex); return AE_OK; } ``` ```c ACPI_STATUS AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER Handler) ``` -------------------------------- ### GDB Initialization Script Source: https://osdev.wiki/wiki/QEMU?action=edit§ion=12 An example .gdbinit file used to load symbols and connect to the QEMU GDB stub. ```gdb file target remote localhost:1234 # Inspect page tables x /8wg &page_tables_start ``` -------------------------------- ### Implement AcpiOsInstallInterruptHandler Source: https://osdev.wiki/wiki/ACPICA?action=edit§ion=35 Example implementation of the interrupt handler installation function, including a wrapper for custom IRQ managers. ```c #include ACPI_OSD_HANDLER ServiceRout; InterruptState *AcpiInt(InterruptState *ctx, void *Context) { ServiceRout(Context); return ctx; } UINT32 AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine, void *Context) { ServiceRout = ServiceRoutine; RegisterIrq(InterruptNumber, AcpiInt, Contex); return AE_OK; } ``` -------------------------------- ### GNU Assembler Interrupt Handler Setup Source: https://osdev.wiki/wiki/I_Can%27t_Get_Interrupts_Working?action=edit Example of setting up an interrupt handler in long mode using GAS. ```asm .text int_handler: movq $0x123abc, 0x0 // this places magic value "0x123abc" at the beginning of memory hlt .p2align 4 idt: .skip 50*16 idtr: .short (50*16)-1 .quad idt .globl do_test do_test: lidt idtr movq $int_handler, %rax mov %ax, idt+49*16 movw $0x20, idt+49*16+2 // replace 0x20 with your code section selector movw $0x8e00, idt+49*16+4 shr $16, %rax mov %ax, idt+49*16+6 shr $16, %rax mov %rax, idt+49*16+8 int $49 ``` -------------------------------- ### Build and Run Commands Source: https://osdev.wiki/wiki/Sparc_Barebones?action=edit Commands for assembling, linking, creating a bootable ISO, and running the project in QEMU. ```bash sparc-elf-as boot.S -o boot.o sparc-elf-ld boot.o -o boot.bin -T sparcboot.ld ``` ```bash dd if=/dev/zero of=bootblock.bin bs=2048 count=4 dd if=boot.bin of=bootblock.bin bs=512 seek=1 conv=notrunc mkisofs -o helloworld.iso -G bootblock.bin /path/to/other/cd/contents ``` ```bash qemu-system-sparc -cdrom helloworld.iso ``` -------------------------------- ### Setup GDC source within GCC Source: https://osdev.wiki/wiki/GDC_Cross-Compiler Run the setup script to integrate the D language support into the GCC source tree. ```bash cd /usr/src/gcc-x.x.x ./gcc/d/setup-gcc.sh ``` -------------------------------- ### Install required software on Ubuntu/Debian Source: https://osdev.wiki/wiki/Bootable_El-Torito_CD_with_GRUB_Legacy?action=edit Installs the necessary tools for creating ISO images and GRUB bootloaders. ```bash sudo apt-get install genisoimage grub ``` -------------------------------- ### Loop Device Setup Source: https://osdev.wiki/wiki/GRUB?action=edit&mobileaction=toggle_view_desktop Configure loop devices for the disk image and partition. ```bash $ sudo losetup /dev/loop0 disk.img $ sudo losetup /dev/loop1 disk.img -o 1048576 ``` -------------------------------- ### Configure EDK2 Build Environment Source: https://osdev.wiki/wiki/EDK2?action=edit Sets up environment variables and installs cross-compilers for specific architectures before sourcing the setup script. ```bash export EDK_TOOLS_PATH=$PWD/BaseTools # If you are compiling for ARM, then this is needed sudo apt install gcc-aarch64-linux-gnu # Or whatever your package manager is export GCC5_AARCH64_PREFIX=aarch64-linux-gnu- # This is needed on RISC-V sudo apt install gcc-riscv64-linux-gnu # Or whatever your package manager is export GCC5_RISCV64_PREFIX=riscv64-linux-gnu- # Run this no matter what you are compiling for source edksetup.sh ``` -------------------------------- ### Start QEMU Monitor Source: https://osdev.wiki/wiki/QEMU_Monitor Commands to launch the QEMU monitor via standard I/O or a telnet connection. ```bash qemu -hda disk.img -monitor stdio #start monitor at current shell qemu -hda disk.img -monitor telnet:127.0.0.1:[7777] #start monitor at different PC ``` -------------------------------- ### Prepare GCC and GDC Source Source: https://osdev.wiki/wiki/GDC_Cross-Compiler?action=edit Unpack GDC into the GCC source tree and run the setup script. ```bash cd /usr/src/gcc-x.x.x ./gcc/d/setup-gcc.sh ``` -------------------------------- ### Set environment variables and create build directories Source: https://osdev.wiki/wiki/GDC_Cross-Compiler?action=edit§ion=3 Defines the installation prefix and target architecture, then creates the necessary directory structure for building binutils and GCC. ```bash export PREFIX=/usr/local/cross export TARGET=i586-elf cd /usr/src mkdir build build/binutils build/gcc ``` -------------------------------- ### Allocating Header Externally with Internal Bitmap Source: https://osdev.wiki/wiki/User%3APancakes/BitmapHeapImplementationEnhanced Example of placing the block header outside the heap while keeping the bitmap at the start of the managed memory. ```c k_heapBMInit(&bmh); addr = (uintptr)malloc(SIZE); b = (KHEAPBLOCKBM*)malloc(sizeof(KHEAPBLOCKBM)); bm = (uint8*)addr; k_heapBMAddBlock(&bmh, addr, SIZE, BSIZE, b, bm, 1); ``` -------------------------------- ### Cross-compile and install software Source: https://osdev.wiki/wiki/Cross-Porting_Software Use this sequence to configure, build, and install software into a system root directory. Ensure cross-compilation tools are correctly set to avoid using local host tools. ```bash # Potentially unset CC and such here (see configure --help) to prevent local # tools from being mistakenly used as cross-tools. Alternatively, set them to # your cross-tools unconditionally. Note also the existence of CC_FOR_BUILD in # the case of packages that needs to build local tools to build themselves. ./configure --host=x86_64-myos --prefix=/usr make make DESTDIR=$SYSROOT install ``` -------------------------------- ### Setting up UEFI Disk Image on FreeBSD Source: https://osdev.wiki/wiki/UEFI?action=edit§ion=16 Commands to configure a block device, create GPT tables, and add an EFI partition. ```bash $ mdconfig -f /path/to/uefi.img md0 ``` ```bash $ gpart create -s GPT md0 md0 created ``` ```bash $ gpart add -t efi md0 md0p1 added ``` -------------------------------- ### CFE Boot Output Example Source: https://osdev.wiki/wiki/CFE_Bare_Bones?action=edit§ion=4 Example output displayed in the CFE console when successfully booting a kernel from a USB device. ```text CFE> boot -elf usbdisk0:Kernel.elf Loader:elf Filesys:fat Dev:usbdisk0 File:Kernel.elf Options:(null) Loading: 0x80001000/4112 0x80003000/4096 Entry address is 0x80001000 TP1 Entry Address at 0x80000ffc = 80001000 Starting program at 0x80001000 Hello world! ``` -------------------------------- ### Example fdisk partition table output Source: https://osdev.wiki/wiki/Loopback_Device?action=edit§ion=7 Sample output showing the partition table structure after configuration. ```text Disk /path/to/c.img: 516 MB, 516096000 bytes 16 heads, 63 sectors/track, 1000 cylinders, total 1008000 sectors Units = sectors of 1 * 512 = 512 bytes Device Boot Start End Blocks Id System /path/to/c.img1 * 63 1007999 503968+ 83 Linux ``` -------------------------------- ### Install Python Source: https://osdev.wiki/wiki/Porting_Python Install the cross-compiled Python to the specified directory. ```bash make install prefix= HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="i686-myos-gcc -shared" CROSS_COMPILE=yes ``` -------------------------------- ### Initialize Directory Listing Source: https://osdev.wiki/wiki/BMFS?action=edit§ion=4 Start the process of listing a directory by initializing the file system. ```c int list_dir(const char *path) { /* Initialize the file system here. ``` -------------------------------- ### Configure boot script and entry point Source: https://osdev.wiki/wiki/PowerPC_Bare_Bones Commands to load a binary and a minimal assembly start routine for the PowerPC architecture. ```text boot &device;:&partition;,\ppc\boot.bin ``` ```asm .globl _start _start: b _start ``` -------------------------------- ### Build script Source: https://osdev.wiki/wiki/Meaty_Skeleton Iterates through project directories to install components into the system root. ```shell #!/bin/sh set -e . ./headers.sh for PROJECT in $PROJECTS; do (cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install) done ``` -------------------------------- ### Build and install GCC with D support Source: https://osdev.wiki/wiki/GDC_Cross-Compiler Configure and compile GCC with C, D, and C++ language support enabled, then install the compiler. ```bash cd /usr/src/build-gcc export PATH=$PATH:$PREFIX/bin ../gcc-x.x.x/configure --target=$TARGET --prefix=$PREFIX --disable-nls \ --enable-languages=c,d,c++ --without-headers make all-gcc make install-gcc ``` -------------------------------- ### Creating Directories Source: https://osdev.wiki/wiki/Porting_Newlib?action=edit§ion=3 Prepare the destination and build directories. ```bash mkdir ~/bin ``` ```bash mkdir build cd build ``` -------------------------------- ### Headers installation script Source: https://osdev.wiki/wiki/Meaty_Skeleton?action=edit§ion=12 Installs system headers into the sysroot directory. ```bash #!/bin/sh set -e . ./config.sh mkdir -p "$SYSROOT" for PROJECT in $SYSTEM_HEADER_PROJECTS; do (cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install-headers) done ``` ```bash chmod +x headers.sh ``` -------------------------------- ### Create and enter build directory Source: https://osdev.wiki/wiki/RISC-V_Meaty_Skeleton_with_QEMU_virt_board Prepare a separate directory for the build process. ```bash mkdir build pushd build/ ``` -------------------------------- ### Test with uefi-run Source: https://osdev.wiki/wiki/EFI Automates the creation of a temporary FAT image and QEMU execution for quick testing. ```bash $ uefi-run -b /path/to/OVMF.fd -q /path/to/qemu app.efi -- ``` -------------------------------- ### GRUB2 USB Installation Source: https://osdev.wiki/wiki/GRUB?action=edit&mobileaction=toggle_view_desktop Install GRUB2 onto a mounted USB device. ```bash sudo grub-install --root-directory=/media/YourLabel --no-floppy --recheck --force /dev/sdX ``` -------------------------------- ### Initialize GPT on FreeBSD Source: https://osdev.wiki/wiki/EFI Creates a GPT partition table on the attached device. ```bash $ gpart create -s GPT md0 md0 created ``` -------------------------------- ### Exception Vector Installation Source: https://osdev.wiki/wiki/ARM_Integrator-CP_IRQTimerAndPIC Installs a branch instruction at the specified vector index. ```c void arm4_xrqinstall(uint32 ndx, void *addr) { char buf[32]; uint32 *v; v = (uint32*)0x0; v[ndx] = 0xEA000000 | (((uintptr)addr - (8 + (4 * ndx))) >> 2); } ``` -------------------------------- ### Create a basic UEFI Hello World application Source: https://osdev.wiki/wiki/UEFI_App_Bare_Bones A minimal UEFI application that prints a message to the console and waits for a keystroke. ```c #include #include EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { EFI_STATUS Status; EFI_INPUT_KEY Key; /* Store the system table for future use in other functions */ ST = SystemTable; /* Say hi */ Status = ST->ConOut->OutputString(ST->ConOut, L"Hello World\r\n"); // EFI Applications use Unicode and CRLF, a la Windows if (EFI_ERROR(Status)) return Status; /* Now wait for a keystroke before continuing, otherwise your message will flash off the screen before you see it. First, we need to empty the console input buffer to flush out any keystrokes entered before this point */ Status = ST->ConIn->Reset(ST->ConIn, FALSE); if (EFI_ERROR(Status)) return Status; /* Now wait until a key becomes available. This is a simple polling implementation. You could try and use the WaitForKey event instead if you like */ while ((Status = ST->ConIn->ReadKeyStroke(ST->ConIn, &Key)) == EFI_NOT_READY) ; return Status; } ``` -------------------------------- ### Execute application on BeagleBoard Source: https://osdev.wiki/wiki/ARM_Beagleboard?action=edit§ion=17 Use the 'go' command followed by the start address to initiate the application. ```asm OMAP3 beagleboard.org # go 0x80200000 ``` ```asm ## Starting application at 0x80200000 ... ! ``` -------------------------------- ### Build script Source: https://osdev.wiki/wiki/Meaty_Skeleton?section=35&veaction=edit Iterates through projects and executes the make install command. ```shell #!/bin/sh set -e . ./headers.sh for PROJECT in $PROJECTS; do (cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install) done ``` ```shell chmod +x build.sh ``` -------------------------------- ### Verify libgcc installation Source: https://osdev.wiki/wiki/Libgcc_without_red_zone?section=7&veaction=edit Check the installed libgcc.a archives to confirm the multilib build. ```bash find $TOOLCHAIN_PREFIX/lib -name 'libgcc.a' ``` ```text ./gcc/x86_64-pc-elf/4.9.1/libgcc.a ./gcc/x86_64-pc-elf/4.9.1/no-red-zone/libgcc.a ``` -------------------------------- ### Create ISO and test in QEMU Source: https://osdev.wiki/wiki/D_Bare_Bones_With_LDC2?action=edit§ion=3 Commands to generate a bootable ISO image and execute it within the QEMU emulator. ```bash mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 16 \ -boot-info-table -input-charset UTF-8 -o xomb.iso ./iso qemu-system-x86_64 -cdrom xomb.iso ``` -------------------------------- ### Install Clang on Debian Source: https://osdev.wiki/wiki/LLVM_Cross-Compiler?action=edit§ion=4 Install the Clang compiler on a Debian-based system using apt-get. ```bash sudo apt-get install clang ``` -------------------------------- ### Create and run UEFI CD image Source: https://osdev.wiki/wiki/UEFI_App_Bare_Bones?action=edit§ion=12 Commands to prepare an ISO directory, generate an El Torito bootable ISO, and launch it via QEMU with OVMF firmware. ```bash mkdir iso cp fat.img iso xorriso -as mkisofs -R -f -e fat.img -no-emul-boot -o cdimage.iso iso qemu-system-x86_64 -L OVMF_dir/ -pflash OVMF.fd -cdrom cdimage.iso ``` -------------------------------- ### Linker error example Source: https://osdev.wiki/wiki/Pascal_Bare_Bones?mobileaction=toggle_view_desktop Example of a linker error output when architecture mismatch occurs. ```text i386-linux-ld --gc-sections -s -Tlinker.script -o kernel.obj stub.o kernel.o multiboot.o console.o system.o ld: i386 architecture of input file `stub.o' is incompatible with i386:x86-64 output ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output ld: i386 architecture of input file `multiboot.o' is incompatible with i386:x86-64 output ld: i386 architecture of input file `console.o' is incompatible with i386:x86-64 output ld: i386 architecture of input file `system.o' is incompatible with i386:x86-64 output make: *** [Makefile:27: _LD] Error 1 ``` -------------------------------- ### Setup Loop Devices Source: https://osdev.wiki/wiki/GRUB?action=edit§ion=9 Configures loop devices for the MBR and the partition offset. ```bash $ sudo losetup /dev/loop0 disk.img $ sudo losetup /dev/loop1 disk.img -o 1048576 ``` -------------------------------- ### Setup loop device and format filesystem Source: https://osdev.wiki/wiki/Bootable_Disk Configures a loop device for the partition and formats it as FAT16. ```bash $ losetup -o $[2048*512] --sizelimit $[8*1024*1024] -f diskimage.dd ``` ```bash $ losetup -a ``` ```bash $ mkfs.vfat -F 16 -n "EFI System" /dev/loop0 ``` -------------------------------- ### Compile and install binutils Source: https://osdev.wiki/wiki/User%3ALionel/OSX Final build and installation commands for binutils after manual Makefile adjustments. ```bash make all sudo make install ``` -------------------------------- ### Basic QEMU Execution Command Source: https://osdev.wiki/wiki/QEMU?action=edit§ion=8 Standard command-line invocation for starting a QEMU virtual machine with specific hardware emulation settings. ```bash qemu-system-i386 \ -accel tcg,thread=single \ -cpu core2duo \ -m 128 \ -no-reboot \ -drive format=raw,media=cdrom,file=myos.iso \ -serial stdio \ -smp 1 \ -usb \ -vga std ``` -------------------------------- ### Install UEFI development dependencies Source: https://osdev.wiki/wiki/UEFI_App_Bare_Bones?action=edit§ion=1 Installs the required packages for UEFI development on Debian-based systems. ```bash sudo apt-get install qemu ovmf gnu-efi binutils-mingw-w64 gcc-mingw-w64 xorriso mtools ``` -------------------------------- ### Install SysLinux on a Floppy Disk (Windows) Source: https://osdev.wiki/wiki/SysLinux Command to install the bootloader onto a floppy drive. ```text syslinux.exe a: ``` -------------------------------- ### Sample GRUB 2 Configuration File Source: https://osdev.wiki/wiki/GRUB?action=edit§ion=7 A basic grub.cfg file template for loading a multiboot-compliant kernel. Ensure this file is placed in the /boot/grub directory of your disk image. ```bash set timeout=15 set default=0 # Set the default menu entry menuentry "OS Name" { # The multiboot command replaces the kernel command # For multiboot v2, use the multiboot2 command multiboot /boot/kernel-file boot } ``` -------------------------------- ### Install Required Packages Source: https://osdev.wiki/wiki/Stivale2_CSharp_BareBones Commands to install dependencies on a Debian-based system and register the Tysila2 package. ```bash sudo apt install nasm ld.lld xorriso qemu-system-x86 mono-runtime // First download tysila2.deb from project's repository sudo dpkg -i tysila2.deb ``` -------------------------------- ### Install Rustup and Dependencies Source: https://osdev.wiki/wiki/Raspberry_Pi_Bare_Bones_Rust Commands to install the Rust toolchain, source components, and Xargo for cross-compilation. ```bash curl https://sh.rustup.rs -sSf | sh ``` ```bash rustup component add rust-src ``` ```bash cargo install xargo ``` -------------------------------- ### Create and configure a disk image for Limine Source: https://osdev.wiki/wiki/Limine_Bare_Bones?action=edit§ion=11 Commands to prepare a 64MiB disk image, partition it, and install the Limine bootloader files. ```bash # Create an empty zeroed-out 64MiB image file. dd if=/dev/zero bs=1M count=0 seek=64 of=image.hdd # Create a partition table. PATH=$PATH:/usr/sbin:/sbin sgdisk image.hdd -n 1:2048 -t 1:ef00 -m 1 # Download the latest Limine binary release. curl -L https://github.com/Limine-Bootloader/Limine/releases/latest/download/limine-binary.tar.gz | gunzip | tar -xf - # Build "limine" utility. make -C limine-binary # Install the Limine BIOS stages onto the image. ./limine-binary/limine bios-install image.hdd # Format the image as fat32. mformat -i image.hdd@@1M # Make relevant subdirectories. mmd -i image.hdd@@1M ::/EFI ::/EFI/BOOT ::/boot ::/boot/limine # Copy over the relevant files. mcopy -i image.hdd@@1M bin/myos ::/boot mcopy -i image.hdd@@1M limine.conf limine-binary/limine-bios.sys ::/boot/limine mcopy -i image.hdd@@1M limine-binary/BOOTX64.EFI ::/EFI/BOOT mcopy -i image.hdd@@1M limine-binary/BOOTIA32.EFI ::/EFI/BOOT ``` -------------------------------- ### Library Module Configuration Source: https://osdev.wiki/wiki/User%3ASolar/Makefile Example build.mk content for defining a library module. ```makefile # CFLAGS for module 'baz' CFLAGS_baz := # Archive / Lib to build in module 'baz' baz_ARCHIVE := libbaz.a # Sources for the archive / lib 'libbaz.a' (without headers) libbaz.a_SOURCES := hashmap.c algorithm.c ``` -------------------------------- ### Create a bootable ISO image on Windows using mkisofs Source: https://osdev.wiki/wiki/Genisoimage Demonstrates creating a bootable ISO without a floppy image by configuring GRUB files in the ISO directory structure. ```bash mkdir -p $ISO_DIR/boot/grub cp $GRUB_BIN/stage2_eltorito $ISO_DIR/boot/grub cp menu.lst $ISO_DIR/boot/grub cp your_kernel $ISO_DIR mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o bootcd.iso $ISO_DIR ``` -------------------------------- ### Install system headers Source: https://osdev.wiki/wiki/Meaty_Skeleton?action=edit§ion=52 Installs system headers into the system root without requiring a compiler. ```bash ./headers.sh ``` -------------------------------- ### Kernel Installation Makefile Rule Source: https://osdev.wiki/wiki/Meaty_Skeleton?action=edit§ion=13 Makefile rule for installing the kernel binary into the boot directory. ```makefile install-kernel: myos.kernel mkdir -p $(DESTDIR)$(BOOTDIR) cp myos.kernel $(DESTDIR)$(BOOTDIR) -include $(OBJS:.o=.d) ``` -------------------------------- ### Install GCC Source: https://osdev.wiki/wiki/Building_GCC?action=edit§ion=9 The final command to install the compiled GCC binaries to the configured prefix directory. ```bash make install ``` -------------------------------- ### Install Bochs Dependencies on Ubuntu Source: https://osdev.wiki/wiki/Bochs?action=edit&mobileaction=toggle_view_desktop Command to install required development libraries for Bochs on Ubuntu. ```bash sudo apt-get install libgtk2.0-dev ```