Compare commits
77
Commits
master
...
89f7d2120f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89f7d2120f | ||
|
|
7515ebdf1c | ||
|
|
b0e59b3e26 | ||
|
|
153a8d43f1 | ||
|
|
bf9a005dbc | ||
|
|
53e2e52bbe | ||
|
|
12067b8e1a | ||
|
|
8278c4211b | ||
|
|
3bdc5bccdd | ||
|
|
f904ec2b48 | ||
|
|
bcec23ef89 | ||
|
|
d86745d91d | ||
|
|
cf5956dcd3 | ||
|
|
8498de6b62 | ||
|
|
f761d0a445 | ||
|
|
f29bd9d00c | ||
|
|
f236a64b21 | ||
|
|
1225e98276 | ||
|
|
cb31e36e90 | ||
|
|
0568a813f2 | ||
|
|
37d5621e41 | ||
|
|
98e992aad0 | ||
|
|
06242a0c9f | ||
|
|
e214a9c3de | ||
|
|
c259ae4cee | ||
|
|
b4d8707243 | ||
|
|
6b7b14d954 | ||
|
|
9e7c3ee676 | ||
|
|
2d7bf5197f | ||
|
|
7562be585f | ||
|
|
3d04eec427 | ||
|
|
5c97acba5f | ||
|
|
c3ead56582 | ||
|
|
15559b0a56 | ||
|
|
c58284761a | ||
|
|
bd99e429a9 | ||
|
|
d0acf5a718 | ||
|
|
b40151055c | ||
|
|
1e00d7a9e9 | ||
|
|
79b34477ed | ||
|
|
163ef9f79e | ||
|
|
3c549f0838 | ||
|
|
d8c85ad045 | ||
|
|
7c5af33ace | ||
|
|
6f3521c576 | ||
|
|
5a5d60abae | ||
|
|
9182a83ef2 | ||
|
|
195b7496f4 | ||
|
|
b1042fd649 | ||
|
|
6beb7da4cd | ||
|
|
f27851def9 | ||
|
|
18f1bfc88f | ||
|
|
cd6983e2cd | ||
|
|
8df1646c61 | ||
|
|
3e25ab6ae4 | ||
|
|
05cc2da2e3 | ||
|
|
a54536660b | ||
|
|
9e3d9b18ea | ||
|
|
ef01239468 | ||
|
|
372b7265f1 | ||
|
|
1bc8722098 | ||
|
|
cd2f3f9a84 | ||
|
|
08a35e40d4 | ||
|
|
a855702214 | ||
|
|
706f2c1c5d | ||
|
|
704fd15f7b | ||
|
|
f054bab5cc | ||
|
|
3fa8e4a24b | ||
|
|
a38f95a7b8 | ||
|
|
dd57a31d38 | ||
|
|
406f17c1db | ||
|
|
0be1b113aa | ||
|
|
d782b59768 | ||
|
|
c3a6139f83 | ||
|
|
3d3a433800 | ||
|
|
54451bcf5b | ||
|
|
1fc2dd34e5 |
No files matched your search
+1
-1
@@ -1,3 +1,3 @@
|
||||
.rscons*
|
||||
/i686-elf-gcc/
|
||||
/x86_64-elf-gcc/
|
||||
/build/
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "uefi-d"]
|
||||
path = uefi-d
|
||||
url = git://github.com/kubasz/uefi-d
|
||||
+90
-126
@@ -1,98 +1,52 @@
|
||||
path_prepend "i686-elf-gcc/bin"
|
||||
|
||||
configure do
|
||||
rscons "i686-elf-gcc.rb", "-b", "#{build_dir}/i686-elf-gcc"
|
||||
check_c_compiler "i686-elf-gcc"
|
||||
check_program "genext2fs"
|
||||
check_program "grub-mkstandalone"
|
||||
check_program "mformat", on_fail: "Install the mtools package"
|
||||
check_program "xorriso"
|
||||
check_cfg package: "freetype2", on_fail: "Install libfreetype-dev", use: "freetype"
|
||||
end
|
||||
|
||||
require "tmpdir"
|
||||
|
||||
# EFI (w/ GRUB) partition size (MiB)
|
||||
EFI_PART_SIZE = 8
|
||||
# HOS partition size (MiB)
|
||||
HOS_PART_SIZE = 4
|
||||
# Kernel default font size
|
||||
KFONT_SIZE = 15
|
||||
project_name "HOS"
|
||||
path_prepend "x86_64-elf-gcc/bin"
|
||||
|
||||
class BiosImage < Builder
|
||||
configure do
|
||||
rscons "x86_64-elf-gcc.rb", "-b", "#{build_dir}/x86_64-elf-gcc"
|
||||
check_d_compiler "ldc2", use: "ldc2"
|
||||
check_c_compiler "x86_64-w64-mingw32-gcc", use: "x86_64-w64-mingw32-gcc"
|
||||
check_c_compiler "x86_64-elf-gcc", use: "x86_64-elf-gcc"
|
||||
check_c_compiler
|
||||
check_program "mformat", on_fail: "Install the mtools package"
|
||||
check_cfg package: "freetype2", on_fail: "Install libfreetype-dev", use: "freetype"
|
||||
sh %w[git submodule update --init]
|
||||
end
|
||||
|
||||
# Kernel default font size.
|
||||
KFONT_SIZE = 18
|
||||
|
||||
class HulkBinObj < Builder
|
||||
def run(options)
|
||||
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
||||
print_run_message("Generating BIOS boot image #{@target}", nil)
|
||||
Dir.mktmpdir do |tmpdir|
|
||||
# Create iso directory.
|
||||
FileUtils.mkdir_p("#{tmpdir}/iso/boot/grub")
|
||||
File.open("#{tmpdir}/iso/boot/grub/grub.cfg", "wb") do |fh|
|
||||
fh.write(<<EOF)
|
||||
set default="0"
|
||||
set timeout=1
|
||||
menuentry "HOS" {
|
||||
insmod multiboot2
|
||||
multiboot2 /hos.elf
|
||||
}
|
||||
FileUtils.mkdir_p(File.dirname(@target))
|
||||
File.write(@target, <<EOF)
|
||||
.section ".rodata"
|
||||
.balign 4096
|
||||
.global _hulk_bin_start
|
||||
_hulk_bin_start:
|
||||
.incbin "#{@sources.first}"
|
||||
.balign 4096
|
||||
.global _hulk_bin_end
|
||||
_hulk_bin_end:
|
||||
EOF
|
||||
end
|
||||
@sources.each do |source|
|
||||
FileUtils.cp(source, "#{tmpdir}/iso")
|
||||
end
|
||||
# Build bootable GRUB image.
|
||||
system(*%W[grub-mkrescue -o #{@target} #{tmpdir}/iso], err: "#{@env.build_root}/grub-mkrescue.log")
|
||||
end
|
||||
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
||||
print_run_message("Creating HULK binary object <target>#{@target}<reset>", nil)
|
||||
@cache.register_build(@target, nil, @sources, @env)
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
class EfiImage < Builder
|
||||
class Image < Builder
|
||||
def run(options)
|
||||
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
||||
print_run_message("Generating EFI boot image #{@target}", nil)
|
||||
Dir.mktmpdir do |tmpdir|
|
||||
# Build a standalone GRUB.
|
||||
File.open("#{tmpdir}/grub.cfg", "wb") do |fh|
|
||||
fh.write(<<EOF)
|
||||
insmod part_gpt
|
||||
configfile (hd0,gpt2)/grub.cfg
|
||||
EOF
|
||||
end
|
||||
system(*%W[grub-mkstandalone -O x86_64-efi -o #{tmpdir}/BOOTX64.EFI boot/grub/grub.cfg=#{tmpdir}/grub.cfg])
|
||||
# Create EFI partition.
|
||||
system(*%W[dd if=/dev/zero of=#{tmpdir}/efi.part bs=1M count=#{EFI_PART_SIZE}], err: "/dev/null")
|
||||
system(*%W[mformat -i #{tmpdir}/efi.part ::])
|
||||
system(*%W[mmd -i #{tmpdir}/efi.part ::/EFI])
|
||||
system(*%W[mmd -i #{tmpdir}/efi.part ::/EFI/BOOT])
|
||||
system(*%W[mcopy -i #{tmpdir}/efi.part #{tmpdir}/BOOTX64.EFI ::/EFI/BOOT])
|
||||
# Create ext2 HOS partition.
|
||||
FileUtils.mkdir_p("#{tmpdir}/ext2")
|
||||
@sources.each do |source|
|
||||
FileUtils.cp(source, "#{tmpdir}/ext2")
|
||||
end
|
||||
File.open("#{tmpdir}/ext2/grub.cfg", "wb") do |fh|
|
||||
fh.write(<<EOF)
|
||||
set default="0"
|
||||
set timeout=1
|
||||
menuentry "HOS" {
|
||||
insmod part_gpt
|
||||
insmod multiboot2
|
||||
set root=(hd0,gpt2)
|
||||
multiboot2 /hos.elf
|
||||
}
|
||||
EOF
|
||||
end
|
||||
system(*%W[genext2fs -b #{HOS_PART_SIZE * 1024} -d #{tmpdir}/ext2 #{tmpdir}/ext2.part])
|
||||
# Create full disk image.
|
||||
system(*%W[dd if=/dev/zero of=#{@target} bs=1M count=#{EFI_PART_SIZE + HOS_PART_SIZE + 2}], err: "/dev/null")
|
||||
system(*%W[parted -s #{@target} mklabel gpt])
|
||||
system(*%W[parted -s #{@target} mkpart efi 1MiB #{EFI_PART_SIZE + 1}MiB])
|
||||
system(*%W[parted -s #{@target} mkpart hos #{EFI_PART_SIZE + 1}MiB #{EFI_PART_SIZE + HOS_PART_SIZE + 1}MiB])
|
||||
system(*%W[dd if=#{tmpdir}/efi.part of=#{@target} bs=1M seek=1 conv=notrunc], err: "/dev/null")
|
||||
system(*%W[dd if=#{tmpdir}/ext2.part of=#{@target} bs=1M seek=#{1 + EFI_PART_SIZE} conv=notrunc], err: "/dev/null")
|
||||
end
|
||||
print_run_message("Creating disk image <target>#{@target}<reset>", nil)
|
||||
File.binwrite(@target, "\0" * (1440 * 1024))
|
||||
system(*%W[mformat -i #{@target} -f 1440 ::])
|
||||
system(*%W[mmd -i #{@target} ::/EFI])
|
||||
system(*%W[mmd -i #{@target} ::/EFI/BOOT])
|
||||
system(*%W[mcopy -i #{@target} #{@sources.first} ::/EFI/BOOT])
|
||||
@cache.register_build(@target, nil, @sources, @env)
|
||||
end
|
||||
true
|
||||
@@ -112,55 +66,65 @@ class FontGen < Builder
|
||||
end
|
||||
end
|
||||
|
||||
class Size < Builder
|
||||
def run(options)
|
||||
if @command
|
||||
finalize_command
|
||||
else
|
||||
@vars["_SOURCES"] = @sources
|
||||
@vars["_TARGET"] = @target
|
||||
command = @env.build_command(%w[${SIZE} ${_SOURCES}], @vars)
|
||||
standard_command("Size <target>#{@target}<reset>", command, stdout: @target)
|
||||
fontgen_env = env "fontgen", use: "freetype" do |env|
|
||||
env.Program("^/fontgen", glob("src/fontgen/**/*.c"))
|
||||
end
|
||||
|
||||
hulk_env = env "hulk", use: %w[ldc2 x86_64-elf-gcc] do |env|
|
||||
env.add_builder(FontGen)
|
||||
env.FontGen("^/src/hulk/kfont.d", "font/Hack-Regular.ttf",
|
||||
"fontgen" => fontgen_env.expand("^/fontgen"))
|
||||
env["sources"] = glob("src/hulk/**/*.d")
|
||||
env["sources"] << "^/src/hulk/kfont.d"
|
||||
env["DFLAGS"] += %w[-mtriple=x86_64-unknown-elf --betterC -release -O3 --wi --enable-cross-module-inlining -code-model=large]
|
||||
env["D_IMPORT_PATH"] += %w[src]
|
||||
env["D_IMPORT_PATH"] << env.expand("^/src")
|
||||
env["LD"] = "x86_64-elf-gcc"
|
||||
env["LDFLAGS"] += %w[-nostdlib -Tsrc/hulk/hulk.ld -Wl,-Map,${_TARGET}.map]
|
||||
env["LDCMD"] = %w[${LD} -o ${_TARGET} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}]
|
||||
env["OBJDUMP"] = "x86_64-elf-objdump"
|
||||
env["OBJCOPY"] = "x86_64-elf-objcopy"
|
||||
env.Program("^/hulk.elf", "${sources}")
|
||||
env.depends("^/hulk.elf", "src/hulk/hulk.ld")
|
||||
env["SIZE"] = "x86_64-elf-size"
|
||||
env.Size("^/hulk.size", "^/hulk.elf")
|
||||
env.Disassemble("^/hulk.txt", "^/hulk.elf")
|
||||
env.Command("^/hulk.bin", "^/hulk.elf",
|
||||
"CMD" => %W[${OBJCOPY} -O binary ${_SOURCES} ${_TARGET}],
|
||||
"CMD_DESC" => "Convert ELF to binary:")
|
||||
env.add_build_hook do |builder|
|
||||
if builder.target.end_with?(".o")
|
||||
env.Disassemble("#{builder.target}.txt", builder.target)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# FontGen Environment
|
||||
fontgen_env = env "fontgen", use: "freetype" do |env|
|
||||
env["CC"] = "gcc"
|
||||
env.Program("^/fontgen.bin", glob("fontgen/**/*.c"))
|
||||
end
|
||||
|
||||
# Kernel Environment
|
||||
kernel_env = env "kernel" do |env|
|
||||
env.add_builder(EfiImage)
|
||||
env.add_builder(BiosImage)
|
||||
env.add_builder(FontGen)
|
||||
env.add_builder(Size)
|
||||
env["OBJDUMP"] = "i686-elf-objdump"
|
||||
env["SIZE"] = "i686-elf-size"
|
||||
env["CCFLAGS"] += %w[-ffreestanding -Wall -O2]
|
||||
env["LDFLAGS"] += %w[-ffreestanding -nostdlib -T src/link.ld]
|
||||
env["LDFLAGS"] += %W[-Wl,-Map,${_TARGET}.map]
|
||||
env["LIBS"] += %w[gcc]
|
||||
env.FontGen("^/kfont/kfont.c", "font/Hack-Regular.ttf",
|
||||
"fontgen" => fontgen_env.expand("^/fontgen.bin"))
|
||||
env.barrier
|
||||
env["CPPPATH"] += ["#{env.build_root}/kfont"]
|
||||
env.Program("^/hos.elf", glob("src/**/*.{S,c}") + ["^/kfont/kfont.c"])
|
||||
env.depends("#{env.build_root}/hos.elf", "src/link.ld")
|
||||
env.Disassemble("^/hos.elf.txt", "^/hos.elf")
|
||||
env.Size("^/hos.elf.size", "^/hos.elf")
|
||||
env.EfiImage("^/hos-efi.img", %w[^/hos.elf])
|
||||
env.BiosImage("^/hos.img", %w[^/hos.elf])
|
||||
hello_env = env "hello", use: %w[ldc2 x86_64-w64-mingw32-gcc] do |env|
|
||||
env.add_builder(Image)
|
||||
env.add_builder(HulkBinObj)
|
||||
env["sources"] = glob("src/hello/**/*.d")
|
||||
env["sources"] += glob("uefi-d/source/**/*.d")
|
||||
env.HulkBinObj("^/hulk_bin.S", hulk_env.expand("^/hulk.bin"))
|
||||
env.Object("^/hulk_bin.o", "^/hulk_bin.S")
|
||||
env.depends("^/hulk_bin.o", hulk_env.expand("^/hulk.bin"))
|
||||
env["sources"] << "^/hulk_bin.o"
|
||||
env["DFLAGS"] += %w[-mtriple=x86_64-unknown-windows-coff --betterC -release -O3 --wi --enable-cross-module-inlining]
|
||||
env["D_IMPORT_PATH"] += %w[src uefi-d/source]
|
||||
env["LD"] = "x86_64-w64-mingw32-gcc"
|
||||
env["LDFLAGS"] += %w[-nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main -Wl,-Map,${_TARGET}.map]
|
||||
env["LDCMD"] = %w[${LD} -o ${_TARGET} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}]
|
||||
env["OBJDUMP"] = "x86_64-w64-mingw32-objdump"
|
||||
env.Program("^/BOOTX64.EFI", "${sources}")
|
||||
env["SIZE"] = "x86_64-w64-mingw32-size"
|
||||
env.Size("^/BOOTX64.size", "^/BOOTX64.EFI")
|
||||
env.Disassemble("^/BOOTX64.txt", "^/BOOTX64.EFI")
|
||||
env.Image("^/hos.img", "^/BOOTX64.EFI")
|
||||
end
|
||||
|
||||
task "run", desc: "Run HOS in QEMU" do
|
||||
img = kernel_env.expand("^/hos.img")
|
||||
sh %W[qemu-system-x86_64 -hda #{img}]
|
||||
end
|
||||
|
||||
task "run-efi", desc: "Run HOS EFI in QEMU" do
|
||||
img = kernel_env.expand("^/hos-efi.img")
|
||||
sh %W[qemu-system-x86_64 -bios OVMF.fd -hda #{img}]
|
||||
Dir.mktmpdir do |tmpdir|
|
||||
img = hello_env.expand("^/hos.img")
|
||||
FileUtils.cp(img, tmpdir)
|
||||
sh %W[qemu-system-x86_64 -bios OVMF.fd -drive file=#{tmpdir}/hos.img,format=raw -device qemu-xhci -device usb-tablet]
|
||||
end
|
||||
end
|
||||
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# Copyright (c) 2013-2022 Josh Holtrop
|
||||
#
|
||||
#
|
||||
# MIT License
|
||||
#
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
@@ -11,10 +11,10 @@
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
@@ -24,7 +24,7 @@
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
script = File.join(File.dirname(__FILE__), ".rscons-3.0.0-077c0388ca4d1d902141299abcc4b8f6.rb")
|
||||
script = File.join(File.dirname(__FILE__), ".rscons-3.0.2-c49c635f1e4166223367979510498b28.rb")
|
||||
unless File.exists?(script)
|
||||
if File.read(__FILE__, mode: "rb") =~ /^#==>(.*)/
|
||||
require "zlib"
|
||||
@@ -43,4 +43,4 @@ load script
|
||||
if __FILE__ == $0
|
||||
Rscons::Cli.new.run(ARGV)
|
||||
end
|
||||
#==>eJztfWt3G0eO6Pf8inbbiUmZouzMndlzGCuSLMmJ9sqWryRnPUszHIpsSj0mu7ndpGStzP3tt4B6AVXVTcqP3Oye6zkTseuJQqFQKBQKePhga1EWWxdptpVk11GxuLj9rkj+Y5EWSRRnyXzraj6fxTZplF4m5Tz+bpqPFpMkOi2HeVZ+F0Xqey8rU/EVRcPJoCyj58+jMpmMMSWKTg/PDs+j7Sh+n3SfTmOVOkrG0U2RzpNGmreijWlSloPLpKlyRX7eH+aTvBAVZW/twWw2SYeDeZpnbZE7EH3KIqZOOjbV2lk62TEZrDlVd0d0bLtLspH5nS/mAG4capc0OVwURZLNLZgwTtplUgrcjSrz1ZDbyWB4JdqPPk0/kVzsddpOy/5gp3E2L9Lsssmyo2iSZkkpGp62S4GZeSN+n8WtaPNZsBx2079J51f9NBslH7FHyGlF6SenAvYNedEDhgeWz4cvCrLxBupIxD5Zp6CL2lU16Ox53cFAvNxQDTGoNHqu0FWm/5lEm9GzNQfvTq4HRXWBVXS01iBh7tcYpJuSTEoXN8NBmURTJ/HmKsmijpiCn2iqS+G4wn/6y7OpC4qsflkkSfbTyuo/VlS/TSaT/OanVdX/UlH9YrJIKPQV1f9XRfWpWKrZfPDTiup/rag+vB1ka/T+t4rqN1eCU65G3b9UjT2fjOjkhao/q544qE4nr6J61cRBdTp5FdUrJ05Up5NXUb1q4qA6nbyK6lUTB9Xp5FVUr5o4qE4nr6J63cSt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5plhfvv3kjuPeb08OXR++EcOsZF8gZ7qpyR68PoS+PyNgobMCMusz/CsjRkL50xNir8rYs8nz+NbqlQa09bzU1vmjujl7vrzVxb/bOf62ZNQfq8dGL46PX/3s1ZFGwjhh8sAdHp2tBXdFfmM9plm8Oby9vUvaCITBfUIVhPDBDThmvLdHKKL8pQy2tD2UmjS2/bXcB55v/Nmh52NVg9s40mEfPiEVTHbRJNTTbqbWhzaqhCUpdGxyYMBdz3EV3GvEmOy6sRmsVnCf3hLPm9CShCnLxeKUD+oLi2pMQiaDzgEsdWpapFIVQtgtl4IfXUn1xKcvMBmmBW7+Wk7kYI4RCJmKre5G9ohjcNnGrhm2aJlKWKGpLOdsVQzhebbkqaSV0PhwtplrEkqJv/2pQXkXbRhKe5/0rvwCe0lAZ17+4bfzQAdOkJtOEMM1iv5wXUhusr4Rupxf5pBntyDR5Eo5QZjb1guZW8KikpUESEyowJECNiu4hSm7mjE0srEJYWPdgJtXC61shQ2FusqKuI/UpBv50475OjZ2VRTQrtFcUSPgxpmjJ3HAuSqYIQQJrsFwyc+LT07eINNZfB2B9X3Xlr6POqG6HtpHqVcuwjEkLine truncated
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
.global hos_start
|
||||
.type hos_start, @function
|
||||
hos_start:
|
||||
/* Set stack pointer. */
|
||||
mov $_stack_end, %esp
|
||||
|
||||
/* Jump to C. */
|
||||
push $0
|
||||
push $0
|
||||
push $0
|
||||
push %ebx
|
||||
call hos_main
|
||||
|
||||
cli
|
||||
1: hlt
|
||||
jmp 1b
|
||||
|
||||
.size hos_start, . - hos_start
|
||||
@@ -1,116 +0,0 @@
|
||||
#include "fb.h"
|
||||
#include <stddef.h>
|
||||
#include "mem.h"
|
||||
|
||||
static struct {
|
||||
uint32_t * addr;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t pitch;
|
||||
} fb;
|
||||
|
||||
static inline uint32_t build_pixel(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
return (r << 16u) | (g << 8u) | b;
|
||||
}
|
||||
|
||||
static inline void fb_set_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
fb.addr[fb.pitch * y + x] = build_pixel(r, g, b);
|
||||
}
|
||||
|
||||
void fb_clear(void)
|
||||
{
|
||||
memset32(fb.addr, 0u, fb.pitch * fb.height);
|
||||
}
|
||||
|
||||
void fb_init(uint32_t * addr, uint32_t width, uint32_t height, uint32_t pitch)
|
||||
{
|
||||
fb.addr = addr;
|
||||
fb.width = width;
|
||||
fb.height = height;
|
||||
fb.pitch = pitch / 4u;
|
||||
fb_clear();
|
||||
}
|
||||
|
||||
uint32_t * fb_addr(void)
|
||||
{
|
||||
return fb.addr;
|
||||
}
|
||||
|
||||
bool fb_ready(void)
|
||||
{
|
||||
return fb.addr != NULL;
|
||||
}
|
||||
|
||||
uint32_t fb_width(void)
|
||||
{
|
||||
return fb.width;
|
||||
}
|
||||
|
||||
uint32_t fb_height(void)
|
||||
{
|
||||
return fb.height;
|
||||
}
|
||||
|
||||
void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, int x, int y, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
if (((x + width) <= 0) || (x >= (int)fb.width) || ((y + height) <= 0) || (y >= (int)fb.height))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
bitmap += (-x);
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
bitmap += ((-y) * pitch);
|
||||
y = 0;
|
||||
}
|
||||
if ((x + width) > (int)fb.width)
|
||||
{
|
||||
width = (int)fb.width - x;
|
||||
}
|
||||
if ((y + height) > (int)fb.height)
|
||||
{
|
||||
height = (int)fb.height - y;
|
||||
}
|
||||
uint32_t * target = &fb.addr[fb.pitch * y + x];
|
||||
for (int row = 0; row < height; row++)
|
||||
{
|
||||
for (int col = 0; col < width; col++)
|
||||
{
|
||||
uint32_t alpha = bitmap[col];
|
||||
uint32_t current_pixel = target[col];
|
||||
uint8_t cr = (current_pixel >> 16u) & 0xFFu;
|
||||
uint8_t cg = (current_pixel >> 8u) & 0xFFu;
|
||||
uint8_t cb = current_pixel & 0xFFu;
|
||||
uint8_t pr = alpha * r / 255u;
|
||||
uint8_t pg = alpha * g / 255u;
|
||||
uint8_t pb = alpha * b / 255u;
|
||||
uint32_t current_alpha = 255u - alpha;
|
||||
uint32_t pixel = build_pixel(
|
||||
pr + current_alpha * cr / 255u,
|
||||
pg + current_alpha * cg / 255u,
|
||||
pb + current_alpha * cb / 255u);
|
||||
target[col] = pixel;
|
||||
}
|
||||
bitmap += pitch;
|
||||
target += fb.pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void fb_fill(int x, int y, int width, int height, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
uint32_t * target = &fb.addr[fb.pitch * y + x];
|
||||
uint32_t pixel = build_pixel(r, g, b);
|
||||
for (int row = 0; row < height; row++)
|
||||
{
|
||||
memset32(target, pixel, width);
|
||||
target += fb.pitch;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef FB_H
|
||||
#define FB_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void fb_init(uint32_t * addr, uint32_t width, uint32_t height, uint32_t pitch);
|
||||
bool fb_ready(void);
|
||||
uint32_t * fb_addr(void);
|
||||
uint32_t fb_width(void);
|
||||
uint32_t fb_height(void);
|
||||
void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, int x, int y, uint8_t r, uint8_t g, uint8_t b);
|
||||
void fb_fill(int x, int y, int width, int height, uint8_t r, uint8_t g, uint8_t b);
|
||||
void fb_clear(void);
|
||||
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
#include "fb_text.h"
|
||||
#include "kfont.h"
|
||||
#include "fb.h"
|
||||
|
||||
void fb_text_render_char(int c, int x, int y, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
const fontgen_char_info_t * char_info = kfont.char_infos[c];
|
||||
y += kfont.line_height - kfont.baseline_offset - char_info->top;
|
||||
x += char_info->left;
|
||||
fb_blend_alpha8(char_info->bitmap, char_info->width, char_info->height, char_info->width, x, y, r, g, b);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef FB_TEXT_H
|
||||
#define FB_TEXT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void fb_text_render_char(int c, int x, int y, uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
#endif
|
||||
@@ -62,52 +62,13 @@ static void load_char(FT_Face face, int char_code)
|
||||
char_infos[char_code].width * char_infos[char_code].height);
|
||||
}
|
||||
|
||||
static const char * bare_header_name(const char * h_file_name)
|
||||
{
|
||||
const char * p = rindex(h_file_name, '/');
|
||||
if (p == NULL)
|
||||
{
|
||||
p = h_file_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static char * include_guard_name(const char * h_file_name)
|
||||
{
|
||||
const char * p = bare_header_name(h_file_name);
|
||||
char * guard_name = malloc(strlen(p) + 1);
|
||||
strcpy(guard_name, p);
|
||||
char * m = guard_name;
|
||||
while (*m != '\0')
|
||||
{
|
||||
if ('a' <= *m && *m <= 'z')
|
||||
{
|
||||
*m = toupper(*m);
|
||||
}
|
||||
else if (('0' <= *m && *m <= '9') || ('A' <= *m && *m <= 'Z'))
|
||||
{
|
||||
/* no change */
|
||||
}
|
||||
else
|
||||
{
|
||||
*m = '_';
|
||||
}
|
||||
m++;
|
||||
}
|
||||
return guard_name;
|
||||
}
|
||||
|
||||
static void generate_bytes(FILE * file, const uint8_t * bytes, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (i % 8 == 0)
|
||||
{
|
||||
fprintf(file, " ");
|
||||
fprintf(file, " ");
|
||||
}
|
||||
fprintf(file, "0x%02xu,", bytes[i]);
|
||||
if ((i + 1) % 8 == 0)
|
||||
@@ -125,62 +86,50 @@ static void generate_bytes(FILE * file, const uint8_t * bytes, int count)
|
||||
}
|
||||
}
|
||||
|
||||
static void generate(const char * c_file_name)
|
||||
static void generate(const char * d_file_name)
|
||||
{
|
||||
char * h_file_name = malloc(strlen(c_file_name) + 1);
|
||||
strcpy(h_file_name, c_file_name);
|
||||
h_file_name[strlen(h_file_name) - 1] = 'h';
|
||||
char * guard = include_guard_name(h_file_name);
|
||||
|
||||
FILE * h_file = fopen(h_file_name, "wb");
|
||||
fprintf(h_file, "#ifndef %s\n", guard);
|
||||
fprintf(h_file, "#define %s\n\n", guard);
|
||||
fprintf(h_file, "#include <stdint.h>\n");
|
||||
fprintf(h_file, "typedef struct {\n int width;\n int height;\n int top;\n int left;\n const uint8_t * bitmap;\n} fontgen_char_info_t;\n");
|
||||
fprintf(h_file, "typedef struct {\n int line_height;\n int advance;\n int baseline_offset;\n const fontgen_char_info_t ** char_infos;\n} fontgen_font_t;\n");
|
||||
fprintf(h_file, "extern const fontgen_font_t kfont;\n");
|
||||
fprintf(h_file, "#endif\n");
|
||||
fclose(h_file);
|
||||
|
||||
FILE * c_file = fopen(c_file_name, "wb");
|
||||
fprintf(c_file, "#include \"%s\"\n", bare_header_name(h_file_name));
|
||||
fprintf(c_file, "#include <stddef.h>\n");
|
||||
FILE * fh = fopen(d_file_name, "wb");
|
||||
fprintf(fh, "module hulk.kfont;\n");
|
||||
fprintf(fh, "struct CharInfo {\n");
|
||||
fprintf(fh, " uint width;\n");
|
||||
fprintf(fh, " uint height;\n");
|
||||
fprintf(fh, " int top;\n");
|
||||
fprintf(fh, " int left;\n");
|
||||
fprintf(fh, " const ubyte[] bitmap;\n");
|
||||
fprintf(fh, "};\n");
|
||||
fprintf(fh, "struct FontInfo {\n");
|
||||
fprintf(fh, " uint line_height;\n");
|
||||
fprintf(fh, " uint advance;\n");
|
||||
fprintf(fh, " int baseline_offset;\n");
|
||||
fprintf(fh, " const CharInfo[] chars;\n");
|
||||
fprintf(fh, "};\n");
|
||||
fprintf(fh, "__gshared const FontInfo kfont = {\n");
|
||||
fprintf(fh, " %du,\n", line_height);
|
||||
fprintf(fh, " %du,\n", max_advance);
|
||||
fprintf(fh, " %d,\n", baseline_offset);
|
||||
fprintf(fh, " [\n");
|
||||
for (int i = 0; i < N_CHARS; i++)
|
||||
{
|
||||
fprintf(fh, " CharInfo(\n");
|
||||
fprintf(fh, " %du,\n", char_infos[i].width);
|
||||
fprintf(fh, " %du,\n", char_infos[i].height);
|
||||
fprintf(fh, " %d,\n", char_infos[i].top);
|
||||
fprintf(fh, " %d,\n", char_infos[i].left);
|
||||
if (char_infos[i].width > 0)
|
||||
{
|
||||
fprintf(c_file, "static const uint8_t char_bitmap_%d[] = {\n", i);
|
||||
generate_bytes(c_file, char_infos[i].bitmap, char_infos[i].width * char_infos[i].height);
|
||||
fprintf(c_file, "};\n");
|
||||
}
|
||||
fprintf(c_file, "static const fontgen_char_info_t char_%d = {\n", i);
|
||||
fprintf(c_file, " %d,\n", char_infos[i].width);
|
||||
fprintf(c_file, " %d,\n", char_infos[i].height);
|
||||
fprintf(c_file, " %d,\n", char_infos[i].top);
|
||||
fprintf(c_file, " %d,\n", char_infos[i].left);
|
||||
if (char_infos[i].width > 0)
|
||||
{
|
||||
fprintf(c_file, " char_bitmap_%d,\n", i);
|
||||
fprintf(fh, " [\n");
|
||||
generate_bytes(fh, char_infos[i].bitmap, char_infos[i].width * char_infos[i].height);
|
||||
fprintf(fh, " ]\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(c_file, " NULL,\n");
|
||||
fprintf(fh, " []\n");
|
||||
}
|
||||
fprintf(c_file, "};\n\n");
|
||||
fprintf(fh, " ),\n");
|
||||
}
|
||||
fprintf(c_file, "const fontgen_char_info_t * char_infos[] = {\n");
|
||||
for (int i = 0; i < N_CHARS; i++)
|
||||
{
|
||||
fprintf(c_file, " &char_%d,\n", i);
|
||||
}
|
||||
fprintf(c_file, "};\n");
|
||||
fprintf(c_file, "const fontgen_font_t kfont = {\n");
|
||||
fprintf(c_file, " %d,\n", line_height);
|
||||
fprintf(c_file, " %d,\n", max_advance);
|
||||
fprintf(c_file, " %d,\n", baseline_offset);
|
||||
fprintf(c_file, " char_infos,\n");
|
||||
fprintf(c_file, "};\n");
|
||||
fclose(c_file);
|
||||
fprintf(fh, " ],\n");
|
||||
fprintf(fh, "};\n");
|
||||
fclose(fh);
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
@@ -1,16 +0,0 @@
|
||||
.global gdt_set
|
||||
.extern gdtr
|
||||
.type gdt_set, @function
|
||||
gdt_set:
|
||||
lgdt gdtr
|
||||
jmp $0x8, $gdt_set_reload
|
||||
gdt_set_reload:
|
||||
mov $0x10, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
mov %ax, %fs
|
||||
mov %ax, %gs
|
||||
mov %ax, %ss
|
||||
ret
|
||||
|
||||
.size gdt_set, . - gdt_set
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "gdt.h"
|
||||
|
||||
static const gdt_entry_t gdt_entries[] = {
|
||||
/* Null descriptor */
|
||||
0u,
|
||||
/* Code segment for kernel */
|
||||
gdt_build_entry(0u, 0xFFFFFu, 1u, 0u, 1u, 1u, 0u, 1u, 0u, 1u, 1u, 0u),
|
||||
/* Data segment for kernel */
|
||||
gdt_build_entry(0u, 0xFFFFFu, 1u, 0u, 1u, 0u, 0u, 1u, 0u, 1u, 1u, 0u),
|
||||
};
|
||||
|
||||
gdtr_t gdtr;
|
||||
|
||||
void gdt_init(void)
|
||||
{
|
||||
gdtr.size = sizeof(gdt_entries);
|
||||
gdtr.offset_lower = (uintptr_t)gdt_entries & 0xFFFFu;
|
||||
gdtr.offset_upper = (uintptr_t)gdt_entries >> 16u;
|
||||
gdt_set();
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef GDT_H
|
||||
#define GDT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t size;
|
||||
uint16_t offset_lower;
|
||||
uint16_t offset_upper;
|
||||
uint16_t _reserved;
|
||||
} gdtr_t;
|
||||
|
||||
typedef uint64_t gdt_entry_t;
|
||||
#define gdt_build_entry(base, limit, pr, privl, s, ex, dc, rw, ac, gr, sz, l) \
|
||||
(gdt_entry_t)( \
|
||||
(((gdt_entry_t)base << 32) & 0xFF00000000000000ull) | /* Base 0:15 */ \
|
||||
(((gdt_entry_t)gr & 0x1u) << 55) | /* Granularity (0 = bytes, 1 = blocks) */ \
|
||||
(((gdt_entry_t)sz & 0x1u) << 54) | /* Size (0 = 16-bit, 1 = 32-bit) */ \
|
||||
(((gdt_entry_t)l & 0x1u) << 53) | /* L flag (x86_64 code) */ \
|
||||
(((gdt_entry_t)limit << 32) & 0x000F000000000000ull) | /* Limit 16:19 */ \
|
||||
(((gdt_entry_t)pr & 0x1u) << 47) | /* Present flag */ \
|
||||
(((gdt_entry_t)privl & 0x3u) << 45) | /* Privilege (ring level) */ \
|
||||
(((gdt_entry_t)s & 0x1u) << 44) | /* Type (0 = system, 1 = code/data) */ \
|
||||
(((gdt_entry_t)ex & 0x1u) << 43) | /* Executable flag */ \
|
||||
(((gdt_entry_t)dc & 0x1u) << 42) | /* Direction/Conforming */ \
|
||||
(((gdt_entry_t)rw & 0x1u) << 41) | /* Readable/Writable */ \
|
||||
(((gdt_entry_t)ac & 0x1u) << 40) | /* Accessed flag */ \
|
||||
(((gdt_entry_t)base << 16) & 0x000000FFFFFF0000ull) | /* Base 0:23 */ \
|
||||
((gdt_entry_t)limit & 0x000000000000FFFFull)) /* Limit 0:15 */
|
||||
|
||||
void gdt_init(void);
|
||||
void gdt_set(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* HELLO console support.
|
||||
*/
|
||||
module hello.console;
|
||||
|
||||
import uefi;
|
||||
import hello.hello;
|
||||
import core.stdc.stdarg;
|
||||
|
||||
struct console
|
||||
{
|
||||
/**
|
||||
* Format a hexadecimal value to a string.
|
||||
*
|
||||
* @param s String buffer.
|
||||
* @param v Value to format.
|
||||
* @param ptr If true, always output all 16 digits, and separate the upper and
|
||||
* lower halves with an underscore.
|
||||
*/
|
||||
private static size_t format_hex(CHAR16 * s, ulong v, bool ptr)
|
||||
{
|
||||
string hex_chars = "0123456789ABCDEF";
|
||||
bool print = ptr;
|
||||
size_t si = 0u;
|
||||
for (size_t i = 0u; i < 16u; i++)
|
||||
{
|
||||
if (ptr && (i == 8u))
|
||||
{
|
||||
s[si++] = '_';
|
||||
}
|
||||
ulong n = (v >> (60u - 4u * i)) & 0xFu;
|
||||
if (n != 0u)
|
||||
{
|
||||
print = true;
|
||||
}
|
||||
if (print || (i == 15u))
|
||||
{
|
||||
s[si++] = hex_chars[n];
|
||||
}
|
||||
}
|
||||
return si;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a decimal value to a string.
|
||||
*
|
||||
* @param s String buffer.
|
||||
* @param v Value to format.
|
||||
*/
|
||||
private static size_t format_dec(CHAR16 * s, ulong v)
|
||||
{
|
||||
string dec_chars = "0123456789";
|
||||
bool print;
|
||||
char[20] buf;
|
||||
size_t buf_i;
|
||||
while ((buf_i == 0u) || (v != 0u))
|
||||
{
|
||||
ulong n = v % 10u;
|
||||
buf[buf_i++] = dec_chars[n];
|
||||
v /= 10u;
|
||||
}
|
||||
for (size_t si = 0u; si < buf_i; si++)
|
||||
{
|
||||
s[si] = buf[buf_i - si - 1u];
|
||||
}
|
||||
return buf_i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to the console.
|
||||
*
|
||||
* @param s Format string.
|
||||
* @param args Variable arguments structure.
|
||||
*/
|
||||
public static void write(string s, va_list args)
|
||||
{
|
||||
__gshared static CHAR16[256] s16;
|
||||
size_t i = 0u;
|
||||
bool escape = false;
|
||||
foreach (char c; s)
|
||||
{
|
||||
if (escape)
|
||||
{
|
||||
if (c == '%')
|
||||
{
|
||||
s16[i++] = '%';
|
||||
}
|
||||
else if (c == 'x')
|
||||
{
|
||||
ulong v;
|
||||
va_arg(args, v);
|
||||
i += format_hex(&s16[i], v, false);
|
||||
}
|
||||
else if (c == 'p')
|
||||
{
|
||||
ulong v;
|
||||
va_arg(args, v);
|
||||
i += format_hex(&s16[i], v, true);
|
||||
}
|
||||
else if (c == 'S')
|
||||
{
|
||||
const(CHAR16) * s2;
|
||||
va_arg(args, s2);
|
||||
for (size_t s2_i = 0u; s2[s2_i] != 0; s2_i++)
|
||||
{
|
||||
s16[i++] = s2[s2_i];
|
||||
}
|
||||
}
|
||||
else if (c == 'u')
|
||||
{
|
||||
ulong v;
|
||||
va_arg(args, v);
|
||||
i += format_dec(&s16[i], v);
|
||||
}
|
||||
else
|
||||
{
|
||||
s16[i++] = c;
|
||||
}
|
||||
escape = false;
|
||||
}
|
||||
else if (c == '%')
|
||||
{
|
||||
escape = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
s16[i++] = c;
|
||||
}
|
||||
}
|
||||
s16[i++] = 0u;
|
||||
st.ConOut.OutputString(st.ConOut, &s16[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to the console.
|
||||
*
|
||||
* @param s Format string.
|
||||
*/
|
||||
public static extern (C) void write(string s, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, s);
|
||||
write(s, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to the console.
|
||||
*
|
||||
* @param s Format string.
|
||||
*/
|
||||
public static extern (C) void writeln(string s, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, s);
|
||||
write(s, args);
|
||||
write("\r\n", args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a message to press any key and wait for a key to be pressed.
|
||||
*/
|
||||
public static void wait_key()
|
||||
{
|
||||
writeln("Press any key...");
|
||||
st.ConIn.Reset(st.ConIn, FALSE);
|
||||
EFI_INPUT_KEY key;
|
||||
while (st.ConIn.ReadKeyStroke(st.ConIn, &key) == EFI_NOT_READY)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the console.
|
||||
*/
|
||||
public static void clear()
|
||||
{
|
||||
st.ConOut.ClearScreen(st.ConOut);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,457 @@
|
||||
/**
|
||||
* HELLO, the HOS EFI Lightweight LOader.
|
||||
*/
|
||||
module hello.hello;
|
||||
|
||||
import uefi;
|
||||
import hello.console;
|
||||
import hello.scratch;
|
||||
import hulk.bootinfo;
|
||||
import hulk.header;
|
||||
import hos.page_table;
|
||||
import hos.cpu;
|
||||
import hos.memory;
|
||||
import ldc.llvmasm;
|
||||
|
||||
__gshared EFI_SYSTEM_TABLE * st;
|
||||
extern extern(C) __gshared ubyte _hulk_bin_start;
|
||||
extern extern(C) __gshared ubyte _hulk_bin_end;
|
||||
|
||||
private HulkHeader * hulk_header()
|
||||
{
|
||||
return cast(HulkHeader *)&_hulk_bin_start;
|
||||
}
|
||||
|
||||
private BootInfo * bootinfo()
|
||||
{
|
||||
return &hulk_header().bootinfo;
|
||||
}
|
||||
|
||||
private ulong hulk_bin_phys()
|
||||
{
|
||||
return cast(ulong)&_hulk_bin_start;
|
||||
}
|
||||
|
||||
private ulong hulk_bin_size()
|
||||
{
|
||||
return cast(ulong)&_hulk_bin_end - cast(ulong)&_hulk_bin_start;
|
||||
}
|
||||
|
||||
private ulong hulk_total_size()
|
||||
{
|
||||
return cast(ulong)hulk_header().total_size;
|
||||
}
|
||||
|
||||
private ulong hulk_bss_size()
|
||||
{
|
||||
return hulk_total_size() - hulk_bin_size();
|
||||
}
|
||||
|
||||
private ulong hulk_stack_size()
|
||||
{
|
||||
return hulk_header().stack_size;
|
||||
}
|
||||
|
||||
private ulong hulk_virt_base_address()
|
||||
{
|
||||
return hulk_header().virt_base;
|
||||
}
|
||||
|
||||
private ulong hulk_virt_stack_top()
|
||||
{
|
||||
return hulk_header().virt_stack_top;
|
||||
}
|
||||
|
||||
private ulong hulk_virt_framebuffer_address()
|
||||
{
|
||||
return hulk_header().virt_fb_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if we're running in QEMU.
|
||||
*/
|
||||
private bool in_qemu()
|
||||
{
|
||||
ulong * firmware_vendor = cast(ulong *) st.FirmwareVendor;
|
||||
ulong fv1 = firmware_vendor[0];
|
||||
return fv1 ==
|
||||
((cast(ulong)'E') |
|
||||
(cast(ulong)'D' << 16) |
|
||||
(cast(ulong)'K' << 32) |
|
||||
(cast(ulong)' ' << 48));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a graphics mode.
|
||||
*/
|
||||
private bool set_graphics_mode()
|
||||
{
|
||||
uint max_horizontal_resolution = in_qemu() ? 1920u : 0xFFFFFFFFu;
|
||||
UINTN buffer_size = scratch.free();
|
||||
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
||||
EFI_HANDLE * handles = cast(EFI_HANDLE *)scratch.current();
|
||||
EFI_STATUS status = st.BootServices.LocateHandle(ByProtocol,
|
||||
&gop_guid, null, &buffer_size, handles);
|
||||
if (status != EFI_SUCCESS)
|
||||
{
|
||||
console.writeln("LocateHandle: error %x", status);
|
||||
return false;
|
||||
}
|
||||
EFI_HANDLE gop_handle = handles[0];
|
||||
EFI_HANDLE gop_interface;
|
||||
status = st.BootServices.HandleProtocol(gop_handle,
|
||||
&gop_guid, &gop_interface);
|
||||
if (status != EFI_SUCCESS)
|
||||
{
|
||||
console.writeln("HandleProtocol: error %x", status);
|
||||
return false;
|
||||
}
|
||||
if (gop_interface == null)
|
||||
{
|
||||
console.writeln("null interface from HandleProtocol");
|
||||
return false;
|
||||
}
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop = cast(EFI_GRAPHICS_OUTPUT_PROTOCOL *)gop_interface;
|
||||
UINTN info_size;
|
||||
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * info;
|
||||
uint best_width;
|
||||
uint best_mode_number;
|
||||
for (uint mode_number = 0u;
|
||||
(status = gop.QueryMode(gop, mode_number, &info_size, &info)) == EFI_SUCCESS;
|
||||
mode_number++)
|
||||
{
|
||||
if ((info.HorizontalResolution > best_width) &&
|
||||
(info.HorizontalResolution <= max_horizontal_resolution))
|
||||
{
|
||||
best_width = info.HorizontalResolution;
|
||||
best_mode_number = mode_number;
|
||||
}
|
||||
st.BootServices.FreePool(info);
|
||||
}
|
||||
if ((status = gop.SetMode(gop, best_mode_number)) != EFI_SUCCESS)
|
||||
{
|
||||
console.writeln("SetMode: Error %x\n", status);
|
||||
return false;
|
||||
}
|
||||
bootinfo().fb.buffer = cast(uint *)gop.Mode.FrameBufferBase;
|
||||
bootinfo().fb.width = gop.Mode.Info.HorizontalResolution;
|
||||
bootinfo().fb.height = gop.Mode.Info.VerticalResolution;
|
||||
bootinfo().fb.stride = gop.Mode.Info.PixelsPerScanLine;
|
||||
bootinfo().fb.format = gop.Mode.Info.PixelFormat;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk the EFI memory map and translate it to the HULK bootinfo format.
|
||||
*/
|
||||
private void get_memory_map(ulong * bss_phys, ulong * stack_phys, ulong * max_physical_address, UINTN * memory_map_key)
|
||||
{
|
||||
immutable static ubyte[] efi_to_hulk_memory_map_type = [
|
||||
BootInfo.MemoryRegion.Type.Reserved, // EfiReservedMemoryType
|
||||
BootInfo.MemoryRegion.Type.Conventional, // EfiLoaderCode
|
||||
BootInfo.MemoryRegion.Type.Conventional, // EfiLoaderData
|
||||
BootInfo.MemoryRegion.Type.Conventional, // EfiBootServicesCode
|
||||
BootInfo.MemoryRegion.Type.Conventional, // EfiBootServicesData
|
||||
BootInfo.MemoryRegion.Type.Reserved, // EfiRuntimeServicesCode
|
||||
BootInfo.MemoryRegion.Type.Reserved, // EfiRuntimeServicesData
|
||||
BootInfo.MemoryRegion.Type.Conventional, // EfiConventionalMemory
|
||||
BootInfo.MemoryRegion.Type.Unusable, // EfiUnusableMemory
|
||||
BootInfo.MemoryRegion.Type.ACPIReclaim, // EfiACPIReclaimMemory
|
||||
BootInfo.MemoryRegion.Type.ACPINVS, // EfiACPIMemoryNVS
|
||||
BootInfo.MemoryRegion.Type.MemoryMappedIO, // EfiMemoryMappedIO
|
||||
BootInfo.MemoryRegion.Type.MemoryMappedIOPortSpace, // EfiMemoryMappedIOPortSpace
|
||||
BootInfo.MemoryRegion.Type.PalCode, // EfiPalCode
|
||||
];
|
||||
*max_physical_address = 0u;
|
||||
UINTN memory_map_size = scratch.free();
|
||||
UINTN descriptor_size;
|
||||
UINT32 descriptor_version;
|
||||
ubyte * scratch_base = scratch.current();
|
||||
UINTN status = st.BootServices.GetMemoryMap(
|
||||
&memory_map_size,
|
||||
cast(EFI_MEMORY_DESCRIPTOR *)scratch_base,
|
||||
memory_map_key,
|
||||
&descriptor_size,
|
||||
&descriptor_version);
|
||||
if (status != EFI_SUCCESS)
|
||||
{
|
||||
console.writeln("GetMemoryMap: Error %x", status);
|
||||
for (;;) {}
|
||||
}
|
||||
size_t n_entries = memory_map_size / descriptor_size;
|
||||
size_t count;
|
||||
bool found_bss;
|
||||
bool found_stack;
|
||||
for (count = 0u; count < n_entries; count++)
|
||||
{
|
||||
if (count > bootinfo().memory_map.length)
|
||||
{
|
||||
console.writeln("Memory map too large");
|
||||
for (;;) {}
|
||||
}
|
||||
EFI_MEMORY_DESCRIPTOR * descriptor = cast(EFI_MEMORY_DESCRIPTOR *)&scratch_base[count * descriptor_size];
|
||||
ulong end_address = descriptor.PhysicalStart + descriptor.NumberOfPages * 4096u;
|
||||
if ((end_address > *max_physical_address) &&
|
||||
((descriptor.Type == EfiLoaderCode) ||
|
||||
(descriptor.Type == EfiLoaderData) ||
|
||||
(descriptor.Type == EfiBootServicesCode) ||
|
||||
(descriptor.Type == EfiBootServicesData) ||
|
||||
(descriptor.Type == EfiRuntimeServicesCode) ||
|
||||
(descriptor.Type == EfiRuntimeServicesData) ||
|
||||
(descriptor.Type == EfiConventionalMemory)))
|
||||
{
|
||||
*max_physical_address = end_address;
|
||||
}
|
||||
if (descriptor.Type >= efi_to_hulk_memory_map_type.length)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bootinfo().memory_map[count].base = descriptor.PhysicalStart;
|
||||
bootinfo().memory_map[count].size = descriptor.NumberOfPages * 4096u;
|
||||
bootinfo().memory_map[count].type = efi_to_hulk_memory_map_type[descriptor.Type];
|
||||
if ((!found_bss) &&
|
||||
(descriptor.Type == EfiConventionalMemory) &&
|
||||
(bootinfo().memory_map[count].size >= hulk_bss_size()))
|
||||
{
|
||||
*bss_phys = bootinfo().memory_map[count].base;
|
||||
bootinfo().memory_map[count].base += hulk_bss_size();
|
||||
bootinfo().memory_map[count].size -= hulk_bss_size();
|
||||
found_bss = true;
|
||||
}
|
||||
if ((!found_stack) &&
|
||||
(descriptor.Type == EfiConventionalMemory) &&
|
||||
(bootinfo().memory_map[count].size >= hulk_stack_size()))
|
||||
{
|
||||
*stack_phys = bootinfo().memory_map[count].base;
|
||||
bootinfo().memory_map[count].base += hulk_stack_size();
|
||||
bootinfo().memory_map[count].size -= hulk_stack_size();
|
||||
found_stack = true;
|
||||
}
|
||||
}
|
||||
bootinfo().memory_map_count = count;
|
||||
if ((!found_bss) && (!found_stack))
|
||||
{
|
||||
for (;;) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a new page table.
|
||||
*/
|
||||
private PageTableEntry * new_page_table()
|
||||
{
|
||||
PageTableEntry * pt = cast(PageTableEntry *)scratch.alloc(1u);
|
||||
memset64(pt, 0u, 512);
|
||||
return pt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a virtual address to a physical address using 4KB pages.
|
||||
*
|
||||
* @param source_page Source page address.
|
||||
* @param dest_page Destination page address.
|
||||
* @param pt_base Page table base address.
|
||||
*/
|
||||
private void map4k(ulong source_page, ulong dest_page, PageTableEntry * pt_base)
|
||||
{
|
||||
PageTableEntry * pt = pt_base;
|
||||
PageTableEntry * next_pt;
|
||||
for (size_t level = 0; level < 4u; level++)
|
||||
{
|
||||
size_t pt_index = PageTableEntry.page_table_index(source_page, level);
|
||||
if (pt[pt_index].present())
|
||||
{
|
||||
pt = pt[pt_index].next();
|
||||
}
|
||||
else
|
||||
{
|
||||
ulong addr;
|
||||
if (level < 3u)
|
||||
{
|
||||
next_pt = new_page_table();
|
||||
addr = cast(ulong)next_pt;
|
||||
}
|
||||
else
|
||||
{
|
||||
addr = dest_page;
|
||||
}
|
||||
pt[pt_index] = PageTableEntry(addr,
|
||||
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u);
|
||||
pt = next_pt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a virtual region to a physical region using 4KB pages.
|
||||
*
|
||||
* @param source Source address.
|
||||
* @param dest Destination address.
|
||||
* @param size Region size.
|
||||
* @param pt_base Page table base address.
|
||||
*/
|
||||
private void map4kregion(ulong source, ulong dest, size_t size, PageTableEntry * pt_base)
|
||||
{
|
||||
ulong end = source + size;
|
||||
while (source < end)
|
||||
{
|
||||
map4k(source, dest, pt_base);
|
||||
source += 4096u;
|
||||
dest += 4096u;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a virtual address to a physical address using 2MB pages.
|
||||
*
|
||||
* @param source_page Source page address.
|
||||
* @param dest_page Destination page address.
|
||||
* @param pt_base Page table base address.
|
||||
*/
|
||||
private void map2m(ulong source_page, ulong dest_page, PageTableEntry * pt_base)
|
||||
{
|
||||
PageTableEntry * pt = pt_base;
|
||||
PageTableEntry * next_pt;
|
||||
for (size_t level = 0; level < 3u; level++)
|
||||
{
|
||||
size_t pt_index = PageTableEntry.page_table_index(source_page, level);
|
||||
if (pt[pt_index].present())
|
||||
{
|
||||
pt = pt[pt_index].next();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (level < 2u)
|
||||
{
|
||||
next_pt = new_page_table();
|
||||
pt[pt_index] = PageTableEntry(cast(ulong)next_pt,
|
||||
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u);
|
||||
}
|
||||
else
|
||||
{
|
||||
pt[pt_index] = PageTableEntry(dest_page,
|
||||
0u, 0u, 1u, 0u, 0u, 0u, 1u, 1u);
|
||||
}
|
||||
pt = next_pt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map HULK virtual addresses to physical kernel location.
|
||||
*
|
||||
* @param pt_base Page table base address.
|
||||
*/
|
||||
private void map_hulk(PageTableEntry * pt_base, ulong bss_phys, ulong stack_phys)
|
||||
{
|
||||
/* Map HULK bin region. */
|
||||
ulong virt = hulk_virt_base_address();
|
||||
map4kregion(virt, hulk_bin_phys(), hulk_bin_size(), pt_base);
|
||||
/* Map HULK bss region. */
|
||||
virt += hulk_bin_size();
|
||||
map4kregion(virt, bss_phys, hulk_bss_size(), pt_base);
|
||||
/* Map HULK stack. */
|
||||
virt = hulk_virt_stack_top() - hulk_stack_size();
|
||||
map4kregion(virt, stack_phys, hulk_stack_size(), pt_base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build page tables in preparation to jump to HULK.
|
||||
*
|
||||
* @param max_physical_address Maximum physical address to identity map.
|
||||
*/
|
||||
private void build_page_tables(ulong max_physical_address, ulong bss_phys, ulong stack_phys)
|
||||
{
|
||||
PageTableEntry * pt_base = new_page_table();
|
||||
/* Map physical RAM. */
|
||||
for (size_t addr = 0u; addr < max_physical_address; addr += (2u * 1024u * 1024u))
|
||||
{
|
||||
map2m(addr, addr, pt_base);
|
||||
}
|
||||
/* Map any memory regions that are outside physical RAM. */
|
||||
for (size_t i = 0u; i < bootinfo().memory_map_count; i++)
|
||||
{
|
||||
ulong addr = bootinfo().memory_map[i].base;
|
||||
if (addr >= max_physical_address)
|
||||
{
|
||||
map4kregion(addr, addr, bootinfo().memory_map[i].size, pt_base);
|
||||
}
|
||||
}
|
||||
/* Map graphics framebuffer. */
|
||||
ulong framebuffer_size = bootinfo().fb.height * bootinfo().fb.stride * 4u;
|
||||
ulong fb_phys = cast(ulong)bootinfo().fb.buffer;
|
||||
ulong fb_virt = hulk_virt_framebuffer_address();
|
||||
map4kregion(fb_virt, fb_phys, framebuffer_size, pt_base);
|
||||
/* Map HULK regions. */
|
||||
map_hulk(pt_base, bss_phys, stack_phys);
|
||||
/* Switch to the new page table. */
|
||||
write_cr3(cast(ulong)pt_base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Jump to HULK entry point.
|
||||
*/
|
||||
private void jump_to_hulk()
|
||||
{
|
||||
__asm(
|
||||
"jmpq *$0",
|
||||
"r,{rsp}",
|
||||
hulk_header().entry, hulk_virt_stack_top());
|
||||
}
|
||||
|
||||
/**
|
||||
* EFI application entry point.
|
||||
*
|
||||
* @param image_handle EFI application handle.
|
||||
* @param st Pointer to EFI system table.
|
||||
*/
|
||||
extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st)
|
||||
{
|
||||
.st = st;
|
||||
|
||||
console.clear();
|
||||
|
||||
console.writeln("Welcome to HELLO, HOS EFI Lightweight LOader, v0.1.0");
|
||||
console.writeln("Firmware vendor: '%S', version: 0x%x", st.FirmwareVendor, st.FirmwareVendor);
|
||||
|
||||
bootinfo().pt_phys = cast(ulong)scratch.current();
|
||||
|
||||
if (!set_graphics_mode())
|
||||
{
|
||||
console.wait_key();
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
ulong bss_phys;
|
||||
ulong stack_phys;
|
||||
ulong max_physical_address;
|
||||
UINTN memory_map_key;
|
||||
for (;;)
|
||||
{
|
||||
get_memory_map(&bss_phys, &stack_phys, &max_physical_address, &memory_map_key);
|
||||
|
||||
EFI_STATUS status = st.BootServices.ExitBootServices(image_handle, memory_map_key);
|
||||
if (status == EFI_INVALID_PARAMETER)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (status == EFI_SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
console.writeln("ExitBootServices: Error %x", status);
|
||||
console.wait_key();
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
build_page_tables(max_physical_address, bss_phys, stack_phys);
|
||||
|
||||
bootinfo().hulk_phys = hulk_bin_phys();
|
||||
bootinfo().bss_phys = bss_phys;
|
||||
bootinfo().stack_phys = stack_phys;
|
||||
bootinfo().pt_size = cast(ulong)scratch.current() - bootinfo().pt_phys;
|
||||
|
||||
jump_to_hulk();
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* HELLO scratch buffer.
|
||||
*/
|
||||
module hello.scratch;
|
||||
|
||||
struct scratch
|
||||
{
|
||||
/* Scratch buffer. */
|
||||
private static align(4096) __gshared ubyte[1024 * 1024] scratch;
|
||||
|
||||
/* Number of scratch buffer bytes used. */
|
||||
private static __gshared size_t scratch_used;
|
||||
|
||||
/**
|
||||
* Get the number of free bytes in the scratch buffer.
|
||||
*/
|
||||
public static size_t free()
|
||||
{
|
||||
return scratch.sizeof - scratch_used;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current free scratch buffer address.
|
||||
*/
|
||||
public static ubyte * current()
|
||||
{
|
||||
return &scratch[scratch_used];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate pages from the scratch buffer.
|
||||
*/
|
||||
public static ubyte * alloc(size_t n = 1)
|
||||
{
|
||||
ubyte * address = &scratch[scratch_used];
|
||||
scratch_used += 4096u * n;
|
||||
return address;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import ldc.llvmasm;
|
||||
|
||||
ulong read_cr0()
|
||||
{
|
||||
return __asm!ulong("mov %cr0, %rax", "={rax}");
|
||||
}
|
||||
|
||||
ulong read_cr2()
|
||||
{
|
||||
return __asm!ulong("mov %cr2, %rax", "={rax}");
|
||||
}
|
||||
|
||||
ulong read_cr3()
|
||||
{
|
||||
return __asm!ulong("mov %cr3, %rax", "={rax}");
|
||||
}
|
||||
|
||||
void write_cr3(ulong v)
|
||||
{
|
||||
__asm("mov $0, %cr3", "r", v);
|
||||
}
|
||||
|
||||
ulong read_cr4()
|
||||
{
|
||||
return __asm!ulong("mov %cr4, %rax", "={rax}");
|
||||
}
|
||||
|
||||
ushort in16(ushort ioaddr)
|
||||
{
|
||||
return __asm!ushort("inw %dx, %ax", "={ax},{dx}", ioaddr);
|
||||
}
|
||||
|
||||
ulong in32(ushort ioaddr)
|
||||
{
|
||||
return __asm!ulong("inl %dx, %eax", "={eax},{dx}", ioaddr);
|
||||
}
|
||||
|
||||
void out16(ushort ioaddr, ushort v)
|
||||
{
|
||||
__asm("outw %ax, %dx", "{dx},{ax}", ioaddr, v);
|
||||
}
|
||||
|
||||
void out32(ushort ioaddr, ulong v)
|
||||
{
|
||||
__asm("outl %eax, %dx", "{dx},{eax}", ioaddr, v);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import ldc.llvmasm;
|
||||
|
||||
void memset(void * dest, ubyte v, size_t n)
|
||||
{
|
||||
__asm("rep stosb",
|
||||
"{al},{rcx},{rdi},~{rcx},~{rdi},~{memory}",
|
||||
v, n, dest);
|
||||
}
|
||||
|
||||
void memset16(void * dest, ushort v, size_t n)
|
||||
{
|
||||
__asm("rep stosw",
|
||||
"{ax},{rcx},{rdi},~{rcx},~{rdi},~{memory}",
|
||||
v, n, dest);
|
||||
}
|
||||
|
||||
void memset32(void * dest, uint v, size_t n)
|
||||
{
|
||||
__asm("rep stosl",
|
||||
"{eax},{rcx},{rdi},~{rcx},~{rdi},~{memory}",
|
||||
v, n, dest);
|
||||
}
|
||||
|
||||
void memset64(void * dest, ulong v, size_t n)
|
||||
{
|
||||
__asm("rep stosq",
|
||||
"{rax},{rcx},{rdi},~{rcx},~{rdi},~{memory}",
|
||||
v, n, dest);
|
||||
}
|
||||
|
||||
void memcpy(void * dest, void * src, size_t n)
|
||||
{
|
||||
__asm("rep movsb",
|
||||
"{rcx},{rsi},{rdi},~{rcx},~{rsi},~{rdi},~{memory}",
|
||||
n, src, dest);
|
||||
}
|
||||
|
||||
void memcpy16(void * dest, void * src, size_t n)
|
||||
{
|
||||
__asm("rep movsw",
|
||||
"{rcx},{rsi},{rdi},~{rcx},~{rsi},~{rdi},~{memory}",
|
||||
n, src, dest);
|
||||
}
|
||||
|
||||
void memcpy32(void * dest, void * src, size_t n)
|
||||
{
|
||||
__asm("rep movsl",
|
||||
"{rcx},{rsi},{rdi},~{rcx},~{rsi},~{rdi},~{memory}",
|
||||
n, src, dest);
|
||||
}
|
||||
|
||||
void memcpy64(void * dest, void * src, size_t n)
|
||||
{
|
||||
__asm("rep movsq",
|
||||
"{rcx},{rsi},{rdi},~{rcx},~{rsi},~{rdi},~{memory}",
|
||||
n, src, dest);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
struct PageTableEntry
|
||||
{
|
||||
ulong entry;
|
||||
|
||||
this(ulong address, ulong no_execute, ulong global,
|
||||
ulong huge, ulong disable_cache, ulong write_through, ulong user,
|
||||
ulong writable, ulong present)
|
||||
{
|
||||
entry = (present |
|
||||
(writable << 1) |
|
||||
(user << 2) |
|
||||
(write_through << 3) |
|
||||
(disable_cache << 4) |
|
||||
(huge << 7) |
|
||||
(global << 8) |
|
||||
(no_execute << 63)) | address;
|
||||
}
|
||||
|
||||
bool present()
|
||||
{
|
||||
return (entry & 0x1u) != 0u;
|
||||
}
|
||||
|
||||
PageTableEntry * next()
|
||||
{
|
||||
return cast(PageTableEntry *)(entry & 0x7FFF_FFFF_FFFF_F000u);
|
||||
}
|
||||
|
||||
static ulong page_table_index(ulong address, size_t level)
|
||||
{
|
||||
return ((address >> (39u - 9u * level)) & 0x1FFu);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include "fb.h"
|
||||
#include "mbinfo.h"
|
||||
#include "klog.h"
|
||||
#include "gdt.h"
|
||||
#include "mm.h"
|
||||
|
||||
void hos_main(uint32_t mbinfo_addr)
|
||||
{
|
||||
gdt_init();
|
||||
if (!mbinfo_init(mbinfo_addr))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!fb_ready())
|
||||
{
|
||||
return;
|
||||
}
|
||||
klog_init();
|
||||
klog_printf("Welcome to HOS!\n");
|
||||
mm_init();
|
||||
mbinfo_load();
|
||||
klog_printf("Found %dKB of usable RAM\n", mm_get_total_ram() / 1024u);
|
||||
klog_printf("Kernel is %dKB at 0x%x\n", mm_get_kernel_size() / 1024u, mm_get_kernel_address());
|
||||
}
|
||||
@@ -1,281 +0,0 @@
|
||||
#include "hos_printf.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "string.h"
|
||||
|
||||
static size_t format_dec(char * buffer, int32_t v)
|
||||
{
|
||||
size_t sz = 0u;
|
||||
bool printing = false;
|
||||
if (v < 0)
|
||||
{
|
||||
buffer[sz++] = '-';
|
||||
v = -v;
|
||||
}
|
||||
for (int32_t div = 1000000000; div >= 1; div /= 10)
|
||||
{
|
||||
int32_t digit = v / div;
|
||||
v %= div;
|
||||
if ((digit != 0) || (div == 1))
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
buffer[sz++] = digit + '0';
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
static size_t format_dec64(char * buffer, int64_t v)
|
||||
{
|
||||
size_t sz = 0u;
|
||||
bool printing = false;
|
||||
if (v < 0)
|
||||
{
|
||||
buffer[sz++] = '-';
|
||||
v = -v;
|
||||
}
|
||||
for (int64_t div = 1000000000000000000; div >= 1; div /= 10)
|
||||
{
|
||||
int64_t digit = v / div;
|
||||
v %= div;
|
||||
if ((digit != 0) || (div == 1))
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
buffer[sz++] = digit + '0';
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
static size_t format_udec(char * buffer, int32_t v)
|
||||
{
|
||||
size_t sz = 0u;
|
||||
for (int32_t div = 1000000000u; div >= 1u; div /= 10u)
|
||||
{
|
||||
int32_t digit = v / div;
|
||||
v %= div;
|
||||
if ((digit != 0) || (sz > 0u) || (div == 1))
|
||||
{
|
||||
buffer[sz++] = digit + '0';
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
static size_t format_udec64(char * buffer, uint64_t v)
|
||||
{
|
||||
size_t sz = 0u;
|
||||
for (uint64_t div = 10000000000000000000u; div >= 1u; div /= 10u)
|
||||
{
|
||||
uint64_t digit = v / div;
|
||||
v %= div;
|
||||
if ((digit != 0) || (sz > 0u) || (div == 1))
|
||||
{
|
||||
buffer[sz++] = digit + '0';
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
static size_t format_hex(char * buffer, uint32_t v, bool upper)
|
||||
{
|
||||
const char upper_hex[] = "0123456789ABCDEF";
|
||||
const char lower_hex[] = "0123456789abcdef";
|
||||
size_t sz = 0u;
|
||||
for (int i = 28; i >= 0; i -= 4)
|
||||
{
|
||||
uint8_t n = (v >> i) & 0xFu;
|
||||
if ((sz > 0u) || (n != 0u) || (i == 0))
|
||||
{
|
||||
buffer[sz] = upper ? upper_hex[n] : lower_hex[n];
|
||||
sz++;
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
static size_t format_hex64(char * buffer, uint64_t v, bool upper)
|
||||
{
|
||||
const char upper_hex[] = "0123456789ABCDEF";
|
||||
const char lower_hex[] = "0123456789abcdef";
|
||||
size_t sz = 0u;
|
||||
for (int i = 60; i >= 0; i -= 4)
|
||||
{
|
||||
uint8_t n = (v >> i) & 0xFu;
|
||||
if ((sz > 0u) || (n != 0u) || (i == 0))
|
||||
{
|
||||
buffer[sz] = upper ? upper_hex[n] : lower_hex[n];
|
||||
sz++;
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
static void pad_write(const stream_t * stream, const char * data, size_t length, bool leading_zero, bool left_just, size_t width)
|
||||
{
|
||||
if (left_just)
|
||||
{
|
||||
stream->write(data, length);
|
||||
while (length < width)
|
||||
{
|
||||
stream->write1(' ');
|
||||
length++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char fill = leading_zero ? '0' : ' ';
|
||||
size_t l = length;
|
||||
while (l < width)
|
||||
{
|
||||
stream->write1(fill);
|
||||
l++;
|
||||
}
|
||||
stream->write(data, length);
|
||||
}
|
||||
}
|
||||
|
||||
void hos_vprintf(const stream_t * stream, const char * fmt, va_list va)
|
||||
{
|
||||
bool in_conv = false;
|
||||
char c;
|
||||
char buffer[22];
|
||||
size_t width;
|
||||
bool leading_zero;
|
||||
bool left_just;
|
||||
bool long_flag;
|
||||
size_t length;
|
||||
while ((c = *fmt))
|
||||
{
|
||||
if (in_conv)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '%':
|
||||
stream->write1('%');
|
||||
break;
|
||||
case 'X':
|
||||
{
|
||||
if (long_flag)
|
||||
{
|
||||
uint64_t v = va_arg(va, uint64_t);
|
||||
length = format_hex(buffer, v, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t v = va_arg(va, uint32_t);
|
||||
length = format_hex(buffer, v, true);
|
||||
}
|
||||
pad_write(stream, buffer, length, leading_zero, left_just, width);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
{
|
||||
char ch = va_arg(va, int);
|
||||
pad_write(stream, &ch, 1u, leading_zero, left_just, width);
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
{
|
||||
if (long_flag)
|
||||
{
|
||||
int64_t v = va_arg(va, int64_t);
|
||||
length = format_dec64(buffer, v);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t v = va_arg(va, int32_t);
|
||||
length = format_dec(buffer, v);
|
||||
}
|
||||
pad_write(stream, buffer, length, leading_zero, left_just, width);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
{
|
||||
const char * s = va_arg(va, const char *);
|
||||
pad_write(stream, s, strlen(s), leading_zero, left_just, width);
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
if (long_flag)
|
||||
{
|
||||
uint64_t v = va_arg(va, uint64_t);
|
||||
length = format_udec64(buffer, v);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t v = va_arg(va, uint32_t);
|
||||
length = format_udec(buffer, v);
|
||||
}
|
||||
pad_write(stream, buffer, length, leading_zero, left_just, width);
|
||||
}
|
||||
break;
|
||||
case 'x':
|
||||
{
|
||||
if (long_flag)
|
||||
{
|
||||
uint64_t v = va_arg(va, uint64_t);
|
||||
length = format_hex64(buffer, v, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t v = va_arg(va, uint32_t);
|
||||
length = format_hex(buffer, v, false);
|
||||
}
|
||||
pad_write(stream, buffer, length, leading_zero, left_just, width);
|
||||
}
|
||||
break;
|
||||
}
|
||||
in_conv = false;
|
||||
}
|
||||
else if (c == '%')
|
||||
{
|
||||
in_conv = true;
|
||||
width = 0u;
|
||||
leading_zero = false;
|
||||
left_just = false;
|
||||
long_flag = false;
|
||||
if (fmt[1] == '-')
|
||||
{
|
||||
left_just = true;
|
||||
fmt++;
|
||||
}
|
||||
if (fmt[1] == '0')
|
||||
{
|
||||
leading_zero = true;
|
||||
fmt++;
|
||||
}
|
||||
while (('0' <= fmt[1]) && (fmt[1] <= '9'))
|
||||
{
|
||||
width *= 10u;
|
||||
width += (fmt[1] - '0');
|
||||
fmt++;
|
||||
}
|
||||
if (fmt[1] == 'l')
|
||||
{
|
||||
long_flag = true;
|
||||
fmt++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stream->write1(c);
|
||||
}
|
||||
fmt++;
|
||||
}
|
||||
}
|
||||
|
||||
void hos_printf(const stream_t * stream, const char * fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
hos_vprintf(stream, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef HOS_PRINTF_H
|
||||
#define HOS_PRINTF_H
|
||||
|
||||
#include "stream.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
void hos_vprintf(const stream_t * stream, const char * fmt, va_list va);
|
||||
void hos_printf(const stream_t * stream, const char * fmt, ...);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* HULK boot information.
|
||||
*/
|
||||
module hulk.bootinfo;
|
||||
|
||||
/**
|
||||
* HULK boot information structure.
|
||||
*/
|
||||
struct BootInfo
|
||||
{
|
||||
/**
|
||||
* Framebuffer description structure.
|
||||
*/
|
||||
struct Framebuffer
|
||||
{
|
||||
/** Framebuffer physical base address. */
|
||||
uint * buffer;
|
||||
/** Horizontal resolution. */
|
||||
uint width;
|
||||
/** Vertical resolution. */
|
||||
uint height;
|
||||
/** Number of pixels per scan line. */
|
||||
uint stride;
|
||||
/** Pixel format. */
|
||||
uint format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Memory map entry description structure.
|
||||
*/
|
||||
struct MemoryRegion
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
Reserved,
|
||||
Conventional,
|
||||
Unusable,
|
||||
ACPIReclaim,
|
||||
ACPINVS,
|
||||
MemoryMappedIO,
|
||||
MemoryMappedIOPortSpace,
|
||||
PalCode,
|
||||
}
|
||||
|
||||
/** Base address of the memory region. */
|
||||
ulong base;
|
||||
/** Size in bytes of the memory region. */
|
||||
size_t size;
|
||||
/** Type of the memory region. */
|
||||
ubyte type;
|
||||
}
|
||||
|
||||
/* Framebuffer parameters. */
|
||||
Framebuffer fb;
|
||||
|
||||
/* Memory map. */
|
||||
MemoryRegion[1000] memory_map;
|
||||
|
||||
/* Number of memory map entries. */
|
||||
size_t memory_map_count;
|
||||
|
||||
/* Physical address of HULK. */
|
||||
ulong hulk_phys;
|
||||
|
||||
/* Physical address used for HULK bss section. */
|
||||
ulong bss_phys;
|
||||
|
||||
/* Physical address of stack while jumping to HULK. */
|
||||
ulong stack_phys;
|
||||
|
||||
/* Physical address of page tables while jumping to HULK. */
|
||||
ulong pt_phys;
|
||||
|
||||
/* Size of page tables while jumping to HULK. */
|
||||
ulong pt_size;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* HULK Console functionality.
|
||||
*/
|
||||
module hulk.console;
|
||||
|
||||
import hulk.fb;
|
||||
import hulk.kfont;
|
||||
|
||||
struct console
|
||||
{
|
||||
/** Console width in text columns. */
|
||||
private static __gshared size_t m_width;
|
||||
|
||||
/** Console height in text rows. */
|
||||
private static __gshared size_t m_height;
|
||||
|
||||
/** Current console cursor X position. */
|
||||
private static __gshared size_t m_x;
|
||||
|
||||
/** Current console cursor Y position. */
|
||||
private static __gshared size_t m_y;
|
||||
|
||||
/**
|
||||
* Initialize the console.
|
||||
*/
|
||||
public static void initialize()
|
||||
{
|
||||
m_width = fb.width / kfont.advance;
|
||||
m_height = fb.height / kfont.line_height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the console.
|
||||
*/
|
||||
public static void clear()
|
||||
{
|
||||
fb.clear();
|
||||
m_x = 0u;
|
||||
m_y = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a character to the console.
|
||||
*
|
||||
* @param ch Character to write.
|
||||
*/
|
||||
public static void write(char ch)
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
m_x = 0u;
|
||||
m_y++;
|
||||
}
|
||||
else
|
||||
{
|
||||
render_char(m_x, m_y, ch);
|
||||
m_x++;
|
||||
if (m_x == m_width)
|
||||
{
|
||||
m_x = 0u;
|
||||
m_y++;
|
||||
}
|
||||
}
|
||||
if (m_y == m_height)
|
||||
{
|
||||
m_y--;
|
||||
fb.copy_rows_up(fb_y(m_height - 1u),
|
||||
(m_height - 1u) * kfont.line_height,
|
||||
kfont.line_height);
|
||||
fb.rect(0u, fb_y(m_height - 1u), fb_x(m_width), kfont.line_height, 0u);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a character.
|
||||
*
|
||||
* @param x X position.
|
||||
* @param y Y position.
|
||||
* @param ch Character to render.
|
||||
*/
|
||||
private static void render_char(size_t x, size_t y, char ch)
|
||||
{
|
||||
const(CharInfo) * ci = &kfont.chars[ch];
|
||||
fb.blit_alpha_bitmap(fb_x(x) + ci.left, fb_y(y) + ci.top - ci.height, ci.bitmap, ci.width, ci.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the framebuffer X coordinate corresponding to the console X position.
|
||||
*/
|
||||
private static size_t fb_x(size_t x)
|
||||
{
|
||||
return x * kfont.advance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the framebuffer Y coordinate corresponding to the console Y position.
|
||||
*/
|
||||
private static size_t fb_y(size_t y)
|
||||
{
|
||||
return fb.height - ((y + 1u) * kfont.line_height);
|
||||
}
|
||||
}
|
||||
+274
@@ -0,0 +1,274 @@
|
||||
/**
|
||||
* HULK Framebuffer support.
|
||||
*/
|
||||
module hulk.fb;
|
||||
|
||||
import hos.memory;
|
||||
import hulk.kfont;
|
||||
|
||||
/**
|
||||
* Represent a graphical frame buffer.
|
||||
*
|
||||
* TODO: Handle other pixel formats. Currently only BGRx is supported.
|
||||
*/
|
||||
struct fb
|
||||
{
|
||||
/** Frame buffer base address. */
|
||||
private __gshared static uint * m_buffer;
|
||||
|
||||
/** Frame buffer width. */
|
||||
private __gshared static uint m_width;
|
||||
|
||||
/** Frame buffer height. */
|
||||
private __gshared static uint m_height;
|
||||
|
||||
/** Frame buffer stride. */
|
||||
private __gshared static uint m_stride;
|
||||
|
||||
/** Number of pixels in the frame buffer (whether visible or not). */
|
||||
private __gshared static uint m_buffer_size;
|
||||
|
||||
/**
|
||||
* Get the framebuffer width.
|
||||
*/
|
||||
public static @property uint width()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the framebuffer height.
|
||||
*/
|
||||
public static @property uint height()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a frame buffer.
|
||||
*
|
||||
* @param buffer Frame buffer base address.
|
||||
* @param width Frame buffer width.
|
||||
* @param height Frame buffer height.
|
||||
* @param stride Frame buffer stride.
|
||||
*/
|
||||
static void initialize(uint * buffer, uint width, uint height, uint stride)
|
||||
{
|
||||
m_buffer = buffer;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_stride = stride;
|
||||
m_buffer_size = stride * height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the frame buffer to the given color.
|
||||
*
|
||||
* @param color Color to clear to.
|
||||
*/
|
||||
static void clear(uint color = 0u)
|
||||
{
|
||||
memset32(m_buffer, color, m_buffer_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a solid rectangle on the framebuffer.
|
||||
*
|
||||
* @param x X coordinate of left side of rectangle.
|
||||
* @param y Y coordinate of bottom side of rectangle.
|
||||
* @param width Width of rectangle.
|
||||
* @param height Height of rectangle.
|
||||
* @param color Color of rectangle.
|
||||
*/
|
||||
static void rect(size_t x, size_t y, size_t width, size_t height, uint color)
|
||||
{
|
||||
for (size_t iy = 0u; iy < height; iy++)
|
||||
{
|
||||
size_t buffer_index = buffer_index(x, y);
|
||||
memset32(&m_buffer[buffer_index], color, width);
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a horizontal line.
|
||||
*
|
||||
* @param x X coordinate of left side of line.
|
||||
* @param y Y coordinate of line.
|
||||
* @param width Width of line.
|
||||
* @param color Color of line.
|
||||
*/
|
||||
static void hline(size_t x, size_t y, size_t width, uint color)
|
||||
{
|
||||
size_t buffer_index = buffer_index(x, y);
|
||||
memset32(&m_buffer[buffer_index], color, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a vertical line.
|
||||
*
|
||||
* @param x X coordinate of line.
|
||||
* @param y Y coordinate of bottom of line.
|
||||
* @param height Height of line.
|
||||
* @param color Color of line.
|
||||
*/
|
||||
static void vline(size_t x, size_t y, size_t height, uint color)
|
||||
{
|
||||
size_t buffer_index = buffer_index(x, y);
|
||||
for (size_t iy = 0u; iy < height; iy++)
|
||||
{
|
||||
m_buffer[buffer_index] = color;
|
||||
buffer_index -= m_stride;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a character.
|
||||
*
|
||||
* @param x X coordinate of left side of character.
|
||||
* @param y Y coordinate of bottom side of character.
|
||||
* @param ch Character to draw.
|
||||
* @param color Color of character.
|
||||
*/
|
||||
static void character(int x, int y, char ch, uint color)
|
||||
{
|
||||
const(CharInfo) * ci = &kfont.chars[ch];
|
||||
blend_alpha_bitmap(x + ci.left, y + kfont.baseline_offset + ci.top - ci.height, ci.bitmap, ci.width, ci.height, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blend an 8-bit alpha bitmap to the framebuffer.
|
||||
*
|
||||
* @param x X coordinate of left side of target location.
|
||||
* @param y Y coordinate of bottom side of target location.
|
||||
* @param alpha_bitmap 8-bit alpha-channel bitmap.
|
||||
* @param width Bitmap width.
|
||||
* @param height Bitmap height.
|
||||
* @param color Color to blend with alpha value.
|
||||
*/
|
||||
static void blend_alpha_bitmap(size_t x, size_t y, const(ubyte) * alpha_bitmap,
|
||||
size_t width, size_t height, uint color)
|
||||
{
|
||||
y += height - 1u;
|
||||
size_t bitmap_index;
|
||||
for (size_t iy = 0u; iy < height; iy++)
|
||||
{
|
||||
for (size_t ix = 0u; ix < width; ix++)
|
||||
{
|
||||
size_t buffer_index = buffer_index(x + ix, y);
|
||||
ubyte alpha = alpha_bitmap[bitmap_index];
|
||||
uint current_color = m_buffer[buffer_index];
|
||||
uint in_color_scaled = scale_color(color, alpha);
|
||||
uint old_color_scaled = scale_color(current_color, 255u - alpha);
|
||||
uint new_color = old_color_scaled + in_color_scaled;
|
||||
m_buffer[buffer_index] = new_color;
|
||||
bitmap_index++;
|
||||
}
|
||||
y--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blend an 8-bit alpha bitmap to the framebuffer.
|
||||
*
|
||||
* @param x X coordinate of left side of target location.
|
||||
* @param y Y coordinate of bottom side of target location.
|
||||
* @param alpha_bitmap 8-bit alpha-channel bitmap.
|
||||
* @param width Bitmap width.
|
||||
* @param height Bitmap height.
|
||||
* @param color Color to blend with alpha value.
|
||||
*/
|
||||
static void blend_alpha_bitmap(size_t x, size_t y, const(ubyte)[] alpha_bitmap,
|
||||
size_t width, size_t height, uint color)
|
||||
{
|
||||
blend_alpha_bitmap(x, y, alpha_bitmap.ptr, width, height, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blit an 8-bit alpha bitmap to the framebuffer.
|
||||
* The foreground will be white (based on the alpha value), and the
|
||||
* background black.
|
||||
*
|
||||
* @param x X coordinate of left side of target location.
|
||||
* @param y Y coordinate of bottom side of target location.
|
||||
* @param alpha_bitmap 8-bit alpha-channel bitmap.
|
||||
* @param width Bitmap width.
|
||||
* @param height Bitmap height.
|
||||
*/
|
||||
static void blit_alpha_bitmap(size_t x, size_t y, const(ubyte) * alpha_bitmap,
|
||||
size_t width, size_t height)
|
||||
{
|
||||
y += height - 1u;
|
||||
size_t bitmap_index;
|
||||
for (size_t iy = 0u; iy < height; iy++)
|
||||
{
|
||||
for (size_t ix = 0u; ix < width; ix++)
|
||||
{
|
||||
size_t buffer_index = buffer_index(x + ix, y);
|
||||
ubyte alpha = alpha_bitmap[bitmap_index];
|
||||
m_buffer[buffer_index] = (alpha << 16u) | (alpha << 8u) | alpha;
|
||||
bitmap_index++;
|
||||
}
|
||||
y--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blit an 8-bit alpha bitmap to the framebuffer.
|
||||
* The foreground will be white (based on the alpha value), and the
|
||||
* background black.
|
||||
*
|
||||
* @param x X coordinate of left side of target location.
|
||||
* @param y Y coordinate of bottom side of target location.
|
||||
* @param alpha_bitmap 8-bit alpha-channel bitmap.
|
||||
* @param width Bitmap width.
|
||||
* @param height Bitmap height.
|
||||
*/
|
||||
static void blit_alpha_bitmap(size_t x, size_t y, const(ubyte)[] alpha_bitmap,
|
||||
size_t width, size_t height)
|
||||
{
|
||||
blit_alpha_bitmap(x, y, alpha_bitmap.ptr, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy framebuffer rows up in the framebuffer.
|
||||
*
|
||||
* @param y Y coordinate of bottom side of region to copy up.
|
||||
* @param height Height of region to copy up.
|
||||
* @param offset Number of rows to copy region up by.
|
||||
*/
|
||||
static void copy_rows_up(size_t y, size_t height, size_t offset)
|
||||
{
|
||||
memcpy32(&m_buffer[buffer_index(0u, y + height + offset - 1u)],
|
||||
&m_buffer[buffer_index(0u, y + height - 1u)],
|
||||
(m_stride * height));
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a color value by an alpha amount.
|
||||
*
|
||||
* @param color Color value.
|
||||
* @param alpha Alpha amount.
|
||||
*
|
||||
* @return Scaled color value.
|
||||
*/
|
||||
private static uint scale_color(uint color, ubyte alpha)
|
||||
{
|
||||
return ((((color & 0xFFu) * alpha) >> 8u) & 0xFFu) |
|
||||
((((color & 0xFF00u) * alpha) >> 8u) & 0xFF00u) |
|
||||
((((color & 0xFF0000u) * alpha) >> 8u) & 0xFF0000u);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the buffer index for the given X and Y coordinates.
|
||||
*
|
||||
* @param x X coordinate from left side of framebuffer.
|
||||
* @param y Y coordinate from bottom side of framebuffer.
|
||||
*
|
||||
* @return Buffer index for the given X and Y coordinates.
|
||||
*/
|
||||
private static size_t buffer_index(size_t x, size_t y)
|
||||
{
|
||||
return (m_height - y - 1u) * m_stride + x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* HULK image header.
|
||||
*/
|
||||
module hulk.header;
|
||||
|
||||
import hulk.bootinfo;
|
||||
|
||||
/**
|
||||
* Header describing the HULK image.
|
||||
*/
|
||||
struct HulkHeader
|
||||
{
|
||||
/**
|
||||
* Total size of memory to be mapped.
|
||||
*
|
||||
* The OS loader must ensure that virtual memory is mapped for this entire
|
||||
* size.
|
||||
* This value is really an integer, but is stored as a pointer because it
|
||||
* is provided by the linker and LDC does not like us to cast it.
|
||||
*/
|
||||
void * total_size;
|
||||
|
||||
/** Entry point. */
|
||||
void * entry;
|
||||
|
||||
/** Stack size. */
|
||||
ulong stack_size;
|
||||
|
||||
/** Virtual base address. */
|
||||
ulong virt_base;
|
||||
|
||||
/** Stack top virtual address. */
|
||||
ulong virt_stack_top;
|
||||
|
||||
/** Framebuffer virtual address. */
|
||||
ulong virt_fb_buffer;
|
||||
|
||||
/** HULK boot information. */
|
||||
BootInfo bootinfo;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* HIPPO, the HOS In-place Physical Page Organizer.
|
||||
*/
|
||||
module hulk.hippo;
|
||||
|
||||
import hulk.header;
|
||||
import hulk.bootinfo;
|
||||
import hulk.klog;
|
||||
import hulk.linker_addresses;
|
||||
|
||||
struct hippo
|
||||
{
|
||||
/**
|
||||
* Linked list node entry for a physical page.
|
||||
*/
|
||||
private struct PhysicalPage
|
||||
{
|
||||
PhysicalPage * next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Linked list of free physical pages.
|
||||
*/
|
||||
private static __gshared PhysicalPage * free_pages;
|
||||
|
||||
/**
|
||||
* Number of free physical pages.
|
||||
*/
|
||||
private static __gshared size_t n_free_pages;
|
||||
|
||||
/**
|
||||
* Initialize HIPPO.
|
||||
*
|
||||
* Ok, what we do here is iterate through all of the memory map regions in
|
||||
* the bootinfo memory_map array, and create a linked list of all free
|
||||
* physical pages that are available. Within the available memory regions,
|
||||
* we have to watch out for the following items:
|
||||
* 1) HULK binary (text + data)
|
||||
* - This includes the HULK header and bootinfo structures
|
||||
* 2) HULK bss
|
||||
* 3) HULK stack
|
||||
* 4) Framebuffer
|
||||
* 5) Page tables
|
||||
*
|
||||
* @param bootinfo HULK boot information structure.
|
||||
*/
|
||||
public static void initialize(HulkHeader * header)
|
||||
{
|
||||
size_t usable_memory;
|
||||
ulong[2][5] reserved = [
|
||||
[header.bootinfo.hulk_phys, cast(ulong)header.total_size],
|
||||
[header.bootinfo.bss_phys, LinkerAddresses.hulk_bss_size],
|
||||
[header.bootinfo.stack_phys, header.stack_size],
|
||||
[cast(ulong)header.bootinfo.fb.buffer, header.bootinfo.fb.height * header.bootinfo.fb.stride],
|
||||
[header.bootinfo.pt_phys, header.bootinfo.pt_size],
|
||||
];
|
||||
for (size_t ri = 0u; ri < reserved.length; ri++)
|
||||
{
|
||||
reserved[ri][1] += reserved[ri][0];
|
||||
}
|
||||
for (size_t bii = 0u; bii < header.bootinfo.memory_map_count; bii++)
|
||||
{
|
||||
if (header.bootinfo.memory_map[bii].type == BootInfo.MemoryRegion.Type.Conventional)
|
||||
{
|
||||
ulong phys = header.bootinfo.memory_map[bii].base;
|
||||
ulong phys_end = phys + header.bootinfo.memory_map[bii].size;
|
||||
usable_memory += header.bootinfo.memory_map[bii].size;
|
||||
while (phys < phys_end)
|
||||
{
|
||||
bool is_reserved = false;
|
||||
for (size_t ri = 0u; ri < reserved.length; ri++)
|
||||
{
|
||||
if ((reserved[ri][0] <= phys) && (phys < reserved[ri][1]))
|
||||
{
|
||||
is_reserved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!is_reserved)
|
||||
{
|
||||
free_page(phys);
|
||||
}
|
||||
phys += 4096u;
|
||||
}
|
||||
}
|
||||
}
|
||||
size_t usable_kb = usable_memory >> 10u;
|
||||
size_t usable_mb = usable_kb >> 10u;
|
||||
size_t frac_mb = ((1000u * (usable_kb & 0x3FFu)) + 512u) >> 10u;
|
||||
klog.writefln("Found %u.%03uMB of usable RAM", usable_mb, frac_mb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a physical page.
|
||||
*
|
||||
* @param phys Physical page address.
|
||||
*/
|
||||
private static void free_page(ulong phys)
|
||||
{
|
||||
PhysicalPage * pp = cast(PhysicalPage *)phys;
|
||||
pp.next = free_pages;
|
||||
free_pages = pp;
|
||||
n_free_pages++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a physical page.
|
||||
*
|
||||
* @return Page address, or null if none available.
|
||||
*/
|
||||
public static void * allocate_page()
|
||||
{
|
||||
PhysicalPage * pp;
|
||||
if (free_pages != null)
|
||||
{
|
||||
pp = free_pages;
|
||||
free_pages = free_pages.next;
|
||||
}
|
||||
return cast(void *)pp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* HULK, the HOS Ultra Light Kernel.
|
||||
*/
|
||||
module hulk.hulk;
|
||||
|
||||
import hulk.header;
|
||||
import hulk.fb;
|
||||
import hulk.console;
|
||||
import hos.memory;
|
||||
import ldc.attributes;
|
||||
import hulk.kfont;
|
||||
import hulk.klog;
|
||||
import hulk.hurl;
|
||||
import hulk.hippo;
|
||||
import hulk.pci;
|
||||
|
||||
extern extern(C) __gshared ubyte _hulk_total_size;
|
||||
|
||||
@(ldc.attributes.section(".hulk_header"))
|
||||
private __gshared HulkHeader hulk_header = {
|
||||
&_hulk_total_size, /* total_size */
|
||||
&hulk_start, /* entry */
|
||||
16u * 1024u, /* stack_size */
|
||||
HULK_VIRTUAL_BASE_ADDRESS, /* virt_base */
|
||||
HULK_VIRTUAL_STACK_TOP_ADDRESS, /* virt_stack_top */
|
||||
HULK_VIRTUAL_FRAMEBUFFER_ADDRESS, /* virt_fb_buffer */
|
||||
};
|
||||
|
||||
/**
|
||||
* HULK entry point.
|
||||
*/
|
||||
void hulk_start()
|
||||
{
|
||||
fb.initialize(cast(uint *)HULK_VIRTUAL_FRAMEBUFFER_ADDRESS, hulk_header.bootinfo.fb.width, hulk_header.bootinfo.fb.height, hulk_header.bootinfo.fb.stride);
|
||||
console.initialize();
|
||||
console.clear();
|
||||
klog.initialize();
|
||||
|
||||
klog.writefln("Welcome to HULK, the HOS UltraLight Kernel!");
|
||||
|
||||
hippo.initialize(&hulk_header);
|
||||
pci.initialize();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
SECTIONS
|
||||
{
|
||||
. = 0xFFFF800000000000;
|
||||
_hulk_mem_start = .;
|
||||
|
||||
.hulk_header :
|
||||
{
|
||||
*(.hulk_header)
|
||||
}
|
||||
|
||||
. = ALIGN(4K);
|
||||
_hulk_text_start = .;
|
||||
|
||||
.text :
|
||||
{
|
||||
*(.text)
|
||||
}
|
||||
|
||||
. = ALIGN(4K);
|
||||
_hulk_text_end = .;
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
}
|
||||
|
||||
. = ALIGN(4K);
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
|
||||
. = ALIGN(4K);
|
||||
_hulk_bss_start = .;
|
||||
|
||||
.bss :
|
||||
{
|
||||
*(COMMON)
|
||||
*(.bss)
|
||||
}
|
||||
|
||||
. = ALIGN(4K);
|
||||
_hulk_bss_size = . - _hulk_bss_start;
|
||||
_hulk_mem_end = .;
|
||||
_hulk_total_size = _hulk_mem_end - _hulk_mem_start;
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* HURL, the HOS Unreal Region Locator.
|
||||
*
|
||||
* HURL provides virtual memory management for HULK.
|
||||
*/
|
||||
module hulk.hurl;
|
||||
|
||||
import hos.cpu;
|
||||
import hulk.hippo;
|
||||
import hos.memory;
|
||||
|
||||
/** HULK virtual base address. */
|
||||
enum ulong HULK_VIRTUAL_BASE_ADDRESS = 0xFFFF_8000_0000_0000u;
|
||||
|
||||
/** HULK virtual stack top address. */
|
||||
enum ulong HULK_VIRTUAL_STACK_TOP_ADDRESS = 0xFFFF_A000_0000_0000u;
|
||||
|
||||
/** HULK virtual framebuffer address. */
|
||||
enum ulong HULK_VIRTUAL_FRAMEBUFFER_ADDRESS = 0xFFFF_A000_0000_0000u;
|
||||
|
||||
/** Page table entry attributes. @{ */
|
||||
enum ulong MAP_PRESENT = 0x1u;
|
||||
enum ulong MAP_WRITABLE = 0x2u;
|
||||
enum ulong MAP_USER = 0x4u;
|
||||
enum ulong MAP_WRITE_THROUGH = 0x8u;
|
||||
enum ulong MAP_DISABLE_CACHE = 0x10u;
|
||||
enum ulong MAP_HUGE_PAGE = 0x20u;
|
||||
enum ulong MAP_GLOBAL = 0x40u;
|
||||
enum ulong MAP_NO_EXECUTE = 0x8000_0000_0000_0000u;
|
||||
/** @} */
|
||||
|
||||
struct Hurl
|
||||
{
|
||||
private struct PageTableEntry
|
||||
{
|
||||
private ulong m_entry;
|
||||
|
||||
this(ulong address, ulong flags)
|
||||
{
|
||||
m_entry = address | flags;
|
||||
}
|
||||
|
||||
this(void * address, ulong flags)
|
||||
{
|
||||
m_entry = cast(ulong)address | flags;
|
||||
}
|
||||
|
||||
public @property bool present()
|
||||
{
|
||||
return (m_entry & MAP_PRESENT) != 0u;
|
||||
}
|
||||
|
||||
public PageTable * follow()
|
||||
{
|
||||
return cast(PageTable *)(m_entry & 0x7FFF_FFFF_FFFF_F000u);
|
||||
}
|
||||
}
|
||||
|
||||
private struct PageTable
|
||||
{
|
||||
public PageTableEntry opIndex(ulong address, ulong level)
|
||||
{
|
||||
PageTableEntry * entries = cast(PageTableEntry *)&this;
|
||||
return entries[pt_index(address, level)];
|
||||
}
|
||||
|
||||
public PageTableEntry opIndex(void * address, ulong level)
|
||||
{
|
||||
return opIndex(cast(ulong)address, level);
|
||||
}
|
||||
|
||||
public PageTableEntry opIndexAssign(PageTableEntry pte, ulong address, ulong level)
|
||||
{
|
||||
PageTableEntry * entries = cast(PageTableEntry *)&this;
|
||||
entries[pt_index(address, level)] = pte;
|
||||
return pte;
|
||||
}
|
||||
|
||||
public PageTableEntry opIndexAssign(PageTableEntry pte, void * address, ulong level)
|
||||
{
|
||||
return opIndexAssign(pte, cast(ulong)address, level);
|
||||
}
|
||||
|
||||
private ulong pt_index(ulong address, ulong level)
|
||||
{
|
||||
return (address >> (39u - (9u * level))) & 0x1FFu;
|
||||
}
|
||||
}
|
||||
|
||||
private static __gshared PageTable * m_pt_base;
|
||||
|
||||
public static void initialize()
|
||||
{
|
||||
m_pt_base = cast(PageTable *)read_cr3();
|
||||
}
|
||||
|
||||
public static void map(ulong virtual, ulong physical, ulong flags)
|
||||
{
|
||||
size_t last_level = ((flags & MAP_HUGE_PAGE) != 0u) ? 2u : 3u;
|
||||
PageTable * pt = m_pt_base;
|
||||
for (size_t level = 0; level <= last_level; level++)
|
||||
{
|
||||
if (level < last_level)
|
||||
{
|
||||
PageTableEntry entry = (*pt)[virtual, level];
|
||||
if (entry.present)
|
||||
{
|
||||
pt = entry.follow();
|
||||
}
|
||||
else
|
||||
{
|
||||
PageTable * next_pt = cast(PageTable *)hippo.allocate_page();
|
||||
memset32(next_pt, 0, 4096u / 4u);
|
||||
(*pt)[virtual, level] = PageTableEntry(next_pt, MAP_WRITABLE | MAP_PRESENT);
|
||||
pt = next_pt;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(*pt)[virtual, level] = PageTableEntry(physical, flags | MAP_PRESENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* HULK Kernel Log buffer.
|
||||
*/
|
||||
module hulk.klog;
|
||||
|
||||
import core.stdc.stdarg;
|
||||
import hulk.console;
|
||||
static import hulk.writef;
|
||||
|
||||
struct klog
|
||||
{
|
||||
/**
|
||||
* Kernel buffer size log.
|
||||
* 16 gives a kernel buffer size of 64KB.
|
||||
*/
|
||||
private enum size_t KLOG_SIZE_LOG = 16u;
|
||||
|
||||
/** Kernel buffer size. */
|
||||
private enum size_t KLOG_SIZE = 1u << KLOG_SIZE_LOG;
|
||||
|
||||
/** Kernel log buffer. */
|
||||
private static __gshared align(4096) char[KLOG_SIZE] klog_buffer;
|
||||
|
||||
/** Write index in the kernel log buffer. */
|
||||
private static __gshared size_t klog_index;
|
||||
|
||||
/**
|
||||
* Initialize the klog module.
|
||||
*/
|
||||
public static void initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a formatted string to the kernel log.
|
||||
*
|
||||
* @param s Format string.
|
||||
* @param args Variable arguments structure.
|
||||
*/
|
||||
public static void writef(string s, va_list args)
|
||||
{
|
||||
hulk.writef.writef(s, args, function void(ubyte ch) {
|
||||
console.write(ch);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a formatted string to the kernel log.
|
||||
*
|
||||
* @param s Format string.
|
||||
*/
|
||||
public static extern (C) void writef(string s, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, s);
|
||||
writef(s, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a formatted string and newline to the console.
|
||||
*
|
||||
* @param s Format string.
|
||||
*/
|
||||
public static extern (C) void writefln(string s, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, s);
|
||||
writef(s, args);
|
||||
writef("\n", args);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* This module provides access to linker-defined symbols.
|
||||
*/
|
||||
module hulk.linker_addresses;
|
||||
|
||||
private extern extern(C) __gshared ubyte _hulk_mem_start;
|
||||
private extern extern(C) __gshared ubyte _hulk_bss_start;
|
||||
private extern extern(C) __gshared ubyte _hulk_bss_size;
|
||||
private extern extern(C) __gshared ubyte _hulk_mem_end;
|
||||
private extern extern(C) __gshared ubyte _hulk_total_size;
|
||||
|
||||
/**
|
||||
* This struct provides access to linker-defined symbols.
|
||||
*/
|
||||
public struct LinkerAddresses
|
||||
{
|
||||
public static @property ulong hulk_mem_start()
|
||||
{
|
||||
return cast(ulong)&_hulk_mem_start;
|
||||
}
|
||||
|
||||
public static @property ulong hulk_bss_start()
|
||||
{
|
||||
return cast(ulong)&_hulk_bss_start;
|
||||
}
|
||||
|
||||
public static @property ulong hulk_bss_size()
|
||||
{
|
||||
return cast(ulong)&_hulk_bss_size;
|
||||
}
|
||||
|
||||
public static @property ulong hulk_mem_end()
|
||||
{
|
||||
return cast(ulong)&_hulk_mem_end;
|
||||
}
|
||||
|
||||
public static @property ulong hulk_total_size()
|
||||
{
|
||||
return cast(ulong)&_hulk_total_size;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
module hulk.pci;
|
||||
|
||||
import hos.cpu;
|
||||
import hulk.klog;
|
||||
|
||||
struct pci
|
||||
{
|
||||
/* IO address for PCI configuration address. */
|
||||
enum IO_ADDR_CONFIG_ADDRESS = 0xCF8u;
|
||||
|
||||
/* IO address for PCI configuration data. */
|
||||
enum IO_ADDR_CONFIG_DATA = 0xCFCu;
|
||||
|
||||
private static ulong read_config_register(ulong bus_id, ulong device_id, ulong register_id)
|
||||
{
|
||||
ulong addr = 0x8000_0000u | (bus_id << 16u) | (device_id << 11u) | (register_id << 2u);
|
||||
out32(IO_ADDR_CONFIG_ADDRESS, addr);
|
||||
return in32(IO_ADDR_CONFIG_DATA);
|
||||
}
|
||||
|
||||
private static void scan(ulong bus_id, ulong device_id)
|
||||
{
|
||||
ulong reg0 = read_config_register(bus_id, device_id, 0u);
|
||||
if (reg0 != 0xFFFFFFFFu)
|
||||
{
|
||||
ulong reg2 = read_config_register(bus_id, device_id, 2u);
|
||||
klog.writefln("Found PCI device %04x:%04x (%02x:%02x:%02x) at %02u:%02u",
|
||||
(reg0 & 0xFFFFu), (reg0 >> 16u),
|
||||
(reg2 >> 24u) & 0xFFu,
|
||||
(reg2 >> 16u) & 0xFFu,
|
||||
(reg2 >> 8u) & 0xFFu,
|
||||
bus_id, device_id);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initialize()
|
||||
{
|
||||
klog.writefln("Scanning PCI devices...");
|
||||
for (ulong bus_id = 0u; bus_id < 256u; bus_id++)
|
||||
{
|
||||
for (ulong device_id = 0u; device_id < 32u; device_id++)
|
||||
{
|
||||
scan(bus_id, device_id);
|
||||
}
|
||||
}
|
||||
klog.writefln("PCI scan complete.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* HULK Formatted stream writing support.
|
||||
*/
|
||||
module hulk.writef;
|
||||
|
||||
import core.stdc.stdarg;
|
||||
|
||||
alias ch_out_fn = void function(ubyte);
|
||||
|
||||
/**
|
||||
* Format a string and write characters to the given output function.
|
||||
*
|
||||
* @param s Format string.
|
||||
* @param args Variable arguments structure.
|
||||
* @param ch_out Character output function.
|
||||
*
|
||||
* @return Number of characters written.
|
||||
*/
|
||||
size_t writef(string s, va_list args, ch_out_fn ch_out)
|
||||
{
|
||||
size_t length_written;
|
||||
bool escape = false;
|
||||
char pad = ' ';
|
||||
size_t width;
|
||||
foreach (char c; s)
|
||||
{
|
||||
if (escape)
|
||||
{
|
||||
if (c == 'x')
|
||||
{
|
||||
ulong v;
|
||||
va_arg(args, v);
|
||||
length_written += write_hex(v, false, pad, width, ch_out);
|
||||
escape = false;
|
||||
}
|
||||
else if (c == 'X')
|
||||
{
|
||||
ulong v;
|
||||
va_arg(args, v);
|
||||
length_written += write_hex(v, true, pad, width, ch_out);
|
||||
escape = false;
|
||||
}
|
||||
else if (c == 'u')
|
||||
{
|
||||
ulong v;
|
||||
va_arg(args, v);
|
||||
length_written += write_udec(v, pad, width, ch_out);
|
||||
escape = false;
|
||||
}
|
||||
else if ((c == '0') && (width == 0u))
|
||||
{
|
||||
pad = '0';
|
||||
}
|
||||
else if (('0' <= c) && (c <= '9'))
|
||||
{
|
||||
width = (width * 10u) + (c - '0');
|
||||
}
|
||||
else
|
||||
{
|
||||
ch_out(c);
|
||||
escape = false;
|
||||
}
|
||||
}
|
||||
else if (c == '%')
|
||||
{
|
||||
escape = true;
|
||||
pad = ' ';
|
||||
width = 0u;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch_out(c);
|
||||
}
|
||||
}
|
||||
return length_written;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a value in hexadecimal to the given output function.
|
||||
*
|
||||
* @param v Value to format.
|
||||
* @param upper Whether to use uppercase letters.
|
||||
* @param pad Pad character to use.
|
||||
* @param width Field width.
|
||||
* @param ch_out Character output function.
|
||||
*
|
||||
* @return Number of characters written.
|
||||
*/
|
||||
private size_t write_hex(ulong v, bool upper, char pad, size_t width, ch_out_fn ch_out)
|
||||
{
|
||||
string hex_chars_lower = "0123456789abcdef";
|
||||
string hex_chars_upper = "0123456789ABCDEF";
|
||||
char[16] buf;
|
||||
size_t i;
|
||||
do
|
||||
{
|
||||
ulong n = v & 0xFu;
|
||||
buf[i] = upper ? hex_chars_upper[n] : hex_chars_lower[n];
|
||||
v >>= 4u;
|
||||
i++;
|
||||
} while (v != 0u);
|
||||
size_t length_written = i;
|
||||
while (width > i)
|
||||
{
|
||||
ch_out(pad);
|
||||
width--;
|
||||
length_written++;
|
||||
}
|
||||
do
|
||||
{
|
||||
i--;
|
||||
ch_out(buf[i]);
|
||||
} while (i != 0u);
|
||||
return length_written;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a value in decimal to the given output function.
|
||||
*
|
||||
* @param v Value to format.
|
||||
* @param pad Pad character to use.
|
||||
* @param width Field width.
|
||||
* @param ch_out Character output function.
|
||||
*
|
||||
* @return Number of characters written.
|
||||
*/
|
||||
private size_t write_udec(ulong v, char pad, size_t width, ch_out_fn ch_out)
|
||||
{
|
||||
char[20] buf;
|
||||
size_t i;
|
||||
do
|
||||
{
|
||||
ulong d = v % 10u;
|
||||
buf[i] = cast(char)(d + '0');
|
||||
v /= 10u;
|
||||
i++;
|
||||
} while (v != 0u);
|
||||
size_t length_written = i;
|
||||
while (width > i)
|
||||
{
|
||||
ch_out(pad);
|
||||
width--;
|
||||
length_written++;
|
||||
}
|
||||
do
|
||||
{
|
||||
i--;
|
||||
ch_out(buf[i]);
|
||||
} while (i != 0u);
|
||||
return length_written;
|
||||
}
|
||||
-103
@@ -1,103 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include "klog.h"
|
||||
#include "kfont.h"
|
||||
#include "fb.h"
|
||||
#include "fb_text.h"
|
||||
#include "stream.h"
|
||||
#include "hos_printf.h"
|
||||
#include "mem.h"
|
||||
|
||||
static struct {
|
||||
size_t console_width;
|
||||
size_t console_height;
|
||||
size_t x;
|
||||
size_t y;
|
||||
bool need_shift;
|
||||
} klog;
|
||||
|
||||
static void shift_line(void)
|
||||
{
|
||||
uint32_t * fb = fb_addr();
|
||||
uint32_t w = fb_width();
|
||||
size_t console_fb_line_words = w * kfont.line_height;
|
||||
for (size_t row = 0u; row < klog.console_height; row++)
|
||||
{
|
||||
memcpy32(fb, fb + console_fb_line_words, console_fb_line_words);
|
||||
fb += console_fb_line_words;
|
||||
}
|
||||
fb_fill(0, kfont.line_height * (klog.console_height - 1u), w, kfont.line_height, 0u, 0x2Cu, 0x55u);
|
||||
}
|
||||
|
||||
static void klog_fb_write1(char c)
|
||||
{
|
||||
if (klog.need_shift)
|
||||
{
|
||||
shift_line();
|
||||
klog.need_shift = false;
|
||||
}
|
||||
if (c == '\n')
|
||||
{
|
||||
if (klog.y == (klog.console_height - 1u))
|
||||
{
|
||||
klog.need_shift = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
klog.y++;
|
||||
}
|
||||
klog.x = 0u;
|
||||
}
|
||||
else
|
||||
{
|
||||
int px = klog.x * kfont.advance;
|
||||
int py = klog.y * kfont.line_height;
|
||||
fb_text_render_char(c, px, py, 0xFFu, 0x80u, 0u);
|
||||
klog.x++;
|
||||
if (klog.x == klog.console_width)
|
||||
{
|
||||
if (klog.y == (klog.console_height - 1u))
|
||||
{
|
||||
klog.need_shift = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
klog.y++;
|
||||
}
|
||||
klog.x = 0u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void klog_fb_write(const char * src, size_t length)
|
||||
{
|
||||
for (size_t i = 0u; i < length; i++)
|
||||
{
|
||||
klog_fb_write1(src[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static const stream_t klog_fb_stream = {
|
||||
klog_fb_write,
|
||||
klog_fb_write1,
|
||||
};
|
||||
|
||||
void klog_init(void)
|
||||
{
|
||||
klog.console_width = fb_width() / kfont.advance;
|
||||
klog.console_height = fb_height() / kfont.line_height;
|
||||
klog.x = 0u;
|
||||
klog.y = 0u;
|
||||
klog.need_shift = false;
|
||||
fb_fill(0, 0, fb_width(), fb_height(), 0u, 0x2Cu, 0x55u);
|
||||
}
|
||||
|
||||
void klog_printf(const char * fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
hos_vprintf(&klog_fb_stream, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
#ifndef KLOG_H
|
||||
#define KLOG_H
|
||||
|
||||
void klog_init(void);
|
||||
void klog_printf(const char * fmt, ...);
|
||||
|
||||
#endif
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
ENTRY(hos_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 1M;
|
||||
_hos_mem_start = .;
|
||||
|
||||
.text BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.multiboot)
|
||||
*(.text)
|
||||
}
|
||||
|
||||
.rodata BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.rodata)
|
||||
}
|
||||
|
||||
.data BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
|
||||
_stack_size = 16K;
|
||||
.stack (NOLOAD) : ALIGN(4K)
|
||||
{
|
||||
_stack_start = .;
|
||||
. = . + _stack_size;
|
||||
_stack_end = .;
|
||||
}
|
||||
|
||||
.bss BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(COMMON)
|
||||
*(.bss)
|
||||
}
|
||||
|
||||
. = ALIGN(4K);
|
||||
|
||||
_hos_mem_end = .;
|
||||
}
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
#include "multiboot2.h"
|
||||
#include "fb.h"
|
||||
#include "mem.h"
|
||||
#include <stdint.h>
|
||||
#include "klog.h"
|
||||
#include "mm.h"
|
||||
|
||||
static uint32_t mbinfo[2048];
|
||||
|
||||
static void mbinfo_process_tag(const multiboot2_info_tag_t * tag)
|
||||
{
|
||||
switch (tag->type)
|
||||
{
|
||||
case MULTIBOOT2_INFO_BOOT_COMMAND_LINE:
|
||||
{
|
||||
multiboot2_info_boot_command_line_t * cl =
|
||||
(multiboot2_info_boot_command_line_t *)tag;
|
||||
klog_printf("Kernel boot command line: '%s'\n", cl->string);
|
||||
}
|
||||
break;
|
||||
|
||||
case MULTIBOOT2_INFO_BOOT_LOADER_NAME:
|
||||
{
|
||||
multiboot2_info_boot_loader_name_t * bln =
|
||||
(multiboot2_info_boot_loader_name_t *)tag;
|
||||
klog_printf("Boot loader: '%s'\n", bln->string);
|
||||
}
|
||||
break;
|
||||
|
||||
case MULTIBOOT2_INFO_MEMORY_MAP:
|
||||
{
|
||||
multiboot2_info_memory_map_t * mmap_info =
|
||||
(multiboot2_info_memory_map_t *)tag;
|
||||
size_t sz = sizeof(mmap_info->header) +
|
||||
sizeof(mmap_info->entry_size) +
|
||||
sizeof(mmap_info->entry_version);
|
||||
multiboot2_info_memory_map_entry_t * entry = &mmap_info->entries[0];
|
||||
for (;;)
|
||||
{
|
||||
sz += mmap_info->entry_size;
|
||||
if (sz > mmap_info->header.size)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (entry->type == MULTIBOOT2_MEMORY_MAP_TYPE_RAM)
|
||||
{
|
||||
klog_printf("Memory region %16lx : %16lx\n",
|
||||
entry->base_addr,
|
||||
entry->length);
|
||||
mm_register_ram_region(entry->base_addr, entry->length);
|
||||
}
|
||||
entry = (multiboot2_info_memory_map_entry_t *)((uintptr_t)entry + mmap_info->entry_size);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MULTIBOOT2_INFO_FRAMEBUFFER_INFO:
|
||||
{
|
||||
multiboot2_info_framebuffer_info_t * fbinfo =
|
||||
(multiboot2_info_framebuffer_info_t *)tag;
|
||||
fb_init((uint32_t *)(uintptr_t)fbinfo->framebuffer_addr,
|
||||
fbinfo->framebuffer_width,
|
||||
fbinfo->framebuffer_height,
|
||||
fbinfo->framebuffer_pitch);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void process_tags(const multiboot2_info_tag_t * tag, bool init)
|
||||
{
|
||||
while (tag->type != 0u)
|
||||
{
|
||||
if ((init && (tag->type == MULTIBOOT2_INFO_FRAMEBUFFER_INFO)) ||
|
||||
(!init && (tag->type != MULTIBOOT2_INFO_FRAMEBUFFER_INFO)))
|
||||
{
|
||||
mbinfo_process_tag(tag);
|
||||
}
|
||||
tag = multiboot2_info_next_tag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
bool mbinfo_init(uint32_t mbinfo_addr)
|
||||
{
|
||||
multiboot2_info_header_t * mbinfo_header = (multiboot2_info_header_t *)mbinfo_addr;
|
||||
if (mbinfo_header->total_size <= sizeof(mbinfo))
|
||||
{
|
||||
memcpy32(mbinfo, mbinfo_header, mbinfo_header->total_size / 4u);
|
||||
multiboot2_info_tag_t * tag = (multiboot2_info_tag_t *)(mbinfo + sizeof(multiboot2_info_header_t) / 4u);
|
||||
process_tags(tag, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void mbinfo_load(void)
|
||||
{
|
||||
multiboot2_info_tag_t * tag = (multiboot2_info_tag_t *)(mbinfo + sizeof(multiboot2_info_header_t) / 4u);
|
||||
process_tags(tag, false);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef MBINFO_H
|
||||
#define MBINFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool mbinfo_init(uint32_t mbinfo_addr);
|
||||
void mbinfo_load(void);
|
||||
|
||||
#endif
|
||||
@@ -1,49 +0,0 @@
|
||||
#ifndef MEM_H
|
||||
#define MEM_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
static inline void memcpy(void * dest, const void * src, size_t n)
|
||||
{
|
||||
uint32_t r0, r1, r2;
|
||||
__asm__ __volatile__ (
|
||||
"cld\n\t"
|
||||
"rep movsb"
|
||||
: "=&c" (r0), "=&S" (r1), "=&D" (r2)
|
||||
: "2" (dest), "1" (src), "0" (n)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline void memcpy32(void * dest, const void * src, size_t count)
|
||||
{
|
||||
uint32_t r0, r1, r2;
|
||||
__asm__ __volatile__ (
|
||||
"cld\n\t"
|
||||
"rep movsd"
|
||||
: "=&c" (r0), "=&S" (r1), "=&D" (r2)
|
||||
: "2" (dest), "1" (src), "0" (count)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline void * memmove(void * dest, const void * src, size_t count)
|
||||
{
|
||||
return __builtin_memmove(dest, src, count);
|
||||
}
|
||||
|
||||
static inline void * memset(void * dest, int val, size_t count)
|
||||
{
|
||||
return __builtin_memset(dest, val, count);
|
||||
}
|
||||
|
||||
static inline void memset32(void * dest, uint32_t val, size_t count)
|
||||
{
|
||||
uint32_t r0, r1;
|
||||
__asm__ __volatile__ (
|
||||
"cld\n\t"
|
||||
"rep stosl"
|
||||
: "=&c" (r0), "=&D" (r1)
|
||||
: "a" (val), "1" (dest), "0" (count)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,91 +0,0 @@
|
||||
#include "mm.h"
|
||||
|
||||
typedef struct mm_page_entry_s {
|
||||
size_t count;
|
||||
struct mm_page_entry_s * next;
|
||||
} mm_region_entry_t;
|
||||
|
||||
static mm_region_entry_t * mm_next_free_region;
|
||||
static size_t mm_free_pages;
|
||||
static size_t mm_total_ram;
|
||||
static size_t kernel_start_address;
|
||||
static size_t kernel_size;
|
||||
|
||||
extern uint8_t _hos_mem_start;
|
||||
extern uint8_t _hos_mem_end;
|
||||
|
||||
static void mm_add_ram_region(size_t base, size_t size)
|
||||
{
|
||||
mm_region_entry_t * region = (mm_region_entry_t *)base;
|
||||
size_t pages = size / PAGE_SIZE;
|
||||
region->count = pages;
|
||||
region->next = mm_next_free_region;
|
||||
mm_next_free_region = region;
|
||||
mm_total_ram += size;
|
||||
mm_free_pages = pages;
|
||||
}
|
||||
|
||||
void mm_register_ram_region(uint64_t base, size_t size)
|
||||
{
|
||||
/* Ignore any RAM region above 4GB. */
|
||||
if (base >= 0x100000000ull)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((base + size) > 0x100000000ull)
|
||||
{
|
||||
size = (size_t)(0x100000000ull - base);
|
||||
}
|
||||
size_t end_address = mm_page_floor((size_t)base + size);
|
||||
size_t start_address = mm_page_ceil(base);
|
||||
size = end_address - start_address;
|
||||
if (size < PAGE_SIZE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
size_t kernel_end_address = kernel_start_address + kernel_size;
|
||||
/* Add regions before and after kernel RAM. */
|
||||
if (start_address < kernel_start_address)
|
||||
{
|
||||
/* RAM region begins before kernel RAM. */
|
||||
size_t this_sz = size;
|
||||
if ((start_address + this_sz) > kernel_start_address)
|
||||
{
|
||||
this_sz = kernel_start_address - start_address;
|
||||
}
|
||||
mm_add_ram_region(start_address, this_sz);
|
||||
}
|
||||
if ((start_address + size) > kernel_end_address)
|
||||
{
|
||||
/* RAM region ends after kernel RAM. */
|
||||
size_t this_sz = size;
|
||||
if (start_address < kernel_end_address)
|
||||
{
|
||||
this_sz = (start_address + size) - kernel_end_address;
|
||||
start_address = kernel_end_address;
|
||||
}
|
||||
mm_add_ram_region(start_address, this_sz);
|
||||
}
|
||||
}
|
||||
|
||||
void mm_init(void)
|
||||
{
|
||||
kernel_start_address = mm_page_floor((size_t)&_hos_mem_start);
|
||||
kernel_size = mm_page_ceil((size_t)&_hos_mem_end - kernel_start_address);
|
||||
mm_total_ram = kernel_size;
|
||||
}
|
||||
|
||||
size_t mm_get_total_ram(void)
|
||||
{
|
||||
return mm_total_ram;
|
||||
}
|
||||
|
||||
size_t mm_get_kernel_address(void)
|
||||
{
|
||||
return kernel_start_address;
|
||||
}
|
||||
|
||||
size_t mm_get_kernel_size(void)
|
||||
{
|
||||
return kernel_size;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef MM_H
|
||||
#define MM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define PAGE_SIZE 4096u
|
||||
|
||||
static inline size_t mm_page_floor(size_t bytes)
|
||||
{
|
||||
return bytes & ~(PAGE_SIZE - 1u);
|
||||
}
|
||||
|
||||
static inline size_t mm_page_ceil(size_t bytes)
|
||||
{
|
||||
return (bytes + PAGE_SIZE - 1u) & ~(PAGE_SIZE - 1u);
|
||||
}
|
||||
|
||||
void mm_init(void);
|
||||
void mm_register_ram_region(uint64_t base, size_t size);
|
||||
size_t mm_get_total_ram(void);
|
||||
size_t mm_get_kernel_address(void);
|
||||
size_t mm_get_kernel_size(void);
|
||||
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
#ifndef MULTIBOOT2_H
|
||||
#define MULTIBOOT2_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MULTIBOOT2_MAGIC 0xE85250D6u
|
||||
#define MULTIBOOT2_ARCHITECTURE_I386 0u
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t architecture;
|
||||
uint32_t header_length;
|
||||
uint32_t checksum;
|
||||
} multiboot2_header_t;
|
||||
#define multiboot2_header(magic, architecture, header_length) \
|
||||
{(magic), (architecture), (header_length), (uint32_t)(0x100000000u - (magic) - (architecture) - (header_length))}
|
||||
#define multiboot2_header_default() \
|
||||
multiboot2_header(MULTIBOOT2_MAGIC, MULTIBOOT2_ARCHITECTURE_I386, sizeof(multiboot2_header_t))
|
||||
|
||||
typedef struct {
|
||||
uint16_t type;
|
||||
uint16_t flags;
|
||||
uint32_t size;
|
||||
} multiboot2_tag_t;
|
||||
#define multiboot2_end_tag() {0u, 0u, 8u}
|
||||
|
||||
typedef struct {
|
||||
multiboot2_tag_t header;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t depth;
|
||||
uint32_t _padding;
|
||||
} multiboot2_framebuffer_tag_t;
|
||||
#define multiboot2_framebuffer_tag(width, height, depth) \
|
||||
{{5u, 0u, 20u}, width, height, depth}
|
||||
|
||||
#define MULTIBOOT2_INFO_TAG_ALIGNMENT 8u
|
||||
#define MULTIBOOT2_INFO_BOOT_COMMAND_LINE 1u
|
||||
#define MULTIBOOT2_INFO_BOOT_LOADER_NAME 2u
|
||||
#define MULTIBOOT2_INFO_MODULES 3u
|
||||
#define MULTIBOOT2_INFO_BASIC_MEMORY_INFO 4u
|
||||
#define MULTIBOOT2_INFO_BIOS_BOOT_DEVICE 5u
|
||||
#define MULTIBOOT2_INFO_MEMORY_MAP 6u
|
||||
#define MULTIBOOT2_INFO_VBE_INFO 7u
|
||||
#define MULTIBOOT2_INFO_FRAMEBUFFER_INFO 8u
|
||||
#define MULTIBOOT2_INFO_ELF_SYMBOLS 9u
|
||||
#define MULTIBOOT2_INFO_APM_TABLE 10u
|
||||
#define MULTIBOOT2_INFO_EFI_32BIT_SYSTEM_TABLE_POINTER 11u
|
||||
#define MULTIBOOT2_INFO_EFI_64BIT_SYSTEM_TABLE_POINTER 12u
|
||||
#define MULTIBOOT2_INFO_SMBIOS_TABLES 13u
|
||||
#define MULTIBOOT2_INFO_ACPI_OLD_RSDP 14u
|
||||
#define MULTIBOOT2_INFO_NETWORKING_INFO 16u
|
||||
#define MULTIBOOT2_INFO_EFI_MEMORY_MAP 17u
|
||||
#define MULTIBOOT2_INFO_EFI_BOOT_SERVICES_NOT_TERMINATED 18u
|
||||
#define MULTIBOOT2_INFO_EFI_32BIT_IMAGE_HANDLE_POINTER 19u
|
||||
#define MULTIBOOT2_INFO_EFI_64BIT_IMAGE_HANDLE_POINTER 20u
|
||||
#define MULTIBOOT2_INFO_IMAGE_LOAD_BASE_PHYSICAL_ADDRESS 21u
|
||||
|
||||
typedef struct {
|
||||
uint32_t total_size;
|
||||
uint32_t _reserved;
|
||||
} multiboot2_info_header_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t type;
|
||||
uint32_t size;
|
||||
} multiboot2_info_tag_t;
|
||||
#define multiboot2_info_next_tag(current_tag) \
|
||||
(multiboot2_info_tag_t *)(((uintptr_t)current_tag + current_tag->size + MULTIBOOT2_INFO_TAG_ALIGNMENT - 1u) & ~(MULTIBOOT2_INFO_TAG_ALIGNMENT - 1u))
|
||||
|
||||
typedef struct {
|
||||
multiboot2_info_tag_t header;
|
||||
char string[];
|
||||
} multiboot2_info_boot_command_line_t;
|
||||
|
||||
typedef struct {
|
||||
multiboot2_info_tag_t header;
|
||||
char string[];
|
||||
} multiboot2_info_boot_loader_name_t;
|
||||
|
||||
typedef struct {
|
||||
multiboot2_info_tag_t header;
|
||||
uint32_t mem_lower;
|
||||
uint32_t mem_upper;
|
||||
} multiboot2_info_basic_memory_info_t;
|
||||
|
||||
#define MULTIBOOT2_MEMORY_MAP_TYPE_RAM 1u
|
||||
#define MULTIBOOT2_MEMORY_MAP_TYPE_ACPI 3u
|
||||
#define MULTIBOOT2_MEMORY_MAP_TYPE_PRESERVE 4u
|
||||
#define MULTIBOOT2_MEMORY_MAP_TYPE_DEFECTIVE 5u
|
||||
|
||||
typedef struct {
|
||||
uint64_t base_addr;
|
||||
uint64_t length;
|
||||
uint32_t type;
|
||||
uint32_t _reserved;
|
||||
} multiboot2_info_memory_map_entry_t;
|
||||
|
||||
typedef struct {
|
||||
multiboot2_info_tag_t header;
|
||||
uint32_t entry_size;
|
||||
uint32_t entry_version;
|
||||
multiboot2_info_memory_map_entry_t entries[];
|
||||
} multiboot2_info_memory_map_t;
|
||||
|
||||
typedef struct {
|
||||
multiboot2_info_tag_t header;
|
||||
uint16_t vbe_mode;
|
||||
uint16_t vbe_interface_set;
|
||||
uint16_t vbe_interface_off;
|
||||
uint16_t vbe_interface_len;
|
||||
uint8_t vbe_control_info[512];
|
||||
uint8_t vbe_mode_info[256];
|
||||
} multiboot2_info_vbe_info_t;
|
||||
|
||||
typedef struct {
|
||||
multiboot2_info_tag_t header;
|
||||
uint64_t framebuffer_addr;
|
||||
uint32_t framebuffer_pitch;
|
||||
uint32_t framebuffer_width;
|
||||
uint32_t framebuffer_height;
|
||||
uint8_t framebuffer_bpp;
|
||||
uint8_t framebuffer_type;
|
||||
uint8_t _reserved;
|
||||
} multiboot2_info_framebuffer_info_t;
|
||||
|
||||
#endif
|
||||
@@ -1,12 +0,0 @@
|
||||
#include "multiboot2.h"
|
||||
|
||||
/* Multiboot2 Header. */
|
||||
struct {
|
||||
multiboot2_header_t header;
|
||||
multiboot2_framebuffer_tag_t framebuffer_tag;
|
||||
multiboot2_tag_t end_tag;
|
||||
} multiboot_header __attribute__((section(".multiboot"))) = {
|
||||
multiboot2_header_default(),
|
||||
multiboot2_framebuffer_tag(1600u, 900u, 32u),
|
||||
multiboot2_end_tag(),
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef STREAM_H
|
||||
#define STREAM_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
void (*write)(const char * src, size_t length);
|
||||
void (*write1)(char c);
|
||||
} stream_t;
|
||||
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
static inline size_t strlen(const char * s)
|
||||
{
|
||||
size_t r = 0u;
|
||||
while (*s++ != (char)0)
|
||||
{
|
||||
r++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline char * strcpy(char * dest, const char * src)
|
||||
{
|
||||
return __builtin_strcpy(dest, src);
|
||||
}
|
||||
|
||||
static inline char * strncpy(char * dest, const char * src, size_t n)
|
||||
{
|
||||
return __builtin_strncpy(dest, src, n);
|
||||
}
|
||||
|
||||
#endif
|
||||
Submodule
+1
Submodule uefi-d added at e70959ce8a.
@@ -1,9 +1,10 @@
|
||||
project_name "x86_64-elf-gcc"
|
||||
binutils_version = "2.35"
|
||||
binutils_checksum = "1b11659fb49e20e18db460d44485f09442c8c56d5df165de9461eb09c8302f85"
|
||||
gcc_version = "10.2.0"
|
||||
gcc_checksum = "b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c"
|
||||
install_path = File.expand_path("i686-elf-gcc")
|
||||
target = "i686-elf"
|
||||
install_path = File.expand_path("x86_64-elf-gcc")
|
||||
target = "x86_64-elf"
|
||||
path_prepend "#{install_path}/bin"
|
||||
|
||||
configure do
|
||||
@@ -53,7 +54,7 @@ default do
|
||||
cd "#{build_dir}/build-gcc" do
|
||||
sh %W[../gcc-#{gcc_version}/configure
|
||||
--target=#{target} --prefix=#{install_path} --disable-nls
|
||||
--enable-languages=c,c++ --without-headers]
|
||||
--enable-languages=c --without-headers]
|
||||
sh "make all-gcc"
|
||||
sh "make all-target-libgcc"
|
||||
sh "make install-gcc"
|
||||
Reference in new issue
Block a user