diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..3d68dd1
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+root = true
+
+[*]
+indent_style = tab
+trim_trailing_whitespaces = true
+insert_final_newline = false
+charset = utf-8
+
+[*.nix]
+indent_size = 2
+
+[*.{c,h,ld}]
+indent_size = 4
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
new file mode 100644
index 0000000..f4dd614
--- /dev/null
+++ b/.github/workflows/deploy.yml
@@ -0,0 +1,54 @@
+name: Deploy website
+
+# Set permissions of the `GITHUB_TOKEN` to allow deployment to Github Pages
+permissions:
+ contents: read
+ pages: write
+ id-token: write
+
+# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued
+# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete
+concurrency:
+ group: "pages"
+ cancel-in-progress: false
+
+# Workflow triggers
+on:
+ # Whenever any changes are made to `web/` from either a push or merging a pull request
+ push:
+ paths:
+ - "web/**"
+ pull_request:
+ paths:
+ - "web/**"
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+# Workflow actions
+jobs:
+ deploy:
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ runs-on: ubuntu-latest
+ steps:
+ # Clone repository
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ # Configure Github Pages
+ - name: Setup Pages
+ uses: actions/configure-pages@v5
+
+ # Upload build - In this case it's just static files e.g. HTML and CSS
+ - name: Upload artifact
+ uses: actions/upload-pages-artifact@v3
+ with:
+ # Upload specific directory
+ path: './web'
+
+ # Deploy to Github Pages
+ - name: Deploy to GitHub Pages
+ id: deployment
+ uses: actions/deploy-pages@v4
diff --git a/.gitignore b/.gitignore
index 08f6d07..570a96f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,7 +6,7 @@ build/
!build/src/kernel/console/functions/edit.c.o
# Libraries/Dependencies
-include/limine
+include/limine/*
#!include/limine/limine.h
.DS_Store
@@ -17,8 +17,9 @@ tools/png
tools/bmp
tools/lg.py
-dsk/hdd0
-dsk/disk.img
+.github/*
+
+logo.txt
src/kernel/console/functions/edit.c
diff --git a/.zed/settings.json b/.zed/settings.json
new file mode 100644
index 0000000..1d0ac21
--- /dev/null
+++ b/.zed/settings.json
@@ -0,0 +1,3 @@
+{
+ "project_name": "emexOS",
+}
diff --git a/Makefile b/Makefile
index 388a8c9..ecaaf12 100644
--- a/Makefile
+++ b/Makefile
@@ -15,12 +15,13 @@ all: $(ISO)
fetchDeps:
@echo "[DEPS] Fetching dependencies/libraries"
@mkdir -p $(INCLUDE_DIR)
- #@mkdir -p $(BUILD_DIR)/src/kernel/console/functions
+
@echo "[DEPS] Fetching Limine"
- @rm -rf $(INCLUDE_DIR)/limine
- @git clone https://codeberg.org/Limine/Limine.git --branch=v10.3.0-binary --depth=1 $(INCLUDE_DIR)/limine
- @echo "[DEPS] Building limine binary"
- @$(MAKE) -C $(INCLUDE_DIR)/limine
+ @rm -rf $(LIMINE_DIR)
+ @git clone https://codeberg.org/Limine/Limine.git --branch=v10.x-binary --depth=1 $(LIMINE_DIR)
+ @rm -rf $(LIMINE_DIR)/.git
+ @echo "[DEPS] Fetching Limine protocol header file"
+ @wget https://codeberg.org/Limine/limine-protocol/raw/branch/trunk/include/limine.h -O $(LIMINE_DIR)/limine.h
disk:
@mkdir -p $(DISK_DIR)
@@ -34,24 +35,16 @@ $(BUILD_DIR)/kernel.elf: src/kernel/linker.ld $(OBJS)
userspace:
@$(MAKE) -C src/userspace
-# Ensure host limine tool exists (Linux/macOS binary).
+# Compile Limine
$(LIMINE_TOOL):
@$(MAKE) -C $(LIMINE_DIR)
# Create bootable ISO
-$(ISO): limine.conf $(BUILD_DIR)/kernel.elf disk userspace $(LIMINE_TOOL)
+$(ISO): limine.conf $(LIMINE_TOOL) $(BUILD_DIR)/kernel.elf disk userspace
@echo "[ISO] Creating bootable image..."
@rm -rf $(ISODIR)
+ @rm -f $(DISK_DIR)/initrd.cpio
@mkdir -p $(ISODIR)/boot/limine $(ISODIR)/EFI/BOOT
-#@cp $(BUILD_DIR)/kernel.elf $(ISODIR)/boot/
- @cp $(BUILD_DIR)/kernel.elf $(ISODIR)/boot/kernel_a.elf
- @cp $(BUILD_DIR)/kernel.elf $(ISODIR)/boot/kernel_b.elf
-#@cp activeslot.txt $(ISODIR)/boot/activeslot.cfg # slot system
-
- @cp $< $(ISODIR)/boot/limine/
- @cp $(addprefix $(INCLUDE_DIR)/limine/limine-, bios.sys bios-cd.bin uefi-cd.bin) $(ISODIR)/boot/limine/
- @cp $(addprefix $(INCLUDE_DIR)/limine/BOOT, IA32.EFI X64.EFI) $(ISODIR)/EFI/BOOT/
-
@mkdir -p $(ISODIR)/boot
@mkdir -p $(ISODIR)/boot/ui
@mkdir -p $(ISODIR)/boot/ui/fonts
@@ -60,26 +53,38 @@ $(ISO): limine.conf $(BUILD_DIR)/kernel.elf disk userspace $(LIMINE_TOOL)
@mkdir -p $(ISODIR)/boot/keymaps
@mkdir -p $(ISODIR)/boot/images
@mkdir -p $(ISODIR)/boot/programs
+ @cp $(BUILD_DIR)/kernel.elf $(ISODIR)/boot/kernel_a.elf
+ @cp $(BUILD_DIR)/kernel.elf $(ISODIR)/boot/kernel_b.elf
+ @cp $< $(ISODIR)/boot/limine/
+ @cp $(addprefix $(INCLUDE_DIR)/limine/limine-, bios.sys bios-cd.bin uefi-cd.bin) $(ISODIR)/boot/limine/
+ @cp $(addprefix $(INCLUDE_DIR)/limine/BOOT, IA32.EFI X64.EFI) $(ISODIR)/EFI/BOOT/
- @echo "[MOD] creating executables..."
- @cp src/userspace/hello.elf $(ISODIR)/boot/programs/hello.elf
-
-#@echo "[MOD] copying configs..."
-#@cp shared/theme/bootconf.emcg $(ISODIR)/boot/bootconf.emcg
-#@cp shared/theme/font8x15.bin $(ISODIR)/boot/liminefont.f15
-
- @echo "[MOD] copying assets..."
- @cp shared/ui/assets/bootlogo.bin $(ISODIR)/boot/ui/assets/
-#@cp shared/images/logo.bmp $(ISODIR)/boot/images/
-#@cp shared/images/background.bmp $(ISODIR)/boot/images/
- @cp shared/images/frog.bmp $(ISODIR)/boot/images/
-
-#@cp shared/images/bg.jpg $(ISODIR)/boot/
-
- @echo "[MOD] copying keymaps..."
- @cp shared/keymaps/US.map $(ISODIR)/boot/keymaps/
- @cp shared/keymaps/DE.map $(ISODIR)/boot/keymaps/
-#@cp shared/keymaps/PL.map $(ISODIR)/boot/keymaps/
+ @echo "[MK] copying executables..."
+ @mkdir -p $(DISK_DIR)/rd/user/apps
+ @mkdir -p $(DISK_DIR)/rd/user/bin
+ @mkdir -p $(DISK_DIR)/rd/bin
+ @mkdir -p $(DISK_DIR)/rd/emr/system
+ @cp -r src/userspace/apps/shell/shell.emx $(DISK_DIR)/rd/user/apps/
+ @cp -r src/userspace/apps/system/system.emx $(DISK_DIR)/rd/emr/system/
+ @cp -r src/userspace/apps/gui/gui.emx $(DISK_DIR)/rd/user/apps/
+
+ @echo "[MK] copying files..."
+#@cp limine.conf $(DISK_DIR)/rd/boot/
+ @cp src/userspace/apps/login/login.elf $(DISK_DIR)/rd/emr/system
+ @cp src/userspace/bin/echo/echo.elf $(DISK_DIR)/rd/bin/
+ @cp src/userspace/bin/hello/hello.elf $(DISK_DIR)/rd/bin/
+ @cp src/userspace/bin/ls/ls.elf $(DISK_DIR)/rd/bin/
+ @cp src/userspace/bin/tree/tree.elf $(DISK_DIR)/rd/bin/
+ @cp src/userspace/bin/cat/cat.elf $(DISK_DIR)/rd/bin/
+ @cp src/userspace/bin/cd/cd.elf $(DISK_DIR)/rd/bin/
+ @cp src/userspace/bin/lsblk/lsblk.elf $(DISK_DIR)/rd/bin/
+ @cp src/userspace/bin/reboot/reboot.elf $(DISK_DIR)/rd/bin/
+
+
+ @echo "[MK] creating initrd.cpio..."
+ @chmod +x tools/initrd.sh
+ ./tools/initrd.sh
+ @cp $(DISK_DIR)/initrd.cpio $(ISODIR)/boot/
@xorriso -as mkisofs -b boot/limine/limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
@@ -123,4 +128,4 @@ $(BUILD_DIR)/%.asm.o: %.asm
clean:
@echo "[CLR] Cleaning..."
@rm -rf $(BUILD_DIR)
- @echo "[OK]"
+ @echo "[OK]"
\ No newline at end of file
diff --git a/README.md b/README.md
index b73d268..143622c 100644
--- a/README.md
+++ b/README.md
@@ -1,77 +1,160 @@
-# emexOS - a simple 64 Bit OS written in C
-
-

-

+
$${\Huge \color{white} \tilde{}~emexOS~\tilde{}}$$
+
+ $${\LARGE \color{red}A \space Simple,\space Modern \space x86\textunderscore 64 \space Operating \space System \space in \space C}$$
+
+
+
+
+
+
+
+
+
+
+
+
+
-## Build Dependencies
-For building and compiling emexOS, ensure you have the following installed,
-- x86_64 GCC cross-compiler - This is our preferred compiler for the source code. Currently, emexOS only supports 64-bit x86 machines, but we plan to support more architectures in the future.
-- [NASM](https://www.nasm.us/) - Assembler.
-- [QEMU](https://www.qemu.org/) - Our preferred emulator.
-- [Xorriso](https://www.gnu.org/software/xorriso/) - ISO creation.
-- [Git](https://git-scm.com/) - To fetch dependencies.
-
-You can use Zig instead of x86_64-gcc if you prefer to,
-- [Zig](https://ziglang.org/) - Zig lets you build the whole OS using just one command.
-
-## For Nix Users
-If you’re using [Nix](https://nixos.org/), you can run the provided flake that installs all the build dependencies. That way, you can set up a complete emexOS development environment with a single, simple command.
-
-## Building and Compiling
-Now that you have all the required build dependencies installed, you can finally build and run emexOS.
-
-**Using gnu-make**
-- `make fetchDeps` - Fetches all libraries and such that emexOS depends on. Obviously `git` is used for this operation.
-- `make` - Builds emexOS.
-- `make run` - Emulates emexOS using QEMU.
-- `make clean` - Cleans up all build outputs.
-
-**Using Zig**
-- `zig build` - Fetch, build and run.
-- `zig build -Dnofetch` - Build and run.
-- `zig build -Dclean` - Remove (cache, output), fetch, build and run.
-- `zig build -Dnofetch -Dclean` - Remove (cache, output), build and run.
-
-## Running
-to run emexOS on QEMU use `make run`
-on real hardware make sure your device does not have any existing data on the disk, emexOS will delete it without asking! (soon there will be a menu which asks you)
-
-## Console
-After the bootup emexOS will ask you about a password to login. the password is "emex", but you can change that in shared/config/user.h
-
-## Commands
-
-### Common
-
-| command | example | output |
-|-----------------|-----------------|------------------------------|
-| echo | echo text | text |
-| clear | clear | [clears screen] |
-| help | help echo | [help menu/specific command] |
-| scale | scale 3 | [font size from 1 to 4] |
-| date | date | [shows current date] |
-| calendar | calendar | [shows current date & time] |
-| time | time | [shows current time] |
-| uptime | uptime | [shows current uptime] |
-
-### System
-
-| command | example | output |
-|-----------------|-----------------|------------------------------|
-| meminfo | meminfo | free memory: ... |
-| dofetch | dofetch | [emexOS logo, user, ...] |
-| date | date | [shows current date] |
+---
+
+## $${\Large About\space emexOS}$$
+
+**emexOS** is a hobbyist, monolithic x86\_64 operating system project with a focus on simplicity, modularity, and modern OS development practices. It is built mostly in C with a touch of assembly, learning towards clarity and educational value. Core goals include:
+
+- Developing a functioning 64-bit modern kernel from scratch
+- Clear modular design and codebase, suitable for learning OS concepts
+- Clean, approachable interfaces for drivers, FS, graphics, and more
+- Easy contribution and extensibility
+- Real hardware support (where possible) and robust QEMU emulation
+
+**emexOS** is open for contributors and experimenters — your feedback is always welcome!
---
-## License:
-- GNU GPLv3
-- Attribution required (see ATTRIBUTION.md)
+## $${\Large Key\space Features}$$
+- 64-bit x86_64 support
+- Modern C codebase (with some assembly for low-level interaction)
+- Limine bootloader compatibility
+- Modular kernel designed for extensibility
+- Early filesystem and ATA disk support (see caution below)
+- Text console with password protection and user configuration
+- Cross-platform compilation (Linux, Nix, etc.)
+- Easy-to-use Makefile and Zig build systems
+- Growing documentation and contributor guides
-## Writer
- - README.md by Voxi0 & emexSW & Bi Moz
- - emexOS project started by emexSW
-##
+---
+
+## $${\large Build\space Dependencies}$$
+
+To build and run emexOS, you’ll need the following minimal toolchain:
+- **x86_64 GCC cross-compiler**
+ (Primary recommended: emexOS currently only supports 64-bit x86 platforms. Support for new architectures is planned)
+- **[NASM](https://www.nasm.us/)** -- Netwide Assembler, for boot and low-level routines.
+- **[QEMU](https://www.qemu.org/)** -- Emulator to test-run OS builds on any machine.
+- **[Xorriso](https://www.gnu.org/software/xorriso/)** -- For ISO creation.
+- **[Git](https://git-scm.com/)** and **[wget](https://www.gnu.org/software/wget/)** -- To fetch dependencies.
+
+You can also use [Zig](https://ziglang.org/) as an alternative to GCC.
+
+*Optional nice-to-haves:*
+- [GDB](https://www.gnu.org/software/gdb/) for kernel debugging
+- [Bochs](https://bochs.sourceforge.io/) for additional x86 virtualization
+
+---
+
+## $${\large For\space Nix\space Users}$$
+
+If you're on [NixOS](https://nixos.org/) or using Nix package manager:
+
+1. Ensure Nix flakes are enabled (see [nix flakes guide](https://nixos.wiki/wiki/Flakes))
+2. Run `nix develop` to enter a shell with all build tools already present (no manual installation needed)
+3. For freshest dependencies, update the flake:
+ ```shell
+ nix flake update
+ ```
+4. The devShell includes all required compilers, emulator, linker, assembler and tools.
+
+---
+
+## $${\large Building\space and\space Running}$$
+
+With the dependencies in place, you can compile and test-drive emexOS.
+
+> **:warning: WARNING:**
+> emexOS currently only supports ATA disks.
+> If an ATA disk is detected, emexOS **CAN/WILL DELETE IT WITHOUT ASKING** if `OVERWRITEALL` is set to 1 in the configs (default is 0).
+> Do **NOT** run on bare metal or on drives with important data unless you understand the risks!
+> Use QEMU/virtual machines for experimentation.
+
+### **GNU Make Workflow**
+- `make fetchDeps` : Pull in third-party libraries and bootloader packages (uses git/wget)
+- `make` : Complete build of emexOS (kernel, ISO, etc.)
+- `make run` : Launches emulated OS in QEMU for testing
+- `make clean` : Cleans out build artifacts
+
+### **Zig Build Workflow**
+- `zig build` : Fetch dependencies, build, run in one command
+- `zig build -Dnofetch` : Skip dependency fetch, just build & run
+- `zig build -Dclean` : Clean output/cache and then build afresh
+- `zig build -Dnofetch -Dclean` : Thorough clean & build, skips fetching
+
+---
+
+## $${\large Project\space Structure}$$
+
+- `kernel/` : The OS kernel (C)
+- `boot/` : Bootloader integration and multiboot setup
+- `shared/` : Shared configuration, user/password management, and common headers
+- `docs/` : Documentation, guides, design docs, specs
+- `Makefile`, `build.zig` : Build scripts for GNU make and Zig
+- Other directories: Drivers, FS, graphics (in-progress), libraries
+
+---
+
+## $${Console}$$
+
+Once emexOS boots in your emulator (or real hardware):
+- **Login**: You'll be prompted for a password. Default is `"emex"` (located/configurable in `shared/config/user.h`)
+- **User Management**: Change the password by editing the config file and rebuilding.
+- **Limitations**: No SMP (multi-core) support yet; emexOS kernel runs on a single CPU only.
+ Graphics, networking, and other advanced features are in progress.
+
+---
+
+## $${\large Contributing}$$
+
+We encourage all contributions!
+If you'd like to add a driver, fix a bug, improve code or docs, please open an [issue](https://github.com/emexos/emexOS1/issues) or [pull request](https://github.com/emexos/emexOS1/pulls).
+
+### Ways to help:
+- Report bugs and missing features
+- Submit code PRs and documentation improvements
+- Discuss features and design in [Discord](https://discord.gg/JFGK4yqSyA)
+- Package, test, and extend emexOS
+
+See `CONTRIBUTING.md` for more info (coming soon!)
+
+---
+
+## $${\large Attribution}$$
+
+This OS is a fork-friendly, FOSS project licensed under **GNU GPLv3**.
+**If you fork or modify emexOS, please read [ATTRIBUTION.md](./ATTRIBUTION.md) and retain clear references to "emexOS"** as required.
+
+---
+
+
+
$${Contributors}$$
+
+
+
+
+
+
+
+
+
$\color{gray}{README \space by\space emexSW,\space Voxi0,\space and\space Bi\ Moz}$
+
diff --git a/common.mk b/common.mk
index 0b41dc3..8fb6688 100644
--- a/common.mk
+++ b/common.mk
@@ -15,8 +15,8 @@ VLD = @echo "[LD] $@" && $(LD)
# Compiler Flags
COMMON_FLAGS += -I $(INCLUDE_DIR) -I $(SRC_DIR) -I shared/ -ffreestanding -fno-stack-protector -fno-lto \
-fno-PIE -fno-pic -m64 -march=x86-64 -mno-80387 -mno-mmx \
- -mno-sse -mno-sse2 -mno-red-zone -mcmodel=kernel -Wall -Wextra
-CFLAGS ?= $(COMMON_FLAGS) -std=gnu11
+ -mno-sse -mno-sse2 -mno-red-zone -mcmodel=kernel -Wall -Wextra -Wpedantic
+CFLAGS ?= $(COMMON_FLAGS) -std=c23
CXXFLAGS ?= $(COMMON_FLAGS) -std=c++17 -fno-exceptions -fno-rtti
LDFLAGS ?= -nostdlib -static -no-pie -z text -z max-page-size=0x1000
ASFLAGS ?= -f elf64
@@ -28,8 +28,8 @@ SRC_DIR := src
USERSPACE_DIR = src/userspace
USERSPACE_BUILD = build/userspace
BUILD_DIR := build
-DISK_DIR := $(BUILD_DIR)/dsk
+DISK_DIR := dsk
DISK_IMG := $(DISK_DIR)/disk.img
INCLUDE_DIR := include
ISODIR := $(BUILD_DIR)/isodir
-ISO := $(BUILD_DIR)/$(OS_NAME).iso
+ISO := $(BUILD_DIR)/$(OS_NAME).iso
\ No newline at end of file
diff --git a/docs/Building emexOS from source b/docs/Building emexOS from source
deleted file mode 100644
index 8b13789..0000000
--- a/docs/Building emexOS from source
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/docs/Emulating_emexOS_binary_using_QEMU.md b/docs/Emulating_emexOS_binary_using_QEMU.md
index 1b51f17..d266bf7 100644
--- a/docs/Emulating_emexOS_binary_using_QEMU.md
+++ b/docs/Emulating_emexOS_binary_using_QEMU.md
@@ -11,4 +11,4 @@ The easiest way to run emexOS is to run it in QEMU.
- Choose either to enable storage or not to.
- Keep the default options and select "finish".
-Learn how to install QEMU in [Arch](https://github.com/BloopBiMoz/emexOS1/blob/main/docs/QEMU_Arch.md) and [Debian](https://github.com/BloopBiMoz/emexOS1/blob/main/docs/QEMU_Debian.md) based distributions.
+Learn how to install QEMU in [Arch](./QEMU_Arch.md) and [Debian](./QEMU_Debian.md) based distributions.
\ No newline at end of file
diff --git a/dsk/disk.img b/dsk/disk.img
new file mode 100644
index 0000000..dbfe748
Binary files /dev/null and b/dsk/disk.img differ
diff --git a/dsk/initrd.cpio b/dsk/initrd.cpio
new file mode 100644
index 0000000..becb5e9
Binary files /dev/null and b/dsk/initrd.cpio differ
diff --git a/dsk/rd/bin/cat.elf b/dsk/rd/bin/cat.elf
new file mode 100755
index 0000000..4ff1ee4
Binary files /dev/null and b/dsk/rd/bin/cat.elf differ
diff --git a/dsk/rd/bin/cd.elf b/dsk/rd/bin/cd.elf
new file mode 100755
index 0000000..d88d1a9
Binary files /dev/null and b/dsk/rd/bin/cd.elf differ
diff --git a/dsk/rd/bin/echo.elf b/dsk/rd/bin/echo.elf
new file mode 100755
index 0000000..8bee398
Binary files /dev/null and b/dsk/rd/bin/echo.elf differ
diff --git a/dsk/rd/bin/hello.elf b/dsk/rd/bin/hello.elf
new file mode 100755
index 0000000..f292287
Binary files /dev/null and b/dsk/rd/bin/hello.elf differ
diff --git a/dsk/rd/bin/ls.elf b/dsk/rd/bin/ls.elf
new file mode 100755
index 0000000..18a517d
Binary files /dev/null and b/dsk/rd/bin/ls.elf differ
diff --git a/dsk/rd/bin/lsblk.elf b/dsk/rd/bin/lsblk.elf
new file mode 100755
index 0000000..42f0314
Binary files /dev/null and b/dsk/rd/bin/lsblk.elf differ
diff --git a/dsk/rd/bin/reboot.elf b/dsk/rd/bin/reboot.elf
new file mode 100755
index 0000000..5374ad1
Binary files /dev/null and b/dsk/rd/bin/reboot.elf differ
diff --git a/dsk/rd/bin/rm.elf b/dsk/rd/bin/rm.elf
new file mode 100755
index 0000000..254cf23
Binary files /dev/null and b/dsk/rd/bin/rm.elf differ
diff --git a/dsk/rd/bin/tree.elf b/dsk/rd/bin/tree.elf
new file mode 100755
index 0000000..2a4a630
Binary files /dev/null and b/dsk/rd/bin/tree.elf differ
diff --git a/dsk/rd/boot/activeslot.txt b/dsk/rd/boot/activeslot.txt
new file mode 100644
index 0000000..f70f10e
--- /dev/null
+++ b/dsk/rd/boot/activeslot.txt
@@ -0,0 +1 @@
+A
diff --git a/dsk/rd/boot/limine.conf b/dsk/rd/boot/limine.conf
new file mode 100644
index 0000000..c9e16a1
--- /dev/null
+++ b/dsk/rd/boot/limine.conf
@@ -0,0 +1,40 @@
+timeout: 1 # better for trying on real hardware
+
+kaslr: yes
+verbose: yes
+
+#wallpaper: boot():/boot/bg.jpg
+default_entry: 0
+
+#term_font: boot():/boot/liminefont.f15
+#term_font_size: 8x15
+#term_font_spacing: 0
+
+# ----
+# Dualslot kernel system
+# ----
+
+# default/ active
+/emexOS A
+ protocol: limine
+ kernel_path: boot():/boot/kernel_a.elf
+ #module_path: boot():/boot/activeslot.txt # Slot A
+
+ module_path: boot():/boot/initrd.cpio
+
+# slot 2 for update
+/emexOS B
+ protocol: limine
+ kernel_path: boot():/boot/kernel_b.elf
+ #module_path: boot():/boot/activeslot.txt # slot B
+
+ module_path: boot():/boot/initrd.cpio
+
+
+# ----
+# resolutions
+# ----
+
+# resolution: 1920x1080x32
+# resolution: 2560x1440x32
+# resolution: 3840x2160x32
diff --git a/shared/ui/assets/bootlogo.bin b/dsk/rd/boot/ui/assets/bootlogo.bin
similarity index 100%
rename from shared/ui/assets/bootlogo.bin
rename to dsk/rd/boot/ui/assets/bootlogo.bin
diff --git a/shared/theme/font8x15.bin b/dsk/rd/boot/ui/fonts/font8x15.bin
similarity index 100%
rename from shared/theme/font8x15.bin
rename to dsk/rd/boot/ui/fonts/font8x15.bin
diff --git a/dsk/rd/boot/ui/fonts/unifont.sfn b/dsk/rd/boot/ui/fonts/unifont.sfn
new file mode 100644
index 0000000..4a5addd
Binary files /dev/null and b/dsk/rd/boot/ui/fonts/unifont.sfn differ
diff --git a/dsk/rd/emr/.emxrc b/dsk/rd/emr/.emxrc
new file mode 100644
index 0000000..9acf122
--- /dev/null
+++ b/dsk/rd/emr/.emxrc
@@ -0,0 +1,11 @@
+var login_path = ("/emr/system/login.elf")
+var shell_path = (ep: "/user/apps/shell.emx")
+var gui_path = (ep: "/user/apps/gui.emx")
+
+// ep == emex package
+
+//exec -f"ep" gui_path
+
+// last things which should happen
+exec login_path
+exec -f"ep" shell_path
diff --git a/dsk/rd/emr/assets/copy_folders.bmp b/dsk/rd/emr/assets/copy_folders.bmp
new file mode 100644
index 0000000..d360fe7
Binary files /dev/null and b/dsk/rd/emr/assets/copy_folders.bmp differ
diff --git a/dsk/rd/emr/assets/file.bmp b/dsk/rd/emr/assets/file.bmp
new file mode 100644
index 0000000..171ed6c
Binary files /dev/null and b/dsk/rd/emr/assets/file.bmp differ
diff --git a/dsk/rd/emr/assets/folder.bmp b/dsk/rd/emr/assets/folder.bmp
new file mode 100644
index 0000000..b83966d
Binary files /dev/null and b/dsk/rd/emr/assets/folder.bmp differ
diff --git a/dsk/rd/emr/assets/locked_folder.bmp b/dsk/rd/emr/assets/locked_folder.bmp
new file mode 100644
index 0000000..cf40e8b
Binary files /dev/null and b/dsk/rd/emr/assets/locked_folder.bmp differ
diff --git a/dsk/rd/emr/assets/system_file.bmp b/dsk/rd/emr/assets/system_file.bmp
new file mode 100644
index 0000000..5553d3e
Binary files /dev/null and b/dsk/rd/emr/assets/system_file.bmp differ
diff --git a/dsk/rd/emr/assets/this_disk.bmp b/dsk/rd/emr/assets/this_disk.bmp
new file mode 100644
index 0000000..8f6b976
Binary files /dev/null and b/dsk/rd/emr/assets/this_disk.bmp differ
diff --git a/shared/keymaps/DE.map b/dsk/rd/emr/config/keymaps/DE.map
similarity index 100%
rename from shared/keymaps/DE.map
rename to dsk/rd/emr/config/keymaps/DE.map
diff --git a/shared/keymaps/PL.map b/dsk/rd/emr/config/keymaps/PL.map
similarity index 100%
rename from shared/keymaps/PL.map
rename to dsk/rd/emr/config/keymaps/PL.map
diff --git a/dsk/rd/emr/config/keymaps/RU.map b/dsk/rd/emr/config/keymaps/RU.map
new file mode 100644
index 0000000..96e99c0
--- /dev/null
+++ b/dsk/rd/emr/config/keymaps/RU.map
@@ -0,0 +1,62 @@
+# Russian JCUKEN keyboard layout (CP1251 encoding)
+
+# row 1 - numbers
+0x02 = '1' '!'
+0x03 = '2' '@'
+0x04 = '3' '#'
+0x05 = '4' '$'
+0x06 = '5' '%'
+0x07 = '6' '^'
+0x08 = '7' '&'
+0x09 = '8' '*'
+0x0A = '9' '('
+0x0B = '0' ')'
+0x0C = '-' '_'
+0x0D = '=' '+'
+
+# row 2 - JCUKEN
+0x10 = '\xE9' '\xC9'
+0x11 = '\xF6' '\xD6'
+0x12 = '\xF3' '\xD3'
+0x13 = '\xEA' '\xCA'
+0x14 = '\xE5' '\xC5'
+0x15 = '\xED' '\xCD'
+0x16 = '\xE3' '\xC3'
+0x17 = '\xF8' '\xD8'
+0x18 = '\xF9' '\xD9'
+0x19 = '\xE7' '\xC7'
+0x1A = '\xF5' '\xD5'
+0x1B = '\xFA' '\xDA'
+
+# row 3
+0x1E = '\xF4' '\xD4'
+0x1F = '\xFB' '\xDB'
+0x20 = '\xE2' '\xC2'
+0x21 = '\xE0' '\xC0'
+0x22 = '\xEF' '\xCF'
+0x23 = '\xF0' '\xD0'
+0x24 = '\xEE' '\xCE'
+0x25 = '\xEB' '\xCB'
+0x26 = '\xE4' '\xC4'
+0x27 = '\xE6' '\xC6'
+0x28 = '\xFD' '\xDD'
+
+# row 4
+0x2C = '\xFF' '\xDF'
+0x2D = '\xF7' '\xD7'
+0x2E = '\xF1' '\xD1'
+0x2F = '\xEC' '\xCC'
+0x30 = '\xE8' '\xC8'
+0x31 = '\xF2' '\xD2'
+0x32 = '\xFC' '\xDC'
+0x33 = '\xE1' '\xC1'
+0x34 = '\xFE' '\xDE'
+
+# backtick = ё/Ё
+0x29 = '\xB8' '\xA8'
+
+# special keys
+0x0E = '\b' '\b'
+0x0F = '\t' '\t'
+0x1C = '\n' '\n'
+0x39 = ' ' ' '
diff --git a/shared/keymaps/US.map b/dsk/rd/emr/config/keymaps/US.map
similarity index 100%
rename from shared/keymaps/US.map
rename to dsk/rd/emr/config/keymaps/US.map
diff --git a/dsk/rd/emr/config/keymaps/keymap.cfg b/dsk/rd/emr/config/keymaps/keymap.cfg
new file mode 100644
index 0000000..dc62f5d
--- /dev/null
+++ b/dsk/rd/emr/config/keymaps/keymap.cfg
@@ -0,0 +1,6 @@
+KEYMAP: US
+
+#DE: path("/emr/config/keymaps/DE.map");
+#PL: path("/emr/config/keymaps/PL.map");
+#US: path("/emr/config/keymaps/US.map");
+#RU: path("/emr/config/keymaps/RU.map");
diff --git a/dsk/rd/emr/config/system.ecfg b/dsk/rd/emr/config/system.ecfg
new file mode 100644
index 0000000..add10e2
--- /dev/null
+++ b/dsk/rd/emr/config/system.ecfg
@@ -0,0 +1,7 @@
+#
+# System config
+# system.emcg (emex config)
+#
+
+OS_DEFNAME: "emexOS [x86_64] ";
+OS_DEFRELEASE: "v0.5";
diff --git a/dsk/rd/emr/config/user.ecfg b/dsk/rd/emr/config/user.ecfg
new file mode 100644
index 0000000..b3b9df5
--- /dev/null
+++ b/dsk/rd/emr/config/user.ecfg
@@ -0,0 +1,9 @@
+#
+# User config
+# user.emcg (emex config)
+#
+
+PC_NAME: "pc"
+USER_NAME: "emex"
+PASSWORD: "emex"
+DEFAULT_KM: US
diff --git a/src/drivers/drivers.cfg b/dsk/rd/emr/drivers/drivers.cfg
similarity index 100%
rename from src/drivers/drivers.cfg
rename to dsk/rd/emr/drivers/drivers.cfg
diff --git a/dsk/rd/emr/system.ini b/dsk/rd/emr/system.ini
new file mode 100644
index 0000000..232d78d
--- /dev/null
+++ b/dsk/rd/emr/system.ini
@@ -0,0 +1,3 @@
+[GENERAL]
+default_shell="/user/bin/shell.elf"
+root_user=admin # from users.ini
diff --git a/dsk/rd/emr/system/login.elf b/dsk/rd/emr/system/login.elf
new file mode 100755
index 0000000..4162f16
Binary files /dev/null and b/dsk/rd/emr/system/login.elf differ
diff --git a/dsk/rd/emr/system/srv.emx/app.elf b/dsk/rd/emr/system/srv.emx/app.elf
new file mode 100755
index 0000000..e22e426
Binary files /dev/null and b/dsk/rd/emr/system/srv.emx/app.elf differ
diff --git a/dsk/rd/emr/system/srv.emx/package.info b/dsk/rd/emr/system/srv.emx/package.info
new file mode 100644
index 0000000..9350078
--- /dev/null
+++ b/dsk/rd/emr/system/srv.emx/package.info
@@ -0,0 +1,2 @@
+x1srv
+emex
\ No newline at end of file
diff --git a/dsk/rd/emr/system/system.emx/app.elf b/dsk/rd/emr/system/system.emx/app.elf
new file mode 100755
index 0000000..195d898
Binary files /dev/null and b/dsk/rd/emr/system/system.emx/app.elf differ
diff --git a/dsk/rd/emr/system/system.emx/package.info b/dsk/rd/emr/system/system.emx/package.info
new file mode 100644
index 0000000..e7767fe
--- /dev/null
+++ b/dsk/rd/emr/system/system.emx/package.info
@@ -0,0 +1,10 @@
+
+
+ emr_system
+
+
+ emex
+ []
+ []
+
+
diff --git a/dsk/rd/emr/system/ter-powerline-v16n.psf b/dsk/rd/emr/system/ter-powerline-v16n.psf
new file mode 100644
index 0000000..13a4489
Binary files /dev/null and b/dsk/rd/emr/system/ter-powerline-v16n.psf differ
diff --git a/dsk/rd/emr/users.ini b/dsk/rd/emr/users.ini
new file mode 100644
index 0000000..a78d33f
--- /dev/null
+++ b/dsk/rd/emr/users.ini
@@ -0,0 +1,7 @@
+[USERS]
+users=admin,user
+
+[admin]
+permissions=administrator
+[user]
+permissions=user
diff --git a/dsk/rd/user/apps/gui.emx/app.elf b/dsk/rd/user/apps/gui.emx/app.elf
new file mode 100755
index 0000000..a751917
Binary files /dev/null and b/dsk/rd/user/apps/gui.emx/app.elf differ
diff --git a/dsk/rd/user/apps/gui.emx/package.info b/dsk/rd/user/apps/gui.emx/package.info
new file mode 100644
index 0000000..bb06ff6
--- /dev/null
+++ b/dsk/rd/user/apps/gui.emx/package.info
@@ -0,0 +1,4 @@
+gui
+emexOS
+0.1
+starts the mouse cursor daemon
\ No newline at end of file
diff --git a/src/userspace/hello.elf b/dsk/rd/user/apps/hello.elf
similarity index 100%
rename from src/userspace/hello.elf
rename to dsk/rd/user/apps/hello.elf
diff --git a/dsk/rd/user/apps/hello.emx/app.elf b/dsk/rd/user/apps/hello.emx/app.elf
new file mode 100755
index 0000000..3e654b5
Binary files /dev/null and b/dsk/rd/user/apps/hello.emx/app.elf differ
diff --git a/dsk/rd/user/apps/hello.emx/app_icon.bmp b/dsk/rd/user/apps/hello.emx/app_icon.bmp
new file mode 100644
index 0000000..e69de29
diff --git a/dsk/rd/user/apps/hello.emx/package.info b/dsk/rd/user/apps/hello.emx/package.info
new file mode 100644
index 0000000..eae9087
--- /dev/null
+++ b/dsk/rd/user/apps/hello.emx/package.info
@@ -0,0 +1,10 @@
+
+
+ hello.elf
+
+
+ ein_franzose
+ 3001.0
+ does cool stuff
+
+
diff --git a/dsk/rd/user/apps/shell.emx/app.elf b/dsk/rd/user/apps/shell.emx/app.elf
new file mode 100755
index 0000000..cba027a
Binary files /dev/null and b/dsk/rd/user/apps/shell.emx/app.elf differ
diff --git a/dsk/rd/user/apps/shell.emx/package.info b/dsk/rd/user/apps/shell.emx/package.info
new file mode 100644
index 0000000..055ff67
--- /dev/null
+++ b/dsk/rd/user/apps/shell.emx/package.info
@@ -0,0 +1,10 @@
+
+
+ shell
+
+
+ emex
+ v0.0.1a
+ emx userspace shell
+
+
diff --git a/dsk/rd/user/apps/test.t b/dsk/rd/user/apps/test.t
new file mode 100644
index 0000000..b14df64
--- /dev/null
+++ b/dsk/rd/user/apps/test.t
@@ -0,0 +1 @@
+Hi
diff --git a/shared/images/frog.bmp b/dsk/rd/user/images/frog.bmp
similarity index 100%
rename from shared/images/frog.bmp
rename to dsk/rd/user/images/frog.bmp
diff --git a/flake.lock b/flake.lock
index 171c4ba..ba65bc9 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,30 +1,12 @@
{
"nodes": {
- "flake-utils": {
- "inputs": {
- "systems": "systems"
- },
- "locked": {
- "lastModified": 1731533236,
- "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
- "owner": "numtide",
- "repo": "flake-utils",
- "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
- "type": "github"
- },
- "original": {
- "owner": "numtide",
- "repo": "flake-utils",
- "type": "github"
- }
- },
"nixpkgs": {
"locked": {
- "lastModified": 1762111121,
- "narHash": "sha256-4vhDuZ7OZaZmKKrnDpxLZZpGIJvAeMtK6FKLJYUtAdw=",
+ "lastModified": 1772198003,
+ "narHash": "sha256-I45esRSssFtJ8p/gLHUZ1OUaaTaVLluNkABkk6arQwE=",
"owner": "nixos",
"repo": "nixpkgs",
- "rev": "b3d51a0365f6695e7dd5cdf3e180604530ed33b4",
+ "rev": "dd9b079222d43e1943b6ebd802f04fd959dc8e61",
"type": "github"
},
"original": {
@@ -36,8 +18,8 @@
},
"root": {
"inputs": {
- "flake-utils": "flake-utils",
- "nixpkgs": "nixpkgs"
+ "nixpkgs": "nixpkgs",
+ "systems": "systems"
}
},
"systems": {
diff --git a/flake.nix b/flake.nix
index eb85cbf..3054dba 100644
--- a/flake.nix
+++ b/flake.nix
@@ -2,18 +2,39 @@
description = "emexos dev flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
- flake-utils.url = "github:numtide/flake-utils";
+ systems.url = "github:nix-systems/default";
};
- outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem(system: let
- pkgs = import inputs.nixpkgs {inherit system;};
+ outputs = inputs: let
+ forEachSystem = inputs.nixpkgs.lib.genAttrs (import inputs.systems);
+ pkgs = forEachSystem (system: import inputs.nixpkgs {inherit system;});
in {
- devShells.default = pkgs.mkShellNoCC {
- nativeBuildInputs = with pkgs; [
- pkgsCross.x86_64-embedded.stdenv.cc
- nasm
- libisoburn
- git
- ];
- };
- });
-}
+ formatter = forEachSystem (system: pkgs.${system}.alejandra);
+ devShells = forEachSystem (system: {
+ default = pkgs.${system}.mkShellNoCC {
+ nativeBuildInputs = with pkgs.${system}; [
+ # Compiler and assembler
+ pkgsCross.x86_64-embedded.stdenv.cc
+ gcc # For building Limine
+ nasm
+
+ # Provides a lot of handy tools for C/C++ dev e.g. formatter (clang-format)
+ clang-tools
+
+ # For generating a `compile_commands.json` which can be used by clangd
+ # That file is used by the clangd lsp to figure out includes and all
+ compiledb
+
+ # Provides `xorriso` for creating the emexOS ISO
+ libisoburn
+
+ # Emulator
+ qemu
+
+ # Git and wget are required to fetch some dependencies
+ git
+ wget
+ ];
+ };
+ });
+ };
+}
\ No newline at end of file
diff --git a/limine b/limine
deleted file mode 160000
index 0aa46ad..0000000
--- a/limine
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 0aa46ad0a034a111df345dd80c3b950629041e2b
diff --git a/limine.conf b/limine.conf
index 3f967fa..c9e16a1 100644
--- a/limine.conf
+++ b/limine.conf
@@ -1,4 +1,4 @@
-timeout: 10 # better for trying on real hardware
+timeout: 1 # better for trying on real hardware
kaslr: yes
verbose: yes
@@ -20,15 +20,7 @@ default_entry: 0
kernel_path: boot():/boot/kernel_a.elf
#module_path: boot():/boot/activeslot.txt # Slot A
- module_path: boot():/boot/ui/assets/bootlogo.bin
- module_path: boot():/boot/keymaps/US.map
- module_path: boot():/boot/keymaps/DE.map
- #module_path: boot():/boot/keymaps/PL.map
- #module_path: boot():/boot/images/logo.bmp
- #module_path: boot():/boot/images/background.bmp
- module_path: boot():/boot/images/frog.bmp
- module_path: boot():/boot/programs/hello.elf
-
+ module_path: boot():/boot/initrd.cpio
# slot 2 for update
/emexOS B
@@ -36,15 +28,7 @@ default_entry: 0
kernel_path: boot():/boot/kernel_b.elf
#module_path: boot():/boot/activeslot.txt # slot B
- module_path: boot():/boot/ui/assets/bootlogo.bin
- module_path: boot():/boot/keymaps/US.map
- module_path: boot():/boot/keymaps/DE.map
- #module_path: boot():/boot/keymaps/PL.map
- #module_path: boot():/boot/images/logo.bmp
- #module_path: boot():/boot/images/background.bmp
- module_path: boot():/boot/images/frog.bmp
- module_path: boot():/boot/programs/hello.elf
-
+ module_path: boot():/boot/initrd.cpio
# ----
diff --git a/logo.txt b/logo.txt
index 27f6699..301ff4c 100644
--- a/logo.txt
+++ b/logo.txt
@@ -1,10 +1,29 @@
- ###########;m; ###########;m;
- # ####### #;m; # ###########;m;
- ##########;m; #; ###; #####;m; ##########;m; ###;m; ###;m; # #;m; # #;m; # #;m;
- # ######## #;m; ## ## #;# ## #;m; # ######## #;m; # #;m; # #;m; # #;m; # #;m; # #;m;
-# #;m; # #;m; # #; # # #; # #;m; # #;m; # #;m; # #;m;# #;m; # #;m; # #;m; # #########;m;
-# ######## #;m; # #; # #; # #;m; # ######## #;m; # ### #;m; # #;m; # #;m; ######### #;m;
-# ##########;m; # #; # #; # #;m; # ##########;m; # ### #;m; # #;m; # #;m; # #;m;
-# #;m; # #; # #; # #;m; # #;m; # #;m;# #;m; # #;m; # #;m; # #;m;
- # ########## #;m; # #; # #; # #;m; # ########## #;m; # #;m; # #;m; # ####### #;m; ########### #;m;
- ###########;m; # #; # #; # #;m; ###########;m; ###;m; ###;m; ###########;m; ##########;m;
+ ###########;m; ###########;m;
+ # ####### #;m; # ###########;m;
+ ##########;m; #; ###; #####;m; ##########;m; ###;m; ###;m; # #;m; # #;m; # #;m;
+ # ######## #;m; ## ## #;# ## #;m; # ######## #;m; # #;m; # #;m; # #;m; # #;m; # #;m;
+ # #;m; # #;m; # #; # # #; # #;m; # #;m; # #;m; # #;m;# #;m; # #;m; # #;m; # #########;m;
+ # ######## #;m; # #; # #; # #;m; # ######## #;m; # ### #;m; # #;m; # #;m; ######### #;m;
+ # ##########;m; # #; # #; # #;m; # ##########;m; # ### #;m; # #;m; # #;m; # #;m;
+ # #;m; # #; # #; # #;m; # #;m; # #;m;# #;m; # #;m; # #;m; # #;m;
+ # ########## #;m; # #; # #; # #;m; # ########## #;m; # #;m; # #;m; # ####### #;m; ########### #;m;
+ ###########;m; # #; # #; # #;m; ###########;m; ###;m; ###;m; ###########;m; ##########;m;
+
+┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬────────────┐
+│ esc │ f1 │ f2 │ f3 │ f4 │ f5 │ f6 │ f7 │ f8 │ f9 │ f10 │ f11 │ f12 │ power │
+├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼────────────┤
+│ ~ │ ! │ @ │ # │ $ │ % │ ^ │ & │ * │ ( │ ) │ _ │ + │ │
+│ ` │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 0 │ — │ = │ delete │
+├─────┴─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┬──────┤
+│ │ │ │ │ │ │ │ │ │ │ │ { │ } │ | │
+│ tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │ [ │ ] │ \ │
+├───────────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┴──────┤
+│ │ │ │ │ │ │ │ │ │ │ : │ “ │ │
+│ caps lock │ A │ S │ D │ F │ G │ H │ J │ K │ L │ ; │ ' │ enter │
+├───────────┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴────────────┤
+│ │ │ │ │ │ │ │ │ < │ > │ ? │ │
+│ shift │ Z │ X │ C │ V │ B │ N │ M │ , │ . │ / │ shift │
+├─────┬──────┬─┴───┬─┴───┬─┴─────┴─────┴─────┴─────┴─────┼─────┼─────┼─────┴┬───────┬──────┤
+│ │ │ │ │ │ │ ├──────┤ ^ ├──────┤
+│ fn │ ctrl │ opt │ cmd │ s p a c e │ cmd │ opt │ < ├───────┤ > │
+└─────┴──────┴─────┴─────┴───────────────────────────────┴─────┴─────┴──────┴───────┴──────┘
diff --git a/shared/config/system.h b/shared/config/system.h
index e861186..e84f8df 100644
--- a/shared/config/system.h
+++ b/shared/config/system.h
@@ -12,6 +12,8 @@
#define KERNELSPACE 0x40000000
#define KERNELPRIORITY 255
+#define JUMPTOUSER 1
+
#define USE_HCF 1
#define BOOTUP_VISUALS 0 // verbose boot == 0, silent boot == 1
@@ -25,23 +27,33 @@
// on some hardware you can use "hardware compatibility off" and it will still run
#define HARDWARE_SC 0
-// 1 == enable automatic formatting
-// 0 == require manual formatting
-// NOTE: this will ERASE *ALL DATA* on your disk if enabled!
-#define OVERWRITEALL 0
-
#if HARDWARE_SC == 1
- #define ENABLE_FAT32 0
- #define ENABLE_ATA 0
- #define ENABLE_ULIME 0
- #define ENABLE_GLIME 0
+# define ENABLE_FAT32 0
+# define ENABLE_ATA 0
+# define ENABLE_ULIME 0
+# define ENABLE_GLIME 0
#else
- #define ENABLE_FAT32 1
- #define ENABLE_ATA 1
- #define ENABLE_ULIME 1
- #define ENABLE_GLIME 1
+# define ENABLE_FAT32 1
+# define ENABLE_ATA 1
+# define ENABLE_ULIME 1
+# define ENABLE_GLIME 1
#endif
#define X64 1
#define RISCV 0
#define ARM64 0
+
+#define EMEX "emex"
+#define EMEX1 "EMEX"
+#define EMEX2 "[emex]"
+#define EMEX3 "[EMEX]"
+#define EMEX4 "emx"
+#define EMX EMEX4
+
+
+// 1 == enable automatic formatting
+// 0 == require manual formatting
+// NOTE: this will ERASE *ALL DATA* on your disk if enabled!
+#define OVERWRITEALL 0
+
+//#define NULL_ 1
\ No newline at end of file
diff --git a/shared/config/tasks.h b/shared/config/tasks.h
new file mode 100644
index 0000000..e83f4aa
--- /dev/null
+++ b/shared/config/tasks.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#define SOCKET1 0
+#define SOCKET2 0
+#define SOCKET3 1
+#define SOCKET4 0
diff --git a/shared/config/user_config.c b/shared/config/user_config.c
index ee668bd..8e8bdf6 100644
--- a/shared/config/user_config.c
+++ b/shared/config/user_config.c
@@ -1,5 +1,6 @@
#include "user_config.h"
#include
+#include
#include
#include
diff --git a/shared/keymaps/dirs.cfg b/shared/keymaps/dirs.cfg
deleted file mode 100644
index 84046ff..0000000
--- a/shared/keymaps/dirs.cfg
+++ /dev/null
@@ -1,3 +0,0 @@
-DE: path("/emr/config/keymaps/DE.map");
-PL: path("/emr/config/keymaps/PL.map");
-US: path("/emr/config/keymaps/US.map");
diff --git a/shared/memory/mem.c b/shared/memory/mem.c
index 3ab74c6..9e5256b 100644
--- a/shared/memory/mem.c
+++ b/shared/memory/mem.c
@@ -7,16 +7,38 @@
void memset(void *ptr, u8 val, size_t n)
{
u8 *p = (u8 *)ptr;
- for (size_t i = 0; i < n; i++)
- p[i] = val;
+
+ while (n && ((size_t)p & 7)) { *p++ = val; n--; }
+
+ // fill 8 bytes at a time
+ u64 fill = (u64)val * 0x0101010101010101ULL;
+ u64 *p64 = (u64 *)p;
+ size_t blocks = n / 8;
+ while (blocks--) *p64++ = fill;
+
+ // remaining bytes
+ p = (u8 *)p64;
+ n &= 7;
+ while (n--) *p++ = val;
}
void memcpy(void *dst, const void *src, size_t n)
{
u8 *d = (u8 *)dst;
+ u64 *d64 = (u64 *)d;
const u8 *s = (const u8 *)src;
- for (size_t i = 0; i < n; i++)
- d[i] = s[i];
+ const u64 *s64 = (const u64 *)s;
+
+ size_t blocks = n / 8; // 8 bytes
+
+ while (n && ((size_t)d & 7)) { *d++ = *s++; n--; }
+ while (blocks--) *d64++ = *s64++;
+
+ // remaining bytes
+ d = (u8 *)d64;
+ s = (const u8 *)s64;
+ n &= 7;
+ while (n--) *d++ = *s++;
}
void memmove(void *dst, const void *src, size_t n)
@@ -24,12 +46,27 @@ void memmove(void *dst, const void *src, size_t n)
u8 *d = (u8 *)dst;
const u8 *s = (const u8 *)src;
+ if (d == s || n == 0) return;
+
if (d < s) {
- for (size_t i = 0; i < n; i++)
- d[i] = s[i];
+ // forward copy: align then 8-byte chunks
+ while (n && ((size_t)d & 7)) { *d++ = *s++; n--; }
+ u64 *d64 = (u64 *)d;
+ const u64 *s64 = (const u64 *)s;
+ size_t blocks = n / 8;
+ while (blocks--) *d64++ = *s64++;
+ d = (u8 *)d64; s = (const u8 *)s64; n &= 7;
+ while (n--) *d++ = *s++;
} else {
- for (size_t i = n; i > 0; i--)
- d[i - 1] = s[i - 1];
+ // backward copy to handle overlap
+ d += n; s += n;
+ while (n && ((size_t)d & 7)) { *--d = *--s; n--; }
+ u64 *d64 = (u64 *)d;
+ const u64 *s64 = (const u64 *)s;
+ size_t blocks = n / 8;
+ while (blocks--) *--d64 = *--s64;
+ d = (u8 *)d64; s = (const u8 *)s64; n &= 7;
+ while (n--) *--d = *--s;
}
}
diff --git a/shared/string/log.c b/shared/string/log.c
deleted file mode 100644
index 316211e..0000000
--- a/shared/string/log.c
+++ /dev/null
@@ -1,144 +0,0 @@
-#include "log.h"
-#include
-#include
-#include
-#include
-#include
-
-static u32 get_log_color(log_level_t level) {
- switch (level) {
- case LSUCCESS:
- return LCOLOR_SCS;
- case LWARNING:
- return LCOLOR_WAR;
- case LERROR:
- return LCOLOR_ERR;
- case LDEF:
- default:
- return LCOLOR_D;
- }
-}
-
-
-
-void log_message(const char *tag, const char *message, log_level_t level) {
- if (!tag || !message) return;
-
- u32 msg_color = get_log_color(level);
-
- // gray
- //print("[", LCOLOR_BRACKET);
- print(tag, LCOLOR_TAG);
- print(" ", LCOLOR_BRACKET);
-
- print(message, msg_color);
- //printf("%s %s", tag, message);
-}
-void log_printf(log_level_t level, const char *tag, const char *format, ...) {
- if (!tag || !format) return;
-
- u32 msg_color = get_log_color(level);
-
- // gray
- //print("[", LCOLOR_BRACKET);
- print(tag, LCOLOR_TAG);
- print(" ", LCOLOR_BRACKET);
-
-
-
- va_list args;
- va_start(args, format);
- char buffer[512];
- int pos = 0;
-
- // formated string
- for (const char *p = format; *p && pos < 511; p++) {
- if (*p == '%' && *(p + 1)) {
- p++;
- switch (*p) {
- case 's': {
- const char *s = va_arg(args, const char*);
- if (s) {
- while (*s && pos < 511) {
- buffer[pos++] = *s++;
- }
- }
- break;
- }
- case 'd':
- case 'i': {
- int val = va_arg(args, int);
- char num_buf[32];
- str_from_int(num_buf, val);
- for (char *n = num_buf; *n && pos < 511; n++) {
- buffer[pos++] = *n;
- }
- break;
- }
- case 'u': {
- u32 val = va_arg(args, u32);
- char num_buf[32];
- num_buf[0] = '\0';
- str_append_uint(num_buf, val);
- for (char *n = num_buf; *n && pos < 511; n++) {
- buffer[pos++] = *n;
- }
- break;
- }
- case 'x':
- case 'X': {
- u32 val = va_arg(args, u32);
- char hex_buf[16];
- int hex_pos = 0;
- if (val == 0) {
- hex_buf[hex_pos++] = '0';
- } else {
- u32 temp = val;
- while (temp > 0 && hex_pos < 15) {
- int digit = temp % 16;
- hex_buf[hex_pos++] = (digit < 10) ? ('0' + digit) : ('a' + digit - 10);
- temp /= 16;
- }
- }
- hex_buf[hex_pos] = '\0';
- // reverse hex string
- for (int i = hex_pos - 1; i >= 0 && pos < 511; i--) {
- buffer[pos++] = hex_buf[i];
- }
- break;
- }
- case 'c': {
- char c = (char)va_arg(args, int);
- if (pos < 511) {
- buffer[pos++] = c;
- }
- break;
- }
- case '%': {
- if (pos < 511) {
- buffer[pos++] = '%';
- }
- break;
- }
- default:
- if (pos < 511) {
- buffer[pos++] = '%';
- }
- if (pos < 511) {
- buffer[pos++] = *p;
- }
- break;
- }
- } else {
- buffer[pos++] = *p;
- }
- }
-
- buffer[pos] = '\0';
- va_end(args);
-
-
-
- print(buffer, msg_color);
- //printf("%s", buffer);
-}
diff --git a/shared/string/string.c b/shared/string/string.c
index fdfe129..2163ae9 100644
--- a/shared/string/string.c
+++ b/shared/string/string.c
@@ -1,5 +1,5 @@
#include "string.h"
-#include "print.h"
+//#include "print.h"
void str_copy(char *dest, const char *src)
{
diff --git a/shared/string/string.h b/shared/string/string.h
index e495714..e143d12 100644
--- a/shared/string/string.h
+++ b/shared/string/string.h
@@ -2,11 +2,14 @@
#define STRING_H
#include
-#include "print.h"
-#include "log.h"
+//#include "print.h"
+//#include "log.h"
#include
#include
+#include
+#include
+
void str_copy(char *dest, const char *src);
void str_append(char *dest, const char *src);
void str_append_uint(char *dest, u32 num);
diff --git a/shared/syscalls/mmap.h b/shared/syscalls/mmap.h
new file mode 100644
index 0000000..a24afe7
--- /dev/null
+++ b/shared/syscalls/mmap.h
@@ -0,0 +1,29 @@
+#ifndef MMAP_ARGS_H
+#define MMAP_ARGS_H
+
+typedef struct {
+ unsigned long addr;
+ unsigned long length;
+ int prot;
+ int flags;
+ int fd;
+ long offset;
+} mmap_args_t;
+
+// prot flags
+#define PROT_NONE 0x00
+#define PROT_READ 0x01
+#define PROT_WRITE 0x02
+#define PROT_EXEC 0x04
+
+// default flags
+#define MAP_SHARED 0x01
+#define MAP_PRIVATE 0x02
+#define MAP_ANONYMOUS 0x20
+#define MAP_ANON MAP_ANONYMOUS
+#define MAP_FAILED ((void *)-1)
+
+#define _SCAL_MMAP 9
+#define _SCAL_MUNMAP 11
+
+#endif
\ No newline at end of file
diff --git a/shared/theme/bootconf.emcg b/shared/theme/bootconf.emcg
deleted file mode 100644
index d24b17a..0000000
--- a/shared/theme/bootconf.emcg
+++ /dev/null
@@ -1,76 +0,0 @@
-include stdio; # printf, print, printInt
-include stdclrs;
-
-#
-# emexOS boot configuration
-# bootconf.emcg (emex config)
-#
-
-# bootup visuals
-BOOTUP_VISUALS 0; # verbose boot == 0, silent boot == 1
-BOOTUP_COLOR_THEME STD
-BOOTSCREEN_BG_COLOR GFX_ST_BLACK
-BOOTSCREEN_COLOR GFX_ST_WHITE
-LOGO_SCALE 1
-
-# macros
-if BOOTUP_VISUALS == 0:
- BOOTUP_PRINTF(fmt, ...) == printf(fmt, ##__VA_ARGS__);
- BOOTUP_PRINT(msg, col) == (__c__ #inline c
- {
- do {
- print(msg, col);
- if (boot_log_fd >= 0) fs_write(boot_log_fd, msg, str_len(msg));
- } while(0)
-
- }__c__);
-
- BOOTUP_PRINT_INT(num, col) == (__c__
- {
- do {
- printInt(num, col);
- if (boot_log_fd >= 0) {
- char buf[12];
- buf[0] = '\0';
- str_append_uint(buf, (u32)num);
- fs_write(boot_log_fd, buf, str_len(buf));
- }
- } while(0);
- }__c__);
-
-else:
- BOOTUP_PRINTF(fmt, ...) == ((void)0);
-
- BOOTUP_PRINT(msg, col) == (__c__ #inline c
- {
- do {
- printf("%s", msg);
- if (boot_log_fd >= 0) fs_write(boot_log_fd, msg, str_len(msg));
- } while(0)
-
- }__c__);
-
- BOOTUP_PRINT_INT(num, col) == (__c__
- {
- do {
- printInt(num, col);
- if (boot_log_fd >= 0) {
- char buf[12];
- buf[0] = '\0';
- str_append_uint(buf, (u32)num);
- fs_write(boot_log_fd, buf, str_len(buf));
- }
- } while(0);
- }__c__);
-end;
-
-# console
-CONSOLESCREEN_BG_COLOR GFX_BG
-CONSOLESCREEN_COLOR GFX_WHITE
-CONSOLE_COLOR_THEME FLU
-
-# panic screen
-PANICSCREEN_BG_COLOR GFX_ST_BLUE
-PANICSCREEN_COLOR GFX_ST_WHITE
-PANICSCREEN_COLOR_R GFX_ST_RED
-PANIC_COLOR_THEME STD
diff --git a/shared/theme/doccr.h b/shared/theme/doccr.h
index 2396b08..09a79df 100644
--- a/shared/theme/doccr.h
+++ b/shared/theme/doccr.h
@@ -1,5 +1,7 @@
#pragma once
#include "stdclrs.h"
+#include "../ui/fonts.h"
+
#include // fs_write & fs_open
#include
#include
@@ -33,8 +35,9 @@ extern int init_boot_log;
#define CONSOLE_COLOR_THEME FLU
//panic
-#define PANIC_FONT FONT_8X8_DOS
-#define PANICSCREEN_BG_COLOR GFX_ST_BLUE
+#define PANIC_FONT FONT_8X8_BOLD
+#define PANICSCREEN_BG_COLOR GFX_ST_RED
+#define PANICSCREEN_FG_COLOR GFX_ST_RED + GFX_ST_WHITE
#define PANICSCREEN_COLOR GFX_ST_WHITE
#define PANICSCREEN_COLOR_R GFX_ST_RED
#define PANIC_COLOR_THEME STD
diff --git a/shared/types.h b/shared/types.h
index fa6411b..44c85c4 100644
--- a/shared/types.h
+++ b/shared/types.h
@@ -1,6 +1,11 @@
#ifndef TYPES_H
#define TYPES_H
+/*
+ * THIS IS ONLY THE KLIBC TYPES.H NOT FOR USERSPACE
+ *
+*/
+
typedef unsigned char u8;
typedef unsigned short u16, USHORT;
typedef unsigned int u32;
diff --git a/shared/ui/fonts.c b/shared/ui/fonts.c
index 88f8d57..12eec72 100644
--- a/shared/ui/fonts.c
+++ b/shared/ui/fonts.c
@@ -10,7 +10,7 @@
// font registery
const font_t font_registry[FONT_COUNT] = {
- [FONT_8X12_BOLD] = {
+ /*[FONT_8X12_BOLD] = {
.name = "8x12_BOLD",
.data = &font_8x12_bold,
.char_width = 8,
@@ -29,7 +29,7 @@ const font_t font_registry[FONT_COUNT] = {
.lsb_left = 1,
.glyph_count = 2048,
.unicode_direct = 1
- },
+ },*/
[FONT_8X8_BOLD] = {
.name = "8x8_BOLD",
.data = &font_8x8_bold,
@@ -40,7 +40,7 @@ const font_t font_registry[FONT_COUNT] = {
.glyph_count = 256,
.unicode_direct = 0
},
- [FONT_8X16] = {
+ /*[FONT_8X16] = {
.name = "8x16",
.data = &font_8x16,
.char_width = 8,
@@ -59,7 +59,7 @@ const font_t font_registry[FONT_COUNT] = {
.lsb_left = 0,
.glyph_count = 256,
.unicode_direct = 0
- },
+ },*/
[FONT_8X8] = {
.name = "8x8",
.data = &font_8x8,
@@ -70,7 +70,7 @@ const font_t font_registry[FONT_COUNT] = {
.glyph_count = 256,
.unicode_direct = 0
},
- [FONT_16X32] = {
+ /*[FONT_16X32] = {
.name = "16x32",
.data = &font_16x32,
.char_width = 16,
@@ -79,7 +79,7 @@ const font_t font_registry[FONT_COUNT] = {
.lsb_left = 0,
.glyph_count = 256,
.unicode_direct = 0
- }/*,
+ }*//*,
[GOHUFONT] = {
.name = "gohufont",
.data = &gohufont_8x16,
diff --git a/shared/ui/fonts.h b/shared/ui/fonts.h
index 30bcdf4..0b5a8c8 100644
--- a/shared/ui/fonts.h
+++ b/shared/ui/fonts.h
@@ -3,15 +3,15 @@
#include
typedef enum {
- FONT_8X12_BOLD = 0,
- FONT_8X12 = 1,
- FONT_8X8_BOLD = 2,
- FONT_8X8 = 3,
- FONT_8X16 = 4,
- FONT_8X16_BOLD = 5,
- FONT_16X32 = 6,
+ //FONT_8X12_BOLD = 0,
+ //FONT_8X12 = 1,
+ FONT_8X8_BOLD = 0,
+ FONT_8X8 = 1,
+ //FONT_8X16 = 4,
+ //FONT_8X16_BOLD = 5,
+ //FONT_16X32 = 6,
//GOHUFONT = 7,
- FONT_COUNT = 7//8
+ FONT_COUNT = 2//8
} font_type_t;
typedef struct {
const char *name;
diff --git a/shared/ui/fonts/font_8x8.h b/shared/ui/fonts/font_8x8.h
index 3b1dc58..4028fbc 100644
--- a/shared/ui/fonts/font_8x8.h
+++ b/shared/ui/fonts/font_8x8.h
@@ -4,17 +4,28 @@
//https://github.com/SloopyCode/BitFonts
static const u8 font_8x8[256][8] = {
// all unused characters can be used as a custom texture (0x00 to 0x1F)
- [0x00] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // null
- [0x01] = { 0x10, 0x18, 0x1C, 0x1E, 0x1C, 0x18, 0x10, 0x00}, // arrow
- [0x02] = { 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00}, // long dash
- [0x03] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // block filled
- [0x04] = { 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF}, // hollow block
- [0x05] = { 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E}, // rounded block filled
- [0x06] = { 0x7E, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x7E}, // rounded hollow block
- [0x07] = { 0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C}, // circle filled
- [0x08] = { 0x18, 0x7E, 0x7E, 0xFF, 0xFF, 0x7E, 0x7E, 0x18}, // circle2 filled
- [0x09] = { 0x3C, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3C}, // circle outline
- [0x0A] = { 0x18, 0x66, 0x42, 0x81, 0x81, 0x42, 0x66, 0x18}, // circle2 outline
+ [0x00] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x01] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x02] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x03] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x04] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x05] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x06] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x07] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x08] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x09] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x0A] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ //[0x00] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // null
+ //[0x01] = { 0x10, 0x18, 0x1C, 0x1E, 0x1C, 0x18, 0x10, 0x00}, // arrow
+ //[0x02] = { 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00}, // long dash
+ //[0x03] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // block filled
+ //[0x04] = { 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF}, // hollow block
+ //[0x05] = { 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E}, // rounded block filled
+ //[0x06] = { 0x7E, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x7E}, // rounded hollow block
+ //[0x07] = { 0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C}, // circle filled
+ //[0x08] = { 0x18, 0x7E, 0x7E, 0xFF, 0xFF, 0x7E, 0x7E, 0x18}, // circle2 filled
+ //[0x09] = { 0x3C, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3C}, // circle outline
+ //[0x0A] = { 0x18, 0x66, 0x42, 0x81, 0x81, 0x42, 0x66, 0x18}, // circle2 outline
// and iknow there are unicode expecialy for these special characters but this is simpler for now
[0x0B] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // unused
@@ -142,16 +153,16 @@ static const u8 font_8x8[256][8] = {
// German (custom slots)
- [0x80] = { 0x00,0x00,0x28,0x00,0x38,0x04,0x3C,0x44}, // ä
- [0x81] = { 0x00,0x00,0x28,0x00,0x38,0x44,0x44,0x38}, // ö
- [0x82] = { 0x00,0x00,0x28,0x00,0x44,0x44,0x44,0x3C}, // ü
- [0x83] = { 0x00,0x00,0x38,0x44,0x40,0x38,0x40,0x7C}, // ß
+ [0x80] = { 0x28,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00}, // ä
+ [0x81] = { 0x28,0x00,0x38,0x44,0x44,0x44,0x38,0x00}, // ö
+ [0x82] = { 0x28,0x00,0x44,0x44,0x44,0x44,0x3C,0x00}, // ü
+ [0x83] = { 0x00,0x38,0x44,0x40,0x38,0x40,0x7C,0x00}, // ß
// Russian (CP1251 code points)
[0xA8] = { 0x7c, 0x40, 0x40, 0x78, 0x40, 0x40, 0x7c, 0x10 }, // Ё
[0xB8] = { 0x28, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00 }, // ё
-
+
[0xC0] = { 0x10, 0x28, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x00 }, // А
[0xC1] = { 0x78, 0x40, 0x40, 0x78, 0x44, 0x44, 0x78, 0x00 }, // Б
[0xC2] = { 0x78, 0x44, 0x44, 0x78, 0x44, 0x44, 0x78, 0x00 }, // В
diff --git a/shared/ui/fonts/font_8x8_bold.h b/shared/ui/fonts/font_8x8_bold.h
index 90c11bb..49c079d 100644
--- a/shared/ui/fonts/font_8x8_bold.h
+++ b/shared/ui/fonts/font_8x8_bold.h
@@ -3,18 +3,29 @@
#include
//https://github.com/SloopyCode/BitFonts
static const u8 font_8x8_bold[256][8] = {
- // all unused characters can be used as a custom texture (0x00 to 0x1F)
- [0x00] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // null
- [0x01] = { 0x10, 0x18, 0x1C, 0x1E, 0x1C, 0x18, 0x10, 0x00}, // arrow
- [0x02] = { 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00}, // long dash
- [0x03] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // block filled
- [0x04] = { 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF}, // hollow block
- [0x05] = { 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E}, // rounded block filled
- [0x06] = { 0x7E, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x7E}, // rounded hollow block
- [0x07] = { 0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C}, // circle filled
- [0x08] = { 0x18, 0x7E, 0x7E, 0xFF, 0xFF, 0x7E, 0x7E, 0x18}, // circle2 filled
- [0x09] = { 0x3C, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3C}, // circle outline
- [0x0A] = { 0x18, 0x66, 0x42, 0x81, 0x81, 0x42, 0x66, 0x18}, // circle2 outline
+ // all unused characters can be used as a custom texture (0x00 to 0x1F)
+ [0x00] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x01] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x02] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x03] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x04] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x05] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x06] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x07] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x08] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x09] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ [0x0A] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ //[0x00] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // null
+ //[0x01] = { 0x10, 0x18, 0x1C, 0x1E, 0x1C, 0x18, 0x10, 0x00}, // arrow
+ //[0x02] = { 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00}, // long dash
+ //[0x03] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // block filled
+ //[0x04] = { 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF}, // hollow block
+ //[0x05] = { 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E}, // rounded block filled
+ //[0x06] = { 0x7E, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x7E}, // rounded hollow block
+ //[0x07] = { 0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C}, // circle filled
+ //[0x08] = { 0x18, 0x7E, 0x7E, 0xFF, 0xFF, 0x7E, 0x7E, 0x18}, // circle2 filled
+ //[0x09] = { 0x3C, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3C}, // circle outline
+ //[0x0A] = { 0x18, 0x66, 0x42, 0x81, 0x81, 0x42, 0x66, 0x18}, // circle2 outline
// and iknow there are unicode expecialy for these special characters but this is simpler for now
[0x0B] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // unused
@@ -141,10 +152,10 @@ static const u8 font_8x8_bold[256][8] = {
[0x007E] = {0x76,0xdc,0x00,0x00,0x00,0x00,0x00,0x00}, // ~
// German (custom slots)
- [0x80] = { 0x00,0x00,0x28,0x00,0x38,0x04,0x3C,0x44}, // ä
- [0x81] = { 0x00,0x00,0x28,0x00,0x38,0x44,0x44,0x38}, // ö
- [0x82] = { 0x00,0x00,0x28,0x00,0x44,0x44,0x44,0x3C}, // ü
- [0x83] = { 0x00,0x00,0x38,0x44,0x40,0x38,0x40,0x7C}, // ß
+ [0x80] = { 0x28,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00}, // ä
+ [0x81] = { 0x28,0x00,0x38,0x44,0x44,0x44,0x38,0x00}, // ö
+ [0x82] = { 0x28,0x00,0x44,0x44,0x44,0x44,0x3C,0x00}, // ü
+ [0x83] = { 0x00,0x38,0x44,0x40,0x38,0x40,0x7C,0x00}, // ß
// Russian (CP1251 code points)
[0xA8] = { 0x7c, 0x40, 0x40, 0x78, 0x40, 0x40, 0x7c, 0x10 }, // Ё
diff --git a/shared/ui/uno.c b/shared/ui/uno.c
index 75cf1aa..f4e29c0 100644
--- a/shared/ui/uno.c
+++ b/shared/ui/uno.c
@@ -1,6 +1,5 @@
#include "uno.h"
#include
-#include
static u32 calculate_text_width(const char *text, u16 font_size) {
if (!text) return 0;
diff --git a/src/TODO.md b/src/TODO.md
index 91a6334..0b5a973 100644
--- a/src/TODO.md
+++ b/src/TODO.md
@@ -1,19 +1,26 @@
-move reqs (inline assembly, limine reqs) to /kernel/include/ports(.h&.c)
-with /kernel/include/reqs(.h&.c)
+NOTE:
+this is not a complete todo list
+[ ] fix log system
+[ ] fix slow bootscreen
+[ ] fix user_config creates a already written file
+[ ] fix fat32 is not registered
+[ ] implement atapi support
+[x] implement bmp
+[ ] implement png
+[ ] implement mp4
+[ ] implement ahci
+[x] implement a libc
+[ ] implement a stub system like vmlinux(virtual memory linux zipped), call it emez (emex's zipped kernel)
+[x] implement procfs
+[ ] implement ext2
+[ ] implement ext4
+[ ] implement window system/server
+[ ] implement desktop enviroment
+[ ] implement window manager
+[ ] upgrade theme manager
+[ ] upgrade font manager
+[ ] upgrade bootscreen manager
-remaking mem_manager with slab
-Make console to an app
-make the top bar in console to an app
-make every command to an app
-
-
-if we have a fs the kernel should no longer load per keyboard_pull and so on,
-it should load the module system which searches for all modules which
-are all saved in the fs and then they get loaded and everything should work
-
-
-simple disk driver for fat32 (block reading)
-(sector reader, 512 b)
-bps parser , cluster size
+
diff --git a/src/commands.TODO b/src/commands.TODO
new file mode 100644
index 0000000..f01618f
--- /dev/null
+++ b/src/commands.TODO
@@ -0,0 +1,54 @@
+[ ] dofetch
+[ ] version
+[x] cat
+[x] ls
+[x] echo
+[x] cd
+[x] tree
+[ ] pwd
+[ ] touch
+[ ] mkdir
+[ ] rmdir
+[ ] rm
+[ ] cp
+[ ] ecc (emex c compiler)
+[ ] mv
+[ ] chmod
+[ ] chown
+[ ] find
+[ ] grep
+[ ] head
+[ ] tail
+[ ] less
+[ ] more
+[ ] wc
+[ ] man
+[ ] history
+[ ] alias
+[ ] uname
+[ ] whoami
+[ ] env
+[ ] export
+[ ] unset
+[ ] source
+[ ] df
+[ ] du
+[ ] dd
+[ ] ping
+[ ] top
+[ ] htop
+[ ] ps
+[ ] kill
+[ ] killall
+[ ] jobs
+[ ] bg
+[ ] fg
+[ ] sleep
+[ ] date
+[ ] cal
+[ ] mount
+[ ] umount
+[ ] unalias
+[ ] clear
+[ ] reboot
+[ ] shutdown
diff --git a/src/drivers/drivers.h b/src/drivers/drivers.h
index 027ffc6..a427b45 100644
--- a/src/drivers/drivers.h
+++ b/src/drivers/drivers.h
@@ -5,3 +5,13 @@
#include
//#include
//#include
+
+//#include
+//#include
+
+//#include
+//#include
+
+#include
+
+//ddir == dev dir
\ No newline at end of file
diff --git a/src/drivers/ps2/keyboard/keyboard.c b/src/drivers/ps2/keyboard/keyboard.c
index dce2303..f69003d 100644
--- a/src/drivers/ps2/keyboard/keyboard.c
+++ b/src/drivers/ps2/keyboard/keyboard.c
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
static key_buffer_t key_buffer = {0};
static int shift = 0;
@@ -194,9 +195,9 @@ static void keyboard_module_fini(void) {
}
driver_module keyboard_module = (driver_module) {
- .name = "ps2_keyboard",
- .mount = "/emr/drv/keyboard", // because its not the driver not the device
- .version = VERSION_NUM(0, 3, 1, 0),
+ .name = KBDNAME,
+ .mount = KBDPATH, // because its the driver not the device
+ .version = KBDUNIVERSAL,
.init = keyboard_module_init,
.fini = keyboard_module_fini,
.open = NULL,
diff --git a/src/drivers/ps2/keyboard/loader.c b/src/drivers/ps2/keyboard/loader.c
index 365ac3d..417bc2a 100644
--- a/src/drivers/ps2/keyboard/loader.c
+++ b/src/drivers/ps2/keyboard/loader.c
@@ -1,6 +1,6 @@
// loader.c
#include "loader.h"
-#include
+//#include
#include
#include
#include
@@ -8,6 +8,8 @@
#include
// Parse .map (emex keymap) file format
+#define KEYMAP_DIR "/emr/config/keymaps/"
+
static int parse_keymap_data(const char *data, size_t size, keymap_t *km) {
if (!data || !km || size == 0) return -1;
@@ -26,7 +28,7 @@ static int parse_keymap_data(const char *data, size_t size, keymap_t *km) {
if (*line == '#' || *line == '\n') {
// skip comments and empty lines
while (line < end && *line != '\n') line++;
- if (line < end && *line == '\n') line++;
+ if (line < end) line++;
continue;
}
@@ -38,21 +40,17 @@ static int parse_keymap_data(const char *data, size_t size, keymap_t *km) {
// (2 digits)
for (int i = 0; i < 2 && line < end; i++) {
scancode <<= 4;
- if (*line >= '0' && *line <= '9') {
- scancode |= (*line - '0');
- } else if (*line >= 'A' && *line <= 'F') {
- scancode |= (*line - 'A' + 10);
- } else if (*line >= 'a' && *line <= 'f') {
- scancode |= (*line - 'a' + 10);
- }
+ if (*line >= '0' && *line <= '9') scancode |= (*line - '0');
+ else if (*line >= 'A' && *line <= 'F') scancode |= (*line - 'A' + 10);
+ else if (*line >= 'a' && *line <= 'f') scancode |= (*line - 'a' + 10);
line++;
}
- while (line < end && *line != '=') line++; // =
- if (line < end && *line == '=') line++;
- while (line < end && (*line == ' ' || *line == '\t')) line++; // space
+ while (line < end && *line != '=') line++;
+ if (line < end) line++; // skip '='
+ while (line < end && (*line == ' ' || *line == '\t')) line++;
- // parse normal, between single quotes
+ // parse normal char
if (line < end && *line == '\'') {
line++;
if (line < end) {
@@ -70,13 +68,9 @@ static int parse_keymap_data(const char *data, size_t size, keymap_t *km) {
u8 hex = 0;
for (int i = 0; i < 2 && line < end; i++) {
hex <<= 4;
- if (*line >= '0' && *line <= '9') {
- hex |= (*line - '0');
- } else if (*line >= 'A' && *line <= 'F') {
- hex |= (*line - 'A' + 10);
- } else if (*line >= 'a' && *line <= 'f') {
- hex |= (*line - 'a' + 10);
- }
+ if (*line >= '0' && *line <= '9') hex |= (*line - '0');
+ else if (*line >= 'A' && *line <= 'F') hex |= (*line - 'A' + 10);
+ else if (*line >= 'a' && *line <= 'f') hex |= (*line - 'a' + 10);
line++;
}
km->normal[scancode] = hex;
@@ -115,13 +109,9 @@ static int parse_keymap_data(const char *data, size_t size, keymap_t *km) {
u8 hex = 0;
for (int i = 0; i < 2 && line < end; i++) {
hex <<= 4;
- if (*line >= '0' && *line <= '9') {
- hex |= (*line - '0');
- } else if (*line >= 'A' && *line <= 'F') {
- hex |= (*line - 'A' + 10);
- } else if (*line >= 'a' && *line <= 'f') {
- hex |= (*line - 'a' + 10);
- }
+ if (*line >= '0' && *line <= '9') hex |= (*line - '0');
+ else if (*line >= 'A' && *line <= 'F') hex |= (*line - 'A' + 10);
+ else if (*line >= 'a' && *line <= 'f') hex |= (*line - 'a' + 10);
line++;
}
km->shift[scancode] = hex;
@@ -142,7 +132,7 @@ static int parse_keymap_data(const char *data, size_t size, keymap_t *km) {
// skip to nect line
while (line < end && *line != '\n') line++;
- if (line < end && *line == '\n') line++;
+ if (line < end) line++;
}
return 0;
@@ -151,90 +141,32 @@ static int parse_keymap_data(const char *data, size_t size, keymap_t *km) {
int keymap_load_from_module(const char *name, keymap_t *km) {
if (!name || !km) return -1;
- if (!module_request.response || module_request.response->module_count == 0) {
- printf("[KEYMAP] No Limine modules available\n");
+ // build path with us keymap
+ char path[64];
+ str_copy(path, KEYMAP_DIR);
+ str_append(path, name);
+ str_append(path, KEYMAP_FORMAT);
+
+ int fd = fs_open(path, O_RDONLY);
+ if (fd < 0) {
+ log("[KEYMAP]", "not found: ", d);
+ BOOTUP_PRINT(path, white());
+ BOOTUP_PRINT("\n", white());
return -1;
}
- struct limine_module_response *response =
- (struct limine_module_response *)module_request.response;
-
- // Builds the expected filename
- char expected_name[64];
- str_copy(expected_name, name);
- str_append(expected_name, KEYMAP_FORMAT);
-
- // search for keymap module
- for (u64 i = 0; i < response->module_count; i++) {
- struct limine_file *module = response->modules[i];
-
- //Extract filename from path
- const char *filename = module->path;
- const char *last_slash = filename;
- for (const char *p = filename; *p; p++) {
- if (*p == '/') last_slash = p + 1;
- }
- filename = last_slash;
+ // read the whole file into a stack buffer
+ // .map files are small (< 4KB)
+ char buf[4096];
+ ssize_t bytes = fs_read(fd, buf, sizeof(buf) - 1);
+ fs_close(fd);
- // checks if this is our keymap
- if (str_equals(filename, expected_name)) {
- printf("[KEYMAP] Loading %s from module (%lu bytes)\n",
- filename, module->size);
+ if (bytes <= 0) return -1;
+ buf[bytes] = '\0';
- return parse_keymap_data((const char*)module->address,
- module->size, km);
- }
- }
-
- printf("[KEYMAP] Module %s not found\n", expected_name);
- return -1;
+ return parse_keymap_data(buf, (size_t)bytes, km);
}
int keymap_modules_init(void) {
- if (!module_request.response) {
- printf("[KEYMAP] No module response available\n");
- return -1;
- }
-
- struct limine_module_response *response =
- (struct limine_module_response *)module_request.response;
-
- log("[KEYMAP]", "Found ", d);
- char buf[32];
- str_from_int(buf, (int)response->module_count);
- BOOTUP_PRINT(buf, white());
- BOOTUP_PRINT(" Limine modules\n", white());
-
-
- // lists all keymap modules
- int keymap_count = 0;
- for (u64 i = 0; i < response->module_count; i++) {
- struct limine_file *module = response->modules[i];
-
- const char *filename = module->path;
- const char *last_slash = filename;
- for (const char *p = filename; *p; p++) {
- if (*p == '/') last_slash = p + 1;
- }
- filename = last_slash;
-
- // check if this is a keymap file
- if (str_contains(filename, KEYMAP_FORMAT)) {
- printf("[KEYMAP] Available: %s\n", filename);
- keymap_count++;
- }
- }
-
- buf[0] = '\0';
- //char buf[64];
- char numbuf[32];
-
- str_copy(buf, "Total keymaps found: ");
- str_from_int(numbuf, keymap_count);
- str_append(buf, numbuf);
- str_append(buf, "\n");
-
- log("[KEYMAP]", buf, d);
-
- return keymap_count;
+ return 0;
}
diff --git a/src/drivers/ps2/keyboard/maps.c b/src/drivers/ps2/keyboard/maps.c
index e0b5d5b..1f961bf 100644
--- a/src/drivers/ps2/keyboard/maps.c
+++ b/src/drivers/ps2/keyboard/maps.c
@@ -33,6 +33,12 @@ int keymap_init(void) {
return 0;
}
+ if (keymap_load_from_module("RU", ¤t_keymap) == 0) {
+ str_copy(current_keymap_name, "RU");
+ log("[KEYMAP]", "Loaded default: RU\n", d);
+ return 0;
+ }
+
log("[KEYMAP]", "ERROR: No keymap could be loaded!\n", warning);
return -1;
}
diff --git a/src/drivers/ps2/mouse/mouse.c b/src/drivers/ps2/mouse/mouse.c
new file mode 100644
index 0000000..220070e
--- /dev/null
+++ b/src/drivers/ps2/mouse/mouse.c
@@ -0,0 +1,93 @@
+#include "mouse.h"
+#include
+#include
+#include
+
+static mouse_event_t evbuf[MOUSE_BUF_SIZE];
+static volatile int ev_r = 0, ev_w = 0;
+static void ev_push(mouse_event_t *e) {
+ int next = (ev_w + 1) % MOUSE_BUF_SIZE;
+ if (next != ev_r) { evbuf[ev_w] = *e; ev_w = next; }
+}
+
+int mouse_has_event(void) { return ev_r != ev_w; }
+int mouse_get_event(mouse_event_t *e) {
+ if (ev_r == ev_w) return 0;
+ *e = evbuf[ev_r]; ev_r = (ev_r + 1) % MOUSE_BUF_SIZE;
+ return 1;
+}
+
+static int abs_x = 0, abs_y = 0;
+static void ps2_wait_w(void) {
+ int t=100000; while(t-- && ( inb(PS2_CMD)&0x02));
+}
+static void ps2_wait_r(void) {
+ int t=100000; while(t-- && (!inb(PS2_CMD)&0x01));
+}
+static u8 ps2_rd(void){
+ ps2_wait_r(); return inb(PS2_DATA);
+}
+static void ps2_cmd(u8 c){
+ ps2_wait_w(); outb(PS2_CMD, c);
+}
+static void ps2_dat(u8 d){
+ ps2_wait_w(); outb(PS2_DATA, d);
+}
+
+static u8 pkt[3];
+static int pkt_i = 0;
+
+static void mouse_irq(cpu_state_t *s) {
+ (void)s;
+ u8 status = inb(PS2_CMD);
+ if (!(status & 0x01)) return;
+
+ if (!(status & 0x20)) { inb(PS2_DATA); return; }
+
+ u8 b = inb(PS2_DATA);
+
+ if (pkt_i == 0 && !(b & 0x08)) return; // sync check
+ pkt[pkt_i++] = b;
+ if (pkt_i < 3) return;
+ pkt_i = 0;
+
+ if (pkt[0] & 0xC0) return; // overflow and discard
+
+ // 9-bit signed via sign bits in byte 0
+ int dx = (int)pkt[1] - ((pkt[0] & 0x10) ? 256 : 0);
+ int dy = -((int)pkt[2] - ((pkt[0] & 0x20) ? 256 : 0));
+
+ u32 fw = get_fb_width(), fh = get_fb_height();
+ if (!fw || !fh) return;
+
+ abs_x += dx; abs_y += dy;
+ if (abs_x < 0) abs_x = 0;
+ if (abs_y < 0) abs_y = 0;
+ if (abs_x >= (int)fw) abs_x = (int)fw - 1;
+ if (abs_y >= (int)fh) abs_y = (int)fh - 1;
+
+ mouse_event_t ev = {
+ .dx = dx, .dy = dy,
+ .abs_x = abs_x, .abs_y = abs_y,
+ .buttons = pkt[0] & 0x07
+ };
+ ev_push(&ev);
+}
+
+void mouse_init(void) {
+ ps2_cmd(0xA8);
+ ps2_cmd(0x20); u8 cfg = ps2_rd(); cfg |= 0x02; cfg &= ~0x20;
+ ps2_cmd(0x60); ps2_dat(cfg);
+ ps2_cmd(0xD4); ps2_dat(0xF6); ps2_rd(); // defaults
+ ps2_cmd(0xD4); ps2_dat(0xE8); ps2_rd(); // set resolution
+ ps2_cmd(0xD4); ps2_dat(0x02); ps2_rd(); // 4 counts/mm
+ ps2_cmd(0xD4); ps2_dat(0xF3); ps2_rd(); // set sample rate
+ ps2_cmd(0xD4); ps2_dat(40); ps2_rd(); // 40 samples per sec
+ ps2_cmd(0xD4); ps2_dat(0xF4); ps2_rd(); // enable
+
+ abs_x = (int)(get_fb_width() / 2);
+ abs_y = (int)(get_fb_height() / 2);
+ pkt_i = 0;
+
+ irq_register_handler(12, mouse_irq);
+}
\ No newline at end of file
diff --git a/src/drivers/ps2/mouse/mouse.h b/src/drivers/ps2/mouse/mouse.h
new file mode 100644
index 0000000..6664a2b
--- /dev/null
+++ b/src/drivers/ps2/mouse/mouse.h
@@ -0,0 +1,21 @@
+#pragma once
+#include
+
+#define MOUSE_BUF_SIZE 64
+
+#define PS2_DATA 0x60
+#define PS2_CMD 0x64
+
+typedef struct {
+ int dx, dy; // relative movements
+ int abs_x, abs_y;
+ unsigned char buttons;
+} mouse_event_t;
+
+#define MOUSE_BTN_LEFT (1<<0)
+#define MOUSE_BTN_RIGHT (1<<1)
+#define MOUSE_BTN_MIDDLE (1<<2)
+
+void mouse_init(void);
+int mouse_has_event(void);
+int mouse_get_event(mouse_event_t *ev);
\ No newline at end of file
diff --git a/src/drivers/ps2/ps2.h b/src/drivers/ps2/ps2.h
index 9cb89be..c68a0fa 100644
--- a/src/drivers/ps2/ps2.h
+++ b/src/drivers/ps2/ps2.h
@@ -2,10 +2,9 @@
#define PS2_H
#include "keyboard/keyboard.h"
+#include "mouse/mouse.h"
// keyboard driver
void keyboard_poll(void);
-// mouse driver
-
-#endif
+#endif
\ No newline at end of file
diff --git a/src/drivers/storage/ata/disk.c b/src/drivers/storage/ata/disk.c
index cde8d02..970a276 100644
--- a/src/drivers/storage/ata/disk.c
+++ b/src/drivers/storage/ata/disk.c
@@ -6,6 +6,7 @@
#include
#include
#include
+//#include
//note:
// this is not a perfect ata driver and will not work on real hardware, but for fat32 i need a disk driver so i chose this one
@@ -461,14 +462,14 @@ int ATAget_device_count(void) {
return ATAdevice_count;
}
-
+/*
static int ATAmodule_init(void) {
//ATAdetect_devices();
// already done
log("[ATA]", "Load ATA module...\n", d);
return 0;
-}
+}*/
// pub:
void ata_init(void) {
@@ -482,18 +483,19 @@ void ata_init(void) {
//ATAmodule_init();
ATAdetect_devices();
}
-
+/*
static void ATAmodule_fini(void) {
// cleanup if needed
}
driver_module ata_module = {
- .name = "ata-hdd0",
- .mount = "/emr/drv/hdd0",
- .version = VERSION_NUM(0, 1, 0, 0),
+ .name = ATANAME,
+ .mount = ATAPATH,
+ .version = ATAUNIVERSAL,
.init = ATAmodule_init,
.fini = ATAmodule_fini,
.open = NULL,
.read = NULL,
.write = NULL,
};
+*/
\ No newline at end of file
diff --git a/src/kernel/arch/amd64/amd64.c b/src/kernel/arch/amd64/amd64.c
index 96aa003..d42e1ac 100644
--- a/src/kernel/arch/amd64/amd64.c
+++ b/src/kernel/arch/amd64/amd64.c
@@ -10,12 +10,6 @@ static void cpuid(u32 leaf, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) {
: "a"(leaf), "c"(0));
}
-static void cpuid_count(u32 leaf, u32 subleaf, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) {
- __asm__ volatile("cpuid"
- : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
- : "a"(leaf), "c"(subleaf));
-}
-
void amd64_detect(amd64_info_t *info) {
if (!info) return;
@@ -209,4 +203,4 @@ void amd64_init_optimizations(void) {
if (ecx & AMD_FEATURE_SVM) {
printf("[AMD64] AMD-V virtualization available\n");
}
-}
+}
\ No newline at end of file
diff --git a/src/kernel/arch/x86_64/exceptions/irq.c b/src/kernel/arch/x86_64/exceptions/irq.c
index ab72d7d..d0f2de8 100644
--- a/src/kernel/arch/x86_64/exceptions/irq.c
+++ b/src/kernel/arch/x86_64/exceptions/irq.c
@@ -84,7 +84,8 @@ void irq_register_handler(u8 irq, irq_handler_t handler)
{
if (irq < 16) {
irq_handlers[irq] = handler;
- irq_set_mask(irq, 0); // enable
+ irq_set_mask(irq, 0);
+ if (irq >= 8) irq_set_mask(2, 0);
}
}
diff --git a/src/kernel/arch/x86_64/exceptions/isr.c b/src/kernel/arch/x86_64/exceptions/isr.c
index 6d33c9a..16f7e60 100644
--- a/src/kernel/arch/x86_64/exceptions/isr.c
+++ b/src/kernel/arch/x86_64/exceptions/isr.c
@@ -12,16 +12,17 @@ void isr_install(void)
}
// set IDT Gates for ALL Exceptions
- idt_set_gate(0, (u64)isr0, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(1, (u64)isr1, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(2, (u64)isr2, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(3, (u64)isr3, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(4, (u64)isr4, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(5, (u64)isr5, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(6, (u64)isr6, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(7, (u64)isr7, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(8, (u64)isr8, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
- idt_set_gate(9, (u64)isr9, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(0, (u64)isr0, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(1, (u64)isr1, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(2, (u64)isr2, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(3, (u64)isr3, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(4, (u64)isr4, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(5, (u64)isr5, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(6, (u64)isr6, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(7, (u64)isr7, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate_ist(8, (u64)isr8, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT, 1);
+ //idt_set_gate(8, (u64)isr8, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
+ idt_set_gate(9, (u64)isr9, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
idt_set_gate(10, (u64)isr10, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
idt_set_gate(11, (u64)isr11, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
idt_set_gate(12, (u64)isr12, IDT_FLAG_PRESENT | IDT_FLAG_RING0 | IDT_FLAG_GATE_INT);
diff --git a/src/kernel/arch/x86_64/exceptions/panic.c b/src/kernel/arch/x86_64/exceptions/panic.c
index 172edb6..cea3854 100644
--- a/src/kernel/arch/x86_64/exceptions/panic.c
+++ b/src/kernel/arch/x86_64/exceptions/panic.c
@@ -1,50 +1,96 @@
#include "panic.h"
+
#include
-#include
#include
#include
+#include
+#include
+#include
+
+//#define BOOTUP_VISUALS 0
+
+#define PANIC_BG PANICSCREEN_BG_COLOR
+#define PANIC_FG PANICSCREEN_FG_COLOR
+
+// from the old console poweroff
+static void panic_reboot(void) {
+ outb(0x64, 0xFE);
+ for (volatile int i = 0; i < 1000000; i++) __asm__ volatile("nop");
+
+ u8 tmp = inb(0xCF9);
+ outb(0xCF9, tmp | 0x02);
+ outb(0xCF9, tmp | 0x06);
+ for (volatile int i = 0; i < 1000000; i++) __asm__ volatile("nop");
+
+ // nothing worked, halt forever
+ log("\n::", "SHUTDOWN FAILED, HALTING FOREVER.", _d);
+ while (1) __asm__ volatile("cli; hlt");
+}
__attribute__((noreturn)) void panic(const char *message)
{
+ log("\n::", "PANIC WILL BE EXECUTED IN 100000000 TICKS\n\n", _d);
+ delay(10);
+
setcontext(THEME_PANIC);
clear(PANICSCREEN_BG_COLOR);
- // Disable interrupts
+ f_setcontext(PANIC_FONT);
+ // disable interrupts
__asm__ volatile("cli");
- print("\n", white());
- print("!!! --- KERNEL PANIC --- !!!", red());
- print("\n", white());
+ print("\n", PANIC_FG);
+ print("--- KERNEL PANIC --- ", PANIC_FG);
+ print("\n", PANIC_FG);
+
+ f_setcontext(FONT_8X8);
+
+ print("\nIt seems that emexOS has encountered an error.\n\n", PANIC_FG);
if (message) {
- print(message, red());
- print("\n", white());
+ print(message, PANIC_FG);
+ print("\n", PANIC_FG);
}
- print("\nSystem halted.", white());
+ print("System halted, \nYour computer will now restart...", PANIC_FG);
+
+ delay(50);
+ panic_reboot();
// HALT
- while(1) {
- __asm__ volatile("cli; hlt");
- }
+ //while(1) {
+ // __asm__ volatile("cli; hlt");
+ //}
}
__attribute__((noreturn)) void panic_exception(cpu_state_t *state, const char *message)
{
+ u64 cr2, cr3;
+ __asm__ volatile("mov %%cr2, %0" : "=r"(cr2));
+ __asm__ volatile("mov %%cr3, %0" : "=r"(cr3));
+
+ log("\n::", "PANIC WILL BE EXECUTED IN 100000000 TICKS\n\n", _d);
+ delay(10);
+
setcontext(THEME_PANIC);
clear(PANICSCREEN_BG_COLOR);
+ f_setcontext(PANIC_FONT);
// Disable interrupts
__asm__ volatile("cli");
- print("\n", white());
- print("!!! PANIC !!!", red());
- print("\n", white());
+ print("\n", PANIC_FG);
+ print("--- KERNEL PANIC --- ", PANIC_FG);
+ print("\n", PANIC_FG);
+
+ f_setcontext(FONT_8X8);
+
+ print("\nIt seems that emexOS has encountered an error.\n\n", PANIC_FG);
if (message) {
char buf[128];
str_copy(buf, "Exception: ");
str_append(buf, message);
- print(buf, red());
- print("\n", white());
+ print(buf, PANIC_FG);
+ print("\n", PANIC_FG);
}
// Print exception details
@@ -53,27 +99,70 @@ __attribute__((noreturn)) void panic_exception(cpu_state_t *state, const char *m
str_append_uint(buf, (u32)state->int_no);
str_append(buf, " ERR: ");
str_append_uint(buf, (u32)state->err_code);
- print(buf, white());
- print("\n", white());
+ print(buf, PANIC_FG);
+ print("\n", PANIC_FG);
// Print RIP
+ char hex[32];
str_copy(buf, "RIP: 0x");
- str_append_uint(buf, (u32)(state->rip >> 32));
- str_append_uint(buf, (u32)(state->rip & 0xFFFFFFFF));
- print(buf, white());
- print("\n", white());
+ str_from_hex(hex, state->rip);
+ str_append(buf, hex);
+ print(buf, PANIC_FG);
+ print("\n", PANIC_FG);
// Print RSP
str_copy(buf, "RSP: 0x");
- str_append_uint(buf, (u32)(state->rsp >> 32));
- str_append_uint(buf, (u32)(state->rsp & 0xFFFFFFFF));
+ str_from_hex(hex, state->rsp);
+ str_append(buf, hex);
+ print(buf, PANIC_FG);
+ print("\n\n", PANIC_FG);
+
+ // Print RFLAGS
+ str_copy(buf, "RFLAGS: 0x");
+ str_from_hex(hex, state->rflags);
+ str_append(buf, hex);
+ print(buf, white());
+ print("\n", white());
+
+ if (state->int_no == 14) {
+ str_copy(buf, "CR2: 0x");
+ str_from_hex(hex, cr2);
+ str_append(buf, hex);
+ str_append(buf, " (faulting address)");
+ print(buf, PANIC_FG);
+ print("\n", white());
+
+ str_copy(buf, "Fault: ");
+ if (state->err_code & 1)
+ str_append(buf, "prot-violation ");
+ else str_append(buf, "not-present ");
+ if (state->err_code & 2)
+ str_append(buf, "write ");
+ else str_append(buf, "read ");
+ if (state->err_code & 4)
+ str_append(buf, "user-mode ");
+ else str_append(buf, "kernel-mode ");
+ if (state->err_code & 8)
+ str_append(buf, "reserved-bits ");
+ if (state->err_code & 16)
+ str_append(buf, "instruction-fetch ");
+ print(buf, PANIC_FG);
+ print("\n", white());
+ }
+
+ str_copy(buf, "CR3: 0x");
+ str_from_hex(hex, cr3);
+ str_append(buf, hex);
print(buf, white());
print("\n\n", white());
- print("System halted.", white());
+ print("System halted, \nYour computer will now restart...", PANIC_FG);
+
+ delay(50);
+ panic_reboot();
// HALT
- while(1) {
- __asm__ volatile("cli; hlt");
- }
+ //while(1) {
+ // __asm__ volatile("cli; hlt");
+ //}
}
diff --git a/src/kernel/arch/x86_64/exceptions/panic.h b/src/kernel/arch/x86_64/exceptions/panic.h
index 526d0b2..2d66a5e 100644
--- a/src/kernel/arch/x86_64/exceptions/panic.h
+++ b/src/kernel/arch/x86_64/exceptions/panic.h
@@ -4,6 +4,8 @@
#include
#include
+#define PANIC_SHOWSWITCH 1
+
// Kernel panic
__attribute__((noreturn)) void panic(const char *message);
__attribute__((noreturn)) void panic_exception(cpu_state_t *state, const char *message);
diff --git a/src/kernel/arch/x86_64/exceptions/timer.c b/src/kernel/arch/x86_64/exceptions/timer.c
index d0a118e..1aa14c4 100644
--- a/src/kernel/arch/x86_64/exceptions/timer.c
+++ b/src/kernel/arch/x86_64/exceptions/timer.c
@@ -6,6 +6,7 @@
#include
#include
#include
+//#include
#include
// using PIT (8254)
@@ -17,12 +18,13 @@ static timer_callback_t timer_callbacks[MAX_TIMER_CALLBACKS];
static int callback_count = 0;
#if ENABLE_ULIME
-extern scheduler_t* scheduler; // Zugriff auf globale Variable
+extern scheduler_t* scheduler;
+extern mt_t* mt;
#endif
void timer_handler(cpu_state_t* state)
{
- (void)state;
+ //(void)state;
if (!timer_initialized) {
return;
@@ -36,12 +38,10 @@ void timer_handler(cpu_state_t* state)
}
}
- //banner_tick();
-
// call schedule
#if ENABLE_ULIME
- if (scheduler) {
- scheduler_tick(scheduler);
+ if (mt) {
+ mt_preempt(mt, state); // real preemptive switch
}
#endif
}
@@ -81,7 +81,7 @@ void timer_init(u32 frequency)
timer_ticks = 0;
timer_initialized = 1;
- // Enable interrupts to start timer
+ // enable interrupts to start timer
__asm__ volatile("sti");
//TODO:
diff --git a/src/kernel/arch/x86_64/exceptions/timer.h b/src/kernel/arch/x86_64/exceptions/timer.h
index 24cde7b..ab98be8 100644
--- a/src/kernel/arch/x86_64/exceptions/timer.h
+++ b/src/kernel/arch/x86_64/exceptions/timer.h
@@ -2,6 +2,7 @@
#define TIMER_H
#include
+#include
#define TIMER_FREQUENCY 1000 // 1000 Hz = 1ms Ticks
#define MAX_TIMER_CALLBACKS 8
diff --git a/src/kernel/arch/x86_64/gdt/gdt.c b/src/kernel/arch/x86_64/gdt/gdt.c
index c79e83d..b3b21e6 100644
--- a/src/kernel/arch/x86_64/gdt/gdt.c
+++ b/src/kernel/arch/x86_64/gdt/gdt.c
@@ -8,10 +8,8 @@
static gdt_entry_t gdt[GDT_ENTRIES];
static tss_t tss;
static gdt_ptr_t gdt_ptr;
-
-// Kernel stack for syscalls/interrupts (16KB, 16-byte aligned)
-static u8 kernel_stack[16384] __attribute__((aligned(16)));
-
+static u8 kernel_stack[16384] __attribute__((aligned(16))); // 16KB
+static u8 df_stack[8192] __attribute__((aligned(16))); // this time via ist1
// TODO:
// move tss to kernel/arch/x64/tss/tss.c
@@ -92,6 +90,7 @@ void tss_init(void)
log("[TSS]", "init (Task State Segment)\n", d);
memset(&tss, 0, sizeof(tss_t));
tss.rsp0 = (u64)kernel_stack + sizeof(kernel_stack);
+ tss.ist1 = (u64)df_stack + sizeof(df_stack);
tss.iopb_offset = sizeof(tss_t);
}
diff --git a/src/kernel/arch/x86_64/idt/idt.c b/src/kernel/arch/x86_64/idt/idt.c
index 77c6735..1c40a49 100644
--- a/src/kernel/arch/x86_64/idt/idt.c
+++ b/src/kernel/arch/x86_64/idt/idt.c
@@ -23,6 +23,12 @@ void idt_set_gate(u8 num, u64 handler, u8 flags)
idt[num].reserved = 0;
}
+void idt_set_gate_ist(u8 num, u64 handler, u8 flags, u8 ist)
+{
+ idt_set_gate(num, handler, flags);
+ idt[num].ist = ist & 0x07;
+}
+
void idt_load(void)
{
idt_ptr.limit = sizeof(idt) - 1;
diff --git a/src/kernel/arch/x86_64/idt/idt.h b/src/kernel/arch/x86_64/idt/idt.h
index 92f28a8..2aeb967 100644
--- a/src/kernel/arch/x86_64/idt/idt.h
+++ b/src/kernel/arch/x86_64/idt/idt.h
@@ -46,9 +46,10 @@ typedef struct {
u64 rip, cs, rflags, rsp, ss;
} __attribute__((packed)) cpu_state_t;
-// Funktionen
+// funktions
void idt_init(void);
void idt_set_gate(u8 num, u64 handler, u8 flags);
+void idt_set_gate_ist(u8 num, u64 handler, u8 flags, u8 ist);
void idt_load(void);
#endif
diff --git a/src/kernel/arch/x86_64/syscall_entry.asm b/src/kernel/arch/x86_64/syscall_entry.asm
index 79b0c60..5a594ce 100644
--- a/src/kernel/arch/x86_64/syscall_entry.asm
+++ b/src/kernel/arch/x86_64/syscall_entry.asm
@@ -1,20 +1,40 @@
bits 64
global syscall_entry
-extern syscall_handler
-
+global user_rsp
+global user_rcx
+global user_r11
+global user_cr3
+global user_rbx
+global user_rbp
+global user_r12
+global user_r13
+global user_r14
+global user_r15
+extern syscall_handler
syscall_entry:
- ; save user stack pointer
mov [rel user_rsp], rsp
+ mov [rel user_rcx], rcx
+ mov [rel user_r11], r11
+
+ push rax
+ mov rax, cr3
+ mov [rel user_cr3], rax
+ pop rax
+
+ mov [rel user_rbx], rbx
+ mov [rel user_rbp], rbp
+ mov [rel user_r12], r12
+ mov [rel user_r13], r13
+ mov [rel user_r14], r14
+ mov [rel user_r15], r15
- ; switch to kernel stack
- mov rsp, [rel kernel_stack_top]
+ lea rsp, [rel kernel_stack_top]
- ; save registers on kernel stack
- push r11 ; rflags
- push rcx ; user rip
+ push r11
+ push rcx
push rbx
push rbp
push r12
@@ -22,24 +42,15 @@ syscall_entry:
push r14
push r15
+ mov rcx, rdx ; arg3
+ mov rdx, rsi ; arg2
+ mov rsi, rdi ; arg1
+ mov rdi, rax ; syscall_num
- mov r10, rdi ; save arg1
- mov rdi, rax ; syscall number -> first param
- mov rsi, r10 ; arg1 -> second param
- ; rdx already has arg2
- mov rcx, rdx ; arg3
- ; r8 already correct
- mov r10, r8
- mov r8, r10 ; arg4
- ; r9 already correct
-
-
-
- call syscall_handler ; from C
+ call syscall_handler
; result is in rax
- ; restore registers
pop r15
pop r14
pop r13
@@ -49,20 +60,24 @@ syscall_entry:
pop rcx ; user rip
pop r11 ; rflags
- ; restore user stack
mov rsp, [rel user_rsp]
-
- ; return to userspace with SYSRET
- ; rcx = return address, r11 = rflags
- o64 sysret
+ o64 sysret ; RIP = rcx, RFLAGS = r11, CPL → 3
section .data
align 16
user_rsp: dq 0
-
+user_rcx: dq 0
+user_r11: dq 0
+user_cr3: dq 0
+user_rbx: dq 0
+user_rbp: dq 0
+user_r12: dq 0
+user_r13: dq 0
+user_r14: dq 0
+user_r15: dq 0
section .bss
align 16
kernel_stack_bottom:
- resb 16384 ; 16KB kernel stack
+ resb 16384
kernel_stack_top:
diff --git a/src/kernel/console/console.c b/src/kernel/console/console.c
deleted file mode 100644
index 11e2479..0000000
--- a/src/kernel/console/console.c
+++ /dev/null
@@ -1,407 +0,0 @@
-#include "console.h"
-#include "functions.h"
-
-static char input_buffer[MAX_INPUT_LEN];
-static int input_pos = 0;
-char cwd[MAX_PATH_LEN] = "/";
-//int is_login_active = 0;
-
-//----------------------------------
-// ! IMPORTANT FOR NEW COMMANDS !
-int cmd_count = 30;
-
-console_cmd_t commands[MAX_CMDS] = {
- CMDENTRY(cmd_echo, "echo", "prints text to console", "echo [text]"),
- CMDENTRY(cmd_clear, "clear", "clears the screen", "clear [color]"),
- CMDENTRY(cmd_help, "help", "displays all available commands", "help [command]"),
- CMDENTRY(cmd_fsize, "scale", "change screen size", "scale [2-4]"),
- CMDENTRY(cmd_modules, "lsmod", "list loaded modules", "lsmod"),
- CMDENTRY(cmd_meminfo, "meminfo", "displays memory infos", "meminfo"),
- //CMDENTRY(cmd_memtest, "memtest", "Memory test suite", "memtest"),
- CMDENTRY(cmd_sysinfo, "dofetch", "system fetch", "dofetch"),
- CMDENTRY(cmd_cal, "calendar", "displays current date & time", "calendar"),
- CMDENTRY(cmd_date, "date", "displays current date", "date"),
- CMDENTRY(cmd_uptime, "uptime", "System uptime", "uptime"),
- CMDENTRY(cmd_time, "time", "displays current time", "time"),
- CMDENTRY(cmd_reboot, "reboot", "Reboot the system", "reboot"),
- CMDENTRY(cmd_shutdown, "shutdown", "Shutsdown the system", "shutdown"),
- CMDENTRY(cmd_shutdown, "shut", "Shutsdown the system", "shut"), // alias
- CMDENTRY(cmd_cat, "cat", "show file", "cat "),
- CMDENTRY(cmd_ls, "ls", "list directory contents", "ls [path]"),
- CMDENTRY(cmd_cd, "cd", "Change directory", "cd [path]"),
- CMDENTRY(cmd_tree, "tree", "shows every folder, file * content", "tree"),
- CMDENTRY(cmd_mkdir, "mkdir", "create directory", "mkdir "),
- CMDENTRY(cmd_font, "font", "change console font", "font [0-1]"),
- CMDENTRY(cmd_cyrillc_sumbol, "cyrillc-sumbol", "print cyrillic alphabet test", "cyrillc-sumbol"),
- CMDENTRY(cmd_latin_sumbol, "latin-sumbol", "print latin alphabet test", "latin-sumbol"),
- CMDENTRY(cmd_all_sumbol, "all-sumbol", "print latin and cyrillic alphabets", "all-sumbol"),
- CMDENTRY(cmd_keymap, "loadkeys", "change keyboard layout", "loadkeys [keymap]"),
- CMDENTRY(cmd_whoami, "whoami", "display current user", "whoami"),
- CMDENTRY(cmd_source, "source", "reload configuration", "source console"),
- CMDENTRY(cmd_touch, "touch", "create empty file", "touch "),
- CMDENTRY(cmd_view, "view", "view BMP image", "view "),
- CMDENTRY(cmd_ps, "ps", "displays processes", "ps"),
- CMDENTRY(cmd_slot, "slot", "switch kernel slots", "slot "),
-};
-
-//----------------------------------
-
-//module---------------------------
-static int console_module_init(void) {
- // console already initialized in main
- log("[CONSOLE]", "Load CONSOLE module...\n", d);
- return 0;
-}
-
-static void console_module_fini(void) {
- //
-}
-
-driver_module console_module = (driver_module) {
- .name = "console",
- .mount = "/dev/console",
- .version = VERSION_NUM(0, 1, 2, 0), //should print like [v0.1.0.0]
- .init = console_module_init,
- .fini = console_module_fini,
- .open = NULL, // later for fs
- .read = NULL, // later for fs
- .write = NULL, // later for fs
-};
-
-//---------------------------------
-
-
-//extern void prompt_config_init();
-void console_init(void)
-{
- input_pos = 0;
- input_buffer[0] = '\0';
- char buf[64];
-
- log("[CONSOLE]","starting console...\n", d);
-
- //sconsole_theme(THEME_FLU);
- f_setcontext(FONT_8X8);
- clear(CONSOLESCREEN_BG_COLOR);
- font_scale = 2;
-
- buf[0] = '\0'; //reset
- //reset_cursor();
- /*
- //module_register_driver(&console_module);
-
- if (cursor_x == 0 && cursor_y == 0) {
- clear(CONSOLESCREEN_COLOR);
- reset_cursor();
- }
- */
-
- cursor_x = 0;
- cursor_y = 0;
-
- //is_login_active = 1;
- //if (!login_authenticate()) {
- // Login failed - should never reach here due to lock
- //panic("Login authentication failed");
- //}
- //is_login_active = 0;
-
-
- //create config files for console:
- /*fs_mkdir("/.config/ekmsh");
- fs_mkdir("/.config/ekmsh/promts");
- fs_open("/.config/ekmsh/promts/promt.conf", O_CREAT | O_WRONLY);*/
-
- console_config_init();
-
- clear(CONSOLESCREEN_BG_COLOR);
- banner_init();
-
- // Initialize console window
- console_window_init();
- cursor_();
-
- //string("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+#,.-;:_'*`?=!\\\"$%&/()^°", GFX_WHITE);
- // font testing
- shell_print_prompt();
-
- //console_execute("view /images/logo.bmp");
- cursor_draw();
-
- console_run();
-
-}
-
-void console_run(void)
-{
- // main console loop will be called from keyboard handler
- // this function exists for future expansion like syscalls maybe for a app like a code editor which needs a console
- // actually idk why i created this xd
- while (1) {
- if (keyboard_has_key()) {
- key_event_t event;
- if (keyboard_get_event(&event)) {
- if (event.pressed) {
- console_handle_key_event(&event);
- }
- }
- }
- // Let CPU rest
- __asm__ volatile("hlt");
- }
-}
-
-static void console_redraw_input_line(void) {
- u32 saved_y = cursor_y;
- u32 char_width = fm_get_char_width() * font_scale;
- u32 char_height = fm_get_char_height() * font_scale;
- u32 start_x = cursor_x;
- u32 clear_width = get_fb_width() - cursor_x;
-
- draw_rect(cursor_x, cursor_y, clear_width, char_height, CONSOLESCREEN_BG_COLOR);
-
- for (int i = input_pos; input_buffer[i] != '\0'; i++) {
- putchar(input_buffer[i], GFX_WHITE);
- }
-
- cursor_x = start_x;
- cursor_y = saved_y;
- cursor_draw();
-}
-
-void console_handle_key_event(key_event_t *event) {
- cursor_c();
-
- // Arrow keys
- if (event->keycode == KEY_ARROW_LEFT) {
- if (input_pos > 0) {
- input_pos--;
- u32 char_width = 8 * font_scale;
- cursor_x -= char_width;
- cursor_draw();
- }
- return;
- }
-
- if (event->keycode == KEY_ARROW_RIGHT) {
- if (input_pos < str_len(input_buffer)) {
- input_pos++;
- u32 char_width = 8 * font_scale;
- cursor_x += char_width;
- cursor_draw();
- }
- return;
- }
-
- if (event->keycode == KEY_HOME) {
- u32 char_width = 8 * font_scale;
- cursor_x -= input_pos * char_width;
- input_pos = 0;
- cursor_draw();
- return;
- }
-
- if (event->keycode == KEY_END) {
- int len = str_len(input_buffer);
- u32 char_width = 8 * font_scale;
- cursor_x += (len - input_pos) * char_width;
- input_pos = len;
- cursor_draw();
- return;
- }
-
- if (event->keycode == KEY_DELETE) {
- int len = str_len(input_buffer);
- if (input_pos < len) {
- for (int i = input_pos; i < len; i++) {
- input_buffer[i] = input_buffer[i + 1];
- }
- console_redraw_input_line();
- }
- return;
- }
-
- if ((event->modifiers & KEY_CTRL_MASK) && (event->keycode == 's' || event->keycode == 'S')) {
- // This will be handled by edit command
- return;
- }
-
- char c = (char)(event->keycode & 0xFF);
- console_handle_key(c);
-
- cursor_reset_blink();
- cursor_draw();
-}
-
-void console_handle_key(char c)
-{
- cursor_c();
- if (c == '\n') {
- // execute command when enter
- putchar('\n', GFX_WHITE);
-
- if (input_pos > 0 || str_len(input_buffer) > 0) {
- input_buffer[str_len(input_buffer)] = '\0';
-
- // check for && and use chained execution
- int has_chain = 0;
- int len = str_len(input_buffer);
- for (int i = 0; i < len - 1; i++) {
- if (input_buffer[i] == '&' && input_buffer[i+1] == '&') {
- has_chain = 1;
- break;
- }
- }
-
- // prints every command to the console
- printf("%s\n", input_buffer);
-
- if (has_chain) {
- parse_and_execute_chained(input_buffer);
- } else {
- console_execute(input_buffer);
- }
-
-
- input_pos = 0;
- input_buffer[0] = '\0';
- }
-
- cursor_reset_blink();
- //cursor_draw();
- shell_print_prompt();
- return;
- }
-
- if (c == '\r') {
- putchar('\n', GFX_WHITE);
- input_buffer[input_pos++] = '\n';
- cursor_draw();
- return;
- }
-
- if (c == '\b') {
- if (input_pos > 0) {
- int len = str_len(input_buffer);
- for (int i = input_pos - 1; i < len; i++) {
- input_buffer[i] = input_buffer[i + 1];
- }
- input_pos--;
- //input_buffer[input_pos] = '\0';
-
- // just move the cursor back then print space, draw rext, and move back again
- u32 char_width = fm_get_char_width() * font_scale;
- u32 char_height = fm_get_char_height() * font_scale;
- /*if (cursor_x >= char_width) {
- cursor_x -= char_width;
- putchar(' ', GFX_WHITE);
- cursor_x -= char_width;
-
- draw_rect(cursor_x, cursor_y, char_width, 8 * font_scale, CONSOLESCREEN_BG_COLOR);
- }*/
- cursor_x -= char_width;
- draw_rect(cursor_x, cursor_y, char_width, char_height, CONSOLESCREEN_BG_COLOR);
- console_redraw_input_line();
- }
- cursor_reset_blink();
- cursor_draw();
- return;
- }
-
- console_window_check_scroll();
-
- // add character to buffer
- if (input_pos < MAX_INPUT_LEN - 1) {
- int len = str_len(input_buffer);
-
- for (int i = len; i > input_pos; i--) {
- input_buffer[i] = input_buffer[i - 1];
- }
-
- input_buffer[input_pos] = c;
- input_buffer[len + 1] = '\0';
-
- putchar(c, GFX_WHITE);
- input_pos++;
-
- if (input_buffer[input_pos] != '\0') {
- u32 old_x = cursor_x;
- u32 old_y = cursor_y;
- for (int i = input_pos; input_buffer[i] != '\0'; i++) {
- putchar(input_buffer[i], GFX_WHITE);
- }
- cursor_x = old_x;
- cursor_y = old_y;
- }
- }
- cursor_reset_blink();
- cursor_draw();
-}
-
-void console_execute(const char *input)
-{
- //TODO:
- // OF UNKOWN BUGS THE SYSTEM CRASHES WHEN YOU ENTER A WRONG COMMAND
- // not anymore :)
-
- // skip leading spaces
- while (*input == ' ') input++;
-
- if (*input == '\0') return;
-
- // find command name end
- const char *end = input;
- while (*end && *end != ' ') end++;
-
- // extract it
- char cmd_name[64];
- int len = end - input;
- if (len >= 64) len = 63;
-
- for (int i = 0; i < len; i++) {
- cmd_name[i] = input[i];
- }
- cmd_name[len] = '\0';
-
- // find arguments
- const char *args = end;
- while (*args == ' ') args++;
-
- console_cmd_t *cmd = console_find_cmd(cmd_name);
- if (cmd) {
- cmd->func(args);
-
- banner_force_update();
-
- // for PC_NAME and USER_NAME
- uci_reload();
- } else {
- print(CONSOLE_NAME, WRONG_COMMAND_CL);
- print(": command not found:", WRONG_COMMAND_CL);
- print(cmd_name, WRONG_COMMAND_CL);
- }
-}
-
-console_cmd_t* console_find_cmd(const char *name)
-{
- for (int i = 0; i < cmd_count; i++) {
- // simple string comparison
- const char *a = name;
- const char *b = commands[i].name;
- int match = 1;
-
- while (*a && *b) {
- if (*a != *b) {
- match = 0;
- break;
- }
- a++;
- b++;
- }
-
- if (match && *a == '\0' && *b == '\0') {
- return &commands[i];
- }
- }
- return NULL;
-}
diff --git a/src/kernel/console/console.h b/src/kernel/console/console.h
deleted file mode 100644
index 26b253a..0000000
--- a/src/kernel/console/console.h
+++ /dev/null
@@ -1,81 +0,0 @@
-#ifndef CONSOLE_H
-#define CONSOLE_H
-
-#include
-#include
-#include
-#include
-#include
-#include "graph/uno.h"
-#include "graph/dos.h"
-#include
-#include
-#include
-#include
-#include
-//#include "login/login.h"
-#include
-#include
-#include
-
-#include
-
-#include
-extern driver_module console_module;
-
-#define MAX_INPUT_LEN 256
-#define MAX_PATH_LEN 256
-#define MAX_CMDS 32
-#define MAX_CHAINED_CMDS 8
-
-#define CONSOLE_APP_NAME "console"
-#define CONSOLE_NAME "ekmsh" // emex-kernelmode-shell
-#define WRONG_COMMAND_CL GFX_RED
-
-// function header macro for command declarations it should be easier to port it to future syscalls
-#define FHDR(name) void name(const char* s)
-
-typedef struct {
- void (*func)(const char*);
- const char *name;
- const char *description;
- const char *usage;
-} console_cmd_t;
-
-// for the 'help '
-#define CMDENTRY(func, name, desc, usage) { func, name, desc, usage }
-
-extern char cwd[];
-//for help.c
-extern console_cmd_t commands[];
-extern int cmd_count;
-
-void console_init(void);
-void console_run(void);
-
-void console_handle_key(char c);
-void console_handle_key_event(key_event_t *event);
-void console_execute(const char *input);
-
-void shell_clear_screen(u32 color);
-void shell_print_prompt(void);
-void shell_redraw_input(void);
-
-void cursor_(void);
-void cursor_draw(void);
-void cursor_c(void);
-void cursor_redraw(void);
-void cursor_enable(void);
-void cursor_disable(void);
-void cursor_reset_blink(void);
-
-
-void console_config_init(void); // config for promt in /.config/ekmsh/promts/promt.conf
-
-
-console_cmd_t* console_find_cmd(const char *name);
-
-int parse_color(const char *color_str, u32 *out_color);
-void parse_and_execute_chained(const char *input);
-
-#endif
diff --git a/src/kernel/console/cursor.c b/src/kernel/console/cursor.c
deleted file mode 100644
index bb98a21..0000000
--- a/src/kernel/console/cursor.c
+++ /dev/null
@@ -1,86 +0,0 @@
-#include "console.h"
-#include
-#include
-
-static int cursor_visible = 1;
-static u32 cursor_blink_counter = 0;
-static int cursor_enabled = 1;
-
-//todo:
-// move to doccr.h with custom cursor bitmap/ character (e.g: A,B, _, █)
-#define CURSOR_BLINK_RATE 300 // blinking
-//------------------------
-// "_"
-#define CURSOR_WIDTH_RATIO 6
-#define CURSOR_HEIGHT_RATIO 1
-//------------------------
-// "█"
-//#define CURSOR_WIDTH_RATIO 5
-//#define CURSOR_HEIGHT_RATIO 8
-//------------------------
-// "|"
-//#define CURSOR_WIDTH_RATIO 1
-///#define CURSOR_HEIGHT_RATIO 8
-//------------------------
-static void cursor_timer_callback() {
- if (!cursor_enabled) return;
-
- cursor_blink_counter++;
- if (cursor_blink_counter >= CURSOR_BLINK_RATE) {
- cursor_blink_counter = 0;
- cursor_visible = !cursor_visible;
- cursor_redraw();
- }
-}
-
-void cursor_(void) {
- cursor_visible = 1;
- cursor_blink_counter = 0;
- cursor_enabled = 1;
- timer_register_callback(cursor_timer_callback);
-}
-
-void cursor_draw(void) {
- if (!cursor_visible || !cursor_enabled) return;
-
- u32 char_width = fm_get_char_width() * font_scale;
- u32 char_height = fm_get_char_height() * font_scale;
-
- u32 cursor_width = (char_width * CURSOR_WIDTH_RATIO) / 8;
- u32 cursor_height = (char_height * CURSOR_HEIGHT_RATIO) / 8;
- u32 cursor_y_pos = cursor_y + char_height - cursor_height;
-
- draw_rect(cursor_x, cursor_y_pos, cursor_width, cursor_height, CONSOLESCREEN_COLOR);
-}
-
-void cursor_c(void) {
- u32 char_width = fm_get_char_width() * font_scale;
- u32 char_height = fm_get_char_height() * font_scale;
-
- u32 cursor_width = (char_width * CURSOR_WIDTH_RATIO) / 8;
- u32 cursor_height = (char_height * CURSOR_HEIGHT_RATIO) / 8;
- u32 cursor_y_pos = cursor_y + char_height - cursor_height;
-
- draw_rect(cursor_x, cursor_y_pos, cursor_width, cursor_height, CONSOLESCREEN_BG_COLOR);
-}
-
-void cursor_redraw(void) {
- cursor_c();
- cursor_draw();
-}
-
-void cursor_enable(void) {
- cursor_enabled = 1;
- cursor_visible = 1;
- cursor_blink_counter = 0;
-}
-
-void cursor_disable(void) {
- cursor_c();
- cursor_enabled = 0;
-}
-
-void cursor_reset_blink(void) {
- cursor_blink_counter = 0;
- cursor_visible = 1;
-}
diff --git a/src/kernel/console/functions.h b/src/kernel/console/functions.h
deleted file mode 100644
index 1c2a980..0000000
--- a/src/kernel/console/functions.h
+++ /dev/null
@@ -1,61 +0,0 @@
-#pragma once
-
-#include "console.h"
-
-// text.c
-FHDR(cmd_echo);
-FHDR(cmd_clear);
-FHDR(cmd_font);
-FHDR(cmd_fsize);
-FHDR(cmd_cyrillc_sumbol);
-FHDR(cmd_latin_sumbol);
-FHDR(cmd_all_sumbol);
-
-// help.c
-FHDR(cmd_help);
-
-// system.c
-FHDR(cmd_modules);
-FHDR(cmd_meminfo);
-FHDR(cmd_memtest);
-FHDR(cmd_sysinfo);
-//FHDR(cmd_usb);
-//FHDR(cmd_usbinfo);
-
-//cmos.c
-FHDR(cmd_cal);
-FHDR(cmd_date);
-FHDR(cmd_time);
-FHDR(cmd_uptime);
-
-// File System
-FHDR(cmd_tree);
-FHDR(cmd_cat);
-FHDR(cmd_ls);
-FHDR(cmd_cd);
-FHDR(cmd_mkdir);
-FHDR(cmd_touch);
-
-// whoami.c
-FHDR(cmd_whoami);
-
-// source.c
-FHDR(cmd_source);
-
-// keymap.c
-FHDR(cmd_keymap);
-
-// poweroff.c
-//FHDR(cmd_poweroff);
-FHDR(cmd_reboot);
-FHDR(cmd_shutdown);
-
-
-// view.c
-FHDR(cmd_view);
-
-// proc
-FHDR(cmd_ps);
-
-// slots.c
-FHDR(cmd_slot);
diff --git a/src/kernel/console/functions/cat.c b/src/kernel/console/functions/cat.c
deleted file mode 100644
index 01d8676..0000000
--- a/src/kernel/console/functions/cat.c
+++ /dev/null
@@ -1,46 +0,0 @@
-#include
-#include
-
-extern char cwd[];
-
-FHDR(cmd_cat) {
- (void)s;
- if (!s || *s == '\0') {
- print("error: no file specified\n", GFX_RED);
- return;
- }
-
- char path[MAX_PATH_LEN];
-
- if (s[0] == '/') {
- str_copy(path, s);
- } else {
- str_copy(path, cwd);
-
- if (cwd[str_len(cwd) - 1] != '/') {
- str_append(path, "/");
- }
-
- str_append(path, s);
- }
-
- // opens in read only (RDONLY)
- int fd = fs_open(path, O_RDONLY);
- if (fd < 0) {
- print("error: cannot open file\n", GFX_RED);
- return;
- }
-
- char buf[256];
- ssize_t bytes;
-
- while ((bytes = fs_read(fd, buf, sizeof(buf) - 1)) > 0) {
- buf[bytes] = '\0';
- print(buf, GFX_WHITE);
- }
-
- fs_close(fd);
-
- // buf[0] = '\0';
- print("\n", GFX_WHITE);
-}
diff --git a/src/kernel/console/functions/cd.c b/src/kernel/console/functions/cd.c
deleted file mode 100644
index 678c620..0000000
--- a/src/kernel/console/functions/cd.c
+++ /dev/null
@@ -1,66 +0,0 @@
-#include
-#include
-
-extern char cwd[];
-
-FHDR(cmd_cd) {
- if (!s || *s == '\0') {
- // cd with no arguments goes to root
- str_copy(cwd, "/");
- return;
- }
-
- char new_path[MAX_PATH_LEN];
-
- if (s[0] == '/') {
- str_copy(new_path, s);
- } else {
- str_copy(new_path, cwd);
-
- if (cwd[str_len(cwd) - 1] != '/') {
- str_append(new_path, "/");
- }
-
- str_append(new_path, s);
- }
-
- if (str_equals(s, "..")) {
- int len = str_len(cwd);
- if (len > 1 && cwd[len - 1] == '/') {
- cwd[len - 1] = '\0';
- len--;
- }
- for (int i = len - 1; i >= 0; i--) {
- if (cwd[i] == '/') {
- if (i == 0) {
- str_copy(cwd, "/");
- } else {
- cwd[i] = '\0';
- }
- return;
- }
- }
- return;
- }
-
- // if directory exists
- fs_node *dir = fs_resolve(new_path);
- if (!dir) {
- print("error: directory not found\n", GFX_RED);
- return;
- }
-
- if (dir->type != FS_DIR) {
- print("error: not a directory\n", GFX_RED);
- return;
- }
-
- // updates cwd
- str_copy(cwd, new_path);
-
- // when cwd ends with / (except for the root)
- int len = str_len(cwd);
- if (len > 1 && cwd[len - 1] != '/') {
- str_append(cwd, "/");
- }
-}
diff --git a/src/kernel/console/functions/cmos.c b/src/kernel/console/functions/cmos.c
deleted file mode 100644
index fa7180e..0000000
--- a/src/kernel/console/functions/cmos.c
+++ /dev/null
@@ -1,31 +0,0 @@
-#include
-#include
-#include
-
-FHDR(cmd_cal) {
- (void)s;
-
- GetCMOSDate();
- print(" ", GFX_WHITE);
- GetCMOSTime();
-
-}
-
-FHDR(cmd_date) {
- (void)s;
-
- GetCMOSDate();
-}
-
-FHDR(cmd_time) {
- (void)s;
-
- GetCMOSTime();
-}
-
-FHDR(cmd_uptime) {
- (void)s;
-
- print("Uptime: ", GFX_WHITE);
- timer_print_uptime();
-}
diff --git a/src/kernel/console/functions/help.c b/src/kernel/console/functions/help.c
deleted file mode 100644
index 39c3ce7..0000000
--- a/src/kernel/console/functions/help.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#include
-
-#define GEN "[GENERIC]"
-#define FS "[FILESYSTEM]"
-#define GUI "[GRAPHICS]"
-#define PADDING 12
-
-FHDR(cmd_help)
-{
- extern console_cmd_t commands[];
- extern int cmd_count;
-
- if (*s == '\0') {
- // these are COMMON commands, soon i will split all comands
- print("[COMMON]\n", GFX_YELLOW);
-
- for (int i = 0; i < cmd_count; i++) {
- char buf[128];
- str_copy(buf, " ");
- str_append(buf, commands[i].name);
-
- int name_len = str_len(commands[i].name);
- int padding = PADDING - name_len;
- for (int p = 0; p < padding && p < 14; p++) {
- str_append(buf, " ");
- }
-
- str_append(buf, "- ");
- str_append(buf, commands[i].description);
- str_append(buf, "\n");
- print(buf, GFX_WHITE);
- }
-
- print("Type 'help ' for details", GFX_GRAY_50);
- } else {
- // specific commands
- const char *p = s;
- while (*p == ' ') p++;
-
- console_cmd_t *cmd = console_find_cmd(p);
- if (cmd) {
- char buf[128];
-
- str_copy(buf, "\n");
- str_append(buf, cmd->description);
- print(buf, GFX_WHITE);
-
- str_copy(buf, "\nUsage: ");
- str_append(buf, cmd->usage);
- print(buf, GFX_YELLOW);
- print("\n", GFX_WHITE);
- } else {
- print("\nCommand not found", GFX_RED);
- }
- }
-}
diff --git a/src/kernel/console/functions/keymap.c b/src/kernel/console/functions/keymap.c
deleted file mode 100644
index a64d676..0000000
--- a/src/kernel/console/functions/keymap.c
+++ /dev/null
@@ -1,40 +0,0 @@
-#include
-#include
-
-FHDR(cmd_keymap) {
- if (!s || *s == '\0') {
- // Show current keymap
- print("you use keymap: ", GFX_WHITE);
- print(keymap_get_current_name(), GFX_WHITE);
- print("\nuse: keymap \n", GFX_WHITE);
- print("\nnote that only DE & US are correctly supported by now.\n", GFX_WHITE);
- return;
- }
-
- // parse keymap name
- const char *p = s;
- while (*p == ' ') p++;
-
- char keymap_name[16];
- int i = 0;
- while (*p && *p != ' ' && *p != '\n' && i < 15) {
- keymap_name[i++] = *p++;
- }
- keymap_name[i] = '\0';
-
- // convert to uppercase
- str_to_upper(keymap_name);
-
- // trys to set the keymap
- if (keymap_set(keymap_name) != 0) {
- print("error: keymap '", GFX_RED);
- print(keymap_name, GFX_RED);
- print("' not found\n", GFX_RED);
- print("try: US, DE\n", GFX_RED);
- return;
- }
-
- print("keymap changed to: ", GFX_WHITE);
- print(keymap_name, GFX_WHITE);
- print("\n", GFX_WHITE);
-}
diff --git a/src/kernel/console/functions/ls.c b/src/kernel/console/functions/ls.c
deleted file mode 100644
index 0442814..0000000
--- a/src/kernel/console/functions/ls.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include
-#include
-
-extern char cwd[];
-
-FHDR(cmd_ls) {
- const char *path = s;
-
- // default to cwd if no path given
- if (!s || *s == '\0') {
- path = cwd;
- }
-
- // resolve the directory
- fs_node *dir = fs_resolve(path);
- if (!dir) {
- print("error: directory not found\n", GFX_RED);
- print("use: \"ls /boot\" or \"ls /dev\" or any kind of dir.\n", GFX_RED);
- return;
- }
-
- if (dir->type != FS_DIR) {
- print("error: not a directory\n", GFX_RED);
- return;
- }
-
- // list all children
- fs_node *child = dir->children;
- if (!child) {
- print("this folder is empty \n", GFX_GRAY_50);
- return;
- }
-
- int count = 0;
- while (child) {
- // different colors for different types
- u32 color = GFX_WHITE;
- const char *type_str = "";
-
- if (child->type == FS_DIR) {
- color = GFX_BLUE;
- type_str = "/";
- color = GFX_WHITE;
- } else if (child->type == FS_DEV) {
- color = GFX_WHITE;
- type_str = "*";
- color = GFX_WHITE;
- }
-
- print(child->name, color);
- print(type_str, color);
-
- // show size for files
- /*if (child->type == FS_FILE && child->size > 0) {
- char buf[32];
- str_copy(buf, " | ");
- str_append_uint(buf, (u32)child->size);
- str_append(buf, " bytes");
- print(buf, GFX_GRAY_50);
- }*/
-
- print(" ", GFX_WHITE);
- count++;
- if (count % 6 == 0) {
- print("\n", GFX_WHITE);
- }
-
- child = child->next;
- }
-
- if (count % 6 != 0) {
- print("\n", GFX_WHITE);
- }
-}
diff --git a/src/kernel/console/functions/mkdir.c b/src/kernel/console/functions/mkdir.c
deleted file mode 100644
index bc5240f..0000000
--- a/src/kernel/console/functions/mkdir.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include
-#include
-
-extern char cwd[];
-
-FHDR(cmd_mkdir) {
- if (!s || *s == '\0') {
- print("usage: mkdir \n", GFX_RED);
- return;
- }
-
- char full_path[MAX_PATH_LEN];
-
- // Handle absolute vs relative paths
- if (s[0] == '/') {
- str_copy(full_path, s);
- } else {
- str_copy(full_path, cwd);
-
- if (cwd[str_len(cwd) - 1] != '/') {
- str_append(full_path, "/");
- }
-
- str_append(full_path, s);
- }
-
- // Create the directory
- if (fs_mkdir(full_path) != 0) {
- print("error: could not create directory\n", GFX_RED);
- return;
- }
-
- print("directory created: ", GFX_GREEN);
- print(full_path, GFX_WHITE);
- print("\n", GFX_WHITE);
-}
diff --git a/src/kernel/console/functions/poweroff.c b/src/kernel/console/functions/poweroff.c
deleted file mode 100644
index ed3f12c..0000000
--- a/src/kernel/console/functions/poweroff.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include
-#include
-
-FHDR(cmd_reboot)
-{
- (void)s;
-
- cursor_disable();
- print("Restarting system...\n", GFX_YELLOW);
-
- for (volatile int i = 0; i < 5000000; i++)
- __asm__ volatile("nop");
-
- cpu_poweroff(POWEROFF_REBOOT);
-}
-
-FHDR(cmd_shutdown)
-{
- (void)s;
-
- cursor_disable();
- print("Shutting down system...\n", GFX_YELLOW);
-
- for (volatile int i = 0; i < 5000000; i++)
- __asm__ volatile("nop");
-
- cpu_poweroff(POWEROFF_SHUTDOWN);
-}
diff --git a/src/kernel/console/functions/proc.c b/src/kernel/console/functions/proc.c
deleted file mode 100644
index a33cf76..0000000
--- a/src/kernel/console/functions/proc.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include
-
-FHDR(cmd_ps)
-{
-#if ENABLE_ULIME && RUNTESTS
- if (!proc_mgr)
- {
- print("proc_mgr not initialized\n", white());
- return;
- }
-
- proc_list_procs(proc_mgr);
-#endif
-}
diff --git a/src/kernel/console/functions/slots.c b/src/kernel/console/functions/slots.c
deleted file mode 100644
index bce3e76..0000000
--- a/src/kernel/console/functions/slots.c
+++ /dev/null
@@ -1,69 +0,0 @@
-#include
-#include
-//#include
-
-// ----
-// NOTE:
-// Switching the active boot slot is a low-level operation,
-// this directly modifies the boot configuration used by
-// the system!
-// ----
-
-// ---
-// this is a test function it will help us wenn updating the kernel
-// ---
-
-FHDR(cmd_slot)
-{
- if (!s || str_len(s) == 0) {
- char current = readslot();
-
- char msg[32] = "current active slot: ";
- char slot_str[2];
- slot_str[0] = current;
- slot_str[1] = 0;
-
- str_append(msg, slot_str);
- str_append(msg, "\n");
-
- print(msg, GFX_GREEN);
- return;
- }
-
- if (str_starts_with(s, "set ")) {
-
- char slot = s[4];
-
- if (slot != 'A' && slot != 'B' &&
- slot != 'a' && slot != 'b') {
- print("wrong slot num, use \"A\" or \"B\"\n", GFX_RED);
- return;
- }
-
- print("this does currently not switch the real kernel slot!\n", GFX_YELLOW);
-
- if (slot == 'a') slot = 'A';
- if (slot == 'b') slot = 'B';
-
- char current = readslot();
-
- if (current == slot) {
- print("slot is already active\n", GFX_YELLOW);
- return;
- }
-
- if (writeslot(slot) == 0) {
- print("switch slot and reboot...\n", GFX_YELLOW);
-
- for (volatile int i = 0; i < 5000000; i++)
- __asm__ volatile("nop");
-
- cpu_poweroff(POWEROFF_REBOOT);
- } else {
- print("failed to switch slot\n", GFX_RED);
- }
-
- return;
- }
- return;
-}
diff --git a/src/kernel/console/functions/source.c b/src/kernel/console/functions/source.c
deleted file mode 100644
index 389e8db..0000000
--- a/src/kernel/console/functions/source.c
+++ /dev/null
@@ -1,31 +0,0 @@
-// src/kernel/console/functions/source.c
-#include
-
-FHDR(cmd_source) {
-
- // reloads the shell
-
- if (!s || *s == '\0') {
- print("usage: source \n", GFX_RED);
- return;
- }
-
- if (str_equals(s, "console") || str_equals(s, "console/")) {
- uci_reload();
-
- reload_console_theme();
-
- // Redraw banner
- banner_force_update();
-
- clear(CONSOLESCREEN_BG_COLOR);
- banner_draw();
- console_window_init();
-
- print("Console reloaded\n", GFX_GREEN);
- //shell_print_prompt();
- return;
- }
-
- print("source: only 'console' is supported\n", GFX_RED);
-}
diff --git a/src/kernel/console/functions/system.c b/src/kernel/console/functions/system.c
deleted file mode 100644
index b955653..0000000
--- a/src/kernel/console/functions/system.c
+++ /dev/null
@@ -1,136 +0,0 @@
-#include
-#include
-#include
-#include
-#include
-#include
-
-FHDR(cmd_modules)
-{
- (void)s; // unused
- print("Loaded Modules:\n", GFX_WHITE);
-
- int count = module_get_count();
-
- if (count == 0) {
- print("No modules loaded\n", GFX_WHITE);
- return;
- }
-
- char buf[128];
- for (int i = 0; i < count; i++) {
- driver_module *mod = module_get_by_index(i);
- if (mod) {
-
- //print("- ", GFX_WHITE);
- //print(mod->name, GFX_GREEN);
-
- //print(" -> ", GFX_WHITE);
- print(mod->mount, GFX_WHITE);
-
- //i simplified the module printing because its uneccesary
-
- u32 ver = mod->version;
- u32 major = (ver >> 24) & 0xFF;
- u32 minor = (ver >> 16) & 0xFF;
- u32 patch = (ver >> 8) & 0xFF;
-
- //actually version is uneccesary too but i let it for now idk
- str_copy(buf, " [v");
- str_append_uint(buf, major);
- str_append(buf, ".");
- str_append_uint(buf, minor);
- str_append(buf, ".");
- str_append_uint(buf, patch);
- str_append(buf, "]");
- print(buf, GFX_GRAY_50);
-
- print("\n", GFX_WHITE);
- }
- }
-
- str_copy(buf, "\nTotal: ");
- str_append_uint(buf, count);
- str_append(buf, " module(s)");
- print(buf, GFX_WHITE);
- //print("\nkeep in mind it will only show all modules if the os has a fs/vfs/memfs", GFX_GRAY_20);
-}
-
-FHDR(cmd_meminfo)
-{
- // (void)s; // unused parameter
-
- // char buf[128];
-
- // u64 free = mem_get_free() / 1024;
- // u64 used = mem_get_used() / 1024;
- // u64 total = mem_get_total() / 1024;
-
- // str_copy(buf, "Free : ");
- // str_append_uint(buf, (u32)(free >> 32));
- // str_append(buf, ":");
- // str_append_uint(buf, (u32)(free));
- // str_append(buf, " KB");
- // print(buf, GFX_GREEN);
-
- // str_copy(buf, "\nUsed : ");
- // str_append_uint(buf, (u32)(used >> 32));
- // str_append(buf, ":");
- // str_append_uint(buf, (u32)(used));
- // str_append(buf, " KB");
- // print(buf, GFX_YELLOW);
-
- // str_copy(buf, "\nTotal: ");
- // str_append_uint(buf, (u32)(total >> 32));
- // str_append(buf, ":");
- // str_append_uint(buf, (u32)(total));
- // str_append(buf, " KB");
- // print(buf, GFX_WHITE);
-
-}
-
-void print_res() {
- char buf[128];
- str_copy(buf, "");
- str_append_uint(buf, get_fb_width());
- str_append(buf, "x");
- str_append_uint(buf, get_fb_height());
- str_append(buf, "\n");
- print(buf, GFX_WHITE);
-}
-
-void ShowCPUName(){
- const char *cpu_name = cpu_get_brand();
- if (cpu_name[0]) {
- print(cpu_name, GFX_WHITE);
- } else {
- print("Unknown CPU", GFX_WHITE);
- }
-}
-
-FHDR(cmd_sysinfo)
-{
- (void)s; // unused parameter
-
- print(" \n", GFX_GREEN);
- print(" ###########;m; ", GFX_GREEN); print(PC_NAME, GFX_GREEN); print("@", GFX_GREEN); print(USER_NAME, GFX_GREEN); print("\n", GFX_GREEN);
- print(" # #########;m; ---------------\n", GFX_GREEN); //15 characters
- print(" # #;m; Kernel: ", GFX_GREEN); print(KERNEL_BARENAME " " KERNEL_DEFRELEASE, GFX_WHITE); print("\n", GFX_WHITE);
- print(" # #;m; Resolution: ", GFX_GREEN); print_res();
- print(" # ########;m; Bootloader: ", GFX_GREEN); print("Limine \n", GFX_WHITE);
- print(" # ########;m; CPU: ", GFX_GREEN); ShowCPUName(); print("\n", GFX_WHITE);
- print(" # #;m; Date: ", GFX_GREEN); GetCMOSDate(); print("\n", GFX_WHITE);
- print(" # #;m; Uptime: ", GFX_GREEN); timer_print_uptime(); print("\n", GFX_WHITE);
- print(" # #########;m; ---------------\n", GFX_GREEN);
- print(" ###########;m; ", GFX_GREEN);
- print("^ ", GFX_WHITE); //all colors:
- print("^ ", GFX_RED);
- print("^ ", GFX_GREEN);
- print("^ ", GFX_YELLOW);
- print("^ ", GFX_BLUE);
- print("^ ", GFX_PURPLE);
- print("^ ", GFX_CYAN);
- print("^ \n", GFX_BG); //i think nobody will see this xd
- print(" ", GFX_GREEN); // empty/new line
-
-}
diff --git a/src/kernel/console/functions/text.c b/src/kernel/console/functions/text.c
deleted file mode 100644
index 66f5dd9..0000000
--- a/src/kernel/console/functions/text.c
+++ /dev/null
@@ -1,167 +0,0 @@
-#include
-
-FHDR(cmd_echo)
-{
- if (*s == '\0') {
- print("\n", GFX_WHITE);
- return;
- }
-
- print(s, GFX_WHITE);
-}
-
-FHDR(cmd_clear)
-{
- u32 color = CONSOLESCREEN_BG_COLOR;
-
- /*
- if (*s != '\0') {
- if (!parse_color(s, &color)) {
- print("wrong color\n", GFX_RED);
- return;
- }
- }
- */
-
- if (*s != '\0') {
- return;
- }
-
- shell_clear_screen(color);
- banner_force_update();
-}
-
-FHDR(cmd_fsize)
-{
- if (*s == '\0') {
- char buf[64];
- str_copy(buf, "Current font size: ");
- str_append_uint(buf, font_scale);
- print(buf, GFX_WHITE);
- return;
- }
-
- // skip spaces
- while (*s == ' ') s++;
-
- // parse number
- int size = 0;
- while (*s >= '0' && *s <= '9') {
- size = size * 10 + (*s - '0');
- s++;
- }
-
- if (size < 1 || size > 4) {
- print("Invalid size. Use 1-4\n", GFX_RED);
- return;
- }
-
- clear(CONSOLESCREEN_BG_COLOR);
- set_font_scale(size);
- /*char buf[64];
- str_copy(buf, " Font size set to ");
- str_append_uint(buf, size);
- print(buf, GFX_GREEN);
- */
- clear(CONSOLESCREEN_BG_COLOR);
- banner_force_update();
- console_window_update_layout();
-
- cursor_x = CONSOLE_PADDING_X;
- cursor_y = banner_get_height();
-}
-
-FHDR(cmd_font) {
- if (*s == '\0') {
- return;
- }
-
- // Parse font number
- const char *p = s;
- while (*p == ' ') p++;
-
- int font_num = 0;
- while (*p >= '0' && *p <= '9') {
- font_num = font_num * 10 + (*p - '0');
- p++;
- }
-
- if (f_setcontext((font_type_t)font_num) == 0) {
- clear(CONSOLESCREEN_BG_COLOR);
- banner_force_update();
- print("\n", GFX_GREEN);
- } else {
- print("use: font ", GFX_RED);
- }
-}
-
-FHDR(cmd_cyrillc_sumbol)
-{
- (void)s;
- print("АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ\n", GFX_WHITE);
- print("абвгдеёжзийклмнопрстуфхцчшщъыьэюя\n", GFX_WHITE);
-}
-
-FHDR(cmd_latin_sumbol)
-{
- (void)s;
- print("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", GFX_WHITE);
- print("abcdefghijklmnopqrstuvwxyz\n", GFX_WHITE);
-}
-
-FHDR(cmd_all_sumbol)
-{
- (void)s;
- print("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", GFX_WHITE);
- print("abcdefghijklmnopqrstuvwxyz\n", GFX_WHITE);
- print("AEOEUESS: ÄÖÜ äöü ß\n", GFX_WHITE);
- print("АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ\n", GFX_WHITE);
- print("абвгдеёжзийклмнопрстуфхцчшщъыьэюя\n", GFX_WHITE);
- print("0123456789 !?.,:;+-*/=_()[]{}@#%&$\"'<>\\|`\n", GFX_WHITE);
-}
-
-/*FHDR(cmd_help)
-{
- if (*s == '\0') {
- // show all commands
- print("[COMMMON]\n", GFX_YELLOW);
- print(" echo [text] - echo [text]\n", GFX_WHITE);
- print(" clear [color] - clear screen\n", GFX_WHITE);
- print(" help [command] - displays this list\n", GFX_WHITE);
- print(" scale [1-4] - change screen size\n", GFX_WHITE);
- print(" font [0-1] - switch fonts\n", GFX_WHITE);
- print(" date - show current date\n", GFX_WHITE);
- print(" time - show current time\n", GFX_WHITE);
- print(" calendar - show date & time\n", GFX_WHITE);
- print(" uptime - displays the uptime\n", GFX_WHITE);
- print(" dofetch - emexOS system fetch\n", GFX_WHITE);
- print(" cat - show file content\n", GFX_WHITE);
- print(" ls - list directory contents\n", GFX_WHITE);
- print(" shut - shuts down the system\n", GFX_WHITE);
- //print("[SYSTEM]\n", GFX_YELLOW);
- print(" meminfo - heap memory information\n", GFX_WHITE);
- print(" modules - shows all modules in fs\n", GFX_WHITE);
- print("Type 'help ' for details", GFX_GRAY_50);
- } else {
- // show specific command help
- const char *p = s;
- while (*p == ' ') p++;
-
- console_cmd_t *cmd = console_find_cmd(p);
- if (cmd) {
- char buf[128];
-
- str_copy(buf, "\n");
- str_append(buf, cmd->description);
- print(buf, GFX_WHITE);
-
- str_copy(buf, "\nUsage: ");
- str_append(buf, cmd->usage);
- print(buf, GFX_YELLOW);
- print("\n", GFX_WHITE);
- } else {
- print("\nCommand not found", GFX_RED);
- }
- }
-}
-*/
diff --git a/src/kernel/console/functions/touch.c b/src/kernel/console/functions/touch.c
deleted file mode 100644
index f549ce4..0000000
--- a/src/kernel/console/functions/touch.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include
-#include
-
-extern char cwd[];
-
-FHDR(cmd_touch)
-{
- if (!s || *s == '\0') {
- print("usage: touch \n", GFX_RED);
- return;
- }
-
- char path[MAX_PATH_LEN];
-
- if (s[0] == '/') {
- str_copy(path, s);
- } else {
- str_copy(path, cwd);
- if (cwd[str_len(cwd) - 1] != '/') str_append(path, "/");
- str_append(path, s);
- }
-
- int fd = fs_open(path, O_CREAT | O_WRONLY);
- if (fd < 0) {
- print("error: cannot create file\n", GFX_RED);
- return;
- }
-
- fs_close(fd);
-}
diff --git a/src/kernel/console/functions/tree.c b/src/kernel/console/functions/tree.c
deleted file mode 100644
index 4344aea..0000000
--- a/src/kernel/console/functions/tree.c
+++ /dev/null
@@ -1,76 +0,0 @@
-// src/kernel/console/functions/tree.c
-#include
-#include
-extern char cwd[];
-
-static void tree_print(fs_node *node, int depth, int is_last)
-{
- while (node)
- {
- // indentation
- for (int i = 0; i < depth; i++) {
- print("| ", GFX_GRAY_50);
- }
-
- // prefix
- if (is_last && !node->next) {
- print("`-- ", GFX_GRAY_50);
- } else {
- print("|-- ", GFX_GRAY_50);
- }
-
- // name + color
- u32 color = GFX_WHITE;
- const char *suffix = "";
-
- if (node->type == FS_DIR) {
- color = GFX_BLUE;
- suffix = "/";
- } else if (node->type == FS_DEV) {
- color = GFX_WHITE;
- suffix = "*";
- }
-
- print(node->name, color);
- print(suffix, color);
- print("\n", GFX_WHITE);
-
- // recurse into directories
- if (node->type == FS_DIR && node->children) {
- tree_print(node->children, depth + 1, !node->next);
- }
-
- node = node->next;
- }
-}
-
-FHDR(cmd_tree)
-{
- const char *path = s;
-
- if (!s || *s == '\0') {
- path = cwd;
- }
-
- fs_node *dir = fs_resolve(path);
- if (!dir) {
- print("error: directory not found\n", GFX_RED);
- return;
- }
-
- if (dir->type != FS_DIR) {
- print("error: not a directory\n", GFX_RED);
- return;
- }
-
- // print root
- print(dir->name, GFX_BLUE);
- print("/\n", GFX_BLUE);
-
- if (!dir->children) {
- print("(empty)\n", GFX_GRAY_50);
- return;
- }
-
- tree_print(dir->children, 0, 1);
-}
diff --git a/src/kernel/console/functions/view.c b/src/kernel/console/functions/view.c
deleted file mode 100644
index 95347cd..0000000
--- a/src/kernel/console/functions/view.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include
-#include
-#include
-
-FHDR(cmd_view) {
- if (!s || *s == '\0') {
- print("usage: view \n", GFX_RED);
- return;
- }
-
- bmp_image_t img;
- if (bmp_load(s, &img) != 0) {
- print("error: cannot load image\n", GFX_RED);
- return;
- }
-
- //clear(CONSOLESCREEN_BG_COLOR);
-
- // centers image
- u32 x = (get_fb_width() - img.width) / 2;
- u32 y = (get_fb_height() - img.height) / 2;
-
- bmp_draw(&img, x, y);
- banner_draw();
-
- //print("\nPress any key to continue...\n", GFX_GRAY_50);
-
- while (1) {
- if (keyboard_has_key()) {
- key_event_t event;
- if (keyboard_get_event(&event) && event.pressed) {
- break;
- }
- }
- __asm__ volatile("hlt");
- }
-
- bmp_free(&img);
- //clear(CONSOLESCREEN_BG_COLOR);
- banner_draw();
-}
diff --git a/src/kernel/console/functions/whoami.c b/src/kernel/console/functions/whoami.c
deleted file mode 100644
index da4cb21..0000000
--- a/src/kernel/console/functions/whoami.c
+++ /dev/null
@@ -1,9 +0,0 @@
-// src/kernel/console/functions/whoami.c
-#include
-
-FHDR(cmd_whoami) {
- (void)s;
-
- print(uci_get_user_name(), GFX_WHITE);
- print("\n", GFX_WHITE);
-}
diff --git a/src/kernel/console/graph/dos.c b/src/kernel/console/graph/dos.c
deleted file mode 100644
index 0588fbb..0000000
--- a/src/kernel/console/graph/dos.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "dos.h"
-#include "uno.h"
-#include
-#include
-
-void console_window_init(void) {
- cursor_x = CONSOLE_PADDING_X;
- cursor_y = banner_get_height();
-}
-
-void console_window_clear(u32 color)
-{
- u32 fb_w = get_fb_width();
- u32 fb_h = get_fb_height();
- u32 banner_h = banner_get_height();
-
- // clear below banner
- draw_rect(0, banner_h, fb_w, fb_h - banner_h, color);
- //TODO:
- // implement real dirty rectangles/ screen clear
-
- // redraw banner
- banner_draw();
-
- // reset cursor to console start
- cursor_x = CONSOLE_PADDING_X;
- cursor_y = banner_h;
-}
-
-u32 console_window_get_start_y(void) {
- return banner_get_height();
-}
-
-u32 console_window_get_max_y(void) {
- return get_fb_height();
-}
-
-void console_window_check_scroll(void)
-{
- u32 char_height = fm_get_char_height() * font_scale;
- u32 line_height = char_height + 2 * font_scale;
- u32 fb_h = get_fb_height();
- u32 banner_h = banner_get_height();
-
- // check if cursor is out of screen
- if (cursor_y + char_height > fb_h) {
- u32 fb_w = get_fb_width();
- u32 pitch_dwords = get_fb_pitch() / 4;
- u32 *fb = get_framebuffer();
-
- // move content up by line_height
- for (u32 y = banner_h + line_height; y < fb_h; y++) {
- for (u32 x = 0; x < fb_w; x++) {
- fb[(y - line_height) * pitch_dwords + x] = fb[y * pitch_dwords + x];
- }
- }
-
- // cls bottom line
- for (u32 y = fb_h - line_height; y < fb_h; y++) {
- for (u32 x = 0; x < fb_w; x++) {
- fb[y * pitch_dwords + x] = CONSOLESCREEN_BG_COLOR;
- }
- }
-
- // move cursor up
- cursor_y -= line_height;
-
- if (cursor_y < banner_h) {
- cursor_y = banner_h;
- }
- }
-}
-
-void console_window_update_layout(void)
-{
- //after fsize change
- // adjust cursor
- u32 banner_h = banner_get_height();
-
- if (cursor_y < banner_h) {
- cursor_y = banner_h;
- }
-}
diff --git a/src/kernel/console/graph/dos.h b/src/kernel/console/graph/dos.h
deleted file mode 100644
index d06bd98..0000000
--- a/src/kernel/console/graph/dos.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef CONSOLE_DOS_H
-#define CONSOLE_DOS_H
-
-#include
-
-#define CONSOLE_PADDING_X 0 // 15(baner) + 8(font scale) 23
-
-void console_window_init(void);
-void console_window_clear(u32 color);
-u32 console_window_get_start_y(void);
-u32 console_window_get_max_y(void);
-void console_window_check_scroll(void);
-void console_window_update_layout(void);
-
-//TODO:
-// this needs to be remade when we have a window system in usermode
-
-#endif
diff --git a/src/kernel/console/graph/uno.c b/src/kernel/console/graph/uno.c
deleted file mode 100644
index 692a649..0000000
--- a/src/kernel/console/graph/uno.c
+++ /dev/null
@@ -1,174 +0,0 @@
-#include "uno.h"
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-static u32 banner_y = 0;
-static u32 banner_y_s = BANNER_Y_SPACING;
-static u8 last_second = 0;
-static u8 needs_update = 1;
-static u32 current_banner_height = 0;//BANNER_HEIGHT;
-
-// forward declaration
-static void banner_timer_callback(void);
-
-void banner_init(void)
-{
- banner_y = 0;
- banner_y_s = BANNER_Y_SPACING;
- last_second = 0;
- needs_update = 1;
- //current_banner_height = BANNER_HEIGHT;
-
- u32 char_height = fm_get_char_height() * font_scale;
- current_banner_height = char_height + (banner_y_s * 2);
-
- timer_register_callback(banner_timer_callback);
- banner_draw();
-}
-
-void banner_draw(void)
-{
- u32 fb_w = get_fb_width();
-
- // based on font scale
- u32 char_height = fm_get_char_height() * font_scale;
- u32 o_cursor_x = cursor_x;
- u32 o_cursor_y = cursor_y;
- u32 o_scale = font_scale;
- current_banner_height = char_height + (banner_y_s * 2);
-
- // draw background (in future moved to the wm)
- draw_rect(0, banner_y, fb_w, current_banner_height, BANNER_BG_COLOR);
- draw_rect(0, banner_y + current_banner_height - font_scale, fb_w, font_scale, BANNER_BORDER_COLOR);
-
- // use current screen_scale for banner
-
- cursor_x = 4;
- cursor_y = banner_y + banner_y_s;
-
- const char *os_name = KERNEL_VERSION;
- for (int i = 0; os_name[i]; i++) {
- putchar(os_name[i], BANNER_TEXT_COLOR);
- }
-
- // centered = "console"
- // TODO:
- // should be called after the current app
- const char *center_text = CONSOLE_APP_NAME;
- int text_width = str_len(center_text) * (fm_get_char_width() * font_scale);
- cursor_x = (fb_w - text_width) / 2;
- cursor_y = banner_y + banner_y_s;
-
- for (int i = 0; center_text[i]; i++) {
- putchar(center_text[i], BANNER_TEXT_COLOR);
- }
-
- // right side = Date & Time
- banner_update_time();
-
- // restore cursor and scale from before
- font_scale = o_scale;
- cursor_x = o_cursor_x;
- cursor_y = o_cursor_y;
-
- needs_update = 0;
-}
-
-void banner_update_time(void)
-{
- u32 fb_w = get_fb_width();
- u32 o_cursor_x = cursor_x;
- u32 o_cursor_y = cursor_y;
- u32 o_scale = font_scale;
-
- // based on screen scale
-
- cmos_time_t time;
- cmos_read_time(&time);
-
- char time_buf[32];
- str_copy(time_buf, "");
-
- // date as DD/MM/YY
- if (time.month < 10) str_append(time_buf, "0");
- str_append_uint(time_buf, time.month);
- str_append(time_buf, "/");
- if (time.day < 10) str_append(time_buf, "0");
- str_append_uint(time_buf, time.day);
- str_append(time_buf, "/");
- if (time.year < 10) str_append(time_buf, "0");
- str_append_uint(time_buf, time.year);
- //TODO:
- // in future it will be a programm from functions/cmos.c
-
- str_append(time_buf, " ");
-
- // time in HH:MM:SS
- if (time.hour < 10) str_append(time_buf, "0");
- str_append_uint(time_buf, time.hour);
- str_append(time_buf, ":");
- if (time.minute < 10) str_append(time_buf, "0");
- str_append_uint(time_buf, time.minute);
- str_append(time_buf, ":");
- if (time.second < 10) str_append(time_buf, "0");
- str_append_uint(time_buf, time.second);
- //same for here its from cmos.c
-
- int text_len = str_len(time_buf);
- int text_pixel_width = text_len * (fm_get_char_width() * font_scale);
-
- u32 char_height = fm_get_char_height() * font_scale;
- draw_rect(fb_w - text_pixel_width - 8, banner_y, text_pixel_width + 8, current_banner_height, BANNER_BG_COLOR);
-
- cursor_x = fb_w - text_pixel_width - 4;
- cursor_y = banner_y + banner_y_s;
-
- for (int i = 0; time_buf[i]; i++) {
- putchar(time_buf[i], BANNER_TEXT_COLOR);
- }
-
- //otherwise the time banner will overwrite the line
- draw_rect(fb_w - text_pixel_width - 8, banner_y + current_banner_height - font_scale,
- text_pixel_width + 8, font_scale, BANNER_BORDER_COLOR);
-
- font_scale = o_scale;
- cursor_x = o_cursor_x;
- cursor_y = o_cursor_y;
-}
-
-// private timer callback (c static)
-static void banner_timer_callback(void)
-{
- cmos_time_t time;
- cmos_read_time(&time);
-
- if (time.second != last_second) {
- last_second = time.second;
- needs_update = 1;
- }
- if (needs_update) {
- banner_update_time();
- needs_update = 0;
- }
-}
-
-void banner_tick(void) {
- // This function still exists due compatibility
- // i don't want to rename it in other functions too
- banner_timer_callback();
-}
-
-void banner_force_update(void) {
- needs_update = 1;
- banner_draw();
-}
-
-u32 banner_get_height(void) {
- return current_banner_height;
-}
diff --git a/src/kernel/console/graph/uno.h b/src/kernel/console/graph/uno.h
deleted file mode 100644
index ba2dff8..0000000
--- a/src/kernel/console/graph/uno.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef CONSOLE_UNO_H
-#define CONSOLE_UNO_H
-
-#include
-#include
-#include
-
-//#define BANNER_HEIGHT 15
-#define BANNER_Y_SPACING 4 // vertical spacing
-#define BANNER_BG_COLOR GFX_GRAY_20 // bar background
-#define BANNER_BORDER_COLOR GFX_GRAY_40 // border bottom
-#define BANNER_TEXT_COLOR CONSOLESCREEN_COLOR // White text
-#define BANNER_UPDATE_INTERVAL 60
-
-void banner_init(void);
-void banner_draw(void);
-void banner_update_time(void);
-void banner_tick(void); // called from timer
-void banner_force_update(void); // force update
-u32 banner_get_height(void);
-
-#endif
diff --git a/src/kernel/console/parser.c b/src/kernel/console/parser.c
deleted file mode 100644
index 90e646f..0000000
--- a/src/kernel/console/parser.c
+++ /dev/null
@@ -1,93 +0,0 @@
-#include
-
-// parse color argument if provided
-int parse_color(const char *color_str, u32 *out_color) {
- if (!color_str || !out_color) return 0;
-
- const char *p = color_str;
- while (*p == ' ') p++;
-
- // simple color name parsing
- if (*p == 'b' && *(p+1) == 'l' && *(p+2) == 'a' && *(p+3) == 'c' && *(p+4) == 'k' && *(p+5) == '\0') {
- *out_color = GFX_BLACK;
- return 1;
- } else if (*p == 'w' && *(p+1) == 'h' && *(p+2) == 'i' && *(p+3) == 't' && *(p+4) == 'e' && *(p+5) == '\0') {
- *out_color = GFX_WHITE;
- return 1;
- } else if (*p == 'r' && *(p+1) == 'e' && *(p+2) == 'd' && *(p+3) == '\0') {
- *out_color = GFX_RED;
- return 1;
- } else if (*p == 'g' && *(p+1) == 'r' && *(p+2) == 'e' && *(p+3) == 'e' && *(p+4) == 'n' && *(p+5) == '\0') {
- *out_color = GFX_GREEN;
- return 1;
- } else if (*p == 'b' && *(p+1) == 'l' && *(p+2) == 'u' && *(p+3) == 'e' && *(p+4) == '\0') {
- *out_color = GFX_BLUE;
- return 1;
- } else if (*p == 'c' && *(p+1) == 'y' && *(p+2) == 'a' && *(p+3) == 'n' && *(p+4) == '\0') {
- *out_color = GFX_CYAN;
- return 1;
- } else if (*p == 'y' && *(p+1) == 'e' && *(p+2) == 'l' && *(p+3) == 'l' && *(p+4) == 'o' && *(p+5) == 'w' && *(p+6) == '\0') {
- *out_color = GFX_YELLOW;
- return 1;
- } else if (*p == 'p' && *(p+1) == 'u' && *(p+2) == 'r' && *(p+3) == 'p' && *(p+4) == 'l' && *(p+5) == 'e' && *(p+6) == '\0') {
- *out_color = GFX_PURPLE;
- return 1;
- }
-
- return 0;
-}
-
-// split input in && then execute the commands
-void parse_and_execute_chained(const char *input) {
- if (!input || *input == '\0') return;
-
- char commands[MAX_CHAINED_CMDS][MAX_INPUT_LEN];
- int cmd_count = 0;
- int cmd_pos = 0;
-
- const char *p = input;
-
- // split input in &&
- while (*p && cmd_count < MAX_CHAINED_CMDS) {
- while (*p == ' ') p++; // space after/ before &&
-
- // copy command until && or end
- cmd_pos = 0;
- while (*p && cmd_pos < MAX_INPUT_LEN - 1) {
- if (*p == '&' && *(p+1) == '&') { // == &&
- commands[cmd_count][cmd_pos] = '\0';
- cmd_count++;
- p += 2;
- break;
- }
- commands[cmd_count][cmd_pos++] = *p++;
- }
-
- // if last command is or buffer is full
- if (*p == '\0' || cmd_pos >= MAX_INPUT_LEN - 1) {
- commands[cmd_count][cmd_pos] = '\0';
- cmd_count++;
- break;
- }
- }
-
- // execute all commands
- for (int i = 0; i < cmd_count; i++) {
- //trailing
- int len = 0;
- while (commands[i][len]) len++;
- len--;
- while (len >= 0 && commands[i][len] == ' ') {
- commands[i][len] = '\0';
- len--;
- }
-
- if (commands[i][0] != '\0') {
- console_execute(commands[i]);
- if (i < cmd_count - 1) {
- print("\n", GFX_WHITE);
- }
-
- }
- }
-}
diff --git a/src/kernel/console/promtinit.c b/src/kernel/console/promtinit.c
deleted file mode 100644
index 4ab3032..0000000
--- a/src/kernel/console/promtinit.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "console.h"
-#include
-
-void console_config_init(void) {
- // Create directories
- fs_mkdir("/.config/ekmsh");
- fs_mkdir("/.config/ekmsh/fonts");
- //fs_mkdir("/.config/ekmsh/prompts");
-
- // Create default prompt.conf
- int fd = fs_open("/.config/ekmsh/prompt.cfg", O_CREAT | O_WRONLY);
- if (fd >= 0) {
- const char *default_config =
- "# currently there is no color support for the prompt, but soon!\n"
- "# %u = username,\n# %h = hostname,\n# %w = curent directory\n"
- "[%u@%h:%w]# \n"
- ;
-
- fs_write(fd, default_config, str_len(default_config));
- fs_close(fd);
- }
-
- // Create default theme.cfg
- fd = fs_open("/.config/ekmsh/theme.cfg", O_CREAT | O_WRONLY); // get read by graph/theme
- if (fd >= 0) {
- const char *default_theme =
- "# use: 0xAARRGGBB\n"
- "\n"
- "BLACK: 0xFF111111\n"
- "BG: 0xFF1F1F1F\n"
- "RED: 0xFF9E6E6E\n"
- "GREEN: 0xFF7A8A7A\n"
- "YELLOW: 0xFFB8A788\n"
- "BLUE: 0xFF6E7F8E\n"
- "PURPLE: 0xFF857A8E\n"
- "CYAN: 0xFF7A8E8E\n"
- "WHITE: 0xFFD8D8D8\n"
- ;
-
- fs_write(fd, default_theme, str_len(default_theme));
- fs_close(fd);
- }
- fd = fs_open("/.config/ekmsh/con.cfg", O_CREAT | O_WRONLY); // get read by graph/theme
- if (fd >= 0) {
- const char *Cconfiguration =
- "CONSOLE_PROG: \"ekmsh\"\n"
- "CONSOLE_NAME: \"console\"\n"
- "\n"
- "CONSOLE_VERS: \"1.3\" # new with login\n"
- ;
-
- fs_write(fd, Cconfiguration, str_len(Cconfiguration));
- fs_close(fd);
- }
- // copy bdf here...
-}
diff --git a/src/kernel/console/shell_screen.c b/src/kernel/console/shell_screen.c
deleted file mode 100644
index 56b1d13..0000000
--- a/src/kernel/console/shell_screen.c
+++ /dev/null
@@ -1,108 +0,0 @@
-#include "console.h"
-#include "graph/uno.h"
-#include "graph/dos.h"
-#include
-
-void shell_clear_screen(u32 color)
-{
-
- console_window_clear(color);
-}
-
-static conf_entry_t prompt_conf[16];
-static int prompt_conf_count = 0;
-
-void shell_load_prompt_config(void) {
- prompt_conf_count = conf_load("/.config/ekmsh/prompt.cfg",
- prompt_conf, 16);
-}
-
-extern char cwd[];
-
-/*void shell_print_prompt(void)
-{
-
- string("\n", GFX_WHITE);
- string(user_config_get_pc_name(), GFX_WHITE);
- string("@", GFX_WHITE);
- string(user_config_get_user_name(), GFX_WHITE);
- //string("\x01 ", GFX_YELLOW);
- string(":", GFX_WHITE);
- if (str_len(cwd) > 1 && cwd[str_len(cwd) - 1] == '/') {
- char prompt_cwd[MAX_PATH_LEN];
- str_copy(prompt_cwd, cwd);
- prompt_cwd[str_len(cwd) - 1] = '\0';
- string(prompt_cwd, GFX_WHITE);
- }
- string("# ", GFX_BLUE);
-}*/
-
-void shell_print_prompt(void)
-{
- // emexOS will be the directory if we have a file system
-
- // in future it should be like:
- /*
- * string("\n", GFX_WHITE);
- * string(variable, GFX_PURPLE); // variable is the current dir
- * string(" > ", GFX_WHITE);
- */
- //
-
- if (prompt_conf_count <= 0) {
- shell_load_prompt_config();
- }
-
- const char *format = conf_get(prompt_conf, prompt_conf_count, "format");
-
- if (!format) {
- printf("using standard");
- string("\n[", GFX_WHITE);
- string(uci_get_pc_name(), GFX_WHITE);
- string("@", GFX_WHITE);
- string(uci_get_user_name(), GFX_WHITE);
- string("]", GFX_WHITE);
-
- if (str_len(cwd) > 1 && cwd[str_len(cwd) - 1] == '/') {
- char prompt_cwd[MAX_PATH_LEN];
- str_copy(prompt_cwd, cwd);
- prompt_cwd[str_len(cwd) - 1] = '\0';
- string(prompt_cwd, GFX_WHITE);
- } else {
- string(cwd, GFX_WHITE);
- }
-
- string("# ", GFX_BLUE);
- return;
- }
-
- string("\n", GFX_WHITE);
-
- for (const char *p = format; *p; p++) {
- if (*p == '%') {
- p++;
- if (*p == 'u') string(uci_get_user_name(), GFX_WHITE);
- else if (*p == 'h') string(uci_get_pc_name(), GFX_WHITE);
- else if (*p == 'w') {
- if (str_len(cwd) > 1 && cwd[str_len(cwd) - 1] == '/') {
- char prompt_cwd[MAX_PATH_LEN];
- str_copy(prompt_cwd, cwd);
- prompt_cwd[str_len(cwd) - 1] = '\0';
- string(prompt_cwd, GFX_WHITE);
- } else {
- string(cwd, GFX_WHITE);
- }
- }
- else if (*p == '%') string("%", GFX_WHITE);
- } else {
- char c[2] = {*p, '\0'};
- string(c, GFX_WHITE);
- }
- }
-}
-
-void shell_redraw_input(void)
-{
- // for future use: redraw current input line
- // useful when implementing line editing features (programms)
-}
diff --git a/src/kernel/cpu/cpu.h b/src/kernel/cpu/cpu.h
index 273ff29..243e4aa 100644
--- a/src/kernel/cpu/cpu.h
+++ b/src/kernel/cpu/cpu.h
@@ -79,4 +79,11 @@ const char* cpu_get_brand(void);
cpu_info_t* cpu_get_info(void);
int cpu_has_feature(u32 feature);
+void cli(void);
+void sti(void);
+__attribute__((noreturn)) void halt(void);
+__attribute__((noreturn)) void idle(void);
+void wfi(void);
+void nop(void);
+
#endif
diff --git a/src/kernel/cpu/halt.c b/src/kernel/cpu/halt.c
new file mode 100644
index 0000000..ae18264
--- /dev/null
+++ b/src/kernel/cpu/halt.c
@@ -0,0 +1,39 @@
+#include "cpu.h"
+
+//
+// MADE BY @msaid5860
+//
+
+// Disable interrupts
+void cli(void) {
+ __asm__ volatile("cli");
+}
+
+// Enable interrupts
+void sti(void) {
+ __asm__ volatile("sti");
+}
+
+// Full system halt
+__attribute__((noreturn)) void chalt(void) {
+ __asm__ volatile("cli");
+ for (;;) __asm__ volatile("hlt");
+}
+
+void halt(void) {
+ __asm__ volatile("hlt");
+}
+
+// Idle halt
+__attribute__((noreturn)) void idle(void) {
+ for (;;) __asm__ volatile("hlt");
+}
+
+// Wait for interrupt
+void wfi(void) {
+ __asm__ volatile("sti; pause; hlt");
+}
+
+void nop(void) {
+ __asm__ volatile("nop");
+}
\ No newline at end of file
diff --git a/src/kernel/cpu/poweroff.c b/src/kernel/cpu/poweroff.c
index 421df4e..a255b92 100644
--- a/src/kernel/cpu/poweroff.c
+++ b/src/kernel/cpu/poweroff.c
@@ -18,12 +18,16 @@ static inline void x86_restart(void)
__asm__ volatile("nop");
// PCI RCR
- u8 temp = inb(0xCF9);
- outb(0xCF9, temp | 0x02);
- outb(0xCF9, temp | 0x06);
+ outb(0xCF9, 0x02);
+ for (volatile int i = 0; i < 100; i++) __asm__ volatile("nop");
+ outb(0xCF9, 0x0E);
+ for (volatile int i = 0; i < 1000000; i++) __asm__ volatile("nop");
- for (volatile int i = 0; i < 1000000; i++)
- __asm__ volatile("nop");
+ __asm__ volatile(
+ "lidt %0\n"
+ "int $3\n"
+ :: "m"((u64[]){0, 0}) : "memory"
+ );
}
static inline void x86_shutdown(void)
diff --git a/src/kernel/devices/devices.h b/src/kernel/devices/devices.h
new file mode 100644
index 0000000..bb8af65
--- /dev/null
+++ b/src/kernel/devices/devices.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define ATANAME "dev_atahdd0"
+#define ATAPATH "/dev/hda"
+#define ATAUNIVERSAL VERSION_NUM(0, 1, 2, 0)
+
+#define KBDNAME "dev_ps2_keyboard0"
+#define KBDPATH "/dev/input/keyboard0"
+#define KBDUNIVERSAL VERSION_NUM(0, 3, 1, 0)
+
+#define MS0NAME "dev_ps2_mouse0"
+#define MS0PATH "/dev/input/mouse0"
+#define MS0UNIVERSAL VERSION_NUM(0, 0, 0, 0)
+
+#define EFBNAME FBN
+#define FB0NAME "dev_fb0"
+#define FB0PATH "/dev/fb0"
+#define FB0UNIVERSAL VERSION_NUM(0, 0, 0, 0) // always 0.0.0.0
+
+#define ZERNAME "dev_zero"
+#define ZERPATH "/dev/zero"
+#define ZERUNIVERSAL VERSION_NUM(0, 0, 0, 0) // always 0.0.0.0
+
+#define NULNAME "dev_null"
+#define NULPATH "/dev/null"
+#define NULUNIVERSAL VERSION_NUM(0, 0, 0, 0) // always 0.0.0.0
+
+#define TTY0NAME "dev_tty0"
+#define TTY0PATH "/dev/tty0"
+#define TTY0UNIVERSAL VERSION_NUM(0, 0, 1, 2)
+
+#define URNDNAME "dev_urandom"
+#define URNDPATH "/dev/urandom"
+#define URNDUNIVERSAL VERSION_NUM(0, 0, 1, 0)
+
+#define RNDNAME "dev_random"
+#define RNDPATH "/dev/random"
+#define RNDUNIVERSAL VERSION_NUM(0, 0, 1, 0)
\ No newline at end of file
diff --git a/src/kernel/devices/disks/hdd0.c b/src/kernel/devices/disks/hdd0.c
new file mode 100644
index 0000000..03c3dfe
--- /dev/null
+++ b/src/kernel/devices/disks/hdd0.c
@@ -0,0 +1,97 @@
+#include "hdd0.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define HDA_SECTOR_SIZE 512
+
+static int ATAmodule_init(void) {
+ log("[HDA]", "init /dev/hda\n", d);
+ return 0;
+}
+
+static void ATAmodule_fini(void) {
+ // cleanup if needed
+}
+
+static void *hda_open(const char *path) {
+ (void)path;
+ return ATAget_device(0);
+}
+
+static int hda_read(void *handle, void *buf, size_t count, u64 offset)
+{
+ ATAdevice_t *dev = (ATAdevice_t *)handle;
+ if (!dev || !buf || count == 0) return -1;
+
+ u64 lba = offset / HDA_SECTOR_SIZE;
+ u32 lba_offset = offset % HDA_SECTOR_SIZE;
+ u32 sectors = (u32)((lba_offset + count + HDA_SECTOR_SIZE - 1) / HDA_SECTOR_SIZE);
+
+ // temp buffer for unaligned reads
+ static u8 tmp[HDA_SECTOR_SIZE] __attribute__((aligned(16)));
+ size_t remaining = count;
+ u8 *dst = (u8 *)buf;
+
+ for (u32 i = 0; i < sectors && remaining > 0; i++)
+ {
+ if (ATAread_sectors(dev, lba + i, 1, (u16 *)tmp) != 0) return -1;
+
+ u32 src_off = (i == 0) ? lba_offset : 0;
+ u32 to_copy = HDA_SECTOR_SIZE - src_off;
+ if (to_copy > remaining) to_copy = (u32)remaining;
+
+ memcpy(dst, tmp + src_off, to_copy);
+
+ dst += to_copy;
+ remaining -= to_copy;
+ }
+ return (int)(count - remaining);
+}
+
+static int hda_write(void *handle, const void *buf, size_t count, u64 offset)
+{
+ ATAdevice_t *dev = (ATAdevice_t *)handle;
+ if (!dev || !buf || count == 0) return -1;
+
+ u64 lba = offset / HDA_SECTOR_SIZE;
+ u32 lba_offset = offset % HDA_SECTOR_SIZE;
+ u32 sectors = (u32)((lba_offset + count + HDA_SECTOR_SIZE - 1) / HDA_SECTOR_SIZE);
+
+ static u8 tmp[HDA_SECTOR_SIZE] __attribute__((aligned(16)));
+ size_t remaining = count;
+ const u8 *src = (const u8 *)buf;
+
+ for (u32 i = 0; i < sectors && remaining > 0; i++)
+ {
+ u32 dst_off = (i == 0) ? lba_offset : 0;
+ u32 to_copy = HDA_SECTOR_SIZE - dst_off;
+ if (to_copy > remaining) to_copy = (u32)remaining;
+ if (dst_off != 0 || to_copy != HDA_SECTOR_SIZE) {
+ if (ATAread_sectors(dev, lba + i, 1, (u16 *)tmp) != 0) return -1;
+ }
+
+ memcpy(tmp + dst_off, src, to_copy);
+
+ if (ATAwrite_sectors(dev, lba + i, 1, (u16 *)tmp) != 0) return -1;
+
+ src += to_copy;
+ remaining -= to_copy;
+ }
+ return (int)(count - remaining);
+}
+
+driver_module ata_module = {
+ .name = ATANAME,
+ .mount = ATAPATH,
+ .version = ATAUNIVERSAL,
+ .init = ATAmodule_init,
+ .fini = ATAmodule_fini,
+ .open = hda_open,
+ .read = hda_read,
+ .write = hda_write,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/disks/hdd0.h b/src/kernel/devices/disks/hdd0.h
new file mode 100644
index 0000000..153a8f3
--- /dev/null
+++ b/src/kernel/devices/disks/hdd0.h
@@ -0,0 +1,9 @@
+#ifndef DEVICE_HDD0_H
+#define DEVICE_HDD0_H
+
+#include
+
+// /dev/hda
+extern driver_module ata_module;
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/devices/fb0/fb0.c b/src/kernel/devices/fb0/fb0.c
new file mode 100644
index 0000000..9d865fc
--- /dev/null
+++ b/src/kernel/devices/fb0/fb0.c
@@ -0,0 +1,156 @@
+#include "fb0.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+static size_t fb_write_pos = 0;
+static size_t fb_read_pos = 0;
+
+static int fb0_mod_init(void) {
+ log("[FB0]", "init /dev/fb0\n", d);
+ return 0;
+}
+
+static void fb0_mod_fini(void) {}
+
+static void *fb0_open(const char *path) {
+ (void)path;
+ fb_write_pos = 0;
+ fb_read_pos = 0;
+ return (void *)1;
+}
+
+static int fb0_read(void *handle, void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)offset;
+ u32 *fb = get_framebuffer();
+ u32 pitch = get_fb_pitch();
+ u32 h = get_fb_height();
+
+ if (!fb) return -1;
+
+ size_t fb_size = (size_t)pitch * h;
+
+ // EOF
+ if (fb_read_pos >= fb_size) return 0;
+
+ size_t remaining = fb_size - fb_read_pos;
+ if (count > remaining) count = remaining;
+
+ memcpy(buf, (u8 *)fb + fb_read_pos, count);
+ fb_read_pos += count;
+ return (int)count;
+}
+
+static int fb0_write(void *handle, const void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)offset;
+ u32 *fb = get_framebuffer();
+ u32 pitch = get_fb_pitch();
+ u32 h = get_fb_height();
+
+ if (!fb) return -1;
+
+ size_t fb_size = (size_t)pitch * h;
+
+ // wrap around if we're on end
+ if (fb_write_pos >= fb_size) fb_write_pos = 0;
+
+ size_t remaining = fb_size - fb_write_pos;
+ if (count > remaining) count = remaining;
+
+ memcpy((u8 *)fb + fb_write_pos, buf, count);
+ fb_write_pos += count;
+ return (int)count;
+}
+
+int fb0_ioctl(int request, void *arg) {
+ if (!arg) return -1;
+
+ u32 w = get_fb_width();
+ u32 h = get_fb_height();
+ u32 pitch = get_fb_pitch();
+ u32 *fb = get_framebuffer();
+
+ switch (request) {
+ case FBIOGET_VSCREENINFO: {
+ fb_var_screeninfo_t *info = (fb_var_screeninfo_t *)arg;
+ info->xres = w;
+ info->yres = h;
+ info->xres_virtual = w;
+ info->yres_virtual = h;
+ info->xoffset = 0;
+ info->yoffset = 0;
+ info->bits_per_pixel = 32;
+ info->grayscale = 0;
+ info->blue_offset = 0; info->blue_length = 8;
+ info->green_offset = 8; info->green_length = 8;
+ info->red_offset = 16; info->red_length = 8;
+ info->transp_offset = 24; info->transp_length = 8;
+ return 0;
+ }
+ case FBIOGET_FSCREENINFO: {
+ fb_fix_screeninfo_t *fix = (fb_fix_screeninfo_t *)arg;
+ str_copy(fix->id, FBN);
+ fix->smem_start = (u64)fb;
+ fix->smem_len = pitch * h;
+ fix->type = 0; // FB_TYPE_PACKED_PIXELS
+ fix->visual = 2; // FB_VISUAL_TRUECOLOR
+ fix->line_length = pitch;
+ return 0;
+ }
+ case FBIO_READ_RECT: {
+ fb_rect_t *r = (fb_rect_t *)arg;
+ if (!r || !r->pixels) return -1;
+ u32 pitch_dw = pitch / 4;
+ for (u32 row = 0; row < r->h; row++) {
+ u32 py = r->y + row;
+ if (py >= h) break;
+ for (u32 col = 0; col < r->w; col++) {
+ u32 px = r->x + col;
+ r->pixels[row * r->w + col] = (px < w) ? fb[py * pitch_dw + px] : 0;
+ }
+ }
+ return 0;
+ }
+ case FBIO_BLIT: {
+ fb_rect_t *r = (fb_rect_t *)arg;
+ if (!r || !r->pixels) return -1;
+ u32 pitch_dw = pitch / 4;
+ for (u32 row = 0; row < r->h; row++) {
+ u32 py = r->y + row;
+ if (py >= h) break;
+ for (u32 col = 0; col < r->w; col++) {
+ u32 px = r->x + col;
+ if (px >= w) break;
+ u32 c = r->pixels[row * r->w + col];
+ if ((c >> 24) == 0) continue; // transparent
+ fb[py * pitch_dw + px] = c;
+ }
+ }
+ return 0;
+ }
+ case FBIO_RESET_POS:
+ fb_write_pos = 0;
+ return 0;
+ default:
+ return -1;
+ }
+}
+
+driver_module fb0_module = {
+ .name = FB0NAME,
+ .mount = FB0PATH,
+ .version = FB0UNIVERSAL,
+ .init = fb0_mod_init,
+ .fini = fb0_mod_fini,
+ .open = fb0_open,
+ .read = fb0_read,
+ .write = fb0_write,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/fb0/fb0.h b/src/kernel/devices/fb0/fb0.h
new file mode 100644
index 0000000..186ae16
--- /dev/null
+++ b/src/kernel/devices/fb0/fb0.h
@@ -0,0 +1,58 @@
+#ifndef DEVICE_FB0_H
+#define DEVICE_FB0_H
+
+#include
+#include
+
+#include
+
+#define FBN EMEX "fb0"
+
+// fb_var_screeninfo
+typedef struct {
+ u32 xres;
+ u32 yres;
+ u32 xres_virtual;
+ u32 yres_virtual;
+ u32 xoffset;
+ u32 yoffset;
+ u32 bits_per_pixel;
+ u32 grayscale;
+ u32 red_offset;
+ u32 red_length;
+ u32 green_offset;
+ u32 green_length;
+ u32 blue_offset;
+ u32 blue_length;
+ u32 transp_offset;
+ u32 transp_length;
+} fb_var_screeninfo_t;
+typedef struct {
+ char id[16];
+ u64 smem_start;
+ u32 smem_len;
+ u32 type;
+ u32 visual;
+ u32 line_length; // pitch
+} fb_fix_screeninfo_t;
+
+// /dev/fb0 request codes
+#define FBIOGET_VSCREENINFO 0x4600
+#define FBIOPUT_VSCREENINFO 0x4601
+#define FBIOGET_FSCREENINFO 0x4602
+#define FBIO_RESET_POS 0x4603
+#define FBIO_READ_RECT 0x4610
+#define FBIO_BLIT 0x4611
+
+typedef struct {
+ u32 x, y, w, h;
+ u32 *pixels;
+} fb_rect_t;
+
+// /dev/fb0 module
+extern driver_module fb0_module;
+
+
+int fb0_ioctl(int request, void *arg);
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/devices/input/kbd.c b/src/kernel/devices/input/kbd.c
new file mode 100644
index 0000000..2f5037f
--- /dev/null
+++ b/src/kernel/devices/input/kbd.c
@@ -0,0 +1,67 @@
+#include "kbd.h"
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+static int kbd_dev_init(void) {
+ log("[KBD]", "init /dev/input/keyboard0\n", d);
+ // keyboard_module is gone...
+ keyboard_init();
+ return 0;
+}
+
+static void kbd_dev_fini(void) {
+ irq_unregister_handler(1);
+}
+static void *kbd_dev_open(const char *path) {
+ (void)path;
+ return (void *)1; // dummy handle
+}
+
+static int kbd_dev_read(void *handle, void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)offset;
+
+ size_t ev_size = sizeof(key_event_t);
+ size_t written = 0;
+ u8 *out = (u8 *)buf;
+
+ // drain as many events as fit in buf
+ while (written + ev_size <= count && keyboard_has_key()) {
+ key_event_t ev;
+ if (keyboard_get_event(&ev)) {
+ u8 *src = (u8 *)&ev;
+ for (size_t i = 0; i < ev_size; i++) {
+ out[written + i] = src[i];
+ }
+ written += ev_size;
+ }
+ }
+
+ return (int)written;
+}
+
+// there is no write for input devices
+static int kbd_dev_write(void *handle, const void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)buf;
+ (void)count;
+ (void)offset;
+ return -1;
+}
+
+driver_module kbd_dev_module = {
+ .name = KBDNAME,
+ .mount = KBDPATH,
+ .version = KBDUNIVERSAL,
+ .init = kbd_dev_init,
+ .fini = kbd_dev_fini,
+ .open = kbd_dev_open,
+ .read = kbd_dev_read,
+ .write = kbd_dev_write,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/input/kbd.h b/src/kernel/devices/input/kbd.h
new file mode 100644
index 0000000..76ee2d7
--- /dev/null
+++ b/src/kernel/devices/input/kbd.h
@@ -0,0 +1,8 @@
+#ifndef DEVICE_KBD_H
+#define DEVICE_KBD_H
+
+#include
+
+extern driver_module kbd_dev_module;
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/devices/input/mouse0.c b/src/kernel/devices/input/mouse0.c
new file mode 100644
index 0000000..67366fd
--- /dev/null
+++ b/src/kernel/devices/input/mouse0.c
@@ -0,0 +1,49 @@
+#include "mouse0.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+static int mouse0_init(void) {
+ log("[MOUSE]", "init /dev/input/mouse0\n", d);
+ mouse_init();
+ return 0;
+}
+static void mouse0_fini(void){
+ irq_unregister_handler(12);
+}
+static void *mouse0_open(const char *p){
+ (void)p; return (void *)1;
+}
+static int mouse0_write(void *h, const void *b, size_t c, u64 o){
+ (void)h;(void)b;(void)c;(void)o; return -1;
+}
+
+static int mouse0_read(void *handle, void *buf, size_t count, u64 offset) {
+ (void)handle; (void)offset;
+ size_t esz = sizeof(mouse_event_t);
+ size_t written = 0;
+ u8 *out = (u8 *)buf;
+ while (written + esz <= count && mouse_has_event()) {
+ mouse_event_t ev;
+ if (mouse_get_event(&ev)) {
+ u8 *src = (u8 *)&ev;
+ for (size_t i = 0; i < esz; i++) out[written + i] = src[i];
+ written += esz;
+ }
+ }
+ return (int)written;
+}
+
+driver_module mouse0_module = {
+ .name = MS0NAME,
+ .mount = MS0PATH,
+ .version = MS0UNIVERSAL,
+ .init = mouse0_init,
+ .fini = mouse0_fini,
+ .open = mouse0_open,
+ .read = mouse0_read,
+ .write = mouse0_write,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/input/mouse0.h b/src/kernel/devices/input/mouse0.h
new file mode 100644
index 0000000..17356e4
--- /dev/null
+++ b/src/kernel/devices/input/mouse0.h
@@ -0,0 +1,9 @@
+#ifndef DEVICE_MOUSE0_H
+#define DEVICE_MOUSE0_H
+
+#include
+
+// /dev/input/mouse0
+extern driver_module mouse0_module;
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/devices/null/null.c b/src/kernel/devices/null/null.c
new file mode 100644
index 0000000..91ff4a9
--- /dev/null
+++ b/src/kernel/devices/null/null.c
@@ -0,0 +1,38 @@
+#include "null.h"
+#include
+#include
+#include
+#include
+
+static int null_mod_init(void) {
+ log("[NULL]", "init /dev/null\n", d);
+ return 0;
+}
+
+static void null_mod_fini(void) {}
+
+static void *null_open(const char *path) {
+ (void)path;
+ return (void *)1;
+}
+
+static int null_read(void *handle, void *buf, size_t count, u64 offset) {
+ (void)handle; (void)buf; (void)count; (void)offset;
+ // eof
+ return 0;
+}
+static int null_write(void *handle, const void *buf, size_t count, u64 offset) {
+ (void)handle; (void)buf; (void)offset;
+ return (int)count;
+}
+
+driver_module null_module = {
+ .name = NULNAME,
+ .mount = NULPATH,
+ .version = NULUNIVERSAL,
+ .init = null_mod_init,
+ .fini = null_mod_fini,
+ .open = null_open,
+ .read = null_read,
+ .write = null_write,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/null/null.h b/src/kernel/devices/null/null.h
new file mode 100644
index 0000000..fd9b270
--- /dev/null
+++ b/src/kernel/devices/null/null.h
@@ -0,0 +1,9 @@
+#ifndef DEVICE_NULL_H
+#define DEVICE_NULL_H
+
+#include
+
+// /dev/null device module
+extern driver_module null_module;
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/devices/random/random.c b/src/kernel/devices/random/random.c
new file mode 100644
index 0000000..60564b0
--- /dev/null
+++ b/src/kernel/devices/random/random.c
@@ -0,0 +1,29 @@
+#include "random.h"
+#include "urandom.h"
+#include
+#include
+#include
+#include
+
+//
+// for now random is just a alias from urandom
+// cuz a real random would be way harder
+//
+
+static int random_init(void) {
+ log("[RAND]", "init /dev/random (alias of urandom)\n", d);
+ return 0;
+}
+
+static void random_fini(void) {}
+
+driver_module random_module = {
+ .name = RNDNAME,
+ .mount = RNDPATH,
+ .version = RNDUNIVERSAL,
+ .init = random_init,
+ .fini = random_fini,
+ .open = urandom_open_fn,
+ .read = urandom_read_fn,
+ .write = urandom_write_fn,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/random/random.h b/src/kernel/devices/random/random.h
new file mode 100644
index 0000000..467e8c7
--- /dev/null
+++ b/src/kernel/devices/random/random.h
@@ -0,0 +1,9 @@
+#ifndef DEVICE_RANDOM_H
+#define DEVICE_RANDOM_H
+
+#include
+
+// /dev/random
+extern driver_module random_module;
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/devices/random/urandom.c b/src/kernel/devices/random/urandom.c
new file mode 100644
index 0000000..89dc37c
--- /dev/null
+++ b/src/kernel/devices/random/urandom.c
@@ -0,0 +1,98 @@
+#include "urandom.h"
+
+#include
+#include
+#include
+#include
+#include
+
+//
+// Xorshift64 PRNG
+//
+
+static u64 xr_state = 0; // 0 means "not seeded yet"
+
+static inline u64 rdtsc(void) {
+ u32 lo, hi;
+ __asm__ volatile("rdtsc" : "=a"(lo), "=d"(hi));
+ return ((u64)hi << 32) | lo;
+}
+
+static u64 xorshift64(void) {
+ //https://en.wikipedia.org/wiki/Xorshift
+ // https://github.com/jj1bdx/xorshiftplus-c/blob/master/xorshift64star.c
+ if (xr_state == 0) {
+ xr_state = rdtsc();
+ if (xr_state == 0) xr_state = 0xDEADBEEFCAFEBABEULL; // fallback
+ }
+ u64 x = xr_state;
+ x ^= x << 13;
+ x ^= x >> 7;
+ x ^= x << 17;
+ xr_state = x;
+ return x;
+}
+
+static int urandom_init(void) {
+ log("[URND]", "init /dev/urandom\n", d);
+ // pre-seed from RDTSC so state is ready
+ xr_state = rdtsc();
+ if (xr_state == 0) xr_state = 0xDEADBEEFCAFEBABEULL;
+ return 0;
+}
+
+static void urandom_fini(void) {}
+
+// /dev/random will just alias those next 3
+void *urandom_open_fn(const char *path) {
+ (void)path;
+ return (void *)1;
+}
+
+int urandom_read_fn(void *handle, void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)offset;
+ u8 *out = (u8 *)buf;
+ size_t i = 0;
+
+ // fill 8 bytes at a time then handle tail
+ while (i + 8 <= count) {
+ u64 r = xorshift64();
+ out[i+0] = (u8)(r);
+ out[i+1] = (u8)(r >> 8);
+ out[i+2] = (u8)(r >> 16);
+ out[i+3] = (u8)(r >> 24);
+ out[i+4] = (u8)(r >> 32);
+ out[i+5] = (u8)(r >> 40);
+ out[i+6] = (u8)(r >> 48);
+ out[i+7] = (u8)(r >> 56);
+ i += 8;
+ }
+ if (i < count) {
+ u64 r = xorshift64();
+ while (i < count) {
+ out[i++] = (u8)(r & 0xFF);
+ r >>= 8;
+ }
+ }
+ return (int)count;
+}
+
+int urandom_write_fn(void *handle, const void *buf, size_t count, u64 offset) {
+ // accept writes mb for future
+ (void)handle;
+ (void)buf;
+ (void)offset;
+ return (int)count;
+}
+
+driver_module urandom_module = {
+ .name = URNDNAME,
+ .mount = URNDPATH,
+ .version = URNDUNIVERSAL,
+ .init = urandom_init,
+ .fini = urandom_fini,
+ .open = urandom_open_fn,
+ .read = urandom_read_fn,
+ .write = urandom_write_fn,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/random/urandom.h b/src/kernel/devices/random/urandom.h
new file mode 100644
index 0000000..e4d06e8
--- /dev/null
+++ b/src/kernel/devices/random/urandom.h
@@ -0,0 +1,14 @@
+#ifndef DEVICE_URANDOM_H
+#define DEVICE_URANDOM_H
+
+#include
+
+// /dev/urandom
+extern driver_module urandom_module;
+
+// shared with /dev/random alias
+void *urandom_open_fn(const char *path);
+int urandom_read_fn(void *handle, void *buf, size_t count, u64 offset);
+int urandom_write_fn(void *handle, const void *buf, size_t count, u64 offset);
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/devices/tty/tty0.c b/src/kernel/devices/tty/tty0.c
new file mode 100644
index 0000000..8e8448e
--- /dev/null
+++ b/src/kernel/devices/tty/tty0.c
@@ -0,0 +1,222 @@
+#include "tty0.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+typedef enum {
+ ANSI_NORMAL = 0,
+ ANSI_ESC, // got \033
+ ANSI_CSI, // got \033[
+} tty0_ansi_state_t;
+
+static tty0_ansi_state_t ansi_state = ANSI_NORMAL;
+static int ansi_param = 0;
+static u32 ansi_fg = 0xFFFFFFFF; // default white
+static u32 ansi_bg = 0xFF000000;
+
+static u32 tty0_ansi_color(int code) {
+ switch (code) {
+ case 0: return 0xFFFFFFFF; // reset
+ case 30: return 0xFF111111; // black
+ case 31: return 0xFFFF5555; // red
+ case 32: return 0xFF55FF55; // green
+ case 33: return 0xFFFFFF55; // yellow
+ case 34: return 0xFF5555FF; // blue
+ case 35: return 0xFFFF55FF; // magenta
+ case 36: return 0xFF55FFFF; // cyan
+ case 37: return 0xFFFFFFFF; // white
+ case 90: return 0xFF888888; // bright black/gray
+ case 91: return 0xFFFF8888; // bright red
+ case 92: return 0xFF88FF88; // bright green
+ case 93: return 0xFFFFFF88; // bright yellow
+ case 94: return 0xFF8888FF; // bright blue
+ case 95: return 0xFFFF88FF; // bright magenta
+ case 96: return 0xFF88FFFF; // bright cyan
+ case 97: return 0xFFFFFFFF; // bright white
+ default: return 0xFFFFFFFF;
+ }
+}
+
+void tty0_write_char(char c) {
+ char tmp[2] = { c, '\0' };
+ switch (ansi_state) {
+ case ANSI_NORMAL:
+ if (c == '\033') {
+ ansi_state = ANSI_ESC;
+ } else if (c == '\b') {
+ u32 char_width = fm_get_char_width() * font_scale;
+ u32 char_height = fm_get_char_height() * font_scale;
+ if (cursor_x >= char_width) {
+ cursor_x -= char_width;
+ draw_rect(cursor_x, cursor_y, char_width, char_height, ansi_bg);
+ // later the window-system/desktop-environment should handle that
+ }
+ } else {
+ cprintf(tmp, ansi_fg);
+ }
+ break;
+
+ case ANSI_ESC:
+ if (c == '[') {
+ ansi_state = ANSI_CSI;
+ ansi_param = 0;
+ } else {
+ cprintf("\033", ansi_fg);
+ cprintf(tmp, ansi_fg);
+ ansi_state = ANSI_NORMAL;
+ }
+ break;
+
+ case ANSI_CSI:
+ if (c >= '0' && c <= '9') {
+ ansi_param = ansi_param * 10 + (c - '0');
+ } else if (c == 'm') {
+ ansi_fg = tty0_ansi_color(ansi_param);
+ ansi_param = 0;
+ ansi_state = ANSI_NORMAL;
+ } else if (c == ';') {
+ ansi_fg = tty0_ansi_color(ansi_param);
+ ansi_param = 0;
+ // stay in CSI
+ } else {
+ ansi_param = 0;
+ ansi_state = ANSI_NORMAL;
+ }
+ break;
+ }
+}
+
+
+static int tty0_echo_mode = TTY_ECHO; // default == 0
+
+void tty0_set_echo_mode(int mode) { tty0_echo_mode = mode; }
+int tty0_get_echo_mode(void) { return tty0_echo_mode; }
+
+static int tty0_init(void) {
+ log("[TTY0]", "init /dev/tty0\n", d);
+ return 0;
+}
+
+static void tty0_fini(void) {}
+
+static void *tty0_open(const char *path) {
+ (void)path;
+ return (void *)1; // dummy handle
+}
+
+static int tty0_dev_write(void *handle, const void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)offset;
+ const char *p = (const char *)buf;
+ for (size_t i = 0; i < count; i++) {
+ tty0_write_char(p[i]);
+ }
+ return (int)count;
+}
+static int tty0_dev_read(void *handle, void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)offset;
+ if (!buf || count == 0) return 0;
+
+ char *out = (char *)buf;
+ size_t i = 0;
+
+ // lazyopen keyboard device fd once
+ static int kbd_fd = -1;
+ if (kbd_fd < 0) {
+ kbd_fd = fs_open(KEYBOARD0, O_RDONLY);
+ if (kbd_fd < 0) {
+ printf("[TTY0] read: cannot open " KEYBOARD0 "\n");
+ return -1;
+ }
+ }
+
+ __asm__ volatile("sti");
+
+ if (tty0_echo_mode == TTY_RAW) {
+ while (1) {
+ key_event_t event;
+ char c = (char)(event.keycode & 0xFF);
+ int n = fs_read(kbd_fd, &event, sizeof(key_event_t));
+
+ __asm__ volatile("hlt");
+ if (n != (int)sizeof(key_event_t)) continue;
+ if (!event.pressed) continue;
+ if (event.keycode == 0x09) c = '\t';
+ if (c == '\n' || c == '\r' || c == '\b' || c == '\t' ||
+ (c >= 0x20 && c <= 0x7E)) {
+ out[0] = (c == '\r') ? '\n' : c;
+
+ __asm__ volatile("cli");
+ return 1;
+ }
+ }
+ }
+
+ while (i < count - 1) {
+ key_event_t event;
+ int got = 0;
+
+ while (!got) {
+ __asm__ volatile("hlt");
+ int n = fs_read(kbd_fd, &event, sizeof(key_event_t));
+ if (n == (int)sizeof(key_event_t)) got = 1;
+ }
+
+ if (!event.pressed) continue;
+
+ char c = (char)(event.keycode & 0xFF);
+
+ if (c == '\n' || c == '\r') {
+ // always echo the newline so cursor moves to next line
+ tty0_write_char('\n');
+ out[i++] = '\n';
+ break;
+ }
+
+ if (c == '\b') {
+ if (i > 0) {
+ i--;
+ if (tty0_echo_mode != TTY_NOECHO)
+ tty0_write_char('\b');
+ }
+ continue;
+ }
+
+ if (c < 0x20 || c > 0x7E) continue;
+
+ // echo based on current mode
+ if (tty0_echo_mode == TTY_ECHO)
+ tty0_write_char(c);
+ else if (tty0_echo_mode == TTY_MASKECHO)
+ tty0_write_char('*');
+ // TTY_NOECHO == no output at all
+
+ out[i++] = c;
+ }
+
+ __asm__ volatile("cli");
+
+ out[i] = '\0';
+ return (int)i;
+}
+
+driver_module tty0_module = {
+ .name = TTY0NAME,
+ .mount = TTY0PATH,
+ .version = TTY0UNIVERSAL,
+ .init = tty0_init,
+ .fini = tty0_fini,
+ .open = tty0_open,
+ .read = tty0_dev_read,
+ .write = tty0_dev_write,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/tty/tty0.h b/src/kernel/devices/tty/tty0.h
new file mode 100644
index 0000000..19a0378
--- /dev/null
+++ b/src/kernel/devices/tty/tty0.h
@@ -0,0 +1,23 @@
+#ifndef DEVICE_TTY0_H
+#define DEVICE_TTY0_H
+
+#include
+
+#define KEYBOARD0 KBDPATH
+//#define MOUSE0 MS0PATH
+
+
+extern driver_module tty0_module;
+
+// ioctl request codes for tty
+#define TTY_ECHO 0 // normal echo
+#define TTY_NOECHO 1 // no echo at all
+#define TTY_MASKECHO 2
+#define TTY_RAW 3
+
+
+void tty0_write_char(char c);
+void tty0_set_echo_mode(int mode);
+int tty0_get_echo_mode(void);
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/devices/zero/zero.c b/src/kernel/devices/zero/zero.c
new file mode 100644
index 0000000..c3d5b45
--- /dev/null
+++ b/src/kernel/devices/zero/zero.c
@@ -0,0 +1,48 @@
+#include "zero.h"
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+static int zero_mod_init(void) {
+ log("[ZERO]", "init /dev/zero\n", d);
+ return 0;
+}
+
+static void zero_mod_fini(void) {}
+
+static void *zero_open(const char *path) {
+ (void)path;
+ return (void *)1;
+}
+
+// write buffer full with 0s
+static int zero_read(void *handle, void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)offset;
+ if (buf && count > 0) {
+ memset(buf, 0, count);
+ }
+ return (int)count;
+}
+
+static int zero_write(void *handle, const void *buf, size_t count, u64 offset) {
+ (void)handle;
+ (void)buf;
+ (void)offset;
+ return (int)count;
+}
+
+driver_module zero_module = {
+ .name = ZERNAME,
+ .mount = ZERPATH,
+ .version = ZERUNIVERSAL,
+ .init = zero_mod_init,
+ .fini = zero_mod_fini,
+ .open = zero_open,
+ .read = zero_read,
+ .write = zero_write,
+};
\ No newline at end of file
diff --git a/src/kernel/devices/zero/zero.h b/src/kernel/devices/zero/zero.h
new file mode 100644
index 0000000..7177c4e
--- /dev/null
+++ b/src/kernel/devices/zero/zero.h
@@ -0,0 +1,9 @@
+#ifndef DEVICE_ZERO_H
+#define DEVICE_ZERO_H
+
+#include
+
+// /dev/zero device module
+extern driver_module zero_module;
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/file_systems/fat32/fat32.c b/src/kernel/file_systems/fat32/fat32.c
index 8fd347d..e2c1ec5 100644
--- a/src/kernel/file_systems/fat32/fat32.c
+++ b/src/kernel/file_systems/fat32/fat32.c
@@ -461,7 +461,7 @@ int fat32_read(file_t* this_file, void* buffer, size_t size)
uint32_t skipped_clusters = (uint32_t)(this_file->readPos /
(bootSector.sectors_per_cluster * bootSector.bytes_per_sector));
- for(int i = 0; i < skipped_clusters; i++)
+ for(uint32_t i = 0; i < skipped_clusters; i++)
current_cluster = get_next_cluster(current_cluster);
uint32_t offset = this_file->readPos -
@@ -512,4 +512,4 @@ int fat32_test_write(void) {
log("[FAT32]", "finish\n", success);
return 0;
-}
+}
\ No newline at end of file
diff --git a/src/kernel/file_systems/vfs/devfs/devfs.c b/src/kernel/file_systems/vfs/devfs/devfs.c
index f84ea3d..6c185a1 100644
--- a/src/kernel/file_systems/vfs/devfs/devfs.c
+++ b/src/kernel/file_systems/vfs/devfs/devfs.c
@@ -32,14 +32,18 @@ static ssize_t devfs_read(fs_file *file, void *buf, size_t cnt) {
devfs_data *dev = (devfs_data*)file->node->priv;
if (!dev || !dev->mod || !dev->mod->read) return -1;
- return dev->mod->read(dev->handle, buf, cnt);
+ ssize_t n = dev->mod->read(dev->handle, buf, cnt, file->pos);
+ if (n > 0) file->pos += (u64)n;
+ return n;
}
static ssize_t devfs_write(fs_file *file, const void *buf, size_t cnt) {
devfs_data *dev = (devfs_data*)file->node->priv;
if (!dev || !dev->mod || !dev->mod->write) return -1;
- return dev->mod->write(dev->handle, buf, cnt);
+ ssize_t n = dev->mod->write(dev->handle, buf, cnt, file->pos);
+ if (n > 0) file->pos += (u64)n;
+ return n;
}
static fs_node* devfs_lookup(fs_node *dir, const char *name) {
@@ -56,14 +60,27 @@ static fs_node* devfs_lookup(fs_node *dir, const char *name) {
return NULL;
}
+// create a subdir inside a devfs dir (like /dev/input and so on)
+static int devfs_mkdir_node(fs_node *dir, const char *name) {
+ fs_node *sub = fs_mknode(name, FS_DIR);
+ if (!dir || !name) return -1;
+ if (devfs_lookup(dir, name)) return 0;
+ if (!sub) return -1;
+
+ sub->ops = dir->ops; // inherit devfs ops
+ fs_addchild(dir, sub);
+
+ return 0;
+}
+
static fs_ops devfs_ops = {
- .open = devfs_open,
- .close = devfs_close,
- .read = devfs_read,
- .write = devfs_write,
+ .open = devfs_open,
+ .close = devfs_close,
+ .read = devfs_read,
+ .write = devfs_write,
.lookup = devfs_lookup,
.create = NULL,
- .mkdir = NULL,
+ .mkdir = devfs_mkdir_node,
};
static int devfs_mount(const char *src, const char *tgt, fs_mnt *mnt) {
@@ -95,12 +112,14 @@ void devfs_register(void) {
//cannot be alone standing
// register a device driver module to devfs
+// "/dev/input/keyboard0" creates input/ subdir automatically
int devfs_register_device(driver_module *mod)
{
if (!mod || !devfs_root) return -1;
// extract device name from mount path
// "/dev/console" -> "console"
+ // "/dev/input/keyboard0" -> "input/keyboard0"
const char *path = mod->mount;
const char *name = path;
@@ -108,8 +127,38 @@ int devfs_register_device(driver_module *mod)
name = path + 5; // skip "/dev/"
}
- // check if already exists
- if (devfs_lookup(devfs_root, name)) {
+ // check if there is a subdir
+ const char *slash = NULL;
+ for (const char *p = name; *p; p++) {
+ if (*p == '/') { slash = p; break; }
+ }
+
+ fs_node *parent = devfs_root;
+
+ if (slash) {
+ // extract subdir name ("input")
+ char subdir[64];
+ int slen = slash - name;
+ if (slen <= 0 || slen >= 64) return -1;
+
+ for (int i = 0; i < slen; i++) subdir[i] = name[i];
+ subdir[slen] = '\0';
+
+ // find or create the subdir inside devfs root
+ fs_node *sub = devfs_lookup(devfs_root, subdir);
+ if (!sub) {
+ sub = fs_mknode(subdir, FS_DIR);
+ if (!sub) return -1;
+ sub->ops = &devfs_ops;
+ fs_addchild(devfs_root, sub);
+ }
+
+ parent = sub;
+ name = slash + 1; // device name after the slash
+ }
+
+ // check if already exists in target parent
+ if (devfs_lookup(parent, name)) {
return -1;
}
@@ -128,13 +177,13 @@ int devfs_register_device(driver_module *mod)
data->handle = NULL;
node->priv = data;
- node->ops = &devfs_ops;
+ node->ops = &devfs_ops;
- fs_addchild(devfs_root, node);
+ fs_addchild(parent, node);
log("[DEVFS]", "registered ", d);
- BOOTUP_PRINT(name,white());
- BOOTUP_PRINT("\n",white());
+ BOOTUP_PRINT(mod->mount, white());
+ BOOTUP_PRINT("\n", white());
return 0;
-}
+}
\ No newline at end of file
diff --git a/src/kernel/file_systems/vfs/procfs/procfs.c b/src/kernel/file_systems/vfs/procfs/procfs.c
new file mode 100644
index 0000000..a703251
--- /dev/null
+++ b/src/kernel/file_systems/vfs/procfs/procfs.c
@@ -0,0 +1,344 @@
+#include "../vfs.h"
+#include "procfs.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+//
+// procfs:
+// layout:
+// /proc//status
+// /proc//maps
+//
+
+#if ENABLE_ULIME
+extern ulime_t *ulime;
+#endif
+
+#define STATUS_MSG "status"
+#define MAPS_MSG "maps"
+
+static fs_node *procfs_root = NULL; // nothings mounted on start
+
+//
+// helpers
+//
+
+// convert a decimal string to u64
+static u64 procfs_atopid(const char *s) {
+ if (!s || *s == '\0') return 0;
+ u64 n = 0;
+ const char *p = s;
+ while (*p >= '0' && *p <= '9') {
+ n = n * 10 + (u64)(*p - '0');
+ p++;
+ }
+ // must consume the whole string
+ if (*p != '\0') return 0;
+ if (p == s) return 0;
+
+ return n;
+}
+static ulime_proc_t *procfs_find_pid(u64 pid) {
+ #if ENABLE_ULIME
+ if (!ulime) return NULL;
+ ulime_proc_t *proc = ulime->ptr_proc_list;
+ while (proc) {
+ if (proc->pid == pid) return proc;
+ proc = proc->next;
+ }
+ #else
+ (void)pid;
+ #endif
+ return NULL;
+}
+static const char *procfs_state_str(u64 state) {
+ // same as ulime procs
+ switch (state) {
+ case PROC_CREATED: return "CREATED";
+ case PROC_READY: return "READY";
+ case PROC_RUNNING: return "RUNNING";
+ case PROC_BLOCKED: return "BLOCKED";
+ case PROC_ZOMBIE: return "ZOMBIE";
+ default: return "UNKNOWN";
+ }
+}
+static char *procfs_gen_status(ulime_proc_t *proc, u64 *out_len)
+{
+ char *buf = (char *)klime_create((klime_t *)fs_klime, 256);
+ char tmp[32];
+ if (!buf) return NULL;
+
+ str_copy(buf, "name: ");
+ str_append(buf,(char *)proc->name);
+ str_append(buf,"\n");
+ str_append(buf,"pid: ");
+ tmp[0] = '\0';
+ str_append_uint(tmp, (u32)proc->pid);
+ str_append(buf, tmp);
+ str_append(buf, "\n");
+ str_append(buf,"state: ");
+ str_append(buf,procfs_state_str(proc->state));
+ str_append(buf,"\n");
+ str_append(buf,"priority: ");
+ tmp[0] = '\0';
+ str_append_uint(tmp, (u32)proc->priority);
+ str_append(buf,tmp);
+ str_append(buf,"\n");
+
+ *out_len = (u64)str_len(buf);
+ return buf;
+}
+static char *procfs_gen_maps(ulime_proc_t *proc, u64 *out_len)
+{
+ char *buf = (char *)klime_create((klime_t *)fs_klime, 256);
+ char tmp[32];
+ if (!buf) return NULL;
+
+ str_copy(buf, "heap: 0x");
+ str_from_hex(tmp, proc->heap_base);
+ str_append(buf,tmp);
+ str_append(buf," size: ");
+ tmp[0] = '\0';
+ str_append_uint(tmp, (u32)proc->heap_size);
+ str_append(buf,tmp);
+ str_append(buf,"\n");
+ str_append(buf,"stack: 0x");
+ str_from_hex(tmp, proc->stack_base);
+ str_append(buf, tmp);
+ str_append(buf," size: ");
+ tmp[0] = '\0';
+ str_append_uint(tmp, (u32)proc->stack_size);
+ str_append(buf,tmp);
+ str_append(buf,"\n");
+
+ *out_len = (u64)str_len(buf);
+ return buf;
+}
+static fs_node *procfs_mknode(const char *name, u8 type, u64 pid, u8 kind)
+{
+ fs_node *node = fs_mknode(name, type);
+ if (!node) return NULL;
+
+ procfs_data *data = (procfs_data *)klime_create((klime_t *)fs_klime, sizeof(procfs_data));
+ if (!data) return NULL;
+
+ data->pid = pid;
+ data->kind = kind;
+ data->buf = NULL;
+ data->len = 0;
+
+ node->priv = data;
+ return node;
+}
+
+// ops
+
+
+static int procfs_open(fs_node *node, fs_file *file)
+{
+ procfs_data *data = (procfs_data *)node->priv;
+ if (!data) return -1;
+
+ (void)file;
+
+ // generate content for file nodes on open
+ if (data->kind == PROCFS_KIND_STATUS || data->kind == PROCFS_KIND_MAPS) {
+ #if ENABLE_ULIME // why did i just make this enable_ulime...
+ // the problem it would take days to remove it its toooo deep in the system...
+ ulime_proc_t *proc = procfs_find_pid(data->pid);
+ if (!proc) return -1;
+
+ if (data->kind == PROCFS_KIND_STATUS) {
+ data->buf = procfs_gen_status(proc, &data->len);
+ } else {
+ data->buf = procfs_gen_maps(proc, &data->len);
+ }
+
+ if (!data->buf) return -1;
+ #else
+ data->buf = (char *)klime_create((klime_t *)fs_klime, 32);
+ if (!data->buf) return -1;
+ str_copy(data->buf, "ulime disabled\n");
+ data->len = (u64)str_len(data->buf);
+ #endif
+ }
+
+ return 0;
+}
+
+static int procfs_close(fs_file *file) {(void)file; return 0;}
+
+static ssize_t procfs_read(fs_file *file, void *buf, size_t cnt)
+{
+ fs_node *node = file->node;
+ procfs_data *data = (procfs_data *)node->priv;
+
+ // if dirs are not readable
+ if (!data || data->kind == PROCFS_KIND_ROOT || data->kind == PROCFS_KIND_DIR) return -1;
+ if (!data->buf) return 0;
+
+ // eof
+ if (file->pos >= data->len) return 0;
+
+ size_t to_read = cnt;
+ if (file->pos + to_read > data->len) {
+ to_read = data->len - file->pos;
+ }
+
+ memcpy(buf, data->buf + file->pos, to_read);
+ file->pos += to_read;
+
+ return (ssize_t)to_read;
+}
+static ssize_t procfs_write(fs_file *file, const void *buf, size_t cnt) {
+ {
+ (void)file;(void)buf;(void)cnt;
+ }
+ return -1;
+}
+static fs_node *procfs_lookup(fs_node *dir, const char *name)
+{
+ if (dir->type != FS_DIR) return NULL;
+
+ procfs_data *data = (procfs_data *)dir->priv;
+ if (!data) return NULL;
+
+ if (data->kind == PROCFS_KIND_ROOT) {
+ // /proc/ lookup - name must be a decimal pid
+ u64 pid = procfs_atopid(name);
+ if (pid == 0) return NULL;
+
+ // check the process actually exists
+ if (!procfs_find_pid(pid)) return NULL;
+
+ // build pid dir node
+ fs_node *piddir = procfs_mknode(name, FS_DIR, pid, PROCFS_KIND_DIR);
+ if (!piddir) return NULL;
+
+ piddir->ops = dir->ops;
+ return piddir;
+ }
+
+ if (data->kind == PROCFS_KIND_DIR)
+ {
+ // /proc//status or /proc//maps
+ u8 kind = 0;
+ if (str_equals(name, STATUS_MSG)) {
+ kind = PROCFS_KIND_STATUS;
+ } else if (str_equals(name, MAPS_MSG)) {
+ kind = PROCFS_KIND_MAPS;
+ } else {
+ return NULL;
+ }
+
+ fs_node *fnode = procfs_mknode(name, FS_FILE, data->pid, kind);
+ if (!fnode) return NULL;
+
+ fnode->ops = dir->ops;
+ return fnode;
+ }
+
+ return NULL;
+}
+static fs_ops procfs_ops;
+static fs_node* procfs_readdir(fs_node *dir) {
+ //(void)dir;
+
+ if (!dir || !dir->priv) return NULL;
+ procfs_data *data = (procfs_data *)dir->priv;
+
+ #if ENABLE_ULIME
+ if (data->kind == PROCFS_KIND_ROOT)
+ {
+ if (!ulime) return NULL;
+
+ fs_node *head = NULL;
+ fs_node *tail = NULL;
+ ulime_proc_t *proc = ulime->ptr_proc_list;
+
+ while (proc)
+ {
+ char pidstr[24];
+ u64 pid = proc->pid;
+ int ti = 0;
+ char tmp[24];
+
+ if (pid == 0) { pidstr[0] = '0'; pidstr[1] = '\0'; }
+ else {
+ while (pid > 0) { tmp[ti++] = '0' + (int)(pid % 10); pid /= 10; }
+ for (int i = 0; i < ti; i++) pidstr[i] = tmp[ti - 1 - i];
+ pidstr[ti] = '\0';
+ }
+
+ fs_node *n = procfs_mknode(pidstr, FS_DIR, proc->pid, PROCFS_KIND_DIR);
+
+ if (n) {
+ n->ops = &procfs_ops;
+ if (!head) head = n;
+ else tail->next = n;
+ tail = n;
+ }
+ proc = proc->next;
+ }
+ return head;
+ }
+ if (data->kind == PROCFS_KIND_DIR) {
+ fs_node *status = procfs_mknode(STATUS_MSG, FS_FILE, data->pid, PROCFS_KIND_STATUS);
+ fs_node *maps = procfs_mknode(MAPS_MSG, FS_FILE, data->pid, PROCFS_KIND_MAPS);
+
+ if (status) status->ops = &procfs_ops;
+ if (maps) maps->ops = &procfs_ops;
+ if (status && maps) status->next = maps;
+
+ return status ? status : maps;
+ }
+ #endif
+
+ return NULL;
+}
+
+static fs_ops procfs_ops = {
+ .open = procfs_open,
+ .close = procfs_close,
+ .read = procfs_read,
+ .write = procfs_write,
+ .lookup = procfs_lookup,
+ .create = NULL,
+ .mkdir = NULL,
+ .readdir = procfs_readdir,
+};
+
+//
+// mount
+//
+
+static int procfs_mount(const char *src, const char *tgt, fs_mnt *mnt) {
+ {
+ (void)src;(void)tgt;
+ }
+
+ fs_node *root = procfs_mknode("proc", FS_DIR, 0, PROCFS_KIND_ROOT);
+ if (!root) return -1;
+
+ root->ops = &procfs_ops;
+ mnt->root = root;
+ procfs_root = root;
+
+ return 0;
+}
+
+static fs_type procfs = {
+ .name = "procfs",
+ .mount = procfs_mount,
+ .ops = &procfs_ops,
+};
+
+// register procfs type
+void procfs_register(void) {
+ fs_register(&procfs);
+}
\ No newline at end of file
diff --git a/src/kernel/file_systems/vfs/procfs/procfs.h b/src/kernel/file_systems/vfs/procfs/procfs.h
new file mode 100644
index 0000000..ae061be
--- /dev/null
+++ b/src/kernel/file_systems/vfs/procfs/procfs.h
@@ -0,0 +1,22 @@
+#ifndef PROCFS_H
+#define PROCFS_H
+
+#include
+
+// node kinds stored in procfs_data.kind
+#define PROCFS_KIND_ROOT 0 // /proc itself
+#define PROCFS_KIND_DIR 1 // /proc/
+#define PROCFS_KIND_STATUS 2 // /proc//status
+#define PROCFS_KIND_MAPS 3 // /proc//maps
+
+// stored in node->priv for every procfs node
+typedef struct {
+ u64 pid;
+ u8 kind;
+ char *buf;
+ u64 len;
+} procfs_data;
+
+//void procfs_register(void);
+
+#endif
\ No newline at end of file
diff --git a/src/kernel/file_systems/vfs/sysfs/sysfs.c b/src/kernel/file_systems/vfs/sysfs/sysfs.c
new file mode 100644
index 0000000..439895b
--- /dev/null
+++ b/src/kernel/file_systems/vfs/sysfs/sysfs.c
@@ -0,0 +1,108 @@
+#include "../vfs.h"
+#include "sysfs.h"
+#include
+#include
+#include
+#include
+#include
+
+
+static fs_node* sysfs_lookup(fs_node *dir, const char *name);
+
+static fs_ops sysfs_ops = {
+ .open = NULL,
+ .close = NULL,
+ .read = NULL,
+ .write = NULL,
+ .lookup = sysfs_lookup,
+ .create = NULL,
+ .mkdir = NULL,
+};
+
+static fs_node* sysfs_make_block(void)
+{
+ fs_node *block = fs_mknode("block", FS_DIR);
+ if (!block) return NULL;
+ block->ops = &sysfs_ops;
+
+ int count = ATAget_device_count();
+ fs_node *tail = NULL;
+ for (int i = 0; i < count; i++)
+ {
+ char devname[4];
+ devname[0] = 'h';
+ devname[1] = 'd';
+ devname[2] = (char)('a' + i);
+ devname[3] = '\0';
+
+ fs_node *n = fs_mknode(devname, FS_DIR);
+ if (!n) continue;
+ n->ops = &sysfs_ops;
+
+ if (!block->children) block->children = n;
+ else tail->next = n;
+ tail = n;
+ }
+ return block;
+}
+
+static fs_node* sysfs_lookup(fs_node *dir, const char *name)
+{
+ if (!dir || !name) return NULL;
+
+ // /sys > "block"
+ if (str_equals(dir->name, "sys")) {
+ if (str_equals(name, "block"))
+ return sysfs_make_block();
+ return NULL;
+ }
+
+ // /sys/block
+ if (str_equals(dir->name, "block"))
+ {
+ int count = ATAget_device_count();
+ for (int i = 0; i < count; i++) {
+ char devname[4];
+ devname[0] = 'h';
+ devname[1] = 'd';
+ devname[2] = (char)('a' + i);
+ devname[3] = '\0';
+ if (str_equals(name, devname)) {
+ fs_node *n = fs_mknode(devname, FS_DIR);
+ if (!n) return NULL;
+ n->ops = &sysfs_ops;
+ return n;
+ }
+ }
+ return NULL;
+ }
+ return NULL;
+}
+
+static int sysfs_mount(const char *src, const char *tgt, fs_mnt *mnt)
+{
+ (void)src;
+ (void)tgt;
+
+ fs_node *root = fs_mknode("sys", FS_DIR);
+ if (!root) return -1;
+ root->ops = &sysfs_ops;
+ root->children = sysfs_make_block();
+ mnt->root = root;
+
+ return 0;
+}
+
+static fs_type sysfs_type = {
+ .name = "sysfs",
+ .mount = sysfs_mount,
+ .ops = &sysfs_ops,
+};
+
+void sysfs_register(void) {
+ fs_register(&sysfs_type);
+}
+
+void sysfs_refresh(void) {
+ extern fs_mnt *fs_get_mount(const char *path);
+}
\ No newline at end of file
diff --git a/src/kernel/file_systems/vfs/sysfs/sysfs.h b/src/kernel/file_systems/vfs/sysfs/sysfs.h
new file mode 100644
index 0000000..a3085f1
--- /dev/null
+++ b/src/kernel/file_systems/vfs/sysfs/sysfs.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void sysfs_register(void);
+void sysfs_refresh(void);
\ No newline at end of file
diff --git a/src/kernel/file_systems/vfs/vfs.c b/src/kernel/file_systems/vfs/vfs.c
index 248f359..66c7cb2 100644
--- a/src/kernel/file_systems/vfs/vfs.c
+++ b/src/kernel/file_systems/vfs/vfs.c
@@ -196,6 +196,39 @@ int fs_addchild(fs_node *parent, fs_node *child) {
return 0;
}
+int fs_listdir(const char *path, _emx_kdirent_t *buf, int max_entries) {
+ fs_node *node = fs_resolve(path);
+ if (!node || node->type != FS_DIR) return -1;
+
+ fs_node *children = NULL;
+ if (node->ops && node->ops->readdir)
+ children = node->ops->readdir(node);
+ else
+ children = node->children;
+
+ int count = 0;
+ fs_node *child = children;
+
+ while (child && count < max_entries) {
+ buf[count].type = child->type;
+ // FS_FILE=0x01
+ // FS_DIR=0x02
+ // FS_DEV=0x04
+
+ // copy name safely
+ int i = 0;
+ while (i < 63 && child->name[i]) {
+ buf[count].name[i] = child->name[i];
+ i++;
+ }
+ buf[count].name[i] = '\0';
+
+ count++;
+ child = child->next;
+ }
+
+ return count;
+}
//
// main init
diff --git a/src/kernel/file_systems/vfs/vfs.h b/src/kernel/file_systems/vfs/vfs.h
index 55718ac..d8a8b8f 100644
--- a/src/kernel/file_systems/vfs/vfs.h
+++ b/src/kernel/file_systems/vfs/vfs.h
@@ -58,14 +58,17 @@ struct fs_file {
u64 pos;
u32 flags;
};
+typedef struct {
+ u8 type;
+ char name[64];
+} _emx_kdirent_t;
// operations
struct fs_ops {
int (*open)(fs_node *node, fs_file *file);
int (*close)(fs_file *file);
- ssize_t (*read)(fs_file *file, void *buf, size_t cnt); // read
- ssize_t (*write)(fs_file *file, const void *buf, size_t cnt); // write
- // could be used for syscalls
+ ssize_t (*read)(fs_file *file, void *buf, size_t cnt);
+ ssize_t (*write)(fs_file *file, const void *buf, size_t cnt);
fs_node* (*lookup)(fs_node *dir, const char *name);
int (*create)(fs_node *dir, const char *name);
@@ -74,6 +77,9 @@ struct fs_ops {
//tmpfs using ram
// devfs using modules/modules...
// ... maybe writing on disk
+
+
+ fs_node* (*readdir)(fs_node *dir);
};
// filesystem type
@@ -116,6 +122,7 @@ int fs_close(int fd);
ssize_t fs_read(int fd, void *buf, size_t cnt);
ssize_t fs_write(int fd, const void *buf, size_t cnt);
int fs_mkdir(const char *path);
+int fs_listdir(const char *path, _emx_kdirent_t *buf, int max_entries);
// global klime pointer (shared by all fs types)
extern void *fs_klime;
@@ -142,4 +149,6 @@ typedef struct {
void devfs_register(void);
int devfs_register_device(driver_module *mod);
+void procfs_register(void);
+
#endif
diff --git a/src/kernel/file_systems/vfs/vfs_init.c b/src/kernel/file_systems/vfs/vfs_init.c
index 9465c4e..576fe33 100644
--- a/src/kernel/file_systems/vfs/vfs_init.c
+++ b/src/kernel/file_systems/vfs/vfs_init.c
@@ -1,6 +1,8 @@
-#include "init.h"
+//#include "init.h"
+#include
+#include
int init_boot_log = -1;
-char *logpath = "/emr/logs/log1.txt";
+char *logpath = "/emr/system/logs/log1.txt";
#include "vfs.h"
#include
#include
@@ -129,26 +131,18 @@ void fs_system_init(void *klime)
// register fs types
tmpfs_register();
devfs_register();
+ procfs_register();
+ sysfs_register();
log("[FS]", "mounting roots: \n", white());
- // mount root as tmpfs
- fs_mount(NULL, ROOT_MOUNT_DEFAULT, ROOTFS); // in future its just root so for (fat32,ext2,...)
- //fs_mount(NULL, "/", "/"); // or root
+ // mount file systems
+ fs_mount(NULL, ROOT_MOUNT_DEFAULT, ROOTFS);
+ fs_mount(NULL, DEV_MOUNT_DEFAULT, DEVFS);
+ fs_mount(NULL, PROC_MOUNT_DEFAULT, PROCFS);
+ //fs_mount(NULL, SYS_MOUNT_DEFAULT, SYSFS);
- // create standard dirs
- fs_mkdir(DEV_DIRECTORY);
- fs_mkdir(TMP_DIRECTORY);
- fs_mkdir(BOOT_DIRECTORY);
- //emx system requirement paths
- fs_mkdir(EMX_DIRECTORY); // /emr
- fs_mkdir(EMLOG_DIRECTORY);
- fs_mkdir(EMAST_DIRECTORY);
- fs_mkdir(EMCFG_DIRECTORY);
- fs_mkdir(KEYMP_DIRECTORY);
- fs_mkdir(EMDRV_DIRECTORY);
-
- fs_mkdir(CONF_DIRECTORY);
+ initvfs();
init_boot_log = fs_open(logpath, O_CREAT | O_WRONLY);
log("[FS]", "[FS] wrote", d);
@@ -157,18 +151,9 @@ void fs_system_init(void *klime)
panic("Cannot open [logs]");
}
BOOTUP_PRINT("\n", white());
- //TODO: bootconf loading from /boot/bootconf
- // in shared/theme/bootconf file
-
- //fs_check_bootconf();
- //fs_load_bootconf();
-
- // mount devfs at /dev
- fs_mount(NULL, DEV_MOUNT_DEFAULT, DEVFS);
//last thing for init is loading all limine modules
load_limine_module(); // logo
-
}
void fs_register_mods()
diff --git a/src/kernel/graph/draw.c b/src/kernel/graph/draw.c
index ac954ab..a41d23e 100644
--- a/src/kernel/graph/draw.c
+++ b/src/kernel/graph/draw.c
@@ -3,11 +3,11 @@
void draw_rect(u32 x, u32 y, u32 width, u32 height, u32 color)
{
- for (u32 dy = 0; dy < height; dy++)
- {
- for (u32 dx = 0; dx < width; dx++)
- {
- putpixel(x + dx, y + dy, color);
+ u32 pitch_dwords = fb_pitch / 4;
+ for (u32 dy = 0; dy < height; dy++) {
+ u32 *row = framebuffer + (y + dy) * pitch_dwords + x;
+ for (u32 dx = 0; dx < width; dx++) {
+ row[dx] = color;
}
}
}
diff --git a/src/kernel/graph/graphics.c b/src/kernel/graph/graphics.c
index 1d239f5..68ba1d9 100644
--- a/src/kernel/graph/graphics.c
+++ b/src/kernel/graph/graphics.c
@@ -49,29 +49,37 @@ void clear(u32 color)
u32 w = get_fb_width();
u32 h = get_fb_height();
draw_rect(0, 0, w, h, color);
- reset_cursor();
- print(" ", GFX_BG);
+ //reset_cursor();
+ cursor_y = 0;
+ cursor_x = 0;
+ //print(" ", GFX_BG);
+ // OH WHY DID I PUT THIS HERE MONTHS AGO I WONDERED WHERE THE RANDOM SPACE CAME FROM............. :(
}
void scroll_up(u32 lines)
{
u32 pixels_to_scroll = lines;
u32 pitch_dwords = fb_pitch / 4;
-
- // Move framebuffer content up
- for (u32 y = pixels_to_scroll; y < fb_height; y++) {
- for (u32 x = 0; x < fb_width; x++) {
- framebuffer[(y - pixels_to_scroll) * pitch_dwords + x] =
- framebuffer[y * pitch_dwords + x];
- }
- }
-
- // Clear bottom lines
- for (u32 y = fb_height - pixels_to_scroll; y < fb_height; y++) {
- for (u32 x = 0; x < fb_width; x++) {
- framebuffer[y * pitch_dwords + x] = bg();
- }
- }
+ //u32 bytes_per_row = fb_width * sizeof(u32);
+ //u32 bg_color = black();
+
+ // move framebuffer content up
+ //for (u32 y = pixels_to_scroll; y < fb_height; y++) {
+ // memcpy(framebuffer + (y - pixels_to_scroll) * pitch_dwords,
+ // framebuffer + y * pitch_dwords,
+ // bytes_per_row);
+ //}
+
+ u32 *src = framebuffer + pixels_to_scroll * pitch_dwords;
+ u32 *dst = framebuffer;
+ size_t rows = fb_height - pixels_to_scroll;
+ memmove(dst, src, rows * pitch_dwords * sizeof(u32));
+
+ // clear bottom lines (bg is black = 0)
+ memset(
+ framebuffer + (fb_height - pixels_to_scroll) * pitch_dwords, 0,
+ pixels_to_scroll * pitch_dwords * sizeof(u32)
+ );
}
void putpixel(u32 x, u32 y, u32 color)
diff --git a/src/kernel/graph/graphics.h b/src/kernel/graph/graphics.h
index a6b5ce8..dbc3345 100644
--- a/src/kernel/graph/graphics.h
+++ b/src/kernel/graph/graphics.h
@@ -7,6 +7,7 @@
#include
#include
#include
+#include