-
Notifications
You must be signed in to change notification settings - Fork 5
/
compile.ps1
119 lines (97 loc) · 3.52 KB
/
compile.ps1
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
param($paramName)
Write-Output $paramName
Function Create-Directory($directoryPath) {
if(Test-Path -Path $directoryPath -PathType Container) {
Write-Output "$directoryPath directory exists..."
}
else {
Write-Output "Creating $directoryPath Directory..."
New-Item -Path $directoryPath -ItemType Directory
}
}
Function CleanBinaries() {
Write-Output "Clearing all binaries...."
Remove-Item debug/bin/*.bin
Remove-Item debug/obj/*.o
Remove-Item debug/elf/*.elf
Remove-Item debug/objdump/*.objdump
Remove-Item *.log
}
Function Build() {
Write-Output "Creating Output Directories..."
Create-Directory('debug\bin')
Create-Directory('debug\obj')
Create-Directory('debug\objdump')
Create-Directory('debug\elf')
Write-Output "compile boot.asm"
fasm boot/boot.asm debug/bin/boot.bin
Write-Output "Compile second stage loader"
wsl gcc -g -m32 -ffreestanding -c boot/*.c drivers/*.c utils/*.c drivers/ata/*.c -nostartfiles -nostdlib
Move-Item *.o 'debug/obj'
Write-Output "link all c object files"
wsl ld -m elf_i386 -nostdlib -T ld/loader.ld debug/obj/*.o -o debug/elf/loader.elf
Write-Output "compile loader.asm"
fasm boot/loader.asm debug/obj/loader.o
Write-Output "Link loader asm and loader c"
wsl ld -m elf_i386 -nostdlib -T ld/loader.ld debug/obj/loader.o debug/elf/loader.elf -o debug/elf/loader_full.elf
Write-Output "objdump loader file"
objdump -phxd debug/obj/loader.o > debug/objdump/loader.objdump
Write-Output "objdump loader C file"
objdump -phxd debug/elf/loader_full.elf > debug/objdump/loader_full.objdump
Write-Output "Producing elf file"
wsl objcopy debug/elf/loader_full.elf -O binary debug/bin/loader.bin
Write-Output "Padding loader bin file"
$loader_file_size=$(wsl wc -c debug/bin/loader.bin).Split(" ")[0]
$loader_sectors=[math]::ceiling($loader_file_size/512)
$loader_final_bytes=$loader_sectors * 512
$loader_pad_bytes=$loader_final_bytes-$loader_file_size
wsl dd if=/dev/zero of=debug/bin/loader.bin bs=1 count=$loader_pad_bytes seek=$loader_file_size
Write-Output "Clearing .o and .elf"
Remove-Item debug/obj/*.o
Remove-Item debug/elf/*.elf
Write-Output "Compiling Kernel...."
wsl gcc -g -m32 -ffreestanding utils/*.c drivers/*.c kernel/*.c -nostartfiles -nostdlib -o kernel.o -T ld/kernel.ld
Move-Item *.o 'debug/obj'
#wsl ld -m elf_i386 -nostdlib -T linker.ld *.o -o prog.elf
objdump debug/obj/kernel.o -phxd > debug/objdump/kernel.objdump
Write-Output "Creating Empty Raw 10 MB HDD Image..."
wsl dd if=/dev/zero of=debug/bin/hdd.bin bs=1024 count=10240
Write-Output "Writing Kernel to HDD Image...."
$second_kernel_size=$(wsl wc -c debug/obj/kernel.o).Split(" ")[0]
wsl dd if=debug/obj/kernel.o of=debug/bin/hdd.bin count=$second_kernel_size conv=notrunc
}
Function Make()
{
Write-Output "Creating image...."
Get-Content debug/bin/boot.bin, debug/bin/loader.bin, debug/bin/hdd.bin -Raw | Set-Content debug/bin/os_image.bin -NoNewline
}
Function RunOS()
{
Write-Output "Launching QEMU"
qemu-system-x86_64 debug/bin/os_image.bin
# #bochs -f bochsconfig.conf
# #bochsdbg -f bochsconfig.conf
}
if($paramName -eq "all" -Or $Null -eq $paramName)
{
CleanBinaries
Build
Make
RunOS
}
if($paramName -eq "clean")
{
CleanBinaries
}
if($paramName -eq "build")
{
Build
}
if($paramName -eq "make")
{
Make
}
if($paramName -eq "run")
{
RunOS
}