Add file functionality in fs.cpp
This commit is contained in:
@@ -58,6 +58,7 @@ modules:
|
|||||||
- src/boot/main.cpp
|
- src/boot/main.cpp
|
||||||
- src/boot/console.cpp
|
- src/boot/console.cpp
|
||||||
- src/boot/error.cpp
|
- src/boot/error.cpp
|
||||||
|
- src/boot/fs.cpp
|
||||||
- src/boot/hardware.cpp
|
- src/boot/hardware.cpp
|
||||||
- src/boot/memory.cpp
|
- src/boot/memory.cpp
|
||||||
|
|
||||||
|
|||||||
65
src/boot/fs.cpp
Normal file
65
src/boot/fs.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include <uefi/types.h>
|
||||||
|
#include <uefi/protos/loaded_image.h>
|
||||||
|
#include <uefi/protos/simple_file_system.h>
|
||||||
|
|
||||||
|
#include "fs.h"
|
||||||
|
#include "console.h"
|
||||||
|
#include "error.h"
|
||||||
|
|
||||||
|
namespace boot {
|
||||||
|
namespace fs {
|
||||||
|
|
||||||
|
file::file(uefi::protos::file *f) :
|
||||||
|
m_file(f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
file::file(file &&o) :
|
||||||
|
m_file(o.m_file)
|
||||||
|
{
|
||||||
|
o.m_file = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
file
|
||||||
|
file::open(const wchar_t *path)
|
||||||
|
{
|
||||||
|
uefi::protos::file *fh = nullptr;
|
||||||
|
|
||||||
|
try_or_raise(
|
||||||
|
m_file->open(&fh, path, uefi::file_mode::read, uefi::file_attr::none),
|
||||||
|
L"Could not open relative path to file");
|
||||||
|
|
||||||
|
return file(fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
file
|
||||||
|
get_boot_volume(uefi::handle image, uefi::boot_services *bs)
|
||||||
|
{
|
||||||
|
status_line status(L"Looking up boot volume");
|
||||||
|
|
||||||
|
const uefi::guid le_guid = uefi::protos::loaded_image::guid;
|
||||||
|
uefi::protos::loaded_image *loaded_image = nullptr;
|
||||||
|
|
||||||
|
try_or_raise(
|
||||||
|
bs->handle_protocol(image, &le_guid,
|
||||||
|
reinterpret_cast<void**>(&loaded_image)),
|
||||||
|
L"Could not find currently running UEFI loaded image");
|
||||||
|
|
||||||
|
const uefi::guid sfs_guid = uefi::protos::simple_file_system::guid;
|
||||||
|
uefi::protos::simple_file_system *fs;
|
||||||
|
try_or_raise(
|
||||||
|
bs->handle_protocol(loaded_image->device_handle, &sfs_guid,
|
||||||
|
reinterpret_cast<void**>(&fs)),
|
||||||
|
L"Could not find filesystem protocol for boot volume");
|
||||||
|
|
||||||
|
uefi::protos::file *f;
|
||||||
|
try_or_raise(
|
||||||
|
fs->open_volume(&f),
|
||||||
|
L"Could not open the boot volume");
|
||||||
|
|
||||||
|
return file(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace fs
|
||||||
|
} // namespace boot
|
||||||
|
|
||||||
25
src/boot/fs.h
Normal file
25
src/boot/fs.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <uefi/types.h>
|
||||||
|
#include <uefi/boot_services.h>
|
||||||
|
#include <uefi/protos/file.h>
|
||||||
|
|
||||||
|
namespace boot {
|
||||||
|
namespace fs {
|
||||||
|
|
||||||
|
class file
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
file(uefi::protos::file *f);
|
||||||
|
file(file &&o);
|
||||||
|
|
||||||
|
file open(const wchar_t *path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uefi::protos::file *m_file;
|
||||||
|
};
|
||||||
|
|
||||||
|
file get_boot_volume(uefi::handle image, uefi::boot_services *bs);
|
||||||
|
|
||||||
|
} // namespace fs
|
||||||
|
} // namespace boot
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "fs.h"
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ detect_debug_mode(EFI_RUNTIME_SERVICES *run, kernel_args *header) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
uefi::status
|
uefi::status
|
||||||
bootloader_main_uefi(uefi::system_table *st, console &con)
|
bootloader_main_uefi(uefi::handle image, uefi::system_table *st, console &con)
|
||||||
{
|
{
|
||||||
error::uefi_handler handler(con);
|
error::uefi_handler handler(con);
|
||||||
|
|
||||||
@@ -102,6 +103,8 @@ bootloader_main_uefi(uefi::system_table *st, console &con)
|
|||||||
args->runtime_services = rs;
|
args->runtime_services = rs;
|
||||||
args->acpi_table = hw::find_acpi_table(st);
|
args->acpi_table = hw::find_acpi_table(st);
|
||||||
|
|
||||||
|
fs::file disk = fs::get_boot_volume(image, bs);
|
||||||
|
fs::file kernel = disk.open(L"jsix.elf");
|
||||||
|
|
||||||
{
|
{
|
||||||
status_line status(L"Loading modules");
|
status_line status(L"Loading modules");
|
||||||
@@ -246,7 +249,7 @@ efi_main(uefi::handle image_handle, uefi::system_table *st)
|
|||||||
error::cpu_assert_handler handler;
|
error::cpu_assert_handler handler;
|
||||||
console con(st->boot_services, st->con_out);
|
console con(st->boot_services, st->con_out);
|
||||||
|
|
||||||
/*return*/ bootloader_main_uefi(st, con);
|
/*return*/ bootloader_main_uefi(image_handle, st, con);
|
||||||
|
|
||||||
while(1);
|
while(1);
|
||||||
return uefi::status::success;
|
return uefi::status::success;
|
||||||
|
|||||||
Reference in New Issue
Block a user