Skip to content

Commit ae46dfc

Browse files
[libc][uefi] move uefi system table & image to app config
1 parent 0a47352 commit ae46dfc

File tree

8 files changed

+55
-18
lines changed

8 files changed

+55
-18
lines changed

libc/config/app.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "gpu/app.h"
1616
#elif defined(__linux__)
1717
#include "linux/app.h"
18+
#elif defined(__UEFI__)
19+
#include "uefi/app.h"
1820
#endif
1921

2022
#endif // LLVM_LIBC_CONFIG_APP_H

libc/config/uefi/app.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- Classes to capture properites of UEFI applications ------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_CONFIG_UEFI_APP_H
10+
#define LLVM_LIBC_CONFIG_UEFI_APP_H
11+
12+
#include "include/llvm-libc-types/EFI_HANDLE.h"
13+
#include "include/llvm-libc-types/EFI_SYSTEM_TABLE.h"
14+
#include "src/__support/macros/config.h"
15+
#include "src/__support/macros/properties/architectures.h"
16+
17+
#include <stdint.h>
18+
19+
namespace LIBC_NAMESPACE_DECL {
20+
21+
// Data structure which captures properties of a UEFI application.
22+
struct AppProperties {
23+
// UEFI system table
24+
EFI_SYSTEM_TABLE *system_table;
25+
26+
// UEFI image handle
27+
EFI_HANDLE image_handle;
28+
};
29+
30+
[[gnu::weak]] extern AppProperties app;
31+
32+
} // namespace LIBC_NAMESPACE_DECL
33+
34+
#endif // LLVM_LIBC_CONFIG_UEFI_APP_H

libc/include/Uefi.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,4 @@ types:
99
- type_name: EFI_SYSTEM_TABLE
1010
enums: []
1111
functions: []
12-
objects:
13-
- object_name: __llvm_libc_efi_system_table
14-
object_type: EFI_SYSTEM_TABLE *
15-
- object_name: __llvm_libc_efi_image_handle
16-
object_type: EFI_HANDLE
12+
objects: []

libc/src/__support/OSUtil/uefi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_object_library(
66
HDRS
77
io.h
88
DEPENDS
9+
libc.config.app_h
910
libc.include.llvm-libc-types.EFI_SYSTEM_TABLE
1011
libc.src.__support.common
1112
libc.src.__support.CPP.string_view

libc/src/__support/OSUtil/uefi/exit.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
//===-----------------------------------------------------------------===//
88

99
#include "src/__support/OSUtil/exit.h"
10+
#include "config/uefi/app.h"
1011
#include "include/llvm-libc-types/EFI_SYSTEM_TABLE.h"
1112
#include "src/__support/macros/config.h"
1213

1314
namespace LIBC_NAMESPACE_DECL {
1415
namespace internal {
1516

1617
[[noreturn]] void exit(int status) {
17-
__llvm_libc_efi_system_table->BootServices->Exit(__llvm_libc_efi_image_handle,
18-
status, 0, nullptr);
18+
app.system_table->BootServices->Exit(__llvm_libc_efi_image_handle, status, 0,
19+
nullptr);
1920
__builtin_unreachable();
2021
}
2122

libc/src/__support/OSUtil/uefi/io.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "io.h"
1010

1111
#include "Uefi.h"
12+
#include "config/uefi/app.h"
1213
#include "src/__support/CPP/string_view.h"
1314
#include "src/__support/macros/config.h"
1415

@@ -23,19 +24,17 @@ void write_to_stdout(cpp::string_view msg) {
2324
// TODO: use mbstowcs once implemented
2425
for (size_t i = 0; i < msg.size(); i++) {
2526
char16_t e[2] = {msg[i], 0};
26-
__llvm_libc_efi_system_table->ConOut->OutputString(
27-
__llvm_libc_efi_system_table->ConOut,
28-
reinterpret_cast<const char16_t *>(&e));
27+
app.system_table->ConOut->OutputString(
28+
app.system_table->ConOut, reinterpret_cast<const char16_t *>(&e));
2929
}
3030
}
3131

3232
void write_to_stderr(cpp::string_view msg) {
3333
// TODO: use mbstowcs once implemented
3434
for (size_t i = 0; i < msg.size(); i++) {
3535
char16_t e[2] = {msg[i], 0};
36-
__llvm_libc_efi_system_table->StdErr->OutputString(
37-
__llvm_libc_efi_system_table->StdErr,
38-
reinterpret_cast<const char16_t *>(&e));
36+
app.system_table->StdErr->OutputString(
37+
app.system_table->StdErr, reinterpret_cast<const char16_t *>(&e));
3938
}
4039
}
4140

libc/startup/uefi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ add_startup_object(
3434
SRCS
3535
crt1.cpp
3636
DEPENDS
37+
libc.config.app_h
3738
libc.src.__support.OSUtil.uefi.uefi_util
3839
)
3940

libc/startup/uefi/crt1.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "include/llvm-libc-macros/stdlib-macros.h"
10-
#include "include/llvm-libc-types/EFI_HANDLE.h"
119
#include "include/llvm-libc-types/EFI_STATUS.h"
12-
#include "include/llvm-libc-types/EFI_SYSTEM_TABLE.h"
10+
#include "config/uefi/app.h"
1311
#include "src/__support/OSUtil/uefi/error.h"
1412
#include "src/__support/macros/config.h"
1513

14+
namespace LIBC_NAMESPACE_DECL {
15+
AppProperties app;
16+
}
17+
1618
extern "C" {
1719
EFI_HANDLE __llvm_libc_efi_image_handle;
1820
EFI_SYSTEM_TABLE *__llvm_libc_efi_system_table;
1921

2022
int main(int argc, char **argv, char **envp);
2123

2224
EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
23-
__llvm_libc_efi_image_handle = ImageHandle;
24-
__llvm_libc_efi_system_table = SystemTable;
25+
LIBC_NAMESPACE::app.image_handle = ImageHandle;
26+
LIBC_NAMESPACE::app.system_table = SystemTable;
2527

2628
// TODO: we need the EFI_SHELL_PROTOCOL, malloc, free, and UTF16 -> UTF8
2729
// conversion.
2830
return LIBC_NAMESPACE::errno_to_uefi_status(main(0, nullptr, nullptr));
2931
}
32+
3033
}

0 commit comments

Comments
 (0)