├── .circleci └── config.yml ├── .clang-format ├── .codecov.yml ├── .devcontainer └── devcontainer.json ├── .dockerignore ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .travis.yml ├── .vscode ├── c_cpp_properties.json ├── cmake-kits.json ├── launch.json ├── settings.json └── tasks.json ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── NOTICE ├── README.md ├── boot ├── common │ ├── basic_printk.c │ ├── common_int.h │ ├── gfx.c │ ├── main_common_logic.c │ ├── simple_elf_loader.c │ └── stdio.c ├── efi │ ├── CMakeLists.txt │ ├── GenericBuild.cmake │ ├── defs.h │ ├── efimain.c │ ├── elf_loader.c │ ├── ia32 │ │ └── CMakeLists.txt │ ├── intf.c │ ├── multiboot.c │ ├── panic.c │ ├── ramdisk.c │ ├── setup_graphics.c │ ├── utils.c │ ├── utils.h │ └── x86_64 │ │ ├── CMakeLists.txt │ │ └── switchmode.S └── legacy │ ├── CMakeLists.txt │ ├── boot.S │ ├── boot_enable_a20.S │ ├── early_boot_script.ld │ └── stage3 │ ├── CMakeLists.txt │ ├── basic_term.c │ ├── basic_term.h │ ├── common.h │ ├── entry.S │ ├── intf.c │ ├── linker_script.ld │ ├── main.c │ ├── mm.c │ ├── mm.h │ ├── multiboot.c │ ├── panic.c │ ├── ramdisk.c │ ├── realmode_call.c │ ├── realmode_call.h │ ├── rm_calls.S │ ├── vbe.c │ └── vbe.h ├── common ├── 3rd_party │ ├── base64.c │ ├── crc32.c │ ├── datetime.c │ └── fdt_helper.c ├── README ├── arch │ └── generic_x86 │ │ └── cpu_features.c ├── asserts.c ├── fat32_base.c ├── itoa.cpp ├── misc.c ├── panic.c └── string_util.c ├── config ├── config_boot.h ├── config_debug.h ├── config_global.h ├── config_init.h ├── config_kernel.h ├── config_kmalloc.h ├── config_mm.h ├── config_sched.h ├── config_userlim.h ├── mod_acpi.h ├── mod_console.h ├── mod_debugpanel.h ├── mod_fb.h ├── mod_goldfish.h ├── mod_kb8042.h ├── mod_pci.h ├── mod_ramfb.h ├── mod_riscv_irq.h ├── mod_sb16.h ├── mod_serial.h ├── mod_sysfs.h ├── mod_systests.h ├── mod_tracing.h └── modules_list.h ├── docs ├── ancient_commits.md ├── atomics.md ├── building.md ├── code_of_conduct.md ├── contributing.md ├── coverage.md ├── debugging.md ├── figures │ ├── .gitignore │ └── overview.svg ├── pull_request_template.md ├── syscalls.md └── testing.md ├── include ├── 3rd_party │ ├── base64.h │ ├── bithacks.h │ ├── crc32.h │ └── fdt_helper.h ├── system_headers │ └── multiboot.h └── tilck │ ├── acpi │ └── actilck.h │ ├── boot │ └── common.h │ ├── common │ ├── arch │ │ ├── generic_x86 │ │ │ ├── asm_consts.h │ │ │ ├── asm_x86_strings.h │ │ │ ├── cpu_features.h │ │ │ └── x86_utils.h │ │ ├── i386 │ │ │ └── utils.h │ │ ├── riscv │ │ │ ├── asm_consts.h │ │ │ ├── asm_riscv_strings.h │ │ │ ├── image.h │ │ │ ├── riscv_utils.h │ │ │ └── utils.h │ │ └── x86_64 │ │ │ └── utils.h │ ├── assert.h │ ├── atomics.h │ ├── basic_defs.h │ ├── boot.h │ ├── build_info.h │ ├── cmdline_opts.h │ ├── cmdline_types.h │ ├── color_defs.h │ ├── compiler.h │ ├── cpputils.h │ ├── datetime.h │ ├── debug │ │ └── termios_debug.c.h │ ├── elf_calc_mem_size.c.h │ ├── elf_get_section.c.h │ ├── elf_types.h │ ├── fake_atomics.h │ ├── fat32_base.h │ ├── norec.h │ ├── page_size.h │ ├── panic.h │ ├── printk.h │ ├── string_util.h │ ├── syscalls.h │ ├── tilck_sound.h │ ├── unaligned.h │ └── utils.h │ ├── kernel │ ├── arch │ │ ├── generic_x86 │ │ │ ├── arch_ints.h │ │ │ ├── debug_utils_x86.h │ │ │ ├── dma.h │ │ │ └── fpu_memcpy.h │ │ ├── i386 │ │ │ ├── arch_utils.h │ │ │ ├── asm_defs.h │ │ │ └── tss.h │ │ ├── riscv │ │ │ ├── arch_ints.h │ │ │ ├── arch_utils.h │ │ │ ├── asm_defs.h │ │ │ ├── cpu_features.h │ │ │ ├── fpu_memcpy.h │ │ │ ├── ioremap.h │ │ │ ├── mmio.h │ │ │ └── sbi.h │ │ └── x86_64 │ │ │ ├── arch_utils.h │ │ │ └── asm_defs.h │ ├── bintree.h │ ├── cmdline.h │ ├── datetime.h │ ├── debug_utils.h │ ├── elf_loader.h │ ├── elf_utils.h │ ├── errno.h │ ├── fault_resumable.h │ ├── fs │ │ ├── devfs.h │ │ ├── fat32.h │ │ ├── flock.h │ │ ├── kernelfs.h │ │ ├── vfs.h │ │ └── vfs_base.h │ ├── gcov.h │ ├── hal.h │ ├── hal_types.h │ ├── interrupts.h │ ├── irq.h │ ├── kb.h │ ├── kb_scancode_set1_keys.h │ ├── kmalloc.h │ ├── kmalloc_debug.h │ ├── list.h │ ├── modules.h │ ├── paging.h │ ├── paging_hw.h │ ├── pipe.h │ ├── process.h │ ├── process_int.h │ ├── process_mm.h │ ├── ringbuf.h │ ├── rwlock.h │ ├── safe_ringbuf.h │ ├── sched.h │ ├── self_tests.h │ ├── signal.h │ ├── sort.h │ ├── subsystems.h │ ├── switch.h │ ├── sync.h │ ├── sys_types.h │ ├── syscalls.h │ ├── system_mmap.h │ ├── system_mmap_int.h │ ├── term.h │ ├── term_aux.h │ ├── test │ │ ├── README │ │ ├── cmdline.h │ │ ├── fat32.h │ │ ├── fork.h │ │ ├── itoa.h │ │ ├── kmalloc.h │ │ ├── mem_regions.h │ │ ├── tracing.h │ │ ├── tty_test.h │ │ └── vfs.h │ ├── timer.h │ ├── tty.h │ ├── tty_struct.h │ ├── uefi.h │ ├── user.h │ ├── vdso.h │ └── worker_thread.h │ └── mods │ ├── acpi.h │ ├── console.h │ ├── fb_console.h │ ├── irqchip.h │ ├── pci.h │ ├── serial.h │ ├── sysfs.h │ ├── sysfs_utils.h │ └── tracing.h ├── kernel ├── CMakeLists.txt ├── arch │ ├── CMakeLists.txt │ ├── generic_x86 │ │ ├── cpu.c │ │ ├── debug_generic.c │ │ ├── fpu_memcpy.c │ │ ├── idt_generic.c │ │ ├── irq_generic.c │ │ ├── misc.c │ │ ├── mmap.c │ │ ├── mtrr.c │ │ ├── paging_generic_x86.c │ │ ├── paging_generic_x86.h │ │ ├── panic.c │ │ ├── pic.c │ │ ├── pic.h │ │ ├── pit.c │ │ └── rtc.c │ ├── i386 │ │ ├── CMakeLists.txt │ │ ├── arch_syscalls.c │ │ ├── debug.c │ │ ├── double_fault.c │ │ ├── double_fault.h │ │ ├── fault_handlers.S │ │ ├── fault_resumable.S │ │ ├── gdt.c │ │ ├── gdt_int.h │ │ ├── idt.c │ │ ├── idt_int.h │ │ ├── irq.c │ │ ├── irq_handlers.S │ │ ├── kernel_yield.S │ │ ├── ldt.c │ │ ├── linker_script.ld │ │ ├── misc.S │ │ ├── paging.c │ │ ├── paging_int.h │ │ ├── process32.c │ │ ├── start.S │ │ ├── syscall_entry.S │ │ └── vdso.S │ ├── riscv │ │ ├── cpu.c │ │ ├── cpu_features.c │ │ ├── debug.c │ │ ├── early_fdt.c │ │ ├── fault.c │ │ ├── fault_resumable.S │ │ ├── fpu.S │ │ ├── fpu_memcpy.c │ │ ├── irq.c │ │ ├── kernel_yield.S │ │ ├── misc.S │ │ ├── misc.c │ │ ├── mmap.c │ │ ├── paging.c │ │ ├── paging_generic.c │ │ ├── paging_generic.h │ │ ├── paging_int.h │ │ ├── panic.c │ │ ├── process_riscv.c │ │ ├── sbi.c │ │ ├── start.S │ │ ├── timer.c │ │ ├── trap_entry.S │ │ └── vdso.S │ ├── riscv64 │ │ ├── CMakeLists.txt │ │ ├── arch_syscalls.c │ │ └── linker_script.ld │ └── x86_64 │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── arch_syscalls_x64.c │ │ ├── debug.c │ │ ├── double_fault.c │ │ ├── fake_impl.c │ │ ├── fault_resumable.S │ │ ├── idt64.c │ │ ├── irq64.c │ │ ├── kernel_yield.S │ │ ├── linker_script.ld │ │ ├── misc.S │ │ ├── paging64.c │ │ ├── process64.c │ │ └── start.S ├── auth.c ├── bintree │ ├── avl_bintree.c │ ├── avl_find.c.h │ ├── avl_insert.c.h │ └── avl_remove.c.h ├── cmdline.c ├── cwd.c ├── datetime.c ├── debug.c ├── elf.c ├── execve.c ├── exit.c ├── fork.c ├── fs │ ├── devfs.c │ ├── fat32.c │ ├── fat32_mm.c │ ├── flock.c │ ├── fs_int.h │ ├── fs_syscalls.c │ ├── kernelfs.c │ ├── mp.c │ ├── ramfs │ │ ├── blocks.c.h │ │ ├── dir_entries.c.h │ │ ├── getdents.c.h │ │ ├── inodes.c.h │ │ ├── locking.c.h │ │ ├── mkdir.c.h │ │ ├── mmap.c.h │ │ ├── open.c.h │ │ ├── ramfs.c │ │ ├── ramfs_int.h │ │ ├── rw_ops.c.h │ │ └── stat.c.h │ ├── vfs │ │ ├── vfs.c │ │ ├── vfs_getdents.c.h │ │ ├── vfs_locking.c.h │ │ ├── vfs_mp.c.h │ │ ├── vfs_op_ready.c.h │ │ └── vfs_resolve.c.h │ └── vfs_util.c ├── gcov.c ├── interrupts.c ├── kb_input.c ├── kcond.c ├── kmalloc │ ├── general_kmalloc.c.h │ ├── kmalloc.c │ ├── kmalloc_accelerator.c.h │ ├── kmalloc_block_node.h │ ├── kmalloc_debug.h │ ├── kmalloc_heap_struct.h │ ├── kmalloc_heaps.c.h │ ├── kmalloc_leak_detector.c.h │ ├── kmalloc_small_heaps.c.h │ └── kmalloc_stats.c.h ├── kmutex.c ├── ksem.c ├── main.c ├── misc.c ├── mm │ ├── process_mm.c │ ├── process_mm_base.c │ └── system_mmap.c ├── modules.c ├── pipe.c ├── poll.c ├── printk.c ├── process.c ├── ringbuf.c ├── rwlock.c ├── safe_ringbuf.cpp ├── sched.c ├── select.c ├── signal.c ├── snprintk.c ├── sort.c ├── sources.cmake ├── switch.c ├── syscalls.c ├── tilck_cmd.c ├── timer.c ├── tty │ ├── term_aux.c │ ├── term_mgmt.c │ ├── tty.c │ ├── tty_ctrl_handlers.c.h │ ├── tty_input.c │ ├── tty_int.h │ ├── tty_ioctl.c │ └── ttyaux.c ├── ubsan.c ├── uefi.c ├── user.c ├── waitpid.c ├── wobj.c ├── wth.c ├── wth_aux.c └── wth_int.h ├── modules ├── acpi │ ├── acpi.cmake │ ├── acpi_int.h │ ├── acpi_module.c │ ├── acpi_sysfs.c │ ├── battery.c │ ├── module_deps │ ├── osl.h │ ├── osl_hw.c │ ├── osl_malloc.c │ ├── osl_misc.c │ ├── osl_mm.c │ ├── osl_sync.c │ ├── osl_tasks.c │ └── powerbtn.c ├── console │ ├── console.c │ ├── console_def_state.c.h │ ├── console_int.h │ ├── generic_x86 │ │ └── textmode_video.c │ ├── gfx_chars.h │ ├── tables.c │ ├── term_action_wrappers.c.h │ ├── term_actions.c.h │ ├── video_term.c │ └── video_term_int.h ├── debugpanel │ ├── dp.c │ ├── dp_debugger.c │ ├── dp_heaps.c │ ├── dp_input.c │ ├── dp_int.h │ ├── dp_irqs.c │ ├── dp_mem_chunks.c │ ├── dp_opts.c │ ├── dp_sys_mmap.c │ ├── dp_tasks.c │ ├── dp_tracing.c │ ├── dp_tracing_int.h │ ├── dp_tracing_sys.c │ ├── termutil.c │ └── termutil.h ├── fb │ ├── fb.cmake │ ├── fb_console.c │ ├── fb_int.h │ ├── fb_raw.c │ ├── fbdev.c │ ├── font16x32.psf │ ├── font8x16.psf │ └── se_fb_perf.c ├── goldfish │ └── riscv │ │ ├── fdt_rtc.c │ │ ├── fdt_rtc.h │ │ └── goldfish.c ├── kb8042 │ └── generic_x86 │ │ ├── i8042.c │ │ ├── i8042.h │ │ ├── kb.c │ │ ├── kb_ansi_seq.c.h │ │ └── kb_layouts.c.h ├── pci │ └── generic_x86 │ │ ├── pci.c │ │ ├── pci_classes.c.h │ │ ├── pci_sysfs.c.h │ │ └── pci_vendors.c.h ├── ramfb │ └── riscv │ │ └── ramfb.c ├── riscv_irq │ └── riscv │ │ ├── fdt_irqchip.c │ │ ├── riscv-intc.c │ │ └── riscv-plic.c ├── sb16 │ └── generic_x86 │ │ ├── sb16.c │ │ ├── sb16.h │ │ └── sb16_hw.c ├── serial │ ├── generic_x86 │ │ └── uart_8250.c │ ├── riscv │ │ ├── fdt_serial.c │ │ ├── fdt_serial.h │ │ └── ns16550.c │ ├── serial.c │ └── serial_term.c ├── sysfs │ ├── config.c │ ├── dents.c.h │ ├── dirops.c.h │ ├── fileops.c.h │ ├── inodes.c.h │ ├── lock_and_retain.c.h │ ├── ro_config_vars.h │ ├── sysfs.c │ ├── sysfs.cmake │ ├── sysfs_int.h │ └── types.c.h ├── systests │ └── systests.c └── tracing │ ├── errno_names.c │ ├── ptype_buffer.c │ ├── ptype_iov.c │ ├── syscall_types.h │ ├── tracing.c │ ├── tracing_metadata.c │ └── tracing_types.c ├── other ├── alt_fonts │ ├── .gitignore │ └── README ├── bsp │ └── riscv64 │ │ ├── licheerv-nano │ │ ├── board_bsp.cmake │ │ ├── bootloader │ │ ├── fit-image.its │ │ ├── u-boot.cmd │ │ └── uEnv.txt │ │ └── qemu-virt │ │ ├── board_bsp.cmake │ │ ├── bootloader │ │ ├── fit-image.its │ │ ├── u-boot.cmd │ │ ├── u-boot.config │ │ └── uEnv.txt ├── busybox.config ├── ci │ ├── i386.yml │ ├── riscv64.yml │ ├── tc-arch-i386.yml │ ├── tc-arch-riscv64.yml │ ├── tc-debian-i386.yml │ ├── tc-debian-riscv64.yml │ ├── tc-fedora-i386.yml │ ├── tc-fedora-riscv64.yml │ ├── tc-opensuse-i386.yml │ ├── tc-opensuse-riscv64.yml │ └── x86_64.yml ├── cmake │ ├── build_modules.cmake │ ├── compiler_flags.cmake │ ├── config_fatpart │ ├── errors.cmake │ ├── extra_apps.cmake │ ├── gen_config_post.cmake │ ├── gen_config_pre.cmake │ ├── utils.cmake │ └── wrapped_syms.cmake ├── containers │ ├── README.md │ ├── arch-base │ │ └── Dockerfile │ ├── debian-base │ │ └── Dockerfile │ ├── fedora-base │ │ └── Dockerfile │ ├── opensuse-base │ │ └── Dockerfile │ ├── tilck-i386 │ │ └── Dockerfile │ ├── tilck-riscv64 │ │ └── Dockerfile │ └── tilck-x86_64 │ │ └── Dockerfile ├── debugging_readme ├── gcc_tc_conf │ ├── i386 │ │ ├── default_ver │ │ └── min_ver │ ├── riscv64 │ │ ├── default_ver │ │ └── min_ver │ └── x86_64 │ │ ├── default_ver │ │ └── min_ver ├── gdb_scripts │ ├── __init__.py │ ├── base_utils.py │ ├── fs_handle_printer.py │ ├── get_cmds.py │ ├── list_cmds.py │ ├── mi_printer.py │ ├── mobj_printer.py │ ├── process_printer.py │ ├── regs_printer.py │ ├── task_printer.py │ ├── tasks.py │ └── tilck_types.py ├── mock_experiments.c └── tilck_unstripped-gdb.py ├── scripts ├── adv │ ├── gen_other_builds │ └── test_all_other_builds ├── bash_includes │ ├── README │ ├── arch_checks │ ├── arch_utils │ ├── cc_vars │ ├── compiler_checks │ └── script_utils ├── build_apps │ ├── .gitignore │ ├── CMakeLists.txt │ ├── elfhack.c │ ├── fathack.c │ ├── gen_config.cpp │ ├── mbrhack.c │ └── pnm2text.c ├── build_generators │ ├── clang_small_offt │ ├── clang_tc_isystem │ ├── clang_wconv │ ├── gcc │ ├── gcc_fast_rel │ ├── gcc_gcov │ ├── gcc_no_nested_irq_tracking │ ├── gcc_nocow │ ├── gcc_rel │ ├── gcc_small_offt │ ├── gcc_syscc │ └── minimal ├── build_scripts │ ├── bss_checker │ ├── create_empty_img_if_necessary │ ├── get_commit_hash │ ├── i386-ar │ ├── i386-g++ │ ├── i386-gcc │ ├── i386-ld │ ├── i386-linux-ar │ ├── i386-linux-g++ │ ├── i386-linux-gcc │ ├── i386-linux-ranlib │ ├── i386-linux-strip │ ├── i386-objcopy │ ├── i386-ranlib │ ├── i386-size │ ├── i386-strip │ ├── i686-linux-ar │ ├── i686-linux-g++ │ ├── i686-linux-gcc │ ├── i686-linux-ld │ ├── i686-linux-objcopy │ ├── i686-linux-ranlib │ ├── i686-linux-size │ ├── i686-linux-strip │ ├── tilck_set_commit_hash │ ├── x86_64-ar │ ├── x86_64-g++ │ ├── x86_64-gcc │ ├── x86_64-linux-ar │ ├── x86_64-linux-g++ │ ├── x86_64-linux-gcc │ ├── x86_64-linux-ranlib │ ├── x86_64-linux-strip │ ├── x86_64-ranlib │ └── x86_64-strip ├── build_toolchain ├── cmake_run ├── configurator │ ├── configurator.yml │ └── parser │ │ ├── cmake_parser.py │ │ ├── cmake_row.py │ │ ├── cmake_var.py │ │ ├── test_cmakeparser.py │ │ ├── test_cmakerow.py │ │ └── test_cmakevar.py ├── dev │ ├── README │ ├── cmp_build_dirs │ ├── cmp_funcs_size │ ├── count_lines_of_code │ ├── dump_all_funcs │ ├── flat_objdump_386 │ ├── flat_objdump_8086 │ ├── flat_objdump_x64 │ ├── generate_pci_ids │ ├── objdump_no_machine_code │ ├── qemu_img_create_vmdk │ ├── remove_32bit_addrs_from_dump │ ├── run_ctags │ └── virtualbox_create_vmdk_loop0 ├── run_config ├── tc │ ├── arch │ │ ├── install_pkg │ │ └── update │ ├── debian │ │ ├── install_pkg │ │ └── update │ ├── fedora │ │ ├── install_pkg │ │ └── update │ ├── opensuse │ │ ├── install_pkg │ │ └── update │ └── pkgs │ │ ├── README │ │ ├── acpica │ │ ├── busybox │ │ ├── cmake │ │ ├── custom_gcc_cross_tc │ │ ├── fbdoom │ │ ├── gcc_tc │ │ ├── gnuefi │ │ ├── gtest │ │ ├── install_pkgs │ │ ├── lcov │ │ ├── libfdt │ │ ├── lua │ │ ├── micropython │ │ ├── mtools │ │ ├── musl │ │ ├── ncurses │ │ ├── ovmf │ │ ├── tcc │ │ ├── tfblib │ │ ├── tree │ │ ├── vim │ │ └── zlib └── templates │ ├── README │ ├── build_bootpart │ ├── build_fatpart │ ├── build_test_fatpart │ ├── generate_coverage_report │ ├── musl-g++ │ ├── musl-gcc │ ├── qemu │ ├── debug_run_qemu │ ├── run_efi_qemu32 │ ├── run_efi_qemu64 │ ├── run_multiboot_qemu │ └── run_qemu │ └── weaken_syms ├── sysroot ├── README ├── bin │ └── .gitignore ├── etc │ ├── group │ ├── passwd │ └── start └── usr │ ├── bin │ ├── .gitignore │ └── vim │ ├── lib │ └── .gitignore │ └── share │ └── terminfo │ └── l │ └── linux ├── tests ├── interactive │ ├── README │ ├── dp.py │ ├── expected │ │ ├── fbtest.png │ │ ├── vim1-0.gz │ │ ├── vim1-1.gz │ │ ├── vim1-2.gz │ │ ├── vim1-3.gz │ │ ├── vim1-4.gz │ │ ├── vim1-5.gz │ │ ├── vim1-6.gz │ │ ├── vim1-7.gz │ │ ├── vim1-8.gz │ │ ├── vim2-0.gz │ │ ├── vim2-1.gz │ │ ├── vim2-2.gz │ │ ├── vim2-3.gz │ │ └── vim2-4.gz │ ├── fbtest.py │ ├── ls.py │ ├── tracing.py │ ├── vim1.py │ ├── vim2.py │ └── vim_text_files │ │ ├── numbers.txt │ │ ├── perl.pl │ │ ├── python.py │ │ ├── ruby.rb │ │ └── shell.sh ├── runners │ ├── ci_run_all_tests_wrapper │ ├── lib │ │ ├── __init__.py │ │ ├── detect_kvm.py │ │ ├── env.py │ │ ├── exceptions.py │ │ ├── lang_aux.py │ │ ├── qemu.py │ │ ├── stdio.py │ │ └── utils.py │ ├── run_all_tests │ ├── run_interactive_test │ └── single_test_run ├── self │ ├── README │ ├── deadlock_detection.c │ ├── se_bintree.c │ ├── se_common.c │ ├── se_data.c │ ├── se_data.h │ ├── se_fault_resumable.c │ ├── se_kcond.c │ ├── se_kmalloc_perf.c │ ├── se_kmutex.c │ ├── se_ksem.c │ ├── se_misc.c │ ├── se_mobj_waiter.c │ ├── se_panic.c │ ├── se_rwlock.c │ ├── se_time.c │ └── se_wth.c ├── system │ ├── README │ ├── cmds_table.c │ ├── cmds_table.h │ ├── scripts │ │ ├── sysfs │ │ ├── tar │ │ └── tcc │ ├── test_bigargv.c │ ├── test_common.h │ ├── test_fat32.c │ ├── test_fork.c │ ├── test_fs1.c │ ├── test_fs2.c │ ├── test_fs_perf.c │ ├── test_misc.c │ ├── test_mm.c │ ├── test_pipe.c │ ├── test_poll.c │ ├── test_select.c │ ├── test_signals.c │ └── test_waitpid.c └── unit │ ├── CMakeLists.txt │ ├── README │ ├── asm_fake_funcs.c │ ├── avl_bintree.cpp │ ├── cmdline.cpp │ ├── console_test.cpp │ ├── datetime_test.cpp │ ├── fake_funcs_utils.h │ ├── fat32_debug.c │ ├── fat32_test.cpp │ ├── fork_test.cpp │ ├── generic_stubs.c │ ├── itoa_test.cpp │ ├── kernel_init_funcs.h │ ├── kmalloc_test.cpp │ ├── list_test.cpp │ ├── mem_regions.cpp │ ├── misc_fake.c │ ├── mm_fakes.cpp │ ├── mock_experiments.cpp │ ├── mocked_funcs.h │ ├── mocking.cpp │ ├── mocking.h │ ├── printk_test.cpp │ ├── ringbuf_test.cpp │ ├── sort_test.cpp │ ├── string_util_test.cpp │ ├── test_sysroot │ └── testdir │ │ ├── 12345678.xyz │ │ ├── Aaa │ │ ├── BBB │ │ ├── This_is_a_file_with_a_veeeery_long_name.txt │ │ ├── dir1 │ │ ├── f1 │ │ └── f2 │ │ ├── dir2 │ │ ├── f3 │ │ └── f4 │ │ ├── dir3 │ │ └── f5 │ │ ├── file.a │ │ ├── file.ab │ │ ├── file.abc │ │ └── manyfiles │ │ ├── f1 │ │ ├── f10 │ │ ├── f11 │ │ ├── f12 │ │ ├── f13 │ │ ├── f14 │ │ ├── f15 │ │ ├── f16 │ │ ├── f17 │ │ ├── f18 │ │ ├── f19 │ │ ├── f2 │ │ ├── f20 │ │ ├── f3 │ │ ├── f4 │ │ ├── f5 │ │ ├── f6 │ │ ├── f7 │ │ ├── f8 │ │ └── f9 │ ├── tests_main.cpp │ ├── tracerTest.cpp │ ├── tracing_test.cpp │ ├── trivial_allocator.h │ ├── vfs_perf.cpp │ ├── vfs_resolve.cpp │ ├── vfs_test.cpp │ ├── vfs_test.h │ ├── vfs_test_fs.cpp │ ├── vfs_test_fs.h │ └── wth_test.cpp └── userapps ├── CMakeLists.txt ├── README.md ├── devshell ├── commands.c ├── cov.c ├── devshell.c ├── devshell.h ├── i386.S ├── readcmd.c ├── riscv64.S ├── sysenter.h └── x86_64.S ├── dp.c ├── extra ├── .gitignore ├── CMakeLists.txt └── README.md ├── fbtest.c ├── filedump.c ├── init.c ├── ncapp.c ├── play.c └── termtest.c /.codecov.yml: -------------------------------------------------------------------------------- 1 | 2 | comment: false 3 | 4 | coverage: 5 | range: 0..80 6 | round: nearest 7 | precision: 1 8 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Tilck default devcontainer", 3 | "image": "mcr.microsoft.com/devcontainers/universal:2", 4 | "features": { 5 | "ghcr.io/devcontainers/features/desktop-lite:1": {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | build 2 | toolchain 3 | toolchain2 4 | other_builds 5 | 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[feature request]" 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | bochsrc-disk.bxrc 3 | bochsrc.bxrc 4 | toolchain/ 5 | toolchain2/ 6 | .gdb_history 7 | GPATH 8 | GRTAGS 9 | GTAGS 10 | tags 11 | rel_build/* 12 | .vscode/ipch/ 13 | other_build* 14 | tcci_* 15 | .mypy_cache 16 | .vscode/.ropeproject 17 | __pycache__ 18 | .gcc_tc_ver 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | notifications: 3 | email: 4 | on_success: never 5 | on_failure: always 6 | 7 | # In order to ask travis to install packages: 8 | # sudo: required AND under matrix/include: 9 | # addons: 10 | # apt: 11 | # packages: 12 | # - qemu-system-x86 13 | # [ at the same level of env ] 14 | 15 | matrix: 16 | include: 17 | - os: linux 18 | dist: trusty 19 | sudo: false 20 | language: generic 21 | env: NO_BUSYBOX=1 RELEASE=0 22 | 23 | before_install: 24 | - mkdir -p toolchain2/cache 25 | - (cd toolchain2/cache && wget http://vvaltchev.github.io/cache/mtools-4.0.23.tar.gz) 26 | - ./scripts/build_toolchain --skip-install-pkgs 27 | - ./scripts/build_toolchain -s build_gtest 28 | 29 | install: 30 | - make -j 31 | - make -j gtests 32 | 33 | script: 34 | - MALLOC_CHECK_=2 ./build/gtests 35 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "cStandard": "c11", 6 | "cppStandard": "c++11", 7 | "compileCommands": "${workspaceRoot}/build/compile_commands.json", 8 | "defines": [ 9 | 10 | ], 11 | "includePath": [ 12 | "${workspaceRoot}/include" 13 | ], 14 | "browse": { 15 | "path": [ 16 | "${workspaceRoot}/boot", 17 | "${workspaceRoot}/include", 18 | "${workspaceRoot}/kernel", 19 | "${workspaceRoot}/tests", 20 | "${workspaceRoot}/build" 21 | ], 22 | "limitSymbolsToIncludedHeaders": false 23 | }, 24 | "configurationProvider": "vector-of-bool.cmake-tools" 25 | } 26 | ], 27 | "version": 4 28 | } 29 | -------------------------------------------------------------------------------- /.vscode/cmake-kits.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Tilck Clang", 4 | "compilers": { 5 | "C": "clang", 6 | "CXX": "clang++" 7 | }, 8 | "cmakeSettings": { 9 | "WCONV": 1, 10 | "KERNEL_SYSCC": 1, 11 | "CMAKE_EXPORT_COMPILE_COMMANDS": 1 12 | } 13 | }, 14 | 15 | { 16 | "name": "Tilck GCC", 17 | "compilers": { 18 | "CC": "gcc", 19 | "CXX": "g++" 20 | }, 21 | "cmakeSettings": { 22 | "CMAKE_EXPORT_COMPILE_COMMANDS": 1 23 | } 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build-kernel", 8 | "type": "shell", 9 | "command": "make", 10 | "group": { 11 | "kind": "build", 12 | "isDefault": true 13 | } 14 | }, 15 | { 16 | "label": "build-gtests", 17 | "type": "shell", 18 | "command": "make gtests", 19 | "group": { 20 | "kind": "build", 21 | "isDefault": true 22 | } 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2016-2024, Vladislav K. Valtchev 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | # This is a commodity fake Makefile that allows people to run the build from the 3 | # project's root directory, instead of entering in the build/ directory first. 4 | 5 | MAKEFLAGS += --no-print-directory 6 | 7 | TCROOT_PARENT ?= ./ 8 | TCROOT ?= $(TCROOT_PARENT)/toolchain2 9 | 10 | PREREQUISITES := $(TCROOT) build/CMakeCache.txt 11 | 12 | all: $(PREREQUISITES) 13 | @$(MAKE) -C build 14 | 15 | gtests: $(PREREQUISITES) 16 | @$(MAKE) -C build gtests 17 | 18 | clean: $(PREREQUISITES) 19 | @$(MAKE) -C build clean 20 | 21 | # Rem is a shortcut for rebuild_img 22 | rem: $(PREREQUISITES) 23 | @rm -rf ./build/fatpart ./build/tilck.img 24 | @$(MAKE) -C build 25 | 26 | rebuild_img: $(PREREQUISITES) 27 | @rm -rf ./build/fatpart ./build/tilck.img 28 | @$(MAKE) -C build 29 | 30 | config: $(PREREQUISITES) 31 | @./scripts/run_config 32 | 33 | menuconfig: $(PREREQUISITES) 34 | @./scripts/run_config 35 | 36 | $(TCROOT): 37 | $(error Before building Tilck, you need to build the toolchain by running ./scripts/build_toolchain) 38 | 39 | build/CMakeCache.txt: 40 | @echo No CMakeCache.txt found: running CMake first. 41 | @./scripts/cmake_run 42 | 43 | .PHONY: all gtests clean 44 | -------------------------------------------------------------------------------- /boot/common/common_int.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | extern const struct bootloader_intf *intf; 8 | extern video_mode_t g_defmode; 9 | 10 | void show_video_modes(void); 11 | void show_mode(int num, struct generic_video_mode_info *gi, bool is_default); 12 | int read_line(char *buf, int buf_sz); 13 | int fetch_all_video_modes_once(void); 14 | video_mode_t get_user_video_mode_choice(void); 15 | void *simple_elf_loader(void *elf); 16 | -------------------------------------------------------------------------------- /boot/common/stdio.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "common_int.h" 10 | 11 | int 12 | read_line(char *buf, int buf_sz) 13 | { 14 | int len = 0; 15 | int c; 16 | 17 | for (char *s = buf; *s; s++) { 18 | printk("%c", *s); 19 | len++; 20 | } 21 | 22 | while (true) { 23 | 24 | c = intf->read_key(); 25 | 26 | if (c == '\r' || c == '\n') { 27 | printk("\n"); 28 | break; 29 | } 30 | 31 | if (!isprint(c)) { 32 | 33 | if (c == '\b' && len > 0) { 34 | printk("\b \b"); 35 | len--; 36 | } 37 | 38 | continue; 39 | } 40 | 41 | if (len < buf_sz - 1) { 42 | printk("%c", c); 43 | buf[len++] = c; 44 | } 45 | } 46 | 47 | buf[len] = 0; 48 | return len; 49 | } 50 | -------------------------------------------------------------------------------- /boot/efi/ia32/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | cmake_minimum_required(VERSION 3.22) 4 | 5 | set(EFI_ARCH ia32) 6 | set(GNUEFI_DIR ${TCROOT}/i386/gnu-efi) 7 | file(GLOB SOURCES ${GLOB_CONF_DEP} "../*.c") 8 | 9 | set_cross_compiler() 10 | include (../GenericBuild.cmake) 11 | -------------------------------------------------------------------------------- /boot/efi/panic.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include "defs.h" 4 | #include "utils.h" 5 | 6 | #include 7 | #include 8 | 9 | NORETURN void panic(const char *fmt, ...) 10 | { 11 | UINTN mapkey; 12 | va_list args; 13 | 14 | if (!gExitBootServicesCalled) { 15 | 16 | printk("\n"); 17 | printk("******************* UEFI BOOTLOADER PANIC ********************"); 18 | printk("\n"); 19 | 20 | va_start(args, fmt); 21 | vprintk(fmt, args); 22 | va_end(args); 23 | 24 | printk("\n"); 25 | 26 | if (GetMemoryMap(&mapkey) == EFI_SUCCESS) { 27 | 28 | if (BS->ExitBootServices(gImageHandle, mapkey) != EFI_SUCCESS) 29 | Print(L"Error in panic: ExitBootServices() failed.\n"); 30 | 31 | } else { 32 | 33 | Print(L"Error in panic: GetMemoryMap() failed.\n"); 34 | } 35 | } 36 | 37 | disable_interrupts_forced(); 38 | 39 | while (true) { 40 | halt(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /boot/legacy/early_boot_script.ld: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | OUTPUT_FORMAT("binary") 4 | 5 | OUTPUT_ARCH(i386) 6 | ENTRY(_start) 7 | SEARCH_DIR("=/tmp/x86-i686--glibc--stable/usr/i686-buildroot-linux-gnu/lib32"); 8 | SEARCH_DIR("=/tmp/x86-i686--glibc--stable/usr/i686-buildroot-linux-gnu/lib"); 9 | 10 | SECTIONS 11 | { 12 | . = SEGMENT_START("text-segment", 0x0); 13 | 14 | .text : 15 | { 16 | *(.text) 17 | . = @EARLY_BOOT_SZ@; 18 | } 19 | 20 | /DISCARD/ : { *(*) } 21 | } 22 | -------------------------------------------------------------------------------- /boot/legacy/stage3/basic_term.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | void init_bt(void); 7 | void bt_write_char(char c); 8 | void bt_setcolor(u8 color); 9 | void bt_movecur(int row, int col); 10 | u16 bt_get_curr_row(void); 11 | u16 bt_get_curr_col(void); 12 | -------------------------------------------------------------------------------- /boot/legacy/stage3/common.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | /* 8 | * Static address of a single bios memory area struct: it must be in the lowest 9 | * 64 KB and must be hard-coded (because we don't know the memory map yet!). 10 | */ 11 | #define BIOS_MEM_AREA_BUF (16 * KB) 12 | 13 | struct mem_info; 14 | 15 | extern const struct bootloader_intf legacy_boot_intf; 16 | extern struct ModeInfoBlock *usable_vbe_mode_info_block; 17 | extern struct VbeInfoBlock *vbe_info_block; 18 | extern video_mode_t selected_mode; 19 | extern struct mem_info g_meminfo; 20 | extern ulong initrd_paddr; 21 | extern u32 initrd_size; 22 | extern ulong bp_paddr; 23 | extern u32 bp_size; 24 | extern ulong kernel_file_pa; 25 | extern u32 kernel_file_sz; 26 | 27 | multiboot_info_t * 28 | setup_multiboot_info(ulong ramdisk_paddr, ulong ramdisk_size); 29 | 30 | u32 31 | rd_compact_clusters(void *ramdisk, u32 rd_size); 32 | 33 | bool 34 | load_fat_ramdisk(const char *load_str, 35 | u32 first_sec, 36 | ulong min_paddr, 37 | ulong *ref_rd_paddr, 38 | u32 *ref_rd_size, 39 | bool alloc_extra_page); 40 | 41 | bool 42 | load_kernel_file(const char *filepath); 43 | 44 | void 45 | alloc_mbi(void); 46 | 47 | char * 48 | legacy_boot_get_cmdline_buf(u32 *buf_sz); 49 | -------------------------------------------------------------------------------- /boot/legacy/stage3/panic.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | NORETURN void panic(const char *fmt, ...) 8 | { 9 | printk("\n********************* BOOTLOADER PANIC *********************\n"); 10 | 11 | va_list args; 12 | va_start(args, fmt); 13 | vprintk(fmt, args); 14 | va_end(args); 15 | 16 | printk("\n"); 17 | 18 | while (true) { 19 | halt(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /boot/legacy/stage3/realmode_call.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | void 7 | realmode_call(void *func, 8 | u32 *eax_ref, 9 | u32 *ebx_ref, 10 | u32 *ecx_ref, 11 | u32 *edx_ref, 12 | u32 *esi_ref, 13 | u32 *edi_ref, 14 | u32 *flags_ref); 15 | 16 | void 17 | realmode_call_by_val(void *func, u32 a, u32 b, u32 c, u32 d, u32 si, u32 di); 18 | 19 | /* 20 | * Realmode functions 21 | * 22 | * Usage: realmode_call(&realmode_func_name, ); 23 | */ 24 | extern u32 realmode_int_10h; 25 | extern u32 realmode_int_13h; 26 | extern u32 realmode_int_15h; 27 | extern u32 realmode_int_16h; 28 | 29 | void test_rm_call_working(void); 30 | 31 | struct VbeFarPtr { 32 | 33 | u16 off; 34 | u16 seg; 35 | 36 | } PACKED; 37 | 38 | static ALWAYS_INLINE void *get_flat_ptr(struct VbeFarPtr fp) 39 | { 40 | return (void *)((u32)fp.off + ((u32)fp.seg) * 16); 41 | } 42 | 43 | char bios_read_char(void); 44 | 45 | bool read_drive_params(u8 drive, 46 | u32 *sectors_per_track, 47 | u32 *heads_per_cylinder, 48 | u32 *cylinder_count); 49 | 50 | void read_sectors(u32 dest_paddr, u32 lba_sector, u32 sector_count); 51 | -------------------------------------------------------------------------------- /common/README: -------------------------------------------------------------------------------- 1 | This directory contains common code that is shared between the kernel and the 2 | bootloader. 3 | -------------------------------------------------------------------------------- /common/asserts.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | 5 | NORETURN void assert_failed(const char *expr, const char *file, int line) 6 | { 7 | panic("ASSERTION '%s' FAILED in %s:%i\n", expr, file, line); 8 | } 9 | 10 | NORETURN void not_reached(const char *file, int line) 11 | { 12 | panic("NOT_REACHED in %s:%i\n", file, line); 13 | } 14 | 15 | NORETURN void not_implemented(const char *file, int line) 16 | { 17 | panic("NOT_IMPLEMENTED in %s:%i\n", file, line); 18 | } 19 | -------------------------------------------------------------------------------- /common/panic.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This whole file exists in order to allow non-bootloader/kernel code to use 5 | * the 'common' code. Since that common code (like fat32_base) uses ASSERT 6 | * and panic(), we need to have a common generic and weak panic implementation, 7 | * meant for traditional usermode code. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #ifndef USERMODE_APP 14 | 15 | /* 16 | * NOTE: this case exists ONLY to make the file to compile! 17 | * The bootloaders and the kernel MUST have their custom panic() function. 18 | */ 19 | #include 20 | #define abort() while (1) 21 | #define printf printk 22 | #define vprintf vprintk 23 | 24 | #else 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #endif 32 | 33 | NORETURN WEAK void panic(const char *fmt, ...) 34 | { 35 | printf("\n********************* PANIC *********************\n"); 36 | 37 | va_list args; 38 | va_start(args, fmt); 39 | vprintf(fmt, args); 40 | va_end(args); 41 | 42 | printf("\n"); 43 | abort(); 44 | } 45 | -------------------------------------------------------------------------------- /config/config_boot.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config file is generated by CMake and stored 5 | * in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | 12 | #define KERNEL_FILE_PATH "/@KERNEL_BOOTPART_PATH@" 13 | 14 | #define SECTOR_SIZE @SECTOR_SIZE@ 15 | #define BL_ST2_DATA_SEG @BL_ST2_DATA_SEG@ 16 | #define BL_BASE_ADDR @BL_BASE_ADDR@ 17 | #define BL_BASE_SEG (@BL_BASE_ADDR@ / 16) 18 | #define DISK_UUID @DISK_UUID@ 19 | #define IMG_SZ_SEC @IMG_SZ_SEC@ /* size of the whole image */ 20 | #define BOOT_SECTORS @BOOT_SECTORS@ /* bootloader sectors */ 21 | #define BOOTPART_SEC @BOOTPART_SEC@ /* start of the bootpart */ 22 | #define BOOTPART_SZ_SEC @BOOTPART_SZ_SEC@ /* size of the bootpart */ 23 | #define INITRD_SECTOR @INITRD_SECTOR@ /* start of the initrd */ 24 | #define INITRD_SZ_SEC @INITRD_SZ_SEC@ /* size of the initrd */ 25 | #define PREFERRED_GFX_MODE_W @PREFERRED_GFX_MODE_W@ 26 | #define PREFERRED_GFX_MODE_H @PREFERRED_GFX_MODE_H@ 27 | 28 | /* Boolean config variables */ 29 | #cmakedefine01 BOOTLOADER_POISON_MEMORY 30 | #cmakedefine01 BOOT_INTERACTIVE 31 | #cmakedefine01 EFI_BOOTLOADER_DEBUG 32 | -------------------------------------------------------------------------------- /config/config_init.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config file is generated by CMake and stored 5 | * in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #define START_SCRIPT "@START_SCRIPT@" 11 | #define DEFAULT_SHELL "@DEFAULT_SHELL@" 12 | 13 | /* --------- Boolean config variables --------- */ 14 | 15 | #cmakedefine01 INIT_REPORT_PROC_EXIT 16 | #cmakedefine01 USERAPPS_busybox 17 | 18 | /* 19 | * -------------------------------------------------------------------------- 20 | * Hard-coded global & derived constants 21 | * -------------------------------------------------------------------------- 22 | * 23 | * Here below there are many dervied constants and convenience constants not 24 | * designed to be easily changed because of the code makes assumptions about 25 | * them. Because of that, those constants are hard-coded and not available as 26 | * CMake variables. With time, some of those constants get "promoted" and moved 27 | * in CMake, others remain here. See the comments and think about the potential 28 | * implications before promoting a hard-coded constant to a configurable CMake 29 | * variable. 30 | */ 31 | 32 | #define BUSYBOX "/initrd/bin/busybox" 33 | #define TTYS0_MINOR 64 34 | -------------------------------------------------------------------------------- /config/config_kmalloc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config file is generated by CMake and stored 5 | * in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #define KMALLOC_FIRST_HEAP_SIZE (@KMALLOC_FIRST_HEAP_SIZE_KB_VAL@ * KB) 12 | 13 | /* --------- Boolean config variables --------- */ 14 | 15 | #cmakedefine01 KMALLOC_FREE_MEM_POISONING 16 | #cmakedefine01 KMALLOC_HEAVY_STATS 17 | #cmakedefine01 KMALLOC_SUPPORT_DEBUG_LOG 18 | #cmakedefine01 KMALLOC_SUPPORT_LEAK_DETECTOR 19 | 20 | 21 | /* 22 | * -------------------------------------------------------------------------- 23 | * Hard-coded global & derived constants 24 | * -------------------------------------------------------------------------- 25 | * 26 | * Here below there are many dervied constants and convenience constants not 27 | * designed to be easily changed because of the code makes assumptions about 28 | * them. Because of that, those constants are hard-coded and not available as 29 | * CMake variables. With time, some of those constants get "promoted" and moved 30 | * in CMake, others remain here. See the comments and think about the potential 31 | * implications before promoting a hard-coded constant to a configurable CMake 32 | * variable. 33 | */ 34 | 35 | /* --- NOTHING HERE at the moment --- */ 36 | -------------------------------------------------------------------------------- /config/mod_acpi.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_acpi 11 | #cmakedefine01 ACPI_DEBUGGER_ENABLED 12 | -------------------------------------------------------------------------------- /config/mod_debugpanel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_debugpanel 11 | -------------------------------------------------------------------------------- /config/mod_goldfish.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_goldfish 11 | -------------------------------------------------------------------------------- /config/mod_kb8042.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_kb8042 11 | #cmakedefine01 PS2_DO_SELFTEST 12 | #cmakedefine01 PS2_VERBOSE_DEBUG_LOG 13 | -------------------------------------------------------------------------------- /config/mod_pci.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_pci 11 | #cmakedefine01 PCI_VENDORS_LIST 12 | -------------------------------------------------------------------------------- /config/mod_ramfb.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_ramfb 11 | -------------------------------------------------------------------------------- /config/mod_riscv_irq.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_riscv_irq 11 | -------------------------------------------------------------------------------- /config/mod_sb16.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_sb16 11 | -------------------------------------------------------------------------------- /config/mod_serial.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_serial 11 | -------------------------------------------------------------------------------- /config/mod_sysfs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_sysfs 11 | 12 | #ifdef KERNEL_TEST 13 | #define MOD_sysfs_actual 1 14 | #else 15 | #define MOD_sysfs_actual MOD_sysfs 16 | #endif 17 | -------------------------------------------------------------------------------- /config/mod_systests.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_systests 11 | -------------------------------------------------------------------------------- /config/mod_tracing.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config header file is generated by CMake 5 | * and put in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | 10 | #cmakedefine01 MOD_tracing 11 | #cmakedefine01 TRACE_PRINTK_ENABLED_ON_BOOT 12 | 13 | #ifdef KERNEL_TEST 14 | #define MOD_tracing_actual 1 15 | #else 16 | #define MOD_tracing_actual MOD_tracing 17 | #endif 18 | -------------------------------------------------------------------------------- /config/modules_list.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * This is a TEMPLATE. The actual config file is generated by CMake and stored 5 | * in /tilck_gen_headers/. 6 | */ 7 | 8 | #pragma once 9 | #define ENABLED_MODULES_LIST "@ENABLED_MODULES_LIST@" 10 | -------------------------------------------------------------------------------- /docs/figures/.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.log 3 | *.pdf 4 | *.synctex.gz 5 | *.png 6 | -------------------------------------------------------------------------------- /docs/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Thank you for contributing to the project! 2 | 3 | In order to ensure a fast and smooth review process: 4 | 5 | - Please **read carefully** the [contributing] document before sending out 6 | the pull request, to make sure the changes follow project's **coding style** 7 | and meet the acceptance criteria (e.g. don't break builds, tests etc.) 8 | 9 | - Lines in any source file must be no more than **80** columns long, 10 | **no exceptions**. Run the `scripts/dev/count_lines_of_code -l` 11 | script to check for long lines in your branch. 12 | 13 | - For the commits, choose between model 1 or model 2. **Hint:** for most people, 14 | model 1 is the right choice as it's simpler and more time-efficient for 15 | contributors. Model 2 is great for people who have time & patience and want 16 | to use the Linux kernel contribution style. 17 | 18 | [contributing]: docs/contributing.md 19 | -------------------------------------------------------------------------------- /include/3rd_party/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Base64 encoding/decoding (RFC1341) 3 | * Copyright (c) 2005, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | 9 | #ifndef BASE64_H 10 | #define BASE64_H 11 | 12 | unsigned char * base64_encode(const unsigned char *src, size_t len, 13 | size_t *out_len); 14 | unsigned char * base64_decode(const unsigned char *src, size_t len, 15 | size_t *out_len); 16 | 17 | #endif /* BASE64_H */ 18 | -------------------------------------------------------------------------------- /include/3rd_party/crc32.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | uint32_t crc32(uint32_t crc, const void *buf, size_t size); 7 | -------------------------------------------------------------------------------- /include/tilck/acpi/actilck.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * Name: actilck.h - OS specific defines, etc. for Tilck 4 | * 5 | *****************************************************************************/ 6 | 7 | #pragma once 8 | #include 9 | #include 10 | 11 | #define ACPI_USE_SYSTEM_CLIBRARY 12 | #define ACPI_USE_NATIVE_MATH64 13 | #define ACPI_USE_NATIVE_DIVIDE 14 | #define ACPI_USE_LOCAL_CACHE 15 | 16 | #define ACPI_MACHINE_WIDTH NBITS 17 | -------------------------------------------------------------------------------- /include/tilck/common/arch/i386/utils.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #ifndef __i386__ 6 | #error This header can be used only when building for ia32. 7 | #endif 8 | 9 | static ALWAYS_INLINE ulong get_stack_ptr(void) 10 | { 11 | ulong sp; 12 | 13 | asmVolatile("mov %%esp, %0" 14 | : "=r" (sp) 15 | : /* no input */ 16 | : /* no clobber */); 17 | 18 | return sp; 19 | } 20 | -------------------------------------------------------------------------------- /include/tilck/common/arch/riscv/asm_riscv_strings.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | /* 7 | * TODO: Implement arch-specific version string function 8 | * instead of the generic C version function 9 | */ 10 | size_t strlen(const char *s); 11 | void *memcpy(void *dest, const void *src, size_t count); 12 | void *memmove(void *dest, const void *src, size_t count); 13 | void *memset(void *s, int c, size_t count); 14 | void bzero(void *s, size_t n); 15 | size_t strnlen(const char *str, size_t count); 16 | void *memchr(const void *s, int c, size_t count); 17 | char *strrchr(const char *s, int c); 18 | char *strchr(const char *s, int c); 19 | void *memset16(u16 *s, u16 val, size_t n); 20 | void *memset32(u32 *s, u32 val, size_t n); 21 | void *memcpy16(void *dest, const void *src, size_t n); 22 | void *memcpy32(void *dest, const void *src, size_t n); 23 | -------------------------------------------------------------------------------- /include/tilck/common/arch/riscv/image.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #ifndef __riscv 6 | #error This header can be used only when building for riscv. 7 | #endif 8 | 9 | /* riscv kernel image header */ 10 | struct linux_image_h { 11 | u32 code0; /* Executable code */ 12 | u32 code1; /* Executable code */ 13 | u64 text_offset; /* Image load offset */ 14 | u64 image_size; /* Effective Image size */ 15 | u64 flags; /* kernel flags (little endian) */ 16 | u32 version; /* version of the header */ 17 | u32 res1; /* reserved */ 18 | u64 res2; /* reserved */ 19 | u64 res3; /* reserved */ 20 | u32 magic; /* Magic number */ 21 | u32 res4; /* reserved */ 22 | }; 23 | -------------------------------------------------------------------------------- /include/tilck/common/arch/riscv/utils.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #ifndef __riscv 6 | #error This header can be used only when building for riscv. 7 | #endif 8 | 9 | static ALWAYS_INLINE ulong get_stack_ptr(void) 10 | { 11 | register ulong current_sp __asm__ ("sp"); 12 | 13 | return current_sp; 14 | } 15 | -------------------------------------------------------------------------------- /include/tilck/common/arch/x86_64/utils.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #ifndef __x86_64__ 6 | #error This header can be used only when building for x86_64. 7 | #endif 8 | 9 | static ALWAYS_INLINE ulong get_stack_ptr(void) 10 | { 11 | ulong sp; 12 | 13 | asmVolatile("mov %%rsp, %0" 14 | : "=r" (sp) 15 | : /* no input */ 16 | : /* no clobber */); 17 | 18 | return sp; 19 | } 20 | -------------------------------------------------------------------------------- /include/tilck/common/boot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The following two defines refer to the memory regions 3 | * that are required at runtime by EFI. 4 | * 5 | * See EfiToMultibootMemType() and 6 | * setup_uefi_runtime_services() for more details. 7 | */ 8 | #define TILCK_BOOT_EFI_RUNTIME_RO (MULTIBOOT_MEMORY_RESERVED + 1) 9 | #define TILCK_BOOT_EFI_RUNTIME_RW (MULTIBOOT_MEMORY_RESERVED + 2) 10 | 11 | struct tilck_extra_boot_info 12 | { 13 | uint32_t RSDP; 14 | uint32_t RT; 15 | }; 16 | -------------------------------------------------------------------------------- /include/tilck/common/build_info.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | struct build_info { 7 | 8 | char commit[160]; /* hash + commit date + tags + [other stuff] */ 9 | char ver[32]; /* string version, like "0.1.0" */ 10 | char arch[32]; /* arch name, like "i686" */ 11 | char extra[32]; /* unused, at the moment */ 12 | char modules_list[256]; /* space-separated list of built-in modules */ 13 | }; 14 | 15 | STATIC_ASSERT(sizeof(struct build_info) == 512); 16 | 17 | struct commit_hash_and_date { 18 | 19 | char hash[16]; 20 | char date[26]; 21 | char tags[53]; 22 | bool dirty; 23 | }; 24 | 25 | extern const struct build_info tilck_build_info; 26 | 27 | void 28 | extract_commit_hash_and_date(const struct build_info *bi, 29 | struct commit_hash_and_date *c); 30 | -------------------------------------------------------------------------------- /include/tilck/common/cmdline_types.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | enum kopt_type { 7 | KOPT_TYPE_bool, 8 | KOPT_TYPE_long, 9 | KOPT_TYPE_ulong, 10 | KOPT_TYPE_wordstr, 11 | }; 12 | 13 | /* Used by cmdline.c in the kernel */ 14 | struct kopt { 15 | const char *name; 16 | const char *alias; 17 | enum kopt_type type; 18 | void *data; 19 | }; 20 | 21 | typedef const char *wordstr; 22 | -------------------------------------------------------------------------------- /include/tilck/common/compiler.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #if defined(__GNUC__) && !defined(__clang__) 4 | 5 | #define COMPILER_NAME "gcc" 6 | #define COMPILER_MAJOR __GNUC__ 7 | #define COMPILER_MINOR __GNUC_MINOR__ 8 | #define COMPILER_PATCHLEVEL __GNUC_PATCHLEVEL__ 9 | 10 | #elif defined(__clang__) 11 | 12 | #define COMPILER_NAME "clang" 13 | #define COMPILER_MAJOR __clang_major__ 14 | #define COMPILER_MINOR __clang_minor__ 15 | #define COMPILER_PATCHLEVEL __clang_patchlevel__ 16 | 17 | #else 18 | 19 | #error Compiler not supported 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/tilck/common/datetime.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | struct datetime { 7 | 8 | union { 9 | 10 | struct { 11 | u8 sec; /* Seconds (0-60) */ 12 | u8 min; /* Minutes (0-59) */ 13 | u8 hour; /* Hours (0-23) */ 14 | u8 __unused; /* unused */ 15 | u8 day; /* Month day (1 - 31) */ 16 | u8 month; /* Month (1 - 12) */ 17 | u16 year; /* Absolute year (e.g. 1542, 2019, 2059, ...) */ 18 | }; 19 | 20 | u64 raw; 21 | }; 22 | }; 23 | 24 | int timestamp_to_datetime(int64_t t, struct datetime *d); 25 | int64_t datetime_to_timestamp(struct datetime d); 26 | -------------------------------------------------------------------------------- /include/tilck/common/elf_calc_mem_size.c.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* 10 | * NOTE[1]: the code is in a source-header (.c.h) in order to avoid it to be 11 | * compiled and linked in binaries that don't need it, with the whole package 12 | * of C files in common/. 13 | * 14 | * NOTE[2]: this file uses Tilck's generic ELF types (Elf_Ehdr instead of 15 | * Elf_Ehdr32 etc.). In your code, you might need to define USE_ELF32 or 16 | * USE_ELF64 to work with ELF files having bitness different than your NBITS. 17 | */ 18 | 19 | static size_t 20 | elf_calc_mem_size(Elf_Ehdr *h) 21 | { 22 | Elf_Phdr *phdrs = (Elf_Phdr *)((char*)h + h->e_phoff); 23 | Elf_Addr min_pbegin = 0; 24 | Elf_Addr max_pend = 0; 25 | 26 | for (uint32_t i = 0; i < h->e_phnum; i++) { 27 | 28 | Elf_Phdr *p = phdrs + i; 29 | Elf_Addr pend = pow2_round_up_at(p->p_paddr + p->p_memsz, p->p_align); 30 | 31 | if (i == 0 || p->p_paddr < min_pbegin) 32 | min_pbegin = p->p_paddr; 33 | 34 | if (pend > max_pend) 35 | max_pend = pend; 36 | } 37 | 38 | return max_pend - min_pbegin; 39 | } 40 | -------------------------------------------------------------------------------- /include/tilck/common/elf_get_section.c.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* 10 | * NOTE[1]: the code is in a source-header (.c.h) in order to avoid it to be 11 | * compiled and linked in binaries that don't need it, with the whole package 12 | * of C files in common/. 13 | * 14 | * NOTE[2]: this file uses Tilck's generic ELF types (Elf_Ehdr instead of 15 | * Elf_Ehdr32 etc.). In your code, you might need to define USE_ELF32 or 16 | * USE_ELF64 to work with ELF files having bitness different than your NBITS. 17 | */ 18 | 19 | static Elf_Shdr * 20 | elf_get_section(Elf_Ehdr *h, const char *section_name) 21 | { 22 | Elf_Shdr *sections = (Elf_Shdr *) ((char *)h + h->e_shoff); 23 | Elf_Shdr *section_header_strtab = sections + h->e_shstrndx; 24 | 25 | for (uint32_t i = 0; i < h->e_shnum; i++) { 26 | 27 | Elf_Shdr *s = sections + i; 28 | char *name = (char *)h + section_header_strtab->sh_offset + s->sh_name; 29 | 30 | if (!strcmp(name, section_name)) { 31 | return s; 32 | } 33 | } 34 | 35 | return NULL; 36 | } 37 | -------------------------------------------------------------------------------- /include/tilck/common/page_size.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) \ 6 | || defined(__riscv) 7 | 8 | #define PAGE_SHIFT 12ul 9 | 10 | #if !defined(PAGE_SIZE) || (defined(PAGE_SIZE) && PAGE_SIZE == 4096) 11 | #undef PAGE_SIZE 12 | #define PAGE_SIZE 4096ul 13 | #else 14 | #error PAGE_SIZE already defined with different value 15 | #endif 16 | 17 | #else 18 | 19 | #error Unsupported architecture. 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/tilck/common/tilck_sound.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * Tilck's userspace interface for sound drivers (e.g. /dev/sb16). 5 | * 6 | * TODO: drop this by implementing Linux's kernel ALSA interface. 7 | */ 8 | 9 | #pragma once 10 | #include 11 | 12 | #define TILCK_IOCTL_SOUND_ACQUIRE 1 13 | #define TILCK_IOCTL_SOUND_RELEASE 2 14 | #define TILCK_IOCTL_SOUND_SETUP 3 15 | #define TILCK_IOCTL_SOUND_PAUSE 4 16 | #define TILCK_IOCTL_SOUND_CONTINUE 5 17 | #define TILCK_IOCTL_SOUND_GET_INFO 6 18 | #define TILCK_IOCTL_SOUND_WAIT_COMPLETION 7 19 | 20 | /* Used with TILCK_IOCTL_SOUND_GET_INFO */ 21 | struct tilck_sound_card_info { 22 | 23 | char name[32]; 24 | u32 max_sample_rate; 25 | u32 max_bits; 26 | u32 max_channels; 27 | }; 28 | 29 | /* Used with TILCK_IOCTL_SOUND_SETUP */ 30 | struct tilck_sound_params { 31 | 32 | u16 sample_rate; /* 44100, 22050 etc. */ 33 | u8 bits; /* 8 or 16 */ 34 | u8 channels; /* 1 or 2 */ 35 | u8 sign; /* 0 = unsigned, 1 = signed */ 36 | }; 37 | -------------------------------------------------------------------------------- /include/tilck/kernel/arch/generic_x86/arch_ints.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | extern const char *x86_exception_names[32]; 8 | extern struct list irq_handlers_lists[16]; 9 | extern void (*irq_entry_points[16])(void); 10 | extern soft_int_handler_t fault_handlers[32]; 11 | 12 | static ALWAYS_INLINE int int_to_irq(int int_num) 13 | { 14 | return int_num >= 32 ? int_num - 32 : -1; 15 | } 16 | 17 | static ALWAYS_INLINE bool is_irq(int int_num) 18 | { 19 | return int_num >= 32 && int_num != SYSCALL_SOFT_INTERRUPT; 20 | } 21 | 22 | static ALWAYS_INLINE bool is_timer_irq(int int_num) 23 | { 24 | return int_to_irq(int_num) == X86_PC_TIMER_IRQ; 25 | } 26 | 27 | static ALWAYS_INLINE bool is_fault(int int_num) 28 | { 29 | return IN_RANGE(int_num, 0, 32); 30 | } 31 | -------------------------------------------------------------------------------- /include/tilck/kernel/arch/generic_x86/debug_utils_x86.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | void dump_eflags(u32 f); 7 | -------------------------------------------------------------------------------- /include/tilck/kernel/arch/i386/tss.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | struct tss_entry { 7 | 8 | u32 prev_tss; /* ptr to the previous TSS: unused in Tilck */ 9 | 10 | u32 esp0; /* ESP to use when we change to kernel mode */ 11 | u32 ss0; /* SS to use when we change to kernel mode */ 12 | 13 | /* Unused registers in Tilck (the hardware task-switch is not used) */ 14 | u32 esp1; 15 | u32 ss1; 16 | u32 esp2; 17 | u32 ss2; 18 | u32 cr3; 19 | u32 eip; 20 | u32 eflags; 21 | u32 eax; 22 | u32 ecx; 23 | u32 edx; 24 | u32 ebx; 25 | u32 esp; 26 | u32 ebp; 27 | u32 esi; 28 | u32 edi; 29 | u32 es; 30 | u32 cs; 31 | u32 ss; 32 | u32 ds; 33 | u32 fs; 34 | u32 gs; 35 | u32 ldt; 36 | u16 trap; 37 | u16 iomap_base; 38 | 39 | } PACKED; 40 | -------------------------------------------------------------------------------- /include/tilck/kernel/arch/riscv/arch_ints.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | #define MAX_IRQ_NUM 256 8 | 9 | extern const char *riscv_exception_names[32]; 10 | extern struct list irq_handlers_lists[MAX_IRQ_NUM]; 11 | extern soft_int_handler_t fault_handlers[32]; 12 | 13 | static ALWAYS_INLINE int int_to_irq(int int_num) 14 | { 15 | return int_num >= 32 ? int_num - 32 : -1; 16 | } 17 | 18 | static ALWAYS_INLINE bool is_irq(int int_num) 19 | { 20 | return int_num >= 32; 21 | } 22 | 23 | static ALWAYS_INLINE bool is_timer_irq(int int_num) 24 | { 25 | return int_to_irq(int_num) == IRQ_S_TIMER; 26 | } 27 | 28 | static ALWAYS_INLINE bool is_fault(int int_num) 29 | { 30 | return IN_RANGE(int_num, 0, 32); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /include/tilck/kernel/arch/riscv/ioremap.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | /* The size pointer returns the actual allocated size */ 7 | void *ioremap(ulong paddr, size_t size); 8 | void iounmap(void *vaddr); 9 | 10 | -------------------------------------------------------------------------------- /include/tilck/kernel/arch/x86_64/asm_defs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | #if KERNEL_STACK_PAGES == 1 8 | #define ASM_KERNEL_STACK_SZ 4096 9 | #elif KERNEL_STACK_PAGES == 2 10 | #define ASM_KERNEL_STACK_SZ 8192 11 | #elif KERNEL_STACK_PAGES == 4 12 | #define ASM_KERNEL_STACK_SZ 16384 13 | #else 14 | #error Unsupported value of KERNEL_STACK_PAGES 15 | #endif 16 | 17 | 18 | #define REGS_FL_FPU_ENABLED 8 19 | 20 | 21 | /* Some useful asm macros */ 22 | #ifdef ASM_FILE 23 | 24 | #define NBITS 64 25 | 26 | #define FUNC(x) .type x, @function; x 27 | #define END_FUNC(x) .size x, .-(x) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/tilck/kernel/cmdline.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | #define MAX_CMD_ARGS 16 8 | #define MAX_CMD_ARG_LEN 255 9 | 10 | extern const char *cmd_args[MAX_CMD_ARGS]; 11 | extern void (*self_test_to_run)(void); 12 | 13 | #define DEFINE_KOPT(name, alias, type, default) extern type kopt_##name; 14 | #include 15 | #undef DEFINE_KOPT 16 | 17 | #define KOPT_DEFAULT_ELEM(name, alias, type, default) \ 18 | { #name, #alias, KOPT_TYPE_##type, &kopt_##name }, 19 | 20 | void parse_kernel_cmdline(const char *cmdline); 21 | -------------------------------------------------------------------------------- /include/tilck/kernel/elf_loader.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #define ELF_RAW_HEADER_SIZE 128 9 | 10 | struct locked_file; /* forward declaration */ 11 | 12 | struct elf_program_info { 13 | 14 | pdir_t *pdir; // The pdir used for the program 15 | void *entry; // The address of program's entry point 16 | void *stack; // The initial value of the stack pointer 17 | void *brk; // The first invalid vaddr (program break) 18 | struct locked_file *lf; // ELF's file lock (can be NULL) 19 | bool wrong_arch; // The ELF is compiled for the wrong arch 20 | bool dyn_exec; // The ELF is a dynamic executable (not supported) 21 | }; 22 | 23 | /* 24 | * Loads an ELF program in memory. 25 | * 26 | * `filepath`: IN arg, the path of the ELF file to load. 27 | * 28 | * `header_buf`: IN arg, the address of a buffer where to store the first 29 | * `ELF_RAW_HEADER_SIZE` bytes of the file at `filepath`. 30 | * 31 | * 'pinfo': OUT arg, essential info about the loaded program. 32 | */ 33 | int load_elf_program(const char *filepath, 34 | char *header_buf, 35 | struct elf_program_info *pinfo); 36 | -------------------------------------------------------------------------------- /include/tilck/kernel/elf_utils.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | #define SELFTEST_PREFIX "selftest_" 8 | 9 | struct elf_symbol_info { 10 | 11 | void *vaddr; 12 | u32 size; 13 | const char *name; 14 | }; 15 | 16 | void call_kernel_global_ctors(void); 17 | ulong find_addr_of_symbol(const char *searched_sym); 18 | const char *find_sym_at_addr(ulong vaddr, long *off, u32 *sym_size); 19 | const char *find_sym_at_addr_safe(ulong vaddr, long *off, u32 *sym_size); 20 | 21 | int foreach_symbol(int (*cb)(struct elf_symbol_info *, void *), void *arg); 22 | -------------------------------------------------------------------------------- /include/tilck/kernel/fault_resumable.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static inline bool in_fault_resumable_code(void) 10 | { 11 | return get_curr_task()->faults_resume_mask != 0; 12 | } 13 | 14 | static inline bool is_fault_resumable(int fault_num) 15 | { 16 | ASSERT(fault_num <= 31); 17 | return (1u << fault_num) & get_curr_task()->faults_resume_mask; 18 | } 19 | 20 | static inline int get_fault_num(u32 r) 21 | { 22 | for (int i = 0; i < 32; i++) 23 | if (r & (1 << i)) 24 | return i; 25 | 26 | return -1; 27 | } 28 | 29 | void handle_resumable_fault(regs_t *r); 30 | u32 fault_resumable_call(u32 faults_mask, void *func, u32 nargs, ...); 31 | 32 | -------------------------------------------------------------------------------- /include/tilck/kernel/fs/flock.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | struct locked_file; /* forward declaration */ 12 | 13 | int 14 | acquire_subsys_flock(struct mnt_fs *fs, 15 | vfs_inode_ptr_t i, 16 | enum subsystem subsys, 17 | struct locked_file **lock_ref); /* out */ 18 | 19 | int 20 | acquire_subsys_flock_h(fs_handle h, 21 | enum subsystem subsys, 22 | struct locked_file **lock_ref); /* out */ 23 | 24 | void retain_subsys_flock(struct locked_file *lf); 25 | void release_subsys_flock(struct locked_file *lf); 26 | -------------------------------------------------------------------------------- /include/tilck/kernel/fs/kernelfs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | #define KOBJ_BASE_FIELDS \ 7 | REF_COUNTED_OBJECT; \ 8 | void (*on_handle_close)(fs_handle h); \ 9 | void (*on_handle_dup)(fs_handle h); \ 10 | void (*destory_obj)(struct kobj_base *); 11 | 12 | struct kobj_base { 13 | 14 | KOBJ_BASE_FIELDS 15 | }; 16 | 17 | struct kfs_handle { 18 | 19 | FS_HANDLE_BASE_FIELDS 20 | struct kobj_base *kobj; 21 | }; 22 | 23 | STATIC_ASSERT(sizeof(struct kfs_handle) <= MAX_FS_HANDLE_SIZE); 24 | 25 | void init_kernelfs(void); 26 | void kfs_destroy_handle(struct kfs_handle *h); 27 | struct kfs_handle * 28 | kfs_create_new_handle(const struct file_ops *fops, 29 | struct kobj_base *kobj, 30 | int fl_flags); 31 | -------------------------------------------------------------------------------- /include/tilck/kernel/gcov.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | void gcov_dump_coverage(void); 6 | 7 | int tilck_sys_gcov_get_file_count(void); 8 | int tilck_sys_gcov_get_file_info(int fn, 9 | char *user_fname_buf, 10 | u32 fname_buf_size, 11 | u32 *user_fsize); 12 | int tilck_sys_gcov_get_file(int fn, char *user_buf); 13 | -------------------------------------------------------------------------------- /include/tilck/kernel/interrupts.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | void set_fault_handler(int fault, void *ptr); 11 | 12 | static ALWAYS_INLINE bool in_irq(void) 13 | { 14 | extern ATOMIC(int) __in_irq_count; 15 | return atomic_load_explicit(&__in_irq_count, mo_relaxed) > 0; 16 | } 17 | 18 | #if KRN_TRACK_NESTED_INTERR 19 | void check_not_in_irq_handler(void); 20 | void check_in_irq_handler(void); 21 | void push_nested_interrupt(int int_num); 22 | void pop_nested_interrupt(void); 23 | void nested_interrupts_drop_top_syscall(void); 24 | void panic_dump_nested_interrupts(void); 25 | void check_in_no_other_irq_than_timer(void); 26 | bool in_nested_irq_num(int irq_num); 27 | #else 28 | static inline void check_not_in_irq_handler(void) { } 29 | static inline void check_in_irq_handler(void) { } 30 | static inline void push_nested_interrupt(int int_num) { } 31 | static inline void pop_nested_interrupt(void) { } 32 | static inline void nested_interrupts_drop_top_syscall(void) { } 33 | static inline void panic_dump_nested_interrupts(void) { } 34 | static inline void check_in_no_other_irq_than_timer(void) { } 35 | static inline bool in_nested_irq_num(int irq_num) { NOT_REACHED(); } 36 | #endif 37 | -------------------------------------------------------------------------------- /include/tilck/kernel/irq.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | struct irq_handler_node { 10 | 11 | struct list_node node; 12 | irq_handler_t handler; 13 | void *context; /* device-specific context, passed to the handler */ 14 | }; 15 | 16 | #define DEFINE_IRQ_HANDLER_NODE(node_name, func, ctx) \ 17 | static struct irq_handler_node node_name = { \ 18 | .node = STATIC_LIST_NODE_INIT(node_name.node), \ 19 | .handler = (func), \ 20 | .context = (ctx), \ 21 | }; 22 | 23 | 24 | void init_irq_handling(); 25 | 26 | void irq_install_handler(u8 irq, struct irq_handler_node *n); 27 | void irq_uninstall_handler(u8 irq, struct irq_handler_node *n); 28 | 29 | void irq_set_mask(int irq); 30 | void irq_clear_mask(int irq); 31 | bool irq_is_masked(int irq); 32 | -------------------------------------------------------------------------------- /include/tilck/kernel/modules.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | struct module { 9 | 10 | const char *name; 11 | int priority; 12 | void (*init)(void); 13 | }; 14 | 15 | void init_modules(void); 16 | void register_module(struct module *m); 17 | 18 | #define REGISTER_MODULE(m) \ 19 | __attribute__((constructor)) \ 20 | static void __register_module(void) \ 21 | { \ 22 | register_module(m); \ 23 | } 24 | 25 | 26 | /* Order of initialization of Tilck's modules */ 27 | 28 | #define MOD_sysfs_prio 10 /* first */ 29 | #define MOD_pci_prio 20 30 | #define MOD_acpi_prio 30 31 | #define MOD_kb_prio 50 32 | #define MOD_tracing_prio 100 33 | #define MOD_tty_prio 200 34 | #define MOD_fbdev_prio 300 35 | #define MOD_serial_prio 400 36 | #define MOD_sb16_prio 410 37 | #define MOD_systests_prio 990 38 | #define MOD_dp_prio 1000 /* last */ 39 | -------------------------------------------------------------------------------- /include/tilck/kernel/paging_hw.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | static ALWAYS_INLINE void set_curr_pdir(pdir_t *pdir) 8 | { 9 | __set_curr_pdir(LIN_VA_TO_PA(pdir)); 10 | } 11 | 12 | static ALWAYS_INLINE pdir_t *get_curr_pdir() 13 | { 14 | return PA_TO_LIN_VA(__get_curr_pdir()); 15 | } 16 | 17 | /* 18 | * Tilck's entry point is in `_start` where the so-called "original" 19 | * page directory is set, using the `page_size_buf` as buffer. The original 20 | * page directory just linearly maps the first 8 MB of the physical memory to 21 | * BASE_VA. This function returns true if we're still using that page 22 | * directory (-> early_init_paging() has not been called yet). 23 | */ 24 | static ALWAYS_INLINE bool still_using_orig_pdir(void) 25 | { 26 | #ifndef UNIT_TEST_ENVIRONMENT 27 | /* 28 | * Use the lower-level __get_curr_pdir() function and compare the pdirs using 29 | * their physical address, in order to handle the case where KRN32_LIN_VADDR 30 | * is disabled. 31 | */ 32 | return __get_curr_pdir() == KERNEL_VA_TO_PA(page_size_buf); 33 | #else 34 | return false; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /include/tilck/kernel/pipe.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #define PIPE_BUF_SIZE 4096 5 | 6 | struct pipe; 7 | 8 | struct pipe *create_pipe(void); 9 | void destroy_pipe(struct pipe *p); 10 | fs_handle pipe_create_read_handle(struct pipe *p); 11 | fs_handle pipe_create_write_handle(struct pipe *p); 12 | -------------------------------------------------------------------------------- /include/tilck/kernel/signal.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include // system header 8 | #include // system header 9 | 10 | #define SIG_FL_PROCESS (1 << 0) 11 | #define SIG_FL_FAULT (1 << 1) 12 | 13 | enum sig_state { 14 | 15 | sig_none = 0, 16 | sig_pre_syscall = 1, 17 | sig_in_syscall = 2, 18 | sig_in_usermode = 3, 19 | sig_in_return = 4, 20 | sig_in_fault = 5, 21 | 22 | } PACKED; 23 | 24 | int send_signal_to_group(int pgid, int sig); 25 | int send_signal_to_session(int sid, int sig); 26 | int send_signal2(int pid, int tid, int signum, int flags); 27 | bool process_signals(void *curr, enum sig_state new_sig_state, void *regs); 28 | void drop_all_pending_signals(void *curr); 29 | void reset_all_custom_signal_handlers(void *curr); 30 | 31 | static inline int send_signal(int tid, int signum, int flags) 32 | { 33 | return send_signal2(tid, tid, signum, flags); 34 | } 35 | 36 | #define K_SIGACTION_MASK_WORDS (_NSIG / NBITS) 37 | -------------------------------------------------------------------------------- /include/tilck/kernel/sort.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | void 7 | insertion_sort_ptr(void *arr, u32 elem_count, cmpfun_ptr cmp); 8 | 9 | void 10 | insertion_sort_generic(void *a, ulong elem_sz, u32 elem_count, cmpfun_ptr cmp); 11 | 12 | void 13 | array_reverse_ptr(void *a, u32 elem_count); 14 | -------------------------------------------------------------------------------- /include/tilck/kernel/subsystems.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | enum subsystem { 6 | 7 | SUBSYS_INVALID = 0, 8 | SUBSYS_VFS = 1, 9 | SUBSYS_PROCMGNT = 2, 10 | }; 11 | -------------------------------------------------------------------------------- /include/tilck/kernel/system_mmap_int.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | /* 4 | * Expose the internal data variables of system memory's map. 5 | * 6 | * WARNING 7 | * --------- 8 | * This *internal* header is supposed to be used in the very few places where 9 | * actually updating system's memory map is allowed. For example: 10 | * 11 | * - in set_framebuffer_info_from_mbi(), 12 | * during the initialization of the framebuffer console 13 | * 14 | * - in arch_add_initial_mem_regions(), 15 | * during system_mmap_set() 16 | * 17 | * - in arch_add_final_mem_regions(), 18 | * during system_mmap_set() 19 | * 20 | * - in the system map's unit tests 21 | * 22 | * Outside of kernel's initialization, system's memory map is assumed to be 23 | * immutable. 24 | */ 25 | 26 | #pragma once 27 | #include 28 | 29 | extern struct mem_region mem_regions[MAX_MEM_REGIONS]; 30 | extern int mem_regions_count; 31 | void append_mem_region(struct mem_region r); 32 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/README: -------------------------------------------------------------------------------- 1 | This directory contains special test headers, where STATIC kernel functions 2 | are declared. STATIC kernel functions are functions that are static only when 3 | the real kernel is compiled, while they turn to regular functions when the 4 | kernel is compiled as a static library for unit tests. 5 | 6 | The reason for having such headers and including the both in the kernel's and 7 | in the unit tests' code is to make impossible to have a function signature 8 | mismatch without breaking the build. 9 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/cmdline.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | struct arg_parse_ctx; 7 | 8 | STATIC void 9 | use_kernel_arg(struct arg_parse_ctx *ctx, int arg_num, const char *arg); 10 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/fat32.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | void fat_dump_info(void *fatpart_begin); 6 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/fork.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | STATIC int fork_dup_all_handles(struct process *pi); 7 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/itoa.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | s32 tilck_strtol32(const char *s, const char **endptr, int base, int *err); 7 | s64 tilck_strtol64(const char *s, const char **endptr, int base, int *err); 8 | u32 tilck_strtoul32(const char *s, const char **endptr, int base, int *err); 9 | u64 tilck_strtoul64(const char *s, const char **endptr, int base, int *err); 10 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/kmalloc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | #ifdef UNIT_TEST_ENVIRONMENT 8 | extern bool kmalloc_initialized; 9 | extern struct kmalloc_heap first_heap_struct; 10 | extern struct kmalloc_heap *heaps[KMALLOC_HEAPS_COUNT]; 11 | extern int used_heaps; 12 | extern size_t max_tot_heap_mem_free; 13 | #endif 14 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/mem_regions.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | STATIC void fix_mem_regions(void); 8 | STATIC void align_mem_regions_to_page_boundary(void); 9 | STATIC void sort_mem_regions(void); 10 | STATIC void merge_adj_mem_regions(void); 11 | STATIC void handle_overlapping_regions(void); 12 | 13 | extern struct mem_region mem_regions[MAX_MEM_REGIONS]; 14 | extern int mem_regions_count; 15 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/tracing.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #include 6 | STATIC bool simple_wildcard_match(const char *str, const char *expr); 7 | STATIC int set_traced_syscalls_int(const char *str); 8 | 9 | STATIC bool save_param_buffer(void *, long, char *, size_t); 10 | STATIC bool dump_param_buffer(ulong, char *, long, long, char *, size_t); 11 | 12 | extern bool *traced_syscalls; 13 | extern char *traced_syscalls_str; 14 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/tty_test.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | #include 7 | 8 | STATIC struct tty * 9 | allocate_and_init_tty(u16 minor, u16 serial_port_fwd, int rows_buf); 10 | 11 | void tty_update_default_state_tables(struct tty *t); 12 | 13 | extern term *__curr_term; 14 | extern const struct term_interface *__curr_term_intf; 15 | extern const struct term_interface *video_term_intf; 16 | extern const struct term_interface *serial_term_intf; 17 | -------------------------------------------------------------------------------- /include/tilck/kernel/test/vfs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | struct mnt_fs *ramfs_create(void); 8 | -------------------------------------------------------------------------------- /include/tilck/kernel/timer.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | void kernel_sleep(u64 ticks); /* sleep for `ticks` timer ticks (jiffies) */ 8 | void kernel_sleep_ms(u64 ms); /* sleep for `ms` milliseconds */ 9 | void delay_us(u32 us); /* busy-wait for `us` microseconds */ 10 | 11 | static ALWAYS_INLINE u64 12 | ms_to_ticks(u64 ms) 13 | { 14 | return ms / (1000 / TIMER_HZ); 15 | } 16 | 17 | u64 get_ticks(void); 18 | void init_timer(void); 19 | -------------------------------------------------------------------------------- /include/tilck/kernel/tty.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | struct tty; 8 | 9 | static ALWAYS_INLINE struct tty *get_curr_tty(void) 10 | { 11 | extern struct tty *__curr_tty; 12 | return __curr_tty; 13 | } 14 | 15 | void tty_send_keyevent(struct tty *t, struct key_event ke, bool block); 16 | void tty_setup_for_panic(struct tty *t); 17 | int tty_get_num(struct tty *t); 18 | void tty_restore_kd_text_mode(struct tty *t); 19 | struct tty *get_serial_tty(int n); 20 | void tty_reset_termios(struct tty *t); 21 | struct tty *get_curr_process_tty(void); 22 | int get_curr_proc_tty_term_type(void); 23 | ssize_t tty_curr_proc_write(const char *buf, size_t size); 24 | void tty_write_on_all_ttys(const char *buf, size_t size); 25 | 26 | static inline int get_curr_tty_num(void) 27 | { 28 | return tty_get_num(get_curr_tty()); 29 | } 30 | 31 | /* Used only by the debug panel */ 32 | int set_curr_tty(struct tty *t); 33 | struct tty *create_tty_nodev(void); 34 | void tty_set_raw_mode(struct tty *t); 35 | void tty_set_medium_raw_mode(struct tty *t, bool enabled); 36 | -------------------------------------------------------------------------------- /include/tilck/kernel/tty_struct.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include // system header 13 | #include // system header 14 | 15 | struct tty; 16 | typedef bool (*tty_ctrl_sig_func)(struct tty *, bool); 17 | 18 | void tty_reset_filter_ctx(struct tty *t); 19 | void tty_inbuf_reset(struct tty *t); 20 | 21 | struct tty { 22 | 23 | term *tstate; 24 | const struct term_interface *tintf; 25 | struct term_params tparams; 26 | void *console_data; 27 | void *devfile; 28 | char dev_filename[16]; 29 | 30 | int minor; 31 | int fg_pgid; 32 | 33 | struct ringbuf input_ringbuf; 34 | struct kcond input_cond; /* signal when we can read from input_rb */ 35 | struct kcond output_cond; /* signal when we can write to input_rb */ 36 | int end_line_delim_count; 37 | 38 | bool mediumraw_mode; 39 | u8 curr_color; 40 | u16 serial_port_fwd; 41 | 42 | char *input_buf; 43 | u32 kd_gfx_mode; 44 | tty_ctrl_sig_func *ctrl_handlers; 45 | struct termios c_term; 46 | }; 47 | -------------------------------------------------------------------------------- /include/tilck/kernel/uefi.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | void uefi_set_rt_pointer(ulong addr); 7 | void setup_uefi_runtime_services(void); 8 | 9 | static ALWAYS_INLINE bool is_uefi_boot(void) 10 | { 11 | extern ulong uefi_rt_addr; 12 | return !!uefi_rt_addr; 13 | } 14 | -------------------------------------------------------------------------------- /include/tilck/kernel/vdso.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | extern const ulong vdso_begin; 7 | extern const ulong vdso_end; 8 | extern const ulong sysexit_user_code_user_vaddr; 9 | extern const ulong post_sig_handler_user_vaddr; 10 | extern const ulong pause_trampoline_user_vaddr; 11 | -------------------------------------------------------------------------------- /include/tilck/kernel/worker_thread.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | #define WTH_PRIO_HIGHEST 0 7 | #define WTH_PRIO_LOWEST 255 8 | 9 | struct worker_thread; 10 | 11 | void 12 | init_worker_threads(); 13 | 14 | struct task * 15 | wth_get_task(struct worker_thread *wth); 16 | 17 | u32 18 | wth_get_queue_size(struct worker_thread *wth); 19 | 20 | int 21 | wth_get_priority(struct worker_thread *wth); 22 | 23 | const char * 24 | wth_get_name(struct worker_thread *wth); 25 | 26 | struct task * 27 | wth_get_runnable_thread(void); 28 | 29 | struct worker_thread * 30 | wth_create_thread(const char *name, int priority, u16 queue_size); 31 | 32 | struct worker_thread * 33 | wth_find_worker(int lowest_prio); 34 | 35 | NODISCARD bool 36 | wth_enqueue_on(struct worker_thread *wth, void (*func)(void *), void *arg); 37 | 38 | NODISCARD bool 39 | wth_enqueue_anywhere(int lowest_prio, void (*func)(void *), void *arg); 40 | 41 | void 42 | wth_wait_for_completion(struct worker_thread *wth); 43 | -------------------------------------------------------------------------------- /include/tilck/mods/console.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | struct tty; 7 | 8 | void *alloc_console_data(void); 9 | void free_console_data(void *data); 10 | void reset_console_data(struct tty *t); 11 | void init_textmode_console(void); 12 | -------------------------------------------------------------------------------- /include/tilck/mods/fb_console.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | static ALWAYS_INLINE bool use_framebuffer(void) 9 | { 10 | extern bool __use_framebuffer; 11 | return __use_framebuffer; 12 | } 13 | 14 | void set_framebuffer_info_from_mbi(multiboot_info_t *mbi); 15 | void init_fb_console(void); 16 | 17 | // Debug/devel function 18 | void debug_dump_glyph(u32 n); 19 | 20 | // Runtime debug info funcs [debugpanel] 21 | 22 | struct fb_console_info { 23 | 24 | u16 res_x; 25 | u16 res_y; 26 | u16 bpp; 27 | u16 font_h; 28 | u16 font_w; 29 | }; 30 | 31 | bool fb_is_using_opt_funcs(void); 32 | void fb_console_get_info(struct fb_console_info *i); 33 | -------------------------------------------------------------------------------- /include/tilck/mods/serial.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | void init_serial_port(u16 port); 8 | 9 | bool serial_read_ready(u16 port); 10 | void serial_wait_for_read(u16 port); 11 | char serial_read(u16 port); 12 | 13 | bool serial_write_ready(u16 port); 14 | void serial_wait_for_write(u16 port); 15 | void serial_write(u16 port, char c); 16 | 17 | #if MOD_serial 18 | void early_init_serial_ports(void); 19 | #else 20 | static inline void early_init_serial_ports(void) { } 21 | #endif 22 | -------------------------------------------------------------------------------- /kernel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | include_directories(${CMAKE_SOURCE_DIR}/include) 5 | include_directories(${CMAKE_SOURCE_DIR}/include/system_headers) 6 | include_directories(${TCROOT}/noarch/acpica) 7 | 8 | add_subdirectory(arch) 9 | -------------------------------------------------------------------------------- /kernel/arch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | if (${KERNEL_SYSCC} OR ${USE_SYSCC}) 5 | 6 | if (${ARCH} STREQUAL "i386") 7 | 8 | set(CMAKE_C_FLAGS "${ARCH_GCC_FLAGS}") 9 | set(CMAKE_CXX_FLAGS "${ARCH_GCC_FLAGS} ${KERNEL_CXX_FLAGS}") 10 | 11 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU") 12 | set(CMAKE_ASM_FLAGS "${ARCH_GCC_FLAGS}") 13 | else() 14 | # If system's compiler (CC) is Clang, we cannot use it for compiling 15 | # our assembly code, because LLVM's assembler (llvm-as) is not 100% 16 | # compatible with GAS's intel-syntax dialect. 17 | set(CMAKE_ASM_COMPILER ${GCC_TOOLCHAIN}/${ARCH_GCC_TC}-linux-gcc) 18 | endif() 19 | 20 | endif() 21 | 22 | if (KERNEL_FORCE_TC_ISYSTEM) 23 | include_directories(SYSTEM ${GCC_TC_ISYSTEM}) 24 | endif() 25 | 26 | else() 27 | set_cross_compiler() 28 | endif() 29 | 30 | smart_config_file( 31 | ${CMAKE_SOURCE_DIR}/scripts/templates/generate_coverage_report 32 | ${CMAKE_BINARY_DIR}/scripts/generate_kernel_coverage_report 33 | ) 34 | 35 | add_subdirectory(${ARCH}) 36 | -------------------------------------------------------------------------------- /kernel/arch/generic_x86/pic.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | 5 | void init_pic_8259(u8 offset1, u8 offset2); 6 | void pic_mask_and_send_eoi(int irq); 7 | void pic_send_eoi(int irq); 8 | bool pic_is_spur_irq(int irq); 9 | void irq_set_mask(int irq); 10 | void irq_clear_mask(int irq); 11 | -------------------------------------------------------------------------------- /kernel/arch/i386/double_fault.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | void register_double_fault_tss_entry(void); 7 | -------------------------------------------------------------------------------- /kernel/arch/i386/irq.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include "idt_int.h" 12 | #include "../generic_x86/pic.h" 13 | 14 | 15 | /* 16 | * We first remap the interrupt controllers, and then we install 17 | * the appropriate ISRs to the correct entries in the IDT. This 18 | * is just like installing the exception handlers. 19 | */ 20 | 21 | void init_irq_handling(void) 22 | { 23 | ASSERT(!are_interrupts_enabled()); 24 | init_pic_8259(32, 40); 25 | 26 | for (int i = 0; i < ARRAY_SIZE(irq_handlers_lists); i++) { 27 | 28 | idt_set_entry(32 + (u8)i, 29 | irq_entry_points[i], 30 | X86_KERNEL_CODE_SEL, 31 | IDT_FLAG_PRESENT | IDT_FLAG_INT_GATE | IDT_FLAG_DPL0); 32 | 33 | irq_set_mask(i); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /kernel/arch/i386/irq_handlers.S: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | .intel_syntax noprefix 4 | 5 | #define ASM_FILE 1 6 | #include 7 | #include 8 | 9 | .section .text 10 | .global irq_entry_points 11 | .global asm_irq_entry 12 | 13 | # IRQs common entry point 14 | FUNC(asm_irq_entry): 15 | 16 | kernel_entry_common 17 | push_custom_flags (0) 18 | 19 | push offset .irq_resume 20 | mov eax, esp 21 | cld # Set DF = 0, as C compilers by default assume that. 22 | push eax 23 | call irq_entry 24 | 25 | add esp, 8 # Discard the previousy-pushed 'eax' and .irq_resume 26 | 27 | .irq_resume: 28 | pop_custom_flags 29 | kernel_exit_common 30 | 31 | END_FUNC(asm_irq_entry) 32 | 33 | .macro create_irq_entry_point number 34 | FUNC(irq\number): 35 | push 0 36 | push 32+\number 37 | jmp asm_irq_entry 38 | END_FUNC(irq\number) 39 | .endm 40 | 41 | .altmacro 42 | 43 | .set i, 0 44 | .rept 16 45 | create_irq_entry_point %i 46 | .set i, i+1 47 | .endr 48 | 49 | .macro insert_irq_addr num 50 | .long irq\num 51 | .endm 52 | 53 | .align 4 54 | irq_entry_points: 55 | .set i, 0 56 | .rept 16 57 | insert_irq_addr %i 58 | .set i, i+1 59 | .endr 60 | 61 | # Tell GNU ld to not worry about us having an executable stack 62 | .section .note.GNU-stack,"",@progbits 63 | -------------------------------------------------------------------------------- /kernel/arch/i386/ldt.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "gdt_int.h" 10 | 11 | void load_ldt(u32 entry_index_in_gdt, u32 dpl) 12 | { 13 | ASSERT(!are_interrupts_enabled()); 14 | 15 | asmVolatile("lldt %w0" 16 | : /* no output */ 17 | : "q" (X86_SELECTOR(entry_index_in_gdt, TABLE_GDT, dpl)) 18 | : "memory"); 19 | } 20 | -------------------------------------------------------------------------------- /kernel/arch/riscv/fpu_memcpy.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #define __FPU_MEMCPY_C__ 4 | 5 | /* 6 | * The code in this translation unit, in particular the *single* funcs defined 7 | * in fpu_memcpy.h have to be FAST, even in debug builds. It is important the 8 | * hot-patched fpu_cpy_single_256_nt, created by copying the once of the 9 | * fpu_cpy_*single* funcs to just execute the necessary MOVs and then just a 10 | * RET. No prologue/epilogue, no frame pointer, no stack variables. 11 | * NOTE: clearly, the code works well even if -O0 and without the PRAGMAs 12 | * below. Just, we want it to be fast in debug builds to improve the user 13 | * experience there. 14 | */ 15 | 16 | #if defined(__GNUC__) && !defined(__clang__) 17 | #pragma GCC optimize "-O3" 18 | #pragma GCC optimize "-fomit-frame-pointer" 19 | #endif 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | void 32 | memcpy256_failsafe(void *dest, const void *src, u32 n) 33 | { 34 | memcpy32(dest, src, n * 8); 35 | } 36 | 37 | FASTCALL void 38 | memcpy_single_256_failsafe(void *dest, const void *src) 39 | { 40 | memcpy32(dest, src, 8); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /kernel/arch/riscv/misc.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | void init_textmode_console(void) 13 | { 14 | panic("ERROR: riscv don't support textmode console\n"); 15 | } 16 | 17 | NORETURN void poweroff(void) 18 | { 19 | printk("Halting the system...\n"); 20 | disable_interrupts_forced(); 21 | 22 | /* 23 | * Just print a message confirming that's safe to turn off 24 | * the machine. 25 | */ 26 | 27 | printk("System halted.\n"); 28 | 29 | while (true) { 30 | sbi_shutdown(); 31 | } 32 | } 33 | 34 | /* Reboot the machine, using the best method available */ 35 | NORETURN void reboot(void) 36 | { 37 | printk("Rebooting the machine...\n"); 38 | disable_interrupts_forced(); 39 | sbi_system_reset(SBI_SRST_TYPE_COLD_REBOOT, SBI_SRST_REASON_NONE); 40 | panic("Unable to reboot the machine"); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /kernel/arch/riscv/mmap.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | 6 | #include "paging_int.h" 7 | 8 | void arch_add_initial_mem_regions() 9 | { 10 | /* 11 | * Reserve 1MB below kernel's head, where 12 | * the flattened device tree is located. 13 | */ 14 | append_mem_region((struct mem_region) { 15 | .addr = KERNEL_VA_TO_PA(KERNEL_VADDR) - (1 * MB), 16 | .len = 1 * MB, 17 | .type = MULTIBOOT_MEMORY_RESERVED, 18 | .extra = MEM_REG_EXTRA_LOWMEM, 19 | }); 20 | } 21 | 22 | bool arch_add_final_mem_regions() 23 | { 24 | /* do nothing */ 25 | return false; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /kernel/arch/riscv/vdso.S: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | #define ASM_FILE 1 4 | #include 5 | #include 6 | 7 | .text 8 | 9 | .global vdso_begin 10 | .global vdso_end 11 | 12 | .balign 4096 13 | vdso_begin: 14 | 15 | .align 4 16 | # When each signal handler returns, it will jump here 17 | .post_sig_handler: 18 | li a7, 139 # sys_rt_sigreturn_impl() 19 | ecall # do the syscall 20 | 21 | .align 4 22 | # When we cannot immediately KILL a task != current, we make it call sys_pause() 23 | # and it will be killed after the task switch, in handle_syscall(). 24 | .pause_trampoline: 25 | li a0, 0 26 | li a1, 0 27 | li a2, 0 28 | li a3, 0 29 | li a4, 0 30 | li a7, 73 # sys_ppoll() 31 | ecall 32 | 33 | .space 4096-(.-vdso_begin), 0 34 | vdso_end: 35 | 36 | .global post_sig_handler_user_vaddr 37 | post_sig_handler_user_vaddr: 38 | RISCV_PTR USER_VDSO_VADDR + (.post_sig_handler - vdso_begin) 39 | 40 | .global pause_trampoline_user_vaddr 41 | pause_trampoline_user_vaddr: 42 | RISCV_PTR USER_VDSO_VADDR + (.pause_trampoline - vdso_begin) 43 | 44 | -------------------------------------------------------------------------------- /kernel/arch/x86_64/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/kernel/arch/x86_64/.gitignore -------------------------------------------------------------------------------- /kernel/arch/x86_64/debug.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | void dump_stacktrace(void *ebp, pdir_t *pdir) 18 | { 19 | // TODO: implement dump_stacktrace for x86-64 20 | } 21 | 22 | void dump_regs(regs_t *r) 23 | { 24 | // TODO: implement dump_regs for x86-64 25 | } 26 | -------------------------------------------------------------------------------- /kernel/arch/x86_64/double_fault.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | 6 | void on_first_pdir_update(void) 7 | { 8 | /* DO NOTHING, AT THE MOMENT */ 9 | } 10 | -------------------------------------------------------------------------------- /kernel/arch/x86_64/fake_impl.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | ulong vdso_begin = 0; /* fake value */ 8 | 9 | void copy_main_tss_on_regs(regs_t *ctx) 10 | { 11 | NOT_IMPLEMENTED(); 12 | } 13 | 14 | void init_segmentation(void) 15 | { 16 | NOT_IMPLEMENTED(); 17 | } 18 | -------------------------------------------------------------------------------- /kernel/arch/x86_64/fault_resumable.S: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | .intel_syntax noprefix 4 | 5 | #define ASM_FILE 1 6 | 7 | #include 8 | #include 9 | 10 | .code64 11 | 12 | .section .text 13 | 14 | .global fault_resumable_call 15 | 16 | FUNC(fault_resumable_call): 17 | // our 1st arg (mask) -> ignored 18 | mov rax, rsi // our 2nd arg (func pointer) -> RAX 19 | // our 3rd arg (nargs) -> ignored 20 | mov rdi, rcx // our 4rd arg -> 1st arg for func (RDI) 21 | mov rsi, r8 // our 5th arg -> 2nd arg for func (RSI) 22 | mov rdx, r9 // our 6th arg -> 3rd arg for func (RDX) 23 | mov rcx, QWORD PTR [rsp+16] // our 7th arg -> 4th arg of func (RCX) 24 | mov r8, QWORD PTR [rsp+24] // our 8th arg -> 5th arg of func (R8) 25 | mov r9, QWORD PTR [rsp+32] // our 9th arg -> 6th arg of func (R9) 26 | call rax 27 | xor rax, rax // simulate no faults, return 0 28 | ret 29 | 30 | .asm_fault_resumable_call_resume: 31 | 32 | //TODO: implement this 33 | ret 34 | 35 | END_FUNC(fault_resumable_call) 36 | 37 | # Tell GNU ld to not worry about us having an executable stack 38 | .section .note.GNU-stack,"",@progbits 39 | -------------------------------------------------------------------------------- /kernel/arch/x86_64/idt64.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void init_cpu_exception_handling(void) 12 | { 13 | NOT_IMPLEMENTED(); 14 | } 15 | -------------------------------------------------------------------------------- /kernel/arch/x86_64/irq64.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | void init_irq_handling(void) 12 | { 13 | NOT_IMPLEMENTED(); 14 | } 15 | -------------------------------------------------------------------------------- /kernel/arch/x86_64/kernel_yield.S: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | .intel_syntax noprefix 4 | 5 | #define ASM_FILE 1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | .section .text 15 | 16 | .code64 17 | 18 | .global asm_save_regs_and_schedule 19 | .global panic_save_current_state 20 | .global switch_to_initial_kernel_stack 21 | 22 | # Saves the current (kernel) state as if an interrupt occurred while running 23 | # in kernel mode. 24 | 25 | FUNC(asm_save_regs_and_schedule): 26 | 27 | # TODO: implement this 28 | ret 29 | 30 | .kernel_yield_resume: 31 | 32 | # TODO: implement this 33 | ret 34 | 35 | END_FUNC(asm_save_regs_and_schedule) 36 | 37 | FUNC(panic_save_current_state): 38 | 39 | # TODO: implement this 40 | ret 41 | 42 | END_FUNC(panic_save_current_state) 43 | 44 | FUNC(switch_to_initial_kernel_stack): 45 | 46 | # TODO: implement this 47 | ret 48 | 49 | END_FUNC(switch_to_initial_kernel_stack) 50 | 51 | # Tell GNU ld to not worry about us having an executable stack 52 | .section .note.GNU-stack,"",@progbits 53 | -------------------------------------------------------------------------------- /kernel/bintree/avl_find.c.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #if BINTREE_PTR_FUNCS 4 | #define CMP(a, b) bintree_find_ptr_cmp(a, b, field_off) 5 | #else 6 | #define CMP(a, b) objval_cmpfun(a, b) 7 | #endif 8 | 9 | #if BINTREE_PTR_FUNCS 10 | void * 11 | bintree_find_ptr_internal(void *root_obj, 12 | const void *value_ptr, 13 | long bintree_offset, 14 | long field_off) 15 | #else 16 | void * 17 | bintree_find_internal(void *root_obj, 18 | const void *value_ptr, 19 | cmpfun_ptr objval_cmpfun, 20 | long bintree_offset) 21 | #endif 22 | { 23 | long c; 24 | 25 | while (root_obj) { 26 | 27 | if (!(c = CMP(root_obj, value_ptr))) 28 | return root_obj; 29 | 30 | // root_obj is smaller then val => val is bigger => go right. 31 | root_obj = c < 0 ? RIGHT_OF(root_obj) : LEFT_OF(root_obj); 32 | } 33 | 34 | return NULL; 35 | } 36 | 37 | #undef CMP 38 | -------------------------------------------------------------------------------- /kernel/bintree/avl_remove.c.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #if BINTREE_PTR_FUNCS 4 | #define CMP(a, b) bintree_insrem_ptr_cmp(a, b, field_off) 5 | #else 6 | #define CMP(a, b) objval_cmpfun(a, b) 7 | #endif 8 | 9 | #if BINTREE_PTR_FUNCS 10 | void * 11 | bintree_remove_ptr_internal(void **root_obj_ref, 12 | void *obj_or_value, 13 | long bintree_offset, 14 | long field_off) 15 | #else 16 | void * 17 | bintree_remove_internal(void **root_obj_ref, 18 | void *obj_or_value, 19 | cmpfun_ptr objval_cmpfun, 20 | long bintree_offset) 21 | #endif 22 | { 23 | void **stack[MAX_TREE_HEIGHT]; 24 | int stack_size = 0; 25 | void *deleted_obj; 26 | 27 | AVL_BUILD_PATH_TO_OBJ(); 28 | deleted_obj = *STACK_TOP(); 29 | 30 | if (!deleted_obj) 31 | return NULL; /* element not found */ 32 | 33 | bintree_remove_internal_aux(STACK_TOP(), stack, stack_size, bintree_offset); 34 | return deleted_obj; 35 | } 36 | 37 | #undef CMP 38 | -------------------------------------------------------------------------------- /kernel/fs/fs_int.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | struct mountpoint { 7 | 8 | REF_COUNTED_OBJECT; 9 | 10 | vfs_inode_ptr_t host_fs_inode; 11 | struct mnt_fs *host_fs; 12 | struct mnt_fs *target_fs; 13 | }; 14 | 15 | #define RESOLVE_STACK_SIZE 4 16 | 17 | struct vfs_resolve_int_ctx { 18 | 19 | int ss; /* stack size */ 20 | bool exlock; /* true -> use exlock, 21 | false -> use shlock */ 22 | 23 | const char *orig_paths[RESOLVE_STACK_SIZE]; /* original paths stack */ 24 | struct vfs_path paths[RESOLVE_STACK_SIZE]; /* vfs paths stack */ 25 | char sym_paths[RESOLVE_STACK_SIZE][MAX_PATH]; /* symlinks paths stack */ 26 | }; 27 | -------------------------------------------------------------------------------- /kernel/fs/mp.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | 6 | #include "fs_int.h" 7 | 8 | int 9 | sys_mount(const char *user_source, 10 | const char *user_target, 11 | const char *user_fstype, 12 | unsigned long mountflags, 13 | const void *user_data) 14 | { 15 | return -ENOSYS; 16 | } 17 | 18 | int sys_umount(const char *target, int flags) 19 | { 20 | return -ENOSYS; 21 | } 22 | -------------------------------------------------------------------------------- /kernel/fs/ramfs/getdents.c.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | static int ramfs_getdents(fs_handle h, get_dents_func_cb cb, void *arg) 4 | { 5 | struct ramfs_handle *rh = h; 6 | struct ramfs_inode *inode = rh->inode; 7 | int rc = 0; 8 | 9 | if (inode->type != VFS_DIR) 10 | return -ENOTDIR; 11 | 12 | if ((inode->mode & 0400) != 0400) /* read permission */ 13 | return -EACCES; 14 | 15 | list_for_each_ro_kp(rh->dpos, &inode->entries_list, lnode) { 16 | 17 | struct vfs_dent64 dent = { 18 | .ino = rh->dpos->inode->ino, 19 | .type = rh->dpos->inode->type, 20 | .name_len = rh->dpos->name_len, 21 | .name = rh->dpos->name, 22 | }; 23 | 24 | if ((rc = cb(&dent, arg))) 25 | break; 26 | } 27 | 28 | return rc; 29 | } 30 | -------------------------------------------------------------------------------- /kernel/fs/ramfs/locking.c.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | static void ramfs_file_exlock(fs_handle h) 4 | { 5 | struct ramfs_handle *rh = h; 6 | rwlock_wp_exlock(&rh->inode->rwlock); 7 | } 8 | 9 | static void ramfs_file_exunlock(fs_handle h) 10 | { 11 | struct ramfs_handle *rh = h; 12 | rwlock_wp_exunlock(&rh->inode->rwlock); 13 | } 14 | 15 | static void ramfs_file_shlock(fs_handle h) 16 | { 17 | struct ramfs_handle *rh = h; 18 | rwlock_wp_shlock(&rh->inode->rwlock); 19 | } 20 | 21 | static void ramfs_file_shunlock(fs_handle h) 22 | { 23 | struct ramfs_handle *rh = h; 24 | rwlock_wp_shunlock(&rh->inode->rwlock); 25 | } 26 | 27 | 28 | static void ramfs_exlock(struct mnt_fs *fs) 29 | { 30 | struct ramfs_data *d = fs->device_data; 31 | rwlock_wp_exlock(&d->rwlock); 32 | } 33 | 34 | static void ramfs_exunlock(struct mnt_fs *fs) 35 | { 36 | struct ramfs_data *d = fs->device_data; 37 | rwlock_wp_exunlock(&d->rwlock); 38 | } 39 | 40 | static void ramfs_shlock(struct mnt_fs *fs) 41 | { 42 | struct ramfs_data *d = fs->device_data; 43 | rwlock_wp_shlock(&d->rwlock); 44 | } 45 | 46 | static void ramfs_shunlock(struct mnt_fs *fs) 47 | { 48 | struct ramfs_data *d = fs->device_data; 49 | rwlock_wp_shunlock(&d->rwlock); 50 | } 51 | -------------------------------------------------------------------------------- /kernel/fs/vfs/vfs_locking.c.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | void vfs_fs_exlock(struct mnt_fs *fs) 4 | { 5 | NO_TEST_ASSERT(is_preemption_enabled()); 6 | ASSERT(fs != NULL); 7 | ASSERT(fs->fsops->fs_exlock); 8 | 9 | fs->fsops->fs_exlock(fs); 10 | } 11 | 12 | void vfs_fs_exunlock(struct mnt_fs *fs) 13 | { 14 | NO_TEST_ASSERT(is_preemption_enabled()); 15 | ASSERT(fs != NULL); 16 | ASSERT(fs->fsops->fs_exunlock); 17 | 18 | fs->fsops->fs_exunlock(fs); 19 | } 20 | 21 | void vfs_fs_shlock(struct mnt_fs *fs) 22 | { 23 | NO_TEST_ASSERT(is_preemption_enabled()); 24 | ASSERT(fs != NULL); 25 | ASSERT(fs->fsops->fs_shlock); 26 | 27 | fs->fsops->fs_shlock(fs); 28 | } 29 | 30 | void vfs_fs_shunlock(struct mnt_fs *fs) 31 | { 32 | NO_TEST_ASSERT(is_preemption_enabled()); 33 | ASSERT(fs != NULL); 34 | ASSERT(fs->fsops->fs_shunlock); 35 | 36 | fs->fsops->fs_shunlock(fs); 37 | } 38 | -------------------------------------------------------------------------------- /kernel/kmalloc/kmalloc_block_node.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | #define FL_NODE_SPLIT (1 << 0) 7 | #define FL_NODE_FULL (1 << 1) 8 | #define FL_NODE_ALLOCATED (1 << 2) 9 | 10 | #define FL_NODE_SPLIT_AND_FULL (FL_NODE_SPLIT | FL_NODE_FULL) 11 | #define FL_NODE_ALLOCATED_AND_FULL (FL_NODE_ALLOCATED | FL_NODE_FULL) 12 | #define FL_NODE_ALLOCATED_AND_SPLIT (FL_NODE_ALLOCATED | FL_NODE_SPLIT) 13 | 14 | struct block_node { 15 | 16 | union { 17 | 18 | struct { 19 | // 1 if the block has been split. Check its children. 20 | u8 split : 1; 21 | 22 | // 1 means obviously completely full 23 | // 0 means completely empty if split=0, or partially empty if split=1 24 | u8 full : 1; 25 | 26 | u8 allocated : 1; // only for nodes with size = alloc_block_size 27 | u8 alloc_failed : 1; // only for nodes with size = alloc_block_size 28 | 29 | u8 unused : 4; // Free unused (for now) bits. 30 | }; 31 | 32 | u8 raw; 33 | }; 34 | }; 35 | -------------------------------------------------------------------------------- /kernel/modules.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | static int mods_count; 10 | static struct module *modules[32]; 11 | 12 | void register_module(struct module *m) 13 | { 14 | ASSERT(mods_count < ARRAY_SIZE(modules) - 1); 15 | modules[mods_count++] = m; 16 | } 17 | 18 | static long mod_cmp_func(const void *a, const void *b) 19 | { 20 | const struct module * const *ma = a; 21 | const struct module * const *mb = b; 22 | return (*ma)->priority - (*mb)->priority; 23 | } 24 | 25 | void init_modules(void) 26 | { 27 | insertion_sort_ptr(modules, (u32)mods_count, &mod_cmp_func); 28 | 29 | for (int i = 0; i < mods_count; i++) { 30 | struct module *m = modules[i]; 31 | printk("*** Init kernel module: %s\n", m->name); 32 | m->init(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /kernel/sources.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | set( 5 | KERNEL_NOARCH_SOURCES_GLOB 6 | 7 | "${CMAKE_SOURCE_DIR}/kernel/*.c" 8 | "${CMAKE_SOURCE_DIR}/kernel/*.cpp" 9 | "${CMAKE_SOURCE_DIR}/kernel/*/*.c" 10 | "${CMAKE_SOURCE_DIR}/kernel/*/*.cpp" 11 | "${CMAKE_SOURCE_DIR}/kernel/fs/*/*.c" 12 | "${CMAKE_SOURCE_DIR}/kernel/fs/*/*.cpp" 13 | "${CMAKE_SOURCE_DIR}/common/*.c" 14 | "${CMAKE_SOURCE_DIR}/common/*.cpp" 15 | "${CMAKE_SOURCE_DIR}/common/3rd_party/datetime.c" 16 | "${CMAKE_SOURCE_DIR}/common/3rd_party/crc32.c" 17 | ) 18 | 19 | if (KERNEL_SELFTESTS) 20 | list( 21 | APPEND 22 | KERNEL_NOARCH_SOURCES_GLOB 23 | "${CMAKE_SOURCE_DIR}/tests/self/*.c" 24 | ) 25 | endif() 26 | 27 | file(GLOB KERNEL_NOARCH_SOURCES ${GLOB_CONF_DEP} ${KERNEL_NOARCH_SOURCES_GLOB}) 28 | -------------------------------------------------------------------------------- /kernel/wth_int.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | struct wjob { 8 | void (*func)(void *); 9 | void *arg; 10 | }; 11 | 12 | struct worker_thread { 13 | 14 | const char *name; 15 | struct wjob *jobs; 16 | struct safe_ringbuf rb; 17 | struct task *task; 18 | struct kcond completion; 19 | int priority; /* 0 is the max priority */ 20 | volatile bool waiting_for_jobs; 21 | }; 22 | 23 | extern struct worker_thread *worker_threads[WTH_MAX_THREADS]; 24 | extern int worker_threads_cnt; 25 | 26 | void wth_run(void *arg); 27 | void wth_wakeup(struct worker_thread *t); 28 | bool wth_process_single_job(struct worker_thread *t); 29 | int wth_create_thread_for(struct worker_thread *t); 30 | -------------------------------------------------------------------------------- /modules/acpi/acpi_int.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include 6 | 7 | #include <3rd_party/acpi/acpi.h> 8 | #include <3rd_party/acpi/accommon.h> 9 | 10 | #define BATT_UNKNOWN_CHARGE 0xffffffff 11 | 12 | struct basic_battery_info { 13 | 14 | ulong design_cap; 15 | const char *power_unit; 16 | const char *bif_method; /* _BIF or _BIX */ 17 | u32 lfc_idx; /* Last Full Charge Capacity Property Index */ 18 | bool has_BIX; 19 | }; 20 | 21 | void 22 | print_acpi_failure(const char *func, const char *farg, ACPI_STATUS rc); 23 | 24 | ACPI_STATUS 25 | register_acpi_obj_in_sysfs(ACPI_HANDLE parent_obj, 26 | ACPI_HANDLE obj, 27 | ACPI_DEVICE_INFO *obj_info); 28 | 29 | bool 30 | acpi_has_method(ACPI_HANDLE obj, const char *name); 31 | 32 | bool 33 | acpi_is_battery(ACPI_HANDLE obj); 34 | 35 | ACPI_STATUS 36 | acpi_battery_get_basic_info(ACPI_HANDLE obj, struct basic_battery_info *bi); 37 | -------------------------------------------------------------------------------- /modules/acpi/module_deps: -------------------------------------------------------------------------------- 1 | pci 2 | -------------------------------------------------------------------------------- /modules/acpi/osl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | #include <3rd_party/acpi/acpi.h> 6 | 7 | ACPI_STATUS 8 | osl_init_malloc(void); 9 | 10 | ACPI_STATUS 11 | osl_init_tasks(void); 12 | 13 | ACPI_STATUS 14 | osl_init_irqs(void); 15 | -------------------------------------------------------------------------------- /modules/console/gfx_chars.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #define CHAR_BLOCK_LIGHT 0xb0 // # 6 | #define CHAR_BLOCK_MID 0xb1 // # 7 | #define CHAR_BLOCK_HEAVY 0xdb // # 8 | #define CHAR_VLINE 0xb3 // | 9 | #define CHAR_RTEE 0xb4 // -| 10 | #define CHAR_LTEE 0xc3 // |- 11 | #define CHAR_LLCORNER 0xc0 // |_ 12 | #define CHAR_LRCORNER 0xd9 // _| 13 | #define CHAR_ULCORNER 0xda // 14 | #define CHAR_URCORNER 0xbf // 15 | #define CHAR_BTEE 0xc1 // _|_ 16 | #define CHAR_TTEE 0xc2 // T 17 | #define CHAR_HLINE 0xc4 // -- 18 | #define CHAR_CROSS 0xc5 // + 19 | #define CHAR_DIAMOND 0x04 20 | #define CHAR_DEGREE 0xf8 21 | #define CHAR_PLMINUS 0xf1 22 | #define CHAR_BULLET 0x07 23 | #define CHAR_LARROW 0x1b 24 | #define CHAR_RARROW 0x1a 25 | #define CHAR_DARROW 0x19 26 | #define CHAR_UARROW 0x18 27 | -------------------------------------------------------------------------------- /modules/debugpanel/dp_tracing_int.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define REND_BUF_SZ 256 4 | extern char *rend_bufs[6]; 5 | extern int used_rend_bufs; 6 | 7 | void 8 | dp_handle_syscall_event(struct trace_event *e); 9 | -------------------------------------------------------------------------------- /modules/fb/fb_int.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | extern u32 font_w; 6 | extern u32 font_h; 7 | extern u32 vga_rgb_colors[16]; 8 | extern bool __use_framebuffer; 9 | 10 | u32 fb_get_width(void); 11 | u32 fb_get_height(void); 12 | u32 fb_get_bpp(void); 13 | 14 | void fb_map_in_kernel_space(void); 15 | void fb_raw_color_lines(u32 iy, u32 h, u32 color); 16 | void fb_draw_cursor_raw(u32 ix, u32 iy, u32 color); 17 | void fb_draw_char_failsafe(u32 x, u32 y, u16 entry); 18 | void fb_draw_char_optimized(u32 x, u32 y, u16 e); 19 | void fb_draw_row_optimized(u32 y, u16 *entries, u32 count, bool fpu); 20 | void fb_copy_from_screen(u32 ix, u32 iy, u32 w, u32 h, u32 *buf); 21 | void fb_copy_to_screen(u32 ix, u32 iy, u32 w, u32 h, u32 *buf); 22 | void fb_lines_shift_up(u32 src_y, u32 dst_y, u32 lines_count); 23 | bool fb_pre_render_char_scanlines(void); 24 | bool fb_alloc_shadow_buffer(void); 25 | void fb_raw_perf_screen_redraw(u32 color, bool use_fpu); 26 | void fb_set_font(void *font); 27 | void fb_draw_banner(void); 28 | 29 | void fb_fill_fix_info(void *fix_info); 30 | void fb_fill_var_info(void *var_info); 31 | int fb_user_mmap(pdir_t *pdir, void *vaddr, size_t mmap_len); 32 | -------------------------------------------------------------------------------- /modules/fb/font16x32.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/modules/fb/font16x32.psf -------------------------------------------------------------------------------- /modules/fb/font8x16.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/modules/fb/font8x16.psf -------------------------------------------------------------------------------- /modules/goldfish/riscv/fdt_rtc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | struct fdt_rtc { 8 | struct list_node node; 9 | const struct fdt_match *id_table; 10 | int (*init)(void *fdt, int node, const struct fdt_match *match); 11 | }; 12 | 13 | struct fdt_rtc_dev { 14 | void *priv; 15 | int (* rtc_get)(void *priv, struct datetime *d); 16 | }; 17 | 18 | #define REGISTER_FDT_RTC(__name, __id_table, __init) \ 19 | \ 20 | static struct fdt_rtc fdt_rtc_##__name = { \ 21 | .id_table = __id_table, \ 22 | .init = __init \ 23 | }; \ 24 | \ 25 | __attribute__((constructor)) \ 26 | static void __register_fdt_rtc_##__name(void) { \ 27 | fdt_rtc_drv_register(&fdt_rtc_##__name); \ 28 | } 29 | 30 | void fdt_rtc_drv_register(struct fdt_rtc *drv); 31 | int fdt_rtc_register(void *priv, int (* rtc_get)(void *, struct datetime *)); 32 | 33 | -------------------------------------------------------------------------------- /modules/sysfs/config.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | 5 | 6 | static void 7 | sysfs_fail_to_register_obj(const char *name) 8 | { 9 | panic("sysfs: unable to register object '%s'", name); 10 | } 11 | 12 | #include 13 | -------------------------------------------------------------------------------- /modules/sysfs/lock_and_retain.c.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | static int 4 | sysfs_retain_inode(struct mnt_fs *fs, vfs_inode_ptr_t inode) 5 | { 6 | ASSERT(inode != NULL); 7 | return retain_obj((struct sysfs_inode *)inode); 8 | } 9 | 10 | static int 11 | sysfs_release_inode(struct mnt_fs *fs, vfs_inode_ptr_t inode) 12 | { 13 | ASSERT(inode != NULL); 14 | return release_obj((struct sysfs_inode *)inode); 15 | } 16 | 17 | static void 18 | sysfs_exclusive_lock(struct mnt_fs *fs) 19 | { 20 | struct sysfs_data *d = fs->device_data; 21 | rwlock_wp_exlock(&d->rwlock); 22 | } 23 | 24 | static void 25 | sysfs_exclusive_unlock(struct mnt_fs *fs) 26 | { 27 | struct sysfs_data *d = fs->device_data; 28 | rwlock_wp_exunlock(&d->rwlock); 29 | } 30 | 31 | static void 32 | sysfs_shared_lock(struct mnt_fs *fs) 33 | { 34 | struct sysfs_data *d = fs->device_data; 35 | rwlock_wp_shlock(&d->rwlock); 36 | } 37 | 38 | static void 39 | sysfs_shared_unlock(struct mnt_fs *fs) 40 | { 41 | struct sysfs_data *d = fs->device_data; 42 | rwlock_wp_shunlock(&d->rwlock); 43 | } 44 | -------------------------------------------------------------------------------- /modules/sysfs/sysfs.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | build_and_link_module(${TARGET_NAME} "sysfs" ${TARGET_VARIANT}) 5 | 6 | 7 | -------------------------------------------------------------------------------- /other/alt_fonts/.gitignore: -------------------------------------------------------------------------------- 1 | *.psf.gz 2 | *.psf 3 | -------------------------------------------------------------------------------- /other/alt_fonts/README: -------------------------------------------------------------------------------- 1 | In order to use a different pair of fonts, copy or symlink in this directory 2 | two PSF font files named exactly: 3 | 4 | font8x16.psf 5 | font16x32.psf 6 | 7 | If Tilck's build system finds those two files here and FB_CONSOLE_USE_ALT_FONTS 8 | is enabled, it will use them instead of the default ones. 9 | -------------------------------------------------------------------------------- /other/bsp/riscv64/licheerv-nano/u-boot.cmd: -------------------------------------------------------------------------------- 1 | echo licheerv-nano bsp 2 | -------------------------------------------------------------------------------- /other/bsp/riscv64/qemu-virt/board_bsp.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | set(BOARD_BSP_BOOTLOADER ${TCROOT}/${ARCH}/u-boot/u-boot.bin) 5 | set(BOARD_BSP_MKIMAGE ${TCROOT}/${ARCH}/u-boot/tools/mkimage) 6 | 7 | set(KERNEL_PADDR 0x80200000) # Default 8 | 9 | # Parameters required by boot script of u-boot 10 | math(EXPR KERNEL_ENTRY "${KERNEL_PADDR} + 0x1000" 11 | OUTPUT_FORMAT HEXADECIMAL) 12 | math(EXPR KERNEL_LOAD "${KERNEL_PADDR} + 0x800000" 13 | OUTPUT_FORMAT HEXADECIMAL) 14 | math(EXPR INITRD_LOAD "${KERNEL_PADDR} + 0x1400000" 15 | OUTPUT_FORMAT HEXADECIMAL) 16 | 17 | -------------------------------------------------------------------------------- /other/bsp/riscv64/qemu-virt/fit-image.its: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | description = "U-boot FIT image for qemu-riscv64"; 5 | #address-cells = <2>; 6 | 7 | images { 8 | tilck { 9 | description = "tilck"; 10 | data = /incbin/("@KERNEL_FILE@"); 11 | type = "kernel"; 12 | arch = "riscv"; 13 | os = "linux"; 14 | load = <0x0 @KERNEL_LOAD@>; 15 | entry = <0x0 @KERNEL_ENTRY@>; 16 | compression = "none"; 17 | }; 18 | 19 | ramdisk { 20 | description = "buildroot initramfs"; 21 | data = /incbin/("@CMAKE_BINARY_DIR@/fatpart"); 22 | type = "ramdisk"; 23 | arch = "riscv"; 24 | os = "linux"; 25 | load = <0x0 @INITRD_LOAD@>; 26 | compression = "none"; 27 | hash-1 { 28 | algo = "sha256"; 29 | }; 30 | }; 31 | }; 32 | 33 | configurations { 34 | default = "config-1"; 35 | 36 | config-1 { 37 | description = "qemu-riscv64"; 38 | kernel = "tilck"; 39 | ramdisk = "ramdisk"; 40 | }; 41 | }; 42 | }; 43 | -------------------------------------------------------------------------------- /other/bsp/riscv64/qemu-virt/u-boot.cmd: -------------------------------------------------------------------------------- 1 | env set loadaddr @KERNEL_PADDR@ 2 | echo Load ${prefix}uEnv.txt... 3 | fatload ${devtype} ${devnum}:${distro_bootpart} ${loadaddr} ${prefix}uEnv.txt; 4 | env import -t ${loadaddr} ${filesize}; 5 | run boot2; 6 | -------------------------------------------------------------------------------- /other/ci/tc-arch-riscv64.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | exclude: 4 | - readme* 5 | - temp-* 6 | - exp-* 7 | 8 | paths: 9 | include: 10 | - 'scripts/build_toolchain' 11 | - 'scripts/tc/pkgs/**' 12 | exclude: 13 | - 'README.md' 14 | - '*.md' 15 | 16 | pool: 17 | vmImage: 'ubuntu-22.04' 18 | 19 | 20 | container: 'vvaltchev/archlinux:v6' 21 | 22 | variables: 23 | RUNNING_IN_CI: 1 24 | GTEST_SHUFFLE: 0 25 | ARCH: riscv64 26 | 27 | steps: 28 | - script: printenv 29 | displayName: Dump env 30 | - script: sudo -E ./scripts/build_toolchain 31 | displayName: "Install pkgs" 32 | - script: sudo -E ./scripts/build_toolchain -s gtest 33 | displayName: "Build gtest" 34 | - script: sudo -E ./scripts/build_toolchain -s gmock 35 | displayName: "Build gmock" 36 | - script: sudo -E ./scripts/build_toolchain -s lcov 37 | displayName: "Build lcov" 38 | - script: sudo -E ./scripts/build_toolchain -s ncurses 39 | displayName: "Build ncurses" 40 | - script: sudo -E ./scripts/build_toolchain -s tree_cmd 41 | displayName: "Build tree_cmd" 42 | - script: make -j 43 | displayName: Build the kernel 44 | - script: make -j gtests 45 | displayName: Build the unit tests 46 | - script: ./build/gtests 47 | displayName: Run the unit tests 48 | - script: ./tests/runners/ci_run_all_tests_wrapper -c 49 | displayName: Run the system tests 50 | -------------------------------------------------------------------------------- /other/ci/tc-debian-riscv64.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | exclude: 4 | - readme* 5 | - temp-* 6 | - exp-* 7 | 8 | paths: 9 | include: 10 | - 'scripts/build_toolchain' 11 | - 'scripts/tc/pkgs/**' 12 | exclude: 13 | - 'README.md' 14 | - '*.md' 15 | 16 | pool: 17 | vmImage: 'ubuntu-22.04' 18 | 19 | 20 | container: 'vvaltchev/debian:v4' 21 | 22 | variables: 23 | RUNNING_IN_CI: 1 24 | GTEST_SHUFFLE: 0 25 | ARCH: riscv64 26 | 27 | steps: 28 | - script: printenv 29 | displayName: Dump env 30 | - script: sudo -E ./scripts/build_toolchain 31 | displayName: "Install pkgs" 32 | - script: sudo -E ./scripts/build_toolchain -s gtest 33 | displayName: "Build gtest" 34 | - script: sudo -E ./scripts/build_toolchain -s gmock 35 | displayName: "Build gmock" 36 | - script: sudo -E ./scripts/build_toolchain -s lcov 37 | displayName: "Build lcov" 38 | - script: sudo -E ./scripts/build_toolchain -s ncurses 39 | displayName: "Build ncurses" 40 | - script: sudo -E ./scripts/build_toolchain -s tree_cmd 41 | displayName: "Build tree_cmd" 42 | - script: make -j 43 | displayName: Build the kernel 44 | - script: make -j gtests 45 | displayName: Build the unit tests 46 | - script: ./build/gtests 47 | displayName: Run the unit tests 48 | - script: ./tests/runners/ci_run_all_tests_wrapper -c 49 | displayName: Run the system tests 50 | -------------------------------------------------------------------------------- /other/ci/tc-fedora-riscv64.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | exclude: 4 | - readme* 5 | - temp-* 6 | - exp-* 7 | 8 | paths: 9 | include: 10 | - 'scripts/build_toolchain' 11 | - 'scripts/tc/pkgs/**' 12 | exclude: 13 | - 'README.md' 14 | - '*.md' 15 | 16 | pool: 17 | vmImage: 'ubuntu-22.04' 18 | 19 | container: 'vvaltchev/fedora:v3' 20 | 21 | variables: 22 | RUNNING_IN_CI: 1 23 | GTEST_SHUFFLE: 0 24 | ARCH: riscv64 25 | 26 | steps: 27 | - script: printenv 28 | displayName: Dump env 29 | - script: sudo -E ./scripts/build_toolchain 30 | displayName: "Install pkgs" 31 | - script: sudo -E ./scripts/build_toolchain -s gtest 32 | displayName: "Build gtest" 33 | - script: sudo -E ./scripts/build_toolchain -s gmock 34 | displayName: "Build gmock" 35 | - script: sudo -E ./scripts/build_toolchain -s lcov 36 | displayName: "Build lcov" 37 | - script: sudo -E ./scripts/build_toolchain -s ncurses 38 | displayName: "Build ncurses" 39 | - script: sudo -E ./scripts/build_toolchain -s tree_cmd 40 | displayName: "Build tree_cmd" 41 | - script: make -j 42 | displayName: Build the kernel 43 | - script: make -j gtests 44 | displayName: Build the unit tests 45 | - script: ./build/gtests 46 | displayName: Run the unit tests 47 | - script: ./tests/runners/ci_run_all_tests_wrapper -c 48 | displayName: Run the system tests 49 | -------------------------------------------------------------------------------- /other/ci/tc-opensuse-riscv64.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | exclude: 4 | - readme* 5 | - temp-* 6 | - exp-* 7 | 8 | paths: 9 | include: 10 | - 'scripts/build_toolchain' 11 | - 'scripts/tc/pkgs/**' 12 | exclude: 13 | - 'README.md' 14 | - '*.md' 15 | 16 | pool: 17 | vmImage: 'ubuntu-22.04' 18 | 19 | container: 'vvaltchev/opensuse:v4' 20 | 21 | variables: 22 | RUNNING_IN_CI: 1 23 | GTEST_SHUFFLE: 0 24 | ARCH: riscv64 25 | 26 | steps: 27 | - script: printenv 28 | displayName: Dump env 29 | - script: sudo -E ./scripts/build_toolchain 30 | displayName: "Install pkgs" 31 | - script: sudo -E ./scripts/build_toolchain -s gtest 32 | displayName: "Build gtest" 33 | - script: sudo -E ./scripts/build_toolchain -s gmock 34 | displayName: "Build gmock" 35 | - script: sudo -E ./scripts/build_toolchain -s lcov 36 | displayName: "Build lcov" 37 | - script: sudo -E ./scripts/build_toolchain -s ncurses 38 | displayName: "Build ncurses" 39 | - script: sudo -E ./scripts/build_toolchain -s tree_cmd 40 | displayName: "Build tree_cmd" 41 | - script: make -j 42 | displayName: Build the kernel 43 | - script: make -j gtests 44 | displayName: Build the unit tests 45 | - script: ./build/gtests 46 | displayName: Run the unit tests 47 | - script: ./tests/runners/ci_run_all_tests_wrapper -c 48 | displayName: Run the system tests 49 | -------------------------------------------------------------------------------- /other/ci/x86_64.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | 3 | branches: 4 | exclude: 5 | - readme* 6 | - temp-* 7 | - exp-* 8 | 9 | paths: 10 | include: 11 | - 'other/ci/x86_64.yml' 12 | - 'other/busybox.config' 13 | - 'kernel/**' 14 | - 'modules/**' 15 | - 'include/**' 16 | - 'common/**' 17 | - 'boot/**' 18 | - 'tests/**' 19 | - 'userapps/**' 20 | - 'scripts/**' 21 | - 'config/**' 22 | exclude: 23 | - 'README.md' 24 | - 'docs/**' 25 | - 'scripts/configurator/**' 26 | - 'kernel/arch/riscv/**' 27 | - 'kernel/arch/riscv64/**' 28 | - 'include/tilck/kernel/arch/riscv/**' 29 | - 'include/tilck/common/arch/riscv/**' 30 | 31 | jobs: 32 | - job: gcc_12_3_x86_64 33 | container: 'vvaltchev/tilck-x86_64:v5' 34 | pool: 35 | vmImage: 'ubuntu-24.04' 36 | variables: 37 | RUNNING_IN_CI: 1 38 | TCROOT: /tc/toolchain2-gcc123 39 | GTEST_SHUFFLE: 0 40 | TILCK_NO_LOGO: 1 41 | GCC_TC_VER: 12.3.0 42 | ARCH: x86_64 43 | steps: 44 | - script: printenv 45 | displayName: Dump env 46 | - script: ./scripts/cmake_run 47 | displayName: Run CMake 48 | - script: make -j 49 | displayName: Build the kernel 50 | 51 | 52 | -------------------------------------------------------------------------------- /other/cmake/config_fatpart: -------------------------------------------------------------------------------- 1 | # Special config file used to trigger rebuild of the fatpart in case one of the 2 | # following variables changes. 3 | 4 | fbdoom = @EXTRA_FBDOOM@ 5 | micropython = @EXTRA_MICROPYTHON@ 6 | tcc = @EXTRA_TCC@ 7 | lua = @EXTRA_LUA@ 8 | vim = @EXTRA_VIM@ 9 | tree_cmd = @EXTRA_TREE_CMD@ 10 | 11 | devshell = @USERAPPS_devshell@ 12 | dp = @USERAPPS_dp@ 13 | extra = @USERAPPS_extra@ 14 | fbtest = @USERAPPS_fbtest@ 15 | ncapp = @USERAPPS_ncapp@ 16 | termtest = @USERAPPS_termtest@ 17 | filedump = @USERAPPS_filedump@ 18 | extra = @USERAPPS_extra@ 19 | -------------------------------------------------------------------------------- /other/cmake/gen_config_post.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | set(BUILD_BOOTPART ${CMAKE_BINARY_DIR}/scripts/build_bootpart) 5 | set(BUILD_FATPART ${CMAKE_BINARY_DIR}/scripts/build_fatpart) 6 | set(BUILD_TEST_FATPART ${CMAKE_BINARY_DIR}/scripts/build_test_fatpart) 7 | 8 | smart_config_file( 9 | ${CMAKE_SOURCE_DIR}/scripts/templates/build_bootpart 10 | ${BUILD_BOOTPART} 11 | ) 12 | 13 | smart_config_file( 14 | ${CMAKE_SOURCE_DIR}/scripts/templates/build_fatpart 15 | ${BUILD_FATPART} 16 | ) 17 | 18 | smart_config_file( 19 | ${CMAKE_SOURCE_DIR}/scripts/templates/build_test_fatpart 20 | ${BUILD_TEST_FATPART} 21 | ) 22 | -------------------------------------------------------------------------------- /other/cmake/wrapped_syms.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | set( 5 | WRAPPED_SYMS 6 | 7 | assert_failed 8 | not_reached 9 | not_implemented 10 | tilck_vprintk 11 | kmutex_lock 12 | kmutex_unlock 13 | fat_ramdisk_prepare_for_mmap 14 | wth_create_thread_for 15 | wth_wakeup 16 | check_in_irq_handler 17 | general_kmalloc 18 | general_kfree 19 | kmalloc_get_first_heap 20 | vfs_dup 21 | vfs_close 22 | use_kernel_arg 23 | handle_sys_trace_arg 24 | copy_str_from_user 25 | copy_from_user 26 | 27 | experiment_bar 28 | experiment_foo 29 | ) 30 | -------------------------------------------------------------------------------- /other/containers/README.md: -------------------------------------------------------------------------------- 1 | The file structure follows docker standards, and every container can be created 2 | by a Dockerfile that sits in a directory is named after the container's name. 3 | The reasoning behind this structure is allowing syntax highlighting for all 4 | IDEs. See: https://stackoverflow.com/questions/27409761 5 | 6 | To build and tag an image, enter project's root folder an run: 7 | 8 | ```bash 9 | docker build -t /: -f other/containers//Dockerfile . 10 | ``` 11 | 12 | To actually run the image in a container in interactive mode use: 13 | 14 | ```bash 15 | docker run -it /name>: bash 16 | ``` 17 | 18 | With Docker's cloud build, we can do: 19 | 20 | ```bash 21 | docker buildx build --builder --push -t /: -f ./other/containers//Dockerfile . 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /other/containers/arch-base/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM archlinux:latest 2 | RUN pacman -Syu --noconfirm sudo 3 | -------------------------------------------------------------------------------- /other/containers/debian-base/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:stable-slim 2 | ENV DEBIAN_FRONTEND=noninteractive 3 | RUN apt update && apt upgrade -y 4 | RUN apt-get install sudo 5 | -------------------------------------------------------------------------------- /other/containers/fedora-base/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM fedora:latest 2 | RUN yum -y install util-linux sudo 3 | -------------------------------------------------------------------------------- /other/containers/opensuse-base/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM opensuse/tumbleweed 2 | RUN zypper --non-interactive in sudo 3 | -------------------------------------------------------------------------------- /other/debugging_readme: -------------------------------------------------------------------------------- 1 | In order to allow Tilck's gdb script to work, add the following twos lines in 2 | your gdbinit file (typically ~/.gdbinit): 3 | 4 | set print pretty on 5 | add-auto-load-safe-path 6 | 7 | Without the first line, the pretty printers will display the objects in an ugly 8 | way, especially because of the padding used to align all the fields. 9 | 10 | The second line is required because GDB's security protection. Without it, 11 | the scripts won't be loaded and you'll see GDB complaining like: 12 | 13 | Reading symbols from ./build/tilck_unstripped... 14 | warning: File "/home/vlad/dev/tilck/build/tilck_unstripped-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". 15 | To enable execution of this file add 16 | add-auto-load-safe-path /home/vlad/dev/tilck/build/tilck_unstripped-gdb.py 17 | line to your configuration file "/home/vlad/.gdbinit". 18 | To completely disable this security protection add 19 | set auto-load safe-path / 20 | line to your configuration file "/home/vlad/.gdbinit". 21 | For more information about this security protection see the 22 | "Auto-loading safe path" section in the GDB manual. E.g., run from the shell: 23 | info "(gdb)Auto-loading safe path" 24 | -------------------------------------------------------------------------------- /other/gcc_tc_conf/i386/default_ver: -------------------------------------------------------------------------------- 1 | 12.3.0 -------------------------------------------------------------------------------- /other/gcc_tc_conf/i386/min_ver: -------------------------------------------------------------------------------- 1 | 11.3.0 -------------------------------------------------------------------------------- /other/gcc_tc_conf/riscv64/default_ver: -------------------------------------------------------------------------------- 1 | 12.3.0 -------------------------------------------------------------------------------- /other/gcc_tc_conf/riscv64/min_ver: -------------------------------------------------------------------------------- 1 | 12.3.0 -------------------------------------------------------------------------------- /other/gcc_tc_conf/x86_64/default_ver: -------------------------------------------------------------------------------- 1 | 12.3.0 -------------------------------------------------------------------------------- /other/gcc_tc_conf/x86_64/min_ver: -------------------------------------------------------------------------------- 1 | 11.3.0 -------------------------------------------------------------------------------- /other/gdb_scripts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/other/gdb_scripts/__init__.py -------------------------------------------------------------------------------- /other/gdb_scripts/fs_handle_printer.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | import gdb # pylint: disable=import-error 4 | from . import base_utils as bu 5 | 6 | class printer_fs_handle_base: 7 | 8 | def __init__(self, val): 9 | self.val = val 10 | 11 | def to_string(self): 12 | return bu.fmt_type("struct fs_handle_base", self.val) 13 | 14 | def children(self): 15 | 16 | h = self.val 17 | spec_flags = h['spec_flags'] 18 | spf_str = "" 19 | 20 | if spec_flags == 0: 21 | 22 | spf_str = "(none)" 23 | 24 | else: 25 | 26 | if spec_flags & (1 << 0): 27 | spf_str += "NO_USER_COPY " 28 | 29 | if spec_flags & (1 << 1): 30 | spf_str += "MMAP" 31 | 32 | return [ 33 | ("pi ", h['pi']['pid']), 34 | ("fs ", h['fs']), 35 | ("fs_type ", h['fs']['fs_type_name'].string()), 36 | ("fd_flags ", h['fd_flags']), 37 | ("fl_flags ", h['fl_flags']), 38 | ("spec_flags", spf_str), 39 | ("pos ", h['pos']), 40 | ] 41 | 42 | bu.register_tilck_regex_pp( 43 | 'fs_handle_base', '^fs_handle_base$', printer_fs_handle_base 44 | ) 45 | 46 | -------------------------------------------------------------------------------- /other/gdb_scripts/tilck_types.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | import gdb # pylint: disable=import-error 4 | 5 | task = gdb.lookup_type("struct task") 6 | task_p = task.pointer() 7 | 8 | process = gdb.lookup_type("struct process") 9 | process_p = process.pointer() 10 | 11 | list_node = gdb.lookup_type("struct list_node") 12 | list_node_p = list_node.pointer() 13 | 14 | fs_handle_base = gdb.lookup_type("struct fs_handle_base") 15 | fs_handle_base_p = fs_handle_base.pointer() 16 | 17 | user_mapping = gdb.lookup_type("struct user_mapping") 18 | user_mapping_p = user_mapping.pointer() 19 | 20 | multi_obj_waiter = gdb.lookup_type("struct multi_obj_waiter") 21 | multi_obj_waiter_p = multi_obj_waiter.pointer() 22 | -------------------------------------------------------------------------------- /other/mock_experiments.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | 5 | bool experiment_bar(void) { 6 | return true; 7 | } 8 | 9 | int experiment_foo(int n) { 10 | 11 | if (!experiment_bar()) 12 | return -1; 13 | 14 | return n * 10; 15 | } 16 | -------------------------------------------------------------------------------- /other/tilck_unstripped-gdb.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | import gdb # pylint: disable=import-error 4 | import sys 5 | import re 6 | 7 | # Add Tilck's "other/" directory to our import path and import base_utils 8 | sys.path.append("@CMAKE_SOURCE_DIR@/other") 9 | import gdb_scripts.base_utils as bu 10 | 11 | # Set the build config as early as possible using the constants coming from 12 | # CMake (this file gets pre-processed by CMake) 13 | bu.set_build_config( 14 | bu.BuildConfig( 15 | "@CMAKE_SOURCE_DIR@", 16 | int("@MAX_HANDLES@"), 17 | int("@BASE_VA@", 16), 18 | ) 19 | ) 20 | 21 | # Import the rest of our gdb_scripts 22 | import gdb_scripts.list_cmds 23 | import gdb_scripts.get_cmds 24 | import gdb_scripts.process_printer 25 | import gdb_scripts.task_printer 26 | import gdb_scripts.regs_printer 27 | import gdb_scripts.mobj_printer 28 | import gdb_scripts.fs_handle_printer 29 | import gdb_scripts.mi_printer 30 | 31 | # Init all the custom GDB commands 32 | bu.init_all_custom_cmds() 33 | 34 | # Register all the regex pretty printers 35 | gdb.printing.register_pretty_printer( 36 | gdb.current_objfile(), 37 | bu.regex_pretty_printers 38 | ) 39 | -------------------------------------------------------------------------------- /scripts/bash_includes/README: -------------------------------------------------------------------------------- 1 | This directory (and all of its sub-directories) does NOT contain directly 2 | runnable scripts. Instead, if contains pieces of bash code used by the real 3 | scripts. 4 | -------------------------------------------------------------------------------- /scripts/bash_includes/cc_vars: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | function save_cc_vars { 5 | 6 | if [[ "$HOST_ARCH" == "$ARCH" ]]; then 7 | export AR=${AR:-ar} 8 | export NM=${NM:-nm} 9 | export RANLIB=${RANLIB:-ranlib} 10 | fi 11 | 12 | saved_CC=$CC 13 | saved_CXX=$CXX 14 | saved_AR=$AR 15 | saved_NM=$NM 16 | saved_RANLIB=$RANLIB 17 | } 18 | 19 | function set_cc_vars_to_tc { 20 | 21 | export CC="${ARCH_GCC_TC}-linux-gcc" 22 | export CXX="${ARCH_GCC_TC}-linux-g++" 23 | export AR="${ARCH_GCC_TC}-linux-ar" 24 | export NM="${ARCH_GCC_TC}-linux-nm" 25 | export RANLIB="${ARCH_GCC_TC}-linux-ranlib" 26 | } 27 | 28 | function reset_cc_vars_to_null { 29 | 30 | export CC="" 31 | export CXX="" 32 | export AR="" 33 | export NM="" 34 | export RANLIB="" 35 | } 36 | 37 | 38 | function reset_cc_vars { 39 | 40 | export CC=$saved_CC 41 | export CXX=$saved_CXX 42 | export AR=$saved_AR 43 | export NM=$saved_NM 44 | export RANLIB=$saved_RANLIB 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /scripts/build_apps/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/scripts/build_apps/.gitignore -------------------------------------------------------------------------------- /scripts/build_apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | include_directories(${CMAKE_SOURCE_DIR}/include) 5 | add_definitions(-DUSERMODE_APP) 6 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -ggdb") 7 | 8 | file( 9 | GLOB FATHACK_SRC 10 | "fathack.c" 11 | "${CMAKE_SOURCE_DIR}/common/*.c" 12 | "${CMAKE_SOURCE_DIR}/common/*.cpp" 13 | ) 14 | 15 | add_executable(fathack ${FATHACK_SRC}) 16 | add_executable(pnm2text "pnm2text.c") 17 | add_executable(mbrhack "mbrhack.c") 18 | add_executable(gen_config "gen_config.cpp") 19 | 20 | add_executable(elfhack32 "elfhack.c") 21 | set_target_properties( 22 | 23 | elfhack32 24 | 25 | PROPERTIES 26 | COMPILE_DEFINITIONS "USE_ELF32" 27 | ) 28 | 29 | add_executable(elfhack64 "elfhack.c") 30 | set_target_properties( 31 | 32 | elfhack64 33 | 34 | PROPERTIES 35 | COMPILE_DEFINITIONS "USE_ELF64" 36 | ) 37 | -------------------------------------------------------------------------------- /scripts/build_generators/clang_small_offt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | if [[ "$ARCH" == "" ]] || [[ "$ARCH" == "i386" ]]; then 20 | 21 | CC=clang CXX=clang++ $CM \ 22 | -DKERNEL_SYSCC=1 \ 23 | -DWCONV=1 \ 24 | -DKERNEL_64BIT_OFFT=0 \ 25 | "$@" 26 | 27 | else 28 | 29 | echo "Supported only for ARCH=i386. Skip" 30 | echo > skipped 31 | fi 32 | 33 | -------------------------------------------------------------------------------- /scripts/build_generators/clang_tc_isystem: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | if [[ "$ARCH" == "" ]] || [[ "$ARCH" == "i386" ]]; then 20 | 21 | CC=clang CXX=clang++ $CM -DKERNEL_SYSCC=1 -DKERNEL_FORCE_TC_ISYSTEM=1 "$@" 22 | 23 | else 24 | 25 | echo "Supported only for ARCH=i386. Skip" 26 | echo > skipped 27 | fi 28 | 29 | -------------------------------------------------------------------------------- /scripts/build_generators/clang_wconv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | if [[ "$ARCH" == "" ]] || [[ "$ARCH" == "i386" ]]; then 20 | 21 | CC=clang CXX=clang++ $CM -DKERNEL_SYSCC=1 -DWCONV=1 "$@" 22 | 23 | else 24 | 25 | echo "Supported only for ARCH=i386. Skip" 26 | echo > skipped 27 | fi 28 | 29 | -------------------------------------------------------------------------------- /scripts/build_generators/gcc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | $CM "$@" 20 | -------------------------------------------------------------------------------- /scripts/build_generators/gcc_fast_rel: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | RELEASE=1 $CM \ 20 | -DKRN_TRACK_NESTED_INTERR=0 \ 21 | -DDEBUG_CHECKS=0 \ 22 | -DKERNEL_STACK_ISOLATION=0 \ 23 | "$@" 24 | -------------------------------------------------------------------------------- /scripts/build_generators/gcc_gcov: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | TEST_GCOV=1 KERNEL_GCOV=1 $CM "$@" 20 | -------------------------------------------------------------------------------- /scripts/build_generators/gcc_no_nested_irq_tracking: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | $CM -DKERNEL_TRACK_NESTED_INTERRUPTS=0 "$@" 20 | -------------------------------------------------------------------------------- /scripts/build_generators/gcc_nocow: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | $CM -DFORK_NO_COW=1 -DMMAP_NO_COW=1 "$@" 20 | -------------------------------------------------------------------------------- /scripts/build_generators/gcc_rel: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | RELEASE=1 $CM "$@" 20 | -------------------------------------------------------------------------------- /scripts/build_generators/gcc_small_offt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | $CM "$@" -DKERNEL_64BIT_OFFT=0 20 | -------------------------------------------------------------------------------- /scripts/build_generators/gcc_syscc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | CM=$MAIN_DIR/scripts/cmake_run 15 | 16 | ############################################################## 17 | 18 | if [[ "$ARCH" == "" ]] || [[ "$ARCH" == "i386" ]]; then 19 | 20 | if [ -n "$AZURE_HTTP_USER_AGENT" ]; then 21 | sudo -E $MAIN_DIR/scripts/build_toolchain -s build_libmusl 22 | fi 23 | 24 | USE_SYSCC=1 $CM "$@" 25 | 26 | else 27 | 28 | echo "Supported only for ARCH=i386. Skip" 29 | echo > skipped 30 | fi 31 | 32 | -------------------------------------------------------------------------------- /scripts/build_generators/minimal: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # GLOBAL VARIABLES 5 | 6 | # Project's root directory 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 9 | 10 | # Include files 11 | source $MAIN_DIR/scripts/bash_includes/script_utils 12 | 13 | # CONSTANTS 14 | 15 | CM=$MAIN_DIR/scripts/cmake_run 16 | 17 | ############################################################## 18 | 19 | $CM \ 20 | -DCMAKE_BUILD_TYPE=MinSizeRel \ 21 | -DBOOTLOADER_EFI=0 \ 22 | -DKERNEL_GCOV=0 \ 23 | -DKERNEL_SHOW_LOGO=0 \ 24 | -DKERNEL_SYMBOLS=0 \ 25 | -DKERNEL_SELFTESTS=0 \ 26 | -DMOD_console=0 \ 27 | -DMOD_fb=0 \ 28 | -DMOD_kb8042=0 \ 29 | -DMOD_tracing=0 \ 30 | -DMOD_acpi=0 \ 31 | -DMOD_sb16=0 \ 32 | -DMOD_serial=1 \ 33 | -DPCI_VENDORS_LIST=0 \ 34 | -DTINY_KERNEL=1 \ 35 | -DUSERAPPS_extra=0 \ 36 | -DTYPICAL_DEVEL_USERAPPS=0 \ 37 | "$@" 38 | -------------------------------------------------------------------------------- /scripts/build_scripts/bss_checker: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | have_bss=`readelf -S $1 | grep bss` 5 | 6 | if [ -z "$have_bss" ]; then 7 | exit 0 8 | fi 9 | 10 | echo 11 | echo '**** ERROR: the kernel has contents in BSS! ****' 12 | echo 13 | 14 | exit 1 15 | -------------------------------------------------------------------------------- /scripts/build_scripts/create_empty_img_if_necessary: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ ! -f $1 ]; then 4 | dd status=none if=/dev/zero of=$1 bs=1M count=$2 5 | fi 6 | -------------------------------------------------------------------------------- /scripts/build_scripts/get_commit_hash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if ! git --version &> /dev/null; then 4 | echo "" 5 | exit 0 6 | fi 7 | 8 | set -e 9 | ver=`git rev-parse --short=8 HEAD` 10 | commit_date=`git --no-pager log -1 --format="%ai"` 11 | 12 | if [[ $(git diff --stat) != '' ]]; then 13 | 14 | echo "dirty:$ver $commit_date" 15 | 16 | else 17 | 18 | tags="" 19 | for x in `git tag --points-at HEAD`; do 20 | tags="$tags$x," 21 | done 22 | 23 | if [[ "$tags" != "" ]]; then 24 | 25 | # Prepend "tags:" 26 | tags="tags:$tags" 27 | 28 | # Drop the trailing "," 29 | tags=$(echo $tags | sed 's/.$//') 30 | fi 31 | 32 | echo "$ver $commit_date $tags" 33 | fi 34 | -------------------------------------------------------------------------------- /scripts/build_scripts/i386-ar: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ar "$@" 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/i386-g++: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec $SYS_CXX -m32 -march=i686 "$@" $CC_POST_FLAGS 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/i386-gcc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec $SYS_CC -m32 -march=i686 "$@" $CC_POST_FLAGS 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/i386-ld: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ld "$@" 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/i386-linux-ar: -------------------------------------------------------------------------------- 1 | i386-ar -------------------------------------------------------------------------------- /scripts/build_scripts/i386-linux-g++: -------------------------------------------------------------------------------- 1 | i386-g++ -------------------------------------------------------------------------------- /scripts/build_scripts/i386-linux-gcc: -------------------------------------------------------------------------------- 1 | i386-gcc -------------------------------------------------------------------------------- /scripts/build_scripts/i386-linux-ranlib: -------------------------------------------------------------------------------- 1 | i386-ranlib -------------------------------------------------------------------------------- /scripts/build_scripts/i386-linux-strip: -------------------------------------------------------------------------------- 1 | i386-strip -------------------------------------------------------------------------------- /scripts/build_scripts/i386-objcopy: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec objcopy "$@" 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/i386-ranlib: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ranlib "$@" 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/i386-size: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec size "$@" 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/i386-strip: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec strip "$@" 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/i686-linux-ar: -------------------------------------------------------------------------------- 1 | i386-ar -------------------------------------------------------------------------------- /scripts/build_scripts/i686-linux-g++: -------------------------------------------------------------------------------- 1 | i386-g++ -------------------------------------------------------------------------------- /scripts/build_scripts/i686-linux-gcc: -------------------------------------------------------------------------------- 1 | i386-gcc -------------------------------------------------------------------------------- /scripts/build_scripts/i686-linux-ld: -------------------------------------------------------------------------------- 1 | i386-ld -------------------------------------------------------------------------------- /scripts/build_scripts/i686-linux-objcopy: -------------------------------------------------------------------------------- 1 | i386-objcopy -------------------------------------------------------------------------------- /scripts/build_scripts/i686-linux-ranlib: -------------------------------------------------------------------------------- 1 | i386-ranlib -------------------------------------------------------------------------------- /scripts/build_scripts/i686-linux-size: -------------------------------------------------------------------------------- 1 | i386-size -------------------------------------------------------------------------------- /scripts/build_scripts/i686-linux-strip: -------------------------------------------------------------------------------- 1 | i386-strip -------------------------------------------------------------------------------- /scripts/build_scripts/tilck_set_commit_hash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # $1 -> elfhack binary 4 | # $2 -> kernel elf file 5 | 6 | set -e 7 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | hash=`$SOURCE_DIR/get_commit_hash` 9 | exec "$1" "$2" --set-sym-strval .tilck_info tilck_build_info "$hash" 10 | -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-ar: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ar "$@" 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-g++: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec $SYS_CXX "$@" $CC_POST_FLAGS 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-gcc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec $SYS_CC "$@" $CC_POST_FLAGS 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-linux-ar: -------------------------------------------------------------------------------- 1 | x86_64-ar -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-linux-g++: -------------------------------------------------------------------------------- 1 | x86_64-g++ -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-linux-gcc: -------------------------------------------------------------------------------- 1 | x86_64-gcc -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-linux-ranlib: -------------------------------------------------------------------------------- 1 | x86_64-ranlib -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-linux-strip: -------------------------------------------------------------------------------- 1 | x86_64-strip -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-ranlib: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ranlib "$@" 3 | -------------------------------------------------------------------------------- /scripts/build_scripts/x86_64-strip: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec strip "$@" 3 | -------------------------------------------------------------------------------- /scripts/configurator/configurator.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | paths: 3 | include: 4 | - 'scripts/configurator/**' 5 | 6 | jobs: 7 | - job: configurator 8 | pool: 9 | vmImage: 'ubuntu-24.04' 10 | strategy: 11 | matrix: 12 | Python310: 13 | python.version: '3.10' 14 | Python311: 15 | python.version: '3.11' 16 | Python312: 17 | python.version: '3.12' 18 | Python313: 19 | python.version: '3.13' 20 | 21 | steps: 22 | - task: UsePythonVersion@0 23 | displayName: 'Use Python $(python.version)' 24 | inputs: 25 | versionSpec: '$(python.version)' 26 | 27 | - script: python -m unittest discover scripts/configurator/parser 28 | displayName: 'Run unit tests' 29 | 30 | 31 | -------------------------------------------------------------------------------- /scripts/configurator/parser/test_cmakevar.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | from unittest import TestCase 4 | from cmake_var import metadata 5 | 6 | class test_custom_metadata(TestCase): 7 | 8 | generic_comment = \ 9 | """ 10 | GROUP KRN 11 | DEPENDS_ON A, B, C 12 | REALTYPE INT 13 | """.splitlines() 14 | 15 | invalid_keyword_comment = \ 16 | """ 17 | FOO KRN 18 | """.splitlines() 19 | 20 | def test_metadata_creation_correct(self): 21 | m = metadata(self.generic_comment) 22 | with self.subTest(): 23 | self.assertEqual(m.group, "KRN") 24 | with self.subTest(): 25 | self.assertEqual(m.depends_on, ["A", "B", "C"]) 26 | with self.subTest(): 27 | self.assertEqual(m.realtype, "INT") 28 | 29 | def test_metdata_creation_invalid_keyword(self): 30 | self.assertRaises(ValueError, metadata, self.invalid_keyword_comment) 31 | -------------------------------------------------------------------------------- /scripts/dev/README: -------------------------------------------------------------------------------- 1 | This directory contains development-only scripts, which are never used by 2 | Tilck's build system nor by other scripts. They are supposed to be used 3 | only by human users. 4 | -------------------------------------------------------------------------------- /scripts/dev/dump_all_funcs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if [ -z "$1" ]; then 4 | echo 5 | echo "dump_all_funcs: a script for listing all the functions in a binary " 6 | echo "along with their size. Designed to be used in combination with the" 7 | echo "'cmp_funcs_size' script. Requires: nm, grep, cut, sort." 8 | echo 9 | echo "Syntax:" 10 | echo " dump_all_funcs " 11 | exit 1 12 | fi 13 | 14 | if ! [ -f "$1" ]; then 15 | echo "The file '$1' does not exist" 16 | exit 1 17 | fi 18 | 19 | nm_opts='--radix=d --print-size' 20 | exec nm $nm_opts "$1" | grep -E ' [Tt] ' | cut -d ' ' -f 2,4 | sort -t ' ' -k 2 21 | -------------------------------------------------------------------------------- /scripts/dev/flat_objdump_386: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | objdump -D -Mintel,i386 -b binary -m i386 $@ 3 | -------------------------------------------------------------------------------- /scripts/dev/flat_objdump_8086: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | objdump -D -Mintel,i8086 -b binary -m i386 $@ 3 | -------------------------------------------------------------------------------- /scripts/dev/flat_objdump_x64: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | objdump -D -Mintel,x86-64 -b binary -m i386 $@ 3 | -------------------------------------------------------------------------------- /scripts/dev/objdump_no_machine_code: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | exec objdump -M intel -d --no-show-raw-insn "$1" 4 | -------------------------------------------------------------------------------- /scripts/dev/qemu_img_create_vmdk: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | (cd build && qemu-img convert -O vmdk tilck.img tilck.vmdk) 4 | -------------------------------------------------------------------------------- /scripts/dev/remove_32bit_addrs_from_dump: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | sed -E -i 's/[a-f0-9]{8}/ADDR32/g' "$1" 3 | -------------------------------------------------------------------------------- /scripts/dev/run_ctags: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | if ! [ -d kernel ] || ! [ -d userapps ] || ! [ -f LICENSE ]; then 5 | echo "You need to run this script from project's root directory" 6 | exit 1 7 | fi 8 | 9 | echo "Running CTAGS..." 10 | 11 | ctags --languages=C,C++,Python -R \ 12 | config/ common/ kernel/ include/ modules/ \ 13 | tests/ boot/ userapps/ scripts/build_apps/ 14 | 15 | if ! [ -f tags ]; then 16 | echo "ERROR: File 'tags' NOT found" 17 | exit 1 18 | fi 19 | 20 | echo "DONE" 21 | -------------------------------------------------------------------------------- /scripts/dev/virtualbox_create_vmdk_loop0: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | rawImg="tilck.img" 4 | vmdk="tilck.vmdk" 5 | 6 | pushd ./build 7 | 8 | sudo losetup -D 9 | sudo losetup /dev/loop0 $rawImg 10 | sudo chmod o+rw /dev/loop0 11 | rm -f $vmdk 12 | VBoxManage internalcommands createrawvmdk -filename $vmdk -rawdisk /dev/loop0 13 | sudo chown $USER $vmdk 14 | 15 | popd 16 | -------------------------------------------------------------------------------- /scripts/tc/arch/install_pkg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pkg="$1" 4 | ci= 5 | 6 | if [ "$1" == "-ci" ]; then 7 | pkg="$2" 8 | ci=1 9 | fi 10 | 11 | if ! pacman -Q $pkg &> /dev/null; then 12 | 13 | echo "We need to install the package $pkg" 14 | 15 | if [ "$ci" == 1 ]; then 16 | cmd="pacman -S --noconfirm $pkg" 17 | else 18 | cmd="sudo pacman -S $pkg" 19 | fi 20 | 21 | echo "Running the command: $cmd" 22 | eval $cmd 23 | fi 24 | 25 | -------------------------------------------------------------------------------- /scripts/tc/arch/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pkg="$1" 4 | ci= 5 | 6 | if [ "$1" == "-ci" ]; then 7 | pkg="$2" 8 | ci=1 9 | fi 10 | 11 | if [ "$ci" == 1 ]; then 12 | cmd="pacman -Sy" 13 | else 14 | cmd="sudo pacman -Sy" 15 | fi 16 | 17 | echo "Running the command: $cmd" 18 | eval $cmd 19 | 20 | -------------------------------------------------------------------------------- /scripts/tc/debian/install_pkg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pkg="$1" 4 | ci= 5 | 6 | if [ "$1" == "-ci" ]; then 7 | pkg="$2" 8 | ci=1 9 | fi 10 | 11 | if ! [ "`dpkg -s $pkg 2>&1 | grep Status`" ]; then 12 | 13 | echo "We need to install the package $pkg" 14 | 15 | if [ "$ci" == 1 ]; then 16 | cmd="apt install -y $pkg" 17 | else 18 | if ! which sudo &> /dev/null; then 19 | cmd="su -c \"apt install $pkg\"" 20 | else 21 | cmd="sudo apt install $pkg" 22 | fi 23 | fi 24 | 25 | echo "Running the command: $cmd" 26 | eval $cmd 27 | fi 28 | 29 | -------------------------------------------------------------------------------- /scripts/tc/debian/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pkg="$1" 4 | ci= 5 | 6 | if [ "$1" == "-ci" ]; then 7 | pkg="$2" 8 | ci=1 9 | fi 10 | 11 | 12 | if [ "$ci" == 1 ]; then 13 | cmd="apt update" 14 | else 15 | if ! which sudo &> /dev/null; then 16 | cmd="su -c \"apt update\"" 17 | else 18 | cmd="sudo apt update" 19 | fi 20 | fi 21 | 22 | echo "Running the command: $cmd" 23 | eval $cmd 24 | 25 | -------------------------------------------------------------------------------- /scripts/tc/fedora/install_pkg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pkg="$1" 4 | ci= 5 | 6 | if [ "$1" == "-ci" ]; then 7 | pkg="$2" 8 | ci=1 9 | fi 10 | 11 | if ! dnf list installed $pkg &> /dev/null; then 12 | 13 | echo "We need to install the package $pkg" 14 | 15 | if [ "$ci" == 1 ]; then 16 | cmd="dnf install -y $pkg" 17 | else 18 | cmd="sudo dnf install $pkg" 19 | fi 20 | 21 | echo "Running the command: $cmd" 22 | eval $cmd 23 | fi 24 | 25 | -------------------------------------------------------------------------------- /scripts/tc/fedora/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pkg="$1" 4 | ci= 5 | 6 | if [ "$1" == "-ci" ]; then 7 | pkg="$2" 8 | ci=1 9 | fi 10 | 11 | if [ "$ci" == 1 ]; then 12 | cmd="dnf makecache" 13 | else 14 | cmd="sudo dnf makecache" 15 | fi 16 | 17 | echo "Running the command: $cmd" 18 | eval $cmd 19 | 20 | -------------------------------------------------------------------------------- /scripts/tc/opensuse/install_pkg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pkg="$1" 4 | ci= 5 | 6 | if [ "$1" == "-ci" ]; then 7 | pkg="$2" 8 | ci=1 9 | fi 10 | 11 | if ! rpm -q $pkg &> /dev/null; then 12 | 13 | echo "We need to install the package $1" 14 | 15 | if [ "$ci" == 1 ]; then 16 | cmd="zypper install -y $pkg" 17 | else 18 | cmd="sudo zypper install $pkg" 19 | fi 20 | 21 | echo "Running the command: $cmd" 22 | eval $cmd 23 | fi 24 | 25 | -------------------------------------------------------------------------------- /scripts/tc/opensuse/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pkg="$1" 4 | ci= 5 | 6 | if [ "$1" == "-ci" ]; then 7 | pkg="$2" 8 | ci=1 9 | fi 10 | 11 | if [ "$ci" == 1 ]; then 12 | cmd="zypper refresh" 13 | else 14 | cmd="sudo zypper refresh" 15 | fi 16 | 17 | echo "Running the command: $cmd" 18 | eval $cmd 19 | 20 | -------------------------------------------------------------------------------- /scripts/tc/pkgs/README: -------------------------------------------------------------------------------- 1 | # 2 | # README 3 | # --------------------------------------------------------------- 4 | # 5 | # These "scripts" are NOT meant to be executed directly. They are included as 6 | # source files by the scripts/build_toolchain script. 7 | # 8 | # Each one of them, contains one or more "functions" that build or download 9 | # an external component (e.g. busybox). The user can "install" that component 10 | # in the toolchain by running the `build_toolchain` script with the `-s` 11 | # option. 12 | # 13 | # Note: every line in this text file begins with '#' because all the files in 14 | # this directory are treated as bash source files by `build_toolchain`. 15 | # 16 | -------------------------------------------------------------------------------- /scripts/tc/pkgs/lcov: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | ############################### 5 | # LCOV (front end for GCOV) 6 | ############################### 7 | 8 | LCOV_VER="1.15" 9 | 10 | function download_lcov { 11 | 12 | local tarname="lcov-${LCOV_VER}.tgz" 13 | local url="https://github.com/linux-test-project/lcov.git" 14 | 15 | download_git_repo_in_cache "$url" v${LCOV_VER} $tarname lcov-${LCOV_VER} 16 | extract_cachefile_tar_gz $tarname -- 17 | } 18 | 19 | all_funcs_list+=(build_lcov) 20 | function build_lcov { 21 | 22 | pushd noarch 23 | 24 | if ! [ -d lcov-${LCOV_VER} ]; then 25 | 26 | show_work_on_component_msg "LCOV" 27 | 28 | if [ -d lcov ]; then 29 | 30 | # Older versions of this script called this package just `lcov`. 31 | # Rename `lcov` to `lcov-1.13`. 32 | 33 | mv lcov lcov-1.13 34 | ln -s lcov-1.13 lcov 35 | fi 36 | 37 | download_lcov 38 | cd lcov-${LCOV_VER} 39 | 40 | else 41 | show_skip_component_msg "LCOV" 42 | fi 43 | 44 | popd 45 | } 46 | 47 | function build_lcov_installed_status { 48 | if [ -d $TC/noarch/lcov-${LCOV_VER} ]; then 49 | echo "installed noarch" 50 | fi 51 | } 52 | -------------------------------------------------------------------------------- /scripts/tc/pkgs/mtools: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | ############################### 5 | # Mtools 6 | ############################### 7 | 8 | MTOOLS_VER="4.0.23" 9 | 10 | all_funcs_list+=(build_mtools) 11 | function build_mtools { 12 | 13 | pushd host_${HOST_ARCH} 14 | 15 | if ! [ -d mtools ]; then 16 | 17 | show_work_on_component_msg "MTOOLS" 18 | local pkgname="mtools-$MTOOLS_VER" 19 | local tarname=$pkgname.tar.gz 20 | 21 | download_file_in_cache "ftp://ftp.gnu.org/gnu/mtools" "$tarname" 22 | extract_cachefile_tar_gz $tarname $pkgname mtools 23 | 24 | cd mtools 25 | reset_cc_vars 26 | 27 | run_command2 ./configure configure.log 28 | run_command2 "make -j$BUILD_PAR" build.log 29 | else 30 | show_skip_component_msg "MTOOLS" 31 | fi 32 | 33 | popd 34 | } 35 | 36 | function build_mtools_installed_status { 37 | if [ -d $TC/host_${HOST_ARCH}/mtools ]; then 38 | if [ -f $TC/host_${HOST_ARCH}/mtools/mtools ]; then 39 | echo "installed host_${HOST_ARCH}" 40 | else 41 | echo "error" 42 | fi 43 | fi 44 | } 45 | -------------------------------------------------------------------------------- /scripts/tc/pkgs/tfblib: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | TFBLIB_VER="latest" 5 | 6 | if [[ "$ARCH" == "i386" ]]; then 7 | all_funcs_list+=(build_tfblib) 8 | fi 9 | function build_tfblib { 10 | 11 | if [ ! -d noarch/tfblib ]; then 12 | 13 | pushd noarch 14 | show_work_on_component_msg "TFBLIB" 15 | git clone https://github.com/vvaltchev/tfblib 16 | ln -s $TC/noarch/tfblib "$MAIN_DIR/userapps/extra" 17 | popd 18 | 19 | else 20 | show_skip_component_msg "TFBLIB" 21 | fi 22 | } 23 | 24 | function build_tfblib_installed_status { 25 | if [ -d $TC/noarch/tfblib ]; then 26 | echo "installed noarch" 27 | fi 28 | } 29 | -------------------------------------------------------------------------------- /scripts/templates/README: -------------------------------------------------------------------------------- 1 | This directory (and all of its subdirectories) does NOT contain directly 2 | runnable scripts. Instead, it contains template scripts which are "patched" 3 | by CMake with the right paths, config values etc. Their correspondent 4 | runnable scripts are emitted in project's build directory after running 5 | CMake (or our 'cmake_run' wrapper). 6 | -------------------------------------------------------------------------------- /scripts/templates/build_test_fatpart: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | # Exit on any error 5 | set -e 6 | 7 | maindir="@CMAKE_SOURCE_DIR@" 8 | bdir="@CMAKE_BINARY_DIR@" 9 | dest="@CMAKE_BINARY_DIR@/test_fatpart" 10 | tc="@TCROOT@" 11 | host_arch="@HOST_ARCH@" 12 | 13 | mtoolsdir=$tc/host_${host_arch}/mtools 14 | mformat=$mtoolsdir/mformat 15 | mlabel=$mtoolsdir/mlabel 16 | mmd=$mtoolsdir/mmd 17 | mcopy=$mtoolsdir/mcopy 18 | 19 | 20 | if [ ! -f $dest ]; then 21 | # If the 'fatpart' file does not already exist 22 | dd status=none if=/dev/zero of=$dest bs=1M count=35 23 | fi 24 | 25 | # mformat options 26 | # -d ; num of FAT copies 27 | # -F ; force FAT32 to be used 28 | # -c ; sectors per cluster 29 | # -t ; cylinders 30 | # -h ; heads 31 | # -s ; sectors 32 | $mformat -i $dest -d 1 -F -c 1 -t 70 -h 16 -s 63 :: 33 | $mlabel -i $dest ::TILCK 34 | 35 | rm -rf $bdir/test_sysroot 36 | mkdir $bdir/test_sysroot 37 | cp -r $maindir/tests/unit/test_sysroot $bdir/ 38 | cd $bdir/test_sysroot 39 | 40 | # Create file with random data 41 | dd if=/dev/urandom of=./bigfile bs=1 count=1048599 # 1 MB + 23 bytes 42 | 43 | # first, create the directories 44 | for f in $(find * -type d); do 45 | $mmd -i $dest $f 46 | done 47 | 48 | # then, copy all the files in sysroot 49 | for f in $(find * -type f); do 50 | $mcopy -i $dest $f ::/$f 51 | done 52 | -------------------------------------------------------------------------------- /scripts/templates/musl-g++: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | PROJ_DIR="@CMAKE_SOURCE_DIR@" 5 | TCROOT="@TCROOT@" 6 | ARCH="@ARCH@" 7 | HOST_ARCH="@HOST_ARCH@" 8 | VER="@GCC_TC_VER_@" 9 | 10 | if [ @USE_SYSCC@ = 0 ]; then 11 | GCC_TC="$TCROOT/host_$HOST_ARCH/gcc_${VER}_${ARCH}_glibc/bin" 12 | export PATH="$GCC_TC:$PATH" 13 | else 14 | export SYS_CC="@SYS_CC@" 15 | export SYS_CXX="@SYS_CXX@" 16 | export PATH="$PROJ_DIR/scripts/build_scripts:$PATH" 17 | fi 18 | 19 | "$TCROOT/$ARCH/musl/install/bin/musl-g++" "$@" -Wl,-m -Wl,@ARCH_LD_OUTPUT@ 20 | 21 | -------------------------------------------------------------------------------- /scripts/templates/musl-gcc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | 4 | PROJ_DIR="@CMAKE_SOURCE_DIR@" 5 | TCROOT="@TCROOT@" 6 | ARCH="@ARCH@" 7 | HOST_ARCH="@HOST_ARCH@" 8 | VER="@GCC_TC_VER_@" 9 | 10 | if [ @USE_SYSCC@ = 0 ]; then 11 | GCC_TC="$TCROOT/host_$HOST_ARCH/gcc_${VER}_${ARCH}_glibc/bin" 12 | export PATH="$GCC_TC:$PATH" 13 | else 14 | export SYS_CC="@SYS_CC@" 15 | export SYS_CXX="@SYS_CXX@" 16 | export PATH="$PROJ_DIR/scripts/build_scripts:$PATH" 17 | fi 18 | 19 | "$TCROOT/$ARCH/musl/install/bin/musl-gcc" "$@" -Wl,-m -Wl,@ARCH_LD_OUTPUT@ 20 | -------------------------------------------------------------------------------- /scripts/templates/qemu/debug_run_qemu: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BUILD_DIR="@CMAKE_BINARY_DIR@" 4 | $BUILD_DIR/run_multiboot_qemu -S "$@" 5 | -------------------------------------------------------------------------------- /scripts/templates/qemu/run_efi_qemu32: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BUILD_DIR="@CMAKE_BINARY_DIR@" 4 | f="@IMG_FILE@" 5 | tc="@TCROOT@" 6 | 7 | if [ -z "$QEMU_BIOS" ]; then 8 | QEMU_BIOS="$tc/i386/ovmf/OVMF-pure-efi.fd" 9 | fi 10 | 11 | if ! [ -f "$QEMU_BIOS" ]; then 12 | echo "In order to boot with EFI, you need to download OVMF first." 13 | echo "To do that, just run in project's main directory:" 14 | echo " ./scripts/build_toolchain -s download_ovmf" 15 | exit 1 16 | fi 17 | 18 | if [ -z "$GDB_PORT" ]; then 19 | GDB_PORT=1234 20 | fi 21 | 22 | echo "Run QEMU with -bios $QEMU_BIOS -gdb tcp::$GDB_PORT" 23 | 24 | qemu-system-i386 \ 25 | @QEMU_COMMON_OPTS@ \ 26 | @QEMU_RAM_OPT@ \ 27 | -gdb tcp::$GDB_PORT \ 28 | -bios "$QEMU_BIOS" \ 29 | -drive index=0,media=disk,format=raw,file=$f "$@" 30 | -------------------------------------------------------------------------------- /scripts/templates/qemu/run_efi_qemu64: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BUILD_DIR="@CMAKE_BINARY_DIR@" 4 | HOST_ARCH="@HOST_ARCH" 5 | f="@IMG_FILE@" 6 | tc="@TCROOT@" 7 | tc_bios="$tc/x86_64/ovmf/OVMF-pure-efi.fd" 8 | 9 | if [[ $HOST_ARCH != x86_64 ]]; then 10 | QEMU_BIOS="tc" 11 | fi 12 | 13 | if [ -z "$QEMU_BIOS" ]; then 14 | 15 | QEMU_BIOS="/usr/share/qemu/OVMF.fd" 16 | 17 | if ! [ -f "$QEMU_BIOS" ]; then 18 | QEMU_BIOS="$tc_bios" 19 | fi 20 | 21 | elif [ "$QEMU_BIOS" = "tc" ]; then 22 | 23 | QEMU_BIOS="$tc_bios" 24 | fi 25 | 26 | if ! [ -f "$QEMU_BIOS" ]; then 27 | echo "In order to boot with EFI, you need to download OVMF first." 28 | echo "To do that, just run in project's main directory:" 29 | echo " ./scripts/build_toolchain -s download_ovmf" 30 | exit 1 31 | fi 32 | 33 | if [ -z "$GDB_PORT" ]; then 34 | GDB_PORT=1234 35 | fi 36 | 37 | echo "Run QEMU with -bios $QEMU_BIOS -gdb tcp::$GDB_PORT" 38 | 39 | qemu-system-x86_64 \ 40 | @QEMU_COMMON_OPTS@ \ 41 | @QEMU_RAM_OPT@ \ 42 | -gdb tcp::$GDB_PORT \ 43 | -bios "$QEMU_BIOS" \ 44 | -drive index=0,media=disk,format=raw,file=$f "$@" 45 | -------------------------------------------------------------------------------- /scripts/templates/qemu/run_multiboot_qemu: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | BUILD_DIR="@CMAKE_BINARY_DIR@" 4 | FATPART="$BUILD_DIR/fatpart" 5 | 6 | if [ -z "$GDB_PORT" ]; then 7 | GDB_PORT=1234 8 | fi 9 | 10 | qemu-system-@ARCH@ @QEMU_COMMON_OPTS@ -gdb tcp::$GDB_PORT \ 11 | @QEMU_RAM_OPT@ -kernel "@KERNEL_FILE@" -initrd "$FATPART" "$@" 12 | -------------------------------------------------------------------------------- /scripts/templates/qemu/run_qemu: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BUILD_DIR=@CMAKE_BINARY_DIR@ 4 | 5 | if [ -z "$GDB_PORT" ]; then 6 | GDB_PORT=1234 7 | fi 8 | 9 | qemu-system-@ARCH@ \ 10 | @QEMU_COMMON_OPTS@ \ 11 | -gdb tcp::$GDB_PORT \ 12 | @QEMU_RAM_OPT@ \ 13 | -drive id=img1,format=raw,if=none,file=@IMG_FILE@ \ 14 | @QEMU_ARCH_OPTS@ $EXTRA_OPTS "$@" 15 | -------------------------------------------------------------------------------- /sysroot/README: -------------------------------------------------------------------------------- 1 | This is the skeleton of the content of fatpart. 2 | During the build this skeleton will be used as base and other files will be added as well. 3 | -------------------------------------------------------------------------------- /sysroot/bin/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/sysroot/bin/.gitignore -------------------------------------------------------------------------------- /sysroot/etc/group: -------------------------------------------------------------------------------- 1 | root:x:0: 2 | -------------------------------------------------------------------------------- /sysroot/etc/passwd: -------------------------------------------------------------------------------- 1 | root:x:0:0:root:/:/bin/ash 2 | -------------------------------------------------------------------------------- /sysroot/etc/start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Symlink the essential directories from /initrd to / 4 | dirs="bin etc usr lib" 5 | 6 | for d in $dirs; do 7 | 8 | if ! [ -d /initrd/$d ]; then 9 | continue 10 | fi 11 | 12 | mkdir -p $d 13 | for x in /initrd/$d/*; do 14 | 15 | if [ -f $x ]; then 16 | 17 | ln -s $x $d/ 18 | 19 | elif [ -d $x ]; then 20 | 21 | dname=$(basename $x) 22 | mkdir -p /$d/$dname 23 | 24 | for y in /initrd/$d/$dname/*; do 25 | 26 | if [ "$y" = "/initrd/$d/$dname/*" ]; then 27 | break 28 | fi 29 | 30 | ln -s $y /$d/$dname/ 31 | done 32 | fi 33 | done 34 | done 35 | 36 | # Create symlinks for all the busybox's applets 37 | /initrd/bin/busybox --install -s /bin 38 | 39 | # Create a symlink for the `env` applet in /usr/bin/env 40 | ln -s /initrd/bin/busybox /usr/bin/env 41 | 42 | # Create symlinks for some devshell cmds 43 | cd /usr/bin 44 | ln -s devshell runall 45 | ln -s devshell selftest 46 | 47 | # Create a symlink for the debug-panel tools 48 | ln -s /initrd/usr/bin/dp tracer 49 | ln -s /initrd/usr/bin/dp ps 50 | -------------------------------------------------------------------------------- /sysroot/usr/bin/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/sysroot/usr/bin/.gitignore -------------------------------------------------------------------------------- /sysroot/usr/bin/vim: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Constants 5 | # 6 | 7 | VR_TGZ="/initrd/usr/lib/vim/vr.tgz" 8 | VIM_GZ="/initrd/usr/lib/vim/vim.gz" 9 | vim_binary=/tmp/vim/vim 10 | 11 | # 12 | # Main body 13 | # 14 | 15 | set -e 16 | oldpwd="$PWD" 17 | 18 | if ! [ -f $VIM_GZ ] || ! [ -f $VR_TGZ ]; then 19 | 20 | echo "" 21 | echo "VIM is not built-in. Tilck image rebuild needed. Steps:" 22 | echo " - Run: ./scripts/build_toolchain -s build_vim" 23 | echo " - Run: CMAKE_ARGS='-DEXTRA_VIM=1' ./scripts/cmake_run" 24 | echo " - Run: make rem" 25 | echo "" 26 | exit 1 27 | fi 28 | 29 | export VIMRUNTIME=/tmp/vim/runtime 30 | 31 | if ! [ -d $VIMRUNTIME ]; then 32 | 33 | mkdir -p /tmp/vim 34 | cd /tmp/vim 35 | 36 | if ! tar xfz $VR_TGZ; then 37 | echo "ERROR: tar failed" 38 | cd / 39 | rm -rf /tmp/vim 40 | exit 1 41 | fi 42 | 43 | sed -Ei s/scrolloff=[0-9]*/scrolloff=0/g $VIMRUNTIME/defaults.vim 44 | fi 45 | 46 | if ! [ -f $vim_binary ]; then 47 | gzip -cd $VIM_GZ > $vim_binary 48 | chmod 755 $vim_binary 49 | fi 50 | 51 | cd $oldpwd 52 | 53 | # Start vim with no swap file (-n) and no viminfo (-i) 54 | # simply because they're useless for the use case of Tilck. 55 | exec $vim_binary -n -i NONE "$@" 56 | -------------------------------------------------------------------------------- /sysroot/usr/lib/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/sysroot/usr/lib/.gitignore -------------------------------------------------------------------------------- /sysroot/usr/share/terminfo/l/linux: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/sysroot/usr/share/terminfo/l/linux -------------------------------------------------------------------------------- /tests/interactive/README: -------------------------------------------------------------------------------- 1 | INTERACTIVE TESTS: source & helper files 2 | --------------------------------------------- 3 | 4 | This directory contains a list of NON-independent python3 source files, each 5 | one of them being the body of an "interactive test". 6 | 7 | Those source files are dynamically compiled (on-the-fly) and then executed 8 | by the `run_interactive_test` runner. That's not a detail: those files need to 9 | run using the same global context as the runner (because they need functions 10 | like send_string_to_vm(), vm_take_stable_screenshot() etc). 11 | -------------------------------------------------------------------------------- /tests/interactive/dp.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | # pylint: skip-file 3 | # 4 | # NOTE: this file, as all the others in this directory, run in the same global 5 | # context as their runner (run_interactive_test). 6 | 7 | send_to_vm_and_find_text(r"dp{ret}", True, [ 8 | "TilckDebugPanel", 9 | "TERM_ROWS", 10 | "DEBUG_CHECKS", 11 | ]) 12 | 13 | send_to_vm_and_find_text(r"2", True, [ 14 | "START", 15 | "END", 16 | "usable physical mem", 17 | ]) 18 | 19 | send_to_vm_and_find_text(r"3", True, [ 20 | "Usable", 21 | "Used", 22 | "vaddr", 23 | ]) 24 | 25 | send_to_vm_and_find_text(r"4", True, [ 26 | "pid", 27 | "tty", 28 | "cmdline", 29 | ]) 30 | 31 | send_to_vm_and_find_text(r"5", True, [ 32 | "counters", 33 | ]) 34 | 35 | send_to_vm_and_find_text(r"6", True, []) 36 | send_string_to_vm(r"q") 37 | -------------------------------------------------------------------------------- /tests/interactive/expected/fbtest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/fbtest.png -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-0.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-1.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-1.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-2.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-2.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-3.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-4.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-4.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-5.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-5.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-6.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-6.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-7.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-7.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim1-8.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim1-8.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim2-0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim2-0.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim2-1.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim2-1.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim2-2.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim2-2.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim2-3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim2-3.gz -------------------------------------------------------------------------------- /tests/interactive/expected/vim2-4.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/interactive/expected/vim2-4.gz -------------------------------------------------------------------------------- /tests/interactive/fbtest.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | # pylint: skip-file 3 | # 4 | # NOTE: this file, as all the others in this directory, run in the same global 5 | # context as their runner (run_interactive_test). 6 | 7 | send_string_to_vm(r"fbtest{ret}") 8 | s = vm_take_stable_screenshot() 9 | send_string_to_vm(r"{ret}") 10 | 11 | actual = img_convert(s, "png") 12 | expected = os.path.join(INTERACTIVE_EXP, "fbtest.png") 13 | 14 | if not filecmp.cmp(actual, expected, False): 15 | raise IntTestScreenshotNoMatchFailure( 16 | "".format(actual), 17 | "".format(expected) 18 | ) 19 | 20 | -------------------------------------------------------------------------------- /tests/interactive/ls.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | # pylint: skip-file 3 | # 4 | # NOTE: this file, as all the others in this directory, run in the same global 5 | # context as their runner (run_interactive_test). 6 | 7 | send_to_vm_and_find_text(r"ls -l /{ret}", False, ["bin", "dev", "usr"]) 8 | -------------------------------------------------------------------------------- /tests/interactive/vim1.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | # pylint: skip-file 3 | # 4 | # NOTE: this file, as all the others in this directory, run in the same global 5 | # context as their runner (run_interactive_test). 6 | 7 | just_run_vim_and_exit() 8 | 9 | do_interactive_actions( 10 | "vim1", 11 | [ 12 | r"vim /usr/lib/vim/samples/numbers.txt{ret}", 13 | r"{esc}:29{ret}", 14 | r"{down}", 15 | r"{down}", 16 | r"{down}", 17 | r"{esc}:3{ret}", 18 | r"{up}", 19 | r"{up}", 20 | r"{esc}:q{ret}", 21 | ], 22 | false_positive_handler_vim 23 | ) 24 | -------------------------------------------------------------------------------- /tests/interactive/vim2.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | # pylint: skip-file 3 | # 4 | # NOTE: this file, as all the others in this directory, run in the same global 5 | # context as their runner (run_interactive_test). 6 | 7 | just_run_vim_and_exit() 8 | 9 | do_interactive_actions( 10 | "vim2", 11 | [ 12 | r"cd /usr/lib/vim/samples{ret}vim perl.pl{ret}", 13 | r"{esc}:open python.py{ret}", 14 | r"{esc}:open ruby.rb{ret}", 15 | r"{esc}:open shell.sh{ret}", 16 | r"{esc}:q{ret}cd /{ret}", 17 | ], 18 | false_positive_handler_vim 19 | ) 20 | -------------------------------------------------------------------------------- /tests/interactive/vim_text_files/numbers.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 21 | 21 22 | 22 23 | 23 24 | 24 25 | 25 26 | 26 27 | 27 28 | 28 29 | 29 30 | 30 31 | 31 32 | 32 33 | 33 34 | 34 35 | 35 36 | 36 37 | 37 38 | 38 39 | 39 40 | 40 41 | 41 42 | 42 43 | 43 44 | 44 45 | 45 46 | 46 47 | 47 48 | 48 49 | 49 50 | 50 51 | 51 52 | 52 53 | 53 54 | 54 55 | 55 56 | 56 57 | 57 58 | 58 59 | 59 60 | 60 61 | 61 62 | 62 63 | 63 64 | 64 65 | 65 66 | 66 67 | 67 68 | 68 69 | 69 70 | 70 71 | 71 72 | 72 73 | 73 74 | 74 75 | 75 76 | 76 77 | 77 78 | 78 79 | 79 80 | 80 81 | 81 82 | 82 83 | 83 84 | 84 85 | 85 86 | 86 87 | 87 88 | 88 89 | 89 90 | 90 91 | 91 92 | 92 93 | 93 94 | 94 95 | 95 96 | 96 97 | 97 98 | 98 99 | 99 100 | 100 101 | -------------------------------------------------------------------------------- /tests/interactive/vim_text_files/perl.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | use warnings; 4 | 5 | use Path::Tiny; 6 | use autodie; # die if problem reading or writing a file 7 | 8 | my $dir = path("/tmp"); # /tmp 9 | 10 | my $file = $dir->child("file.txt"); # /tmp/file.txt 11 | 12 | # Get a file_handle (IO::File object) you can write to 13 | # with a UTF-8 encoding layer 14 | my $file_handle = $file->openw_utf8(); 15 | 16 | my @list = ('a', 'list', 'of', 'lines'); 17 | 18 | foreach my $line ( @list ) { 19 | # Add the line to the file 20 | $file_handle->print($line . "\n"); 21 | } 22 | Appending to a file 23 | # As above but use opena_utf8() instead of openw_utf8() 24 | my $file_handle = $file->opena_utf8(); 25 | Reading a file 26 | #!/usr/bin/perl 27 | use strict; 28 | use warnings; 29 | 30 | use Path::Tiny; 31 | use autodie; # die if problem reading or writing a file 32 | 33 | my $dir = path("/tmp"); # /tmp 34 | 35 | my $file = $dir->child("file.txt"); 36 | 37 | # Read in the entire contents of a file 38 | my $content = $file->slurp_utf8(); 39 | 40 | # openr_utf8() returns an IO::File object to read from 41 | # with a UTF-8 decoding layer 42 | my $file_handle = $file->openr_utf8(); 43 | 44 | # Read in line at a time 45 | while( my $line = $file_handle->getline() ) { 46 | print $line; 47 | } 48 | -------------------------------------------------------------------------------- /tests/interactive/vim_text_files/python.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | BOARD_SIZE = 8 4 | 5 | def under_attack(col, queens): 6 | left = right = col 7 | 8 | for r, c in reversed(queens): 9 | left, right = left - 1, right + 1 10 | 11 | if c in (left, col, right): 12 | return True 13 | return False 14 | 15 | def solve(n): 16 | if n == 0: 17 | return [[]] 18 | 19 | smaller_solutions = solve(n - 1) 20 | 21 | return [solution+[(n,i+1)] 22 | for i in range(BOARD_SIZE) 23 | for solution in smaller_solutions 24 | if not under_attack(i+1, solution)] 25 | for answer in solve(BOARD_SIZE): 26 | print (answer) 27 | 28 | -------------------------------------------------------------------------------- /tests/interactive/vim_text_files/ruby.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | def prnthelp 3 | puts "Hello sir, what would you like to do?" 4 | puts "1: dir" 5 | puts "2: exit" 6 | end 7 | 8 | def loop 9 | prnthelp 10 | case gets.chomp.to_i 11 | when 1 then puts "you chose dir!" 12 | when 2 then puts "you chose exit!" 13 | exit 14 | end 15 | loop 16 | end 17 | 18 | loop 19 | -------------------------------------------------------------------------------- /tests/interactive/vim_text_files/shell.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | dirs="bin etc usr lib" 4 | 5 | for d in $dirs; do 6 | 7 | if ! [ -d /initrd/$d ]; then 8 | continue 9 | fi 10 | 11 | mkdir -p $d 12 | for x in /initrd/$d/*; do 13 | 14 | if [ -f $x ]; then 15 | 16 | ln -s $x $d/ 17 | 18 | elif [ -d $x ]; then 19 | 20 | dname=$(basename $x) 21 | mkdir -p /$d/$dname 22 | 23 | for y in /initrd/$d/$dname/*; do 24 | 25 | if [ "$y" = "/initrd/$d/$dname/*" ]; then 26 | break 27 | fi 28 | 29 | ln -s $y /$d/$dname/ 30 | done 31 | fi 32 | done 33 | done 34 | -------------------------------------------------------------------------------- /tests/runners/ci_run_all_tests_wrapper: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Project's root directory 4 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | MAIN_DIR="$(cd $SOURCE_DIR/../.. && pwd)" 6 | DISTRO_FILE="$MAIN_DIR/toolchain2/.distro" 7 | 8 | if ! [ "$RUNNING_IN_CI" == 1 ]; then 9 | echo "This script was meant to be run in CI (toolchain_builds.yml)." 10 | echo "Outside CI, please use directly the run_all_tests script." 11 | exit 1 12 | fi 13 | 14 | if ! [ -f $DISTRO_FILE ]; then 15 | echo "ERROR: file $DISTRO_FILE not found." 16 | exit 1 17 | fi 18 | 19 | distro=$(cat $DISTRO_FILE) 20 | 21 | if [ "$distro" == "opensuse" ]; then 22 | 23 | err="$(qemu-system-i386 --help 2>&1)" 24 | if echo "$err" | grep membarrier &> /dev/null; then 25 | echo "WARNING: skipping the system tests because the QEMU version" 26 | echo "on OpenSUSE requires the membarrier syscall, not available on" 27 | echo "the current Linux kernel." 28 | exit 0 29 | fi 30 | fi 31 | 32 | exec $MAIN_DIR/build/st/run_all_tests "$@" 33 | -------------------------------------------------------------------------------- /tests/runners/lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/runners/lib/__init__.py -------------------------------------------------------------------------------- /tests/runners/lib/env.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | import os 4 | import sys 5 | from .lang_aux import Const, ReloadAsConstModule 6 | 7 | def env_bool(x): 8 | return Const(os.environ.get(x, '0') == '1') 9 | 10 | def env_int(x, val): 11 | return Const(int(os.environ.get(x, str(val)))) 12 | 13 | VM_MEMORY_SIZE_IN_MB = env_int('TILCK_VM_MEM', 128) 14 | GEN_TEST_DATA = env_bool('GEN_TEST_DATA') 15 | IN_TRAVIS = env_bool('TRAVIS') 16 | IN_CIRCLECI = env_bool('CIRCLECI') 17 | IN_AZURE = env_bool('AZURE_HTTP_USER_AGENT') 18 | CI = env_bool('RUNNING_IN_CI') 19 | DUMP_COV = env_bool('DUMP_COV') 20 | REPORT_COV = env_bool('REPORT_COV') 21 | VERBOSE = env_bool('VERBOSE') 22 | IN_ANY_CI = Const(IN_TRAVIS.val or IN_CIRCLECI.val or IN_AZURE.val or CI.val) 23 | 24 | ReloadAsConstModule(__name__) 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/runners/lib/lang_aux.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | import sys 4 | import types 5 | 6 | class ConstError(TypeError): 7 | 8 | def __init__(self, name): 9 | super(ConstError, self).__init__() 10 | self.name = name 11 | 12 | def __str__(self): 13 | return "Cannot re-bind '{}'".format(self.name) 14 | 15 | class Const: 16 | 17 | def __init__(self, val): 18 | self.val = val 19 | 20 | def __setattr__(self, name, val): 21 | 22 | if name in self.__dict__: 23 | raise ConstError(name) 24 | 25 | self.__dict__[name] = val 26 | 27 | class ConstModule(types.ModuleType): 28 | 29 | def __init__(self, mod): 30 | 31 | super(ConstModule, self).__init__(mod) 32 | 33 | for pair in sys.modules[mod].__dict__.items(): 34 | if type(pair[1]) is Const: 35 | self.__dict__[pair[0]] = pair[1].val 36 | else: 37 | self.__dict__[pair[0]] = pair[1] 38 | 39 | def __setattr__(self, name, value): 40 | 41 | if name in self.__dict__: 42 | raise ConstError(name) 43 | 44 | self.__dict__[name] = value 45 | 46 | def ReloadAsConstModule(name): 47 | sys.modules[name] = ConstModule(name) 48 | 49 | -------------------------------------------------------------------------------- /tests/runners/lib/stdio.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | import sys 4 | 5 | # Runtime config vars 6 | runnerName = "" 7 | 8 | def direct_print(data): 9 | sys.stdout.buffer.write(data) 10 | sys.stdout.buffer.flush() 11 | 12 | def raw_print(msg): 13 | sys.stdout.buffer.write(msg.encode('utf-8')) 14 | sys.stdout.buffer.write('\n'.encode('utf-8')) 15 | sys.stdout.buffer.flush() 16 | 17 | def raw_stdout_write(msg): 18 | sys.stdout.buffer.write(msg.encode('utf-8')) 19 | sys.stdout.buffer.flush() 20 | 21 | def msg_print(msg): 22 | raw_print("[{}] {}".format(runnerName, msg)) 23 | 24 | def set_runner_name(name): 25 | global runnerName 26 | runnerName = name 27 | -------------------------------------------------------------------------------- /tests/self/README: -------------------------------------------------------------------------------- 1 | 2 | CONTENTS 3 | =========== 4 | 5 | This directory contains code directly compiled-in the Tilck's kernel when 6 | the CMake option KERNEL_SELFTESTS is enabled (default). 7 | 8 | -------------------------------------------------------------------------------- /tests/self/se_data.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #define RANDOM_VALUES_COUNT 1000 4 | extern unsigned int random_values[RANDOM_VALUES_COUNT]; 5 | -------------------------------------------------------------------------------- /tests/system/README: -------------------------------------------------------------------------------- 1 | 2 | CONTENTS 3 | ========== 4 | 5 | This directory contains C files directly built as part of the `devshell` 6 | user app, containing Tilck's system tests. In order words, these tests use 7 | kernel's only interface (syscalls) in order to check its correctness. 8 | The reason for keeping those files here instead of in userapps/devshell/ is 9 | purely organizational: it just makes more sense to have ALL of Tilck's test 10 | in a single (master) directory called `tests`. The non-test part of devshell 11 | clearly should remain in the userapps/ directory. 12 | 13 | NOTE: for info about to run those tests, see the main README.md file. 14 | 15 | DON'T FORGET: to add a new system test, add an entry in `cmds_table.h`. 16 | 17 | Other 18 | ====== 19 | 20 | The subdirectory `runners` contain high-level python scripts used to run 21 | those system tests in QEMU VMs. 22 | -------------------------------------------------------------------------------- /tests/system/cmds_table.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | #include "devshell.h" 3 | 4 | #define CMD_ENTRY(name, len, enabled) int cmd_##name(int argc, char **argv); 5 | #include "cmds_table.h" 6 | 7 | #undef CMD_ENTRY 8 | #define CMD_ENTRY(name, len, enabled) {#name, cmd_ ## name, len, enabled}, 9 | 10 | static struct test_cmd_entry _cmds_table[] = 11 | { 12 | #include "cmds_table.h" 13 | {NULL, NULL, 0, 0} 14 | }; 15 | 16 | struct test_cmd_entry *cmds_table = _cmds_table; 17 | 18 | -------------------------------------------------------------------------------- /tests/system/scripts/sysfs: -------------------------------------------------------------------------------- 1 | #!/initrd/bin/busybox ash 2 | 3 | set -e 4 | 5 | if ! [ -d /syst ]; then 6 | echo "No sysfs mounted at /syst: skipping the test" 7 | exit 0 8 | fi 9 | 10 | echo 11 | echo "[Enter in /syst]" 12 | cd /syst 13 | echo "[ls]" 14 | ls 15 | 16 | if ! [ -d config ]; then 17 | echo "FAIL: /syst/config not found" 18 | exit 1 19 | fi 20 | 21 | if ! [ -d hw ]; then 22 | echo "FAIL: /syst/hw not found" 23 | exit 1 24 | fi 25 | 26 | echo 27 | echo "[Enter in /syst/config]" 28 | cd config 29 | echo "[ls -R]" 30 | ls -R 31 | 32 | echo 33 | echo "[Read all the files in config/]" 34 | 35 | # Read all the files, expecting no errors 36 | for x in `find .`; do 37 | if [ -f $x ]; then 38 | echo $x: `cat $x`; 39 | fi 40 | done 41 | 42 | if ! [ -f commit ]; then 43 | echo "FAIL: no commit file in /syst/config" 44 | exit 1 45 | fi 46 | 47 | # Get kernel's commit's SHA-1 48 | sha1=`uname -v` 49 | 50 | echo 51 | echo "[Check the content of /syst/config/commit]" 52 | 53 | if ! cat commit | grep $sha1; then 54 | echo "FAIL: commit's sha-1: $sha1 not found in the commit file" 55 | echo "FAIL: file's contents: " 56 | cat commit 57 | exit 1 58 | fi 59 | 60 | echo 61 | echo "[Enter in /syst/hw]" 62 | cd /syst/hw 63 | echo "[ls -Rl]" 64 | ls -Rl 65 | 66 | exit 0 67 | -------------------------------------------------------------------------------- /tests/system/scripts/tar: -------------------------------------------------------------------------------- 1 | #!/initrd/bin/busybox ash 2 | 3 | set -e 4 | 5 | cd /tmp 6 | 7 | echo "Running tar cfvz t.tgz /initrd ..." 8 | tar cfvz t.tgz /initrd 9 | 10 | echo "Running tar xfvz t.tgz ..." 11 | tar xfvz t.tgz 12 | 13 | echo "Removing t.tgz and initrd/ ..." 14 | rm -rf t.tgz initrd 15 | 16 | echo "Done." 17 | exit 0 18 | -------------------------------------------------------------------------------- /tests/system/scripts/tcc: -------------------------------------------------------------------------------- 1 | #!/initrd/bin/busybox ash 2 | 3 | # ---------------------------------------------------------------- 4 | # TinyCC support has been disabled. 5 | # ---------------------------------------------------------------- 6 | 7 | # set -e 8 | 9 | # if ! [ -f /bin/tcc ]; then 10 | # echo "No TinyCC in /bin/tcc: skipping the test" 11 | # exit 0 12 | # fi 13 | 14 | # cd /tmp 15 | 16 | # echo "Compiling ex1.c with TinyCC ..." 17 | # tcc -static /lib/tcc-examples/ex1.c -o /tmp/ex1 18 | 19 | # echo "Running the ex1 program ..." 20 | # out=`./ex1` 21 | 22 | # echo "Output:" 23 | # echo "$out" 24 | 25 | # if [ "$out" != "Hello World" ]; then 26 | # echo "The output does not match the expected value" 27 | # exit 1 28 | # fi 29 | 30 | # rm /tmp/ex1 31 | # echo "Done." 32 | # exit 0 33 | -------------------------------------------------------------------------------- /tests/system/test_common.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include "devshell.h" 5 | 6 | void create_test_file(const char *path, int n); 7 | int remove_test_file(const char *path, int n); 8 | void remove_test_file_expecting_success(const char *path, int n); 9 | bool running_on_tilck(void); 10 | void not_on_tilck_message(void); 11 | 12 | int test_sig(void (*child_func)(void *), 13 | void *arg, 14 | int ex_sig, 15 | int ex_code, 16 | int signal_to_send); 17 | -------------------------------------------------------------------------------- /tests/unit/README: -------------------------------------------------------------------------------- 1 | 2 | CONTENTS 3 | ========== 4 | 5 | This directory contains kernel's unit tests, which can be built using the 6 | `gtests` target. 7 | -------------------------------------------------------------------------------- /tests/unit/asm_fake_funcs.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | 5 | // Defining some necessary symbols just to make the linker happy. 6 | 7 | void *kernel_initial_stack = NULL; 8 | 9 | void asm_save_regs_and_schedule() { NOT_REACHED(); } 10 | void switch_to_initial_kernel_stack() { NOT_REACHED(); } 11 | void fault_resumable_call() { NOT_REACHED(); } 12 | void asm_do_bogomips_loop(void) { NOT_REACHED(); } 13 | void asm_nop_loop(void) { NOT_REACHED(); } 14 | void context_switch(void) { NOT_REACHED(); } 15 | -------------------------------------------------------------------------------- /tests/unit/fake_funcs_utils.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | #include 5 | 6 | extern "C" { 7 | void initialize_test_kernel_heap(); 8 | extern bool mock_kmalloc; 9 | extern bool suppress_printk; 10 | } 11 | -------------------------------------------------------------------------------- /tests/unit/kernel_init_funcs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #pragma once 4 | 5 | extern "C" { 6 | 7 | #include 8 | 9 | void init_pageframe_allocator(); 10 | void init_kmalloc(); 11 | void init_worker_threads(); 12 | void init_kmalloc_for_tests(); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/unit/mocked_funcs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | DEF_3(wrap, assert_failed, void, const char *, const char *, int) 4 | DEF_2(wrap, not_reached, void, const char *, int) 5 | DEF_2(wrap, not_implemented, void, const char *, int) 6 | DEF_3(wrap, tilck_vprintk, void, u32, const char *, va_list) 7 | DEF_1(wrap, kmutex_lock, void, struct kmutex *) 8 | DEF_1(wrap, kmutex_unlock, void, struct kmutex *) 9 | DEF_2(wrap, fat_ramdisk_prepare_for_mmap, int, void *, size_t) 10 | DEF_1(wrap, wth_create_thread_for, int, void *) 11 | DEF_1(wrap, wth_wakeup, void, void *) 12 | DEF_0(wrap, check_in_irq_handler, void) 13 | DEF_2(wrap, general_kmalloc, void *, size_t *, u32) 14 | DEF_3(wrap, general_kfree, void, void *, size_t *, u32) 15 | DEF_1(wrap, kmalloc_get_first_heap, void *, size_t *) 16 | DEF_0(real, experiment_bar, bool) 17 | DEF_1(real, experiment_foo, int, int) 18 | DEF_2(real, vfs_dup, int, fs_handle, fs_handle *) 19 | DEF_1(real, vfs_close, void, fs_handle) 20 | DEF_1(real, handle_sys_trace_arg, int , const char *); 21 | DEF_4(real, copy_str_from_user, int, void *, const void *, size_t, size_t *); 22 | DEF_3(real, copy_from_user, int, void *, const void *, size_t); 23 | -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/12345678.xyz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/12345678.xyz -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/Aaa: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/Aaa -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/BBB: -------------------------------------------------------------------------------- 1 | hello world from BBB 2 | -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/This_is_a_file_with_a_veeeery_long_name.txt: -------------------------------------------------------------------------------- 1 | Content of file with a long name 2 | -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/dir1/f1: -------------------------------------------------------------------------------- 1 | hello world! 2 | -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/dir1/f2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/dir1/f2 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/dir2/f3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/dir2/f3 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/dir2/f4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/dir2/f4 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/dir3/f5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/dir3/f5 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/file.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/file.a -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/file.ab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/file.ab -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/file.abc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/file.abc -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f1 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f10 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f11 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f12 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f13: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f13 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f14: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f14 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f15: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f15 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f16 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f17 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f18: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f18 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f19: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f19 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f2 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f20: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f20 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f3 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f4 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f5 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f6 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f7 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f8 -------------------------------------------------------------------------------- /tests/unit/test_sysroot/testdir/manyfiles/f9: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vvaltchev/tilck/669f930ec7cf84098e9ae1ce53905696403b0a4d/tests/unit/test_sysroot/testdir/manyfiles/f9 -------------------------------------------------------------------------------- /tests/unit/tests_main.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | using namespace testing; 7 | 8 | int main(int argc, char **argv) 9 | { 10 | InitGoogleTest(&argc, argv); 11 | return RUN_ALL_TESTS(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/unit/vfs_perf.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include "vfs_test.h" 4 | 5 | using namespace std; 6 | 7 | class ramfs_perf : public vfs_test_base { 8 | 9 | protected: 10 | struct mnt_fs *mnt_fs; 11 | 12 | void SetUp() override { 13 | 14 | vfs_test_base::SetUp(); 15 | 16 | mnt_fs = ramfs_create(); 17 | ASSERT_TRUE(mnt_fs != NULL); 18 | mp_init(mnt_fs); 19 | } 20 | 21 | void TearDown() override { 22 | 23 | // TODO: destroy ramfs 24 | vfs_test_base::TearDown(); 25 | } 26 | }; 27 | 28 | 29 | static void create_test_file(int n) 30 | { 31 | char path[256]; 32 | fs_handle h; 33 | int rc; 34 | 35 | sprintf(path, "/test_%d", n); 36 | 37 | rc = vfs_open(path, &h, O_CREAT, 0644); 38 | ASSERT_EQ(rc, 0); 39 | 40 | vfs_close(h); 41 | } 42 | 43 | TEST_F(ramfs_perf, creat) 44 | { 45 | for (int i = 0; i < 100; i++) 46 | create_test_file(i); 47 | } 48 | -------------------------------------------------------------------------------- /tests/unit/vfs_test.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | 3 | #include 4 | #include "kernel_init_funcs.h" 5 | 6 | extern "C" { 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "kernel/fs/fs_int.h" 14 | } 15 | 16 | #define TEST_FATPART_FILE PROJ_BUILD_DIR "/test_fatpart" 17 | 18 | // Implemented in fat32_test.cpp 19 | const char *load_once_file(const char *filepath, size_t *fsize = nullptr); 20 | void test_dump_buf(char *buf, const char *buf_name, int off, int count); 21 | 22 | class vfs_test_base : public ::testing::Test { 23 | 24 | protected: 25 | 26 | void SetUp() override { 27 | 28 | init_kmalloc_for_tests(); 29 | } 30 | 31 | void TearDown() override { 32 | 33 | /* do nothing, for the moment */ 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /userapps/README.md: -------------------------------------------------------------------------------- 1 | 2 | Contents of this directory 3 | --------------------------- 4 | 5 | This directory contains all the user applications built with using Tilck's 6 | build system. Each application has to be explicitly added into the 7 | CMakeLists.txt file. Applications can be made by more than once C file and the 8 | pattern used by the build system is to treat all C files matching the wildcard 9 | `${APPNAME}*.c` as part of the application named `${APPNAME}`. 10 | 11 | 12 | How to run other apps on Tilck 13 | -------------------------------- 14 | 15 | If you want to test your own application on Tilck, you have two choices: 16 | 17 | 1. Make it compatible with Tilck's CMake build system and put a symlink 18 | to its root directory in `extra` [see `extra/README.md` for more]. 19 | 20 | 2. Compile it and link it *statically* using Tilck's GCC libmusl toolchain 21 | [`toolchain2/x86_gcc_toolchain`]. After that, could can just drop the 22 | executable in sysroot/usr/bin. In order to just rebuild Tilck's image, 23 | updating the sysroot, use the `make rebuild_img` command. 24 | -------------------------------------------------------------------------------- /userapps/devshell/i386.S: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | .intel_syntax noprefix 3 | 4 | .code32 5 | .text 6 | 7 | .global is_stack_aligned_16 8 | .global execute_illegal_instruction 9 | 10 | # This function checks if ESP was aligned at 16-bytes boundary *before* the 11 | # function was called. That's why we add +4 in the 2nd instruction: because 12 | # the CALL instruction pushes the EIP on the stack and that makes it unaligned 13 | # again. 14 | is_stack_aligned_16: 15 | mov eax, esp 16 | add eax, 4 17 | and eax, 0xf 18 | cmp eax, 0 19 | je .ok 20 | mov eax, 0 21 | jmp .out 22 | .ok: 23 | mov eax, 1 24 | .out: 25 | ret 26 | 27 | execute_illegal_instruction: 28 | .byte 0x0f 29 | .byte 0x0b 30 | ret # We should never get here 31 | 32 | 33 | # Tell GNU ld to not worry about us having an executable stack 34 | .section .note.GNU-stack,"",@progbits 35 | -------------------------------------------------------------------------------- /userapps/devshell/riscv64.S: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | .text 4 | 5 | .global is_stack_aligned_16 6 | .global execute_illegal_instruction 7 | 8 | # This function checks if SP was aligned at 16-bytes boundary *before* the 9 | # function was called. 10 | is_stack_aligned_16: 11 | andi a0, sp, 0xf 12 | beqz a0, .ok 13 | li a0, 0 14 | j .out 15 | .ok: 16 | li a0, 1 17 | .out: 18 | ret 19 | 20 | execute_illegal_instruction: 21 | .zero 4 22 | ret # We should never get here 23 | -------------------------------------------------------------------------------- /userapps/devshell/x86_64.S: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | .intel_syntax noprefix 3 | 4 | .code64 5 | .text 6 | 7 | .global is_stack_aligned_16 8 | .global execute_illegal_instruction 9 | 10 | # This function checks if RSP was aligned at 16-bytes boundary *before* the 11 | # function was called. That's why we add +4 in the 2nd instruction: because 12 | # the CALL instruction pushes the RIP on the stack and that makes it unaligned 13 | # again. 14 | is_stack_aligned_16: 15 | mov rax, rsp 16 | add rax, 4 17 | and rax, 0xf 18 | cmp rax, 0 19 | je .ok 20 | mov rax, 0 21 | jmp .out 22 | .ok: 23 | mov rax, 1 24 | .out: 25 | ret 26 | 27 | execute_illegal_instruction: 28 | .byte 0x0f 29 | .byte 0x0b 30 | ret # We should never get here 31 | -------------------------------------------------------------------------------- /userapps/extra/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything 2 | /* 3 | 4 | # Except two files 5 | !CMakeLists.txt 6 | !README.md 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /userapps/extra/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | cmake_minimum_required(VERSION 3.22) 3 | 4 | file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 5 | ${GLOB_CONF_DEP} 6 | ${CMAKE_CURRENT_SOURCE_DIR}/*) 7 | 8 | set(EXTRA_APPS_LIST "") 9 | 10 | foreach(child ${children}) 11 | if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child}) 12 | message(STATUS "Adding EXTRA user apps directory '${child}'") 13 | add_subdirectory(${child}) 14 | endif() 15 | endforeach() 16 | 17 | set(EXTRA_APPS_LIST ${EXTRA_APPS_LIST} PARENT_SCOPE) 18 | --------------------------------------------------------------------------------