pyOS-kernel 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyos_kernel-0.1.0/LICENSE +21 -0
- pyos_kernel-0.1.0/MANIFEST.in +5 -0
- pyos_kernel-0.1.0/PKG-INFO +323 -0
- pyos_kernel-0.1.0/README.md +286 -0
- pyos_kernel-0.1.0/examples/advanced_os.py +76 -0
- pyos_kernel-0.1.0/examples/hello_world.py +40 -0
- pyos_kernel-0.1.0/examples/keyboard_input.py +42 -0
- pyos_kernel-0.1.0/pyOS_kernel.egg-info/PKG-INFO +323 -0
- pyos_kernel-0.1.0/pyOS_kernel.egg-info/SOURCES.txt +36 -0
- pyos_kernel-0.1.0/pyOS_kernel.egg-info/dependency_links.txt +1 -0
- pyos_kernel-0.1.0/pyOS_kernel.egg-info/entry_points.txt +2 -0
- pyos_kernel-0.1.0/pyOS_kernel.egg-info/requires.txt +6 -0
- pyos_kernel-0.1.0/pyOS_kernel.egg-info/top_level.txt +1 -0
- pyos_kernel-0.1.0/pyos/__init__.py +22 -0
- pyos_kernel-0.1.0/pyos/boot/__init__.py +3 -0
- pyos_kernel-0.1.0/pyos/boot/bootloader.asm +174 -0
- pyos_kernel-0.1.0/pyos/builder.py +177 -0
- pyos_kernel-0.1.0/pyos/cli.py +286 -0
- pyos_kernel-0.1.0/pyos/compiler/__init__.py +8 -0
- pyos_kernel-0.1.0/pyos/compiler/assembler.py +180 -0
- pyos_kernel-0.1.0/pyos/compiler/codegen.py +238 -0
- pyos_kernel-0.1.0/pyos/drivers/__init__.py +8 -0
- pyos_kernel-0.1.0/pyos/drivers/keyboard.py +319 -0
- pyos_kernel-0.1.0/pyos/drivers/screen.py +310 -0
- pyos_kernel-0.1.0/pyos/emulator.py +195 -0
- pyos_kernel-0.1.0/pyos/interrupts/__init__.py +8 -0
- pyos_kernel-0.1.0/pyos/interrupts/handler.py +237 -0
- pyos_kernel-0.1.0/pyos/interrupts/idt.py +165 -0
- pyos_kernel-0.1.0/pyos/kernel.py +288 -0
- pyos_kernel-0.1.0/pyos/memory/__init__.py +8 -0
- pyos_kernel-0.1.0/pyos/memory/gdt.py +295 -0
- pyos_kernel-0.1.0/pyos/memory/manager.py +397 -0
- pyos_kernel-0.1.0/pyos/syscalls/__init__.py +7 -0
- pyos_kernel-0.1.0/pyos/syscalls/handler.py +179 -0
- pyos_kernel-0.1.0/pyproject.toml +72 -0
- pyos_kernel-0.1.0/requirements.txt +1 -0
- pyos_kernel-0.1.0/setup.cfg +4 -0
- pyos_kernel-0.1.0/setup.py +19 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 i87kxxz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyOS-kernel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Build complete operating systems using Python - compiles to Assembly and Machine Code
|
|
5
|
+
Author-email: i87kxxz <i87kxxz@users.noreply.github.com>
|
|
6
|
+
Maintainer-email: i87kxxz <i87kxxz@users.noreply.github.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/i87kxxz/pyOS
|
|
9
|
+
Project-URL: Documentation, https://github.com/i87kxxz/pyOS#readme
|
|
10
|
+
Project-URL: Repository, https://github.com/i87kxxz/pyOS
|
|
11
|
+
Project-URL: Issues, https://github.com/i87kxxz/pyOS/issues
|
|
12
|
+
Keywords: operating-system,os,kernel,assembly,x86,bootloader,low-level,systems-programming,qemu,nasm
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Assembly
|
|
25
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
26
|
+
Classifier: Topic :: System :: Operating System Kernels
|
|
27
|
+
Classifier: Topic :: Education
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: click>=8.0.0
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# 🖥️ pyOS
|
|
39
|
+
|
|
40
|
+
**Build complete operating systems using Python.** Write your OS kernel in Python, and pyOS compiles it to Assembly and Machine Code that runs on real hardware.
|
|
41
|
+
|
|
42
|
+
[](https://www.python.org/downloads/)
|
|
43
|
+
[](https://opensource.org/licenses/MIT)
|
|
44
|
+
|
|
45
|
+
<p align="center">
|
|
46
|
+
<img src="https://raw.githubusercontent.com/pyos/pyos/main/docs/screenshot.png" alt="pyOS Screenshot" width="600">
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
## ✨ Features
|
|
50
|
+
|
|
51
|
+
- 🐍 **Write OS in Pure Python** - No Assembly knowledge required
|
|
52
|
+
- ⚡ **Compiles to Native Code** - Python → Assembly → Machine Code
|
|
53
|
+
- 🎨 **VGA Text Mode** - Full color support (16 colors)
|
|
54
|
+
- ⌨️ **Keyboard Support** - PS/2 keyboard driver included
|
|
55
|
+
- 🧠 **Memory Management** - GDT, heap allocation, stack management
|
|
56
|
+
- 🔧 **QEMU Integration** - Test your OS instantly
|
|
57
|
+
- 📦 **Easy Installation** - `pip install pyOS`
|
|
58
|
+
|
|
59
|
+
## 🚀 Quick Start
|
|
60
|
+
|
|
61
|
+
### Installation
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install pyOS
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Requirements:** NASM and QEMU
|
|
68
|
+
```bash
|
|
69
|
+
# Windows (with chocolatey)
|
|
70
|
+
choco install nasm qemu
|
|
71
|
+
|
|
72
|
+
# Linux
|
|
73
|
+
sudo apt install nasm qemu-system-x86
|
|
74
|
+
|
|
75
|
+
# macOS
|
|
76
|
+
brew install nasm qemu
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Hello World OS
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from pyos import Kernel, Screen
|
|
83
|
+
|
|
84
|
+
kernel = Kernel(arch="x86")
|
|
85
|
+
|
|
86
|
+
@kernel.on_boot
|
|
87
|
+
def main():
|
|
88
|
+
Screen.clear()
|
|
89
|
+
Screen.set_color("green", "black")
|
|
90
|
+
Screen.print("Hello World!")
|
|
91
|
+
Screen.print("Welcome to my OS!", row=1)
|
|
92
|
+
|
|
93
|
+
kernel.build("myos.iso")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Run Your OS
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
qemu-system-i386 -fda myos.iso
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 📖 Documentation
|
|
103
|
+
|
|
104
|
+
### Kernel
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from pyos import Kernel
|
|
108
|
+
|
|
109
|
+
# Create a kernel targeting x86 architecture
|
|
110
|
+
kernel = Kernel(
|
|
111
|
+
arch="x86", # or "x86_64"
|
|
112
|
+
stack_size=16384, # 16KB stack
|
|
113
|
+
heap_size=1048576, # 1MB heap
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
# Register boot functions with priority (lower = runs first)
|
|
117
|
+
@kernel.on_boot(priority=0)
|
|
118
|
+
def early_boot():
|
|
119
|
+
pass
|
|
120
|
+
|
|
121
|
+
@kernel.on_boot(priority=1)
|
|
122
|
+
def late_boot():
|
|
123
|
+
pass
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Screen (VGA Text Mode)
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from pyos import Screen
|
|
130
|
+
|
|
131
|
+
# Clear screen
|
|
132
|
+
Screen.clear()
|
|
133
|
+
|
|
134
|
+
# Set default colors
|
|
135
|
+
Screen.set_color("white", "blue")
|
|
136
|
+
|
|
137
|
+
# Print text
|
|
138
|
+
Screen.print("Hello!")
|
|
139
|
+
Screen.print("At position", row=5, col=10)
|
|
140
|
+
Screen.print("Colored text", color="red", background="black")
|
|
141
|
+
|
|
142
|
+
# Available colors:
|
|
143
|
+
# black, blue, green, cyan, red, magenta, brown, light_gray,
|
|
144
|
+
# dark_gray, light_blue, light_green, light_cyan, light_red,
|
|
145
|
+
# light_magenta, yellow, white
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Building & Running
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
# Build ISO image
|
|
152
|
+
kernel.build("myos.iso")
|
|
153
|
+
|
|
154
|
+
# Or build raw binary
|
|
155
|
+
kernel.build("myos.bin", format="bin")
|
|
156
|
+
|
|
157
|
+
# Generate Assembly only (for inspection)
|
|
158
|
+
asm_code = kernel.compile()
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## 🎯 Examples
|
|
162
|
+
|
|
163
|
+
### Multi-Stage Boot
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from pyos import Kernel, Screen
|
|
167
|
+
|
|
168
|
+
kernel = Kernel(arch="x86")
|
|
169
|
+
|
|
170
|
+
@kernel.on_boot(priority=0)
|
|
171
|
+
def init():
|
|
172
|
+
Screen.clear()
|
|
173
|
+
Screen.print("Initializing...", color="cyan")
|
|
174
|
+
|
|
175
|
+
@kernel.on_boot(priority=1)
|
|
176
|
+
def load_drivers():
|
|
177
|
+
Screen.print("[OK] Drivers loaded", row=1, color="green")
|
|
178
|
+
|
|
179
|
+
@kernel.on_boot(priority=2)
|
|
180
|
+
def ready():
|
|
181
|
+
Screen.print("System Ready!", row=3, color="yellow")
|
|
182
|
+
|
|
183
|
+
kernel.build("myos.iso")
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Colorful UI
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from pyos import Kernel, Screen
|
|
190
|
+
|
|
191
|
+
kernel = Kernel(arch="x86")
|
|
192
|
+
|
|
193
|
+
@kernel.on_boot
|
|
194
|
+
def main():
|
|
195
|
+
Screen.clear()
|
|
196
|
+
|
|
197
|
+
# Draw a header
|
|
198
|
+
Screen.set_color("white", "blue")
|
|
199
|
+
Screen.print("=" * 40, row=0)
|
|
200
|
+
Screen.print(" My Operating System v1.0", row=1)
|
|
201
|
+
Screen.print("=" * 40, row=2)
|
|
202
|
+
|
|
203
|
+
# System info
|
|
204
|
+
Screen.set_color("green", "black")
|
|
205
|
+
Screen.print("[OK] CPU initialized", row=4)
|
|
206
|
+
Screen.print("[OK] Memory ready", row=5)
|
|
207
|
+
|
|
208
|
+
# Footer
|
|
209
|
+
Screen.set_color("yellow", "black")
|
|
210
|
+
Screen.print("Press any key to continue...", row=10)
|
|
211
|
+
|
|
212
|
+
kernel.build("myos.iso")
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## 🏗️ Architecture
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
┌─────────────────────────────────────────────────────────┐
|
|
219
|
+
│ Your Python Code │
|
|
220
|
+
│ @kernel.on_boot │
|
|
221
|
+
│ def main(): │
|
|
222
|
+
│ Screen.print("Hello!") │
|
|
223
|
+
└─────────────────────────────────────────────────────────┘
|
|
224
|
+
│
|
|
225
|
+
▼
|
|
226
|
+
┌─────────────────────────────────────────────────────────┐
|
|
227
|
+
│ pyOS Compiler │
|
|
228
|
+
│ • Parses Python code │
|
|
229
|
+
│ • Captures screen/keyboard operations │
|
|
230
|
+
│ • Generates x86 Assembly │
|
|
231
|
+
└─────────────────────────────────────────────────────────┘
|
|
232
|
+
│
|
|
233
|
+
▼
|
|
234
|
+
┌─────────────────────────────────────────────────────────┐
|
|
235
|
+
│ NASM Assembler │
|
|
236
|
+
│ • Converts Assembly to Machine Code │
|
|
237
|
+
└─────────────────────────────────────────────────────────┘
|
|
238
|
+
│
|
|
239
|
+
▼
|
|
240
|
+
┌─────────────────────────────────────────────────────────┐
|
|
241
|
+
│ Bootable Image │
|
|
242
|
+
│ • Bootloader (512 bytes) │
|
|
243
|
+
│ • Kernel binary │
|
|
244
|
+
│ • Runs on QEMU or real hardware │
|
|
245
|
+
└─────────────────────────────────────────────────────────┘
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## 📁 Project Structure
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
pyOS/
|
|
252
|
+
├── pyos/
|
|
253
|
+
│ ├── __init__.py
|
|
254
|
+
│ ├── kernel.py # Kernel class and decorators
|
|
255
|
+
│ ├── builder.py # ISO/binary builder
|
|
256
|
+
│ ├── emulator.py # QEMU integration
|
|
257
|
+
│ ├── cli.py # Command-line interface
|
|
258
|
+
│ ├── compiler/
|
|
259
|
+
│ │ ├── codegen.py # Python → Assembly
|
|
260
|
+
│ │ └── assembler.py # Assembly → Machine Code
|
|
261
|
+
│ ├── drivers/
|
|
262
|
+
│ │ ├── screen.py # VGA text mode driver
|
|
263
|
+
│ │ └── keyboard.py # PS/2 keyboard driver
|
|
264
|
+
│ ├── memory/
|
|
265
|
+
│ │ ├── manager.py # Memory allocation
|
|
266
|
+
│ │ └── gdt.py # Global Descriptor Table
|
|
267
|
+
│ └── boot/
|
|
268
|
+
│ └── bootloader.asm # x86 bootloader
|
|
269
|
+
└── examples/
|
|
270
|
+
├── hello_world.py
|
|
271
|
+
├── keyboard_input.py
|
|
272
|
+
└── advanced_os.py
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## 🛠️ CLI Commands
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
# Create new project
|
|
279
|
+
pyos new myos
|
|
280
|
+
|
|
281
|
+
# Build OS
|
|
282
|
+
pyos build main.py -o myos.iso
|
|
283
|
+
|
|
284
|
+
# Run in QEMU
|
|
285
|
+
pyos run myos.iso
|
|
286
|
+
|
|
287
|
+
# Debug mode
|
|
288
|
+
pyos debug myos.iso
|
|
289
|
+
|
|
290
|
+
# Generate Assembly only
|
|
291
|
+
pyos asm main.py -o kernel.asm
|
|
292
|
+
|
|
293
|
+
# Check dependencies
|
|
294
|
+
pyos check
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## 🤝 Contributing
|
|
298
|
+
|
|
299
|
+
Contributions are welcome! Feel free to:
|
|
300
|
+
|
|
301
|
+
- 🐛 Report bugs
|
|
302
|
+
- 💡 Suggest features
|
|
303
|
+
- 🔧 Submit pull requests
|
|
304
|
+
|
|
305
|
+
## 📄 License
|
|
306
|
+
|
|
307
|
+
MIT License - feel free to use in your own projects!
|
|
308
|
+
|
|
309
|
+
## 🙏 Acknowledgments
|
|
310
|
+
|
|
311
|
+
- NASM - The Netwide Assembler
|
|
312
|
+
- QEMU - Open source machine emulator
|
|
313
|
+
- OSDev Wiki - Invaluable OS development resources
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
<p align="center">
|
|
318
|
+
Made with ❤️ for OS enthusiasts
|
|
319
|
+
</p>
|
|
320
|
+
|
|
321
|
+
<p align="center">
|
|
322
|
+
<b>Build your dream OS with Python!</b>
|
|
323
|
+
</p>
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# 🖥️ pyOS
|
|
2
|
+
|
|
3
|
+
**Build complete operating systems using Python.** Write your OS kernel in Python, and pyOS compiles it to Assembly and Machine Code that runs on real hardware.
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="https://raw.githubusercontent.com/pyos/pyos/main/docs/screenshot.png" alt="pyOS Screenshot" width="600">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
## ✨ Features
|
|
13
|
+
|
|
14
|
+
- 🐍 **Write OS in Pure Python** - No Assembly knowledge required
|
|
15
|
+
- ⚡ **Compiles to Native Code** - Python → Assembly → Machine Code
|
|
16
|
+
- 🎨 **VGA Text Mode** - Full color support (16 colors)
|
|
17
|
+
- ⌨️ **Keyboard Support** - PS/2 keyboard driver included
|
|
18
|
+
- 🧠 **Memory Management** - GDT, heap allocation, stack management
|
|
19
|
+
- 🔧 **QEMU Integration** - Test your OS instantly
|
|
20
|
+
- 📦 **Easy Installation** - `pip install pyOS`
|
|
21
|
+
|
|
22
|
+
## 🚀 Quick Start
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install pyOS
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Requirements:** NASM and QEMU
|
|
31
|
+
```bash
|
|
32
|
+
# Windows (with chocolatey)
|
|
33
|
+
choco install nasm qemu
|
|
34
|
+
|
|
35
|
+
# Linux
|
|
36
|
+
sudo apt install nasm qemu-system-x86
|
|
37
|
+
|
|
38
|
+
# macOS
|
|
39
|
+
brew install nasm qemu
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Hello World OS
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from pyos import Kernel, Screen
|
|
46
|
+
|
|
47
|
+
kernel = Kernel(arch="x86")
|
|
48
|
+
|
|
49
|
+
@kernel.on_boot
|
|
50
|
+
def main():
|
|
51
|
+
Screen.clear()
|
|
52
|
+
Screen.set_color("green", "black")
|
|
53
|
+
Screen.print("Hello World!")
|
|
54
|
+
Screen.print("Welcome to my OS!", row=1)
|
|
55
|
+
|
|
56
|
+
kernel.build("myos.iso")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Run Your OS
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
qemu-system-i386 -fda myos.iso
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 📖 Documentation
|
|
66
|
+
|
|
67
|
+
### Kernel
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from pyos import Kernel
|
|
71
|
+
|
|
72
|
+
# Create a kernel targeting x86 architecture
|
|
73
|
+
kernel = Kernel(
|
|
74
|
+
arch="x86", # or "x86_64"
|
|
75
|
+
stack_size=16384, # 16KB stack
|
|
76
|
+
heap_size=1048576, # 1MB heap
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Register boot functions with priority (lower = runs first)
|
|
80
|
+
@kernel.on_boot(priority=0)
|
|
81
|
+
def early_boot():
|
|
82
|
+
pass
|
|
83
|
+
|
|
84
|
+
@kernel.on_boot(priority=1)
|
|
85
|
+
def late_boot():
|
|
86
|
+
pass
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Screen (VGA Text Mode)
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from pyos import Screen
|
|
93
|
+
|
|
94
|
+
# Clear screen
|
|
95
|
+
Screen.clear()
|
|
96
|
+
|
|
97
|
+
# Set default colors
|
|
98
|
+
Screen.set_color("white", "blue")
|
|
99
|
+
|
|
100
|
+
# Print text
|
|
101
|
+
Screen.print("Hello!")
|
|
102
|
+
Screen.print("At position", row=5, col=10)
|
|
103
|
+
Screen.print("Colored text", color="red", background="black")
|
|
104
|
+
|
|
105
|
+
# Available colors:
|
|
106
|
+
# black, blue, green, cyan, red, magenta, brown, light_gray,
|
|
107
|
+
# dark_gray, light_blue, light_green, light_cyan, light_red,
|
|
108
|
+
# light_magenta, yellow, white
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Building & Running
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# Build ISO image
|
|
115
|
+
kernel.build("myos.iso")
|
|
116
|
+
|
|
117
|
+
# Or build raw binary
|
|
118
|
+
kernel.build("myos.bin", format="bin")
|
|
119
|
+
|
|
120
|
+
# Generate Assembly only (for inspection)
|
|
121
|
+
asm_code = kernel.compile()
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 🎯 Examples
|
|
125
|
+
|
|
126
|
+
### Multi-Stage Boot
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from pyos import Kernel, Screen
|
|
130
|
+
|
|
131
|
+
kernel = Kernel(arch="x86")
|
|
132
|
+
|
|
133
|
+
@kernel.on_boot(priority=0)
|
|
134
|
+
def init():
|
|
135
|
+
Screen.clear()
|
|
136
|
+
Screen.print("Initializing...", color="cyan")
|
|
137
|
+
|
|
138
|
+
@kernel.on_boot(priority=1)
|
|
139
|
+
def load_drivers():
|
|
140
|
+
Screen.print("[OK] Drivers loaded", row=1, color="green")
|
|
141
|
+
|
|
142
|
+
@kernel.on_boot(priority=2)
|
|
143
|
+
def ready():
|
|
144
|
+
Screen.print("System Ready!", row=3, color="yellow")
|
|
145
|
+
|
|
146
|
+
kernel.build("myos.iso")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Colorful UI
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from pyos import Kernel, Screen
|
|
153
|
+
|
|
154
|
+
kernel = Kernel(arch="x86")
|
|
155
|
+
|
|
156
|
+
@kernel.on_boot
|
|
157
|
+
def main():
|
|
158
|
+
Screen.clear()
|
|
159
|
+
|
|
160
|
+
# Draw a header
|
|
161
|
+
Screen.set_color("white", "blue")
|
|
162
|
+
Screen.print("=" * 40, row=0)
|
|
163
|
+
Screen.print(" My Operating System v1.0", row=1)
|
|
164
|
+
Screen.print("=" * 40, row=2)
|
|
165
|
+
|
|
166
|
+
# System info
|
|
167
|
+
Screen.set_color("green", "black")
|
|
168
|
+
Screen.print("[OK] CPU initialized", row=4)
|
|
169
|
+
Screen.print("[OK] Memory ready", row=5)
|
|
170
|
+
|
|
171
|
+
# Footer
|
|
172
|
+
Screen.set_color("yellow", "black")
|
|
173
|
+
Screen.print("Press any key to continue...", row=10)
|
|
174
|
+
|
|
175
|
+
kernel.build("myos.iso")
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## 🏗️ Architecture
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
┌─────────────────────────────────────────────────────────┐
|
|
182
|
+
│ Your Python Code │
|
|
183
|
+
│ @kernel.on_boot │
|
|
184
|
+
│ def main(): │
|
|
185
|
+
│ Screen.print("Hello!") │
|
|
186
|
+
└─────────────────────────────────────────────────────────┘
|
|
187
|
+
│
|
|
188
|
+
▼
|
|
189
|
+
┌─────────────────────────────────────────────────────────┐
|
|
190
|
+
│ pyOS Compiler │
|
|
191
|
+
│ • Parses Python code │
|
|
192
|
+
│ • Captures screen/keyboard operations │
|
|
193
|
+
│ • Generates x86 Assembly │
|
|
194
|
+
└─────────────────────────────────────────────────────────┘
|
|
195
|
+
│
|
|
196
|
+
▼
|
|
197
|
+
┌─────────────────────────────────────────────────────────┐
|
|
198
|
+
│ NASM Assembler │
|
|
199
|
+
│ • Converts Assembly to Machine Code │
|
|
200
|
+
└─────────────────────────────────────────────────────────┘
|
|
201
|
+
│
|
|
202
|
+
▼
|
|
203
|
+
┌─────────────────────────────────────────────────────────┐
|
|
204
|
+
│ Bootable Image │
|
|
205
|
+
│ • Bootloader (512 bytes) │
|
|
206
|
+
│ • Kernel binary │
|
|
207
|
+
│ • Runs on QEMU or real hardware │
|
|
208
|
+
└─────────────────────────────────────────────────────────┘
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 📁 Project Structure
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
pyOS/
|
|
215
|
+
├── pyos/
|
|
216
|
+
│ ├── __init__.py
|
|
217
|
+
│ ├── kernel.py # Kernel class and decorators
|
|
218
|
+
│ ├── builder.py # ISO/binary builder
|
|
219
|
+
│ ├── emulator.py # QEMU integration
|
|
220
|
+
│ ├── cli.py # Command-line interface
|
|
221
|
+
│ ├── compiler/
|
|
222
|
+
│ │ ├── codegen.py # Python → Assembly
|
|
223
|
+
│ │ └── assembler.py # Assembly → Machine Code
|
|
224
|
+
│ ├── drivers/
|
|
225
|
+
│ │ ├── screen.py # VGA text mode driver
|
|
226
|
+
│ │ └── keyboard.py # PS/2 keyboard driver
|
|
227
|
+
│ ├── memory/
|
|
228
|
+
│ │ ├── manager.py # Memory allocation
|
|
229
|
+
│ │ └── gdt.py # Global Descriptor Table
|
|
230
|
+
│ └── boot/
|
|
231
|
+
│ └── bootloader.asm # x86 bootloader
|
|
232
|
+
└── examples/
|
|
233
|
+
├── hello_world.py
|
|
234
|
+
├── keyboard_input.py
|
|
235
|
+
└── advanced_os.py
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 🛠️ CLI Commands
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
# Create new project
|
|
242
|
+
pyos new myos
|
|
243
|
+
|
|
244
|
+
# Build OS
|
|
245
|
+
pyos build main.py -o myos.iso
|
|
246
|
+
|
|
247
|
+
# Run in QEMU
|
|
248
|
+
pyos run myos.iso
|
|
249
|
+
|
|
250
|
+
# Debug mode
|
|
251
|
+
pyos debug myos.iso
|
|
252
|
+
|
|
253
|
+
# Generate Assembly only
|
|
254
|
+
pyos asm main.py -o kernel.asm
|
|
255
|
+
|
|
256
|
+
# Check dependencies
|
|
257
|
+
pyos check
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## 🤝 Contributing
|
|
261
|
+
|
|
262
|
+
Contributions are welcome! Feel free to:
|
|
263
|
+
|
|
264
|
+
- 🐛 Report bugs
|
|
265
|
+
- 💡 Suggest features
|
|
266
|
+
- 🔧 Submit pull requests
|
|
267
|
+
|
|
268
|
+
## 📄 License
|
|
269
|
+
|
|
270
|
+
MIT License - feel free to use in your own projects!
|
|
271
|
+
|
|
272
|
+
## 🙏 Acknowledgments
|
|
273
|
+
|
|
274
|
+
- NASM - The Netwide Assembler
|
|
275
|
+
- QEMU - Open source machine emulator
|
|
276
|
+
- OSDev Wiki - Invaluable OS development resources
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
<p align="center">
|
|
281
|
+
Made with ❤️ for OS enthusiasts
|
|
282
|
+
</p>
|
|
283
|
+
|
|
284
|
+
<p align="center">
|
|
285
|
+
<b>Build your dream OS with Python!</b>
|
|
286
|
+
</p>
|