Compare commits
9
Commits
fdc5584110
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
997d07b64b | ||
|
|
a175c46f25 | ||
|
|
d02f1a9efc | ||
|
|
edd7979b3f | ||
|
|
eb15f473c6 | ||
|
|
df426afbc8 | ||
|
|
fc2efa2474 | ||
|
|
6b10f3f4d9 | ||
|
|
bb24fb937a |
No files matched your search
@@ -1,7 +0,0 @@
|
|||||||
.PHONY: all
|
|
||||||
all:
|
|
||||||
@./rscons
|
|
||||||
|
|
||||||
.PHONY: run
|
|
||||||
run: all
|
|
||||||
qemu-system-x86_64 -bios OVMF.fd -hdb build/e.1/efi-loader.img
|
|
||||||
+14
-3
@@ -1,13 +1,14 @@
|
|||||||
configure do
|
configure do
|
||||||
check_program "mformat"
|
check_program "mformat"
|
||||||
check_program "x86_64-w64-mingw32-gcc"
|
check_program "x86_64-w64-mingw32-gcc"
|
||||||
|
check_cfg package: "gnu-efi", use: false
|
||||||
end
|
end
|
||||||
|
|
||||||
class Image < Builder
|
class Image < Builder
|
||||||
def run(options)
|
def run(options)
|
||||||
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
||||||
print_run_message("Image <target>#{@target}<reset>", nil)
|
print_run_message("Image <target>#{@target}<reset>", nil)
|
||||||
system(*%W[dd if=/dev/zero of=#{@target} bs=1k count=1440])
|
File.binwrite(@target, "\0" * (1440 * 1024))
|
||||||
system(*%W[mformat -i #{@target} -f 1440 ::])
|
system(*%W[mformat -i #{@target} -f 1440 ::])
|
||||||
system(*%W[mmd -i #{@target} ::/EFI])
|
system(*%W[mmd -i #{@target} ::/EFI])
|
||||||
system(*%W[mmd -i #{@target} ::/EFI/BOOT])
|
system(*%W[mmd -i #{@target} ::/EFI/BOOT])
|
||||||
@@ -18,14 +19,24 @@ class Image < Builder
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
env do |env|
|
uefi_env = env "uefi" do |env|
|
||||||
env.add_builder(Image)
|
env.add_builder(Image)
|
||||||
env["CC"] = "x86_64-w64-mingw32-gcc"
|
env["CC"] = "x86_64-w64-mingw32-gcc"
|
||||||
env["CPPPATH"] += %w[/usr/include/efi /usr/include/efi/x86_64]
|
env["CPPPATH"] += %w[/usr/include/efi /usr/include/efi/x86_64]
|
||||||
env["CFLAGS"] += %w[-ffreestanding]
|
env["CFLAGS"] += %w[-ffreestanding]
|
||||||
env["LDFLAGS"] += %w[-nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main]
|
env["LDFLAGS"] += %w[-nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main]
|
||||||
env["LIBS"] += %w[gcc]
|
env["LIBS"] += %w[gcc]
|
||||||
env["sources"] = glob("*.c")
|
env["sources"] = glob("src/**/*.c")
|
||||||
env.Program("^/BOOTX64.EFI", "${sources}")
|
env.Program("^/BOOTX64.EFI", "${sources}")
|
||||||
env.Image("^/efi-loader.img", "^/BOOTX64.EFI")
|
env.Image("^/efi-loader.img", "^/BOOTX64.EFI")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
task "run" do
|
||||||
|
ovmf = "OVMF.fd"
|
||||||
|
if File.exist?("/usr/share/edk2/x64/OVMF.fd")
|
||||||
|
ovmf = "/usr/share/edk2/x64/OVMF.fd"
|
||||||
|
elsif File.exist?("/usr/share/edk2/x64/OVMF.4m.fd")
|
||||||
|
ovmf = "/usr/share/edk2/x64/OVMF.4m.fd"
|
||||||
|
end
|
||||||
|
sh %W[qemu-system-x86_64 -bios #{ovmf} -drive file=#{uefi_env.expand("^/efi-loader.img")},format=raw]
|
||||||
|
end
|
||||||
+41
-6
@@ -38,8 +38,19 @@ static void write_hex64(size_t n)
|
|||||||
write_string(s);
|
write_string(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void wait_key(void)
|
||||||
|
{
|
||||||
|
EFI_INPUT_KEY key;
|
||||||
|
write_string(L"Press any key...\r\n");
|
||||||
|
while (g_system_table->ConIn->ReadKeyStroke(g_system_table->ConIn, &key) == EFI_NOT_READY)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void check_gop_handle(EFI_HANDLE handle)
|
static void check_gop_handle(EFI_HANDLE handle)
|
||||||
{
|
{
|
||||||
|
write_string(L"Going to check GOP handle...\r\n");
|
||||||
|
wait_key();
|
||||||
EFI_HANDLE interface = NULL;
|
EFI_HANDLE interface = NULL;
|
||||||
EFI_STATUS status = g_system_table->BootServices->HandleProtocol(handle,
|
EFI_STATUS status = g_system_table->BootServices->HandleProtocol(handle,
|
||||||
&(EFI_GUID)EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID,
|
&(EFI_GUID)EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID,
|
||||||
@@ -63,6 +74,32 @@ static void check_gop_handle(EFI_HANDLE handle)
|
|||||||
write_string(L"\r\n");
|
write_string(L"\r\n");
|
||||||
|
|
||||||
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop = (EFI_GRAPHICS_OUTPUT_PROTOCOL *)interface;
|
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop = (EFI_GRAPHICS_OUTPUT_PROTOCOL *)interface;
|
||||||
|
UINTN info_size;
|
||||||
|
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * info;
|
||||||
|
for (uint32_t mode_number = 0u;
|
||||||
|
(status = gop->QueryMode(gop, mode_number, &info_size, &info)) == EFI_SUCCESS;
|
||||||
|
mode_number++)
|
||||||
|
{
|
||||||
|
write_string(L"Mode ");
|
||||||
|
write_uint(mode_number);
|
||||||
|
write_string(L": ");
|
||||||
|
write_uint(info->HorizontalResolution);
|
||||||
|
write_string(L"x");
|
||||||
|
write_uint(info->VerticalResolution);
|
||||||
|
write_string(L" f=");
|
||||||
|
write_uint(info->PixelFormat);
|
||||||
|
write_string(L" s=");
|
||||||
|
write_uint(info->PixelsPerScanLine);
|
||||||
|
write_string(L"\r\n");
|
||||||
|
g_system_table->BootServices->FreePool(info);
|
||||||
|
if ((mode_number % 20) == 19)
|
||||||
|
{
|
||||||
|
wait_key();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
write_string(L"Error ");
|
||||||
|
write_uint(status);
|
||||||
|
write_string(L" from QueryMode\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dump_memory_map(void)
|
static void dump_memory_map(void)
|
||||||
@@ -73,7 +110,7 @@ static void dump_memory_map(void)
|
|||||||
UINTN descriptor_size;
|
UINTN descriptor_size;
|
||||||
UINT32 descriptor_version;
|
UINT32 descriptor_version;
|
||||||
EFI_STATUS status = g_system_table->BootServices->GetMemoryMap(&memory_map_size,
|
EFI_STATUS status = g_system_table->BootServices->GetMemoryMap(&memory_map_size,
|
||||||
memory_map_buffer,
|
(EFI_MEMORY_DESCRIPTOR *)memory_map_buffer,
|
||||||
&map_key,
|
&map_key,
|
||||||
&descriptor_size,
|
&descriptor_size,
|
||||||
&descriptor_version);
|
&descriptor_version);
|
||||||
@@ -114,10 +151,11 @@ EFI_STATUS
|
|||||||
efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table)
|
efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table)
|
||||||
{
|
{
|
||||||
EFI_STATUS status;
|
EFI_STATUS status;
|
||||||
EFI_INPUT_KEY key;
|
|
||||||
|
|
||||||
g_system_table = system_table;
|
g_system_table = system_table;
|
||||||
|
|
||||||
|
system_table->ConOut->ClearScreen(system_table->ConOut);
|
||||||
|
|
||||||
write_string(L"My first EFI loader\r\n");
|
write_string(L"My first EFI loader\r\n");
|
||||||
|
|
||||||
status = system_table->ConIn->Reset(system_table->ConIn, FALSE);
|
status = system_table->ConIn->Reset(system_table->ConIn, FALSE);
|
||||||
@@ -149,10 +187,7 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table)
|
|||||||
check_gop_handle(buffer[i]);
|
check_gop_handle(buffer[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
write_string(L"Press any key...\r\n");
|
wait_key();
|
||||||
while ((status = system_table->ConIn->ReadKeyStroke(system_table->ConIn, &key)) == EFI_NOT_READY)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user