diff --git a/assets/disk.fat b/assets/disk.fat deleted file mode 100644 index 87cbc52..0000000 Binary files a/assets/disk.fat and /dev/null differ diff --git a/assets/disk.img b/assets/diskbase.img similarity index 99% rename from assets/disk.img rename to assets/diskbase.img index 9aaf559..5d8f1ba 100644 Binary files a/assets/disk.img and b/assets/diskbase.img differ diff --git a/assets/initrd.toml b/assets/initrd.toml index 04a8847..876430b 100644 --- a/assets/initrd.toml +++ b/assets/initrd.toml @@ -10,14 +10,14 @@ [[files]] dest = "screenfont.psf" -source = "assets/fonts/tamsyn8x16r.psf" +source = "../assets/fonts/tamsyn8x16r.psf" [[files]] dest = "nulldrv1" -source = "build/kernel/src/drivers/nulldrv/nulldrv" +source = "host/nulldrv" executable = true [[files]] dest = "nulldrv2" -source = "build/kernel/src/drivers/nulldrv/nulldrv" +source = "host/nulldrv" executable = true diff --git a/generate_build.py b/generate_build.py index f0e1778..4db01b9 100755 --- a/generate_build.py +++ b/generate_build.py @@ -13,6 +13,9 @@ MODULES = { "kutil": library('src/libraries/kutil', []), "makerd": program('src/tools/makerd', ["initrd", "kutil"], "makerd", ["native"]), + + "nulldrv": program('src/drivers/nulldrv', [], "nulldrv", ["host"]), + "boot": program('src/boot', ["elf"], "boot.elf", ["host"]), "kernel": program('src/kernel', ["elf", "initrd", "kutil"], "popcorn.elf", ["host"]), } @@ -26,9 +29,9 @@ def get_template(env, typename, name): return env.get_template("{}.default.ninja.j2".format(typename)) -def get_sources(path): +def get_sources(path, srcroot): import os - from os.path import abspath, join, splitext + from os.path import abspath, join, relpath, splitext actions = {'.c': 'cc', '.cpp': 'cxx', '.s': 'nasm'} @@ -40,7 +43,7 @@ def get_sources(path): name = join(root, f) sources.append( source( - name, + relpath(name, srcroot), abspath(name), f + ".o", actions[ext])) @@ -68,8 +71,12 @@ def main(buildroot): import os from os.path import abspath, dirname, isdir, join - buildroot = abspath(buildroot) - srcroot = dirname(abspath(__file__)) + generator = abspath(__file__) + srcroot = dirname(generator) + + if buildroot is None: + buildroot = join(srcroot, "build") + if not isdir(buildroot): os.mkdir(buildroot) @@ -96,7 +103,7 @@ def main(buildroot): open_list.extend(dep.deps) targets[target].add(depname) - sources = get_sources(join(srcroot, mod.path)) + sources = get_sources(join(srcroot, mod.path), join(srcroot, "src")) buildfile = join(buildroot, name + ".ninja") buildfiles.append(buildfile) with open(buildfile, 'w') as out: @@ -141,12 +148,12 @@ def main(buildroot): buildfile=buildfile, buildfiles=buildfiles, templates=[abspath(f) for f in templates], - generator=abspath(__file__), + generator=generator, version=git_version)) if __name__ == "__main__": import sys - buildroot = "build" + buildroot = None if len(sys.argv) > 1: buildroot = sys.argv[1] main(buildroot) diff --git a/scripts/templates/build.ninja.j2 b/scripts/templates/build.ninja.j2 index 56a9c58..5ecede4 100644 --- a/scripts/templates/build.ninja.j2 +++ b/scripts/templates/build.ninja.j2 @@ -2,6 +2,29 @@ ninja_required_version = 1.3 builddir = {{ buildroot }} srcroot = {{ srcroot }} +warnflags = $ + -Wformat=2 $ + -Winit-self $ + -Wfloat-equal $ + -Winline $ + -Wmissing-format-attribute $ + -Wmissing-include-dirs $ + -Wswitch $ + -Wundef $ + -Wdisabled-optimization $ + -Wpointer-arith $ + -Wno-attributes $ + -Wno-sign-compare $ + -Wno-multichar $ + -Wno-div-by-zero $ + -Wno-endif-labels $ + -Wno-pragmas $ + -Wno-format-extra-args $ + -Wno-unused-result $ + -Wno-deprecated-declarations $ + -Wno-unused-function $ + -Werror + ccflags = $ -I${srcroot}/src/include $ -I${srcroot}/src/include/x86_64 $ @@ -9,7 +32,8 @@ ccflags = $ -DVERSION_MINOR={{ version.minor }} $ -DVERSION_PATCH={{ version.patch }} $ -DVERSION_GITSHA=\"{{ version.sha }}\" $ - -DGIT_VERSION=\"{{ version.major }}.{{ version.minor }}.{{ version.patch }}-{{ version.sha }}\" + -DGIT_VERSION=\"{{ version.major }}.{{ version.minor }}.{{ version.patch }}-{{ version.sha }}\" $ + $warnflags asflags = $ -DVERSION_MAJOR={{ version.major }} $ @@ -50,7 +74,35 @@ rule lib rule regen generator = true description = Regenrating build files - command = {{ generator }} ${builddir} + command = {{ generator }} $builddir + +rule cp + description = Copying $name + command = cp $in $out + +rule makerd + description = Making init ramdisk + command = $builddir/native/makerd $in $out + +rule makeefi + description = Converting $name + command = objcopy $ + -j .text $ + -j .sdata $ + -j .data $ + -j .dynamic $ + -j .dynsym $ + -j .rel $ + -j .rela $ + -j .reloc $ + --target=efi-app-x86_64 $ + $in $out + +rule makefat + description = Creating $name + command = $ + cp $srcroot/assets/diskbase.img $out; $ + mcopy -s -D o -i $out@@1024K $builddir/fatroot/* ::/ {% for target in targets %} subninja {{ target }}/target.ninja @@ -66,5 +118,27 @@ build $ {%- endfor %} {{ generator }} +build $builddir/flash.img : cp $srcroot/assets/ovmf/x64/OVMF.fd + name = flash.img + +build $builddir/popcorn.fat : cp $srcroot/assets/ovmf/x64/OVMF.fd + name = flash.img + +build $builddir/fatroot/popcorn.elf : cp $builddir/host/popcorn.elf + name = kernel to FAT image + +build $builddir/fatroot/efi/boot/bootx64.efi : cp $builddir/host/boot.efi + name = bootloader to FAT image + +build $builddir/fatroot/initrd.img : makerd ${srcroot}/assets/initrd.toml | $ + ${builddir}/native/makerd $ + ${builddir}/host/nulldrv + +build $builddir/popcorn.img : makefat | $ + $builddir/fatroot/initrd.img $ + $builddir/fatroot/popcorn.elf $ + $builddir/fatroot/efi/boot/bootx64.efi + name = popcorn.img + # vim: et ts=4 sts=4 sw=4 diff --git a/scripts/templates/module.base.ninja.j2 b/scripts/templates/module.base.ninja.j2 index 323f727..9304a27 100644 --- a/scripts/templates/module.base.ninja.j2 +++ b/scripts/templates/module.base.ninja.j2 @@ -22,5 +22,8 @@ build {% block artifact %} ${builddir}/lib{{ name }}.a : lib {% endblock %} $ {%- if module.deps %}| {% for dep in module.deps %} ${builddir}/lib{{ dep }}.a {% endfor %}{% endif %} name = {{ name }} -# End +{% block extra %} +{% endblock %} + +# vim: ft=ninja et ts=4 sts=4 sw=4 diff --git a/scripts/templates/program.boot.ninja.j2 b/scripts/templates/program.boot.ninja.j2 index f731a5c..a6bf7f9 100644 --- a/scripts/templates/program.boot.ninja.j2 +++ b/scripts/templates/program.boot.ninja.j2 @@ -3,16 +3,23 @@ {{ super() }} cflags = $cflags $ - -DKERNEL_FILENAME=L\"popcorn.elf\" $ - -DGNU_EFI_USE_MS_ABI $ - -DHAVE_USE_MS_ABI $ - -DEFI_DEBUG=0 $ - -DEFI_DEBUG_CLEAR_MEMORY=0 $ - -fPIC $ - -fshort-wchar + -DKERNEL_FILENAME=L\"popcorn.elf\" $ + -DGNU_EFI_USE_MS_ABI $ + -DHAVE_USE_MS_ABI $ + -DEFI_DEBUG=0 $ + -DEFI_DEBUG_CLEAR_MEMORY=0 $ + -fPIC $ + -fshort-wchar ldflags = $ldflags $ - -shared $ - -T ${srcroot}/src/arch/x86_64/boot.ld + -shared $ + -T ${srcroot}/src/arch/x86_64/boot.ld + +{% endblock %} + +{% block extra %} + +build $builddir/boot.efi : makeefi ${builddir}/{{ module.output }} + name = boot.efi {% endblock %} diff --git a/scripts/templates/program.default.ninja.j2 b/scripts/templates/program.default.ninja.j2 index ee7b698..4d25973 100644 --- a/scripts/templates/program.default.ninja.j2 +++ b/scripts/templates/program.default.ninja.j2 @@ -3,11 +3,11 @@ {{ super() }} libs = $ - -L${builddir} $ + -L${builddir} $ {%- for dep in module.deps %} -l{{dep}} $ {%- endfor %} - $libs + $libs {% endblock %} -{% block artifact %}{{ module.output }} : exe{% endblock %} +{% block artifact %}${builddir}/{{ module.output }} : exe{% endblock %} diff --git a/scripts/templates/program.kernel.ninja.j2 b/scripts/templates/program.kernel.ninja.j2 index deae3c7..38a0a3d 100644 --- a/scripts/templates/program.kernel.ninja.j2 +++ b/scripts/templates/program.kernel.ninja.j2 @@ -4,5 +4,6 @@ asflags = $asflags -I${srcroot}/src/kernel/ libs = $libs -lc +ldflags = $ldflags -T ${srcroot}/src/arch/x86_64/kernel.ld {% endblock %} diff --git a/scripts/templates/target.default.ninja.j2 b/scripts/templates/target.default.ninja.j2 index e57f874..b18ec94 100644 --- a/scripts/templates/target.default.ninja.j2 +++ b/scripts/templates/target.default.ninja.j2 @@ -9,6 +9,7 @@ cxx = clang++ ld = clang++ ar = ar nasm = nasm +objcopy = objcopy {% endblock %} {% for module in modules %} diff --git a/scripts/templates/target.host.ninja.j2 b/scripts/templates/target.host.ninja.j2 index 60bcb9f..527a73d 100644 --- a/scripts/templates/target.host.ninja.j2 +++ b/scripts/templates/target.host.ninja.j2 @@ -5,12 +5,14 @@ cxx = ${srcroot}/sysroot/bin/clang++ ld = ${srcroot}/sysroot/bin/x86_64-elf-ld ar = ${srcroot}/sysroot/bin/x86_64-elf-ar nasm = ${srcroot}/sysroot/bin/nasm +objcopy = ${srcroot}/sysroot/bin/x86_64-elf-objcopy {% endblock %} {% block variables %} ccflags = $ccflags $ -D__ELF__ $ + -D__POPCORN__ $ -nodefaultlibs $ -nostdinc $ -nostdlib $