-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_v3.ps1
More file actions
211 lines (190 loc) · 6.84 KB
/
build_v3.ps1
File metadata and controls
211 lines (190 loc) · 6.84 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# ToaruOS-Arnold V3 Build Script (Windows Native)
# "DO IT NOW" - The build system
#
# Prerequisites:
# - NASM (nasm.exe in PATH)
# - i686-elf cross-compiler toolchain (i686-elf-ld.exe, i686-elf-objcopy.exe)
# - ArnoldC-Native compiler JAR (Scala-based, requires Java 17+)
# - Java 17+ runtime (java.exe in PATH)
# - QEMU (optional, for -Run flag: qemu-system-i386.exe)
#
# Environment variables (optional overrides):
# $env:I686_ELF_LD - Path to i686-elf-ld.exe
# $env:I686_ELF_OBJCOPY - Path to i686-elf-objcopy.exe
# $env:ARNOLDC_JAR - Path to ArnoldC-Native.jar
# $env:NASM - Path to nasm.exe
# $env:QEMU - Path to qemu-system-i386.exe
param(
[switch]$Run,
[switch]$Clean
)
$ErrorActionPreference = "Stop"
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
# Tool paths with environment variable fallbacks
$NASM = if ($env:NASM) { $env:NASM } else { "nasm" }
$LD = if ($env:I686_ELF_LD) { $env:I686_ELF_LD } else { "C:\Users\Acer\i686-elf-tools\bin\i686-elf-ld.exe" }
$OBJCOPY = if ($env:I686_ELF_OBJCOPY) { $env:I686_ELF_OBJCOPY } else { "C:\Users\Acer\i686-elf-tools\bin\i686-elf-objcopy.exe" }
$JAVA = "java"
$ARNOLDC_JAR = if ($env:ARNOLDC_JAR) { $env:ARNOLDC_JAR } else { "C:\Users\Acer\Desktop\ArnoldC-Native\target\scala-2.13\ArnoldC-Native.jar" }
$QEMU = if ($env:QEMU) { $env:QEMU } else { "C:\Program Files\qemu\qemu-system-i386.exe" }
# Directories
$BUILD_DIR = "$ProjectRoot\build"
$GEN_DIR = "$BUILD_DIR\gen"
# Source files
$BOOT_ASM = "$ProjectRoot\boot\multiboot.asm"
$KERNEL_SRC = "$ProjectRoot\kernel\kernel_v3.arnoldc"
# Output files
$KERNEL_ELF = "$BUILD_DIR\toaruos-arnold.elf"
$KERNEL_BIN = "$BUILD_DIR\toaruos-arnold.bin"
if ($Clean) {
Write-Host "[CLEAN] Removing build artifacts - YOU'RE LUGGAGE"
Remove-Item -Path $BUILD_DIR -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "ERASED FROM EXISTENCE"
exit 0
}
# Create directories
Write-Host "[INIT] Creating directories - I NEED YOUR MEMORY"
New-Item -ItemType Directory -Path $BUILD_DIR -Force | Out-Null
New-Item -ItemType Directory -Path $GEN_DIR -Force | Out-Null
# Build modular kernel using merge_modules.ps1
Write-Host "[ARN ] Building modular kernel - I'LL BE BACK"
# Source files in merge order (kernel core + libraries + games)
# kernel_v3 must be LAST since it has the main function
$sourceFiles = @(
"$ProjectRoot\kernel\kernel_v3.arnoldc",
"$ProjectRoot\kernel\lib\random.arnoldc",
"$ProjectRoot\kernel\lib\timer.arnoldc",
"$ProjectRoot\kernel\lib\speaker.arnoldc",
"$ProjectRoot\kernel\games\snake.arnoldc",
"$ProjectRoot\kernel\games\pong.arnoldc",
"$ProjectRoot\kernel\games\breakout.arnoldc",
"$ProjectRoot\kernel\games\chopper.arnoldc",
"$ProjectRoot\kernel\games\memory.arnoldc",
"$ProjectRoot\kernel\games\skynet.arnoldc",
"$ProjectRoot\kernel\games\tictactoe.arnoldc",
"$ProjectRoot\kernel\window_manager.arnoldc",
"$ProjectRoot\kernel\terminal.arnoldc",
"$ProjectRoot\kernel\terminal_commands.arnoldc",
"$ProjectRoot\kernel\apps\calculator.arnoldc",
"$ProjectRoot\kernel\apps\about.arnoldc",
"$ProjectRoot\kernel\apps\settings.arnoldc",
"$ProjectRoot\kernel\apps\text_editor.arnoldc",
"$ProjectRoot\kernel\apps\file_manager.arnoldc",
"$ProjectRoot\kernel\apps\easter_eggs.arnoldc",
"$ProjectRoot\kernel\apps\context_menu.arnoldc"
)
& "$ProjectRoot\tools\merge_modules.ps1" `
-SourceFiles $sourceFiles `
-OutputFile "$GEN_DIR\kernel.arnoldc"
if (-not (Test-Path "$GEN_DIR\kernel.arnoldc")) { throw "Module merge failed!" }
# Compile ArnoldC to ASM (delete stale ASM first to prevent using cached build on failure)
Write-Host "[ARN ] Compiling ArnoldC - IT'S SHOWTIME"
Remove-Item "$GEN_DIR\kernel.asm" -ErrorAction SilentlyContinue
Push-Location $GEN_DIR
try {
& $JAVA -jar $ARNOLDC_JAR -asm "kernel.arnoldc"
if (-not (Test-Path "kernel.asm")) {
throw "ArnoldC compilation failed - no kernel.asm generated!"
}
} finally {
Pop-Location
}
# Add extern declarations for bootloader functions
Write-Host "[ARN ] Adding extern declarations for V3 kernel"
$asmContent = Get-Content "$GEN_DIR\kernel.asm" -Raw
$externs = @"
; External functions from bootloader
extern get_fb_addr
extern get_fb_pitch
extern get_fb_width
extern get_fb_height
extern get_timer_ticks
extern sleep_ticks
extern get_mouse_x
extern get_mouse_y
extern get_mouse_buttons
extern speaker_on
extern speaker_off
extern speaker_set_frequency
extern get_last_scancode
extern read_rtc_hours
extern read_rtc_minutes
extern read_rtc_seconds
extern read_rtc_day
extern read_rtc_month
extern read_rtc_year
extern halt_system
extern outb
extern inb
extern outw
extern inw
extern outl
extern inl
extern fast_fill_rect
extern fast_memcpy32
extern draw_wallpaper_dots
extern draw_arrow_cursor
extern drawHLine
extern drawVLine
extern pci_config_read
extern pci_config_write
extern pci_find_device
extern e1000_init
extern e1000_send_packet
extern e1000_receive_packet
extern e1000_get_mac
extern e1000_is_link_up
extern net_ping_gateway
extern net_get_ip_byte
extern net_get_gateway_byte
extern net_get_mac_byte
extern net_is_available
extern net_tcp_connect
extern net_tcp_send
extern net_tcp_recv
extern net_tcp_close
extern net_http_get
extern net_wget
extern net_wget_get_byte
extern net_wget_get_len
"@
# Insert externs after "section .text"
$asmContent = $asmContent -replace "(section \.text)", "`$1`n$externs"
Set-Content "$GEN_DIR\kernel.asm" $asmContent -NoNewline
# Assemble bootloader
Write-Host "[ASM ] Assembling bootloader - LISTEN TO ME VERY CAREFULLY"
& $NASM -f elf32 -w-other -o "$BUILD_DIR\multiboot.o" $BOOT_ASM
if ($LASTEXITCODE -ne 0) {
throw "Bootloader assembly failed!"
}
# Assemble kernel
Write-Host "[ASM ] Assembling kernel - THE TERMINATOR AWAKENS"
& $NASM -f elf32 -o "$BUILD_DIR\kernel.o" "$GEN_DIR\kernel.asm"
if ($LASTEXITCODE -ne 0) {
throw "Kernel assembly failed!"
}
# Link
Write-Host "[LD ] Linking kernel - GET TO THE CHOPPER"
& $LD -m elf_i386 -T "$ProjectRoot\linker.ld" -nostdlib -o $KERNEL_ELF "$BUILD_DIR\multiboot.o" "$BUILD_DIR\kernel.o"
if ($LASTEXITCODE -ne 0) {
throw "Linking failed!"
}
# Create binary
Write-Host "[BIN ] Creating binary - CONSIDER THAT A DIVORCE from ELF"
& $OBJCOPY -O binary $KERNEL_ELF $KERNEL_BIN
if ($LASTEXITCODE -ne 0) {
throw "Binary creation failed!"
}
Write-Host ""
Write-Host "============================================================================"
Write-Host " BUILD COMPLETE - I'LL BE BACK"
Write-Host "============================================================================"
Write-Host " Kernel ELF: $KERNEL_ELF"
Write-Host " Kernel BIN: $KERNEL_BIN"
$size = (Get-Item $KERNEL_BIN).Length
Write-Host " Size: $size bytes"
Write-Host ""
if ($Run) {
Write-Host "[QEMU] Launching - GET YOUR ASS TO MARS"
& $QEMU -m 128M -vga std -kernel $KERNEL_ELF -monitor telnet:127.0.0.1:55555,server,nowait
}