Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
CC = gcc
CFLAGS = -O2 -g -Wall -Wextra -I./include -ffreestanding -nostdlib -fno-builtin
LDFLAGS = -nostdlib

KERNEL_OBJS = boot/boot.o \
boot/paging.o \
boot/context.o \
kernel/kernel.o \
system/init.o \
system/memory.o \
system/paging.o \
system/process.o \
system/filesystem.o \
system/fs_utils.o \
system/file_io.o \
system/package.o \
device/video.o \
device/keyboard.o \
shell/shell.o \
shell/shell_io.o \
shell/fs_commands.o \
shell/pkg_commands.o

C_OBJS = kernel/kernel.o \
system/init.o \
system/memory.o \
system/paging.o \
system/process.o \
system/filesystem.o \
system/fs_utils.o \
system/file_io.o \
system/package.o \
device/video.o \
device/keyboard.o \
shell/shell.o \
shell/shell_io.o \
shell/fs_commands.o \
shell/pkg_commands.o \
lib/string.o

.PHONY: all clean test

all: amethystos.bin

amethystos.bin: $(KERNEL_OBJS)
$(LD) $(LDFLAGS) -o $@ $^

%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

%.o: %.s
$(AS) $< -o $@

%.o: %.asm
nasm -f elf32 $< -o $@

clean:
rm -f $(KERNEL_OBJS) amethystos.bin

test: $(C_OBJS)
@echo "C files compiled successfully"
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# AmethystOS

AmethystOS is an educational operating system based on XINU architecture with an amethyst theme. This project serves as a learning platform for operating system concepts and implementation.

## Features

### Core System
- Custom bootloader with multiboot support
- Memory management with paging
- Process scheduling and context switching
- Interactive shell with command history
- Amethyst-themed UI elements

### Device Drivers
- VGA text mode driver with color support
- PS/2 keyboard driver with full layout support
- LED control (Caps Lock, Num Lock, Scroll Lock)
- Support for extended keyboard keys

### File System
- Hierarchical directory structure
- Basic file operations (create, read, write, delete)
- Directory operations (mkdir, rmdir, list)
- Path manipulation (absolute/relative paths)
- File permissions (read/write/execute)
- File descriptors for I/O operations

### Package Manager (amy)
The `amy` package manager provides basic software management:
- Package installation and removal
- Dependency management
- Package database
- Search functionality
- Package information display

Commands:
```
amy install <package> - Install a package
amy remove <package> - Remove a package
amy update [package] - Update packages
amy list - List installed packages
amy search <query> - Search for packages
amy info <package> - Show package information
```

### Shell Commands
- File Operations: ls, cd, pwd, mkdir, rmdir, touch, rm
- Process Management: ps, kill
- System Information: meminfo
- UI Customization: clear, color
- Package Management: amy

## Project Structure

- `boot/` - Bootloader and low-level initialization
- `kernel/` - Core kernel components
- `system/` - System services (memory, process, filesystem)
- `device/` - Device drivers
- `include/` - Header files
- `lib/` - Library functions
- `shell/` - Shell implementation
- `doc/` - Documentation

## Building

1. Prerequisites:
- GCC cross-compiler (i686-elf target)
- GNU Make
- NASM assembler
- GNU Binutils

2. Build Commands:
```sh
make # Build the operating system
make clean # Clean build files
```

## Development

The system is designed to be educational and extensible. Key components are modular and well-documented. The amethyst theme is consistently applied throughout the user interface.

### Adding New Features
1. Device Drivers: Add new files in `device/`
2. System Services: Implement in `system/`
3. Shell Commands: Add to `shell/`
4. Packages: Register in the package database

## License

MIT License

Copyright (c) 2025 AmethystOS

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
37 changes: 37 additions & 0 deletions boot.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
; Multiboot header for GRUB
MBALIGN equ 1 << 0
MEMINFO equ 1 << 1
FLAGS equ MBALIGN | MEMINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)

section .multiboot
align 4
dd MAGIC
dd FLAGS
dd CHECKSUM

section .bss
align 16
stack_bottom:
resb 16384 ; 16 KiB
stack_top:

section .text
global _start
_start:
mov esp, stack_top ; Set up stack

; Initialize processor state
cli ; Disable interrupts
cld ; Clear direction flag

; Call the kernel
extern kmain
call kmain

; If kernel returns, enter infinite loop
cli
.hang:
hlt
jmp .hang
Binary file added boot.o
Binary file not shown.
64 changes: 64 additions & 0 deletions context.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
; Context switching functionality
global context_switch

section .text

context_switch:
; Save current context if it exists
; old_context is in [esp + 4]
; new_context is in [esp + 8]

mov eax, [esp + 4] ; Get old_context
test eax, eax ; Check if NULL
jz load_new ; If NULL, just load new context

; Save current context
mov [eax + 0], ebx ; Save general purpose registers
mov [eax + 4], ecx
mov [eax + 8], edx
mov [eax + 12], esi ; Save index registers
mov [eax + 16], edi
mov [eax + 20], ebp ; Save base pointer

pushf ; Get flags
pop ecx
mov [eax + 28], ecx ; Save flags

mov ecx, cr3
mov [eax + 32], ecx ; Save page directory base

mov ecx, [esp] ; Get return address
mov [eax + 24], ecx ; Save as EIP

lea ecx, [esp + 4]
mov [eax + 36], ecx ; Save ESP

load_new:
; Load new context
mov eax, [esp + 8] ; Get new_context

; Load new page directory if different
mov ecx, [eax + 32] ; Get new CR3
mov edx, cr3
cmp ecx, edx
je .skip_cr3
mov cr3, ecx
.skip_cr3:

; Load registers
mov ebx, [eax + 0] ; Restore general purpose registers
mov ecx, [eax + 4]
mov edx, [eax + 8]
mov esi, [eax + 12] ; Restore index registers
mov edi, [eax + 16]
mov ebp, [eax + 20] ; Restore base pointer

; Load flags
push dword [eax + 28]
popf

; Set up new stack frame
mov esp, [eax + 36] ; Restore stack pointer
push dword [eax + 24] ; Push return address (EIP)

ret ; Jump to new context
Binary file added context.o
Binary file not shown.
Loading