Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/efi.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ extern void efi_free (void *ptr);
extern void efi_free_pages (void *ptr, UINTN pages);
extern void *efi_allocate_pages (UINTN pages, EFI_MEMORY_TYPE type);

extern int efi_set_text_mode (int on);
extern void efi_cls (void);

#endif /* _EFI_H */
1 change: 1 addition & 0 deletions kern/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ OBJECTS += kern/efiblock.o
OBJECTS += kern/efiboot.o
OBJECTS += kern/efifile.o
OBJECTS += kern/efimain.o
OBJECTS += kern/efiterm.o
OBJECTS += kern/payload.o

OBJECTS += kern/callback.o
Expand Down
3 changes: 3 additions & 0 deletions kern/efiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ void efi_boot (EFI_DEVICE_PATH_PROTOCOL *path,
efi_open_protocol_wrapper;
#endif

if (! nt_cmdline->textmode)
efi_set_text_mode (0);

/* Start image */
if ((efirc = bs->StartImage (handle, NULL, NULL)) != 0)
{
Expand Down
2 changes: 2 additions & 0 deletions kern/efimain.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ EFI_STATUS EFIAPI efi_main (EFI_HANDLE image_handle,
/* Initialise stack cookie */
init_cookie();

efi_set_text_mode (1);

/* Print welcome banner */
printf ("\n\nntloader " VERSION "\n\n");

Expand Down
103 changes: 103 additions & 0 deletions kern/efiterm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* ntloader -- Microsoft Windows NT6+ loader
* Copyright (C) 2025 A1ive.
*
* ntloader is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* ntloader is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ntloader. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <strings.h>
#include <wchar.h>
#include "vdisk.h"
#include "cpio.h"
#include "ntloader.h"
#include "bcd.h"
#include "cmdline.h"
#include "efi.h"

/* The console control protocol is not a part of the EFI spec,
* but defined in Intel's Sample Implementation. */

static EFI_GUID efi_console_ctrl_guid =
{
0xf42f7782, 0x12e, 0x4c12,
{ 0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21 },
};

typedef enum
{
EFI_SCREEN_TEXT,
EFI_SCREEN_GRAPHICS,
EFI_SCREEN_TEXT_MAX_VALUE
} EFI_SCREEN_MODE;

struct _EFI_CONSOLE_CTRL_PROTOCOL
{
EFI_STATUS
(EFIAPI *GetMode) (struct _EFI_CONSOLE_CTRL_PROTOCOL *this,
EFI_SCREEN_MODE *mode,
BOOLEAN *uga_exists,
BOOLEAN *std_in_locked);

EFI_STATUS
(EFIAPI *SetMode) (struct _EFI_CONSOLE_CTRL_PROTOCOL *this,
EFI_SCREEN_MODE mode);

EFI_STATUS
(EFIAPI *LockStdin) (struct _EFI_CONSOLE_CTRL_PROTOCOL *this,
CHAR16 *password);
};
typedef struct _EFI_CONSOLE_CTRL_PROTOCOL EFI_CONSOLE_CTRL_PROTOCOL;

int efi_set_text_mode (int on)
{
EFI_STATUS rc;
EFI_CONSOLE_CTRL_PROTOCOL *c;
EFI_SCREEN_MODE mode, new_mode;
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;

rc = bs->LocateProtocol(&efi_console_ctrl_guid,
NULL,
(void**) &c);
if (rc != EFI_SUCCESS)
{
/* No console control protocol instance available, assume it is
* already in text mode. */
DBG ("Console control protocol not found, assume text mode.\n");
return 1;
}

if (c->GetMode (c, &mode, 0, 0) != EFI_SUCCESS)
return 0;

new_mode = on ? EFI_SCREEN_TEXT : EFI_SCREEN_GRAPHICS;
if (mode != new_mode)
if (c->SetMode (c, new_mode) != EFI_SUCCESS)
return 0;

return 1;
}

void efi_cls (void)
{
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
INT32 orig_attr = conout->Mode->Attribute;
conout->SetAttribute (conout, EFI_BLACK);
conout->ClearScreen (conout);
conout->SetAttribute (conout, orig_attr);
}
2 changes: 1 addition & 1 deletion kern/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void extract_initrd (void *ptr, size_t len)
{
nt_cmdline->bcd_length = BCD_LEN;
nt_cmdline->bcd = BCD_RAW;
printf ("...load BCD @%p %c%c%c%c [%x]\n", BCD_RAW,
DBG ("...load BCD @%p %c%c%c%c [%x]\n", BCD_RAW,
BCD_RAW[0], BCD_RAW[1], BCD_RAW[2], BCD_RAW[3], BCD_LEN);
vdisk_add_file ("BCD", BCD_RAW, BCD_LEN, read_mem_file);

Expand Down