Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa6b7924e2 |
+1
-3
@@ -1,9 +1,7 @@
|
|||||||
.cache
|
.cache
|
||||||
.vscode
|
|
||||||
build*
|
build*
|
||||||
.venv
|
.venv
|
||||||
initrd/image.cpio
|
initrd/image.cpio
|
||||||
initramfs/*
|
initramfs/*
|
||||||
|
|
||||||
target
|
target
|
||||||
Cargo.lock
|
|
||||||
+21
-15
@@ -10,7 +10,7 @@ find_program(MCOPY_EXE mcopy)
|
|||||||
find_program(MKFS_EXE mkfs.fat)
|
find_program(MKFS_EXE mkfs.fat)
|
||||||
find_program(CPIO_EXE cpio)
|
find_program(CPIO_EXE cpio)
|
||||||
find_program(QEMU_EXE qemu-system-x86_64)
|
find_program(QEMU_EXE qemu-system-x86_64)
|
||||||
set(OVMF_PATH "/usr/share/edk2/x64/OVMF.4m.fd" CACHE FILEPATH "Path to OVMF bios")
|
set(OVMF_PATH "/usr/share/edk2/ovmf/OVMF_CODE.fd" CACHE FILEPATH "Path to OVMF bios")
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND git describe --tags --always --dirty
|
COMMAND git describe --tags --always --dirty
|
||||||
@@ -26,15 +26,15 @@ endif()
|
|||||||
message(STATUS "Building termOS version: ${KERNEL_VERSION}")
|
message(STATUS "Building termOS version: ${KERNEL_VERSION}")
|
||||||
add_compile_definitions(TERMOS_VERSION=\"${KERNEL_VERSION}\")
|
add_compile_definitions(TERMOS_VERSION=\"${KERNEL_VERSION}\")
|
||||||
|
|
||||||
add_subdirectory(Boot)
|
add_subdirectory(bootloader)
|
||||||
add_subdirectory(System)
|
add_subdirectory(kernel)
|
||||||
add_subdirectory(Runtime)
|
add_subdirectory(userspace)
|
||||||
|
|
||||||
set(SYSTEM_SERVICES
|
set(SYSTEM_SERVICES
|
||||||
init
|
init
|
||||||
debug
|
debug
|
||||||
termosh
|
termosh
|
||||||
rtest
|
testOBJC
|
||||||
)
|
)
|
||||||
|
|
||||||
set(VOLUME_ROOT "${CMAKE_BINARY_DIR}/StartupVolume")
|
set(VOLUME_ROOT "${CMAKE_BINARY_DIR}/StartupVolume")
|
||||||
@@ -42,31 +42,37 @@ set(INITRAMFS_CPIO_FILE "${CMAKE_BINARY_DIR}/StartupVolume.cpio")
|
|||||||
set(IMG_FILE "${CMAKE_BINARY_DIR}/termOS.img")
|
set(IMG_FILE "${CMAKE_BINARY_DIR}/termOS.img")
|
||||||
|
|
||||||
if(MCOPY_EXE AND MKFS_EXE AND CPIO_EXE)
|
if(MCOPY_EXE AND MKFS_EXE AND CPIO_EXE)
|
||||||
add_custom_target(image ALL
|
add_custom_command(
|
||||||
|
OUTPUT ${INITRAMFS_CPIO_FILE}
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${VOLUME_ROOT}
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${VOLUME_ROOT}
|
||||||
COMMAND sh -c "find . -mindepth 1 ! -name '*.cpio' -print0 | ${CPIO_EXE} --null -ov -H newc > \"${INITRAMFS_CPIO_FILE}\""
|
COMMAND sh -c "find . -mindepth 1 ! -name '*.cpio' -print0 | ${CPIO_EXE} --null -ov -H newc > \"${INITRAMFS_CPIO_FILE}\""
|
||||||
|
WORKING_DIRECTORY ${VOLUME_ROOT}
|
||||||
|
DEPENDS ${SYSTEM_SERVICES}
|
||||||
|
VERBATIM
|
||||||
|
COMMENT "Packing StartupVolume to cpio..."
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${IMG_FILE}
|
||||||
COMMAND dd if=/dev/zero of=${IMG_FILE} bs=1M count=64 status=none
|
COMMAND dd if=/dev/zero of=${IMG_FILE} bs=1M count=64 status=none
|
||||||
COMMAND ${MKFS_EXE} -F 32 ${IMG_FILE}
|
COMMAND ${MKFS_EXE} -F 32 ${IMG_FILE}
|
||||||
COMMAND mmd -i ${IMG_FILE} ::/EFI ::/EFI/BOOT
|
COMMAND mmd -i ${IMG_FILE} ::/EFI ::/EFI/BOOT
|
||||||
COMMAND ${MCOPY_EXE} -i ${IMG_FILE} $<TARGET_FILE:BOOTX64> ::/EFI/BOOT/BOOTX64.EFI
|
COMMAND ${MCOPY_EXE} -i ${IMG_FILE} $<TARGET_FILE:BOOTX64> ::/EFI/BOOT/BOOTX64.EFI
|
||||||
COMMAND ${MCOPY_EXE} -i ${IMG_FILE} ${CMAKE_BINARY_DIR}/bin/kernel.bin ::/kernel.bin
|
COMMAND ${MCOPY_EXE} -i ${IMG_FILE} ${CMAKE_BINARY_DIR}/bin/kernel.bin ::/kernel.bin
|
||||||
COMMAND ${MCOPY_EXE} -i ${IMG_FILE} ${INITRAMFS_CPIO_FILE} ::/StartupVolume.cpio
|
COMMAND ${MCOPY_EXE} -i ${IMG_FILE} ${INITRAMFS_CPIO_FILE} ::/StartupVolume.cpio
|
||||||
|
DEPENDS BOOTX64 kernel ${INITRAMFS_CPIO_FILE}
|
||||||
WORKING_DIRECTORY ${VOLUME_ROOT}
|
|
||||||
DEPENDS BOOTX64 kernel ${SYSTEM_SERVICES}
|
|
||||||
VERBATIM
|
VERBATIM
|
||||||
COMMENT "Packing initramfs and generating bootable image: ${IMG_FILE}"
|
COMMENT "Generating bootable image: ${IMG_FILE}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_target(image ALL DEPENDS ${IMG_FILE})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(QEMU_EXE)
|
if(QEMU_EXE)
|
||||||
add_custom_target(run
|
add_custom_target(run
|
||||||
COMMAND ${QEMU_EXE}
|
COMMAND ${QEMU_EXE}
|
||||||
#-enable-kvm
|
-enable-kvm
|
||||||
$<$<BOOL:${APPLE}>:-machine> $<$<BOOL:${APPLE}>:q35>
|
-bios ${OVMF_PATH}
|
||||||
$<$<BOOL:${APPLE}>:-drive> $<$<BOOL:${APPLE}>:if=pflash,format=raw,readonly=on,file=${OVMF_PATH}>
|
|
||||||
$<$<NOT:$<BOOL:${APPLE}>>:-bios> $<$<NOT:$<BOOL:${APPLE}>>:${OVMF_PATH}>
|
|
||||||
-drive file=${IMG_FILE},format=raw
|
-drive file=${IMG_FILE},format=raw
|
||||||
-vga std
|
-vga std
|
||||||
-net none
|
-net none
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
|
|
||||||
**termOS** is a 64-bit, UNIX-hating, bespoke operating system written from scratch in C.
|
**termOS** is a 64-bit, UNIX-hating, bespoke operating system written from scratch in C.
|
||||||
|
|
||||||
Current Kernel: **Dewar** (v0.6.x)
|
Current Kernel: **Dewar** (v0.5.x)
|
||||||
|
|
||||||
## Philosophy
|
## Philosophy
|
||||||
|
|
||||||
- **Zero Bloat:** We don't port libraries; we write them.
|
- **Zero Bloat:** We don't port libraries; we write them.
|
||||||
- **Custom Everything:** Why use ELF when you can invent **HOT!**? Why use GRUB when you can write your own bootloader?
|
- **Custom Everything:** Why use ELF when you can invent **HOT!**? Why use GRUB when you can write your own bootloader (soon)?
|
||||||
|
|
||||||
## Features (v0.6.*)
|
## Features (v0.5.2)
|
||||||
|
|
||||||
- **Architecture:** x86_64 / UEFI.
|
- **Architecture:** x86_64 / UEFI.
|
||||||
- **Memory Management:** PMM (Bitmap), VMM (PML4 + Higher Half Direct Map), Kernel Heap.
|
- **Memory Management:** PMM (Bitmap), VMM (PML4 + Higher Half Direct Map), Kernel Heap.
|
||||||
@@ -24,8 +24,8 @@ Current Kernel: **Dewar** (v0.6.x)
|
|||||||
- **Isolation:** Ring 0 (Kernel) / Ring 3 (Userspace) protection.
|
- **Isolation:** Ring 0 (Kernel) / Ring 3 (Userspace) protection.
|
||||||
- **Binaries:** Custom **HOT!** executable format (parsed via custom `elf2hot` toolchain).
|
- **Binaries:** Custom **HOT!** executable format (parsed via custom `elf2hot` toolchain).
|
||||||
- **Filesystem:** VFS abstraction with CPIO Initramfs support.
|
- **Filesystem:** VFS abstraction with CPIO Initramfs support.
|
||||||
- **Graphics:** linear framebuffer driver.
|
- **Graphics:** `ShitGUI` (yes, really) linear framebuffer driver.
|
||||||
- **Shell:** `termosh`
|
- **Shell:** `ksh` (Kernel Shell) -> transitioning to userspace `ush`
|
||||||
|
|
||||||
## 🔥 The HOT! Format
|
## 🔥 The HOT! Format
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
project(termOSuserspace LANGUAGES C ASM_NASM)
|
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 23)
|
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
||||||
set(CMAKE_C_EXTENSIONS OFF)
|
|
||||||
|
|
||||||
message(STATUS "Building termOS's userspace")
|
|
||||||
|
|
||||||
set(TERMOS_OBJCOPY objcopy)
|
|
||||||
if(APPLE)
|
|
||||||
find_program(TERMOS_LD_LLD NAMES ld.lld HINTS /usr/local/bin /opt/homebrew/bin REQUIRED)
|
|
||||||
find_program(TERMOS_OBJCOPY NAMES llvm-objcopy objcopy HINTS /usr/local/opt/llvm/bin /opt/homebrew/opt/llvm/bin REQUIRED)
|
|
||||||
set(CMAKE_C_LINK_FLAGS "")
|
|
||||||
set(CMAKE_ASM_NASM_COMPILE_OBJECT
|
|
||||||
"<CMAKE_ASM_NASM_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -MD <DEP_FILE> -MT <DEP_TARGET> -f elf64 -o <OBJECT> <SOURCE>")
|
|
||||||
set(CMAKE_C_LINK_EXECUTABLE
|
|
||||||
"${TERMOS_LD_LLD} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory(libterm)
|
|
||||||
add_subdirectory(init)
|
|
||||||
add_subdirectory(rust)
|
|
||||||
add_subdirectory(debug)
|
|
||||||
add_subdirectory(termosh)
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#include <termOS.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
ConsolePrint("Test test test \n Meow meow meow \n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
[env]
|
|
||||||
RUST_TARGET_PATH = { value = ".", relative = true }
|
|
||||||
|
|
||||||
[build]
|
|
||||||
target = "x86_64-termos"
|
|
||||||
|
|
||||||
[unstable]
|
|
||||||
build-std =["core", "alloc", "compiler_builtins"]
|
|
||||||
build-std-features = ["compiler-builtins-mem"]
|
|
||||||
|
|
||||||
[target.x86_64-termos]
|
|
||||||
rustflags =[
|
|
||||||
"-Z", "unstable-options",
|
|
||||||
"-C", "link-arg=-Tlinker.ld"
|
|
||||||
]
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
|
||||||
project(rustApps NONE)
|
|
||||||
|
|
||||||
function(add_rust_app NAME)
|
|
||||||
set(RUST_TARGET "x86_64-termos")
|
|
||||||
set(RUST_TARGET_DIR "${CMAKE_CURRENT_SOURCE_DIR}/target")
|
|
||||||
set(RUST_ELF_FILE "${RUST_TARGET_DIR}/${RUST_TARGET}/release/${NAME}")
|
|
||||||
|
|
||||||
set(STARTUP_VOLUME_DIR "${CMAKE_BINARY_DIR}/StartupVolume/System/CoreServices")
|
|
||||||
set(FINAL_HOT_PATH "${STARTUP_VOLUME_DIR}/${NAME}")
|
|
||||||
set(STRIPPED_ELF "${CMAKE_CURRENT_BINARY_DIR}/${NAME}.stripped")
|
|
||||||
set(ELF2HOT_DIR "${CMAKE_SOURCE_DIR}/tools/elf2hot")
|
|
||||||
|
|
||||||
file(MAKE_DIRECTORY "${STARTUP_VOLUME_DIR}")
|
|
||||||
|
|
||||||
add_custom_target(${NAME} ALL
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E env
|
|
||||||
"CARGO_TARGET_DIR=${RUST_TARGET_DIR}"
|
|
||||||
cargo build --package ${NAME} --release --target ${RUST_TARGET}
|
|
||||||
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E env
|
|
||||||
"PATH=/usr/local/opt/llvm/bin:/opt/homebrew/opt/llvm/bin:$ENV{PATH}"
|
|
||||||
llvm-objcopy --strip-all ${RUST_ELF_FILE} ${STRIPPED_ELF}
|
|
||||||
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E chdir ${ELF2HOT_DIR} cargo run --release --quiet -- ${STRIPPED_ELF} ${FINAL_HOT_PATH}
|
|
||||||
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
COMMENT "Building, stripping and packing ${NAME} to initramfs..."
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
add_rust_app(rtest)
|
|
||||||
Generated
-50
@@ -1,50 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 4
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "linked_list_allocator"
|
|
||||||
version = "0.10.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2b23ac50abb8261cb38c6e2a7192d3302e0836dac1628f6a93b82b4fad185897"
|
|
||||||
dependencies = [
|
|
||||||
"spinning_top",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lock_api"
|
|
||||||
version = "0.4.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
|
|
||||||
dependencies = [
|
|
||||||
"scopeguard",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rtest"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"std",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "scopeguard"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "spinning_top"
|
|
||||||
version = "0.2.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0"
|
|
||||||
dependencies = [
|
|
||||||
"lock_api",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "std"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"linked_list_allocator",
|
|
||||||
]
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
[workspace]
|
|
||||||
members = ["std", "apps/rtest"]
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
strip = true
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "rtest"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
std = { path = "../../std" }
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
let anus = "jopa";
|
|
||||||
println!("meow");
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
ENTRY(_start)
|
|
||||||
|
|
||||||
SECTIONS
|
|
||||||
{
|
|
||||||
. = 0x400000;
|
|
||||||
|
|
||||||
.text : {
|
|
||||||
*(.text)
|
|
||||||
}
|
|
||||||
|
|
||||||
.rodata : {
|
|
||||||
*(.rodata)
|
|
||||||
}
|
|
||||||
|
|
||||||
.data : {
|
|
||||||
*(.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
.bss : {
|
|
||||||
*(.bss)
|
|
||||||
*(COMMON)
|
|
||||||
}
|
|
||||||
|
|
||||||
/DISCARD/ : {
|
|
||||||
*(.note.gnu.build-id)
|
|
||||||
*(.note.GNU-stack)
|
|
||||||
*(.note.gnu.property)
|
|
||||||
*(.comment)
|
|
||||||
*(.interp)
|
|
||||||
*(.dynsym)
|
|
||||||
*(.dynstr)
|
|
||||||
*(.hash)
|
|
||||||
*(.gnu.hash)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
[toolchain]
|
|
||||||
channel = "nightly"
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "std"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
linked_list_allocator = "0.10.6"
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
extern crate alloc;
|
|
||||||
|
|
||||||
use core::alloc::{GlobalAlloc, Layout};
|
|
||||||
use linked_list_allocator::LockedHeap;
|
|
||||||
|
|
||||||
#[global_allocator]
|
|
||||||
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
|
||||||
|
|
||||||
pub unsafe fn init_heap() {
|
|
||||||
let heap_size = 1024 * 1024;
|
|
||||||
let heap_start = crate::syscall::memory_allocate(heap_size);
|
|
||||||
|
|
||||||
ALLOCATOR.lock().init(heap_start as *mut u8, heap_size);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
use core::fmt::{self, Write};
|
|
||||||
|
|
||||||
pub struct Stdout;
|
|
||||||
|
|
||||||
impl Write for Stdout {
|
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
||||||
crate::syscall::io_write(1, s.as_ptr(), s.len());
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub fn _print(args: core::fmt::Arguments) {
|
|
||||||
let mut stdout = crate::io::Stdout;
|
|
||||||
let _ = core::fmt::Write::write_fmt(&mut stdout, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! print {
|
|
||||||
($($arg:tt)*) => ($crate::io::_print(core::format_args!($($arg)*)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! println {
|
|
||||||
() => ($crate::print!("\n"));
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
$crate::print!($($arg)*);
|
|
||||||
$crate::print!("\n");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
#![no_std]
|
|
||||||
#![feature(lang_items)]
|
|
||||||
|
|
||||||
pub use core::*;
|
|
||||||
extern crate alloc;
|
|
||||||
pub use alloc::*;
|
|
||||||
|
|
||||||
pub mod allocator;
|
|
||||||
pub mod io;
|
|
||||||
pub mod panic;
|
|
||||||
pub mod syscall;
|
|
||||||
|
|
||||||
|
|
||||||
pub mod prelude {
|
|
||||||
pub mod rust_2024 {
|
|
||||||
pub use core::prelude::rust_2024::*;
|
|
||||||
pub use alloc::string::{String, ToString};
|
|
||||||
pub use alloc::vec::Vec;
|
|
||||||
pub use alloc::vec;
|
|
||||||
pub use alloc::format;
|
|
||||||
pub use crate::{print, println};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core::arch::global_asm!(
|
|
||||||
".global _start",
|
|
||||||
"_start:",
|
|
||||||
"and rsp, ~0xF",
|
|
||||||
"xor rdi, rdi",
|
|
||||||
"xor rsi, rsi",
|
|
||||||
"call main",
|
|
||||||
"mov rdi, rax",
|
|
||||||
"mov rax, 0",
|
|
||||||
"syscall"
|
|
||||||
);
|
|
||||||
|
|
||||||
#[lang = "start"]
|
|
||||||
fn lang_start<T>(
|
|
||||||
user_main: fn() -> T,
|
|
||||||
_argc: isize,
|
|
||||||
_argv: *const *const u8,
|
|
||||||
_sigpipe: u8,
|
|
||||||
) -> isize {
|
|
||||||
unsafe { crate::allocator::init_heap() };
|
|
||||||
|
|
||||||
user_main();
|
|
||||||
|
|
||||||
crate::syscall::process_exit(0);
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
use core::panic::PanicInfo;
|
|
||||||
use crate::println;
|
|
||||||
|
|
||||||
#[panic_handler]
|
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
|
||||||
println!("{}", info);
|
|
||||||
|
|
||||||
crate::syscall::process_exit(1);
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
use core::arch::asm;
|
|
||||||
|
|
||||||
pub const SYS_EXIT: usize = 0;
|
|
||||||
pub const SYS_SPAWN: usize = 1;
|
|
||||||
pub const SYS_ALLOC: usize = 2;
|
|
||||||
pub const SYS_WRITE: usize = 3;
|
|
||||||
pub const SYS_READ: usize = 4;
|
|
||||||
pub const SYS_WAIT: usize = 5;
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
unsafe fn syscall1(num: usize, arg1: usize) -> usize {
|
|
||||||
let ret: usize;
|
|
||||||
unsafe {
|
|
||||||
asm!(
|
|
||||||
"syscall",
|
|
||||||
inout("rax") num => ret,
|
|
||||||
in("rdi") arg1,
|
|
||||||
out("rcx") _,
|
|
||||||
out("r11") _,
|
|
||||||
options(nostack, preserves_flags)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
unsafe fn syscall3(num: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
|
|
||||||
let ret: usize;
|
|
||||||
core::arch::asm!(
|
|
||||||
"syscall",
|
|
||||||
in("rax") num,
|
|
||||||
in("rdi") arg1,
|
|
||||||
in("rsi") arg2,
|
|
||||||
in("rdx") arg3,
|
|
||||||
lateout("rax") ret,
|
|
||||||
out("rcx") _,
|
|
||||||
out("r11") _,
|
|
||||||
options(nostack)
|
|
||||||
);
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process_exit(code: usize) -> ! {
|
|
||||||
unsafe { syscall1(SYS_EXIT, code) };
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process_spawn(path: usize) -> usize {
|
|
||||||
unsafe { syscall1(SYS_SPAWN, path) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process_wait(pid: usize) -> usize {
|
|
||||||
unsafe { syscall1(SYS_WAIT, pid) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn memory_allocate(size: usize) -> usize {
|
|
||||||
unsafe { syscall1(SYS_ALLOC, size) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn io_write(fd: usize, buf: *const u8, len: usize) -> usize {
|
|
||||||
unsafe { syscall3(SYS_WRITE, fd, buf as usize, len) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn io_read(fd: usize, buf: *const u8, len: usize) -> usize {
|
|
||||||
unsafe { syscall3(SYS_READ, fd, buf as usize, len) }
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"llvm-target": "x86_64-unknown-none",
|
|
||||||
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
|
|
||||||
"arch": "x86_64",
|
|
||||||
"target-endian": "little",
|
|
||||||
"target-pointer-width": 64,
|
|
||||||
"target-c-int-width": 32,
|
|
||||||
"os": "termos",
|
|
||||||
"executables": true,
|
|
||||||
"linker-flavor": "ld.lld",
|
|
||||||
"linker": "rust-lld",
|
|
||||||
"panic-strategy": "abort",
|
|
||||||
"position-independent-executables": true,
|
|
||||||
"relocation-model": "pic"
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
project(termOS_Bootloader LANGUAGES C ASM)
|
project(termOS_Bootloader LANGUAGES C ASM)
|
||||||
|
|
||||||
if(APPLE)
|
|
||||||
set(CMAKE_C_LINK_FLAGS "")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(UEFI_COMPILE_OPTIONS
|
set(UEFI_COMPILE_OPTIONS
|
||||||
-std=c23
|
-std=c23
|
||||||
-target x86_64-unknown-windows-msvc
|
-target x86_64-unknown-windows-msvc
|
||||||
@@ -24,15 +20,14 @@ set(POSIX_UEFI_SOURCES
|
|||||||
src/uefi/unistd.c
|
src/uefi/unistd.c
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(posix_uefi_lib OBJECT ${POSIX_UEFI_SOURCES})
|
add_library(posix_uefi_lib STATIC ${POSIX_UEFI_SOURCES})
|
||||||
target_compile_options(posix_uefi_lib PRIVATE ${UEFI_COMPILE_OPTIONS})
|
target_compile_options(posix_uefi_lib PRIVATE ${UEFI_COMPILE_OPTIONS})
|
||||||
target_include_directories(posix_uefi_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/uefi)
|
target_include_directories(posix_uefi_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/uefi)
|
||||||
|
|
||||||
add_executable(BOOTX64 src/main.c)
|
add_executable(BOOTX64 src/main.c)
|
||||||
target_compile_options(BOOTX64 PRIVATE ${UEFI_COMPILE_OPTIONS})
|
target_compile_options(BOOTX64 PRIVATE ${UEFI_COMPILE_OPTIONS})
|
||||||
target_sources(BOOTX64 PRIVATE $<TARGET_OBJECTS:posix_uefi_lib>)
|
|
||||||
|
|
||||||
target_include_directories(BOOTX64 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/uefi)
|
target_link_libraries(BOOTX64 PRIVATE posix_uefi_lib)
|
||||||
|
|
||||||
target_link_options(BOOTX64 PRIVATE
|
target_link_options(BOOTX64 PRIVATE
|
||||||
-fuse-ld=lld
|
-fuse-ld=lld
|
||||||
@@ -11,17 +11,6 @@ endif()
|
|||||||
|
|
||||||
message(STATUS "Dewar kernel: Building for architecture '${ARCH}'")
|
message(STATUS "Dewar kernel: Building for architecture '${ARCH}'")
|
||||||
|
|
||||||
set(TERMOS_OBJCOPY objcopy)
|
|
||||||
if(APPLE)
|
|
||||||
find_program(TERMOS_LD_LLD NAMES ld.lld HINTS /usr/local/bin /opt/homebrew/bin REQUIRED)
|
|
||||||
find_program(TERMOS_OBJCOPY NAMES llvm-objcopy objcopy HINTS /usr/local/opt/llvm/bin /opt/homebrew/opt/llvm/bin REQUIRED)
|
|
||||||
set(CMAKE_C_LINK_FLAGS "")
|
|
||||||
set(CMAKE_ASM_NASM_COMPILE_OBJECT
|
|
||||||
"<CMAKE_ASM_NASM_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -MD <DEP_FILE> -MT <DEP_TARGET> -f elf64 -o <OBJECT> <SOURCE>")
|
|
||||||
set(CMAKE_C_LINK_EXECUTABLE
|
|
||||||
"${TERMOS_LD_LLD} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
file(GLOB_RECURSE KERNEL_SOURCES CMAKE_CONFIGURE_DEPENDS
|
file(GLOB_RECURSE KERNEL_SOURCES CMAKE_CONFIGURE_DEPENDS
|
||||||
"src/kmain.c"
|
"src/kmain.c"
|
||||||
@@ -35,13 +24,13 @@ file(GLOB_RECURSE KERNEL_SOURCES CMAKE_CONFIGURE_DEPENDS
|
|||||||
"src/lib/*.c"
|
"src/lib/*.c"
|
||||||
"src/IO/*.c"
|
"src/IO/*.c"
|
||||||
"src/VM/*.c"
|
"src/VM/*.c"
|
||||||
|
"src/KSH/*.c"
|
||||||
"src/FS/*.c"
|
"src/FS/*.c"
|
||||||
|
|
||||||
"Data/*.c"
|
"Data/*.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(kernel ${KERNEL_SOURCES})
|
add_executable(kernel ${KERNEL_SOURCES})
|
||||||
set_target_properties(kernel PROPERTIES NASM_OBJ_FORMAT elf64)
|
|
||||||
|
|
||||||
target_include_directories(kernel PRIVATE
|
target_include_directories(kernel PRIVATE
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../common"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../common"
|
||||||
@@ -52,7 +41,6 @@ target_include_directories(kernel PRIVATE
|
|||||||
|
|
||||||
target_compile_options(kernel PRIVATE
|
target_compile_options(kernel PRIVATE
|
||||||
$<$<COMPILE_LANGUAGE:C>:
|
$<$<COMPILE_LANGUAGE:C>:
|
||||||
$<$<BOOL:${APPLE}>:--target=x86_64-none-elf>
|
|
||||||
-ffreestanding
|
-ffreestanding
|
||||||
-mno-red-zone
|
-mno-red-zone
|
||||||
-fno-stack-protector
|
-fno-stack-protector
|
||||||
@@ -60,9 +48,7 @@ target_compile_options(kernel PRIVATE
|
|||||||
-Wall -Wextra
|
-Wall -Wextra
|
||||||
-mcmodel=kernel
|
-mcmodel=kernel
|
||||||
-g
|
-g
|
||||||
-mno-sse -mno-sse2 -msoft-float
|
|
||||||
>
|
>
|
||||||
$<$<AND:$<BOOL:${APPLE}>,$<COMPILE_LANGUAGE:ASM>>:--target=x86_64-none-elf>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_options(kernel PRIVATE
|
target_link_options(kernel PRIVATE
|
||||||
@@ -79,8 +65,6 @@ set_target_properties(kernel PROPERTIES
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_custom_command(TARGET kernel POST_BUILD
|
add_custom_command(TARGET kernel POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E env
|
COMMAND objcopy -O binary $<TARGET_FILE:kernel> $<TARGET_FILE_DIR:kernel>/kernel.bin
|
||||||
"PATH=/usr/local/opt/llvm/bin:/opt/homebrew/opt/llvm/bin:$ENV{PATH}"
|
|
||||||
llvm-objcopy -O binary $<TARGET_FILE:kernel> $<TARGET_FILE_DIR:kernel>/kernel.bin
|
|
||||||
COMMENT "Generating raw binary kernel.bin..."
|
COMMENT "Generating raw binary kernel.bin..."
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2026 0xKarinyash
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void KSHCommandKernelFetch();
|
||||||
|
void KSHCommandMeow();
|
||||||
|
void KSHCommandHelp();
|
||||||
|
void KSHCommandRegisters();
|
||||||
|
void KSHCommandSleep();
|
||||||
|
void KSHCommandDebug();
|
||||||
|
void KSHCommandRand();
|
||||||
|
void KSHCommandVer();
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2026 0xKarinyash
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
UInt64 KSHDebug();
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2026 0xKarinyash
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void KSHEntry();
|
||||||
@@ -6,4 +6,4 @@
|
|||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
|
||||||
Int32 OSLoaderProcessSpawn(const char* executablePath, const char* processName);
|
Int32 OSLoaderProcessSpawn(const char* executablePath, const char* processName);
|
||||||
void initTask();
|
void init_task_entry();
|
||||||
@@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
void VMVirtualMemoryInitialize(Bootinfo* info);
|
void VMVirtualMemoryInitialize(Bootinfo* info);
|
||||||
UInt64* VMVirtualMemoryMapPage(UInt64* PML4, UInt64 physical, UInt64 virtual, UInt64 flags);
|
UInt64* VMVirtualMemoryMapPage(UInt64* PML4, UInt64 physical, UInt64 virtual, UInt64 flags);
|
||||||
void* VMVirtualMemoryGetOrAllocatePage(UInt64* PML4, UInt64 virtual, UInt64 flags);
|
|
||||||
UInt64 VMVirtualMemoryCreateAddressSpace();
|
UInt64 VMVirtualMemoryCreateAddressSpace();
|
||||||
UInt64 VMGetCurrentCR3();
|
UInt64 VMGetCurrentCR3();
|
||||||
void VMLoadCR3(UInt64 PML4Address);
|
void VMLoadCR3(UInt64 PML4Address);
|
||||||
@@ -10,5 +10,4 @@ Int32 StringCompare(const char* firstString, const char* secondString);
|
|||||||
Int32 StringCompareWithLimit(const char* firstString, const char* secondString, UInt64 limit);
|
Int32 StringCompareWithLimit(const char* firstString, const char* secondString, UInt64 limit);
|
||||||
char* StringCopy(char* destination, const char* source);
|
char* StringCopy(char* destination, const char* source);
|
||||||
char* StringCopyWithLimit(char* destination, const char* source, UInt64 limit);
|
char* StringCopyWithLimit(char* destination, const char* source, UInt64 limit);
|
||||||
UInt64 StringGetLength(const char* string);
|
UInt64 StringGetLength(const char* string);
|
||||||
const char* StringFindLastOccurrenceOfCharacter(const char* string, char separator);
|
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2026 0xKarinyash
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
#include <OSCPU.h>
|
||||||
|
|
||||||
|
#include <IO/IOConsole.h>
|
||||||
|
#include <IO/IOTimer.h>
|
||||||
|
|
||||||
|
#include <lib/String.h>
|
||||||
|
#include <lib/Rand.h>
|
||||||
|
|
||||||
|
#include <OS/OSScheduler.h>
|
||||||
|
|
||||||
|
#include <VM/VMM.h>
|
||||||
|
#include <VM/Heap.h>
|
||||||
|
|
||||||
|
#include <KSH/KSHDebug.h>
|
||||||
|
|
||||||
|
#include <Data/cats.h>
|
||||||
|
|
||||||
|
|
||||||
|
const char* asciiLogo[] = {
|
||||||
|
" /\\___/\\ ",
|
||||||
|
" | > < | ",
|
||||||
|
" | w | ",
|
||||||
|
" |=======|__ ",
|
||||||
|
" | | | ",
|
||||||
|
" |TERMOS | | ",
|
||||||
|
" | |__| ",
|
||||||
|
" |_______| "
|
||||||
|
};
|
||||||
|
|
||||||
|
void KSHCommandKernelFetch() {
|
||||||
|
UInt64 uptimeSeconds = IOTimerGetTicks() / 1000;
|
||||||
|
|
||||||
|
IOConsoleLog("\n\n");
|
||||||
|
IOConsoleLog("^p %s ^!\t\t^g kernel^!@^gtermos\n^0", asciiLogo[0]);
|
||||||
|
IOConsoleLog("^p %s ^!\t\t^!-------------\n^!", asciiLogo[1]);
|
||||||
|
IOConsoleLog("^p %s ^!\t\t^gOS^!: termOS %s\n^!", asciiLogo[2], TERMOS_VERSION);
|
||||||
|
IOConsoleLog("^p %s ^!\t\t^gKernel^!: Dewar (x86_64), build: %s %s\n^!", asciiLogo[3], __DATE__, __TIME__);
|
||||||
|
IOConsoleLog("^p %s ^!\t\t^gUptime^!: %d seconds\n^!", asciiLogo[4], uptimeSeconds);
|
||||||
|
IOConsoleLog("^p %s ^!\t\t^gShell^!: ksh\n^!", asciiLogo[5]);
|
||||||
|
IOConsoleLog("^p %s ^!\t\t^gDE^!: shitgui\n^!", asciiLogo[6]);
|
||||||
|
IOConsoleLog("^p %s ^!\t\t^gCPU^!: %s (^yFamily^!: %d; ^yModel^!: %d)\n^!", asciiLogo[7], gOSBootCPU.vendorID, gOSBootCPU.family, gOSBootCPU.model);
|
||||||
|
IOConsoleLog("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSHCommandMeow() {
|
||||||
|
UInt64 catsCount = sizeof(cats) / sizeof(cats[0]);
|
||||||
|
UInt8 randomNumber = Rand() % catsCount;
|
||||||
|
IOConsoleLog("Nyaaa!!\n\n%s\n\n", cats[randomNumber]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSHCommandHelp() {
|
||||||
|
IOConsoleLog("Welcome to ^ptermOS^!'s ^gk^!ernel ^gsh^!ell!\n");
|
||||||
|
IOConsoleLog("It loads when userspace is failed to load and acts as a basic rescue environment\n");
|
||||||
|
IOConsoleLog("Available commands:\n");
|
||||||
|
|
||||||
|
IOConsoleLog("\t^rDebug^!:\n");
|
||||||
|
IOConsoleLog("\t\t^ysleep^! \t\tSleep for 3seconds\n");
|
||||||
|
IOConsoleLog("\t\t^ydbg^! \t\tTest new stuff\n");
|
||||||
|
IOConsoleLog("\t\t^yregs^! \t\tPrint current regs\n");
|
||||||
|
IOConsoleLog("\t\t^ypanic^! \t\tPanics (lol)\n");
|
||||||
|
IOConsoleLog("\t\t^yud2^! \t\tPanics with #UD\n");
|
||||||
|
IOConsoleLog("\t\t^ypf^! \t\tPanics with #PF\n");
|
||||||
|
|
||||||
|
IOConsoleLog("\t^pFun^!:\n");
|
||||||
|
IOConsoleLog("\t\t^ysplash^! \t\tShows splash (works kinda unstable)\n");
|
||||||
|
IOConsoleLog("\t\t^ymeow^! \t\tcats!!!\n");
|
||||||
|
IOConsoleLog("\t\t^ykfetch^! \t\tr/unixporn compatible\n");
|
||||||
|
|
||||||
|
IOConsoleLog("\t^bMisc^!:\n");
|
||||||
|
IOConsoleLog("\t\t^yclear^! \t\tClear console\n");
|
||||||
|
IOConsoleLog("\t\t^yhelp^! \t\tShow this menu\n");
|
||||||
|
IOConsoleLog("\t\t^yrand^! \t\tGet a random number\n");
|
||||||
|
IOConsoleLog("\t\t^yver^! \t\tDisplays termOS's version\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSHCommandRegisters() {
|
||||||
|
__asm__ volatile ("int3");
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSHCommandSleep() {
|
||||||
|
OSSchedulerYield(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSHCommandRand() {
|
||||||
|
IOConsoleLog("Your rand number (0..100) is ... ^y%d^!!\n", Rand() % 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSHCommandDebug() {
|
||||||
|
UInt64 status = KSHDebug();
|
||||||
|
IOConsoleLog("\nDebug ended with code %d\n", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSHCommandVer() {
|
||||||
|
IOConsoleLog("termOS version %s\n", TERMOS_VERSION);
|
||||||
|
IOConsoleLog("Dewar Kernel (x86_64), build: %s %s\n", __DATE__, __TIME__);
|
||||||
|
IOConsoleLog("License: GPL-3.0-or-later\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_userspace() {
|
||||||
|
IOConsoleLog("Command disabled due to be really broken\n");
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2026 0xKarinyash
|
||||||
|
|
||||||
|
#include <KSH/KSHDebug.h>
|
||||||
|
#include <IO/IOConsole.h>
|
||||||
|
|
||||||
|
UInt64 KSHDebug() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
// Copyright (c) 2026 0xKarinyash
|
||||||
|
|
||||||
|
#include <KSH/KSHEntry.h>
|
||||||
|
#include <KSH/KSHBuiltins.h>
|
||||||
|
|
||||||
|
#include <IO/IOConsole.h>
|
||||||
|
#include <IO/IOGraphics.h>
|
||||||
|
|
||||||
|
#include <OS/OSPanic.h>
|
||||||
|
#include <OS/OSScheduler.h>
|
||||||
|
|
||||||
|
#include <lib/String.h>
|
||||||
|
#include <lib/Rand.h>
|
||||||
|
#include <lib/Splash.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TOKEN_EMPTY,
|
||||||
|
|
||||||
|
TOKEN_NULL,
|
||||||
|
TOKEN_ILLEGAL,
|
||||||
|
|
||||||
|
TOKEN_HELP,
|
||||||
|
TOKEN_SPLASH,
|
||||||
|
|
||||||
|
TOKEN_KFETCH,
|
||||||
|
TOKEN_MEOW,
|
||||||
|
|
||||||
|
TOKEN_SLEEP,
|
||||||
|
|
||||||
|
TOKEN_REGS,
|
||||||
|
TOKEN_DEBUG,
|
||||||
|
TOKEN_RECTEST,
|
||||||
|
TOKEN_PANIC,
|
||||||
|
TOKEN_PANIC_UD2,
|
||||||
|
TOKEN_PANIC_PF,
|
||||||
|
|
||||||
|
TOKEN_CLEAR,
|
||||||
|
TOKEN_RAND,
|
||||||
|
TOKEN_VER,
|
||||||
|
|
||||||
|
TOKEN_BACK,
|
||||||
|
TOKEN_FORWARD,
|
||||||
|
} KSHToken;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char* str;
|
||||||
|
KSHToken token;
|
||||||
|
} KSHCommandMap;
|
||||||
|
|
||||||
|
static const KSHCommandMap CommandMap[] = {
|
||||||
|
{"", TOKEN_EMPTY},
|
||||||
|
// debug
|
||||||
|
{"sleep", TOKEN_SLEEP},
|
||||||
|
{"dbg", TOKEN_DEBUG},
|
||||||
|
{"regs", TOKEN_REGS},
|
||||||
|
{"panic", TOKEN_PANIC},
|
||||||
|
{"ud2", TOKEN_PANIC_UD2},
|
||||||
|
{"pf", TOKEN_PANIC_PF},
|
||||||
|
|
||||||
|
// fun
|
||||||
|
{"meow", TOKEN_MEOW},
|
||||||
|
{"splash", TOKEN_SPLASH},
|
||||||
|
{"kfetch", TOKEN_KFETCH},
|
||||||
|
|
||||||
|
// misc
|
||||||
|
{"help", TOKEN_HELP},
|
||||||
|
{"clear", TOKEN_CLEAR},
|
||||||
|
{"rand", TOKEN_RAND},
|
||||||
|
{"ver", TOKEN_VER},
|
||||||
|
|
||||||
|
{nullptr, TOKEN_NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
KSHToken KSHCharacter2Token(char* token) {
|
||||||
|
for (Int32 i = 0; CommandMap[i].str != nullptr; i++) {
|
||||||
|
if (StringCompare(token, CommandMap[i].str) == 0) return CommandMap[i].token;
|
||||||
|
}
|
||||||
|
return TOKEN_ILLEGAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSHEntry() {
|
||||||
|
while (true) {
|
||||||
|
IOConsoleLog("ksh_> ");
|
||||||
|
char cmdbuff[256];
|
||||||
|
IOConsoleReadLine(cmdbuff, 256);
|
||||||
|
switch(KSHCharacter2Token(cmdbuff)) {
|
||||||
|
case TOKEN_EMPTY: continue;
|
||||||
|
|
||||||
|
case TOKEN_CLEAR: IOConsoleClear((UInt32) IOConsoleGetColors() & 0xFFFFFFFF); break;
|
||||||
|
case TOKEN_RAND: KSHCommandRand(); break;
|
||||||
|
case TOKEN_VER: KSHCommandVer(); break;
|
||||||
|
|
||||||
|
case TOKEN_SLEEP: KSHCommandSleep(); break;
|
||||||
|
case TOKEN_DEBUG: KSHCommandDebug(); break;
|
||||||
|
case TOKEN_REGS: KSHCommandRegisters(); break;
|
||||||
|
case TOKEN_PANIC: OSPanic("Manually initiated panic");
|
||||||
|
case TOKEN_PANIC_UD2: __asm__ volatile ("ud2");
|
||||||
|
case TOKEN_PANIC_PF: UInt64* bad_ptr = (UInt64*)0xDEADBEEF; *bad_ptr = 666;
|
||||||
|
|
||||||
|
case TOKEN_SPLASH: SplashShow(IOConsoleGetGraphicsContext()); break;
|
||||||
|
case TOKEN_KFETCH: KSHCommandKernelFetch(); break;
|
||||||
|
case TOKEN_MEOW: KSHCommandMeow(); break;
|
||||||
|
|
||||||
|
case TOKEN_HELP: KSHCommandHelp(); break;
|
||||||
|
default: IOConsoleLog("Unknown command!!\n"); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,10 +26,10 @@ UInt64 HOTLoad(OSProcess* process, UInt8* data) {
|
|||||||
UInt64 end = (segment->vaddr + segment->memsz + 0xFFF) & ~(0xFFFULL);
|
UInt64 end = (segment->vaddr + segment->memsz + 0xFFF) & ~(0xFFFULL);
|
||||||
|
|
||||||
for (UInt64 address = start; address < end; address += kVMPageSize) {
|
for (UInt64 address = start; address < end; address += kVMPageSize) {
|
||||||
void* kernelVirtAddress = VMVirtualMemoryGetOrAllocatePage((UInt64*)process->physicalPML4, address, PTE_USER | PTE_RW | PTE_PRESENT);
|
void* physicalPage = VMPhysicalMemoryAllocatePage();
|
||||||
if (!kernelVirtAddress) {
|
VMVirtualMemoryMapPage((UInt64*)process->physicalPML4, (UInt64)physicalPage, address, PTE_USER | PTE_RW | PTE_PRESENT);
|
||||||
return 0;
|
void* kernelVirtAddress = (void*)((UInt64)physicalPage + HHDM_OFFSET);
|
||||||
}
|
MemorySet(kernelVirtAddress, 0, kVMPageSize);
|
||||||
UInt64 pageOverleapStart = (address > segment->vaddr) ? address : segment->vaddr;
|
UInt64 pageOverleapStart = (address > segment->vaddr) ? address : segment->vaddr;
|
||||||
UInt64 pageOverleapEnd = (address + kVMPageSize < segment->vaddr + segment->filesz)
|
UInt64 pageOverleapEnd = (address + kVMPageSize < segment->vaddr + segment->filesz)
|
||||||
? (address + kVMPageSize)
|
? (address + kVMPageSize)
|
||||||
@@ -71,7 +71,7 @@ Int32 OSLoaderProcessSpawn(const char* executablePath, const char* processName)
|
|||||||
return newProcess->processId;
|
return newProcess->processId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initTask() {
|
void init_task_entry() {
|
||||||
Int32 pid = OSLoaderProcessSpawn("/System/CoreServices/init", "init");
|
Int32 pid = OSLoaderProcessSpawn("/System/CoreServices/init", "init");
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
OSPanic("FATAL: Failed to spawn /System/CoreServices/init");
|
OSPanic("FATAL: Failed to spawn /System/CoreServices/init");
|
||||||
+1
-9
@@ -7,9 +7,6 @@
|
|||||||
#include <OS/Exec/OSLoader.h>
|
#include <OS/Exec/OSLoader.h>
|
||||||
#include <IO/IOConsole.h>
|
#include <IO/IOConsole.h>
|
||||||
|
|
||||||
|
|
||||||
#include <lib/String.h>
|
|
||||||
|
|
||||||
Int32 OSServiceProcessExit(Int32 code) {
|
Int32 OSServiceProcessExit(Int32 code) {
|
||||||
IOConsoleLog("\n[Dewar] process \"%s\" exited with code %d\n", gOSSchedulerCurrentTask->process->name, code);
|
IOConsoleLog("\n[Dewar] process \"%s\" exited with code %d\n", gOSSchedulerCurrentTask->process->name, code);
|
||||||
OSSchedulerTerminate();
|
OSSchedulerTerminate();
|
||||||
@@ -18,12 +15,7 @@ Int32 OSServiceProcessExit(Int32 code) {
|
|||||||
|
|
||||||
|
|
||||||
Int32 OSServiceProcessSpawn(const char* path) {
|
Int32 OSServiceProcessSpawn(const char* path) {
|
||||||
const char* name = StringFindLastOccurrenceOfCharacter(path, '/');
|
return OSLoaderProcessSpawn(path, path);
|
||||||
|
|
||||||
if (name) name++;
|
|
||||||
else name = path;
|
|
||||||
|
|
||||||
return OSLoaderProcessSpawn(path, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 OSServiceProcessWait(UInt64 processID) {
|
Int32 OSServiceProcessWait(UInt64 processID) {
|
||||||
@@ -94,28 +94,6 @@ static UInt64* sVMVirtualMemoryMapPageInternal(UInt64* pml4, UInt64 phys, UInt64
|
|||||||
return (UInt64*)virt;
|
return (UInt64*)virt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* sVMVirtualMemoryGetMappedPageInternal(UInt64* pml4, UInt64 virt) {
|
|
||||||
UInt64 pt_idx = VMM_PT_INDEX(virt);
|
|
||||||
UInt64 pd_idx = VMM_PD_INDEX(virt);
|
|
||||||
UInt64 pdpt_idx = VMM_PDPT_INDEX(virt);
|
|
||||||
UInt64 pml4_idx = VMM_PML4_INDEX(virt);
|
|
||||||
|
|
||||||
UInt64* pml4_virt = pml4;
|
|
||||||
if (isInitialized) pml4_virt = (UInt64*)PHYS_TO_HHDM((UInt64)pml4);
|
|
||||||
|
|
||||||
if (!(pml4_virt[pml4_idx] & PTE_PRESENT)) return nullptr;
|
|
||||||
UInt64* pdpt_virt = sVMGetVirtualTable(PTE_GET_ADDR(pml4_virt[pml4_idx]));
|
|
||||||
|
|
||||||
if (!(pdpt_virt[pdpt_idx] & PTE_PRESENT)) return nullptr;
|
|
||||||
UInt64* pd_virt = sVMGetVirtualTable(PTE_GET_ADDR(pdpt_virt[pdpt_idx]));
|
|
||||||
|
|
||||||
if (!(pd_virt[pd_idx] & PTE_PRESENT)) return nullptr;
|
|
||||||
UInt64* pt_virt = sVMGetVirtualTable(PTE_GET_ADDR(pd_virt[pd_idx]));
|
|
||||||
|
|
||||||
if (!(pt_virt[pt_idx] & PTE_PRESENT)) return nullptr;
|
|
||||||
return (void*)PHYS_TO_HHDM(PTE_GET_ADDR(pt_virt[pt_idx]));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sVMVirtualMemoryUnmapPageInternal(UInt64* pml4, UInt64 virt) {
|
static void sVMVirtualMemoryUnmapPageInternal(UInt64* pml4, UInt64 virt) {
|
||||||
UInt64 pt_idx = VMM_PT_INDEX(virt);
|
UInt64 pt_idx = VMM_PT_INDEX(virt);
|
||||||
UInt64 pd_idx = VMM_PD_INDEX(virt);
|
UInt64 pd_idx = VMM_PD_INDEX(virt);
|
||||||
@@ -150,35 +128,6 @@ UInt64* VMVirtualMemoryMapPage(UInt64* pml4, UInt64 phys, UInt64 virt, UInt64 fl
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* VMVirtualMemoryGetOrAllocatePage(UInt64* pml4, UInt64 virt, UInt64 flags) {
|
|
||||||
OSSpinlockState state;
|
|
||||||
OSSpinlockLockIRQ(&sVMVMMlock, &state);
|
|
||||||
|
|
||||||
void* mappedPage = sVMVirtualMemoryGetMappedPageInternal(pml4, virt);
|
|
||||||
if (mappedPage) {
|
|
||||||
OSSpinlockUnlockIRQ(&sVMVMMlock, &state);
|
|
||||||
return mappedPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* physicalPage = VMPhysicalMemoryAllocatePage();
|
|
||||||
if (!physicalPage) {
|
|
||||||
OSSpinlockUnlockIRQ(&sVMVMMlock, &state);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt64* result = sVMVirtualMemoryMapPageInternal(pml4, (UInt64)physicalPage, virt, flags);
|
|
||||||
if (!result) {
|
|
||||||
OSSpinlockUnlockIRQ(&sVMVMMlock, &state);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* kernelVirtualAddress = (void*)PHYS_TO_HHDM((UInt64)physicalPage);
|
|
||||||
MemorySet(kernelVirtualAddress, 0, kVMPageSize);
|
|
||||||
|
|
||||||
OSSpinlockUnlockIRQ(&sVMVMMlock, &state);
|
|
||||||
return kernelVirtualAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VMVirtualMemoryUnmapPage(UInt64* pml4, UInt64 virt) {
|
void VMVirtualMemoryUnmapPage(UInt64* pml4, UInt64 virt) {
|
||||||
OSSpinlockState state;
|
OSSpinlockState state;
|
||||||
OSSpinlockLockIRQ(&sVMVMMlock, &state);
|
OSSpinlockLockIRQ(&sVMVMMlock, &state);
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user