├── .clang-format ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── help.md └── workflows │ └── build.yml ├── .gitignore ├── .idea ├── .gitignore ├── SimpleKernel.iml ├── cmake.xml ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── dictionaries │ └── SimpleKernel_dir.xml ├── encodings.xml ├── git_toolbox_prj.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── runConfigurations │ ├── kernel.xml │ ├── make_i386_iso.xml │ ├── make_x86_64_iso.xml │ ├── qemu_i386_debug.xml │ ├── qemu_riscv64_debug.xml │ └── qemu_x86_64_debug.xml ├── scopes │ └── src.xml ├── tool_settings.zip └── vcs.xml ├── .vscode ├── c_cpp_properties.json └── settings.json ├── CMakeLists.txt ├── LICENSE ├── README.md ├── README_en.md ├── cmake ├── arch_detector.cmake ├── find_asm_files.cmake ├── header_files.cmake ├── toolchain_linux_aarch64.cmake ├── toolchain_linux_riscv.cmake ├── toolchain_linux_x86_64.cmake ├── toolchain_mac_aarch64.cmake ├── toolchain_mac_riscv.cmake └── toolchain_mac_x86_64.cmake ├── docs ├── -1_参考资料汇总.md ├── 0_工具链.md ├── 1.5_cpp的初始化.md ├── 1_系统启动.md ├── 2_基本输出.md ├── 3_解析启动信息.md ├── 4_物理内存管理.md ├── 5_虚拟内存管理.md ├── 64-ia-32-architectures-software-developer-vol-1-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-2a-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-2b-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-2c-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-2d-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-3a-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-3b-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-3c-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-3d-manual.pdf ├── 64-ia-32-architectures-software-developer-vol-4-manual.pdf ├── 6_堆管理.md ├── 7_c++stl的支持.md ├── 8_中断.md ├── An Introduction to the RISC-V Architecture.pdf ├── Multiboot2 Specification version 2.0.pdf ├── README.md ├── RISC-V-Reader-Chinese-v2p1.pdf ├── UEFI_Spec_2_10_Aug29.pdf ├── devicetree-specification-v0.3.pdf ├── riscv-mmu.pdf ├── riscv-privileged-spec-v1.7中文版.pdf ├── riscv-privileged.pdf ├── riscv-spec-20191213.pdf ├── sifive-interrupt-cookbook.pdf └── virtio-v1.1.pdf ├── run.sh ├── src ├── CMakeLists.txt ├── arch │ ├── CMakeLists.txt │ ├── aarch64 │ │ ├── CMakeLists.txt │ │ ├── boot │ │ │ └── boot.S │ │ ├── hardware.h │ │ ├── link.ld │ │ └── port │ │ │ ├── include │ │ │ └── port.h │ │ │ └── port.cpp │ ├── ia32 │ │ ├── CMakeLists.txt │ │ ├── apic │ │ │ ├── apic.cpp │ │ │ ├── include │ │ │ │ └── apic.h │ │ │ ├── io_apic.cpp │ │ │ └── local_apic.cpp │ │ ├── cpu.hpp │ │ ├── e820.h │ │ ├── i386 │ │ │ ├── boot │ │ │ │ └── boot.S │ │ │ ├── gdt │ │ │ │ ├── gdt.cpp │ │ │ │ ├── gdt_s.S │ │ │ │ └── include │ │ │ │ │ └── gdt.h │ │ │ ├── intr │ │ │ │ ├── include │ │ │ │ │ └── intr.h │ │ │ │ ├── intr.cpp │ │ │ │ ├── intr_s.S │ │ │ │ └── timer.cpp │ │ │ └── link.ld │ │ ├── port │ │ │ ├── include │ │ │ │ └── port.h │ │ │ └── port.cpp │ │ └── x86_64 │ │ │ ├── boot │ │ │ └── boot.S │ │ │ ├── gdt │ │ │ ├── gdt.cpp │ │ │ ├── gdt_s.S │ │ │ └── include │ │ │ │ └── gdt.h │ │ │ ├── intr │ │ │ ├── include │ │ │ │ └── intr.h │ │ │ ├── intr.cpp │ │ │ ├── intr_s.S │ │ │ └── timer.cpp │ │ │ └── link.ld │ └── riscv64 │ │ ├── CMakeLists.txt │ │ ├── boot │ │ └── boot.S │ │ ├── context.S │ │ ├── cpu.hpp │ │ ├── intr │ │ ├── clint.cpp │ │ ├── include │ │ │ └── intr.h │ │ ├── intr.cpp │ │ ├── intr_s.S │ │ ├── page_fault.cpp │ │ ├── plic.cpp │ │ └── timer.cpp │ │ └── link.ld ├── drv │ ├── CMakeLists.txt │ ├── dtb │ │ ├── dtb.cpp │ │ └── include │ │ │ └── dtb.h │ ├── keyboard │ │ ├── include │ │ │ └── keyboard.h │ │ └── keyboard.cpp │ ├── multiboot2 │ │ ├── include │ │ │ └── multiboot2.h │ │ └── multiboot2.cpp │ ├── opensbi │ │ ├── include │ │ │ └── opensbi.h │ │ └── opensbi.cpp │ ├── sbi_console │ │ ├── include │ │ │ └── sbi_console.h │ │ └── sbi_console.cpp │ ├── tui │ │ ├── include │ │ │ └── tui.h │ │ └── tui.cpp │ └── uart │ │ ├── include │ │ └── uart.h │ │ └── uart.cpp ├── include │ ├── boot_info.h │ ├── color.h │ ├── common.h │ ├── io.h │ ├── mem │ │ ├── allocator.h │ │ ├── firstfit.h │ │ ├── heap.h │ │ ├── pmm.h │ │ ├── slab.h │ │ └── vmm.h │ └── resource.h ├── kernel │ ├── CMakeLists.txt │ ├── allocator.cpp │ ├── firstfit.cpp │ ├── heap.cpp │ ├── include │ │ └── kernel.h │ ├── io.cpp │ ├── kernel_main.cpp │ ├── pmm.cpp │ ├── slab.cpp │ ├── test.cpp │ └── vmm.cpp ├── libc │ ├── CMakeLists.txt │ ├── include │ │ ├── assert.h │ │ ├── ctype.h │ │ ├── endian.h │ │ ├── float.h │ │ ├── limits.h │ │ ├── math.h │ │ ├── stdarg.h │ │ ├── stdbool.h │ │ ├── stddef.h │ │ ├── stdint.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.h │ │ └── time.h │ └── src │ │ ├── math │ │ └── math.c │ │ ├── stdio │ │ └── vsprintf.c │ │ ├── stdlib │ │ ├── atoi.c │ │ ├── itoa.c │ │ └── strtol.c │ │ └── string │ │ └── string.c └── libcxx │ ├── CMakeLists.txt │ ├── include │ ├── algo │ ├── algobase │ ├── algorithm │ ├── allocator │ ├── astring │ ├── basic_string │ ├── cassert │ ├── cfloat │ ├── climits │ ├── cmath │ ├── construct │ ├── cstdarg │ ├── cstdbool │ ├── cstddef │ ├── cstdint │ ├── cstdio │ ├── cstdlib │ ├── cstring │ ├── ctype │ ├── cxxabi.h │ ├── deque │ ├── exceptdef │ ├── functional │ ├── hashtable │ ├── heap_algo │ ├── initializer_list │ ├── iostream │ ├── iterator │ ├── list │ ├── map │ ├── memory │ ├── new │ ├── numeric │ ├── queue │ ├── rb_tree │ ├── set │ ├── set_algo │ ├── stack │ ├── string │ ├── type_traits │ ├── type_traits.h │ ├── uninitialized │ ├── unordered_map │ ├── unordered_set │ ├── util │ └── vector │ └── src │ ├── __dso_handle.S │ ├── cxxabi.cpp │ ├── iostream.cpp │ ├── new.cpp │ └── stack_chk.cpp └── tools ├── .Clion_usage.assets ├── 2022-01-16 22.41.38.png ├── 2022-01-16 22.42.21.png ├── 2022-01-16 22.42.56.png ├── 2022-01-16 22.44.30.png ├── 2022-01-16 22.45.14.png ├── 2022-01-16 22.48.24.png ├── 2022-01-16 22.52.00.png ├── 2022-01-16 22.54.02.png ├── 2022-01-16 22.56.43.png ├── 2022-01-17 16.29.12.png ├── 2022-01-22 19.49.01.png ├── 2022-01-22 19.49.07.png ├── 2022-01-22 19.53.12.png ├── 2022-01-22 19.53.34-2852427.png ├── 2022-01-22 19.53.34.png ├── 2022-01-22 19.54.15.png ├── 2022-01-22 19.55.16.png ├── 2022-01-22 19.56.23.png ├── 2022-01-22 19.56.31.png ├── 2022-01-22 19.57.31.png └── 2022-01-22 19.58.14.png ├── Clion 使用说明.md ├── Git Commit 规范.pdf ├── READMD.md ├── env.sh ├── gdbinit ├── grub.cfg ├── grub4mac.sh ├── install.sh ├── opensbi ├── .clang-format ├── .gitignore ├── CONTRIBUTORS.md ├── COPYING.BSD ├── Kconfig ├── Makefile ├── README.md ├── ThirdPartyNotices.md ├── docs │ ├── contributing.md │ ├── domain_support.md │ ├── doxygen.cfg │ ├── external │ │ └── coreboot.md │ ├── firmware │ │ ├── fw.md │ │ ├── fw_dynamic.md │ │ ├── fw_jump.md │ │ ├── fw_payload.md │ │ ├── payload_linux.md │ │ └── payload_uboot.md │ ├── library_usage.md │ ├── platform │ │ ├── andes-ae350.md │ │ ├── fpga-ariane.md │ │ ├── fpga-openpiton.md │ │ ├── generic.md │ │ ├── nuclei_ux600.md │ │ ├── platform.md │ │ ├── qemu_virt.md │ │ ├── renesas-rzfive.md │ │ ├── shakti_cclass.md │ │ ├── sifive_fu540.md │ │ ├── spike.md │ │ └── thead-c9xx.md │ ├── platform_guide.md │ ├── platform_requirements.md │ └── pmu_support.md ├── firmware │ ├── Kconfig │ ├── external_deps.mk │ ├── fw_base.S │ ├── fw_base.ldS │ ├── fw_dynamic.S │ ├── fw_dynamic.elf.ldS │ ├── fw_jump.S │ ├── fw_jump.elf.ldS │ ├── fw_payload.S │ ├── fw_payload.elf.ldS │ ├── objects.mk │ └── payloads │ │ ├── objects.mk │ │ ├── test.elf.ldS │ │ ├── test_head.S │ │ └── test_main.c ├── include │ ├── sbi │ │ ├── fw_dynamic.h │ │ ├── riscv_asm.h │ │ ├── riscv_atomic.h │ │ ├── riscv_barrier.h │ │ ├── riscv_elf.h │ │ ├── riscv_encoding.h │ │ ├── riscv_fp.h │ │ ├── riscv_io.h │ │ ├── riscv_locks.h │ │ ├── sbi_bitmap.h │ │ ├── sbi_bitops.h │ │ ├── sbi_console.h │ │ ├── sbi_const.h │ │ ├── sbi_csr_detect.h │ │ ├── sbi_domain.h │ │ ├── sbi_ecall.h │ │ ├── sbi_ecall_interface.h │ │ ├── sbi_emulate_csr.h │ │ ├── sbi_error.h │ │ ├── sbi_fifo.h │ │ ├── sbi_hart.h │ │ ├── sbi_hartmask.h │ │ ├── sbi_hfence.h │ │ ├── sbi_hsm.h │ │ ├── sbi_illegal_insn.h │ │ ├── sbi_init.h │ │ ├── sbi_ipi.h │ │ ├── sbi_irqchip.h │ │ ├── sbi_list.h │ │ ├── sbi_math.h │ │ ├── sbi_misaligned_ldst.h │ │ ├── sbi_platform.h │ │ ├── sbi_pmu.h │ │ ├── sbi_scratch.h │ │ ├── sbi_string.h │ │ ├── sbi_system.h │ │ ├── sbi_timer.h │ │ ├── sbi_tlb.h │ │ ├── sbi_trap.h │ │ ├── sbi_types.h │ │ ├── sbi_unpriv.h │ │ └── sbi_version.h │ └── sbi_utils │ │ ├── fdt │ │ ├── fdt_domain.h │ │ ├── fdt_fixup.h │ │ ├── fdt_helper.h │ │ └── fdt_pmu.h │ │ ├── gpio │ │ ├── fdt_gpio.h │ │ └── gpio.h │ │ ├── i2c │ │ ├── fdt_i2c.h │ │ └── i2c.h │ │ ├── ipi │ │ ├── aclint_mswi.h │ │ ├── andes_plicsw.h │ │ └── fdt_ipi.h │ │ ├── irqchip │ │ ├── aplic.h │ │ ├── fdt_irqchip.h │ │ ├── fdt_irqchip_plic.h │ │ ├── imsic.h │ │ └── plic.h │ │ ├── reset │ │ └── fdt_reset.h │ │ ├── serial │ │ ├── cadence-uart.h │ │ ├── fdt_serial.h │ │ ├── gaisler-uart.h │ │ ├── litex-uart.h │ │ ├── renesas-scif.h │ │ ├── semihosting.h │ │ ├── shakti-uart.h │ │ ├── sifive-uart.h │ │ ├── uart8250.h │ │ └── xlnx_uartlite.h │ │ ├── sys │ │ ├── htif.h │ │ └── sifive_test.h │ │ └── timer │ │ ├── aclint_mtimer.h │ │ ├── andes_plmt.h │ │ └── fdt_timer.h ├── lib │ ├── sbi │ │ ├── Kconfig │ │ ├── objects.mk │ │ ├── riscv_asm.c │ │ ├── riscv_atomic.c │ │ ├── riscv_hardfp.S │ │ ├── riscv_locks.c │ │ ├── sbi_bitmap.c │ │ ├── sbi_bitops.c │ │ ├── sbi_console.c │ │ ├── sbi_domain.c │ │ ├── sbi_ecall.c │ │ ├── sbi_ecall_base.c │ │ ├── sbi_ecall_exts.carray │ │ ├── sbi_ecall_hsm.c │ │ ├── sbi_ecall_ipi.c │ │ ├── sbi_ecall_legacy.c │ │ ├── sbi_ecall_pmu.c │ │ ├── sbi_ecall_rfence.c │ │ ├── sbi_ecall_srst.c │ │ ├── sbi_ecall_time.c │ │ ├── sbi_ecall_vendor.c │ │ ├── sbi_emulate_csr.c │ │ ├── sbi_expected_trap.S │ │ ├── sbi_fifo.c │ │ ├── sbi_hart.c │ │ ├── sbi_hfence.S │ │ ├── sbi_hsm.c │ │ ├── sbi_illegal_insn.c │ │ ├── sbi_init.c │ │ ├── sbi_ipi.c │ │ ├── sbi_irqchip.c │ │ ├── sbi_math.c │ │ ├── sbi_misaligned_ldst.c │ │ ├── sbi_platform.c │ │ ├── sbi_pmu.c │ │ ├── sbi_scratch.c │ │ ├── sbi_string.c │ │ ├── sbi_system.c │ │ ├── sbi_timer.c │ │ ├── sbi_tlb.c │ │ ├── sbi_trap.c │ │ └── sbi_unpriv.c │ └── utils │ │ ├── Kconfig │ │ ├── fdt │ │ ├── Kconfig │ │ ├── fdt_domain.c │ │ ├── fdt_fixup.c │ │ ├── fdt_helper.c │ │ ├── fdt_pmu.c │ │ └── objects.mk │ │ ├── gpio │ │ ├── Kconfig │ │ ├── fdt_gpio.c │ │ ├── fdt_gpio_drivers.carray │ │ ├── fdt_gpio_sifive.c │ │ ├── gpio.c │ │ └── objects.mk │ │ ├── i2c │ │ ├── Kconfig │ │ ├── fdt_i2c.c │ │ ├── fdt_i2c_adapter_drivers.carray │ │ ├── fdt_i2c_sifive.c │ │ ├── i2c.c │ │ └── objects.mk │ │ ├── ipi │ │ ├── Kconfig │ │ ├── aclint_mswi.c │ │ ├── andes_plicsw.c │ │ ├── fdt_ipi.c │ │ ├── fdt_ipi_drivers.carray │ │ ├── fdt_ipi_mswi.c │ │ ├── fdt_ipi_plicsw.c │ │ └── objects.mk │ │ ├── irqchip │ │ ├── Kconfig │ │ ├── aplic.c │ │ ├── fdt_irqchip.c │ │ ├── fdt_irqchip_aplic.c │ │ ├── fdt_irqchip_drivers.carray │ │ ├── fdt_irqchip_imsic.c │ │ ├── fdt_irqchip_plic.c │ │ ├── imsic.c │ │ ├── objects.mk │ │ └── plic.c │ │ ├── libfdt │ │ ├── .clang-format │ │ ├── Kconfig │ │ ├── Makefile.libfdt │ │ ├── TODO │ │ ├── fdt.c │ │ ├── fdt.h │ │ ├── fdt_addresses.c │ │ ├── fdt_check.c │ │ ├── fdt_empty_tree.c │ │ ├── fdt_overlay.c │ │ ├── fdt_ro.c │ │ ├── fdt_rw.c │ │ ├── fdt_strerror.c │ │ ├── fdt_sw.c │ │ ├── fdt_wip.c │ │ ├── libfdt.h │ │ ├── libfdt_env.h │ │ ├── libfdt_internal.h │ │ ├── objects.mk │ │ └── version.lds │ │ ├── libquad │ │ ├── divdi3.c │ │ ├── include │ │ │ ├── limits.h │ │ │ └── sys │ │ │ │ ├── cdefs.h │ │ │ │ └── types.h │ │ ├── moddi3.c │ │ ├── objects.mk │ │ ├── qdivrem.c │ │ ├── quad.h │ │ ├── udivdi3.c │ │ └── umoddi3.c │ │ ├── reset │ │ ├── Kconfig │ │ ├── fdt_reset.c │ │ ├── fdt_reset_atcwdt200.c │ │ ├── fdt_reset_drivers.carray │ │ ├── fdt_reset_gpio.c │ │ ├── fdt_reset_htif.c │ │ ├── fdt_reset_sifive_test.c │ │ ├── fdt_reset_sunxi_wdt.c │ │ ├── fdt_reset_thead.c │ │ ├── fdt_reset_thead.h │ │ ├── fdt_reset_thead_asm.S │ │ └── objects.mk │ │ ├── serial │ │ ├── Kconfig │ │ ├── cadence-uart.c │ │ ├── fdt_serial.c │ │ ├── fdt_serial_cadence.c │ │ ├── fdt_serial_drivers.carray │ │ ├── fdt_serial_gaisler.c │ │ ├── fdt_serial_htif.c │ │ ├── fdt_serial_litex.c │ │ ├── fdt_serial_renesas_scif.c │ │ ├── fdt_serial_shakti.c │ │ ├── fdt_serial_sifive.c │ │ ├── fdt_serial_uart8250.c │ │ ├── fdt_serial_xlnx_uartlite.c │ │ ├── gaisler-uart.c │ │ ├── litex-uart.c │ │ ├── objects.mk │ │ ├── renesas_scif.c │ │ ├── semihosting.c │ │ ├── shakti-uart.c │ │ ├── sifive-uart.c │ │ ├── uart8250.c │ │ └── xlnx-uartlite.c │ │ ├── sys │ │ ├── Kconfig │ │ ├── htif.c │ │ ├── objects.mk │ │ └── sifive_test.c │ │ └── timer │ │ ├── Kconfig │ │ ├── aclint_mtimer.c │ │ ├── andes_plmt.c │ │ ├── fdt_timer.c │ │ ├── fdt_timer_drivers.carray │ │ ├── fdt_timer_mtimer.c │ │ ├── fdt_timer_plmt.c │ │ └── objects.mk ├── platform │ ├── fpga │ │ ├── ariane │ │ │ ├── Kconfig │ │ │ ├── configs │ │ │ │ └── defconfig │ │ │ ├── objects.mk │ │ │ └── platform.c │ │ └── openpiton │ │ │ ├── Kconfig │ │ │ ├── configs │ │ │ └── defconfig │ │ │ ├── objects.mk │ │ │ └── platform.c │ ├── generic │ │ ├── Kconfig │ │ ├── allwinner │ │ │ ├── objects.mk │ │ │ └── sun20i-d1.c │ │ ├── andes │ │ │ ├── ae350.c │ │ │ └── objects.mk │ │ ├── configs │ │ │ └── defconfig │ │ ├── include │ │ │ ├── platform_override.h │ │ │ └── thead_c9xx.h │ │ ├── objects.mk │ │ ├── platform.c │ │ ├── platform_override_modules.carray │ │ ├── renesas │ │ │ └── rzfive │ │ │ │ ├── objects.mk │ │ │ │ └── rzfive.c │ │ └── sifive │ │ │ ├── fu540.c │ │ │ ├── fu740.c │ │ │ └── objects.mk │ ├── kendryte │ │ └── k210 │ │ │ ├── Kconfig │ │ │ ├── configs │ │ │ └── defconfig │ │ │ ├── k210.dts │ │ │ ├── objects.mk │ │ │ ├── platform.c │ │ │ └── platform.h │ ├── nuclei │ │ └── ux600 │ │ │ ├── Kconfig │ │ │ ├── configs │ │ │ └── defconfig │ │ │ ├── objects.mk │ │ │ └── platform.c │ └── template │ │ ├── Kconfig │ │ ├── configs │ │ └── defconfig │ │ ├── objects.mk │ │ └── platform.c └── scripts │ ├── Kconfiglib │ ├── LICENSE.txt │ ├── allnoconfig.py │ ├── allyesconfig.py │ ├── defconfig.py │ ├── genconfig.py │ ├── kconfiglib.py │ ├── menuconfig.py │ ├── oldconfig.py │ ├── olddefconfig.py │ ├── savedefconfig.py │ └── setconfig.py │ ├── carray.sh │ ├── create-binary-archive.sh │ └── d2c.sh ├── riscv64_qemu_virt.dts ├── setup_x86_64_mac.sh ├── x86_64-elf-binutils.sh └── x86_64-elf-gcc.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel (https://github.com/Simple-XX/SimpleKernel). 3 | # 4 | # FUNDING.yml for Simple-XX/SimpleKernel. 5 | 6 | # These are supported funding model platforms 7 | 8 | github: ['Simple-XX'] 9 | patreon: # Replace with a single Patreon username 10 | open_collective: # Replace with a single Open Collective username 11 | ko_fi: # Replace with a single Ko-fi username 12 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 13 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 14 | liberapay: # Replace with a single Liberapay username 15 | issuehunt: # Replace with a single IssueHunt username 16 | otechie: # Replace with a single Otechie username 17 | custom: ['https://tva1.sinaimg.cn/large/006tNbRwly1g9yjfoboa4j30go0p0411.jpg', 'https://tva1.sinaimg.cn/large/006tNbRwly1g9yjg7p0auj30u014qn7q.jpg'] 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Env (please complete the following information):** 27 | - OS: [e.g. MacOS 10.14.2] 28 | - Compile tools: [e.g. i386-elf-gcc i386-elf-ld] 29 | - Emulator: [e.g. Bochs 2.6.9] 30 | - Branch: [e.g. TODO] 31 | - Any modifications to tools/env.sh: 32 | 33 | **Additional context** 34 | Add any other context about the problem here. 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature request 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 | [Optional] A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | [Optional] 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 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/help.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Help 3 | about: any questions 4 | title: "[HELP]" 5 | labels: help wanted 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Env (please complete the following information):** 11 | - OS: [e.g. MacOS 10.14.2] 12 | - Compile tools: [e.g. i386-elf-gcc i386-elf-ld] 13 | - Emulator: [e.g. Bochs 2.6.9] 14 | - Branch: [e.g. TODO] 15 | - Any modifications to tools/env.sh: 16 | 17 | **Describe your question** 18 | A clear and concise description of what the question is. 19 | 20 | **Additional context** 21 | Add any other context about the problem here. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # .gitinnore for Simple-XX/SimpleKernel. 6 | 7 | *.o 8 | *.gch 9 | *.tags* 10 | .DS_Store 11 | build* 12 | grub-2.04.tar.xz 13 | grub-2.04 14 | tools/opensbi 15 | iso 16 | *.img 17 | *.iso 18 | *.bin 19 | null.d 20 | tools/aarch64-unknown-linux-gnu* 21 | .gdbinit 22 | tools/opensbi/build 23 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/SimpleKernel.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.idea/cmake.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/dictionaries/SimpleKernel_dir.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | bochsrc 5 | corei 6 | imafdc 7 | lriscv 8 | opensbi 9 | readelf 10 | simplekernel 11 | syms 12 | xlen 13 | xorriso 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/git_toolbox_prj.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/runConfigurations/kernel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/runConfigurations/make_i386_iso.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | -------------------------------------------------------------------------------- /.idea/runConfigurations/make_x86_64_iso.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | -------------------------------------------------------------------------------- /.idea/runConfigurations/qemu_i386_debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/runConfigurations/qemu_riscv64_debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/runConfigurations/qemu_x86_64_debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/scopes/src.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/tool_settings.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/.idea/tool_settings.zip -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "SimpleKernel_vscode_cpp", 5 | "includePath": [ 6 | "${workspaceFolder}/src/**" 7 | ], 8 | "cStandard": "gnu17", 9 | "cppStandard": "gnu++17" 10 | } 11 | ], 12 | "version": 4 13 | } -------------------------------------------------------------------------------- /cmake/arch_detector.cmake: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # Based on https://github.com/SynestiaOS/SynestiaOS 5 | # CMakeLists.txt for Simple-XX/SimpleKernel. 6 | # 对 shell 传入的 ARCH 参数进行处理 7 | 8 | # TODO: 优化 CMake 流程,环境搭建由自动脚本实现 9 | 10 | # 如果 ARCH 为 i386 或 x86_64,统一添加 ia32 前缀 11 | if (ARCH STREQUAL i386) 12 | set(SimpleKernelArch ia32/i386) 13 | elseif (ARCH STREQUAL x86_64) 14 | set(SimpleKernelArch ia32/x86_64) 15 | # 其它情况不变 16 | elseif (ARCH STREQUAL aarch64) 17 | set(SimpleKernelArch aarch64) 18 | elseif (ARCH STREQUAL riscv64) 19 | set(SimpleKernelArch riscv64) 20 | else () 21 | # 不支持的 ARCH 22 | message(WARNING "unexpected ARCH: ${ARCH}, using default value \"riscv64\"") 23 | # 默认设为 riscv64 24 | set(SimpleKernelArch riscv64) 25 | endif () 26 | 27 | # 输出 SimpleKernelArch 28 | message(STATUS "SimpleKernelArch is ${SimpleKernelArch}") 29 | -------------------------------------------------------------------------------- /cmake/find_asm_files.cmake: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # Based on https://github.com/SynestiaOS/SynestiaOS 5 | # CMakeLists.txt for Simple-XX/SimpleKernel. 6 | # 在 Directory 目录下寻找 .s/.S 格式的文件,并添加到 OutValue 中 7 | 8 | macro(find_asm_source_files OutValue Directory) 9 | file(GLOB ${OutValue} LIST_DIRECTORIES false ${Directory}/*.[sS]) 10 | message(STATUS "found asm files: ${${OutValue}}") 11 | endmacro() 12 | -------------------------------------------------------------------------------- /cmake/toolchain_linux_aarch64.cmake: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # toolchain_linux_aarch64.cmake for Simple-XX/SimpleKernel. 6 | 7 | set(CMAKE_SYSTEM_NAME Linux) 8 | set(CMAKE_SYSTEM_VERSION 1) 9 | set(CMAKE_SYSTEM_PROCESSOR AARCH64) 10 | 11 | # TODO 12 | # GCC 13 | find_program(GCC aarch64-none-eabi-gcc) 14 | if (NOT GCC) 15 | message(FATAL_ERROR "gcc-aarch64-linux-gnu not found.\n" 16 | "Run `sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu` to install.") 17 | else () 18 | message(STATUS "Found gcc-aarch64-linux-gnu ${GCC}") 19 | endif () 20 | 21 | set(TOOLCHAIN_PREFIX aarch64-linux-gnu-) 22 | set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) 23 | set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) 24 | set(CMAKE_READELF ${TOOLCHAIN_PREFIX}readelf) 25 | set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar) 26 | set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld) 27 | set(CMAKE_NM ${TOOLCHAIN_PREFIX}nm) 28 | set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump) 29 | set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib) 30 | 31 | # qemu 32 | find_program(QEMU qemu-system-aarch64) 33 | if (NOT QEMU) 34 | message(FATAL_ERROR "qemu not found.\n" 35 | "Run `sudo apt-get install -y qemu-system` to install.") 36 | else () 37 | message(STATUS "Found qemu ${QEMU}") 38 | endif () 39 | -------------------------------------------------------------------------------- /cmake/toolchain_linux_riscv.cmake: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # toolchain_linux_riscv.cmake for Simple-XX/SimpleKernel. 6 | 7 | set(CMAKE_SYSTEM_NAME Linux) 8 | set(CMAKE_SYSTEM_VERSION 1) 9 | set(CMAKE_SYSTEM_PROCESSOR RISCV) 10 | 11 | # GCC 12 | find_program(RISCV riscv64-linux-gnu-g++) 13 | if (NOT RISCV) 14 | message(FATAL_ERROR "riscv64-linux-gnu-gcc not found.\n" 15 | "Run `sudo apt-get install -y gcc-riscv64-linux-gnu g++-riscv64-linux-gnu` to install.") 16 | else () 17 | message(STATUS "Found riscv64-linux-gnu-gcc ${RISCV}.") 18 | endif () 19 | 20 | set(TOOLCHAIN_PREFIX riscv64-linux-gnu-) 21 | set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) 22 | set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) 23 | set(CMAKE_READELF ${TOOLCHAIN_PREFIX}readelf) 24 | set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar) 25 | set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld) 26 | set(CMAKE_NM ${TOOLCHAIN_PREFIX}nm) 27 | set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump) 28 | set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib) 29 | 30 | # qemu 31 | find_program(QEMU qemu-system-riscv64) 32 | if (NOT QEMU) 33 | message(FATAL_ERROR "qemu not found.\n" 34 | "Run `sudo apt-get install -y qemu-system` to install.") 35 | else () 36 | message(STATUS "Found qemu ${QEMU}") 37 | endif () 38 | -------------------------------------------------------------------------------- /cmake/toolchain_linux_x86_64.cmake: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # toolchain_linux_x86_64.cmake for Simple-XX/SimpleKernel. 6 | 7 | set(CMAKE_SYSTEM_NAME Linux) 8 | set(CMAKE_SYSTEM_VERSION 1) 9 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 10 | 11 | # GCC 12 | find_program(G++ g++) 13 | if (NOT G++) 14 | message(FATAL_ERROR "g++ not found.\n" 15 | "Run `sudo apt-get install -y gcc g++` to install.") 16 | else () 17 | message(STATUS "Found g++ ${G++}") 18 | endif () 19 | 20 | # xorriso 21 | find_program(XORRISO xorriso) 22 | if (NOT XORRISO) 23 | message(FATAL_ERROR "xorriso not found.\n" 24 | "Run `sudo apt-get install -y xorriso` to install.") 25 | else () 26 | message(STATUS "Found xorriso ${XORRISO}") 27 | endif () 28 | 29 | # GRUB 30 | find_program(GRUB grub-file) 31 | if (NOT GRUB) 32 | message(FATAL_ERROR "grub-file not found.\n" 33 | "Run `sudo apt-get install -y grub2` to install.") 34 | else () 35 | message(STATUS "Found grub-file ${GRUB}") 36 | endif () 37 | 38 | # qemu 39 | find_program(QEMU qemu-system-x86_64) 40 | if (NOT QEMU) 41 | message(FATAL_ERROR "qemu not found.\n" 42 | "Run `sudo apt-get install -y qemu-system` to install.") 43 | else () 44 | message(STATUS "Found qemu ${QEMU}") 45 | endif () 46 | -------------------------------------------------------------------------------- /docs/-1_参考资料汇总.md: -------------------------------------------------------------------------------- 1 | # SimpleKernel 参考资料汇总 2 | 3 | 关于交叉编译的一些说明:https://wiki.osdev.org/GCC_Cross-Compiler 4 | 5 | arm 工具链:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads 6 | 7 | riscv 工具链:https://github.com/riscv/riscv-gnu-toolchain 8 | 9 | GCC 安装: https://gcc.gnu.org/install/ 10 | 11 | i386 的启动代码:https://wiki.osdev.org/Bare_Bones 12 | 13 | grub:https://www.gnu.org/software/grub/manual/grub/grub.html 14 | 15 | multiboot2 规范:https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html 16 | 17 | opensbi:https://github.com/riscv/opensbi 18 | 19 | c++ 的使用:https://wiki.osdev.org/C++ 20 | 21 | 如何对全局对象进行构造:https://wiki.osdev.org/Calling_Global_Constructors 22 | 23 | c++ abi 支持:https://wiki.osdev.org/C%2B%2B_Exception_Support 24 | 25 | gcc 内嵌汇编:https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html 26 | 27 | IA32 prots:https://wiki.osdev.org/I/O_Ports 28 | 29 | IA32 VGA:https://wiki.osdev.org/VGA_Hardware 30 | 31 | IA32 text ui:https://wiki.osdev.org/Text_UI 32 | 33 | IA32 text 模式的光标:https://wiki.osdev.org/Text_Mode_Cursor 34 | 35 | IA32 text 模式在屏幕上输出:https://wiki.osdev.org/Printing_To_Screen 36 | 37 | device-tree:https://github.com/devicetree-org/devicetree-specification 38 | 39 | dtb解析0: https://e-mailky.github.io/2016-12-06-dts-introduce 40 | 41 | dtb解析1: https://e-mailky.github.io/2019-01-14-dts-1 42 | 43 | dtb解析2: https://e-mailky.github.io/2019-01-14-dts-2 44 | 45 | dtb解析3: https://e-mailky.github.io/2019-01-14-dts-3 46 | -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-1-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-1-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-2a-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-2a-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-2b-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-2b-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-2c-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-2c-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-2d-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-2d-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-3a-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-3a-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-3b-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-3b-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-3c-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-3c-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-3d-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-3d-manual.pdf -------------------------------------------------------------------------------- /docs/64-ia-32-architectures-software-developer-vol-4-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/64-ia-32-architectures-software-developer-vol-4-manual.pdf -------------------------------------------------------------------------------- /docs/7_c++stl的支持.md: -------------------------------------------------------------------------------- 1 | # SimpleKernel c++ stl 的支持 2 | 3 | C++ 的标准模版库(STL) 非常强大,这里我们只使用了部分,使用了 [Alinshans/MyTinySTL](https://github.com/Alinshans/MyTinySTL) 的实现。 4 | 5 | - 相关代码 6 | 7 | ./src/libcxx/include/* 8 | -------------------------------------------------------------------------------- /docs/An Introduction to the RISC-V Architecture.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/An Introduction to the RISC-V Architecture.pdf -------------------------------------------------------------------------------- /docs/Multiboot2 Specification version 2.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/Multiboot2 Specification version 2.0.pdf -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # SimpleKerenl's Doc 2 | 3 | TODO 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /docs/RISC-V-Reader-Chinese-v2p1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/RISC-V-Reader-Chinese-v2p1.pdf -------------------------------------------------------------------------------- /docs/UEFI_Spec_2_10_Aug29.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/UEFI_Spec_2_10_Aug29.pdf -------------------------------------------------------------------------------- /docs/devicetree-specification-v0.3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/devicetree-specification-v0.3.pdf -------------------------------------------------------------------------------- /docs/riscv-mmu.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/riscv-mmu.pdf -------------------------------------------------------------------------------- /docs/riscv-privileged-spec-v1.7中文版.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/riscv-privileged-spec-v1.7中文版.pdf -------------------------------------------------------------------------------- /docs/riscv-privileged.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/riscv-privileged.pdf -------------------------------------------------------------------------------- /docs/riscv-spec-20191213.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/riscv-spec-20191213.pdf -------------------------------------------------------------------------------- /docs/sifive-interrupt-cookbook.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/sifive-interrupt-cookbook.pdf -------------------------------------------------------------------------------- /docs/virtio-v1.1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/docs/virtio-v1.1.pdf -------------------------------------------------------------------------------- /src/arch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # CMakeLists.txt for Simple-XX/SimpleKernel. 6 | # 根据 SimpleKernelArch 判断跳转到哪个目录 7 | 8 | # 如果是 ia32/i386 或 ia32/x86_64,跳转到 ia32 目录 9 | if (SimpleKernelArch STREQUAL "ia32/i386" OR SimpleKernelArch STREQUAL "ia32/x86_64") 10 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ia32) 11 | else () 12 | # 其它情况跳转到与 SimpleKernelArch 同名目录即可 13 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${SimpleKernelArch}) 14 | endif () 15 | -------------------------------------------------------------------------------- /src/arch/aarch64/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # CMakeLists.txt for Simple-XX/SimpleKernel. 6 | 7 | PROJECT(arch ASM) 8 | 9 | find_asm_source_files(boot_asm_src ${arch_SOURCE_DIR}/boot) 10 | set(boot_src ${boot_asm_src}) 11 | 12 | set(arch_src ${boot_src}) 13 | 14 | add_library(${PROJECT_NAME} OBJECT ${arch_src}) 15 | -------------------------------------------------------------------------------- /src/arch/aarch64/boot/boot.S: -------------------------------------------------------------------------------- 1 | 2 | // This file is a part of Simple-XX/SimpleKernel 3 | // (https://github.com/Simple-XX/SimpleKernel). 4 | // Based on https://wiki.osdev.org/Raspberry_Pi_Bare_Bones 5 | // boot.S for Simple-XX/SimpleKernel. 6 | 7 | // clang-format off 8 | 9 | .section .init 10 | 11 | // Entry point for the kernel. 12 | // r15 -> should begin execution at 0x8000. 13 | // r0 -> 0x00000000 14 | // r1 -> 0x00000C42 - machine id 15 | // r2 -> 0x00000100 - start of ATAGS 16 | // preserve these registers as argument for kernel_main 17 | .global _start 18 | .type _start, @function 19 | .extern kernel_main 20 | // 规定起始地址 21 | .org 0x8000 22 | _start: 23 | // 设置栈 24 | ldr x5, =_start 25 | mov sp, x5 26 | // 进入 kernel_main 27 | bl kernel_main 28 | 29 | // halt 30 | halt: 31 | wfe 32 | b halt 33 | -------------------------------------------------------------------------------- /src/arch/aarch64/link.ld: -------------------------------------------------------------------------------- 1 | 2 | /* This file is a part of Simple-XX/SimpleKernel 3 | * (https://github.com/Simple-XX/SimpleKernel). 4 | * 5 | * link.ld for Simple-XX/SimpleKernel. 6 | * 链接脚本,指定生成的二进制文件的布局 7 | */ 8 | 9 | OUTPUT_FORMAT(elf64-littleaarch64) 10 | 11 | ENTRY(_start) 12 | 13 | SECTIONS 14 | { 15 | /* 加载地址 */ 16 | . = 0x8000; 17 | 18 | kernel_start = .; 19 | kernel_text_start = .; 20 | .text : ALIGN(4K) 21 | { 22 | *.(.text.init) 23 | *(.text) 24 | } 25 | kernel_text_end = .; 26 | 27 | kernel_rodata_start = .; 28 | .rodata : ALIGN(4K) 29 | { 30 | *(.rodata) 31 | } 32 | kernel_rodata_end = .; 33 | 34 | kernel_data_start = .; 35 | .data : ALIGN(4K) 36 | { 37 | ctors_start = .; 38 | *(.ctor*) 39 | ctors_end = .; 40 | dtors_start = .; 41 | *(.dtor*) 42 | dtors_end = .; 43 | *(.data) 44 | } 45 | kernel_data_end = .; 46 | 47 | kernel_bss_start = .; 48 | .bss : ALIGN(4K) 49 | { 50 | *(COMMON) 51 | *(.bss) 52 | } 53 | kernel_bss_end = .; 54 | 55 | kernel_end = .; 56 | } 57 | -------------------------------------------------------------------------------- /src/arch/aarch64/port/include/port.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file port.h 4 | * @brief arm 端口驱动 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_PORT_H 18 | #define SIMPLEKERNEL_PORT_H 19 | 20 | #include "cstdint" 21 | 22 | namespace PORT { 23 | // 端口读一个字节 24 | uint8_t inb(const uint32_t port); 25 | // 端口读一个字 26 | uint16_t inw(const uint32_t port); 27 | // 端口读一个双字 28 | uint32_t ind(const uint32_t port); 29 | // 端口写一个字节 30 | void outb(const uint32_t port, const uint8_t data); 31 | // 端口写一个字 32 | void outw(const uint32_t port, const uint16_t data); 33 | // 端口写一个双字 34 | void outd(const uint32_t port, const uint32_t data); 35 | }; // namespace PORT 36 | 37 | #endif /* SIMPLEKERNEL_PORT_H */ 38 | -------------------------------------------------------------------------------- /src/arch/aarch64/port/port.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file port.cpp 4 | * @brief 串口驱动 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #include "port.h" 18 | 19 | uint8_t PORT::inb(const uint32_t port __attribute((unused))) { 20 | return 0; 21 | } 22 | 23 | uint16_t PORT::inw(const uint32_t port __attribute((unused))) { 24 | return 0; 25 | } 26 | 27 | uint32_t PORT::ind(const uint32_t port) { 28 | return *(volatile uint32_t*)port; 29 | } 30 | 31 | void PORT::outw(const uint32_t port __attribute((unused)), 32 | const uint16_t data __attribute((unused))) { 33 | return; 34 | } 35 | 36 | void PORT::outb(const uint32_t port __attribute((unused)), 37 | const uint8_t data __attribute((unused))) { 38 | return; 39 | } 40 | 41 | void PORT::outd(const uint32_t port, const uint32_t data) { 42 | *(volatile uint32_t*)port = data; 43 | return; 44 | } 45 | -------------------------------------------------------------------------------- /src/arch/ia32/apic/apic.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file apic.cpp 4 | * @brief APIC 抽象 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-09-18digmouse233迁移到 doxygen 14 | *
15 | */ 16 | 17 | #include "apic.h" 18 | #include "cstdio" 19 | #include "intr.h" 20 | 21 | // 64-ia-32-architectures-software-developer-vol-3a-manual#10 22 | 23 | /// @todo 完善,加入内核 24 | APIC::APIC(void) { 25 | return; 26 | } 27 | 28 | APIC::~APIC(void) { 29 | return; 30 | } 31 | 32 | /// @see 64-ia-32-architectures-software-developer-vol-3a-manual#10.4.3 33 | 34 | int32_t APIC::init(void) { 35 | LOCAL_APIC::init(); 36 | IO_APIC::init(); 37 | info("apic init.\n"); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/arch/ia32/apic/include/apic.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file apic.h 4 | * @brief APIC 抽象头文件 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-09-18digmouse233迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef _APIC_H_ 18 | #define _APIC_H_ 19 | 20 | #include "cstdint" 21 | 22 | /** 23 | * @brief APIC 抽象 24 | */ 25 | class APIC { 26 | private: 27 | 28 | protected: 29 | 30 | public: 31 | APIC(void); 32 | ~APIC(void); 33 | static int32_t init(void); 34 | }; 35 | 36 | /** 37 | * @brief 本地 APIC 38 | */ 39 | class LOCAL_APIC { 40 | private: 41 | 42 | protected: 43 | 44 | public: 45 | LOCAL_APIC(void); 46 | ~LOCAL_APIC(void); 47 | static int32_t init(void); 48 | }; 49 | 50 | /** 51 | * @brief IO APIC 52 | */ 53 | class IO_APIC { 54 | private: 55 | 56 | protected: 57 | 58 | public: 59 | IO_APIC(void); 60 | ~IO_APIC(void); 61 | static int32_t init(void); 62 | }; 63 | 64 | static APIC apic; 65 | 66 | #endif /* _APIC_H_ */ 67 | -------------------------------------------------------------------------------- /src/arch/ia32/apic/io_apic.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file io_apic.cpp 4 | * @brief IOAPIC 抽象 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-09-18digmouse233迁移到 doxygen 14 | *
15 | */ 16 | 17 | #include "apic.h" 18 | #include "cpu.hpp" 19 | #include "intr.h" 20 | 21 | /// @todo 22 | 23 | IO_APIC::IO_APIC(void) { 24 | return; 25 | } 26 | 27 | IO_APIC::~IO_APIC(void) { 28 | return; 29 | } 30 | 31 | int32_t IO_APIC::init(void) { 32 | info("io apic init.\n"); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /src/arch/ia32/e820.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file e820.h 4 | * @brief e820 相关定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-09-18digmouse233迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_E820_H 18 | #define SIMPLEKERNEL_E820_H 19 | 20 | #include "cstddef" 21 | #include "cstdint" 22 | 23 | /// 最大数量 24 | static constexpr const uint32_t E820_MAX = 8; 25 | /// RAM 标记 26 | static constexpr const uint32_t E820_RAM = 1; 27 | /// 保留 标记 28 | static constexpr const uint32_t E820_RESERVED = 2; 29 | /// ACPI 标记 30 | static constexpr const uint32_t E820_ACPI = 3; 31 | /// NVS 标记 32 | static constexpr const uint32_t E820_NVS = 4; 33 | /// 不可用 标记 34 | static constexpr const uint32_t E820_UNUSABLE = 5; 35 | 36 | /** 37 | * @brief e820 项 38 | */ 39 | struct e820entry_t { 40 | // 数据类型由位数决定 41 | uintptr_t addr; 42 | size_t length; 43 | uint32_t type; 44 | }; 45 | 46 | /** 47 | * @brief e820 表 48 | */ 49 | struct e820map_t { 50 | e820map_t(void) { 51 | nr_map = 0; 52 | return; 53 | } 54 | 55 | ~e820map_t(void) { 56 | return; 57 | } 58 | 59 | uint32_t nr_map; 60 | e820entry_t map[E820_MAX]; 61 | }; 62 | 63 | #endif /* SIMPLEKERNEL_E820_H */ 64 | -------------------------------------------------------------------------------- /src/arch/ia32/i386/gdt/gdt_s.S: -------------------------------------------------------------------------------- 1 | 2 | // This file is a part of Simple-XX/SimpleKernel 3 | // (https://github.com/Simple-XX/SimpleKernel). 4 | // 5 | // gdt_s.S for Simple-XX/SimpleKernel. 6 | 7 | // clang-format off 8 | 9 | .code32 10 | 11 | .section .text 12 | .global gdt_load 13 | gdt_load: 14 | cli 15 | // 参数存入 eax 寄存器 16 | mov 4(%esp), %eax 17 | // 加载到 GDTR [修改原先GRUB设置] 18 | lgdt (%eax) 19 | 20 | // 加载数据段描述符 21 | mov $0x10, %ax 22 | // 更新所有可以更新的段寄存器 23 | mov %ax, %ds 24 | mov %ax, %es 25 | mov %ax, %fs 26 | mov %ax, %gs 27 | mov %ax, %ss 28 | // 远跳转,0x08是代码段描述符 29 | jmp $0x08, $flush 30 | // 远跳目的是清空流水线并串行化处理器 31 | 32 | flush: 33 | ret 34 | -------------------------------------------------------------------------------- /src/arch/ia32/i386/intr/timer.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file timer.cpp 4 | * @brief 时钟中断实现 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2022-01-06 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2022-01-06MRNIU新增文件 14 | *
15 | */ 16 | 17 | #include "cstdio" 18 | #include "intr.h" 19 | 20 | /** 21 | * @brief 时钟中断 22 | */ 23 | void timer_intr(INTR::intr_context_t*) { 24 | printf("timer.\n"); 25 | return; 26 | } 27 | 28 | TIMER& TIMER::get_instance(void) { 29 | /// 定义全局 TIMER 对象 30 | static TIMER timer; 31 | return timer; 32 | } 33 | 34 | void TIMER::init(void) { 35 | // 注册中断函数 36 | INTR::get_instance().register_interrupt_handler(INTR::IRQ0, timer_intr); 37 | // 开启时钟中断 38 | INTR::get_instance().enable_irq(INTR::IRQ0); 39 | info("timer init.\n"); 40 | return; 41 | } 42 | -------------------------------------------------------------------------------- /src/arch/ia32/port/port.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file port.cpp 4 | * @brief IA32 端口读写实现 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-09-18digmouse233迁移到 doxygen 14 | *
15 | */ 16 | 17 | #include "port.h" 18 | 19 | uint8_t PORT::inb(const uint32_t _port) { 20 | uint8_t ret; 21 | __asm__ volatile("inb %1, %0" : "=a"(ret) : "dN"(_port)); 22 | return ret; 23 | } 24 | 25 | uint16_t PORT::inw(const uint32_t _port) { 26 | uint16_t ret; 27 | __asm__ volatile("inw %1, %0" : "=a"(ret) : "dN"(_port)); 28 | return ret; 29 | } 30 | 31 | uint32_t PORT::ind(const uint32_t _port) { 32 | uint32_t ret; 33 | __asm__ volatile("inl %1, %0" : "=a"(ret) : "dN"(_port)); 34 | return ret; 35 | } 36 | 37 | void PORT::outw(const uint32_t _port, const uint16_t _data) { 38 | __asm__ volatile("outw %1, %0" : : "dN"(_port), "a"(_data)); 39 | return; 40 | } 41 | 42 | void PORT::outb(const uint32_t _port, const uint8_t _data) { 43 | __asm__ volatile("outb %1, %0" : : "dN"(_port), "a"(_data)); 44 | return; 45 | } 46 | 47 | void PORT::outd(const uint32_t _port, const uint32_t _data) { 48 | __asm__ volatile("outl %1, %0" : : "dN"(_port), "a"(_data)); 49 | return; 50 | } 51 | -------------------------------------------------------------------------------- /src/arch/ia32/x86_64/gdt/gdt_s.S: -------------------------------------------------------------------------------- 1 | 2 | // This file is a part of Simple-XX/SimpleKernel 3 | // (https://github.com/Simple-XX/SimpleKernel). 4 | // 5 | // gdt_s.S for Simple-XX/SimpleKernel. 6 | 7 | // clang-format off 8 | 9 | .code64 10 | 11 | .section .text 12 | .global gdt_load 13 | gdt_load: 14 | cli 15 | // 加载到 GDTR,修改 boot.S 中的设置 16 | lgdt (%rdi) 17 | 18 | // 加载数据段描述符 19 | mov $0x10, %rax 20 | // 更新所有可以更新的段寄存器 21 | mov %rax, %ds 22 | mov %rax, %es 23 | mov %rax, %fs 24 | mov %rax, %gs 25 | mov %rax, %ss 26 | call flush 27 | 28 | flush: 29 | ret 30 | -------------------------------------------------------------------------------- /src/arch/ia32/x86_64/intr/timer.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file timer.cpp 4 | * @brief 时钟中断实现 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2022-01-06 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2022-01-06MRNIU新增文件 14 | *
15 | */ 16 | 17 | #include "cstdio" 18 | #include "intr.h" 19 | 20 | /** 21 | * @brief 时钟中断 22 | */ 23 | void timer_intr(INTR::intr_context_t*) { 24 | printf("timer.\n"); 25 | return; 26 | } 27 | 28 | TIMER& TIMER::get_instance(void) { 29 | /// 定义全局 TIMER 对象 30 | static TIMER timer; 31 | return timer; 32 | } 33 | 34 | void TIMER::init(void) { 35 | // 注册中断函数 36 | INTR::get_instance().register_interrupt_handler(INTR::IRQ0, timer_intr); 37 | // 开启时钟中断 38 | INTR::get_instance().enable_irq(INTR::IRQ0); 39 | info("timer init.\n"); 40 | return; 41 | } 42 | -------------------------------------------------------------------------------- /src/arch/riscv64/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # CMakeLists.txt for Simple-XX/SimpleKernel. 6 | # 架构相关子模块的编译规则 7 | 8 | # 设置子模块名与使用的语言 9 | PROJECT(arch CXX ASM) 10 | 11 | # 寻找汇编文件 12 | find_asm_source_files(boot_asm_src ${arch_SOURCE_DIR}/boot) 13 | # 添加到 boot_src 14 | set(boot_src ${boot_asm_src}) 15 | 16 | find_asm_source_files(intr_asm_src ${arch_SOURCE_DIR}/intr) 17 | aux_source_directory(${arch_SOURCE_DIR}/intr intr_cpp_src) 18 | set(intr_src ${intr_asm_src} ${intr_cpp_src}) 19 | 20 | set(arch_src ${boot_src} ${intr_src}) 21 | 22 | # 添加子模块 23 | add_library(${PROJECT_NAME} OBJECT ${arch_src}) 24 | 25 | # 添加头文件搜索路径 26 | target_include_arch_header_files(${PROJECT_NAME}) 27 | target_include_libc_header_files(${PROJECT_NAME}) 28 | target_include_libcxx_header_files(${PROJECT_NAME}) 29 | target_include_kernel_header_files(${PROJECT_NAME}) 30 | target_include_common_header_files(${PROJECT_NAME}) 31 | target_include_drv_header_files(${PROJECT_NAME}) 32 | -------------------------------------------------------------------------------- /src/arch/riscv64/boot/boot.S: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file boot.S 4 | * @brief 启动代码,进行一些设置后跳转到 kernel_main 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-01-01 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-01-01MRNIU迁移到 doxygen 14 | *
15 | */ 16 | 17 | // clang-format off 18 | 19 | .section .text.boot 20 | .global _start 21 | .type _start, @function 22 | .extern kernel_main 23 | .extern cpp_init 24 | .extern boot_info_addr 25 | .extern dtb_init_hart 26 | _start: 27 | // 保存 sbi 传递的参数 28 | // 将 a0 的值传递给 dtb_init_hart 29 | sw a0, dtb_init_hart, t0 30 | // 将 a1 的值传递给 boot_info_addr 31 | sw a1, boot_info_addr, t0 32 | // 设置栈地址 33 | la sp, stack_top 34 | // 初始化 C++ 35 | call cpp_init 36 | // 跳转到 C 代码执行 37 | call kernel_main 38 | loop: 39 | j loop 40 | 41 | // 声明所属段 42 | .section .bss.boot 43 | // 16 字节对齐 44 | .align 16 45 | .global stack_top 46 | stack_top: 47 | // 跳过 16KB 48 | .space 4096 * 4 49 | -------------------------------------------------------------------------------- /src/arch/riscv64/intr/clint.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file clint.cpp 4 | * @brief clint 抽象 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on http://wiki.0xffffff.org/posts/hurlex-kernel.html 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2021-09-18digmouse233迁移到 doxygen 15 | *
16 | */ 17 | 18 | #include "boot_info.h" 19 | #include "cpu.hpp" 20 | #include "cstdio" 21 | #include "intr.h" 22 | #include "resource.h" 23 | #include "vmm.h" 24 | 25 | CLINT& CLINT::get_instance(void) { 26 | /// 定义全局 CLINT 对象 27 | static CLINT clint; 28 | return clint; 29 | } 30 | 31 | int32_t CLINT::init(void) { 32 | // 映射 clint 地址 33 | resource_t resource = BOOT_INFO::get_clint(); 34 | for (uintptr_t a = resource.mem.addr; 35 | a < resource.mem.addr + resource.mem.len; a += COMMON::PAGE_SIZE) { 36 | VMM::get_instance().mmap(VMM::get_instance().get_pgd(), a, a, 37 | VMM_PAGE_READABLE | VMM_PAGE_WRITABLE); 38 | } 39 | // 开启内部中断 40 | CPU::WRITE_SIE(CPU::READ_SIE() | CPU::SIE_SSIE); 41 | info("clint init.\n"); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/arch/riscv64/intr/intr_s.S: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file intr_s.S 4 | * @brief 中断处理入口 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-01-01 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-01-01MRNIU迁移到 doxygen 14 | *
15 | */ 16 | 17 | #include "context.S" 18 | 19 | // clang-format off 20 | 21 | .section .text 22 | // 保存所有寄存器 23 | .globl trap_entry 24 | .extern trap_handler 25 | .align 4 26 | trap_entry: 27 | // 将所有寄存器保存到栈上 28 | // 在栈上留出保存寄存器的空间 29 | addi sp, sp, -ALL_SIZE 30 | all_regs_save sp 31 | 32 | // 调用 intr.cpp: trap_handler 33 | // 传递参数 34 | csrr a0, sepc 35 | csrr a1, stval 36 | csrr a2, scause 37 | mv a3, sp 38 | csrr a4, sie 39 | csrr a5, sstatus 40 | csrr a6, satp 41 | csrr a7, sscratch 42 | jal trap_handler 43 | 44 | // 从栈上恢复所有寄存器 45 | all_regs_load sp 46 | // 释放栈上用于保存寄存器的空间 47 | addi sp, sp, ALL_SIZE 48 | 49 | // 跳转到 sepc 处执行 50 | sret 51 | -------------------------------------------------------------------------------- /src/kernel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # CMakeLists.txt for Simple-XX/SimpleKernel. 6 | # 内核子模块的编译规则 7 | 8 | # 设置子模块名与使用的语言 9 | PROJECT(kernel CXX) 10 | 11 | # 寻找 CXX 文件 12 | aux_source_directory(${kernel_SOURCE_DIR}/. kernel_src) 13 | 14 | # 添加子模块 15 | add_library(${PROJECT_NAME} OBJECT ${kernel_src}) 16 | 17 | # 添加头文件搜索路径 18 | target_include_arch_header_files(${PROJECT_NAME}) 19 | target_include_kernel_header_files(${PROJECT_NAME}) 20 | target_include_libc_header_files(${PROJECT_NAME}) 21 | target_include_libcxx_header_files(${PROJECT_NAME}) 22 | target_include_common_header_files(${PROJECT_NAME}) 23 | target_include_drv_header_files(${PROJECT_NAME}) -------------------------------------------------------------------------------- /src/kernel/allocator.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file allocator.cpp 4 | * @brief 分配器抽象类实现 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-09-18digmouse233迁移到 doxygen 14 | *
15 | */ 16 | 17 | #include "allocator.h" 18 | #include "cstddef" 19 | #include "cstdint" 20 | 21 | ALLOCATOR::ALLOCATOR(const char* _name, uintptr_t _addr, size_t _len) { 22 | // 默认名字 23 | name = _name; 24 | allocator_start_addr = _addr; 25 | allocator_length = _len; 26 | // 初始状态下所有页都未使用 27 | allocator_free_count = allocator_length; 28 | allocator_used_count = 0; 29 | return; 30 | } 31 | 32 | ALLOCATOR::~ALLOCATOR(void) { 33 | return; 34 | } 35 | -------------------------------------------------------------------------------- /src/kernel/include/kernel.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file kernel.h 4 | * @brief 内核头文件 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2021-09-18digmouse233迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_KERNEL_H 18 | #define SIMPLEKERNEL_KERNEL_H 19 | 20 | /** 21 | * @brief 声明 kernel_main 用 C 方法编译 22 | * @note 这个函数不会返回 23 | */ 24 | extern "C" void kernel_main(void); 25 | 26 | /** 27 | * @brief 物理内存测试函数 28 | * @return int 0 成功 29 | */ 30 | int test_pmm(void); 31 | 32 | /** 33 | * @brief 虚拟内存测试函数 34 | * @return int 0 成功 35 | */ 36 | int test_vmm(void); 37 | 38 | /** 39 | * @brief 堆测试函数 40 | * @return int 0 成功 41 | */ 42 | int test_heap(void); 43 | 44 | /** 45 | * @brief 中断测试函数 46 | * @return int 0 成功 47 | */ 48 | int test_intr(void); 49 | 50 | /** 51 | * @brief 输出系统信息 52 | */ 53 | void show_info(void); 54 | 55 | #endif /* SIMPLEKERNEL_KERNEL_H */ 56 | -------------------------------------------------------------------------------- /src/libc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # CMakeLists.txt for Simple-XX/SimpleKernel. 6 | 7 | PROJECT(libc C) 8 | 9 | aux_source_directory(${libc_SOURCE_DIR}/src/stdio stdio_src) 10 | aux_source_directory(${libc_SOURCE_DIR}/src/stdlib stdlib_src) 11 | aux_source_directory(${libc_SOURCE_DIR}/src/string string_src) 12 | aux_source_directory(${libc_SOURCE_DIR}/src/math math_src) 13 | 14 | set(libc_src ${stdio_src} ${stdio_src} ${stdlib_src} ${string_src} ${math_src}) 15 | add_library(${PROJECT_NAME} OBJECT ${libc_src}) 16 | 17 | target_include_libc_header_files(${PROJECT_NAME}) 18 | target_include_common_header_files(${PROJECT_NAME}) 19 | -------------------------------------------------------------------------------- /src/libc/include/assert.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file assert.h 4 | * @brief assert 实现 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on https://wiki.osdev.org/Raspberry_Pi_Bare_Bones 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-03-31Zone.N迁移到 doxygen 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_ASSERT_H 19 | #define SIMPLEKERNEL_ASSERT_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include "stdio.h" 26 | 27 | #define assert(_e) \ 28 | ((void)((_e) ? ((void)0) : __assert(#_e, __FILE__, __LINE__))) 29 | #define __assert(_e, _file, _line) \ 30 | ((void)err("%s:%d: failed assertion `%s'\n", _file, _line, _e)) 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* SIMPLEKERNEL_ASSERT_H */ 37 | -------------------------------------------------------------------------------- /src/libc/include/ctype.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file ctype.h 4 | * @brief ctype 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CTYPE_H 18 | #define SIMPLEKERNEL_CTYPE_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #define isupper(_c) (_c >= 'A' && _c <= 'Z') 25 | #define isalpha(_c) ((_c >= 'A' && _c <= 'Z') || (_c >= 'a' && _c <= 'z')) 26 | #define isspace(_c) (_c == ' ' || _c == '\t' || _c == '\n' || _c == '\12') 27 | #define isdigit(_c) (_c >= '0' && _c <= '9') 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* SIMPLEKERNEL_CTYPE_H */ 34 | -------------------------------------------------------------------------------- /src/libc/include/float.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file float.h 4 | * @brief float 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_FLOAT_H 18 | #define SIMPLEKERNEL_FLOAT_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #define DBL_MAX (1e37) 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_FLOAT_H */ 31 | -------------------------------------------------------------------------------- /src/libc/include/math.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file math.h 4 | * @brief math 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on libgcc 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-03-31Zone.N迁移到 doxygen 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_MATH_H 19 | #define SIMPLEKERNEL_MATH_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | // TODO: 更多支持 26 | // TODO: 浮点数 27 | 28 | long long divmoddi4(long long _num, long long _den, long long* _rem_p); 29 | unsigned long long udivmoddi4(unsigned long long _num, unsigned long long _den, 30 | unsigned long long* _rem_p); 31 | unsigned long long udivdi3(unsigned long long _num, unsigned long long _den); 32 | unsigned long long umoddi3(unsigned long long _num, unsigned long long _den); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* SIMPLEKERNEL_MATH_H */ 39 | -------------------------------------------------------------------------------- /src/libc/include/stdarg.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file stdarg.h 4 | * @brief stdarg 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_STDARG_H 18 | #define SIMPLEKERNEL_STDARG_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #define va_list __builtin_va_list 25 | #define va_start(_v, _l) __builtin_va_start(_v, _l) 26 | #define va_arg(_v, _l) __builtin_va_arg(_v, _l) 27 | #define va_end(_v) __builtin_va_end(_v) 28 | #define va_copy(_d, _s) __builtin_va_copy(_d, _s) 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* SIMPLEKERNEL_STDARG_H */ 35 | -------------------------------------------------------------------------------- /src/libc/include/stdbool.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file stdbool.h 4 | * @brief stdbool 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * Baseed on GCC stdbool.h 7 | * @version 1.0 8 | * @date 2023-03-31 9 | * @copyright MIT LICENSE 10 | * https://github.com/Simple-XX/SimpleKernel 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-03-31Zone.N迁移到 doxygen 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_STDBOOL_H 19 | #define SIMPLEKERNEL_STDBOOL_H 20 | 21 | #ifndef __cplusplus 22 | 23 | # define bool _Bool 24 | # define true 1 25 | # define false 0 26 | 27 | #else /* __cplusplus */ 28 | 29 | /* Supporting _Bool in C++ is a GCC extension. */ 30 | # define _Bool bool 31 | 32 | # if __cplusplus < 201103L 33 | /* Defining these macros in C++98 is a GCC extension. */ 34 | # define bool bool 35 | # define false false 36 | # define true true 37 | # endif 38 | 39 | #endif /* __cplusplus */ 40 | 41 | /* Signal that all the definitions are present. */ 42 | #define __bool_true_false_are_defined 1 43 | 44 | #endif /* SIMPLEKERNEL_STDBOOL_H */ 45 | -------------------------------------------------------------------------------- /src/libc/include/stddef.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file stddef.h 4 | * @brief stddef 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_STDDEF_H 18 | #define SIMPLEKERNEL_STDDEF_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #ifndef _PTRDIFF_T 25 | # define _PTRDIFF_T 26 | typedef long ptrdiff_t; 27 | #endif 28 | 29 | #ifndef _SIZE_T 30 | # define _SIZE_T 31 | # undef size_t 32 | # if defined(__i386__) 33 | typedef unsigned int size_t; 34 | # elif defined(__riscv) || defined(__x86_64__) 35 | typedef long unsigned int size_t; 36 | # endif 37 | #endif 38 | 39 | #ifndef _SSIZE_T 40 | # define _SSIZE_T 41 | # undef ssize_t 42 | # if defined(__i386__) 43 | typedef int ssize_t; 44 | # elif defined(__riscv) || defined(__x86_64__) 45 | typedef long int ssize_t; 46 | # endif 47 | #endif 48 | 49 | #ifndef _SSIZE_T 50 | # define _SSIZE_T 51 | # undef ssize_t 52 | typedef int ssize_t; 53 | #endif 54 | 55 | #ifndef NULL 56 | # define NULL ((void*)0) 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* SIMPLEKERNEL_STDDEF_H */ 64 | -------------------------------------------------------------------------------- /src/libc/include/stdlib.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file stdlib.h 4 | * @brief stdlib 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_STDLIB_H 18 | #define SIMPLEKERNEL_STDLIB_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "stddef.h" 25 | #include "stdint.h" 26 | 27 | int abs(int); 28 | int atoi(const char*); 29 | long atol(const char*); 30 | long long atoll(const char*); 31 | int itoa(int _num, char* _str, int _len, int _base); 32 | long strtol(const char* _nptr, char** _endptr, int _base); 33 | long long strtoll(const char* _nptr, char** _endptr, int _base); 34 | 35 | void* malloc(size_t size); 36 | 37 | void free(void* ptr); 38 | 39 | void* kmalloc(size_t size); 40 | 41 | void kfree(void* ptr); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* SIMPLEKERNEL_STDLIB_H */ 48 | -------------------------------------------------------------------------------- /src/libc/include/time.h: -------------------------------------------------------------------------------- 1 | 2 | // This file is a part of Simple-XX/SimpleKernel 3 | // (https://github.com/Simple-XX/SimpleKernel). 4 | // 5 | // time.h for Simple-XX/SimpleKernel. 6 | 7 | #ifndef _TIME_H_ 8 | #define _TIME_H_ 9 | 10 | #endif /* _TIME_H_ */ 11 | -------------------------------------------------------------------------------- /src/libc/src/stdlib/atoi.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file atoi.c 4 | * @brief atoi 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #include "stddef.h" 18 | #include "stdlib.h" 19 | 20 | int abs(int _i) { 21 | return _i < 0 ? -_i : _i; 22 | } 23 | 24 | int atoi(const char* _str) { 25 | return (int)strtol(_str, (char**)NULL, 10); 26 | } 27 | 28 | long atol(const char* _str) { 29 | return (long)strtoll(_str, (char**)NULL, 10); 30 | } 31 | 32 | long long atoll(const char* _str) { 33 | return (long long)strtoll(_str, (char**)NULL, 10); 34 | } 35 | -------------------------------------------------------------------------------- /src/libc/src/stdlib/itoa.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file itoa.c 4 | * @brief itoa 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #include "stdlib.h" 18 | #include "string.h" 19 | 20 | int itoa(int _num, char* _str, int _len, int _base) { 21 | int sum = _num; 22 | int i = 0; 23 | int digit; 24 | if (_len == 0) { 25 | return -1; 26 | } 27 | do { 28 | digit = sum % _base; 29 | if (digit < 0xA) { 30 | _str[i++] = '0' + digit; 31 | } 32 | else { 33 | _str[i++] = 'A' + digit - 0xA; 34 | } 35 | sum /= _base; 36 | } while (sum && (i < (_len - 1))); 37 | if (i == (_len - 1) && sum) { 38 | return -1; 39 | } 40 | _str[i] = '\0'; 41 | strrev(_str); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/libcxx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # 5 | # CMakeLists.txt for Simple-XX/SimpleKernel. 6 | 7 | PROJECT(libcxx CXX ASM) 8 | 9 | find_asm_source_files(ASM_SOURCE_FILES ${libcxx_SOURCE_DIR}/src) 10 | aux_source_directory(${libcxx_SOURCE_DIR}/src cxx_src) 11 | 12 | set(libcxx_src ${ASM_SOURCE_FILES} ${cxx_src}) 13 | add_library(${PROJECT_NAME} OBJECT ${libcxx_src}) 14 | 15 | target_include_libc_header_files(${PROJECT_NAME}) 16 | target_include_libcxx_header_files(${PROJECT_NAME}) 17 | -------------------------------------------------------------------------------- /src/libcxx/include/algorithm: -------------------------------------------------------------------------------- 1 |  2 | /** 3 | * @file algorithm 4 | * @brief stl algorithm 支持 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-04-05 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on https://github.com/Alinshans/MyTinySTL 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-04-05Zone.N迁移到 doxygen 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_ALGORITHM 19 | #define SIMPLEKERNEL_ALGORITHM 20 | 21 | // 这个头文件包含了 std 的所有算法,包括基本算法,数值算法,heap 算法,set 22 | // 算法和其他算法 23 | 24 | #include "algo" 25 | #include "algobase" 26 | #include "heap_algo" 27 | #include "numeric" 28 | #include "set_algo" 29 | 30 | namespace mystl { }; 31 | 32 | #endif /* SIMPLEKERNEL_ALGORITHM */ 33 | -------------------------------------------------------------------------------- /src/libcxx/include/astring: -------------------------------------------------------------------------------- 1 |  2 | /** 3 | * @file astring 4 | * @brief stl astring 支持 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-04-05 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on https://github.com/Alinshans/MyTinySTL 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-04-05Zone.N迁移到 doxygen 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_ASTRING 19 | #define SIMPLEKERNEL_ASTRING 20 | 21 | // 定义了 string, wstring, u16string, u32string 类型 22 | 23 | #include "basic_string" 24 | 25 | namespace mystl { 26 | 27 | using string = mystl::basic_string; 28 | using wstring = mystl::basic_string; 29 | using u16string = mystl::basic_string; 30 | using u32string = mystl::basic_string; 31 | 32 | }; // namespace mystl 33 | 34 | #endif /* SIMPLEKERNEL_ASTRING */ 35 | -------------------------------------------------------------------------------- /src/libcxx/include/cassert: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cassert 4 | * @brief assert 实现 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * Based on https://wiki.osdev.org/Raspberry_Pi_Bare_Bones 7 | * @version 1.0 8 | * @date 2023-05-08 9 | * @copyright MIT LICENSE 10 | * https://github.com/Simple-XX/SimpleKernel 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-05-08Zone.N创建文件 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_CASSERT 19 | #define SIMPLEKERNEL_CASSERT 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include "assert.h" 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* SIMPLEKERNEL_CASSERT */ 32 | -------------------------------------------------------------------------------- /src/libcxx/include/cfloat: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cfloat 4 | * @brief float 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-05-08Zone.N创建文件 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CFLOAT 18 | #define SIMPLEKERNEL_CFLOAT 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "float.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_CFLOAT */ 31 | -------------------------------------------------------------------------------- /src/libcxx/include/climits: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file climits 4 | * @brief limits 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-05-08Zone.N创建文件 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CLIMITS 18 | #define SIMPLEKERNEL_CLIMITS 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "limits.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_CLIMITS */ 31 | -------------------------------------------------------------------------------- /src/libcxx/include/cmath: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cmath 4 | * @brief math 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-05-08Zone.N创建文件 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CMATH 18 | #define SIMPLEKERNEL_CMATH 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "math.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_CMATH */ 31 | -------------------------------------------------------------------------------- /src/libcxx/include/cstdarg: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cstdarg 4 | * @brief stdarg 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-05-08Zone.N创建文件 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CSTDARG 18 | #define SIMPLEKERNEL_CSTDARG 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "stdarg.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_CSTDARG */ 31 | -------------------------------------------------------------------------------- /src/libcxx/include/cstdbool: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cstdbool 4 | * @brief stdbool 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-05-08Zone.N创建文件 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CSTDBOOL 18 | #define SIMPLEKERNEL_CSTDBOOL 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "stdbool.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_CSTDBOOL */ 31 | -------------------------------------------------------------------------------- /src/libcxx/include/cstddef: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cstddef 4 | * @brief stddef 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-05-08Zone.N创建文件 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CSTDDEF 18 | #define SIMPLEKERNEL_CSTDDEF 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "stddef.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_CSTDDEF */ 31 | -------------------------------------------------------------------------------- /src/libcxx/include/cstdint: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cstdint 4 | * @brief stdint 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * Based on GNU C Lib 7 | * @version 1.0 8 | * @date 2023-05-08 9 | * @copyright MIT LICENSE 10 | * https://github.com/Simple-XX/SimpleKernel 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-05-08Zone.N创建文件 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_CSTDINT 19 | #define SIMPLEKERNEL_CSTDINT 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include "stdint.h" 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* SIMPLEKERNEL_CSTDINT */ 32 | -------------------------------------------------------------------------------- /src/libcxx/include/cstdio: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cstdio 4 | * @brief stdio 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * Based on https://github.com/mpaland/printf 7 | * @version 1.0 8 | * @date 2023-05-08 9 | * @copyright MIT LICENSE 10 | * https://github.com/Simple-XX/SimpleKernel 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-05-08Zone.N创建文件 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_CSTDIO 19 | #define SIMPLEKERNEL_CSTDIO 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include "stdio.h" 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* SIMPLEKERNEL_CSTDIO */ 32 | -------------------------------------------------------------------------------- /src/libcxx/include/cstdlib: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file cstdlib 4 | * @brief stdlib 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-05-08Zone.N创建文件 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CSTDLIB 18 | #define SIMPLEKERNEL_CSTDLIB 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "stdlib.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_CSTDLIB */ 31 | -------------------------------------------------------------------------------- /src/libcxx/include/ctype: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file ctype 4 | * @brief ctype 定义 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-05-08Zone.N创建文件 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_CTYPE 18 | #define SIMPLEKERNEL_CTYPE 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "ctype.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SIMPLEKERNEL_CTYPE */ 31 | -------------------------------------------------------------------------------- /src/libcxx/include/exceptdef: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file exceptdef 4 | * @brief stl exceptdef 支持 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-04-05 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on https://github.com/Alinshans/MyTinySTL 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-04-05Zone.N迁移到 doxygen 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_EXCEPTDEF 19 | #define SIMPLEKERNEL_EXCEPTDEF 20 | 21 | // #include 22 | 23 | #include "assert.h" 24 | 25 | namespace mystl { 26 | 27 | #define MYSTL_DEBUG(expr) assert(expr) 28 | 29 | #define THROW_LENGTH_ERROR_IF(expr, what) assert(!(expr)) 30 | // if ((expr)) throw std::length_error(what) 31 | 32 | #define THROW_OUT_OF_RANGE_IF(expr, what) assert(!(expr)) 33 | // if ((expr)) throw std::out_of_range(what) 34 | 35 | #define THROW_RUNTIME_ERROR_IF(expr, what) assert(!(expr)) 36 | // if ((expr)) throw std::runtime_error(what) 37 | 38 | }; // namespace mystl 39 | 40 | #endif /* SIMPLEKERNEL_EXCEPTDEF */ 41 | -------------------------------------------------------------------------------- /src/libcxx/include/iostream: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file iostream 4 | * @brief C++ 输入输出 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on https://github.com/MRNIU/MiniCRT 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2021-09-18digmouse233迁移到 doxygen 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_IOSTREAM 19 | #define SIMPLEKERNEL_IOSTREAM 20 | 21 | #include "cstdint" 22 | 23 | namespace std { 24 | class ostream { 25 | private: 26 | 27 | protected: 28 | ostream(const ostream& lhs); 29 | 30 | public: 31 | enum openmode : uint8_t { 32 | in = 1, 33 | out = 2, 34 | binary = 4, 35 | trunc = 8, 36 | }; 37 | 38 | ostream(void); 39 | ~ostream(void); 40 | ostream& operator<<(char c); 41 | ostream& operator<<(int n); 42 | ostream& operator<<(const char* lhs); 43 | ostream& operator<<(ostream& (*)(ostream&)); 44 | }; 45 | 46 | inline ostream& endl(ostream& lhs) { 47 | return lhs << '\n'; 48 | } 49 | 50 | static ostream cout; 51 | }; // namespace std 52 | 53 | #endif /* SIMPLEKERNEL_IOSTREAM */ 54 | -------------------------------------------------------------------------------- /src/libcxx/include/new: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file new 4 | * @brief 内存分配 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-03-31 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * @par change log: 11 | * 12 | *
DateAuthorDescription 13 | *
2023-03-31Zone.N迁移到 doxygen 14 | *
15 | */ 16 | 17 | #ifndef SIMPLEKERNEL_NEW 18 | #define SIMPLEKERNEL_NEW 19 | 20 | #include "cstddef" 21 | 22 | namespace std { 23 | enum class align_val_t : size_t { 24 | }; 25 | }; // namespace std 26 | 27 | void* operator new(size_t size); 28 | 29 | void* operator new(size_t, void* p) throw(); 30 | 31 | void* operator new[](size_t size); 32 | 33 | void* operator new[](size_t, void* p) throw(); 34 | 35 | void operator delete(void* p); 36 | 37 | void operator delete(void* p, size_t size); 38 | 39 | void operator delete(void*, void*) throw(); 40 | 41 | void operator delete[](void* p); 42 | 43 | void operator delete[](void* p, size_t size); 44 | 45 | void operator delete[](void*, void*) throw(); 46 | 47 | void* operator new(size_t, std::align_val_t); 48 | void operator delete(void*, std::align_val_t); 49 | void* operator new[](size_t, std::align_val_t); 50 | void operator delete[](void*, std::align_val_t); 51 | void operator delete(void*, size_t, std::align_val_t); 52 | void operator delete[](void*, size_t, std::align_val_t); 53 | 54 | #endif /* SIMPLEKERNEL_NEW */ 55 | -------------------------------------------------------------------------------- /src/libcxx/include/string: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file string 4 | * @brief stl string 支持 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-04-05 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on https://github.com/Alinshans/MyTinySTL 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-04-05Zone.N迁移到 doxygen 15 | *
16 | */ 17 | 18 | #ifndef SIMPLEKERNEL_STRING 19 | #define SIMPLEKERNEL_STRING 20 | 21 | #include "astring" 22 | 23 | #endif /* SIMPLEKERNEL_STRING */ 24 | -------------------------------------------------------------------------------- /src/libcxx/src/__dso_handle.S: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel 3 | # (https://github.com/Simple-XX/SimpleKernel). 4 | # Based on https://android.googlesource.com/platform/bionic.git/+/gingerbread/libc/private/__dso_handle.S 5 | # __dso_handle.S for Simple-XX/SimpleKernel. 6 | 7 | # The __dso_handle global variable is used by static 8 | # C++ constructors and destructors in the binary. 9 | # See http://www.codesourcery.com/public/cxx-abi/abi.html#dso-dtor 10 | 11 | .section .bss 12 | .align 4 13 | #ifndef CRT_LEGACY_WORKAROUND 14 | .hidden __dso_handle 15 | #endif 16 | .global __dso_handle 17 | __dso_handle: 18 | .long 0 19 | -------------------------------------------------------------------------------- /src/libcxx/src/iostream.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file iostream 4 | * @brief C++ 输入输出 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2021-09-18 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on https://github.com/MRNIU/MiniCRT 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2021-09-18digmouse233迁移到 doxygen 15 | *
16 | */ 17 | 18 | #include "iostream" 19 | #include "cstdio" 20 | 21 | namespace std { 22 | ostream::ostream(void) { 23 | return; 24 | } 25 | 26 | ostream::~ostream(void) { 27 | return; 28 | } 29 | 30 | ostream& ostream::operator<<(char c) { 31 | printf("%c", c); 32 | return *this; 33 | } 34 | 35 | ostream& ostream::operator<<(int n) { 36 | printf("%d", n); 37 | return *this; 38 | } 39 | 40 | ostream& ostream::operator<<(const char* lhs) { 41 | printf("%s", lhs); 42 | return *this; 43 | } 44 | 45 | ostream& ostream::operator<<(ostream& (*manip)(ostream&)) { 46 | return manip(*this); 47 | } 48 | }; // namespace std 49 | -------------------------------------------------------------------------------- /src/libcxx/src/stack_chk.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file stack_chk.cpp 4 | * @brief 栈保护 5 | * @author Zone.N (Zone.Niuzh@hotmail.com) 6 | * @version 1.0 7 | * @date 2023-05-08 8 | * @copyright MIT LICENSE 9 | * https://github.com/Simple-XX/SimpleKernel 10 | * Based on https://github.com/MRNIU/MiniCRT 11 | * @par change log: 12 | * 13 | *
DateAuthorDescription 14 | *
2023-05-08Zone.N创建文件 15 | *
16 | */ 17 | 18 | #include "cstdint" 19 | #include "cstdio" 20 | 21 | #if UINT32_MAX == UINTPTR_MAX 22 | # define STACK_CHK_GUARD 0xe2dee396 23 | #else 24 | # define STACK_CHK_GUARD 0x595e9fbd94fda766 25 | #endif 26 | 27 | uintptr_t __stack_chk_guard = STACK_CHK_GUARD; 28 | 29 | void __stack_chk_fail(void) { 30 | err("Stack smashing detected\n"); 31 | return; 32 | } 33 | -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.41.38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.41.38.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.42.21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.42.21.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.42.56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.42.56.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.44.30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.44.30.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.45.14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.45.14.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.48.24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.48.24.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.52.00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.52.00.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.54.02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.54.02.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-16 22.56.43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-16 22.56.43.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-17 16.29.12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-17 16.29.12.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.49.01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.49.01.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.49.07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.49.07.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.53.12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.53.12.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.53.34-2852427.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.53.34-2852427.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.53.34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.53.34.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.54.15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.54.15.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.55.16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.55.16.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.56.23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.56.23.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.56.31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.56.31.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.57.31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.57.31.png -------------------------------------------------------------------------------- /tools/.Clion_usage.assets/2022-01-22 19.58.14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/.Clion_usage.assets/2022-01-22 19.58.14.png -------------------------------------------------------------------------------- /tools/Git Commit 规范.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/Git Commit 规范.pdf -------------------------------------------------------------------------------- /tools/READMD.md: -------------------------------------------------------------------------------- 1 | # src/ 2 | 3 | - arch/ 4 | 5 | 存放平台相关代码的目录。 6 | 7 | - include/ 8 | 9 | 用到的头文件。 10 | 11 | - kernel/ 12 | 13 | 内核源代码。 14 | 15 | - Makefile 16 | 17 | 指定内核映像的生成规则,最终生成 kernel.kernel. 18 | 19 | - kernel.kernel 20 | 21 | 最终的内核映像。 22 | 23 | -------------------------------------------------------------------------------- /tools/grub.cfg: -------------------------------------------------------------------------------- 1 | set timeout=15 2 | set default=0 3 | menuentry "SimpleKernel" { 4 | multiboot2 /boot/kernel.elf "KERNEL_ELF" 5 | } 6 | -------------------------------------------------------------------------------- /tools/grub4mac.sh: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of SimpleXX/SimpleKernel (https://github.com/SimpleXX/SimpleKernel). 3 | # 4 | # grub4mac.sh for SimpleXX/SimpleKernel. 5 | 6 | #!/bin/bash 7 | 8 | # set -x 9 | set -e 10 | 11 | wget https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz 12 | tar zxvf grub-2.04.tar.xz 13 | cd grub-2.04 14 | if ! [ -x "$(command -v autoconf)" ]; then 15 | echo 'Error: autoconf is not installed.' 16 | echo 'Install autoconf...' 17 | brew install autoconf 18 | fi 19 | if ! [ -x "$(command -v automake)" ]; then 20 | echo 'Error: automake is not installed.' 21 | echo 'Install automake...' 22 | brew install automake 23 | fi 24 | ./autogen.sh 25 | mkdir -p build 26 | cd build 27 | ../configure \ 28 | --target=x86_64-elf \ 29 | --prefix=$(pwd)/grub \ 30 | --disable-werror \ 31 | TARGET_CC=x86_64-elf-gcc \ 32 | TARGET_OBJCOPY=x86_64-elf-objcopy \ 33 | TARGET_STRIP=x86_64-elf-strip \ 34 | TARGET_NM=x86_64-elf-nm \ 35 | TARGET_RANLIB=x86_64-elf-ranlib 36 | 37 | sed -i "" "s/FILE_TYPE_NO_DECOMPRESS/GRUB_FILE_TYPE_NO_DECOMPRESS/g" $(pwd)/../grub-core/osdep/generic/blocklist.c 38 | 39 | make 40 | make install 41 | -------------------------------------------------------------------------------- /tools/opensbi/.clang-format: -------------------------------------------------------------------------------- 1 | AlignConsecutiveAssignments: true 2 | AlignEscapedNewlines: Left 3 | AlignTrailingComments: true 4 | AllowShortFunctionsOnASingleLine: None 5 | BraceWrapping: 6 | AfterFunction: true 7 | BreakBeforeBraces: Custom 8 | BreakStringLiterals: false 9 | ContinuationIndentWidth: 8 10 | Cpp11BracedListStyle: false 11 | IndentWidth: 8 12 | ReflowComments: false 13 | SortIncludes: false 14 | SpacesInContainerLiterals: false 15 | TabWidth: 8 16 | UseTab: Always 17 | -------------------------------------------------------------------------------- /tools/opensbi/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.a 4 | *.dep 5 | 6 | #Build & install directories 7 | build/ 8 | install/ 9 | 10 | # Development friendly files 11 | tags 12 | cscope* 13 | *.swp 14 | -------------------------------------------------------------------------------- /tools/opensbi/CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | 2 | List of OpenSBI Contributors (Alphabetically sorted) 3 | ==================================================== 4 | 5 | * **[Western Digital Corporation](https://www.wdc.com/)** 6 | * Project initiator and maintainer 7 | * Copyright (c) 2019 Western Digital Corporation or its affiliates 8 | 9 | * Alistair Francis 10 | 11 | * Andreas Schwab 12 | 13 | * Anup Patel 14 | 15 | * Atish Patra 16 | 17 | * Bin Meng 18 | 19 | * Damien Le Moal 20 | 21 | * Karsten Merker 22 | 23 | * Nick Kossifidis 24 | 25 | * Shawn Chang 26 | 27 | * Xiang Wang 28 | -------------------------------------------------------------------------------- /tools/opensbi/COPYING.BSD: -------------------------------------------------------------------------------- 1 | The 2-Clause BSD License 2 | SPDX short identifier: BSD-2-Clause 3 | 4 | Copyright (c) 2019 Western Digital Corporation or its affiliates and other 5 | contributors. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 2. 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" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /tools/opensbi/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | mainmenu "OpenSBI $(OPENSBI_PLATFORM) Configuration" 4 | 5 | config OPENSBI_SRC_DIR 6 | string 7 | option env="OPENSBI_SRC_DIR" 8 | 9 | config OPENSBI_PLATFORM 10 | string 11 | option env="OPENSBI_PLATFORM" 12 | 13 | config OPENSBI_PLATFORM_SRC_DIR 14 | string 15 | option env="OPENSBI_PLATFORM_SRC_DIR" 16 | 17 | menu "Platform Options" 18 | source "$(OPENSBI_PLATFORM_SRC_DIR)/Kconfig" 19 | endmenu 20 | 21 | source "$(OPENSBI_SRC_DIR)/lib/sbi/Kconfig" 22 | 23 | source "$(OPENSBI_SRC_DIR)/lib/utils/Kconfig" 24 | 25 | source "$(OPENSBI_SRC_DIR)/firmware/Kconfig" 26 | -------------------------------------------------------------------------------- /tools/opensbi/ThirdPartyNotices.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Western Digital Corporation or its affiliates. 2 | 3 | Third Party Notices 4 | =================== 5 | 6 | This project includes or partly uses code from the following open source 7 | software subject to the following open source licenses. 8 | 9 | libfdt 10 | ------ 11 | 12 | Copyright (C) 2016 Free Electrons 13 | Copyright (C) 2016 NextThing Co. 14 | 15 | The libfdt source code is disjunctively dual licensed (GPL-2.0+ or 16 | BSD-2-Clause). Some of this project code is used in OpenSBI under the terms of 17 | the BSD 2-Clause license. The full text of this license can be found in the 18 | file [COPYING.BSD](COPYING.BSD). 19 | -------------------------------------------------------------------------------- /tools/opensbi/docs/firmware/payload_linux.md: -------------------------------------------------------------------------------- 1 | Linux as a direct payload to OpenSBI 2 | ==================================== 3 | 4 | OpenSBI has the capability to load a Linux kernel image directly in supervisor 5 | mode. The flattened image generated by the Linux kernel build process can be 6 | provided as a payload to OpenSBI. 7 | 8 | Detailed examples can be found in both the [QEMU](../platform/qemu_virt.md) 9 | and the [HiFive Unleashed](../platform/sifive_fu540.md) platform guides. 10 | -------------------------------------------------------------------------------- /tools/opensbi/docs/firmware/payload_uboot.md: -------------------------------------------------------------------------------- 1 | U-Boot as a payload to OpenSBI 2 | ============================== 3 | 4 | [U-Boot](https://www.denx.de/wiki/U-Boot) is an open-source primary boot loader. 5 | It can be used as first and/or second stage boot loader in an embedded 6 | environment. In the context of OpenSBI, U-Boot can be specified as a payload to 7 | the OpenSBI firmware, becoming the boot stage following the OpenSBI firmware 8 | execution. 9 | 10 | Building and Generating U-Boot images 11 | ===================================== 12 | Please refer to the U-Boot build documentation for detailed instructions on 13 | how to build U-Boot image and boot high level operating systems from U-Boot 14 | prompt. 15 | 16 | -------------------------------------------------------------------------------- /tools/opensbi/docs/platform/fpga-ariane.md: -------------------------------------------------------------------------------- 1 | Ariane FPGA SoC Platform 2 | ======================== 3 | Ariane is a 6-stage, single issue, in-order CPU which implements the 64-bit 4 | RISC-V instruction set. The Ariane FPGA development platform is based on FPGA 5 | SoC (which currently supports only Genesys 2 board) and is capable of running 6 | Linux. 7 | 8 | The FPGA SoC currently contains the following peripherals: 9 | - DDR3 memory controller 10 | - SPI controller to connect to an SDCard 11 | - Ethernet controller 12 | - JTAG port (see debugging section below) 13 | - Bootrom containing zero stage bootloader and device tree. 14 | 15 | To build platform specific library and firmwares, provide the 16 | *PLATFORM=fpga/ariane* parameter to the top level `make` command. 17 | 18 | Platform Options 19 | ---------------- 20 | 21 | The *Ariane FPGA* platform does not have any platform-specific options. 22 | 23 | Building Ariane FPGA Platform 24 | ----------------------------- 25 | 26 | **Linux Kernel Payload** 27 | 28 | ``` 29 | make PLATFORM=fpga/ariane FW_PAYLOAD_PATH=/arch/riscv/boot/Image 30 | ``` 31 | 32 | Booting Ariane FPGA Platform 33 | ---------------------------- 34 | 35 | **Linux Kernel Payload** 36 | 37 | As Linux kernel image is embedded in the OpenSBI firmware binary, Ariane will 38 | directly boot into Linux directly after powered on. 39 | -------------------------------------------------------------------------------- /tools/opensbi/docs/platform/fpga-openpiton.md: -------------------------------------------------------------------------------- 1 | OpenPiton FPGA SoC Platform 2 | ======================== 3 | OpenPiton is the world's first open source, general purpose, multithreaded 4 | manycore processor. It is a tiled manycore framework scalable from one to 5 | 1/2 billion cores. Currently, OpenPiton supports the 64bit Ariane RISC-V 6 | processor from ETH Zurich. To this end, Ariane has been equipped with a 7 | different L1 cache subsystem that follows a write-through protocol and that has 8 | support for cache invalidations and atomics. 9 | 10 | To build platform specific library and firmwares, provide the 11 | *PLATFORM=fpga/openpiton* parameter to the top level `make` command. 12 | 13 | Platform Options 14 | ---------------- 15 | 16 | The *OpenPiton* platform does not have any platform-specific options. 17 | 18 | Building Ariane FPGA Platform 19 | ----------------------------- 20 | 21 | **Linux Kernel Payload** 22 | 23 | ``` 24 | make PLATFORM=fpga/openpiton FW_PAYLOAD_PATH=/arch/riscv/boot/Image 25 | ``` 26 | 27 | Booting Ariane FPGA Platform 28 | ---------------------------- 29 | 30 | **Linux Kernel Payload** 31 | 32 | As Linux kernel image is embedded in the OpenSBI firmware binary, Ariane will 33 | directly boot into Linux directly after powered on. 34 | -------------------------------------------------------------------------------- /tools/opensbi/docs/platform/nuclei_ux600.md: -------------------------------------------------------------------------------- 1 | 2 | Nuclei UX600 Platform 3 | ===================== 4 | 5 | The **Nuclei UX600** is a 64-bit RISC-V Core which is capable of running Linux. 6 | 7 | > Nuclei UX600: single core, pipeline as single-issue and 6~9 variable stages, in-order dispatch and out-of-order write-back, running up to >1.2GHz 8 | 9 | To build the platform-specific library and firmware images, provide the 10 | *PLATFORM=nuclei/ux600* parameter to the top level `make` command. 11 | 12 | Platform Options 13 | ---------------- 14 | 15 | The *Nuclei UX600* platform does not have any platform-specific options. 16 | 17 | Building Nuclei UX600 Platform 18 | ------------------------------ 19 | 20 | ``` 21 | make PLATFORM=nuclei/ux600 clean all 22 | ``` 23 | -------------------------------------------------------------------------------- /tools/opensbi/docs/platform/shakti_cclass.md: -------------------------------------------------------------------------------- 1 | Shakti C-class SoC Platform 2 | =========================== 3 | C-Class is a member of the SHAKTI family of processors from 4 | Indian Institute of Technology - Madras (IIT-M). 5 | 6 | It is an extremely configurable and commercial-grade 5-stage 7 | in-order core supporting the standard RV64GCSUN ISA extensions. 8 | 9 | For more details, refer: 10 | * https://gitlab.com/shaktiproject/cores/c-class/blob/master/README.md 11 | * https://c-class.readthedocs.io/en/latest 12 | * https://shakti.org.in 13 | 14 | Platform Options 15 | ---------------- 16 | 17 | The *Shakti C-class SoC* platform does not have any platform-specific 18 | options. 19 | 20 | Building Shakti C-class Platform 21 | -------------------------------- 22 | 23 | **Linux Kernel Payload** 24 | 25 | ``` 26 | make PLATFORM=generic FW_PAYLOAD_PATH=/arch/riscv/boot/Image FW_FDT_PATH= 27 | ``` 28 | 29 | **Test Payload** 30 | 31 | ``` 32 | make PLATFORM=generic FW_FDT_PATH= 33 | ``` 34 | -------------------------------------------------------------------------------- /tools/opensbi/firmware/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | -------------------------------------------------------------------------------- /tools/opensbi/firmware/external_deps.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | $(platform_build_dir)/firmware/fw_dynamic.o: $(FW_FDT_PATH) 11 | $(platform_build_dir)/firmware/fw_jump.o: $(FW_FDT_PATH) 12 | $(platform_build_dir)/firmware/fw_payload.o: $(FW_FDT_PATH) 13 | 14 | $(platform_build_dir)/firmware/fw_payload.o: $(FW_PAYLOAD_PATH_FINAL) 15 | -------------------------------------------------------------------------------- /tools/opensbi/firmware/fw_dynamic.elf.ldS: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | OUTPUT_ARCH(riscv) 11 | ENTRY(_start) 12 | 13 | SECTIONS 14 | { 15 | #include "fw_base.ldS" 16 | 17 | PROVIDE(_fw_reloc_end = .); 18 | } 19 | -------------------------------------------------------------------------------- /tools/opensbi/firmware/fw_jump.elf.ldS: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | OUTPUT_ARCH(riscv) 11 | ENTRY(_start) 12 | 13 | SECTIONS 14 | { 15 | #include "fw_base.ldS" 16 | 17 | PROVIDE(_fw_reloc_end = .); 18 | } 19 | -------------------------------------------------------------------------------- /tools/opensbi/firmware/fw_payload.elf.ldS: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | OUTPUT_ARCH(riscv) 11 | ENTRY(_start) 12 | 13 | SECTIONS 14 | { 15 | #include "fw_base.ldS" 16 | 17 | #ifdef FW_PAYLOAD_OFFSET 18 | . = FW_TEXT_START + FW_PAYLOAD_OFFSET; 19 | #else 20 | . = ALIGN(FW_PAYLOAD_ALIGN); 21 | #endif 22 | 23 | .payload : 24 | { 25 | PROVIDE(_payload_start = .); 26 | *(.payload) 27 | . = ALIGN(8); 28 | PROVIDE(_payload_end = .); 29 | } 30 | 31 | PROVIDE(_fw_reloc_end = .); 32 | } 33 | -------------------------------------------------------------------------------- /tools/opensbi/firmware/payloads/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | firmware-bins-$(FW_PAYLOAD) += payloads/test.bin 11 | 12 | test-y += test_head.o 13 | test-y += test_main.o 14 | 15 | %/test.o: $(foreach obj,$(test-y),%/$(obj)) 16 | $(call merge_objs,$@,$^) 17 | 18 | %/test.dep: $(foreach dep,$(test-y:.o=.dep),%/$(dep)) 19 | $(call merge_deps,$@,$^) 20 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/riscv_elf.h: -------------------------------------------------------------------------------- 1 | #ifndef __RISCV_ELF_H__ 2 | #define __RISCV_ELF_H__ 3 | 4 | #include 5 | 6 | #define R_RISCV_32 1 7 | #define R_RISCV_64 2 8 | #define R_RISCV_RELATIVE 3 9 | 10 | #define RELOC_TYPE __REG_SEL(R_RISCV_64, R_RISCV_32) 11 | #define SYM_INDEX __REG_SEL(0x20, 0x8) 12 | #define SYM_SIZE __REG_SEL(0x18,0x10) 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/riscv_locks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * Copyright (c) 2021 Christoph Müllner 6 | */ 7 | 8 | #ifndef __RISCV_LOCKS_H__ 9 | #define __RISCV_LOCKS_H__ 10 | 11 | #include 12 | 13 | #define TICKET_SHIFT 16 14 | 15 | typedef struct { 16 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 17 | u16 next; 18 | u16 owner; 19 | #else 20 | u16 owner; 21 | u16 next; 22 | #endif 23 | } __aligned(4) spinlock_t; 24 | 25 | #define __SPIN_LOCK_UNLOCKED \ 26 | (spinlock_t) { 0, 0 } 27 | 28 | #define SPIN_LOCK_INIT(x) \ 29 | x = __SPIN_LOCK_UNLOCKED 30 | 31 | #define SPIN_LOCK_INITIALIZER \ 32 | __SPIN_LOCK_UNLOCKED 33 | 34 | #define DEFINE_SPIN_LOCK(x) \ 35 | spinlock_t SPIN_LOCK_INIT(x) 36 | 37 | bool spin_lock_check(spinlock_t *lock); 38 | 39 | bool spin_trylock(spinlock_t *lock); 40 | 41 | void spin_lock(spinlock_t *lock); 42 | 43 | void spin_unlock(spinlock_t *lock); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_CONST_H__ 11 | #define __SBI_CONST_H__ 12 | 13 | /* 14 | * Some constant macros are used in both assembler and 15 | * C code. Therefore we cannot annotate them always with 16 | * 'UL' and other type specifiers unilaterally. We 17 | * use the following macros to deal with this. 18 | * 19 | * Similarly, _AT() will cast an expression with a type in C, but 20 | * leave it unchanged in asm. 21 | */ 22 | 23 | /* clang-format off */ 24 | 25 | #ifdef __ASSEMBLER__ 26 | #define _AC(X,Y) X 27 | #define _AT(T,X) X 28 | #else 29 | #define __AC(X,Y) (X##Y) 30 | #define _AC(X,Y) __AC(X,Y) 31 | #define _AT(T,X) ((T)(X)) 32 | #endif 33 | 34 | #define _UL(x) (_AC(x, UL)) 35 | #define _ULL(x) (_AC(x, ULL)) 36 | 37 | #define _BITUL(x) (_UL(1) << (x)) 38 | #define _BITULL(x) (_ULL(1) << (x)) 39 | 40 | #define UL(x) (_UL(x)) 41 | #define ULL(x) (_ULL(x)) 42 | 43 | #define __STR(s) #s 44 | #define STRINGIFY(s) __STR(s) 45 | 46 | /* clang-format on */ 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_ecall.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_ECALL_H__ 11 | #define __SBI_ECALL_H__ 12 | 13 | #include 14 | #include 15 | 16 | #define SBI_ECALL_VERSION_MAJOR 1 17 | #define SBI_ECALL_VERSION_MINOR 0 18 | #define SBI_OPENSBI_IMPID 1 19 | 20 | struct sbi_trap_regs; 21 | struct sbi_trap_info; 22 | 23 | struct sbi_ecall_extension { 24 | struct sbi_dlist head; 25 | unsigned long extid_start; 26 | unsigned long extid_end; 27 | int (* probe)(unsigned long extid, unsigned long *out_val); 28 | int (* handle)(unsigned long extid, unsigned long funcid, 29 | const struct sbi_trap_regs *regs, 30 | unsigned long *out_val, 31 | struct sbi_trap_info *out_trap); 32 | }; 33 | 34 | u16 sbi_ecall_version_major(void); 35 | 36 | u16 sbi_ecall_version_minor(void); 37 | 38 | unsigned long sbi_ecall_get_impid(void); 39 | 40 | void sbi_ecall_set_impid(unsigned long impid); 41 | 42 | struct sbi_ecall_extension *sbi_ecall_find_extension(unsigned long extid); 43 | 44 | int sbi_ecall_register_extension(struct sbi_ecall_extension *ext); 45 | 46 | void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext); 47 | 48 | int sbi_ecall_handler(struct sbi_trap_regs *regs); 49 | 50 | int sbi_ecall_init(void); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_emulate_csr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_EMULATE_CSR_H__ 11 | #define __SBI_EMULATE_CSR_H__ 12 | 13 | #include 14 | 15 | struct sbi_trap_regs; 16 | 17 | int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs, 18 | ulong *csr_val); 19 | 20 | int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs, 21 | ulong csr_val); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_ERROR_H__ 11 | #define __SBI_ERROR_H__ 12 | 13 | #include 14 | 15 | /* clang-format off */ 16 | 17 | #define SBI_OK 0 18 | #define SBI_EFAIL SBI_ERR_FAILED 19 | #define SBI_ENOTSUPP SBI_ERR_NOT_SUPPORTED 20 | #define SBI_EINVAL SBI_ERR_INVALID_PARAM 21 | #define SBI_EDENIED SBI_ERR_DENIED 22 | #define SBI_EINVALID_ADDR SBI_ERR_INVALID_ADDRESS 23 | #define SBI_EALREADY SBI_ERR_ALREADY_AVAILABLE 24 | #define SBI_EALREADY_STARTED SBI_ERR_ALREADY_STARTED 25 | #define SBI_EALREADY_STOPPED SBI_ERR_ALREADY_STOPPED 26 | 27 | #define SBI_ENODEV -1000 28 | #define SBI_ENOSYS -1001 29 | #define SBI_ETIMEDOUT -1002 30 | #define SBI_EIO -1003 31 | #define SBI_EILL -1004 32 | #define SBI_ENOSPC -1005 33 | #define SBI_ENOMEM -1006 34 | #define SBI_ETRAP -1007 35 | #define SBI_EUNKNOWN -1008 36 | #define SBI_ENOENT -1009 37 | 38 | /* clang-format on */ 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_fifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Atish Patra 8 | * 9 | */ 10 | 11 | #ifndef __SBI_FIFO_H__ 12 | #define __SBI_FIFO_H__ 13 | 14 | #include 15 | #include 16 | 17 | struct sbi_fifo { 18 | void *queue; 19 | spinlock_t qlock; 20 | u16 entry_size; 21 | u16 num_entries; 22 | u16 avail; 23 | u16 tail; 24 | }; 25 | 26 | enum sbi_fifo_inplace_update_types { 27 | SBI_FIFO_SKIP, 28 | SBI_FIFO_UPDATED, 29 | SBI_FIFO_UNCHANGED, 30 | }; 31 | 32 | int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data); 33 | int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data); 34 | void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries, 35 | u16 entry_size); 36 | int sbi_fifo_is_empty(struct sbi_fifo *fifo); 37 | int sbi_fifo_is_full(struct sbi_fifo *fifo); 38 | int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in, 39 | int (*fptr)(void *in, void *data)); 40 | u16 sbi_fifo_avail(struct sbi_fifo *fifo); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_hfence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Atish Patra 8 | * Anup Patel 9 | */ 10 | 11 | #ifndef __SBI_FENCE_H__ 12 | #define __SBI_FENCE_H__ 13 | 14 | /** Invalidate Stage2 TLBs for given VMID and guest physical address */ 15 | void __sbi_hfence_gvma_vmid_gpa(unsigned long gpa_divby_4, 16 | unsigned long vmid); 17 | 18 | /** Invalidate Stage2 TLBs for given VMID */ 19 | void __sbi_hfence_gvma_vmid(unsigned long vmid); 20 | 21 | /** Invalidate Stage2 TLBs for given guest physical address */ 22 | void __sbi_hfence_gvma_gpa(unsigned long gpa_divby_4); 23 | 24 | /** Invalidate all possible Stage2 TLBs */ 25 | void __sbi_hfence_gvma_all(void); 26 | 27 | /** Invalidate unified TLB entries for given asid and guest virtual address */ 28 | void __sbi_hfence_vvma_asid_va(unsigned long va, unsigned long asid); 29 | 30 | /** Invalidate unified TLB entries for given ASID for a guest*/ 31 | void __sbi_hfence_vvma_asid(unsigned long asid); 32 | 33 | /** Invalidate unified TLB entries for a given guest virtual address */ 34 | void __sbi_hfence_vvma_va(unsigned long va); 35 | 36 | /** Invalidate all possible Stage2 TLBs */ 37 | void __sbi_hfence_vvma_all(void); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_illegal_insn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_ILLEGAl_INSN_H__ 11 | #define __SBI_ILLEGAl_INSN_H__ 12 | 13 | #include 14 | 15 | struct sbi_trap_regs; 16 | 17 | int sbi_illegal_insn_handler(ulong insn, struct sbi_trap_regs *regs); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_INIT_H__ 11 | #define __SBI_INIT_H__ 12 | 13 | #include 14 | 15 | struct sbi_scratch; 16 | 17 | void __noreturn sbi_init(struct sbi_scratch *scratch); 18 | 19 | unsigned long sbi_init_count(u32 hartid); 20 | 21 | void __noreturn sbi_exit(struct sbi_scratch *scratch); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_irqchip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Ventana Micro Systems Inc. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_IRQCHIP_H__ 11 | #define __SBI_IRQCHIP_H__ 12 | 13 | #include 14 | 15 | struct sbi_scratch; 16 | struct sbi_trap_regs; 17 | 18 | /** 19 | * Set external interrupt handling function 20 | * 21 | * This function is called by OpenSBI platform code to set a handler for 22 | * external interrupts 23 | * 24 | * @param fn function pointer for handling external irqs 25 | */ 26 | void sbi_irqchip_set_irqfn(int (*fn)(struct sbi_trap_regs *regs)); 27 | 28 | /** 29 | * Process external interrupts 30 | * 31 | * This function is called by sbi_trap_handler() to handle external 32 | * interrupts. 33 | * 34 | * @param regs pointer for trap registers 35 | */ 36 | int sbi_irqchip_process(struct sbi_trap_regs *regs); 37 | 38 | /** Initialize interrupt controllers */ 39 | int sbi_irqchip_init(struct sbi_scratch *scratch, bool cold_boot); 40 | 41 | /** Exit interrupt controllers */ 42 | void sbi_irqchip_exit(struct sbi_scratch *scratch); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_math.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Atish Patra 8 | */ 9 | 10 | #ifndef __SBI_MATH_H__ 11 | #define __SBI_MATH_H__ 12 | 13 | unsigned long log2roundup(unsigned long x); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_misaligned_ldst.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_MISALIGNED_LDST_H__ 11 | #define __SBI_MISALIGNED_LDST_H__ 12 | 13 | #include 14 | 15 | struct sbi_trap_regs; 16 | 17 | int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, 18 | struct sbi_trap_regs *regs); 19 | 20 | int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, 21 | struct sbi_trap_regs *regs); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Atish Patra 8 | */ 9 | 10 | #ifndef __STRING_H__ 11 | #define __STRING_H__ 12 | 13 | #include 14 | 15 | /* 16 | Provides sbi_strcmp for the completeness of supporting string functions. 17 | it is not recommended to use sbi_strcmp() but use sbi_strncmp instead. 18 | */ 19 | 20 | int sbi_strcmp(const char *a, const char *b); 21 | 22 | int sbi_strncmp(const char *a, const char *b, size_t count); 23 | 24 | size_t sbi_strlen(const char *str); 25 | 26 | size_t sbi_strnlen(const char *str, size_t count); 27 | 28 | char *sbi_strcpy(char *dest, const char *src); 29 | 30 | char *sbi_strncpy(char *dest, const char *src, size_t count); 31 | 32 | char *sbi_strchr(const char *s, int c); 33 | 34 | char *sbi_strrchr(const char *s, int c); 35 | 36 | void *sbi_memset(void *s, int c, size_t count); 37 | 38 | void *sbi_memcpy(void *dest, const void *src, size_t count); 39 | 40 | void *sbi_memmove(void *dest, const void *src, size_t count); 41 | 42 | int sbi_memcmp(const void *s1, const void *s2, size_t count); 43 | 44 | void *sbi_memchr(const void *s, int c, size_t count); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_SYSTEM_H__ 11 | #define __SBI_SYSTEM_H__ 12 | 13 | #include 14 | #include 15 | 16 | /** System reset hardware device */ 17 | struct sbi_system_reset_device { 18 | /** Name of the system reset device */ 19 | char name[32]; 20 | 21 | /* Check whether reset type and reason supported by the device */ 22 | int (*system_reset_check)(u32 reset_type, u32 reset_reason); 23 | 24 | /** Reset the system */ 25 | void (*system_reset)(u32 reset_type, u32 reset_reason); 26 | 27 | /** List */ 28 | struct sbi_dlist node; 29 | }; 30 | 31 | static inline struct sbi_system_reset_device *to_system_reset_device( 32 | struct sbi_dlist *node) 33 | { 34 | return container_of(node, struct sbi_system_reset_device, node); 35 | } 36 | 37 | const struct sbi_system_reset_device *sbi_system_reset_get_device( 38 | u32 reset_type, u32 reset_reason); 39 | 40 | void sbi_system_reset_add_device(struct sbi_system_reset_device *dev); 41 | 42 | bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason); 43 | 44 | void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_unpriv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_UNPRIV_H__ 11 | #define __SBI_UNPRIV_H__ 12 | 13 | #include 14 | 15 | struct sbi_scratch; 16 | struct sbi_trap_info; 17 | 18 | #define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type) \ 19 | type sbi_load_##type(const type *addr, \ 20 | struct sbi_trap_info *trap); 21 | 22 | #define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type) \ 23 | void sbi_store_##type(type *addr, type val, \ 24 | struct sbi_trap_info *trap); 25 | 26 | DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u8) 27 | DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u16) 28 | DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s8) 29 | DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s16) 30 | DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s32) 31 | DECLARE_UNPRIVILEGED_STORE_FUNCTION(u8) 32 | DECLARE_UNPRIVILEGED_STORE_FUNCTION(u16) 33 | DECLARE_UNPRIVILEGED_STORE_FUNCTION(u32) 34 | DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u32) 35 | DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u64) 36 | DECLARE_UNPRIVILEGED_STORE_FUNCTION(u64) 37 | DECLARE_UNPRIVILEGED_LOAD_FUNCTION(ulong) 38 | 39 | ulong sbi_get_insn(ulong mepc, struct sbi_trap_info *trap); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi/sbi_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SBI_VERSION_H__ 11 | #define __SBI_VERSION_H__ 12 | 13 | #define OPENSBI_VERSION_MAJOR 1 14 | #define OPENSBI_VERSION_MINOR 2 15 | 16 | /** 17 | * OpenSBI 32-bit version with: 18 | * 1. upper 16-bits as major number 19 | * 2. lower 16-bits as minor number 20 | */ 21 | #define OPENSBI_VERSION ((OPENSBI_VERSION_MAJOR << 16) | \ 22 | (OPENSBI_VERSION_MINOR)) 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/gpio/fdt_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __FDT_GPIO_H__ 11 | #define __FDT_GPIO_H__ 12 | 13 | #include 14 | 15 | struct fdt_phandle_args; 16 | 17 | /** FDT based GPIO driver */ 18 | struct fdt_gpio { 19 | const struct fdt_match *match_table; 20 | int (*xlate)(struct gpio_chip *chip, 21 | const struct fdt_phandle_args *pargs, 22 | struct gpio_pin *out_pin); 23 | int (*init)(void *fdt, int nodeoff, u32 phandle, 24 | const struct fdt_match *match); 25 | }; 26 | 27 | /** Get a GPIO pin using "gpios" DT property of client DT node */ 28 | int fdt_gpio_pin_get(void *fdt, int nodeoff, int index, 29 | struct gpio_pin *out_pin); 30 | 31 | /** Simple xlate function to convert two GPIO FDT cells into GPIO pin */ 32 | int fdt_gpio_simple_xlate(struct gpio_chip *chip, 33 | const struct fdt_phandle_args *pargs, 34 | struct gpio_pin *out_pin); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/i2c/fdt_i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 YADRO 5 | * 6 | * Authors: 7 | * Nikita Shubin 8 | */ 9 | 10 | #ifndef __FDT_I2C_H__ 11 | #define __FDT_I2C_H__ 12 | 13 | #include 14 | 15 | /** FDT based I2C adapter driver */ 16 | struct fdt_i2c_adapter { 17 | const struct fdt_match *match_table; 18 | int (*init)(void *fdt, int nodeoff, 19 | const struct fdt_match *match); 20 | }; 21 | 22 | /** Get I2C adapter identified by nodeoff */ 23 | int fdt_i2c_adapter_get(void *fdt, int nodeoff, 24 | struct i2c_adapter **out_adapter); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/ipi/aclint_mswi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __IPI_ACLINT_MSWI_H__ 11 | #define __IPI_ACLINT_MSWI_H__ 12 | 13 | #include 14 | 15 | #define ACLINT_MSWI_ALIGN 0x1000 16 | #define ACLINT_MSWI_SIZE 0x4000 17 | #define ACLINT_MSWI_MAX_HARTS 4095 18 | 19 | #define CLINT_MSWI_OFFSET 0x0000 20 | 21 | struct aclint_mswi_data { 22 | /* Public details */ 23 | unsigned long addr; 24 | unsigned long size; 25 | u32 first_hartid; 26 | u32 hart_count; 27 | }; 28 | 29 | int aclint_mswi_warm_init(void); 30 | 31 | int aclint_mswi_cold_init(struct aclint_mswi_data *mswi); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/ipi/andes_plicsw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Andes Technology Corporation 5 | * 6 | * Authors: 7 | * Zong Li 8 | * Nylon Chen 9 | * Leo Yu-Chi Liang 10 | * Yu Chien Peter Lin 11 | */ 12 | 13 | #ifndef _IPI_ANDES_PLICSW_H_ 14 | #define _IPI_ANDES_PLICSW_H_ 15 | 16 | #define PLICSW_PRIORITY_BASE 0x4 17 | 18 | #define PLICSW_PENDING_BASE 0x1000 19 | #define PLICSW_PENDING_STRIDE 0x8 20 | 21 | #define PLICSW_ENABLE_BASE 0x2000 22 | #define PLICSW_ENABLE_STRIDE 0x80 23 | 24 | #define PLICSW_CONTEXT_BASE 0x200000 25 | #define PLICSW_CONTEXT_STRIDE 0x1000 26 | #define PLICSW_CONTEXT_CLAIM 0x4 27 | 28 | #define PLICSW_HART_MASK 0x01010101 29 | 30 | #define PLICSW_HART_MAX_NR 8 31 | 32 | #define PLICSW_REGION_ALIGN 0x1000 33 | 34 | struct plicsw_data { 35 | unsigned long addr; 36 | unsigned long size; 37 | uint32_t hart_count; 38 | /* hart id to source id table */ 39 | uint32_t source_id[PLICSW_HART_MAX_NR]; 40 | }; 41 | 42 | int plicsw_warm_ipi_init(void); 43 | 44 | int plicsw_cold_ipi_init(struct plicsw_data *plicsw); 45 | 46 | #endif /* _IPI_ANDES_PLICSW_H_ */ 47 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/ipi/fdt_ipi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __FDT_IPI_H__ 11 | #define __FDT_IPI_H__ 12 | 13 | #include 14 | 15 | #ifdef CONFIG_FDT_IPI 16 | 17 | struct fdt_ipi { 18 | const struct fdt_match *match_table; 19 | int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); 20 | int (*warm_init)(void); 21 | void (*exit)(void); 22 | }; 23 | 24 | void fdt_ipi_exit(void); 25 | 26 | int fdt_ipi_init(bool cold_boot); 27 | 28 | #else 29 | 30 | static inline void fdt_ipi_exit(void) { } 31 | static inline int fdt_ipi_init(bool cold_boot) { return 0; } 32 | 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/irqchip/aplic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Western Digital Corporation or its affiliates. 5 | * Copyright (c) 2022 Ventana Micro Systems Inc. 6 | * 7 | * Authors: 8 | * Anup Patel 9 | */ 10 | 11 | #ifndef __IRQCHIP_APLIC_H__ 12 | #define __IRQCHIP_APLIC_H__ 13 | 14 | #include 15 | 16 | #define APLIC_MAX_DELEGATE 16 17 | 18 | struct aplic_msicfg_data { 19 | unsigned long lhxs; 20 | unsigned long lhxw; 21 | unsigned long hhxs; 22 | unsigned long hhxw; 23 | unsigned long base_addr; 24 | }; 25 | 26 | struct aplic_delegate_data { 27 | u32 first_irq; 28 | u32 last_irq; 29 | u32 child_index; 30 | }; 31 | 32 | struct aplic_data { 33 | unsigned long addr; 34 | unsigned long size; 35 | unsigned long num_idc; 36 | unsigned long num_source; 37 | bool targets_mmode; 38 | bool has_msicfg_mmode; 39 | struct aplic_msicfg_data msicfg_mmode; 40 | bool has_msicfg_smode; 41 | struct aplic_msicfg_data msicfg_smode; 42 | struct aplic_delegate_data delegate[APLIC_MAX_DELEGATE]; 43 | }; 44 | 45 | int aplic_cold_irqchip_init(struct aplic_data *aplic); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/irqchip/fdt_irqchip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __FDT_IRQCHIP_H__ 11 | #define __FDT_IRQCHIP_H__ 12 | 13 | #include 14 | 15 | #ifdef CONFIG_FDT_IRQCHIP 16 | 17 | struct fdt_irqchip { 18 | const struct fdt_match *match_table; 19 | int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); 20 | int (*warm_init)(void); 21 | void (*exit)(void); 22 | }; 23 | 24 | void fdt_irqchip_exit(void); 25 | 26 | int fdt_irqchip_init(bool cold_boot); 27 | 28 | #else 29 | 30 | static inline void fdt_irqchip_exit(void) { } 31 | 32 | static inline int fdt_irqchip_init(bool cold_boot) { return 0; } 33 | 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/irqchip/fdt_irqchip_plic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Samuel Holland 5 | */ 6 | 7 | #ifndef __IRQCHIP_FDT_IRQCHIP_PLIC_H__ 8 | #define __IRQCHIP_FDT_IRQCHIP_PLIC_H__ 9 | 10 | #include 11 | 12 | /** 13 | * Save the PLIC priority state 14 | * @param priority pointer to the memory region for the saved priority 15 | * @param num size of the memory region including interrupt source 0 16 | */ 17 | void fdt_plic_priority_save(u8 *priority, u32 num); 18 | 19 | /** 20 | * Restore the PLIC priority state 21 | * @param priority pointer to the memory region for the saved priority 22 | * @param num size of the memory region including interrupt source 0 23 | */ 24 | void fdt_plic_priority_restore(const u8 *priority, u32 num); 25 | 26 | void fdt_plic_context_save(bool smode, u32 *enable, u32 *threshold, u32 num); 27 | 28 | void fdt_plic_context_restore(bool smode, const u32 *enable, u32 threshold, 29 | u32 num); 30 | 31 | void thead_plic_restore(void); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/irqchip/plic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __IRQCHIP_PLIC_H__ 11 | #define __IRQCHIP_PLIC_H__ 12 | 13 | #include 14 | 15 | struct plic_data { 16 | unsigned long addr; 17 | unsigned long num_src; 18 | }; 19 | 20 | /* So far, priorities on all consumers of these functions fit in 8 bits. */ 21 | void plic_priority_save(const struct plic_data *plic, u8 *priority, u32 num); 22 | 23 | void plic_priority_restore(const struct plic_data *plic, const u8 *priority, 24 | u32 num); 25 | 26 | void plic_context_save(const struct plic_data *plic, int context_id, 27 | u32 *enable, u32 *threshold, u32 num); 28 | 29 | void plic_context_restore(const struct plic_data *plic, int context_id, 30 | const u32 *enable, u32 threshold, u32 num); 31 | 32 | int plic_context_init(const struct plic_data *plic, int context_id, 33 | bool enable, u32 threshold); 34 | 35 | int plic_warm_irqchip_init(const struct plic_data *plic, 36 | int m_cntx_id, int s_cntx_id); 37 | 38 | int plic_cold_irqchip_init(const struct plic_data *plic); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/reset/fdt_reset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __FDT_RESET_H__ 11 | #define __FDT_RESET_H__ 12 | 13 | #include 14 | 15 | struct fdt_reset { 16 | const struct fdt_match *match_table; 17 | int (*init)(void *fdt, int nodeoff, const struct fdt_match *match); 18 | }; 19 | 20 | #ifdef CONFIG_FDT_RESET 21 | 22 | /** 23 | * fdt_reset_driver_init() - initialize reset driver based on the device-tree 24 | */ 25 | int fdt_reset_driver_init(void *fdt, struct fdt_reset *drv); 26 | 27 | /** 28 | * fdt_reset_init() - initialize reset drivers based on the device-tree 29 | * 30 | * This function shall be invoked in final init. 31 | */ 32 | void fdt_reset_init(void); 33 | 34 | #else 35 | 36 | static inline int fdt_reset_driver_init(void *fdt, struct fdt_reset *drv) 37 | { 38 | return 0; 39 | } 40 | static inline void fdt_reset_init(void) { } 41 | 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/cadence-uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 StarFive Technology Co., Ltd. 5 | * 6 | * Author: Jun Liang Tan 7 | */ 8 | 9 | #ifndef __SERIAL_CADENCE_UART_H__ 10 | #define __SERIAL_CADENCE_UART_H__ 11 | 12 | #include 13 | 14 | int cadence_uart_init(unsigned long base, u32 in_freq, u32 baudrate); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/fdt_serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __FDT_SERIAL_H__ 11 | #define __FDT_SERIAL_H__ 12 | 13 | #include 14 | 15 | #ifdef CONFIG_FDT_SERIAL 16 | 17 | struct fdt_serial { 18 | const struct fdt_match *match_table; 19 | int (*init)(void *fdt, int nodeoff, const struct fdt_match *match); 20 | }; 21 | 22 | int fdt_serial_init(void); 23 | 24 | #else 25 | 26 | static inline int fdt_serial_init(void) { return 0; } 27 | 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/gaisler-uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Cobham Gaisler AB. 5 | * 6 | * Authors: 7 | * Daniel Cederman 8 | */ 9 | 10 | #ifndef __SERIAL_GAISLER_APBUART_H__ 11 | #define __SERIAL_GAISLER_APBUART_H__ 12 | 13 | #include 14 | 15 | int gaisler_uart_init(unsigned long base, u32 in_freq, u32 baudrate); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/litex-uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Gabriel Somlo 5 | * 6 | * Authors: 7 | * Gabriel Somlo 8 | */ 9 | 10 | #ifndef __SERIAL_LITEX_UART_H__ 11 | #define __SERIAL_LITEX_UART_H__ 12 | 13 | #include 14 | 15 | int litex_uart_init(unsigned long base); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/renesas-scif.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause */ 2 | /* 3 | * Copyright (C) 2022 Renesas Electronics Corporation 4 | */ 5 | 6 | #ifndef __SERIAL_RENESAS_SCIF_H__ 7 | #define __SERIAL_RENESAS_SCIF_H__ 8 | 9 | int renesas_scif_init(unsigned long base, u32 in_freq, u32 baudrate); 10 | 11 | #endif /* __SERIAL_RENESAS_SCIF_H__ */ 12 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/semihosting.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Ventana Micro Systems Inc. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | * Kautuk Consul 9 | */ 10 | 11 | #ifndef __SERIAL_SEMIHOSTING_H__ 12 | #define __SERIAL_SEMIHOSTING_H__ 13 | 14 | #include 15 | 16 | /** 17 | * enum semihosting_open_mode - Numeric file modes for use with semihosting_open() 18 | * MODE_READ: 'r' 19 | * MODE_BINARY: 'b' 20 | * MODE_PLUS: '+' 21 | * MODE_WRITE: 'w' 22 | * MODE_APPEND: 'a' 23 | * 24 | * These modes represent the mode string used by fopen(3) in a form which can 25 | * be passed to semihosting_open(). These do NOT correspond directly to %O_RDONLY, 26 | * %O_CREAT, etc; see fopen(3) for details. In particular, @MODE_PLUS 27 | * effectively results in adding %O_RDWR, and @MODE_WRITE will add %O_TRUNC. 28 | * For compatibility, @MODE_BINARY should be added when opening non-text files 29 | * (such as images). 30 | */ 31 | enum semihosting_open_mode { 32 | MODE_READ = 0x0, 33 | MODE_BINARY = 0x1, 34 | MODE_PLUS = 0x2, 35 | MODE_WRITE = 0x4, 36 | MODE_APPEND = 0x8, 37 | }; 38 | 39 | #ifdef CONFIG_SERIAL_SEMIHOSTING 40 | int semihosting_init(void); 41 | int semihosting_enabled(void); 42 | #else 43 | static inline int semihosting_init(void) { return SBI_ENODEV; } 44 | static inline int semihosting_enabled(void) { return 0; } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/shakti-uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Vijai Kumar K 5 | */ 6 | 7 | #ifndef __SERIAL_SHAKTI_UART_H__ 8 | #define __SERIAL_SHAKTI_UART_H__ 9 | 10 | #include 11 | 12 | int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/sifive-uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SERIAL_SIFIVE_UART_H__ 11 | #define __SERIAL_SIFIVE_UART_H__ 12 | 13 | #include 14 | 15 | int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/uart8250.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SERIAL_UART8250_H__ 11 | #define __SERIAL_UART8250_H__ 12 | 13 | #include 14 | 15 | int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift, 16 | u32 reg_width, u32 reg_offset); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/serial/xlnx_uartlite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Alistair Francis 8 | */ 9 | #ifndef __SERIAL_XLNX_UARTLITE_H__ 10 | #define __SERIAL_XLNX_UARTLITE_H__ 11 | 12 | #include 13 | 14 | int xlnx_uartlite_init(unsigned long base); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/sys/htif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 2010-2020, The Regents of the University of California 5 | * (Regents). All Rights Reserved. 6 | */ 7 | 8 | #ifndef __SYS_HTIF_H__ 9 | #define __SYS_HTIF_H__ 10 | 11 | #include 12 | 13 | int htif_serial_init(bool custom_addr, 14 | unsigned long custom_fromhost_addr, 15 | unsigned long custom_tohost_addr); 16 | 17 | int htif_system_reset_init(bool custom_addr, 18 | unsigned long custom_fromhost_addr, 19 | unsigned long custom_tohost_addr); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/sys/sifive_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __SYS_SIFIVE_TEST_H__ 11 | #define __SYS_SIFIVE_TEST_H__ 12 | 13 | #include 14 | 15 | int sifive_test_init(unsigned long base); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/timer/andes_plmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Andes Technology Corporation 5 | * 6 | * Authors: 7 | * Zong Li 8 | * Nylon Chen 9 | * Yu Chien Peter Lin 10 | */ 11 | 12 | #ifndef __TIMER_ANDES_PLMT_H__ 13 | #define __TIMER_ANDES_PLMT_H__ 14 | 15 | #define DEFAULT_AE350_PLMT_FREQ 60000000 16 | #define PLMT_REGION_ALIGN 0x1000 17 | 18 | struct plmt_data { 19 | u32 hart_count; 20 | unsigned long size; 21 | unsigned long timer_freq; 22 | volatile u64 *time_val; 23 | volatile u64 *time_cmp; 24 | }; 25 | 26 | int plmt_cold_timer_init(struct plmt_data *plmt); 27 | int plmt_warm_timer_init(void); 28 | 29 | #endif /* __TIMER_ANDES_PLMT_H__ */ 30 | -------------------------------------------------------------------------------- /tools/opensbi/include/sbi_utils/timer/fdt_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __FDT_TIMER_H__ 11 | #define __FDT_TIMER_H__ 12 | 13 | #include 14 | 15 | #ifdef CONFIG_FDT_TIMER 16 | 17 | struct fdt_timer { 18 | const struct fdt_match *match_table; 19 | int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); 20 | int (*warm_init)(void); 21 | void (*exit)(void); 22 | }; 23 | 24 | void fdt_timer_exit(void); 25 | 26 | int fdt_timer_init(bool cold_boot); 27 | 28 | #else 29 | 30 | static inline void fdt_timer_exit(void) { } 31 | static inline int fdt_timer_init(bool cold_boot) { return 0; } 32 | 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /tools/opensbi/lib/sbi/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "SBI Extension Support" 4 | 5 | config SBI_ECALL_TIME 6 | bool "Timer extension" 7 | default y 8 | 9 | config SBI_ECALL_RFENCE 10 | bool "RFENCE extension" 11 | default y 12 | 13 | config SBI_ECALL_IPI 14 | bool "IPI extension" 15 | default y 16 | 17 | config SBI_ECALL_HSM 18 | bool "Hart State Management extension" 19 | default y 20 | 21 | config SBI_ECALL_SRST 22 | bool "System Reset extension" 23 | default y 24 | 25 | config SBI_ECALL_PMU 26 | bool "Performance Monitoring Unit extension" 27 | default y 28 | 29 | config SBI_ECALL_LEGACY 30 | bool "SBI v0.1 legacy extensions" 31 | default y 32 | 33 | config SBI_ECALL_VENDOR 34 | bool "Platform-defined vendor extensions" 35 | default y 36 | 37 | endmenu 38 | -------------------------------------------------------------------------------- /tools/opensbi/lib/sbi/sbi_bitmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | 12 | void __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 13 | const unsigned long *bitmap2, int bits) 14 | { 15 | int k; 16 | int nr = BITS_TO_LONGS(bits); 17 | 18 | for (k = 0; k < nr; k++) 19 | dst[k] = bitmap1[k] & bitmap2[k]; 20 | } 21 | 22 | void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, 23 | const unsigned long *bitmap2, int bits) 24 | { 25 | int k; 26 | int nr = BITS_TO_LONGS(bits); 27 | 28 | for (k = 0; k < nr; k++) 29 | dst[k] = bitmap1[k] | bitmap2[k]; 30 | } 31 | 32 | void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, 33 | const unsigned long *bitmap2, int bits) 34 | { 35 | int k; 36 | int nr = BITS_TO_LONGS(bits); 37 | 38 | for (k = 0; k < nr; k++) 39 | dst[k] = bitmap1[k] ^ bitmap2[k]; 40 | } 41 | -------------------------------------------------------------------------------- /tools/opensbi/lib/sbi/sbi_ecall_exts.carray: -------------------------------------------------------------------------------- 1 | HEADER: sbi/sbi_ecall.h 2 | TYPE: struct sbi_ecall_extension 3 | NAME: sbi_ecall_exts 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/sbi/sbi_ecall_ipi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | * Atish Patra 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | static int sbi_ecall_ipi_handler(unsigned long extid, unsigned long funcid, 18 | const struct sbi_trap_regs *regs, 19 | unsigned long *out_val, 20 | struct sbi_trap_info *out_trap) 21 | { 22 | int ret = 0; 23 | 24 | if (funcid == SBI_EXT_IPI_SEND_IPI) 25 | ret = sbi_ipi_send_smode(regs->a0, regs->a1); 26 | else 27 | ret = SBI_ENOTSUPP; 28 | 29 | return ret; 30 | } 31 | 32 | struct sbi_ecall_extension ecall_ipi = { 33 | .extid_start = SBI_EXT_IPI, 34 | .extid_end = SBI_EXT_IPI, 35 | .handle = sbi_ecall_ipi_handler, 36 | }; 37 | -------------------------------------------------------------------------------- /tools/opensbi/lib/sbi/sbi_ecall_time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | * Atish Patra 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | static int sbi_ecall_time_handler(unsigned long extid, unsigned long funcid, 18 | const struct sbi_trap_regs *regs, 19 | unsigned long *out_val, 20 | struct sbi_trap_info *out_trap) 21 | { 22 | int ret = 0; 23 | 24 | if (funcid == SBI_EXT_TIME_SET_TIMER) { 25 | #if __riscv_xlen == 32 26 | sbi_timer_event_start((((u64)regs->a1 << 32) | (u64)regs->a0)); 27 | #else 28 | sbi_timer_event_start((u64)regs->a0); 29 | #endif 30 | } else 31 | ret = SBI_ENOTSUPP; 32 | 33 | return ret; 34 | } 35 | 36 | struct sbi_ecall_extension ecall_time = { 37 | .extid_start = SBI_EXT_TIME, 38 | .extid_end = SBI_EXT_TIME, 39 | .handle = sbi_ecall_time_handler, 40 | }; 41 | -------------------------------------------------------------------------------- /tools/opensbi/lib/sbi/sbi_ecall_vendor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | * Atish Patra 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | static int sbi_ecall_vendor_probe(unsigned long extid, 18 | unsigned long *out_val) 19 | { 20 | *out_val = sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr(), 21 | extid); 22 | return 0; 23 | } 24 | 25 | static int sbi_ecall_vendor_handler(unsigned long extid, unsigned long funcid, 26 | const struct sbi_trap_regs *regs, 27 | unsigned long *out_val, 28 | struct sbi_trap_info *out_trap) 29 | { 30 | return sbi_platform_vendor_ext_provider(sbi_platform_thishart_ptr(), 31 | extid, funcid, regs, 32 | out_val, out_trap); 33 | } 34 | 35 | struct sbi_ecall_extension ecall_vendor = { 36 | .extid_start = SBI_EXT_VENDOR_START, 37 | .extid_end = SBI_EXT_VENDOR_END, 38 | .probe = sbi_ecall_vendor_probe, 39 | .handle = sbi_ecall_vendor_handler, 40 | }; 41 | -------------------------------------------------------------------------------- /tools/opensbi/lib/sbi/sbi_irqchip.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Ventana Micro Systems Inc. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | static int default_irqfn(struct sbi_trap_regs *regs) 14 | { 15 | return SBI_ENODEV; 16 | } 17 | 18 | static int (*ext_irqfn)(struct sbi_trap_regs *regs) = default_irqfn; 19 | 20 | void sbi_irqchip_set_irqfn(int (*fn)(struct sbi_trap_regs *regs)) 21 | { 22 | if (fn) 23 | ext_irqfn = fn; 24 | } 25 | 26 | int sbi_irqchip_process(struct sbi_trap_regs *regs) 27 | { 28 | return ext_irqfn(regs); 29 | } 30 | 31 | int sbi_irqchip_init(struct sbi_scratch *scratch, bool cold_boot) 32 | { 33 | int rc; 34 | const struct sbi_platform *plat = sbi_platform_ptr(scratch); 35 | 36 | rc = sbi_platform_irqchip_init(plat, cold_boot); 37 | if (rc) 38 | return rc; 39 | 40 | if (ext_irqfn != default_irqfn) 41 | csr_set(CSR_MIE, MIP_MEIP); 42 | 43 | return 0; 44 | } 45 | 46 | void sbi_irqchip_exit(struct sbi_scratch *scratch) 47 | { 48 | const struct sbi_platform *plat = sbi_platform_ptr(scratch); 49 | 50 | if (ext_irqfn != default_irqfn) 51 | csr_clear(CSR_MIE, MIP_MEIP); 52 | 53 | sbi_platform_irqchip_exit(plat); 54 | } 55 | -------------------------------------------------------------------------------- /tools/opensbi/lib/sbi/sbi_math.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Common helper functions used across OpenSBI project. 7 | * 8 | * Authors: 9 | * Atish Patra 10 | */ 11 | 12 | unsigned long log2roundup(unsigned long x) 13 | { 14 | unsigned long ret = 0; 15 | 16 | while (ret < __riscv_xlen) { 17 | if (x <= (1UL << ret)) 18 | break; 19 | ret++; 20 | } 21 | 22 | return ret; 23 | } 24 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "Utils and Drivers Support" 4 | 5 | source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig" 6 | 7 | source "$(OPENSBI_SRC_DIR)/lib/utils/gpio/Kconfig" 8 | 9 | source "$(OPENSBI_SRC_DIR)/lib/utils/i2c/Kconfig" 10 | 11 | source "$(OPENSBI_SRC_DIR)/lib/utils/ipi/Kconfig" 12 | 13 | source "$(OPENSBI_SRC_DIR)/lib/utils/irqchip/Kconfig" 14 | 15 | source "$(OPENSBI_SRC_DIR)/lib/utils/libfdt/Kconfig" 16 | 17 | source "$(OPENSBI_SRC_DIR)/lib/utils/reset/Kconfig" 18 | 19 | source "$(OPENSBI_SRC_DIR)/lib/utils/serial/Kconfig" 20 | 21 | source "$(OPENSBI_SRC_DIR)/lib/utils/sys/Kconfig" 22 | 23 | source "$(OPENSBI_SRC_DIR)/lib/utils/timer/Kconfig" 24 | 25 | endmenu 26 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/fdt/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menuconfig FDT 4 | bool "Flattened Device Tree (FDT) support" 5 | select LIBFDT 6 | default n 7 | 8 | if FDT 9 | 10 | config FDT_DOMAIN 11 | bool "FDT domain support" 12 | default n 13 | 14 | config FDT_PMU 15 | bool "FDT performance monitoring unit (PMU) support" 16 | default n 17 | 18 | endif 19 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/fdt/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (C) 2020 Bin Meng 5 | # 6 | 7 | libsbiutils-objs-$(CONFIG_FDT_DOMAIN) += fdt/fdt_domain.o 8 | libsbiutils-objs-$(CONFIG_FDT_PMU) += fdt/fdt_pmu.o 9 | libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_helper.o 10 | libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_fixup.o 11 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/gpio/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "GPIO Support" 4 | 5 | config FDT_GPIO 6 | bool "FDT based GPIO drivers" 7 | depends on FDT 8 | select GPIO 9 | default n 10 | 11 | if FDT_GPIO 12 | 13 | config FDT_GPIO_SIFIVE 14 | bool "SiFive GPIO FDT driver" 15 | default n 16 | 17 | endif 18 | 19 | config GPIO 20 | bool "GPIO support" 21 | default n 22 | 23 | endmenu 24 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/gpio/fdt_gpio_drivers.carray: -------------------------------------------------------------------------------- 1 | HEADER: sbi_utils/gpio/fdt_gpio.h 2 | TYPE: struct fdt_gpio 3 | NAME: fdt_gpio_drivers 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/gpio/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2021 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | libsbiutils-objs-$(CONFIG_FDT_GPIO) += gpio/fdt_gpio.o 11 | libsbiutils-objs-$(CONFIG_FDT_GPIO) += gpio/fdt_gpio_drivers.o 12 | 13 | carray-fdt_gpio_drivers-$(CONFIG_FDT_GPIO_SIFIVE) += fdt_gpio_sifive 14 | libsbiutils-objs-$(CONFIG_FDT_GPIO_SIFIVE) += gpio/fdt_gpio_sifive.o 15 | 16 | libsbiutils-objs-$(CONFIG_GPIO) += gpio/gpio.o 17 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/i2c/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "I2C Support" 4 | 5 | config FDT_I2C 6 | bool "FDT based I2C drivers" 7 | depends on FDT 8 | select I2C 9 | default n 10 | 11 | if FDT_I2C 12 | 13 | config FDT_I2C_SIFIVE 14 | bool "SiFive I2C FDT driver" 15 | default n 16 | 17 | endif 18 | 19 | config I2C 20 | bool "I2C support" 21 | default n 22 | 23 | endmenu 24 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/i2c/fdt_i2c_adapter_drivers.carray: -------------------------------------------------------------------------------- 1 | HEADER: sbi_utils/i2c/fdt_i2c.h 2 | TYPE: struct fdt_i2c_adapter 3 | NAME: fdt_i2c_adapter_drivers 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/i2c/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2021 YADRO 5 | # 6 | # Authors: 7 | # Nikita Shubin 8 | # 9 | 10 | libsbiutils-objs-$(CONFIG_I2C) += i2c/i2c.o 11 | 12 | libsbiutils-objs-$(CONFIG_FDT_I2C) += i2c/fdt_i2c.o 13 | libsbiutils-objs-$(CONFIG_FDT_I2C) += i2c/fdt_i2c_adapter_drivers.o 14 | 15 | carray-fdt_i2c_adapter_drivers-$(CONFIG_FDT_I2C_SIFIVE) += fdt_i2c_adapter_sifive 16 | libsbiutils-objs-$(CONFIG_FDT_I2C_SIFIVE) += i2c/fdt_i2c_sifive.o 17 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/ipi/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "IPI Device Support" 4 | 5 | config FDT_IPI 6 | bool "FDT based ipi drivers" 7 | depends on FDT 8 | default n 9 | 10 | if FDT_IPI 11 | 12 | config FDT_IPI_MSWI 13 | bool "ACLINT MSWI FDT driver" 14 | select IPI_MSWI 15 | default n 16 | 17 | config FDT_IPI_PLICSW 18 | bool "Andes PLICSW FDT driver" 19 | select IPI_PLICSW 20 | default n 21 | 22 | endif 23 | 24 | config IPI_MSWI 25 | bool "ACLINT MSWI support" 26 | default n 27 | 28 | config IPI_PLICSW 29 | bool "Andes PLICSW support" 30 | default n 31 | 32 | endmenu 33 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/ipi/fdt_ipi_drivers.carray: -------------------------------------------------------------------------------- 1 | HEADER: sbi_utils/ipi/fdt_ipi.h 2 | TYPE: struct fdt_ipi 3 | NAME: fdt_ipi_drivers 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/ipi/fdt_ipi_plicsw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Andes Technology Corporation 5 | * 6 | * Authors: 7 | * Zong Li 8 | * Nylon Chen 9 | * Leo Yu-Chi Liang 10 | * Yu Chien Peter Lin 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | extern struct plicsw_data plicsw; 19 | 20 | int fdt_plicsw_cold_ipi_init(void *fdt, int nodeoff, 21 | const struct fdt_match *match) 22 | { 23 | int rc; 24 | 25 | rc = fdt_parse_plicsw_node(fdt, nodeoff, &plicsw.addr, &plicsw.size, 26 | &plicsw.hart_count); 27 | if (rc) 28 | return rc; 29 | 30 | rc = plicsw_cold_ipi_init(&plicsw); 31 | if (rc) 32 | return rc; 33 | 34 | return 0; 35 | } 36 | 37 | static const struct fdt_match ipi_plicsw_match[] = { 38 | { .compatible = "andestech,plicsw" }, 39 | {}, 40 | }; 41 | 42 | struct fdt_ipi fdt_ipi_plicsw = { 43 | .match_table = ipi_plicsw_match, 44 | .cold_init = fdt_plicsw_cold_ipi_init, 45 | .warm_init = plicsw_warm_ipi_init, 46 | .exit = NULL, 47 | }; 48 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/ipi/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | libsbiutils-objs-$(CONFIG_IPI_MSWI) += ipi/aclint_mswi.o 11 | libsbiutils-objs-$(CONFIG_IPI_PLICSW) += ipi/andes_plicsw.o 12 | 13 | libsbiutils-objs-$(CONFIG_FDT_IPI) += ipi/fdt_ipi.o 14 | libsbiutils-objs-$(CONFIG_FDT_IPI) += ipi/fdt_ipi_drivers.o 15 | 16 | carray-fdt_ipi_drivers-$(CONFIG_FDT_IPI_MSWI) += fdt_ipi_mswi 17 | libsbiutils-objs-$(CONFIG_FDT_IPI_MSWI) += ipi/fdt_ipi_mswi.o 18 | 19 | carray-fdt_ipi_drivers-$(CONFIG_FDT_IPI_PLICSW) += fdt_ipi_plicsw 20 | libsbiutils-objs-$(CONFIG_FDT_IPI_PLICSW) += ipi/fdt_ipi_plicsw.o 21 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/irqchip/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "Interrupt Controller Support" 4 | 5 | config FDT_IRQCHIP 6 | bool "FDT based interrupt controller drivers" 7 | depends on FDT 8 | default n 9 | 10 | if FDT_IRQCHIP 11 | 12 | config FDT_IRQCHIP_APLIC 13 | bool "Advanced Platform Level Interrupt Controller (APLIC) FDT driver" 14 | select IRQCHIP_APLIC 15 | default n 16 | 17 | config FDT_IRQCHIP_IMSIC 18 | bool "Incoming Message Signalled Interrupt Controller (IMSIC) FDT driver" 19 | select IRQCHIP_IMSIC 20 | default n 21 | 22 | config FDT_IRQCHIP_PLIC 23 | bool "Platform Level Interrupt Controller (PLIC) FDT driver" 24 | select IRQCHIP_PLIC 25 | default n 26 | 27 | endif 28 | 29 | config IRQCHIP_APLIC 30 | bool "Advanced Platform Level Interrupt Controller (APLIC) support" 31 | default n 32 | 33 | config IRQCHIP_IMSIC 34 | bool "Incoming Message Signalled Interrupt Controller (IMSIC) support" 35 | default n 36 | 37 | config IRQCHIP_PLIC 38 | bool "Platform Level Interrupt Controller (PLIC) support" 39 | default n 40 | 41 | endmenu 42 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/irqchip/fdt_irqchip_aplic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Western Digital Corporation or its affiliates. 5 | * Copyright (c) 2022 Ventana Micro Systems Inc. 6 | * 7 | * Authors: 8 | * Anup Patel 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define APLIC_MAX_NR 16 19 | 20 | static unsigned long aplic_count = 0; 21 | static struct aplic_data aplic[APLIC_MAX_NR]; 22 | 23 | static int irqchip_aplic_warm_init(void) 24 | { 25 | /* Nothing to do here. */ 26 | return 0; 27 | } 28 | 29 | static int irqchip_aplic_cold_init(void *fdt, int nodeoff, 30 | const struct fdt_match *match) 31 | { 32 | int rc; 33 | struct aplic_data *pd; 34 | 35 | if (APLIC_MAX_NR <= aplic_count) 36 | return SBI_ENOSPC; 37 | pd = &aplic[aplic_count++]; 38 | 39 | rc = fdt_parse_aplic_node(fdt, nodeoff, pd); 40 | if (rc) 41 | return rc; 42 | 43 | return aplic_cold_irqchip_init(pd); 44 | } 45 | 46 | static const struct fdt_match irqchip_aplic_match[] = { 47 | { .compatible = "riscv,aplic" }, 48 | { }, 49 | }; 50 | 51 | struct fdt_irqchip fdt_irqchip_aplic = { 52 | .match_table = irqchip_aplic_match, 53 | .cold_init = irqchip_aplic_cold_init, 54 | .warm_init = irqchip_aplic_warm_init, 55 | .exit = NULL, 56 | }; 57 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/irqchip/fdt_irqchip_drivers.carray: -------------------------------------------------------------------------------- 1 | HEADER: sbi_utils/irqchip/fdt_irqchip.h 2 | TYPE: struct fdt_irqchip 3 | NAME: fdt_irqchip_drivers 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/irqchip/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | libsbiutils-objs-$(CONFIG_FDT_IRQCHIP) += irqchip/fdt_irqchip.o 11 | libsbiutils-objs-$(CONFIG_FDT_IRQCHIP) += irqchip/fdt_irqchip_drivers.o 12 | 13 | carray-fdt_irqchip_drivers-$(CONFIG_FDT_IRQCHIP_APLIC) += fdt_irqchip_aplic 14 | libsbiutils-objs-$(CONFIG_FDT_IRQCHIP_APLIC) += irqchip/fdt_irqchip_aplic.o 15 | 16 | carray-fdt_irqchip_drivers-$(CONFIG_FDT_IRQCHIP_IMSIC) += fdt_irqchip_imsic 17 | libsbiutils-objs-$(CONFIG_FDT_IRQCHIP_IMSIC) += irqchip/fdt_irqchip_imsic.o 18 | 19 | carray-fdt_irqchip_drivers-$(CONFIG_FDT_IRQCHIP_PLIC) += fdt_irqchip_plic 20 | libsbiutils-objs-$(CONFIG_FDT_IRQCHIP_PLIC) += irqchip/fdt_irqchip_plic.o 21 | 22 | libsbiutils-objs-$(CONFIG_IRQCHIP_APLIC) += irqchip/aplic.o 23 | libsbiutils-objs-$(CONFIG_IRQCHIP_IMSIC) += irqchip/imsic.o 24 | libsbiutils-objs-$(CONFIG_IRQCHIP_PLIC) += irqchip/plic.o 25 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libfdt/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libfdt/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | config LIBFDT 4 | bool 5 | default n 6 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libfdt/Makefile.libfdt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) 2 | # Makefile.libfdt 3 | # 4 | # This is not a complete Makefile of itself. Instead, it is designed to 5 | # be easily embeddable into other systems of Makefiles. 6 | # 7 | LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 8 | LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h 9 | LIBFDT_VERSION = version.lds 10 | LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \ 11 | fdt_addresses.c fdt_overlay.c fdt_check.c 12 | LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) 13 | LIBFDT_LIB = libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) 14 | 15 | libfdt_clean: 16 | @$(VECHO) CLEAN "(libfdt)" 17 | rm -f $(STD_CLEANFILES:%=$(LIBFDT_dir)/%) 18 | rm -f $(LIBFDT_dir)/$(LIBFDT_soname) 19 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libfdt/TODO: -------------------------------------------------------------------------------- 1 | - Tree traversal functions 2 | - Graft function 3 | - Complete libfdt.h documenting comments 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libfdt/fdt_empty_tree.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) 2 | /* 3 | * libfdt - Flat Device Tree manipulation 4 | * Copyright (C) 2012 David Gibson, IBM Corporation. 5 | */ 6 | #include "libfdt_env.h" 7 | 8 | #include 9 | #include 10 | 11 | #include "libfdt_internal.h" 12 | 13 | int fdt_create_empty_tree(void *buf, int bufsize) 14 | { 15 | int err; 16 | 17 | err = fdt_create(buf, bufsize); 18 | if (err) 19 | return err; 20 | 21 | err = fdt_finish_reservemap(buf); 22 | if (err) 23 | return err; 24 | 25 | err = fdt_begin_node(buf, ""); 26 | if (err) 27 | return err; 28 | 29 | err = fdt_end_node(buf); 30 | if (err) 31 | return err; 32 | 33 | err = fdt_finish(buf); 34 | if (err) 35 | return err; 36 | 37 | return fdt_open_into(buf, buf, bufsize); 38 | } 39 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libfdt/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Atish Patra 8 | # 9 | 10 | libfdt_files = fdt.o fdt_addresses.o fdt_check.o fdt_empty_tree.o fdt_ro.o fdt_rw.o \ 11 | fdt_strerror.o fdt_sw.o fdt_wip.o 12 | $(foreach file, $(libfdt_files), \ 13 | $(eval CFLAGS_$(file) = -I$(src)/../../utils/libfdt)) 14 | 15 | libsbiutils-objs-$(CONFIG_LIBFDT) += $(addprefix libfdt/,$(libfdt_files)) 16 | libsbiutils-genflags-y += -I$(libsbiutils_dir)/libfdt/ 17 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libquad/include/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Jessica Clarke 5 | */ 6 | 7 | #ifndef __LIMITS_H__ 8 | #define __LIMITS_H__ 9 | 10 | #define CHAR_BIT 8 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libquad/include/sys/cdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Jessica Clarke 5 | */ 6 | 7 | #ifndef __SYS_CDEFS_H__ 8 | #define __SYS_CDEFS_H__ 9 | 10 | #define __FBSDID(s) struct __hack 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libquad/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Jessica Clarke 5 | */ 6 | 7 | #ifndef __SYS_TYPES_H__ 8 | #define __SYS_TYPES_H__ 9 | 10 | #include 11 | 12 | typedef unsigned long u_long; 13 | 14 | typedef int64_t quad_t; 15 | typedef uint64_t u_quad_t; 16 | 17 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 18 | #define _QUAD_LOWWORD 1 19 | #define _QUAD_HIGHWORD 0 20 | #else 21 | #define _QUAD_LOWWORD 0 22 | #define _QUAD_HIGHWORD 1 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/libquad/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2021 Jessica Clarke 5 | # 6 | 7 | ifeq ($(PLATFORM_RISCV_XLEN),32) 8 | libsbiutils-objs-y += libquad/divdi3.o 9 | libsbiutils-objs-y += libquad/moddi3.o 10 | libsbiutils-objs-y += libquad/qdivrem.o 11 | libsbiutils-objs-y += libquad/udivdi3.o 12 | libsbiutils-objs-y += libquad/umoddi3.o 13 | libsbiutils-genflags-y += -I$(libsbiutils_dir)/libquad/include 14 | endif 15 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/reset/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "System Reset Support" 4 | 5 | config FDT_RESET 6 | bool "FDT based reset drivers" 7 | depends on FDT 8 | default n 9 | 10 | if FDT_RESET 11 | 12 | config FDT_RESET_ATCWDT200 13 | bool "Andes WDT FDT reset driver" 14 | default n 15 | 16 | config FDT_RESET_GPIO 17 | bool "GPIO FDT reset driver" 18 | depends on FDT_GPIO 19 | default n 20 | 21 | config FDT_RESET_HTIF 22 | bool "Host transfer interface (HTIF) FDT reset driver" 23 | select SYS_HTIF 24 | default n 25 | 26 | config FDT_RESET_SIFIVE_TEST 27 | bool "SiFive Test FDT reset driver" 28 | select SYS_SIFIVE_TEST 29 | default n 30 | 31 | config FDT_RESET_SUNXI_WDT 32 | bool "Sunxi WDT FDT reset driver" 33 | default n 34 | 35 | config FDT_RESET_THEAD 36 | bool "T-HEAD FDT reset driver" 37 | default n 38 | 39 | endif 40 | 41 | endmenu 42 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/reset/fdt_reset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /* List of FDT reset drivers generated at compile time */ 17 | extern struct fdt_reset *fdt_reset_drivers[]; 18 | extern unsigned long fdt_reset_drivers_size; 19 | 20 | int fdt_reset_driver_init(void *fdt, struct fdt_reset *drv) 21 | { 22 | int noff, rc = SBI_ENODEV; 23 | const struct fdt_match *match; 24 | 25 | noff = fdt_find_match(fdt, -1, drv->match_table, &match); 26 | if (noff < 0) 27 | return SBI_ENODEV; 28 | 29 | if (drv->init) { 30 | rc = drv->init(fdt, noff, match); 31 | if (rc && rc != SBI_ENODEV) { 32 | sbi_printf("%s: %s init failed, %d\n", 33 | __func__, match->compatible, rc); 34 | } 35 | } 36 | 37 | return rc; 38 | } 39 | 40 | void fdt_reset_init(void) 41 | { 42 | int pos; 43 | void *fdt = fdt_get_address(); 44 | 45 | for (pos = 0; pos < fdt_reset_drivers_size; pos++) 46 | fdt_reset_driver_init(fdt, fdt_reset_drivers[pos]); 47 | } 48 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/reset/fdt_reset_drivers.carray: -------------------------------------------------------------------------------- 1 | HEADER: sbi_utils/reset/fdt_reset.h 2 | TYPE: struct fdt_reset 3 | NAME: fdt_reset_drivers 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/reset/fdt_reset_htif.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int htif_reset_init(void *fdt, int nodeoff, 15 | const struct fdt_match *match) 16 | { 17 | bool custom = false; 18 | uint64_t fromhost_addr = 0, tohost_addr = 0; 19 | 20 | if (!fdt_get_node_addr_size(fdt, nodeoff, 0, &fromhost_addr, NULL)) { 21 | custom = true; 22 | tohost_addr = fromhost_addr + sizeof(uint64_t); 23 | } 24 | 25 | fdt_get_node_addr_size(fdt, nodeoff, 1, &tohost_addr, NULL); 26 | 27 | return htif_system_reset_init(custom, fromhost_addr, tohost_addr); 28 | } 29 | 30 | static const struct fdt_match htif_reset_match[] = { 31 | { .compatible = "ucb,htif0" }, 32 | { }, 33 | }; 34 | 35 | struct fdt_reset fdt_reset_htif = { 36 | .match_table = htif_reset_match, 37 | .init = htif_reset_init 38 | }; 39 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/reset/fdt_reset_sifive_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | static int sifive_test_reset_init(void *fdt, int nodeoff, 16 | const struct fdt_match *match) 17 | { 18 | int rc; 19 | uint64_t addr; 20 | 21 | rc = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL); 22 | if (rc) 23 | return rc; 24 | 25 | return sifive_test_init(addr); 26 | } 27 | 28 | static const struct fdt_match sifive_test_reset_match[] = { 29 | { .compatible = "sifive,test1" }, 30 | { }, 31 | }; 32 | 33 | struct fdt_reset fdt_reset_sifive_test = { 34 | .match_table = sifive_test_reset_match, 35 | .init = sifive_test_reset_init, 36 | }; 37 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/reset/fdt_reset_thead.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | */ 4 | 5 | #ifndef __FDT_RESET_THEAD_H__ 6 | #define __FDT_RESET_THEAD_H__ 7 | 8 | #define MAX_CUSTOM_CSR 32 9 | 10 | #ifndef __ASSEMBLER__ 11 | struct custom_csr { 12 | unsigned long index; 13 | unsigned long value; 14 | }; 15 | 16 | u64 __fdt_reset_thead_csrr(void); 17 | 18 | extern struct custom_csr custom_csr[MAX_CUSTOM_CSR]; 19 | extern u32 __reset_thead_csr_stub[]; 20 | 21 | #endif /* __ASSEMBLER__ */ 22 | 23 | #endif /* __FDT_RESET_THEAD_H__ */ 24 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/reset/fdt_reset_thead_asm.S: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | */ 4 | 5 | #include 6 | #include "fdt_reset_thead.h" 7 | 8 | /* 9 | * csrrs rd, csr, rs1 10 | * |31 20|19 15|14 12|11 7|6 0| 11 | * csr rs1 010 rd 1110011 12 | */ 13 | #define CSR_STUB addi x0, x0, 0 14 | 15 | .option norvc 16 | .align 3 17 | .global __fdt_reset_thead_csrr 18 | __fdt_reset_thead_csrr: 19 | csrrs a0, 0, x0 20 | ret 21 | 22 | .align 3 23 | .global __thead_pre_start_warm 24 | __thead_pre_start_warm: 25 | /* 26 | * Clear L1 cache & BTB & BHT ... 27 | */ 28 | li t1, 0x70013 29 | csrw 0x7c2, t1 30 | fence rw,rw 31 | 32 | lla t1, custom_csr 33 | 34 | .global __reset_thead_csr_stub 35 | __reset_thead_csr_stub: 36 | .rept MAX_CUSTOM_CSR 37 | REG_L t2, 8(t1) 38 | CSR_STUB 39 | addi t1, t1, 16 40 | .endr 41 | /* 42 | * Clear L1 cache & BTB & BHT ... 43 | */ 44 | li t1, 0x70013 45 | csrw 0x7c2, t1 46 | fence rw,rw 47 | j _start_warm 48 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/reset/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | libsbiutils-objs-$(CONFIG_FDT_RESET) += reset/fdt_reset.o 11 | libsbiutils-objs-$(CONFIG_FDT_RESET) += reset/fdt_reset_drivers.o 12 | 13 | carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_ATCWDT200) += fdt_reset_atcwdt200 14 | libsbiutils-objs-$(CONFIG_FDT_RESET_ATCWDT200) += reset/fdt_reset_atcwdt200.o 15 | 16 | carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_GPIO) += fdt_poweroff_gpio 17 | carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_GPIO) += fdt_reset_gpio 18 | libsbiutils-objs-$(CONFIG_FDT_RESET_GPIO) += reset/fdt_reset_gpio.o 19 | 20 | carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_HTIF) += fdt_reset_htif 21 | libsbiutils-objs-$(CONFIG_FDT_RESET_HTIF) += reset/fdt_reset_htif.o 22 | 23 | carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_SIFIVE_TEST) += fdt_reset_sifive_test 24 | libsbiutils-objs-$(CONFIG_FDT_RESET_SIFIVE_TEST) += reset/fdt_reset_sifive_test.o 25 | 26 | carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_SUNXI_WDT) += fdt_reset_sunxi_wdt 27 | libsbiutils-objs-$(CONFIG_FDT_RESET_SUNXI_WDT) += reset/fdt_reset_sunxi_wdt.o 28 | 29 | carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_THEAD) += fdt_reset_thead 30 | libsbiutils-objs-$(CONFIG_FDT_RESET_THEAD) += reset/fdt_reset_thead.o 31 | libsbiutils-objs-$(CONFIG_FDT_RESET_THEAD) += reset/fdt_reset_thead_asm.o 32 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_cadence.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 StarFive Technology Co., Ltd. 5 | * 6 | * Author: Jun Liang Tan 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | static int serial_cadence_init(void *fdt, int nodeoff, 14 | const struct fdt_match *match) 15 | { 16 | int rc; 17 | struct platform_uart_data uart = { 0 }; 18 | 19 | rc = fdt_parse_uart_node(fdt, nodeoff, &uart); 20 | if (rc) 21 | return rc; 22 | 23 | return cadence_uart_init(uart.addr, uart.freq, uart.baud); 24 | } 25 | 26 | static const struct fdt_match serial_cadence_match[] = { 27 | { .compatible = "cdns,uart-r1p12" }, 28 | { .compatible = "starfive,jh8100-uart" }, 29 | { }, 30 | }; 31 | 32 | struct fdt_serial fdt_serial_cadence = { 33 | .match_table = serial_cadence_match, 34 | .init = serial_cadence_init 35 | }; 36 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_drivers.carray: -------------------------------------------------------------------------------- 1 | HEADER: sbi_utils/serial/fdt_serial.h 2 | TYPE: struct fdt_serial 3 | NAME: fdt_serial_drivers 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_gaisler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Cobham Gaisler AB. 5 | * 6 | * Authors: 7 | * Daniel Cederman 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int serial_gaisler_init(void *fdt, int nodeoff, 15 | const struct fdt_match *match) 16 | { 17 | int rc; 18 | struct platform_uart_data uart = { 0 }; 19 | 20 | rc = fdt_parse_gaisler_uart_node(fdt, nodeoff, &uart); 21 | if (rc) 22 | return rc; 23 | 24 | return gaisler_uart_init(uart.addr, uart.freq, uart.baud); 25 | } 26 | 27 | static const struct fdt_match serial_gaisler_match[] = { 28 | { .compatible = "gaisler,apbuart" }, 29 | {}, 30 | }; 31 | 32 | struct fdt_serial fdt_serial_gaisler = { 33 | .match_table = serial_gaisler_match, 34 | .init = serial_gaisler_init 35 | }; 36 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_htif.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static const struct fdt_match serial_htif_match[] = { 15 | { .compatible = "ucb,htif0" }, 16 | { }, 17 | }; 18 | 19 | static int serial_htif_init(void *fdt, int nodeoff, 20 | const struct fdt_match *match) 21 | { 22 | bool custom = false; 23 | uint64_t fromhost_addr = 0, tohost_addr = 0; 24 | 25 | if (!fdt_get_node_addr_size(fdt, nodeoff, 0, &fromhost_addr, NULL)) { 26 | custom = true; 27 | tohost_addr = fromhost_addr + sizeof(uint64_t); 28 | } 29 | 30 | fdt_get_node_addr_size(fdt, nodeoff, 1, &tohost_addr, NULL); 31 | 32 | return htif_serial_init(custom, fromhost_addr, tohost_addr); 33 | } 34 | 35 | struct fdt_serial fdt_serial_htif = { 36 | .match_table = serial_htif_match, 37 | .init = serial_htif_init 38 | }; 39 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_litex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2021 Gabriel Somlo 5 | * 6 | * Authors: 7 | * Gabriel Somlo 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | static int serial_litex_init(void *fdt, int nodeoff, 16 | const struct fdt_match *match) 17 | { 18 | uint64_t reg_addr, reg_size; 19 | int rc; 20 | 21 | if (nodeoff < 0 || !fdt) 22 | return SBI_ENODEV; 23 | 24 | rc = fdt_get_node_addr_size(fdt, nodeoff, 0, ®_addr, ®_size); 25 | if (rc < 0 || !reg_addr || !reg_size) 26 | return SBI_ENODEV; 27 | 28 | return litex_uart_init(reg_addr); 29 | } 30 | 31 | static const struct fdt_match serial_litex_match[] = { 32 | { .compatible = "litex,liteuart" }, 33 | { }, 34 | }; 35 | 36 | struct fdt_serial fdt_serial_litex = { 37 | .match_table = serial_litex_match, 38 | .init = serial_litex_init 39 | }; 40 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_renesas_scif.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: BSD-2-Clause 2 | /* 3 | * Copyright (C) 2022 Renesas Electronics Corporation 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | static int serial_renesas_scif_init(void *fdt, int nodeoff, 11 | const struct fdt_match *match) 12 | { 13 | struct platform_uart_data uart = { 0 }; 14 | int ret; 15 | 16 | ret = fdt_parse_renesas_scif_node(fdt, nodeoff, &uart); 17 | if (ret) 18 | return ret; 19 | 20 | return renesas_scif_init(uart.addr, uart.freq, uart.baud); 21 | } 22 | 23 | static const struct fdt_match serial_renesas_scif_match[] = { 24 | { .compatible = "renesas,scif-r9a07g043" }, 25 | { /* sentinel */ } 26 | }; 27 | 28 | struct fdt_serial fdt_serial_renesas_scif = { 29 | .match_table = serial_renesas_scif_match, 30 | .init = serial_renesas_scif_init 31 | }; 32 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_shakti.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Vijai Kumar K 5 | * 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | static int serial_shakti_init(void *fdt, int nodeoff, 13 | const struct fdt_match *match) 14 | { 15 | int rc; 16 | struct platform_uart_data uart = { 0 }; 17 | 18 | rc = fdt_parse_shakti_uart_node(fdt, nodeoff, &uart); 19 | if (rc) 20 | return rc; 21 | 22 | return shakti_uart_init(uart.addr, uart.freq, uart.baud); 23 | } 24 | 25 | static const struct fdt_match serial_shakti_match[] = { 26 | { .compatible = "shakti,uart0" }, 27 | { }, 28 | }; 29 | 30 | struct fdt_serial fdt_serial_shakti = { 31 | .match_table = serial_shakti_match, 32 | .init = serial_shakti_init 33 | }; 34 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_sifive.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int serial_sifive_init(void *fdt, int nodeoff, 15 | const struct fdt_match *match) 16 | { 17 | int rc; 18 | struct platform_uart_data uart = { 0 }; 19 | 20 | rc = fdt_parse_sifive_uart_node(fdt, nodeoff, &uart); 21 | if (rc) 22 | return rc; 23 | 24 | return sifive_uart_init(uart.addr, uart.freq, uart.baud); 25 | } 26 | 27 | static const struct fdt_match serial_sifive_match[] = { 28 | { .compatible = "sifive,fu540-c000-uart" }, 29 | { .compatible = "sifive,uart0" }, 30 | { }, 31 | }; 32 | 33 | struct fdt_serial fdt_serial_sifive = { 34 | .match_table = serial_sifive_match, 35 | .init = serial_sifive_init 36 | }; 37 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_uart8250.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int serial_uart8250_init(void *fdt, int nodeoff, 15 | const struct fdt_match *match) 16 | { 17 | int rc; 18 | struct platform_uart_data uart = { 0 }; 19 | 20 | rc = fdt_parse_uart_node(fdt, nodeoff, &uart); 21 | if (rc) 22 | return rc; 23 | 24 | return uart8250_init(uart.addr, uart.freq, uart.baud, 25 | uart.reg_shift, uart.reg_io_width, 26 | uart.reg_offset); 27 | } 28 | 29 | static const struct fdt_match serial_uart8250_match[] = { 30 | { .compatible = "ns16550" }, 31 | { .compatible = "ns16550a" }, 32 | { .compatible = "snps,dw-apb-uart" }, 33 | { }, 34 | }; 35 | 36 | struct fdt_serial fdt_serial_uart8250 = { 37 | .match_table = serial_uart8250_match, 38 | .init = serial_uart8250_init, 39 | }; 40 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/serial/fdt_serial_xlnx_uartlite.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Alistair Francis 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int serial_xlnx_uartlite_init(void *fdt, int nodeoff, 15 | const struct fdt_match *match) 16 | { 17 | int rc; 18 | struct platform_uart_data uart = { 0 }; 19 | 20 | rc = fdt_parse_xlnx_uartlite_node(fdt, nodeoff, &uart); 21 | if (rc) 22 | return rc; 23 | 24 | return xlnx_uartlite_init(uart.addr); 25 | } 26 | 27 | static const struct fdt_match serial_xlnx_uartlite_match[] = { 28 | { .compatible = "xlnx,xps-uartlite-1.00.a" }, 29 | { }, 30 | }; 31 | 32 | struct fdt_serial fdt_serial_xlnx_uartlite = { 33 | .match_table = serial_xlnx_uartlite_match, 34 | .init = serial_xlnx_uartlite_init, 35 | }; 36 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/sys/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "System Device Support" 4 | 5 | config SYS_HTIF 6 | bool "Host transfere interface (HTIF) support" 7 | default n 8 | 9 | config SYS_SIFIVE_TEST 10 | bool "SiFive test support" 11 | default n 12 | 13 | endmenu 14 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/sys/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | libsbiutils-objs-$(CONFIG_SYS_HTIF) += sys/htif.o 11 | libsbiutils-objs-$(CONFIG_SYS_SIFIVE_TEST) += sys/sifive_test.o 12 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/timer/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | menu "Timer Device Support" 4 | 5 | config FDT_TIMER 6 | bool "FDT based timer drivers" 7 | depends on FDT 8 | default n 9 | 10 | if FDT_TIMER 11 | 12 | config FDT_TIMER_MTIMER 13 | bool "ACLINT MTIMER FDT driver" 14 | select TIMER_MTIMER 15 | default n 16 | 17 | config FDT_TIMER_PLMT 18 | bool "Andes PLMT FDT driver" 19 | select TIMER_PLMT 20 | default n 21 | 22 | endif 23 | 24 | config TIMER_MTIMER 25 | bool "ACLINT MTIMER support" 26 | default n 27 | 28 | config TIMER_PLMT 29 | bool "Andes PLMT support" 30 | default n 31 | 32 | endmenu 33 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/timer/fdt_timer_drivers.carray: -------------------------------------------------------------------------------- 1 | HEADER: sbi_utils/timer/fdt_timer.h 2 | TYPE: struct fdt_timer 3 | NAME: fdt_timer_drivers 4 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/timer/fdt_timer_plmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Andes Technology Corporation 5 | * 6 | * Authors: 7 | * Yu Chien Peter Lin 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | extern struct plmt_data plmt; 15 | 16 | static int fdt_plmt_cold_timer_init(void *fdt, int nodeoff, 17 | const struct fdt_match *match) 18 | { 19 | int rc; 20 | unsigned long plmt_base; 21 | 22 | rc = fdt_parse_plmt_node(fdt, nodeoff, &plmt_base, &plmt.size, 23 | &plmt.hart_count); 24 | if (rc) 25 | return rc; 26 | 27 | plmt.time_val = (u64 *)plmt_base; 28 | plmt.time_cmp = (u64 *)(plmt_base + 0x8); 29 | 30 | rc = fdt_parse_timebase_frequency(fdt, &plmt.timer_freq); 31 | if (rc) 32 | return rc; 33 | 34 | rc = plmt_cold_timer_init(&plmt); 35 | if (rc) 36 | return rc; 37 | 38 | return 0; 39 | } 40 | 41 | static const struct fdt_match timer_plmt_match[] = { 42 | { .compatible = "andestech,plmt0" }, 43 | {}, 44 | }; 45 | 46 | struct fdt_timer fdt_timer_plmt = { 47 | .match_table = timer_plmt_match, 48 | .cold_init = fdt_plmt_cold_timer_init, 49 | .warm_init = plmt_warm_timer_init, 50 | .exit = NULL, 51 | }; 52 | -------------------------------------------------------------------------------- /tools/opensbi/lib/utils/timer/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | libsbiutils-objs-$(CONFIG_TIMER_MTIMER) += timer/aclint_mtimer.o 11 | libsbiutils-objs-$(CONFIG_TIMER_PLMT) += timer/andes_plmt.o 12 | 13 | libsbiutils-objs-$(CONFIG_FDT_TIMER) += timer/fdt_timer.o 14 | libsbiutils-objs-$(CONFIG_FDT_TIMER) += timer/fdt_timer_drivers.o 15 | 16 | carray-fdt_timer_drivers-$(CONFIG_FDT_TIMER_MTIMER) += fdt_timer_mtimer 17 | libsbiutils-objs-$(CONFIG_FDT_TIMER_MTIMER) += timer/fdt_timer_mtimer.o 18 | 19 | carray-fdt_timer_drivers-$(CONFIG_FDT_TIMER_PLMT) += fdt_timer_plmt 20 | libsbiutils-objs-$(CONFIG_FDT_TIMER_PLMT) += timer/fdt_timer_plmt.o 21 | -------------------------------------------------------------------------------- /tools/opensbi/platform/fpga/ariane/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | config PLATFORM_ARIANE_FPGA 4 | bool 5 | select FDT 6 | select IPI_MSWI 7 | select IRQCHIP_PLIC 8 | select SERIAL_UART8250 9 | select TIMER_MTIMER 10 | default y 11 | -------------------------------------------------------------------------------- /tools/opensbi/platform/fpga/ariane/configs/defconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/opensbi/platform/fpga/ariane/configs/defconfig -------------------------------------------------------------------------------- /tools/opensbi/platform/fpga/ariane/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (C) 2019 FORTH-ICS/CARV 5 | # Panagiotis Peristerakis 6 | # 7 | 8 | # Compiler flags 9 | platform-cppflags-y = 10 | platform-cflags-y = 11 | platform-asflags-y = 12 | platform-ldflags-y = 13 | 14 | # Object to build 15 | platform-objs-y += platform.o 16 | 17 | PLATFORM_RISCV_XLEN = 64 18 | 19 | # Blobs to build 20 | FW_TEXT_START=0x80000000 21 | FW_JUMP=n 22 | 23 | ifeq ($(PLATFORM_RISCV_XLEN), 32) 24 | # This needs to be 4MB aligned for 32-bit support 25 | FW_JUMP_ADDR=0x80400000 26 | else 27 | # This needs to be 2MB aligned for 64-bit support 28 | FW_JUMP_ADDR=0x80200000 29 | endif 30 | FW_JUMP_FDT_ADDR=0x82200000 31 | 32 | # Firmware with payload configuration. 33 | FW_PAYLOAD=y 34 | 35 | ifeq ($(PLATFORM_RISCV_XLEN), 32) 36 | # This needs to be 4MB aligned for 32-bit support 37 | FW_PAYLOAD_OFFSET=0x400000 38 | else 39 | # This needs to be 2MB aligned for 64-bit support 40 | FW_PAYLOAD_OFFSET=0x200000 41 | endif 42 | FW_PAYLOAD_FDT_ADDR=0x82200000 43 | FW_PAYLOAD_ALIGN=0x1000 44 | -------------------------------------------------------------------------------- /tools/opensbi/platform/fpga/openpiton/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | config PLATFORM_OPENPITON_FPGA 4 | bool 5 | select FDT 6 | select IPI_MSWI 7 | select IRQCHIP_PLIC 8 | select SERIAL_UART8250 9 | select TIMER_MTIMER 10 | default y 11 | -------------------------------------------------------------------------------- /tools/opensbi/platform/fpga/openpiton/configs/defconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/opensbi/platform/fpga/openpiton/configs/defconfig -------------------------------------------------------------------------------- /tools/opensbi/platform/fpga/openpiton/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | # 6 | 7 | # Compiler flags 8 | platform-cppflags-y = 9 | platform-cflags-y = 10 | platform-asflags-y = 11 | platform-ldflags-y = 12 | 13 | # Objects to build 14 | platform-objs-y += platform.o 15 | 16 | PLATFORM_RISCV_XLEN = 64 17 | 18 | # Blobs to build 19 | FW_TEXT_START=0x80000000 20 | FW_JUMP=n 21 | 22 | ifeq ($(PLATFORM_RISCV_XLEN), 32) 23 | # This needs to be 4MB aligned for 32-bit support 24 | FW_JUMP_ADDR=0x80400000 25 | else 26 | # This needs to be 2MB aligned for 64-bit support 27 | FW_JUMP_ADDR=0x80200000 28 | endif 29 | FW_JUMP_FDT_ADDR=0x82200000 30 | 31 | # Firmware with payload configuration. 32 | FW_PAYLOAD=y 33 | 34 | ifeq ($(PLATFORM_RISCV_XLEN), 32) 35 | # This needs to be 4MB aligned for 32-bit support 36 | FW_PAYLOAD_OFFSET=0x400000 37 | else 38 | # This needs to be 2MB aligned for 64-bit support 39 | FW_PAYLOAD_OFFSET=0x200000 40 | endif 41 | FW_PAYLOAD_FDT_ADDR=0x82200000 42 | FW_PAYLOAD_ALIGN=0x1000 43 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | config PLATFORM_GENERIC 4 | bool 5 | select FDT 6 | select FDT_DOMAIN 7 | select FDT_PMU 8 | default y 9 | 10 | if PLATFORM_GENERIC 11 | 12 | config PLATFORM_GENERIC_NAME 13 | string "Platform default name" 14 | default "Generic" 15 | 16 | config PLATFORM_GENERIC_MAJOR_VER 17 | int "Platform major version" 18 | range 0 65535 19 | default 0 20 | 21 | config PLATFORM_GENERIC_MINOR_VER 22 | int "Platform minor version" 23 | range 0 65535 24 | default 1 25 | 26 | config PLATFORM_ALLWINNER_D1 27 | bool "Allwinner D1 support" 28 | depends on FDT_IRQCHIP_PLIC 29 | default n 30 | 31 | config PLATFORM_ANDES_AE350 32 | bool "Andes AE350 support" 33 | default n 34 | 35 | config PLATFORM_RENESAS_RZFIVE 36 | bool "Renesas RZ/Five support" 37 | default n 38 | 39 | config PLATFORM_SIFIVE_FU540 40 | bool "SiFive FU540 support" 41 | default n 42 | 43 | config PLATFORM_SIFIVE_FU740 44 | bool "SiFive FU740 support" 45 | depends on FDT_RESET && FDT_I2C 46 | default n 47 | 48 | endif 49 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/allwinner/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | 5 | carray-platform_override_modules-$(CONFIG_PLATFORM_ALLWINNER_D1) += sun20i_d1 6 | platform-objs-$(CONFIG_PLATFORM_ALLWINNER_D1) += allwinner/sun20i-d1.o 7 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/andes/ae350.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2022 Andes Technology Corporation 5 | * 6 | * Authors: 7 | * Yu Chien Peter Lin 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static const struct fdt_match andes_ae350_match[] = { 15 | { .compatible = "andestech,ae350" }, 16 | { }, 17 | }; 18 | 19 | const struct platform_override andes_ae350 = { 20 | .match_table = andes_ae350_match, 21 | }; 22 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/andes/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | 5 | carray-platform_override_modules-$(CONFIG_PLATFORM_ANDES_AE350) += andes_ae350 6 | platform-objs-$(CONFIG_PLATFORM_ANDES_AE350) += andes/ae350.o 7 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/configs/defconfig: -------------------------------------------------------------------------------- 1 | CONFIG_PLATFORM_ALLWINNER_D1=y 2 | CONFIG_PLATFORM_ANDES_AE350=y 3 | CONFIG_PLATFORM_RENESAS_RZFIVE=y 4 | CONFIG_PLATFORM_SIFIVE_FU540=y 5 | CONFIG_PLATFORM_SIFIVE_FU740=y 6 | CONFIG_FDT_GPIO=y 7 | CONFIG_FDT_GPIO_SIFIVE=y 8 | CONFIG_FDT_I2C=y 9 | CONFIG_FDT_I2C_SIFIVE=y 10 | CONFIG_FDT_IPI=y 11 | CONFIG_FDT_IPI_MSWI=y 12 | CONFIG_FDT_IPI_PLICSW=y 13 | CONFIG_FDT_IRQCHIP=y 14 | CONFIG_FDT_IRQCHIP_APLIC=y 15 | CONFIG_FDT_IRQCHIP_IMSIC=y 16 | CONFIG_FDT_IRQCHIP_PLIC=y 17 | CONFIG_FDT_RESET=y 18 | CONFIG_FDT_RESET_ATCWDT200=y 19 | CONFIG_FDT_RESET_GPIO=y 20 | CONFIG_FDT_RESET_HTIF=y 21 | CONFIG_FDT_RESET_SIFIVE_TEST=y 22 | CONFIG_FDT_RESET_SUNXI_WDT=y 23 | CONFIG_FDT_RESET_THEAD=y 24 | CONFIG_FDT_SERIAL=y 25 | CONFIG_FDT_SERIAL_CADENCE=y 26 | CONFIG_FDT_SERIAL_GAISLER=y 27 | CONFIG_FDT_SERIAL_HTIF=y 28 | CONFIG_FDT_SERIAL_RENESAS_SCIF=y 29 | CONFIG_FDT_SERIAL_SHAKTI=y 30 | CONFIG_FDT_SERIAL_SIFIVE=y 31 | CONFIG_FDT_SERIAL_LITEX=y 32 | CONFIG_FDT_SERIAL_UART8250=y 33 | CONFIG_FDT_SERIAL_XILINX_UARTLITE=y 34 | CONFIG_FDT_TIMER=y 35 | CONFIG_FDT_TIMER_MTIMER=y 36 | CONFIG_FDT_TIMER_PLMT=y 37 | CONFIG_SERIAL_SEMIHOSTING=y 38 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/include/platform_override.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #ifndef __PLATFORM_OVERRIDE_H__ 11 | #define __PLATFORM_OVERRIDE_H__ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | struct platform_override { 18 | const struct fdt_match *match_table; 19 | u64 (*features)(const struct fdt_match *match); 20 | u64 (*tlbr_flush_limit)(const struct fdt_match *match); 21 | int (*early_init)(bool cold_boot, const struct fdt_match *match); 22 | int (*final_init)(bool cold_boot, const struct fdt_match *match); 23 | void (*early_exit)(const struct fdt_match *match); 24 | void (*final_exit)(const struct fdt_match *match); 25 | int (*fdt_fixup)(void *fdt, const struct fdt_match *match); 26 | int (*extensions_init)(const struct fdt_match *match, 27 | struct sbi_hart_features *hfeatures); 28 | int (*vendor_ext_check)(long extid, const struct fdt_match *match); 29 | int (*vendor_ext_provider)(long extid, long funcid, 30 | const struct sbi_trap_regs *regs, 31 | unsigned long *out_value, 32 | struct sbi_trap_info *out_trap, 33 | const struct fdt_match *match); 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Anup Patel 8 | # 9 | 10 | # Compiler flags 11 | platform-cppflags-y = 12 | platform-cflags-y = 13 | platform-asflags-y = 14 | platform-ldflags-y = 15 | 16 | # Command for platform specific "make run" 17 | platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \ 18 | -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf 19 | 20 | # Objects to build 21 | platform-objs-y += platform.o 22 | platform-objs-y += platform_override_modules.o 23 | 24 | # Blobs to build 25 | FW_TEXT_START=0x80000000 26 | FW_DYNAMIC=y 27 | FW_JUMP=y 28 | ifeq ($(PLATFORM_RISCV_XLEN), 32) 29 | # This needs to be 4MB aligned for 32-bit system 30 | FW_JUMP_ADDR=$(shell printf "0x%X" $$(($(FW_TEXT_START) + 0x400000))) 31 | else 32 | # This needs to be 2MB aligned for 64-bit system 33 | FW_JUMP_ADDR=$(shell printf "0x%X" $$(($(FW_TEXT_START) + 0x200000))) 34 | endif 35 | FW_JUMP_FDT_ADDR=$(shell printf "0x%X" $$(($(FW_TEXT_START) + 0x2200000))) 36 | FW_PAYLOAD=y 37 | ifeq ($(PLATFORM_RISCV_XLEN), 32) 38 | # This needs to be 4MB aligned for 32-bit system 39 | FW_PAYLOAD_OFFSET=0x400000 40 | else 41 | # This needs to be 2MB aligned for 64-bit system 42 | FW_PAYLOAD_OFFSET=0x200000 43 | endif 44 | FW_PAYLOAD_FDT_ADDR=$(FW_JUMP_FDT_ADDR) 45 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/platform_override_modules.carray: -------------------------------------------------------------------------------- 1 | HEADER: platform_override.h 2 | TYPE: const struct platform_override 3 | NAME: platform_override_modules 4 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/renesas/rzfive/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (C) 2022 Renesas Electronics Corp. 5 | # 6 | 7 | carray-platform_override_modules-$(CONFIG_PLATFORM_RENESAS_RZFIVE) += renesas_rzfive 8 | platform-objs-$(CONFIG_PLATFORM_RENESAS_RZFIVE) += renesas/rzfive/rzfive.o 9 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/renesas/rzfive/rzfive.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | /* 3 | * Copyright (C) 2022 Renesas Electronics Corp. 4 | * 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | static const struct fdt_match renesas_rzfive_match[] = { 11 | { .compatible = "renesas,r9a07g043f01" }, 12 | { /* sentinel */ } 13 | }; 14 | 15 | const struct platform_override renesas_rzfive = { 16 | .match_table = renesas_rzfive_match, 17 | }; 18 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/sifive/fu540.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Anup Patel 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match) 15 | { 16 | /* 17 | * The sfence.vma by virtual address does not work on 18 | * SiFive FU540 so we return remote TLB flush limit as zero. 19 | */ 20 | return 0; 21 | } 22 | 23 | static int sifive_fu540_fdt_fixup(void *fdt, const struct fdt_match *match) 24 | { 25 | /* 26 | * SiFive Freedom U540 has an erratum that prevents S-mode software 27 | * to access a PMP protected region using 1GB page table mapping, so 28 | * always add the no-map attribute on this platform. 29 | */ 30 | fdt_reserved_memory_nomap_fixup(fdt); 31 | 32 | return 0; 33 | } 34 | 35 | static const struct fdt_match sifive_fu540_match[] = { 36 | { .compatible = "sifive,fu540" }, 37 | { .compatible = "sifive,fu540g" }, 38 | { .compatible = "sifive,fu540-c000" }, 39 | { .compatible = "sifive,hifive-unleashed-a00" }, 40 | { }, 41 | }; 42 | 43 | const struct platform_override sifive_fu540 = { 44 | .match_table = sifive_fu540_match, 45 | .tlbr_flush_limit = sifive_fu540_tlbr_flush_limit, 46 | .fdt_fixup = sifive_fu540_fdt_fixup, 47 | }; 48 | -------------------------------------------------------------------------------- /tools/opensbi/platform/generic/sifive/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | 5 | carray-platform_override_modules-$(CONFIG_PLATFORM_SIFIVE_FU540) += sifive_fu540 6 | platform-objs-$(CONFIG_PLATFORM_SIFIVE_FU540) += sifive/fu540.o 7 | 8 | carray-platform_override_modules-$(CONFIG_PLATFORM_SIFIVE_FU740) += sifive_fu740 9 | platform-objs-$(CONFIG_PLATFORM_SIFIVE_FU740) += sifive/fu740.o 10 | -------------------------------------------------------------------------------- /tools/opensbi/platform/kendryte/k210/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | config PLATFORM_KENDRYTE_K210 4 | bool 5 | select FDT 6 | select IPI_MSWI 7 | select IRQCHIP_PLIC 8 | select SERIAL_SIFIVE 9 | select TIMER_MTIMER 10 | default y 11 | -------------------------------------------------------------------------------- /tools/opensbi/platform/kendryte/k210/configs/defconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/opensbi/platform/kendryte/k210/configs/defconfig -------------------------------------------------------------------------------- /tools/opensbi/platform/kendryte/k210/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # Damien Le Moal 8 | # 9 | 10 | # Compiler flags 11 | platform-cppflags-y = 12 | platform-cflags-y = 13 | platform-asflags-y = 14 | platform-ldflags-y = 15 | 16 | # Objects to build 17 | platform-objs-y += platform.o 18 | 19 | platform-objs-y += k210.o 20 | platform-varprefix-k210.o = dt_k210 21 | platform-padding-k210.o = 2048 22 | 23 | # Blobs to build 24 | FW_TEXT_START=0x80000000 25 | FW_PAYLOAD=y 26 | FW_PAYLOAD_ALIGN=0x1000 27 | -------------------------------------------------------------------------------- /tools/opensbi/platform/kendryte/k210/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. 5 | * 6 | * Authors: 7 | * Damien Le Moal 8 | */ 9 | #ifndef _K210_PLATFORM_H_ 10 | #define _K210_PLATFORM_H_ 11 | 12 | #include 13 | 14 | #define K210_HART_COUNT 2 15 | 16 | #define K210_UART_BAUDRATE 115200 17 | #define K210_ACLINT_MTIMER_FREQ 7800000 18 | #define K210_CLK0_FREQ 26000000UL 19 | #define K210_PLIC_NUM_SOURCES 65 20 | 21 | /* Registers base address */ 22 | #define K210_SYSCTL_BASE_ADDR 0x50440000ULL 23 | #define K210_UART_BASE_ADDR 0x38000000ULL 24 | #define K210_CLINT_BASE_ADDR 0x02000000ULL 25 | #define K210_ACLINT_MSWI_ADDR \ 26 | (K210_CLINT_BASE_ADDR + CLINT_MSWI_OFFSET) 27 | #define K210_ACLINT_MTIMER_ADDR \ 28 | (K210_CLINT_BASE_ADDR + CLINT_MTIMER_OFFSET) 29 | #define K210_PLIC_BASE_ADDR 0x0C000000ULL 30 | 31 | /* Registers */ 32 | #define K210_PLL0 0x08 33 | #define K210_CLKSEL0 0x20 34 | #define K210_RESET 0x30 35 | 36 | /* Register bit masks */ 37 | #define K210_RESET_MASK 0x01 38 | 39 | static inline u32 k210_read_sysreg(u32 reg) 40 | { 41 | return readl((volatile void *)(K210_SYSCTL_BASE_ADDR + reg)); 42 | } 43 | 44 | static inline void k210_write_sysreg(u32 val, u32 reg) 45 | { 46 | writel(val, (volatile void *)(K210_SYSCTL_BASE_ADDR + reg)); 47 | } 48 | 49 | #endif /* _K210_PLATFORM_H_ */ 50 | -------------------------------------------------------------------------------- /tools/opensbi/platform/nuclei/ux600/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | config PLATFORM_NUCLEI_UX600 4 | bool 5 | select FDT 6 | select IPI_MSWI 7 | select IRQCHIP_PLIC 8 | select SERIAL_SIFIVE 9 | select TIMER_MTIMER 10 | default y 11 | -------------------------------------------------------------------------------- /tools/opensbi/platform/nuclei/ux600/configs/defconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/opensbi/platform/nuclei/ux600/configs/defconfig -------------------------------------------------------------------------------- /tools/opensbi/platform/nuclei/ux600/objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | # 4 | # Copyright (c) 2020 Nuclei Corporation or its affiliates. 5 | # 6 | # Authors: 7 | # lujun 8 | # hqfang <578567190@qq.com> 9 | # 10 | 11 | # Compiler flags 12 | platform-cppflags-y = 13 | platform-cflags-y = 14 | platform-asflags-y = 15 | platform-ldflags-y = 16 | 17 | # Command for platform specific "make run" 18 | platform-runcmd = xl_spike \ 19 | $(build_dir)/platform/nuclei/ux600/firmware/fw_payload.elf 20 | 21 | # Objects to build 22 | platform-objs-y += platform.o 23 | 24 | # Blobs to build 25 | FW_TEXT_START=0xA0000000 26 | FW_DYNAMIC=y 27 | FW_JUMP=y 28 | 29 | FW_JUMP_ADDR=0xA0200000 30 | FW_JUMP_FDT_ADDR=0xA8000000 31 | FW_PAYLOAD=y 32 | FW_PAYLOAD_OFFSET=0x200000 33 | FW_PAYLOAD_FDT_ADDR=0xA8000000 34 | -------------------------------------------------------------------------------- /tools/opensbi/platform/template/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-2-Clause 2 | 3 | # 4 | # All mandatory drivers or libraries for this platform should 5 | # be directly selected by the PLATFORM_xyz kconfig symbol. 6 | # 7 | # All optional drivers or libraries for this platform should 8 | # be enabled via configs/defconfig of this platform. 9 | # 10 | config PLATFORM_TEMPLATE 11 | bool 12 | select IPI_MSWI 13 | select IRQCHIP_PLIC 14 | select SERIAL_UART8250 15 | select TIMER_MTIMER 16 | default y 17 | -------------------------------------------------------------------------------- /tools/opensbi/platform/template/configs/defconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRNIU/SimpleKernel/bfbbc08b6bd92f98fd4a6e5633a1aae7699973cb/tools/opensbi/platform/template/configs/defconfig -------------------------------------------------------------------------------- /tools/opensbi/scripts/Kconfiglib/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2019, Ulf Magnusson 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 6 | -------------------------------------------------------------------------------- /tools/opensbi/scripts/Kconfiglib/allnoconfig.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright (c) 2018-2019, Ulf Magnusson 4 | # SPDX-License-Identifier: ISC 5 | 6 | """ 7 | Writes a configuration file where as many symbols as possible are set to 'n'. 8 | 9 | The default output filename is '.config'. A different filename can be passed 10 | in the KCONFIG_CONFIG environment variable. 11 | 12 | Usage for the Linux kernel: 13 | 14 | $ make [ARCH=] scriptconfig SCRIPT=Kconfiglib/allnoconfig.py 15 | """ 16 | 17 | # See examples/allnoconfig_walk.py for another way to implement this script 18 | 19 | import kconfiglib 20 | 21 | 22 | def main(): 23 | kconf = kconfiglib.standard_kconfig(__doc__) 24 | 25 | # Avoid warnings that would otherwise get printed by Kconfiglib for the 26 | # following: 27 | # 28 | # 1. Assigning a value to a symbol without a prompt, which never has any 29 | # effect 30 | # 31 | # 2. Assigning values invalid for the type (only bool/tristate symbols 32 | # accept 0/1/2, for n/m/y). The assignments will be ignored for other 33 | # symbol types, which is what we want. 34 | kconf.warn = False 35 | for sym in kconf.unique_defined_syms: 36 | sym.set_value(2 if sym.is_allnoconfig_y else 0) 37 | kconf.warn = True 38 | 39 | kconf.load_allconfig("allno.config") 40 | 41 | print(kconf.write_config()) 42 | 43 | 44 | if __name__ == "__main__": 45 | main() 46 | -------------------------------------------------------------------------------- /tools/opensbi/scripts/Kconfiglib/defconfig.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright (c) 2019, Ulf Magnusson 4 | # SPDX-License-Identifier: ISC 5 | 6 | """ 7 | Reads a specified configuration file, then writes a new configuration file. 8 | This can be used to initialize the configuration from e.g. an arch-specific 9 | configuration file. This input configuration file would usually be a minimal 10 | configuration file, as generated by e.g. savedefconfig. 11 | 12 | The default output filename is '.config'. A different filename can be passed in 13 | the KCONFIG_CONFIG environment variable. 14 | """ 15 | import argparse 16 | 17 | import kconfiglib 18 | 19 | 20 | def main(): 21 | parser = argparse.ArgumentParser( 22 | formatter_class=argparse.RawDescriptionHelpFormatter, 23 | description=__doc__) 24 | 25 | parser.add_argument( 26 | "--kconfig", 27 | default="Kconfig", 28 | help="Top-level Kconfig file (default: Kconfig)") 29 | 30 | parser.add_argument( 31 | "config", 32 | metavar="CONFIGURATION", 33 | help="Input configuration file") 34 | 35 | args = parser.parse_args() 36 | 37 | kconf = kconfiglib.Kconfig(args.kconfig, suppress_traceback=True) 38 | print(kconf.load_config(args.config)) 39 | print(kconf.write_config()) 40 | 41 | 42 | if __name__ == "__main__": 43 | main() 44 | -------------------------------------------------------------------------------- /tools/opensbi/scripts/Kconfiglib/olddefconfig.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright (c) 2018-2019, Ulf Magnusson 4 | # SPDX-License-Identifier: ISC 5 | 6 | """ 7 | Updates an old .config file or creates a new one, by filling in default values 8 | for all new symbols. This is the same as picking the default selection for all 9 | symbols in oldconfig, or entering the menuconfig interface and immediately 10 | saving. 11 | 12 | The default input/output filename is '.config'. A different filename can be 13 | passed in the KCONFIG_CONFIG environment variable. 14 | 15 | When overwriting a configuration file, the old version is saved to 16 | .old (e.g. .config.old). 17 | """ 18 | import kconfiglib 19 | 20 | 21 | def main(): 22 | kconf = kconfiglib.standard_kconfig(__doc__) 23 | print(kconf.load_config()) 24 | print(kconf.write_config()) 25 | 26 | 27 | if __name__ == "__main__": 28 | main() 29 | -------------------------------------------------------------------------------- /tools/setup_x86_64_mac.sh: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel (https://github.com/Simple-XX/SimpleKernel). 3 | # 4 | # setup_x86_64_mac.sh for Simple-XX/SimpleKernel. 5 | 6 | #!/bin/bash 7 | 8 | # shell 执行出错时终止运行 9 | set -e 10 | # 输出实际执行内容 11 | set -x 12 | 13 | source ./env.sh 14 | 15 | # 检测环境,如果没有安装需要的软件,则安装 16 | if ! [ -x "$(command -v ${SIMULATOR})" ]; then 17 | echo 'Error: '${SIMULATOR}' is not installed.' 18 | echo 'Install '${SIMULATOR}'...' 19 | brew install ${SIMULATOR} 20 | fi 21 | 22 | if ! [ -x "$(command -v x86_64-elf-ld)" ]; then 23 | echo 'Error: x86_64-elf-binutils is not installed.' 24 | echo 'Install x86_64-elf-binutils...' 25 | brew install x86_64-elf-binutils 26 | fi 27 | 28 | if ! [ -x "$(command -v x86_64-elf-gcc)" ]; then 29 | echo 'Error: x86_64-elf-gcc is not installed.' 30 | echo 'Install x86_64-elf-gcc...' 31 | brew install x86_64-elf-gcc 32 | fi 33 | 34 | if ! [ -x "$(command -v xorriso)" ]; then 35 | echo 'Error: xorriso is not installed.' 36 | echo 'Install xorriso...' 37 | brew install xorriso 38 | fi 39 | 40 | if ! [ -x "$(command -v $(GRUB_PATH)/grub-file)" ]; then 41 | sh ./grub4mac.sh 42 | fi 43 | -------------------------------------------------------------------------------- /tools/x86_64-elf-binutils.sh: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel (https://github.com/Simple-XX/SimpleKernel). 3 | # 4 | # i386-elf-binutils.sh for Simple-XX/SimpleKernel. 5 | 6 | #!/bin/bash 7 | 8 | if ! [ -x "$(command -v wget)" ]; then 9 | echo 'Error: wget is not installed.' 10 | exit 1 11 | elif ! [ -x "$(command -v tar)" ]; then 12 | echo 'Error: tar is not installed.' 13 | exit 1 14 | else 15 | wget https://ftp.gnu.org/gnu/binutils/binutils-2.34.tar.xz 16 | tar zxvf binutils-2.34.tar.xz 17 | cd binutils-2.34 18 | ./configure \ 19 | --target=x86_64-elf \ 20 | --enable-targets=all \ 21 | --enable-multilib \ 22 | --enable-64-bit-bfd \ 23 | --disable-werror 24 | make 25 | make install 26 | fi 27 | -------------------------------------------------------------------------------- /tools/x86_64-elf-gcc.sh: -------------------------------------------------------------------------------- 1 | 2 | # This file is a part of Simple-XX/SimpleKernel (https://github.com/Simple-XX/SimpleKernel). 3 | # 4 | # x86_64-elf-gcc.sh for Simple-XX/SimpleKernel. 5 | 6 | #!/bin/bash 7 | 8 | if ! [ -x "$(command -v x86_64-elf-ld)" ]; then 9 | echo 'Error: i386-elf-binutils is not installed.' 10 | exit 1 11 | elif ! [ -x "$(command -v wget)" ]; then 12 | echo 'Error: wget is not installed.' 13 | exit 1 14 | elif ! [ -x "$(command -v tar)" ]; then 15 | echo 'Error: tar is not installed.' 16 | exit 1 17 | else 18 | wget https://ftp.gnu.org/gnu/gcc/gcc-10.1.0/gcc-10.1.0.tar.xz 19 | tar zxvf gcc-10.1.0.tar.xz 20 | cd gcc-10.1.0 21 | ./configure \ 22 | --target=x86_64-elf \ 23 | --enable-targets=all \ 24 | --enable-multilib \ 25 | --without-isl \ 26 | --disable-werror \ 27 | --without-headers \ 28 | --with-as=x86_64-elf-as \ 29 | --with-ld=x86_64-elf-ld \ 30 | --enable-languages=c,c++ 31 | make all-gcc 32 | make install-gcc 33 | make all-target-libgcc 34 | make install-target-libgcc 35 | fi 36 | --------------------------------------------------------------------------------