-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
61 lines (53 loc) · 1.73 KB
/
Copy pathrun.py
File metadata and controls
61 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""XEKernelOS - QEMU launcher (floppy boot)"""
import os, sys, subprocess, shutil
BASE = os.path.dirname(os.path.abspath(__file__))
BLD = os.path.join(BASE, 'build')
def build():
if os.path.exists(BLD):
print("Cleaning old build...")
shutil.rmtree(BLD)
print("Building...")
r = subprocess.run(['make'], cwd=BASE)
if r.returncode != 0:
print("Build failed!")
sys.exit(1)
def ensure_disk():
path = os.path.join(BLD, 'disk.img')
print("Building FAT12 disk...")
import importlib.util
mkdisk = os.path.join(BASE, 'tools', 'mkdisk.py')
spec = importlib.util.spec_from_file_location("mkdisk", mkdisk)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
mod.build_disk(path)
# Expand to 4MB so font at LBA 2048 fits (needs ~2MB)
sz = os.path.getsize(path)
need = 4 * 1024 * 1024
if sz < need:
with open(path, 'ab') as f:
f.write(b'\x00' * (need - sz))
# Inject CJK font at LBA 2048
font_bin = os.path.join(BLD, 'font_cn.bin')
if os.path.exists(font_bin):
font_data = open(font_bin, 'rb').read()
with open(path, 'r+b') as f:
f.seek(2048 * 512)
f.write(font_data)
print(f"Font injected: {len(font_data)} bytes at LBA 2048")
else:
print("Warning: font_cn.bin not found, skipping")
def main():
build()
ensure_disk()
cmd = [
'qemu-system-i386',
'-hda', os.path.join(BLD, 'xekernelos.img'),
'-hdb', os.path.join(BLD, 'disk.img'),
'-m', '32',
'-boot', 'order=c',
'-serial', 'stdio',
]
print("XEKernelOS - Starting QEMU (hard disk boot)...")
subprocess.call(cmd)
if __name__ == '__main__':
main()