Don't require system_table in console

This commit is contained in:
Justin C. Miller
2020-02-22 15:45:54 -08:00
parent f627ea7de0
commit 570638bba6
3 changed files with 13 additions and 18 deletions

View File

@@ -2,10 +2,8 @@
#include <stdint.h>
#include <uefi/types.h>
#include <uefi/boot_services.h>
#include <uefi/graphics.h>
#include <uefi/protos/graphics_output.h>
#include <uefi/protos/simple_text_output.h>
#include "console.h"
#include "error.h"
@@ -25,18 +23,13 @@ console *console::s_console = nullptr;
static const wchar_t digits[] = {u'0', u'1', u'2', u'3', u'4', u'5',
u'6', u'7', u'8', u'9', u'a', u'b', u'c', u'd', u'e', u'f'};
console::console(uefi::system_table *system_table) :
console::console(uefi::boot_services *bs, uefi::protos::simple_text_output *out) :
m_rows(0),
m_cols(0),
m_current_status_line(0)
m_current_status_line(0),
m_out(out)
{
uefi::status status;
s_console = this;
m_boot = system_table->boot_services;
m_out = system_table->con_out;
pick_mode();
pick_mode(bs);
try_or_raise(
m_out->query_mode(m_out->mode->mode, &m_cols, &m_rows),
@@ -54,17 +47,19 @@ console::console(uefi::system_table *system_table) :
m_out->set_attribute(uefi::attribute::light_gray);
m_out->output_string(L" booting...\r\n\n");
s_console = this;
}
void
console::pick_mode()
console::pick_mode(uefi::boot_services *bs)
{
uefi::status status;
uefi::protos::graphics_output *gfx_out_proto;
uefi::guid guid = uefi::protos::graphics_output::guid;
try_or_raise(
m_boot->locate_protocol(&guid, nullptr, (void **)&gfx_out_proto),
bs->locate_protocol(&guid, nullptr, (void **)&gfx_out_proto),
L"Failed to find a Graphics Output Protocol handle");
const uint32_t modes = gfx_out_proto->mode->max_mode;

View File

@@ -1,14 +1,15 @@
#pragma once
#include <stdarg.h>
#include <stddef.h>
#include <uefi/tables.h>
#include <uefi/boot_services.h>
#include <uefi/protos/simple_text_output.h>
namespace boot {
class console
{
public:
console(uefi::system_table *system_table);
console(uefi::boot_services *bs, uefi::protos::simple_text_output *out);
void status_begin(const wchar_t *message);
void status_fail(const wchar_t *message, const wchar_t *error=nullptr) const;
@@ -25,12 +26,11 @@ public:
static size_t print(const wchar_t *fmt, ...);
private:
void pick_mode();
void pick_mode(uefi::boot_services *bs);
size_t vprintf(const wchar_t *fmt, va_list args) const;
size_t m_rows, m_cols;
int m_current_status_line;
uefi::boot_services *m_boot;
uefi::protos::simple_text_output *m_out;
static console *s_console;

View File

@@ -265,7 +265,7 @@ efi_main(uefi::handle image_handle, uefi::system_table *st)
using namespace boot;
error::cpu_assert_handler handler;
console con(st);
console con(st->boot_services, st->con_out);
return bootloader_main_uefi(st, con);
}