- Tổng Quan
- Tính Năng
- Kiến Thức Nền Tảng
- Cách Thức Hoạt Động
- Cài Đặt và Chạy
- Cấu Trúc Dự Án
- Hướng Dẫn Sử Dụng
- Phát Triển
- Troubleshooting
- Credits
MyOS là một hệ điều hành đơn giản được phát triển từ đầu (từ kernel) bằng C++ và Assembly, chuyên biệt cho việc giải phương trình bậc 2. Dự án này được thiết kế như một công cụ học tập để hiểu về:
- Kernel Development: Phát triển kernel từ cơ bản
- Operating System Concepts: Các khái niệm hệ điều hành
- Low-level Programming: Lập trình mức thấp
- Hardware Interaction: Tương tác với phần cứng
- Giáo dục: Học về phát triển OS từ cơ bản
- Thực hành: Áp dụng kiến thức hệ điều hành
- Chuyên biệt: Tập trung vào một tính năng cụ thể (giải PT bậc 2)
- Cross-platform: Chạy được trên nhiều emulator/virtualizer
- Giải phương trình bậc 2: ax² + bx + c = 0
- Hỗ trợ số âm: Nhập được hệ số âm
- Kết quả chính xác: Tính toán với độ chính xác cao
- Validation: Kiểm tra dữ liệu đầu vào (a ≠ 0)
- Menu tiếng Việt: Giao diện hoàn toàn bằng tiếng Việt
- ASCII Art Logo: Logo đẹp mắt khi khởi động
- Navigation: Điều hướng bằng phím số
- Help System: Hệ thống trợ giúp tích hợp
- Kernel 32-bit: Kernel x86 32-bit
- Memory Management: Quản lý bộ nhớ tùy chỉnh
- Interrupt Handling: Xử lý ngắt phần cứng
- Keyboard Driver: Driver bàn phím tối ưu
- VGA Output: Xuất hình ảnh VGA text mode
- Monolithic Kernel: MyOS sử dụng kiến trúc kernel đơn khối
- Kernel Space vs User Space: Hiện tại chỉ có kernel space
- Boot Process: Quá trình khởi động từ bootloader đến kernel
class MemoryManager {
MemoryChunk* first;
void* malloc(size_t size);
void free(void* ptr);
};- Heap Management: Quản lý heap tùy chỉnh
- Memory Allocation: Cấp phát bộ nhớ động
- Fragmentation: Xử lý phân mảnh bộ nhớ
class Port8Bit {
uint16_t portnumber;
virtual uint8_t Read();
virtual void Write(uint8_t data);
};- Port I/O: Giao tiếp với hardware qua port
- Interrupt Handling: Xử lý ngắt từ keyboard
- Driver Model: Mô hình driver cho các thiết bị
.section .multiboot
.long 0x1BADB002
.long 0x00
.long -(0x1BADB002 + 0x00)- Multiboot Header: Tuân thủ Multiboot specification
- GDT Setup: Thiết lập Global Descriptor Table
- Interrupt Stubs: Assembly stubs cho interrupt handlers
- Classes and Objects: OOP design patterns
- Virtual Functions: Polymorphism cho drivers
- Operator Overloading: Custom new/delete operators
- Namespaces: Tổ chức code với namespaces
- BIOS/UEFI: Firmware khởi tạo hệ thống
- Bootloader (GRUB): Load kernel vào memory
- Kernel Entry: Chạy hàm
kernelMain() - Hardware Init: Khởi tạo GDT, IDT, Memory Manager
- Driver Loading: Load keyboard và VGA drivers
- Main Loop: Vào vòng lặp chính của OS
High Memory +------------------+
| Kernel Stack |
+------------------+
| Heap Space |
+------------------+
| Kernel Code |
+------------------+
Low Memory | Boot Sector |
+------------------+
void OnKeyDown(char c) {
switch(current_state) {
case MAIN_MENU:
handleMenuNavigation(c);
break;
case WAITING_A:
case WAITING_B:
case WAITING_C:
handleCoefficientInput(c);
break;
}
}QuadraticResult solveQuadratic(int32_t a, int32_t b, int32_t c) {
int32_t discriminant = b*b - 4*a*c;
if(discriminant < 0) {
result.hasRealRoots = false;
} else {
int32_t sqrt_disc = sqrt_int(discriminant);
result.x1_int = (-b + sqrt_disc) / (2*a);
result.x2_int = (-b - sqrt_disc) / (2*a);
// Handle fractional parts...
}
return result;
}sudo apt-get install build-essential
sudo apt-get install gcc-multilib g++-multilib
sudo apt-get install grub-legacy xorriso
sudo apt-get install qemu-system-x86brew install i686-elf-binutils # Assembler, linker, etc.
brew install i686-elf-gcc # C/C++ compiler
brew install qemu
brew install i686-elf-grub # GRUB bootloader
brew install xorriso # ISO 9660 filesystem
brew install mtools # MS-DOS filesystem tools- WSL2 với Ubuntu
- QEMU for Windows
- VirtualBox
git clone <repository-url>
cd wyoos-ptb2# Linux
make
# macOS
make build-macosmake clean # Dọn dẹp build files
make qemu # Build và chạy với QEMU
make qemu-debug # Chạy với debug mode
# Tạo ISO cho UTM
make utm
# Hoặc dùng qemu trực tiếp
qemu-system-i386 -cdrom mykernel.iso -m 256M- Architecture: i386
- Memory: 128MB - 256MB
- Boot: CD-ROM first
- Display: VGA
- Architecture: x86_64 (emulation)
- System: Standard PC (i440FX + PIIX)
- Memory: 256MB
- Boot Order: CD/DVD first
- Type: Other/Unknown
- Memory: 256MB
- Boot Order: CD/DVD first
- Enable VT-x/AMD-V: Yes
wyoos-ptb2/
├── src/ # Source code chính
│ ├── kernel.cpp # Kernel chính và logic ứng dụng
│ ├── gdt.cpp # Global Descriptor Table
│ ├── memorymanagement.cpp # Quản lý bộ nhớ
│ ├── multitasking.cpp # Đa nhiệm (hiện chưa dùng)
│ ├── syscalls.cpp # System calls
│ ├── loader.s # Assembly bootloader
│ ├── drivers/ # Hardware drivers
│ │ ├── driver.cpp # Base driver class
│ │ ├── keyboard.cpp # Keyboard driver
│ │ └── vga.cpp # VGA text mode driver
│ └── hardwarecommunication/ # Hardware communication
│ ├── interrupts.cpp # Interrupt management
│ ├── interruptstubs.s # Assembly interrupt stubs
│ └── port.cpp # Port I/O operations
├── include/ # Header files
│ ├── common/
│ │ └── types.h # Common type definitions
│ ├── drivers/
│ │ ├── driver.h
│ │ ├── keyboard.h
│ │ └── vga.h
│ ├── hardwarecommunication/
│ │ ├── interrupts.h
│ │ └── port.h
│ ├── gdt.h
│ ├── memorymanagement.h
│ ├── multitasking.h
│ └── syscalls.h
├── obj/ # Compiled object files
├── mykernel.bin # Kernel binary
├── mykernel.iso # Bootable ISO image
├── linker.ld # Linker script
├── makefile # Build configuration
└── README.md # This file
kernel.cpp: Logic chính, UI, toán họcgdt.cpp: Segment managementmemorymanagement.cpp: Dynamic memory allocationloader.s: Assembly entry point
keyboard.cpp: PS/2 keyboard driver với UTM compatibilityvga.cpp: VGA text mode (80x25, 16 colors)driver.cpp: Base class cho tất cả drivers
interrupts.cpp: IDT setup và interrupt routingport.cpp: Port I/O abstraction (inb/outb)
- 1: Giải phương trình bậc 2
- 2: Xem hướng dẫn
- 3: Thông tin phát triển
- 4: Thoát (QEMU only)
- ESC: Quay lại menu chính
- Số (0-9): Nhập chữ số
- - (dấu trừ): Hệ số âm (chỉ ở đầu)
- Enter: Xác nhận và chuyển hệ số tiếp theo
- Backspace: Xóa ký tự cuối
- ESC: Quay lại menu chính
- R: Giải phương trình mới
- ESC: Quay lại menu chính
- Hệ số a phải khác 0
- Có thể nhập số âm
- Nhấn Enter để xác nhận
- Có thể là 0, âm hoặc dương
- Nhấn Enter để tiếp tục
- Hệ số tự do
- Nhấn Enter để tính toán
- Delta > 0: Hai nghiệm phân biệt
- Delta = 0: Nghiệm kép
- Delta < 0: Vô nghiệm (phức)
Phương trình: x² - 5x + 6 = 0
Input: a = 1, b = -5, c = 6
Output: x₁ = 3, x₂ = 2
Phương trình: x² - 4x + 4 = 0
Input: a = 1, b = -4, c = 4
Output: x = 2 (nghiệm kép)
Phương trình: x² + x + 1 = 0
Input: a = 1, b = 1, c = 1
Output: Vô nghiệm thực
// Trong displayMainMenu()
printAt("5. Tinh nang moi", 30, 15, 0x0F);
// Trong KeyboardEventHandler
case '5':
current_state = NEW_FEATURE;
displayNewFeature();
break;class NewDriver : public Driver {
public:
void Activate();
int Reset();
};
// Trong kernelMain()
NewDriver newdriver(&interrupts);
drvManager.AddDriver(&newdriver);// Trong syscalls.cpp
void SYSCALL_NEW_FUNCTION() {
// Implementation
}# Test math functions
make test-math
# Test memory management
make test-memory
# Test drivers
make test-drivers# Chạy với debug symbols
make qemu-debug
# Kết nối GDB
gdb mykernel.bin
(gdb) target remote localhost:1234
(gdb) continue- Floating Point: Chưa hỗ trợ FPU, dùng fixed-point arithmetic
- Multi-threading: Chưa implement threading
- File System: Chưa có file system
- Network: Chưa hỗ trợ networking
# Đảm bảo có cross-compiler
which i686-elf-gcc
# Hoặc
which x86_64-elf-gcc# Fix permissions
chmod +x setup_scripts.sh
sudo make install-deps- UTM: Kiểm tra architecture (x86_64, không phải ARM)
- QEMU: Thử
-m 256Mthay vì 128M - VirtualBox: Enable VT-x/AMD-V
- Kiểm tra VM có USB controller
- UTM: Enable USB support in settings
- VirtualBox: Install Guest Additions
- Thử display settings khác
- UTM: Thử VGA thay vì virtio-gpu
- Increase video memory
// Thêm vào kernel.cpp
void serial_debug(const char* msg) {
Port8Bit serial(0x3F8);
while(*msg) {
serial.Write(*msg++);
}
}// Kiểm tra memory leaks
void debug_memory() {
printf("Active memory manager: ");
printf(MemoryManager::activeMemoryManager ? "OK" : "NULL");
}# Chạy QEMU với monitor
qemu-system-i386 -cdrom mykernel.iso -monitor stdio
# Commands trong QEMU monitor
(qemu) info registers
(qemu) info memory
(qemu) info interruptsGCCPARAMS += -O2 -ffast-math -funroll-loops// Pre-allocate large objects
static char buffer[4096];
// Thay vì malloc/free nhiều lần// Minimize work in interrupt handlers
uint32_t HandleInterrupt(uint32_t esp) {
// Process quickly
return esp;
}- Nhat: Kernel & Memory Management - MAIN.md
- Ngoc: Keyboard Driver & Input Handling - INPUT.md
- Sang: Mathematical Algorithms & Logic - LOGIC.md
- Minh: User Interface & Display - UI.md
- Quynh: Testing & Documentation - TESTING.md
- GCC Cross Compiler: i686-elf-gcc
- GNU Assembler: gas (GNU as)
- GNU Linker: ld
- GRUB: Bootloader
- QEMU: Emulator
- UTM: macOS virtualization
- Xorriso: ISO creation
MIT License - Chi tiết xem file LICENSE
Contributions welcome! Please read CONTRIBUTING.md for guidelines.
- Project Repository: [GitHub Link]
- Documentation: [Wiki Link]
- Issues: [Issues Link]
MyOS v2.0 - Hệ Điều Hành Giải Phương Trình Bậc 2
Được phát triển với ❤️ bởi nhóm sinh viên IT