3 Commits

Author SHA1 Message Date
Justin C. Miller
dd73cf833f Change initrd 'executable' bool to type enum. 2019-10-10 23:09:40 -07:00
Justin C. Miller
71fe3d733b Add the VDSO to the initrd 2019-10-10 00:14:46 -07:00
Justin C. Miller
991b13424e Initial building of the vdso.
Not actually integrating with the kernel yet.
2019-10-09 22:29:45 -07:00
483 changed files with 19668 additions and 34154 deletions

View File

@@ -1,11 +0,0 @@
[section] Imperative-voiced title in less than 50
# Body describes what was done, and why. New obviously-needed features
# don't necessarily require a why.
# Links to relevant bugs or web pages
See: Github bug #242
See: [frobozz blog post](https://jsix.dev/posts/frobozz/)
# Tags and keywords useful for searching
Tags:

View File

@@ -1,9 +1,7 @@
![jsix](assets/jsix.svg)
# jsix: A toy OS kernel
# jsix: A hobby operating system
**jsix** is the hobby operating system that I am currently building. It's far
from finished, or even being usable. Instead, it's a sandbox for me to play
**jsix** is the kernel for the hobby OS that I am currently building. It's
far from finished, or even being usable. Instead, it's a sandbox for me to play
with kernel-level code and explore architectures.
The design goals of the project are:
@@ -11,8 +9,7 @@ The design goals of the project are:
* Modernity - I'm not interested in designing for legacy systems, or running on
all hardware out there. My target is only 64 bit architecutres, and modern
commodity hardware. Currently that means x64 systems with Nehalem or newer
CPUs and UEFI firmware. (See [this list][cpu_features] for the currently
required CPU features.) Eventually I'd like to work on an AArch64 port,
CPUs and UEFI firmware. Eventually I'd like to work on an AArch64 port,
partly to force myself to factor out the architecture-dependent pieces of the
code base.
@@ -20,7 +17,8 @@ The design goals of the project are:
processes as possible, in the microkernel fashion. A sub-goal of this is to
explore where the bottlenecks of such a microkernel are now, and whether
eschewing legacy hardware will let me design a system that's less bogged down
by the traditional microkernel problems.
by the traditional microkernel problems. Given that there are no processes
yet, the kernel is monolithic by default.
* Exploration - I'm really mostly doing this to have fun learning and exploring
modern OS development. Modular design may be tossed out (hopefully
@@ -33,8 +31,6 @@ name, started around the same time as this project. So I've renamed this kernel
jsix (Always styled _jsix_ or `j6`, never capitalized) as an homage to L4, xv6,
and my wonderful wife.
[cpu_features]: https://github.com/justinian/jsix/blob/master/src/libraries/cpu/include/cpu/features.inc
## Building
jsix uses the [Ninja][] build tool, and generates the build files for it with a
@@ -42,7 +38,7 @@ custom tool called [Bonnibel][]. Bonnibel can be installed with [Cargo][], or
downloaded as a prebuilt binary from its Github repository.
[Ninja]: https://ninja-build.org
[Bonnibel]: https://github.com/justinian/bonnibel_rs
[Bonnibel]: https://github.com/justinian/bonnibel
[Cargo]: https://crates.io/crates/bonnibel
Requrirements:
@@ -75,8 +71,8 @@ I personally run this either from a real debian amd64 testing/buster machine or
a windows WSL debian testing/buster installation. The following should be
enough to set up such a system to build the kernel:
sudo apt install qemu-system-x86 nasm clang-10 mtools curl ninja-build
sudo update-alternatives /usr/bin/clang clang /usr/bin/clang-10 1000
sudo update-alternatives /usr/bin/clang++ clang++ /usr/bin/clang++-10 1000
curl -L -o pb https://github.com/justinian/bonnibel_rs/releases/download/v2.3.0/pb-linux-amd64 && chmod a+x pb
sudo apt install qemu-system-x86 nasm clang-6.0 mtools curl
sudo update-alternatives /usr/bin/clang clang /usr/bin/clang-6.0 1000
sudo update-alternatives /usr/bin/clang++ clang++ /usr/bin/clang++-6.0 1000
curl -L -o pb https://github.com/justinian/bonnibel/releases/download/2.0.0/pb_linux_amd64 && chmod a+x pb

View File

@@ -2,7 +2,7 @@ import gdb
class PrintStackCommand(gdb.Command):
def __init__(self):
super().__init__("j6stack", gdb.COMMAND_DATA)
super().__init__("popc_stack", gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
args = gdb.string_to_argv(arg)
@@ -16,48 +16,16 @@ class PrintStackCommand(gdb.Command):
depth = int(args[1])
for i in range(depth-1, -1, -1):
try:
offset = i * 8
base_addr = gdb.parse_and_eval(base)
value = gdb.parse_and_eval(f"*(uint64_t*)({base} + {offset})")
print("{:016x} (+{:04x}): {:016x}".format(int(base_addr) + offset, offset, int(value)))
except Exception as e:
print(e)
continue
class PrintBacktraceCommand(gdb.Command):
def __init__(self):
super().__init__("j6bt", gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
args = gdb.string_to_argv(arg)
depth = 30
if len(args) > 0:
depth = int(args[0])
frame = "$rbp"
if len(args) > 1:
frame = args[1]
for i in range(depth-1, -1, -1):
ret = gdb.parse_and_eval(f"*(uint64_t*)({frame} + 8)")
frame = gdb.parse_and_eval(f"*(uint64_t*)({frame})")
name = ""
block = gdb.block_for_pc(int(ret))
if block:
name = block.function or ""
print("{:016x} {}".format(int(ret), name))
if frame == 0 or ret == 0:
return
offset = i * 8
base_addr = gdb.parse_and_eval(base)
value = gdb.parse_and_eval(f"*(uint64_t*)({base} + {offset})")
print("{:016x} (+{:04x}): {:016x}".format(int(base_addr) + offset, offset, int(value)))
PrintStackCommand()
PrintBacktraceCommand()
import time
time.sleep(3.5)
gdb.execute("target remote :1234")
gdb.execute("set waiting = false")
gdb.execute("display/i $rip")

View File

@@ -8,21 +8,21 @@
# # initial application for the kernel to execute
# # on startup
[[files]]
dest = "vdso.so"
source = "host/libvdso.so"
type = "vdso"
[[files]]
dest = "screenfont.psf"
source = "../assets/fonts/tamsyn8x16r.psf"
[[files]]
dest = "symbol_table.dat"
source = "symbol_table.dat"
symbols = true
[[files]]
dest = "nulldrv1"
source = "user/nulldrv"
executable = true
type = "executable"
[[files]]
dest = "nulldrv2"
source = "user/nulldrv"
executable = true
type = "executable"

View File

@@ -1 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- Generator: Gravit.io --><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="176.562 356.069 211.11 113" width="211.11pt" height="113pt"><g><g><rect x="176.562" y="356.069" width="211.11" height="113" transform="matrix(1,0,0,1,0,0)" fill="rgb(255,255,255)"/><g><path d=" M 212.981 372.36 L 219.564 376.16 L 226.147 379.961 L 226.147 387.563 L 226.147 395.164 L 219.564 398.965 L 212.981 402.766 L 206.398 398.965 L 199.815 395.164 L 199.815 387.563 L 199.815 379.961 L 206.398 376.16 L 212.981 372.36 L 212.981 372.36 L 212.981 372.36 Z M 256.292 397.366 L 262.875 401.166 L 269.458 404.967 L 269.458 412.569 L 269.458 420.17 L 262.875 423.971 L 256.292 427.772 L 249.709 423.971 L 243.126 420.17 L 243.126 412.569 L 243.126 404.967 L 249.709 401.166 L 256.292 397.366 L 256.292 397.366 Z M 183.622 387.283 L 205.52 374.64 L 227.418 361.997 L 249.316 374.64 L 271.214 387.283 L 271.214 412.569 L 271.214 437.854 L 249.316 450.497 L 227.418 463.14 L 205.52 450.497 L 183.622 437.854 L 183.622 412.569 L 183.622 387.283 L 183.622 387.283 L 183.622 387.283 Z M 241.855 372.36 L 248.438 376.16 L 255.021 379.961 L 255.021 387.563 L 255.021 395.164 L 248.438 398.965 L 241.855 402.766 L 235.272 398.965 L 228.689 395.164 L 228.689 387.563 L 228.689 379.961 L 235.272 376.16 L 241.855 372.36 Z " fill-rule="evenodd" fill="rgb(49,79,128)"/><path d=" M 298.642 379.579 L 291.621 379.579 L 291.621 372.558 L 298.642 372.558 L 298.642 379.579 Z M 285.214 446.718 L 285.214 441.452 L 287.32 441.452 L 287.32 441.452 Q 289.339 441.452 290.524 440.092 L 290.524 440.092 L 290.524 440.092 Q 291.708 438.731 291.708 436.625 L 291.708 436.625 L 291.708 387.039 L 298.729 387.039 L 298.729 436.011 L 298.729 436.011 Q 298.729 440.925 295.921 443.822 L 295.921 443.822 L 295.921 443.822 Q 293.113 446.718 288.286 446.718 L 288.286 446.718 L 285.214 446.718 Z M 306.628 432.676 L 306.628 427.41 L 314.088 427.41 L 314.088 427.41 Q 317.862 427.41 319.573 425.347 L 319.573 425.347 L 319.573 425.347 Q 321.285 423.285 321.285 419.95 L 321.285 419.95 L 321.285 419.95 Q 321.285 417.317 319.705 415.474 L 319.705 415.474 L 319.705 415.474 Q 318.125 413.631 314.966 411.174 L 314.966 411.174 L 314.966 411.174 Q 312.245 408.98 310.621 407.356 L 310.621 407.356 L 310.621 407.356 Q 308.998 405.732 307.813 403.319 L 307.813 403.319 L 307.813 403.319 Q 306.628 400.905 306.628 397.746 L 306.628 397.746 L 306.628 397.746 Q 306.628 393.095 309.744 390.067 L 309.744 390.067 L 309.744 390.067 Q 312.859 387.039 318.125 387.039 L 318.125 387.039 L 325.76 387.039 L 325.76 392.305 L 319.441 392.305 L 319.441 392.305 Q 313.21 392.305 313.21 398.185 L 313.21 398.185 L 313.21 398.185 Q 313.21 400.467 314.615 402.134 L 314.615 402.134 L 314.615 402.134 Q 316.019 403.802 319.003 406.083 L 319.003 406.083 L 319.003 406.083 Q 321.723 408.19 323.479 409.901 L 323.479 409.901 L 323.479 409.901 Q 325.234 411.613 326.463 414.202 L 326.463 414.202 L 326.463 414.202 Q 327.691 416.791 327.691 420.301 L 327.691 420.301 L 327.691 420.301 Q 327.691 426.532 324.4 429.604 L 324.4 429.604 L 324.4 429.604 Q 321.109 432.676 315.141 432.676 L 315.141 432.676 L 306.628 432.676 Z M 342.611 379.579 L 335.59 379.579 L 335.59 372.558 L 342.611 372.558 L 342.611 379.579 Z M 342.611 432.676 L 335.59 432.676 L 335.59 387.039 L 342.611 387.039 L 342.611 432.676 Z M 356.126 432.676 L 348.754 432.676 L 361.392 409.77 L 349.632 387.039 L 356.39 387.039 L 364.639 403.187 L 372.977 387.039 L 379.735 387.039 L 367.974 409.77 L 380.612 432.676 L 373.24 432.676 L 364.639 416.001 L 356.126 432.676 Z " fill="rgb(49,79,128)"/></g></g></g></svg>

Before

Width:  |  Height:  |  Size: 3.6 KiB

2389
external/catch/catch.hpp vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,103 +0,0 @@
#pragma once
#ifndef _uefi_boot_services_h_
#define _uefi_boot_services_h_
// This Source Code Form is part of the j6-uefi-headers project and is subject
// to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
#include <stdint.h>
#include <uefi/tables.h>
#include <uefi/types.h>
namespace uefi {
namespace bs_impl {
using allocate_pages = status (*)(allocate_type, memory_type, size_t, void**);
using free_pages = status (*)(void*, size_t);
using get_memory_map = status (*)(size_t*, memory_descriptor*, size_t*, size_t*, uint32_t*);
using allocate_pool = status (*)(memory_type, uint64_t, void**);
using free_pool = status (*)(void*);
using handle_protocol = status (*)(handle, const guid*, void**);
using create_event = status (*)(evt, tpl, event_notify, void*, event*);
using exit_boot_services = status (*)(handle, size_t);
using locate_protocol = status (*)(const guid*, void*, void**);
using copy_mem = void (*)(void*, void*, size_t);
using set_mem = void (*)(void*, uint64_t, uint8_t);
}
struct boot_services {
static constexpr uint64_t signature = 0x56524553544f4f42ull;
table_header header;
// Task Priority Level management
void *raise_tpl;
void *restore_tpl;
// Memory Services
bs_impl::allocate_pages allocate_pages;
bs_impl::free_pages free_pages;
bs_impl::get_memory_map get_memory_map;
bs_impl::allocate_pool allocate_pool;
bs_impl::free_pool free_pool;
// Event & Timer Services
bs_impl::create_event create_event;
void *set_timer;
void *wait_for_event;
void *signal_event;
void *close_event;
void *check_event;
// Protocol Handler Services
void *install_protocol_interface;
void *reinstall_protocol_interface;
void *uninstall_protocol_interface;
bs_impl::handle_protocol handle_protocol;
void *_reserved;
void *register_protocol_notify;
void *locate_handle;
void *locate_device_path;
void *install_configuration_table;
// Image Services
void *load_image;
void *start_image;
void *exit;
void *unload_image;
bs_impl::exit_boot_services exit_boot_services;
// Miscellaneous Services
void *get_next_monotonic_count;
void *stall;
void *set_watchdog_timer;
// DriverSupport Services
void *connect_controller;
void *disconnect_controller;
// Open and Close Protocol Services
void *open_protocol;
void *close_protocol;
void *open_protocol_information;
// Library Services
void *protocols_per_handle;
void *locate_handle_buffer;
bs_impl::locate_protocol locate_protocol;
void *install_multiple_protocol_interfaces;
void *uninstall_multiple_protocol_interfaces;
// 32-bit CRC Services
void *calculate_crc32;
// Miscellaneous Services
bs_impl::copy_mem copy_mem;
bs_impl::set_mem set_mem;
void *create_event_ex;
};
} // namespace uefi
#endif

View File

@@ -1,39 +0,0 @@
STATUS_WARNING( warn_unknown_glyph, 1)
STATUS_WARNING( warn_delete_failure, 2)
STATUS_WARNING( warn_write_failure, 3)
STATUS_WARNING( warn_buffer_too_small,4)
STATUS_WARNING( warn_stale_data, 5)
STATUS_WARNING( warn_file_system, 6)
STATUS_ERROR( load_error, 1)
STATUS_ERROR( invalid_parameter, 2)
STATUS_ERROR( unsupported, 3)
STATUS_ERROR( bad_buffer_size, 4)
STATUS_ERROR( buffer_too_small, 5)
STATUS_ERROR( not_ready, 6)
STATUS_ERROR( device_error, 7)
STATUS_ERROR( write_protected, 8)
STATUS_ERROR( out_of_resources, 9)
STATUS_ERROR( volume_corrupted, 10)
STATUS_ERROR( volume_full, 11)
STATUS_ERROR( no_media, 12)
STATUS_ERROR( media_changed, 13)
STATUS_ERROR( not_found, 14)
STATUS_ERROR( access_denied, 15)
STATUS_ERROR( no_response, 16)
STATUS_ERROR( no_mapping, 17)
STATUS_ERROR( timeout, 18)
STATUS_ERROR( not_started, 19)
STATUS_ERROR( already_started, 20)
STATUS_ERROR( aborted, 21)
STATUS_ERROR( icmp_error, 22)
STATUS_ERROR( tftp_error, 23)
STATUS_ERROR( protocol_error, 24)
STATUS_ERROR( incompatible_version, 25)
STATUS_ERROR( security_violation, 26)
STATUS_ERROR( crc_error, 27)
STATUS_ERROR( end_of_media, 28)
STATUS_ERROR( end_of_file, 31)
STATUS_ERROR( invalid_language, 32)
STATUS_ERROR( compromised_data, 33)
STATUS_ERROR( http_error, 35)

View File

@@ -1,92 +0,0 @@
#pragma once
#ifndef _uefi_graphics_h_
#define _uefi_graphics_h_
// This Source Code Form is part of the j6-uefi-headers project and is subject
// to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
#include <stdint.h>
#include <uefi/types.h>
namespace uefi {
struct text_output_mode
{
int32_t max_mode;
int32_t mode;
int32_t attribute;
int32_t cursor_column;
int32_t cursor_row;
bool cursor_visible;
};
struct pixel_bitmask
{
uint32_t red_mask;
uint32_t green_mask;
uint32_t blue_mask;
uint32_t reserved_mask;
};
enum class pixel_format
{
rgb8,
bgr8,
bitmask,
blt_only
};
struct graphics_output_mode_info
{
uint32_t version;
uint32_t horizontal_resolution;
uint32_t vertical_resolution;
pixel_format pixel_format;
pixel_bitmask pixel_information;
uint32_t pixels_per_scanline;
};
struct graphics_output_mode
{
uint32_t max_mode;
uint32_t mode;
graphics_output_mode_info *info;
uint64_t size_of_info;
uintptr_t frame_buffer_base;
uint64_t frame_buffer_size;
};
enum class attribute : uint64_t
{
black,
blue,
green,
cyan,
red,
magenta,
brown,
light_gray,
dark_gray,
light_blue,
light_green,
light_cyan,
light_red,
light_magenta,
yellow,
white,
background_black = 0x00,
background_blue = 0x10,
background_green = 0x20,
background_cyan = 0x30,
background_red = 0x40,
background_magenta = 0x50,
background_brown = 0x60,
background_light_gray = 0x70,
};
} // namespace uefi
#endif

29
external/uefi/guid.h vendored
View File

@@ -1,29 +0,0 @@
#pragma once
#ifndef _uefi_guid_h_
#define _uefi_guid_h_
// This Source Code Form is part of the j6-uefi-headers project and is subject
// to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
#include <stdint.h>
namespace uefi {
struct guid
{
uint32_t data1;
uint16_t data2;
uint16_t data3;
uint8_t data4[8];
inline bool operator==(const guid &other) const {
return reinterpret_cast<const uint64_t*>(this)[0] == reinterpret_cast<const uint64_t*>(&other)[0]
&& reinterpret_cast<const uint64_t*>(this)[1] == reinterpret_cast<const uint64_t*>(&other)[1];
}
};
} // namespace uefi
#endif

View File

@@ -1,390 +0,0 @@
#pragma once
#ifndef _uefi_networking_h_
#define _uefi_networking_h_
// This Source Code Form is part of the j6-uefi-headers project and is subject
// to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
#include <stdint.h>
#include <uefi/types.h>
namespace uefi {
//
// IPv4 definitions
//
struct ipv4_address
{
uint8_t addr[4];
};
//
// IPv6 definitions
//
struct ipv6_address
{
uint8_t addr[16];
};
struct ip6_address_info
{
ipv6_address address;
uint8_t prefix_length;
};
struct ip6_route_table
{
ipv6_address gateway;
ipv6_address destination;
uint8_t prefix_length;
};
enum class ip6_neighbor_state : int {
incomplete,
reachable,
stale,
delay,
probe,
}
struct ip6_neighbor_cache
{
ipv6_address neighbor;
mac_address link_address;
ip6_neighbor_state state;
};
enum class icmpv6_type : uint8_t
{
dest_unreachable = 0x1,
packet_too_big = 0x2,
time_exceeded = 0x3,
parameter_problem = 0x4,
echo_request = 0x80,
echo_reply = 0x81,
listener_query = 0x82,
listener_report = 0x83,
listener_done = 0x84,
router_solicit = 0x85,
router_advertise = 0x86,
neighbor_solicit = 0x87,
neighbor_advertise = 0x88,
redirect = 0x89,
listener_report_2 = 0x8f,
};
enum class icmpv6_code : uint8_t
{
// codes for icmpv6_type::dest_unreachable
no_route_to_dest = 0x0,
comm_prohibited = 0x1,
beyond_scope = 0x2,
addr_unreachable = 0x3,
port_unreachable = 0x4,
source_addr_failed = 0x5,
route_rejected = 0x6,
// codes for icmpv6_type::time_exceeded
timeout_hop_limit = 0x0,
timeout_reassemble = 0x1,
// codes for icmpv6_type::parameter_problem
erroneous_header = 0x0,
unrecognize_next_hdr = 0x1,
unrecognize_option = 0x2,
};
struct ip6_icmp_type
{
icmpv6_type type;
icmpv6_code code;
};
struct ip6_config_data
{
uint8_t default_protocol;
bool accept_any_protocol;
bool accept_icmp_errors;
bool accept_promiscuous;
ipv6_address destination_address;
ipv6_address station_address;
uint8_t traffic_class;
uint8_t hop_limit;
uint32_t flow_label;
uint32_t receive_timeout;
uint32_t transmit_timeout;
};
struct ip6_mode_data
{
bool is_started;
uint32_t max_packet_size;
ip6_config_data config_data;
bool is_configured;
uint32_t address_count;
ip6_address_info * address_list;
uint32_t group_count;
ipv6_address * group_table;
uint32_t route_count;
ip6_route_table * route_table;
uint32_t neighbor_count;
ip6_neighbor_cache * neighbor_cache;
uint32_t prefix_count;
ip6_address_info * prefix_table;
uint32_t icmp_type_count;
* icmp_type_list;
};
struct ip6_header
{
uint8_t traffic_class_h : 4;
uint8_t version : 4;
uint8_t flow_label_h : 4;
uint8_t traffic_class_l : 4;
uint16_t flow_label_l;
uint16_t payload_length;
uint8_t next_header;
uint8_t hop_limit;
ipv6_address source_address;
ipv6_address destination_address;
} __attribute__ ((packed));
struct ip6_fragment_data
{
uint32_t fragment_length;
void *fragment_buffer;
};
struct ip6_override_data
{
uint8_t protocol;
uint8_t hop_limit;
uint32_t flow_label;
};
struct ip6_receive_data
{
time time_stamp;
event recycle_signal;
uint32_t header_length;
ip6_header *header;
uint32_t data_length;
uint32_t fragment_count;
ip6_fragment_data fragment_table[1];
};
struct ip6_transmit_data
{
ipv6_address destination_address;
ip6_override_data *override_data;
uint32_t ext_hdrs_length;
void *ext_hdrs;
uint8_t next_header;
uint32_t data_length;
uint32_t fragment_count;
ip6_fragment_data fragment_table[1];
};
struct ip6_completion_token
{
event event;
status status;
union {
ip6_receive_data *rx_data;
ip6_transmit_data *tx_data;
} packet;
};
enum class ip6_config_data_type : int
{
interface_info,
alt_interface_id,
policy,
dup_addr_detect_transmits,
manual_address,
gateway,
dns_server,
maximum
};
struct ip6_config_interface_info
{
wchar_t name[32];
uint8_t if_type;
uint32_t hw_address_size;
mac_address hw_address;
uint32_t address_info_count;
ip6_address_info *address_info;
uint32_t route_count;
ip6_route_table *route_table;
};
struct ip6_config_interface_id
{
uint8_t id[8];
};
enum class ip6_config_policy : int
{
manual,
automatic
};
struct ip6_config_dup_addr_detect_transmits
{
uint32_t dup_addr_detect_transmits;
};
struct ip6_config_manual_address
{
ipv6_address address;
bool is_anycast;
uint8_t prefix_length;
};
//
// IP definitions
//
union ip_address
{
uint8_t addr[4];
ipv4_address v4;
ipv6_address v6;
};
//
// HTTP definitions
//
struct httpv4_access_point
{
bool use_default_address;
ipv4_address local_address;
ipv4_address local_subnet;
uint16_t local_port;
};
struct httpv6_access_point
{
ipv6_address local_address;
uint16_t local_port;
};
enum class http_version : int {
v10,
v11,
unsupported,
};
struct http_config_data
{
http_version http_version;
uint32_t time_out_millisec;
bool local_address_is_ipv6;
union {
httpv4_access_point *ipv4_node;
httpv6_access_point *ipv6_node;
} access_point;
};
enum class http_method : int {
get,
post,
patch,
options,
connect,
head,
put,
delete_,
trace,
};
struct http_request_data
{
http_method method;
wchar_t *url;
};
enum class http_status_code : int {
unsupported,
continue_,
switching_protocols,
ok,
created,
accepted,
non_authoritative_information,
no_content,
reset_content,
partial_content,
multiple_choices,
moved_permanently,
found,
see_other,
not_modified,
use_proxy,
temporary_redirect,
bad_request,
unauthorized,
payment_required,
forbidden,
not_found,
method_not_allowed,
not_acceptable,
proxy_authentication_required,
request_time_out,
conflict,
gone,
length_required,
precondition_failed,
request_entity_too_large,
request_uri_too_large,
unsupported_media_type,
requested_range_not_satisfied,
expectation_failed,
internal_server_error,
not_implemented,
bad_gateway,
service_unavailable,
gateway_timeout,
http_version_not_supported,
permanent_redirect, // I hate your decisions, uefi.
};
struct http_response_data
{
http_status_code status_code;
};
struct http_header
{
char *field_name;
char *field_value;
};
struct http_message
{
union {
http_request_data *request;
http_response_data *response;
} data;
size_t header_count;
http_header *headers;
size_t body_length;
void *body;
};
struct http_token
{
event event;
status status;
http_message *message;
};
} // namespace uefi
#endif

View File

@@ -1,31 +0,0 @@
#pragma once
#ifndef _uefi_protos_device_path_h_
#define _uefi_protos_device_path_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
namespace uefi {
namespace protos {
struct device_path;
struct device_path
{
static constexpr uefi::guid guid{ 0x09576e91,0x6d3f,0x11d2,{0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b} };
uint8_t type;
uint8_t sub_type;
uint16_t length;
protected:
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_device_path_h_

View File

@@ -1,126 +0,0 @@
#pragma once
#ifndef _uefi_protos_file_h_
#define _uefi_protos_file_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
namespace uefi {
namespace protos {
struct file;
struct file
{
inline uefi::status open(file ** new_handle, const wchar_t * file_name, file_mode open_mode, file_attr attributes) {
return _open(this, new_handle, file_name, open_mode, attributes);
}
inline uefi::status close() {
return _close(this);
}
inline uefi::status delete_file() {
return _delete_file(this);
}
inline uefi::status read(uint64_t * buffer_size, void * buffer) {
return _read(this, buffer_size, buffer);
}
inline uefi::status write(uint64_t * buffer_size, void * buffer) {
return _write(this, buffer_size, buffer);
}
inline uefi::status get_position(uint64_t * position) {
return _get_position(this, position);
}
inline uefi::status set_position(uint64_t position) {
return _set_position(this, position);
}
inline uefi::status get_info(const guid * info_type, uint64_t * buffer_size, void * buffer) {
return _get_info(this, info_type, buffer_size, buffer);
}
inline uefi::status set_info(const guid * info_type, uint64_t buffer_size, void * buffer) {
return _set_info(this, info_type, buffer_size, buffer);
}
inline uefi::status flush() {
return _flush(this);
}
inline uefi::status open_ex(file ** new_handle, const wchar_t * file_name, uint64_t open_mode, uint64_t attributes, file_io_token * token) {
return _open_ex(this, new_handle, file_name, open_mode, attributes, token);
}
inline uefi::status read_ex(file_io_token * token) {
return _read_ex(this, token);
}
inline uefi::status write_ex(file_io_token * token) {
return _write_ex(this, token);
}
inline uefi::status flush_ex(file_io_token * token) {
return _flush_ex(this, token);
}
uint64_t revision;
protected:
using _open_def = uefi::status (*)(uefi::protos::file *, file **, const wchar_t *, file_mode, file_attr);
_open_def _open;
using _close_def = uefi::status (*)(uefi::protos::file *);
_close_def _close;
using _delete_file_def = uefi::status (*)(uefi::protos::file *);
_delete_file_def _delete_file;
using _read_def = uefi::status (*)(uefi::protos::file *, uint64_t *, void *);
_read_def _read;
using _write_def = uefi::status (*)(uefi::protos::file *, uint64_t *, void *);
_write_def _write;
using _get_position_def = uefi::status (*)(uefi::protos::file *, uint64_t *);
_get_position_def _get_position;
using _set_position_def = uefi::status (*)(uefi::protos::file *, uint64_t);
_set_position_def _set_position;
using _get_info_def = uefi::status (*)(uefi::protos::file *, const guid *, uint64_t *, void *);
_get_info_def _get_info;
using _set_info_def = uefi::status (*)(uefi::protos::file *, const guid *, uint64_t, void *);
_set_info_def _set_info;
using _flush_def = uefi::status (*)(uefi::protos::file *);
_flush_def _flush;
using _open_ex_def = uefi::status (*)(uefi::protos::file *, file **, const wchar_t *, uint64_t, uint64_t, file_io_token *);
_open_ex_def _open_ex;
using _read_ex_def = uefi::status (*)(uefi::protos::file *, file_io_token *);
_read_ex_def _read_ex;
using _write_ex_def = uefi::status (*)(uefi::protos::file *, file_io_token *);
_write_ex_def _write_ex;
using _flush_ex_def = uefi::status (*)(uefi::protos::file *, file_io_token *);
_flush_ex_def _flush_ex;
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_file_h_

View File

@@ -1,36 +0,0 @@
#pragma once
#ifndef _uefi_protos_file_info_h_
#define _uefi_protos_file_info_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
namespace uefi {
namespace protos {
struct file_info;
struct file_info
{
static constexpr uefi::guid guid{ 0x09576e92,0x6d3f,0x11d2,{0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b} };
uint64_t size;
uint64_t file_size;
uint64_t physical_size;
time create_time;
time last_access_time;
time modification_time;
uint64_t attribute;
wchar_t file_name[];
protected:
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_file_info_h_

View File

@@ -1,51 +0,0 @@
#pragma once
#ifndef _uefi_protos_graphics_output_h_
#define _uefi_protos_graphics_output_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
#include <uefi/graphics.h>
namespace uefi {
namespace protos {
struct graphics_output;
struct graphics_output
{
static constexpr uefi::guid guid{ 0x9042a9de,0x23dc,0x4a38,{0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a} };
inline uefi::status query_mode(uint32_t mode_number, uint64_t * size_of_info, uefi::graphics_output_mode_info ** info) {
return _query_mode(this, mode_number, size_of_info, info);
}
inline uefi::status set_mode(uint32_t mode_number) {
return _set_mode(this, mode_number);
}
inline uefi::status blt() {
return _blt(this);
}
protected:
using _query_mode_def = uefi::status (*)(uefi::protos::graphics_output *, uint32_t, uint64_t *, uefi::graphics_output_mode_info **);
_query_mode_def _query_mode;
using _set_mode_def = uefi::status (*)(uefi::protos::graphics_output *, uint32_t);
_set_mode_def _set_mode;
using _blt_def = uefi::status (*)(uefi::protos::graphics_output *);
_blt_def _blt;
public:
uefi::graphics_output_mode * mode;
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_graphics_output_h_

View File

@@ -1,72 +0,0 @@
#pragma once
#ifndef _uefi_protos_http_h_
#define _uefi_protos_http_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
#include <uefi/networking.h>
namespace uefi {
namespace protos {
struct http;
struct http
{
static constexpr uefi::guid guid{ 0x7a59b29b,0x910b,0x4171,{0x82,0x42,0xa8,0x5a,0x0d,0xf2,0x5b,0x5b} };
static constexpr uefi::guid service_binding{ 0xbdc8e6af,0xd9bc,0x4379,{0xa7,0x2a,0xe0,0xc4,0xe7,0x5d,0xae,0x1c} };
inline uefi::status get_mode_data(uefi::http_config_data * http_config_data) {
return _get_mode_data(this, http_config_data);
}
inline uefi::status configure(uefi::http_config_data * http_config_data) {
return _configure(this, http_config_data);
}
inline uefi::status request(uefi::http_token * token) {
return _request(this, token);
}
inline uefi::status cancel(uefi::http_token * token) {
return _cancel(this, token);
}
inline uefi::status response(uefi::http_token * token) {
return _response(this, token);
}
inline uefi::status poll() {
return _poll(this);
}
protected:
using _get_mode_data_def = uefi::status (*)(uefi::protos::http *, uefi::http_config_data *);
_get_mode_data_def _get_mode_data;
using _configure_def = uefi::status (*)(uefi::protos::http *, uefi::http_config_data *);
_configure_def _configure;
using _request_def = uefi::status (*)(uefi::protos::http *, uefi::http_token *);
_request_def _request;
using _cancel_def = uefi::status (*)(uefi::protos::http *, uefi::http_token *);
_cancel_def _cancel;
using _response_def = uefi::status (*)(uefi::protos::http *, uefi::http_token *);
_response_def _response;
using _poll_def = uefi::status (*)(uefi::protos::http *);
_poll_def _poll;
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_http_h_

View File

@@ -1,93 +0,0 @@
#pragma once
#ifndef _uefi_protos_ip6_h_
#define _uefi_protos_ip6_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
#include <uefi/networking.h>
namespace uefi {
namespace protos {
struct ip6;
struct ip6
{
static constexpr uefi::guid guid{ 0x2c8759d5,0x5c2d,0x66ef,{0x92,0x5f,0xb6,0x6c,0x10,0x19,0x57,0xe2} };
static constexpr uefi::guid service_binding{ 0xec835dd3,0xfe0f,0x617b,{0xa6,0x21,0xb3,0x50,0xc3,0xe1,0x33,0x88} };
inline uefi::status get_mode_data(uefi::ip6_mode_data * ip6_mode_data, uefi::managed_network_config_data * mnp_config_data, uefi::simple_network_mode * snp_config_data) {
return _get_mode_data(this, ip6_mode_data, mnp_config_data, snp_config_data);
}
inline uefi::status configure(uefi::ip6_config_data * ip6_config_data) {
return _configure(this, ip6_config_data);
}
inline uefi::status groups(bool join_flag, uefi::ipv6_address * group_address) {
return _groups(this, join_flag, group_address);
}
inline uefi::status routes(bool delete_route, uefi::ipv6_address * destination, uint8_t prefix_length, uefi::ipv6_address * gateway_address) {
return _routes(this, delete_route, destination, prefix_length, gateway_address);
}
inline uefi::status neighbors(bool delete_flag, uefi::ipv6_address * target_ip6_address, uefi::mac_address * target_link_address, uint32_t timeout, bool override) {
return _neighbors(this, delete_flag, target_ip6_address, target_link_address, timeout, override);
}
inline uefi::status transmit(uefi::ip6_completion_token * token) {
return _transmit(this, token);
}
inline uefi::status receive(uefi::ip6_completion_token * token) {
return _receive(this, token);
}
inline uefi::status cancel(uefi::ip6_completion_token * token) {
return _cancel(this, token);
}
inline uefi::status poll() {
return _poll(this);
}
protected:
using _get_mode_data_def = uefi::status (*)(uefi::protos::ip6 *, uefi::ip6_mode_data *, uefi::managed_network_config_data *, uefi::simple_network_mode *);
_get_mode_data_def _get_mode_data;
using _configure_def = uefi::status (*)(uefi::protos::ip6 *, uefi::ip6_config_data *);
_configure_def _configure;
using _groups_def = uefi::status (*)(uefi::protos::ip6 *, bool, uefi::ipv6_address *);
_groups_def _groups;
using _routes_def = uefi::status (*)(uefi::protos::ip6 *, bool, uefi::ipv6_address *, uint8_t, uefi::ipv6_address *);
_routes_def _routes;
using _neighbors_def = uefi::status (*)(uefi::protos::ip6 *, bool, uefi::ipv6_address *, uefi::mac_address *, uint32_t, bool);
_neighbors_def _neighbors;
using _transmit_def = uefi::status (*)(uefi::protos::ip6 *, uefi::ip6_completion_token *);
_transmit_def _transmit;
using _receive_def = uefi::status (*)(uefi::protos::ip6 *, uefi::ip6_completion_token *);
_receive_def _receive;
using _cancel_def = uefi::status (*)(uefi::protos::ip6 *, uefi::ip6_completion_token *);
_cancel_def _cancel;
using _poll_def = uefi::status (*)(uefi::protos::ip6 *);
_poll_def _poll;
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_ip6_h_

View File

@@ -1,57 +0,0 @@
#pragma once
#ifndef _uefi_protos_ip6_config_h_
#define _uefi_protos_ip6_config_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
#include <uefi/networking.h>
namespace uefi {
namespace protos {
struct ip6_config;
struct ip6_config
{
static constexpr uefi::guid guid{ 0x937fe521,0x95ae,0x4d1a,{0x89,0x29,0x48,0xbc,0xd9,0x0a,0xd3,0x1a} };
inline uefi::status set_data(uefi::ip6_config_data_type data_type, size_t data_size, void * data) {
return _set_data(this, data_type, data_size, data);
}
inline uefi::status get_data(uefi::ip6_config_data_type data_type, size_t data_size, void * data) {
return _get_data(this, data_type, data_size, data);
}
inline uefi::status register_data_notify(uefi::ip6_config_data_type data_type, uefi::event event) {
return _register_data_notify(this, data_type, event);
}
inline uefi::status unregister_data_notify(uefi::ip6_config_data_type data_type, uefi::event event) {
return _unregister_data_notify(this, data_type, event);
}
protected:
using _set_data_def = uefi::status (*)(uefi::protos::ip6_config *, uefi::ip6_config_data_type, size_t, void *);
_set_data_def _set_data;
using _get_data_def = uefi::status (*)(uefi::protos::ip6_config *, uefi::ip6_config_data_type, size_t, void *);
_get_data_def _get_data;
using _register_data_notify_def = uefi::status (*)(uefi::protos::ip6_config *, uefi::ip6_config_data_type, uefi::event);
_register_data_notify_def _register_data_notify;
using _unregister_data_notify_def = uefi::status (*)(uefi::protos::ip6_config *, uefi::ip6_config_data_type, uefi::event);
_unregister_data_notify_def _unregister_data_notify;
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_ip6_config_h_

View File

@@ -1,36 +0,0 @@
#pragma once
#ifndef _uefi_protos_load_file_h_
#define _uefi_protos_load_file_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
#include <uefi/protos/device_path.h>
namespace uefi {
namespace protos {
struct load_file;
struct load_file
{
static constexpr uefi::guid guid{ {0x56ec3091,0x954c,0x11d2,{0x8e,0x3f,0x00,0xa0,0xc9,0x69,0x72,0x3b} };
inline uefi::status load_file(uefi::protos::device_path * file_path, bool boot_policy, size_t * buffer_size, void * buffer) {
return _load_file(this, file_path, boot_policy, buffer_size, buffer);
}
protected:
using _load_file_def = uefi::status (*)(uefi::protos::load_file *, uefi::protos::device_path *, bool, size_t *, void *);
_load_file_def _load_file;
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_load_file_h_

View File

@@ -1,49 +0,0 @@
#pragma once
#ifndef _uefi_protos_loaded_image_h_
#define _uefi_protos_loaded_image_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
#include <uefi/tables.h>
#include <uefi/protos/device_path.h>
namespace uefi {
namespace protos {
struct loaded_image;
struct loaded_image
{
static constexpr uefi::guid guid{ 0x5b1b31a1,0x9562,0x11d2,{0x8e,0x3f,0x00,0xa0,0xc9,0x69,0x72,0x3b} };
inline uefi::status unload(uefi::handle image_handle) {
return _unload(image_handle);
}
uint32_t revision;
uefi::handle parent_handle;
uefi::system_table * system_table;
uefi::handle device_handle;
uefi::protos::device_path * file_path;
void * reserved;
uint32_t load_options_size;
void * load_options;
void * image_base;
uint64_t image_size;
uefi::memory_type image_code_type;
uefi::memory_type image_data_type;
protected:
using _unload_def = uefi::status (*)(uefi::handle);
_unload_def _unload;
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_loaded_image_h_

View File

@@ -1,41 +0,0 @@
#pragma once
#ifndef _uefi_protos_service_binding_h_
#define _uefi_protos_service_binding_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
namespace uefi {
namespace protos {
struct service_binding;
struct service_binding
{
inline uefi::status create_child(uefi::handle * child_handle) {
return _create_child(this, child_handle);
}
inline uefi::status destroy_child(uefi::handle child_handle) {
return _destroy_child(this, child_handle);
}
protected:
using _create_child_def = uefi::status (*)(uefi::protos::service_binding *, uefi::handle *);
_create_child_def _create_child;
using _destroy_child_def = uefi::status (*)(uefi::protos::service_binding *, uefi::handle);
_destroy_child_def _destroy_child;
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_service_binding_h_

View File

@@ -1,37 +0,0 @@
#pragma once
#ifndef _uefi_protos_simple_file_system_h_
#define _uefi_protos_simple_file_system_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
#include <uefi/protos/file.h>
namespace uefi {
namespace protos {
struct simple_file_system;
struct simple_file_system
{
static constexpr uefi::guid guid{ 0x0964e5b22,0x6459,0x11d2,{0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b} };
inline uefi::status open_volume(uefi::protos::file ** root) {
return _open_volume(this, root);
}
uint64_t revision;
protected:
using _open_volume_def = uefi::status (*)(uefi::protos::simple_file_system *, uefi::protos::file **);
_open_volume_def _open_volume;
public:
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_simple_file_system_h_

View File

@@ -1,93 +0,0 @@
#pragma once
#ifndef _uefi_protos_simple_text_output_h_
#define _uefi_protos_simple_text_output_h_
// This file was auto generated by the j6-uefi-headers project. Please see
// https://github.com/justinian/j6-uefi-headers for more information.
#include <uefi/guid.h>
#include <uefi/types.h>
#include <uefi/graphics.h>
namespace uefi {
namespace protos {
struct simple_text_output;
struct simple_text_output
{
static constexpr uefi::guid guid{ 0x387477c2,0x69c7,0x11d2,{0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b} };
inline uefi::status reset(bool extended_verification) {
return _reset(this, extended_verification);
}
inline uefi::status output_string(const wchar_t * string) {
return _output_string(this, string);
}
inline uefi::status test_string(const wchar_t * string) {
return _test_string(this, string);
}
inline uefi::status query_mode(uint64_t mode_number, uint64_t * columns, uint64_t * rows) {
return _query_mode(this, mode_number, columns, rows);
}
inline uefi::status set_mode(uint64_t mode_number) {
return _set_mode(this, mode_number);
}
inline uefi::status set_attribute(uefi::attribute attribute) {
return _set_attribute(this, attribute);
}
inline uefi::status clear_screen() {
return _clear_screen(this);
}
inline uefi::status set_cursor_position(uint64_t column, uint64_t row) {
return _set_cursor_position(this, column, row);
}
inline uefi::status enable_cursor(bool visible) {
return _enable_cursor(this, visible);
}
protected:
using _reset_def = uefi::status (*)(uefi::protos::simple_text_output *, bool);
_reset_def _reset;
using _output_string_def = uefi::status (*)(uefi::protos::simple_text_output *, const wchar_t *);
_output_string_def _output_string;
using _test_string_def = uefi::status (*)(uefi::protos::simple_text_output *, const wchar_t *);
_test_string_def _test_string;
using _query_mode_def = uefi::status (*)(uefi::protos::simple_text_output *, uint64_t, uint64_t *, uint64_t *);
_query_mode_def _query_mode;
using _set_mode_def = uefi::status (*)(uefi::protos::simple_text_output *, uint64_t);
_set_mode_def _set_mode;
using _set_attribute_def = uefi::status (*)(uefi::protos::simple_text_output *, uefi::attribute);
_set_attribute_def _set_attribute;
using _clear_screen_def = uefi::status (*)(uefi::protos::simple_text_output *);
_clear_screen_def _clear_screen;
using _set_cursor_position_def = uefi::status (*)(uefi::protos::simple_text_output *, uint64_t, uint64_t);
_set_cursor_position_def _set_cursor_position;
using _enable_cursor_def = uefi::status (*)(uefi::protos::simple_text_output *, bool);
_enable_cursor_def _enable_cursor;
public:
uefi::text_output_mode * mode;
};
} // namespace protos
} // namespace uefi
#endif // _uefi_protos_simple_text_output_h_

View File

@@ -1,52 +0,0 @@
#pragma once
#ifndef _uefi_runtime_services_h_
#define _uefi_runtime_services_h_
// This Source Code Form is part of the j6-uefi-headers project and is subject
// to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
#include <stdint.h>
#include <uefi/tables.h>
namespace uefi {
namespace rs_impl {
using convert_pointer = uefi::status (*)(uint64_t, void **);
using set_virtual_address_map = uefi::status (*)(size_t, size_t, uint32_t, memory_descriptor *);
}
struct runtime_services {
static constexpr uint64_t signature = 0x56524553544e5552ull;
table_header header;
// Time Services
void *get_time;
void *set_time;
void *get_wakeup_time;
void *set_wakeup_time;
// Virtual Memory Services
rs_impl::set_virtual_address_map set_virtual_address_map;
rs_impl::convert_pointer convert_pointer;
// Variable Services
void *get_variable;
void *get_next_variable_name;
void *set_variable;
// Miscellaneous Services
void *get_next_high_monotonic_count;
void *reset_system;
// UEFI 2.0 Capsule Services
void *update_capsule;
void *query_capsule_capabilities;
// Miscellaneous UEFI 2.0 Service
void *query_variable_info;
};
} // namespace uefi
#endif

View File

@@ -1,73 +0,0 @@
#pragma once
#ifndef _uefi_tables_h_
#define _uefi_tables_h_
// This Source Code Form is part of the j6-uefi-headers project and is subject
// to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
#include <stdint.h>
#include <uefi/guid.h>
#include <uefi/types.h>
namespace uefi {
struct runtime_services;
struct boot_services;
namespace protos {
struct simple_text_input;
struct simple_text_output;
}
struct table_header
{
uint64_t signature;
uint32_t revision;
uint32_t header_size;
uint32_t crc32;
uint32_t reserved;
};
struct configuration_table
{
guid vendor_guid;
void *vendor_table;
};
struct system_table
{
table_header header;
char16_t *firmware_vendor;
uint32_t firmware_revision;
handle console_in_handle;
protos::simple_text_input *con_in;
handle console_out_handle;
protos::simple_text_output *con_out;
handle standard_error_handle;
protos::simple_text_output *std_err;
runtime_services *runtime_services;
boot_services *boot_services;
unsigned int number_of_table_entries;
configuration_table *configuration_table;
};
constexpr uint32_t make_system_table_revision(int major, int minor) {
return (major << 16) | minor;
}
constexpr uint64_t system_table_signature = 0x5453595320494249ull;
constexpr uint32_t system_table_revision = make_system_table_revision(2, 70);
constexpr uint32_t specification_revision = system_table_revision;
namespace vendor_guids {
constexpr guid acpi1{ 0xeb9d2d30,0x2d88,0x11d3,{0x9a,0x16,0x00,0x90,0x27,0x3f,0xc1,0x4d} };
constexpr guid acpi2{ 0x8868e871,0xe4f1,0x11d3,{0xbc,0x22,0x00,0x80,0xc7,0x3c,0x88,0x81} };
} // namespace vendor_guids
} // namespace uefi
#endif

157
external/uefi/types.h vendored
View File

@@ -1,157 +0,0 @@
#pragma once
#ifndef _uefi_types_h_
#define _uefi_types_h_
// This Source Code Form is part of the j6-uefi-headers project and is subject
// to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
// not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
#include <stdint.h>
namespace uefi {
using handle = void *;
//
// Error and status code definitions
//
constexpr uint64_t error_bit = 0x8000000000000000ull;
constexpr uint64_t make_error(uint64_t e) { return e|error_bit; }
enum class status : uint64_t
{
success = 0,
#define STATUS_WARNING(name, num) name = num,
#define STATUS_ERROR(name, num) name = make_error(num),
#include "uefi/errors.inc"
#undef STATUS_WARNING
#undef STATUS_ERROR
};
inline bool is_error(status s) { return static_cast<uint64_t>(s) & error_bit; }
inline bool is_warning(status s) { return !is_error(s) && s != status::success; }
//
// Time defitions
//
struct time
{
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t _pad0;
uint32_t nanosecond;
int16_t time_zone;
uint8_t daylight;
uint8_t _pad1;
};
//
// Memory and allocation defitions
//
enum class memory_type : uint32_t
{
reserved,
loader_code,
loader_data,
boot_services_code,
boot_services_data,
runtime_services_code,
runtime_services_data,
conventional_memory,
unusable_memory,
acpi_reclaim_memory,
acpi_memory_nvs,
memory_mapped_io,
memory_mapped_io_port_space,
pal_code,
persistent_memory,
max_memory_type
};
enum class allocate_type : uint32_t
{
any_pages,
max_address,
address
};
struct memory_descriptor
{
memory_type type;
uintptr_t physical_start;
uintptr_t virtual_start;
uint64_t number_of_pages;
uint64_t attribute;
};
//
// Event handling defitions
//
using event = void *;
enum class evt : uint32_t
{
notify_wait = 0x00000100,
notify_signal = 0x00000200,
signal_exit_boot_services = 0x00000201,
signal_virtual_address_change = 0x60000202,
runtime = 0x40000000,
timer = 0x80000000
};
enum class tpl : uint64_t
{
application = 4,
callback = 8,
notify = 16,
high_level = 31
};
using event_notify = void (*)(event, void*);
//
// File IO defitions
//
struct file_io_token
{
event event;
status status;
uint64_t buffer_size;
void *buffer;
};
enum class file_mode : uint64_t
{
read = 0x0000000000000001ull,
write = 0x0000000000000002ull,
create = 0x8000000000000000ull
};
enum class file_attr : uint64_t
{
none = 0,
read_only = 0x0000000000000001ull,
hidden = 0x0000000000000002ull,
system = 0x0000000000000004ull,
reserved = 0x0000000000000008ull,
directory = 0x0000000000000010ull,
archive = 0x0000000000000020ull
};
} // namespace uefi
#endif

View File

@@ -6,98 +6,102 @@ modules:
output: jsix.elf
target: host
deps:
- cpu
- elf
- initrd
- kutil
- vdso
includes:
- src/kernel
source:
- src/kernel/crti.s
- src/kernel/apic.cpp
- src/kernel/assert.cpp
- src/kernel/boot.s
- src/kernel/clock.cpp
- src/kernel/console.cpp
- src/kernel/cpprt.cpp
- src/kernel/cpu.cpp
- src/kernel/debug.cpp
- src/kernel/debug.s
- src/kernel/device_manager.cpp
- src/kernel/font.cpp
- src/kernel/frame_allocator.cpp
- src/kernel/fs/gpt.cpp
- src/kernel/gdt.cpp
- src/kernel/gdt.s
- src/kernel/hpet.cpp
- src/kernel/interrupts.cpp
- src/kernel/interrupts.s
- src/kernel/io.cpp
- src/kernel/loader.s
- src/kernel/log.cpp
- src/kernel/main.cpp
- src/kernel/memory_bootstrap.cpp
- src/kernel/msr.cpp
- src/kernel/objects/channel.cpp
- src/kernel/objects/endpoint.cpp
- src/kernel/objects/handle.cpp
- src/kernel/objects/kobject.cpp
- src/kernel/objects/thread.cpp
- src/kernel/objects/process.cpp
- src/kernel/objects/system.cpp
- src/kernel/objects/vm_area.cpp
- src/kernel/page_table.cpp
- src/kernel/page_tree.cpp
- src/kernel/page_manager.cpp
- src/kernel/pci.cpp
- src/kernel/process.cpp
- src/kernel/scheduler.cpp
- src/kernel/screen.cpp
- src/kernel/serial.cpp
- src/kernel/symbol_table.cpp
- src/kernel/syscall.cpp
- src/kernel/syscall.s
- src/kernel/syscalls/channel.cpp
- src/kernel/syscalls/endpoint.cpp
- src/kernel/syscalls/object.cpp
- src/kernel/syscalls/process.cpp
- src/kernel/syscalls/system.cpp
- src/kernel/syscalls/thread.cpp
- src/kernel/syscalls/vm_area.cpp
- src/kernel/task.s
- src/kernel/vm_space.cpp
- src/kernel/crtn.s
boot:
kind: exe
target: boot
output: boot.efi
deps:
- cpu
output: boot.elf
source:
- src/boot/main.cpp
- src/boot/crt0.s
- src/boot/console.cpp
- src/boot/error.cpp
- src/boot/fs.cpp
- src/boot/hardware.cpp
- src/boot/guids.cpp
- src/boot/loader.cpp
- src/boot/main.cpp
- src/boot/memory.cpp
- src/boot/paging.cpp
- src/boot/status.cpp
- src/boot/support.cpp
- src/boot/reloc.cpp
- src/boot/utility.cpp
vdso:
kind: exe
target: host
output: libvdso.so
extra:
- src/arch/x86_64/vdso.ld
source:
- src/vdso/syscalls.cpp
- src/vdso/overrides.cpp
nulldrv:
kind: exe
target: user
output: nulldrv.elf
deps:
- libc
output: nulldrv
source:
- src/drivers/nulldrv/io.cpp
- src/drivers/nulldrv/main.cpp
- src/drivers/nulldrv/serial.cpp
- src/drivers/nulldrv/main.s
fb:
kind: exe
target: user
output: fb.elf
elf:
kind: lib
output: libelf.a
deps:
- libc
- kutil
includes:
- src/libraries/elf/include
source:
- src/drivers/fb/font.cpp
- src/drivers/fb/main.cpp
- src/drivers/fb/screen.cpp
- src/drivers/fb/scrollback.cpp
- src/libraries/elf/elf.cpp
initrd:
kind: lib
output: libinitrd.a
deps:
- kutil
includes:
- src/libraries/initrd/include
source:
- src/libraries/initrd/initrd.cpp
kutil:
kind: lib
@@ -111,202 +115,17 @@ modules:
- src/libraries/kutil/logger.cpp
- src/libraries/kutil/memory.cpp
- src/libraries/kutil/printf.c
- src/libraries/kutil/vm_space.cpp
cpu:
kind: lib
output: libcpu.a
includes:
- src/libraries/cpu/include
source:
- src/libraries/cpu/cpu.cpp
j6:
kind: lib
output: libj6.a
includes:
- src/libraries/j6/include
target: user
source:
- src/libraries/j6/syscalls.s
libc:
kind: lib
output: libc.a
includes:
- src/libraries/libc/include
makerd:
kind: exe
target: native
output: makerd
deps:
- j6
target: user
defines:
- DISABLE_SSE
- LACKS_UNISTD_H
- LACKS_FCNTL_H
- LACKS_SYS_PARAM_H
- LACKS_SYS_MMAN_H
- LACKS_SCHED_H
- LACKS_STRINGS_H
- HAVE_MMAP=0
#- LACKS_STRING_H
#- LACKS_ERRNO_H
#- LACKS_STDLIB_H
#- LACKS_TIME_H
- initrd
source:
- src/libraries/libc/arch/x86_64/_Exit.s
- src/libraries/libc/arch/x86_64/crt0.s
- src/libraries/libc/arch/x86_64/init_libc.c
- src/libraries/libc/ctype/isalnum.c
- src/libraries/libc/ctype/isalpha.c
- src/libraries/libc/ctype/isblank.c
- src/libraries/libc/ctype/iscntrl.c
- src/libraries/libc/ctype/isdigit.c
- src/libraries/libc/ctype/isgraph.c
- src/libraries/libc/ctype/islower.c
- src/libraries/libc/ctype/isprint.c
- src/libraries/libc/ctype/ispunct.c
- src/libraries/libc/ctype/isspace.c
- src/libraries/libc/ctype/isupper.c
- src/libraries/libc/ctype/isxdigit.c
- src/libraries/libc/ctype/tolower.c
- src/libraries/libc/ctype/toupper.c
- src/libraries/libc/inttypes/imaxabs.c
- src/libraries/libc/inttypes/imaxdiv.c
- src/libraries/libc/inttypes/strtoimax.c
- src/libraries/libc/inttypes/strtoumax.c
- src/libraries/libc/locale/localeconv.c
- src/libraries/libc/locale/setlocale.c
- src/libraries/libc/j6libc/assert.c
- src/libraries/libc/j6libc/errno.c
- src/libraries/libc/j6libc/allocpages.c
- src/libraries/libc/j6libc/atomax.c
- src/libraries/libc/j6libc/closeall.c
- src/libraries/libc/j6libc/close.c
- src/libraries/libc/j6libc/digits.c
- src/libraries/libc/j6libc/filemode.c
- src/libraries/libc/j6libc/fillbuffer.c
- src/libraries/libc/j6libc/flushbuffer.c
- src/libraries/libc/j6libc/is_leap.c
- src/libraries/libc/j6libc/load_lc_collate.c
- src/libraries/libc/j6libc/load_lc_ctype.c
- src/libraries/libc/j6libc/load_lc_messages.c
- src/libraries/libc/j6libc/load_lc_monetary.c
- src/libraries/libc/j6libc/load_lc_numeric.c
- src/libraries/libc/j6libc/load_lc_time.c
- src/libraries/libc/j6libc/load_lines.c
- src/libraries/libc/j6libc/open.c
- src/libraries/libc/j6libc/prepread.c
- src/libraries/libc/j6libc/prepwrite.c
- src/libraries/libc/j6libc/print.c
- src/libraries/libc/j6libc/rename.c
- src/libraries/libc/j6libc/scan.c
- src/libraries/libc/j6libc/seed.c
- src/libraries/libc/j6libc/seek.c
- src/libraries/libc/j6libc/stdinit.c
- src/libraries/libc/j6libc/strtox_main.c
- src/libraries/libc/j6libc/strtox_prelim.c
- src/libraries/libc/j6libc/sbrk.c
- src/libraries/libc/signal/raise.c
- src/libraries/libc/signal/signal.c
- src/libraries/libc/stdio/clearerr.c
- src/libraries/libc/stdio/fclose.c
- src/libraries/libc/stdio/feof.c
- src/libraries/libc/stdio/ferror.c
- src/libraries/libc/stdio/fflush.c
- src/libraries/libc/stdio/fgetc.c
- src/libraries/libc/stdio/fgetpos.c
- src/libraries/libc/stdio/fgets.c
- src/libraries/libc/stdio/fopen.c
- src/libraries/libc/stdio/fprintf.c
- src/libraries/libc/stdio/fputc.c
- src/libraries/libc/stdio/fputs.c
- src/libraries/libc/stdio/fread.c
- src/libraries/libc/stdio/freopen.c
- src/libraries/libc/stdio/fscanf.c
- src/libraries/libc/stdio/fseek.c
- src/libraries/libc/stdio/fsetpos.c
- src/libraries/libc/stdio/ftell.c
- src/libraries/libc/stdio/fwrite.c
- src/libraries/libc/stdio/getc.c
- src/libraries/libc/stdio/getchar.c
- src/libraries/libc/stdio/perror.c
- src/libraries/libc/stdio/printf.c
- src/libraries/libc/stdio/putc.c
- src/libraries/libc/stdio/putchar.c
- src/libraries/libc/stdio/puts.c
- src/libraries/libc/stdio/remove.c
- src/libraries/libc/stdio/rename.c
- src/libraries/libc/stdio/rewind.c
- src/libraries/libc/stdio/scanf.c
- src/libraries/libc/stdio/setbuf.c
- src/libraries/libc/stdio/setvbuf.c
- src/libraries/libc/stdio/snprintf.c
- src/libraries/libc/stdio/sprintf.c
- src/libraries/libc/stdio/sscanf.c
- src/libraries/libc/stdio/tmpfile.c
- src/libraries/libc/stdio/tmpnam.c
- src/libraries/libc/stdio/ungetc.c
- src/libraries/libc/stdio/vfprintf.c
- src/libraries/libc/stdio/vfscanf.c
- src/libraries/libc/stdio/vprintf.c
- src/libraries/libc/stdio/vscanf.c
- src/libraries/libc/stdio/vsnprintf.c
- src/libraries/libc/stdio/vsprintf.c
- src/libraries/libc/stdio/vsscanf.c
- src/libraries/libc/stdlib/abort.c
- src/libraries/libc/stdlib/abs.c
- src/libraries/libc/stdlib/atexit.c
- src/libraries/libc/stdlib/atoi.c
- src/libraries/libc/stdlib/atol.c
- src/libraries/libc/stdlib/atoll.c
- src/libraries/libc/stdlib/bsearch.c
- src/libraries/libc/stdlib/div.c
- src/libraries/libc/stdlib/exit.c
- src/libraries/libc/stdlib/_Exit.c
- src/libraries/libc/stdlib/getenv.c
- src/libraries/libc/stdlib/labs.c
- src/libraries/libc/stdlib/ldiv.c
- src/libraries/libc/stdlib/llabs.c
- src/libraries/libc/stdlib/lldiv.c
- src/libraries/libc/stdlib/malloc.c
- src/libraries/libc/stdlib/qsort.c
- src/libraries/libc/stdlib/rand.c
- src/libraries/libc/stdlib/srand.c
- src/libraries/libc/stdlib/strtol.c
- src/libraries/libc/stdlib/strtoll.c
- src/libraries/libc/stdlib/strtoul.c
- src/libraries/libc/stdlib/strtoull.c
- src/libraries/libc/stdlib/system.c
- src/libraries/libc/string/memchr.c
- src/libraries/libc/string/memcmp.c
- src/libraries/libc/string/memcpy.c
- src/libraries/libc/string/memmove.c
- src/libraries/libc/string/memset.c
- src/libraries/libc/string/strcat.c
- src/libraries/libc/string/strchr.c
- src/libraries/libc/string/strcmp.c
- src/libraries/libc/string/strcoll.c
- src/libraries/libc/string/strcpy.c
- src/libraries/libc/string/strcspn.c
- src/libraries/libc/string/strerror.c
- src/libraries/libc/string/strlen.c
- src/libraries/libc/string/strncat.c
- src/libraries/libc/string/strncmp.c
- src/libraries/libc/string/strncpy.c
- src/libraries/libc/string/strpbrk.c
- src/libraries/libc/string/strrchr.c
- src/libraries/libc/string/strspn.c
- src/libraries/libc/string/strstr.c
- src/libraries/libc/string/strtok.c
- src/libraries/libc/string/strxfrm.c
- src/libraries/libc/time/asctime.c
- src/libraries/libc/time/clock.c
- src/libraries/libc/time/ctime.c
- src/libraries/libc/time/difftime.c
- src/libraries/libc/time/gmtime.c
- src/libraries/libc/time/localtime.c
- src/libraries/libc/time/mktime.c
- src/libraries/libc/time/strftime.c
- src/libraries/libc/time/time.c
- src/libraries/libc/time/timespec_get.c
- src/tools/makerd/entry.cpp
- src/tools/makerd/main.cpp
tests:
kind: exe
@@ -315,14 +134,12 @@ modules:
deps:
- kutil
source:
- src/tests/address_manager.cpp
- src/tests/constexpr_hash.cpp
- src/tests/linked_list.cpp
- src/tests/logger.cpp
- src/tests/heap_allocator.cpp
- src/tests/main.cpp
- src/tests/map.cpp
- src/tests/vector.cpp
overlays:
- url: https://f000.backblazeb2.com/file/jsix-os/sysroot-llvm8-20190706.tar.bz2
path: sysroot

View File

@@ -87,3 +87,46 @@ which is also released under the terms of the MIT license:
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
## GNU-EFI
jsix's UEFI bootloader initially used [GNU-EFI][], and still uses one file (the
linker script for the bootloader) from that project. GNU-EFI claims to be
released under the BSD license. Again, I could not find its specific license
file, so I am reproducing a generic 3-clause BSD license (the most restrictive,
so as not to assume any extra rights that may not actually be granted) for it
here:
[GNU-EFI]: https://gnu-efi.sourceforge.net
> Copyright (c) Nigel Croxon
>
> Redistribution and use in source and binary forms, with or without
> modification, are permitted provided that the following conditions are met:
>
> 1. Redistributions of source code must retain the above copyright notice, this
> list of conditions and the following disclaimer.
>
> 2. Redistributions in binary form must reproduce the above copyright notice,
> this list of conditions and the following disclaimer in the documentation
> and/or other materials provided with the distribution.
>
> 3. Neither the name of the copyright holder nor the names of its contributors
> may be used to endorse or promote products derived from this software
> without specific prior written permission.
>
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
> ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
> WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
> FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
> CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## Intel EFI Application Toolkit
jsix's UEFI loader uses code from Intel's EFI Application toolkit. Relevant
code includes license statements at the top of each file.

21
qemu.sh
View File

@@ -3,30 +3,19 @@
build="$(dirname $0)/build"
assets="$(dirname $0)/assets"
debug=""
debugtarget="${build}/jsix.elf"
flash_name="ovmf_vars"
gfx="-nographic"
vga="-vga none"
kvm=""
cpu="Broadwell,+pdpe1gb"
for arg in $@; do
case "${arg}" in
--debugboot)
debug="-s -S"
debugtarget="${build}/boot/boot.efi"
flash_name="ovmf_vars_d"
;;
--debug)
debug="-s -S"
debug="-s"
flash_name="ovmf_vars_d"
;;
--gfx)
gfx=""
vga=""
;;
--vga)
vga=""
;;
--kvm)
kvm="-enable-kvm"
@@ -48,10 +37,8 @@ fi
if [[ -n $TMUX ]]; then
if [[ -n $debug ]]; then
tmux split-window -h "gdb ${debugtarget}" &
tmux split-window "gdb ${build}/jsix.elf" &
else
tmux split-window -h -l 80 "sleep 1; telnet localhost 45455" &
tmux last-pane
tmux split-window -l 10 "sleep 1; telnet localhost 45454" &
fi
elif [[ $DESKTOP_SESSION = "i3" ]]; then
@@ -68,8 +55,6 @@ exec qemu-system-x86_64 \
-drive "format=raw,file=${build}/jsix.img" \
-device "isa-debug-exit,iobase=0xf4,iosize=0x04" \
-monitor telnet:localhost:45454,server,nowait \
-serial stdio \
-serial telnet:localhost:45455,server,nowait \
-smp 4 \
-m 512 \
-d mmu,int,guest_errors \
@@ -77,4 +62,4 @@ exec qemu-system-x86_64 \
-cpu "${cpu}" \
-M q35 \
-no-reboot \
$gfx $vga $kvm $debug
$gfx $kvm $debug

View File

@@ -1,75 +0,0 @@
#!/usr/bin/env python3
#
# Generate the jsix style symbol table. The format in memory of this table
# is as follows:
#
# <num_entires> : 8 bytes
# <index> : 16 * N bytes
# <name data> : variable
#
# Each index entry has the format
# <symbol address> : 8 bytes
# <offset of name> : 8 bytes
#
# Name offsets are from the start of the symbol table as a whole. (ie,
# where <num_entries> is located.)
def parse_syms(infile):
"""Take the output of the `nm` command, and parse it into a tuple
representing the symbols in the text segment of the binary. Returns
a list of (address, symbol_name)."""
from cxxfilt import demangle, InvalidName
syms = []
for line in sys.stdin:
addr, t, mangled = line.split()
if t not in "tTvVwW": continue
try:
name = demangle(mangled)
except InvalidName:
continue
addr = int(addr, base=16)
syms.append((addr, name))
return sorted(syms)
def write_table(syms, outfile):
"""Write the given symbol table as generated by parse_syms()
to the outfile, index first, and then name character data."""
import struct
outfile.write(struct.pack("@Q", len(syms)))
index_pos = outfile.tell()
outfile.seek(struct.calcsize("@QQ") * len(syms), 1)
nul = b'\0'
positions = {}
for s in syms:
addr, name = s
positions[addr] = outfile.tell()
data = name.encode('utf-8')
outfile.write(name.encode('utf-8'))
outfile.write(nul)
outfile.seek(index_pos)
for s in syms:
addr = s[0]
pos = positions[addr]
outfile.write(struct.pack("@QQ", addr, pos))
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <output>")
sys.exit(1)
outfile = open(sys.argv[1], "wb")
write_table(parse_syms(sys.stdin), outfile)

View File

@@ -1,75 +0,0 @@
_MAGIC = (0x72, 0xb5, 0x4a, 0x86)
_VERSION = 0
class PSF2:
from collections import namedtuple
Header = namedtuple("PSF2Header",
["version", "offset", "flags", "count", "charsize", "height", "width"])
def __init__(self, filename, header, data):
self.__filename = filename
self.__header = header
self.__data = data
data = property(lambda self: self.__data)
header = property(lambda self: self.__header)
count = property(lambda self: self.__header.count)
charsize = property(lambda self: self.__header.charsize)
dimension = property(lambda self: (self.__header.width, self.__header.height))
filename = property(lambda self: self.__filename)
@classmethod
def load(cls, filename):
from os.path import basename
from struct import unpack_from
data = open(filename, 'rb').read()
fmt = "BBBBIIIIIII"
values = unpack_from(fmt, data)
if values[:len(_MAGIC)] != _MAGIC:
raise Exception("Bad magic number in header")
header = PSF2.Header(*values[len(_MAGIC):])
if header.version != _VERSION:
raise Exception(f"Bad version {header.version} in header")
return cls(basename(filename), header, data)
class Glyph:
__slots__ = ['index', 'data']
def __init__(self, i, data):
self.index = i
self.data = data
def __index__(self):
return self.index
def empty(self):
return not bool([b for b in self.data if b != 0])
def description(self):
c = chr(self.index)
if c.isprintable():
return "Glyph {:02x}: '{}'".format(self.index, c)
else:
return "Glyph {:02x}".format(self.index)
def __getitem__(self, i):
c = self.__header.charsize
n = i * c + self.__header.offset
return PSF2.Glyph(i, self.__data[n:n+c])
class __iter:
__slots__ = ['font', 'n']
def __init__(self, font):
self.font = font
self.n = 0
def __next__(self):
if self.n < self.font.count:
glyph = self.font[self.n]
self.n += 1
return glyph
else:
raise StopIteration
def __iter__(self):
return PSF2.__iter(self)

34
scripts/parse_font.py Executable file → Normal file
View File

@@ -1,6 +1,21 @@
#!/usr/bin/env python3
from fontpsf import PSF2
MAGIC = (0x72, 0xb5, 0x4a, 0x86)
from collections import namedtuple
PSF2 = namedtuple("PSF2", ["version", "offset", "flags", "count", "charsize", "height", "width"])
def read_header(data):
from struct import unpack_from, calcsize
fmt = "BBBBIIIIIII"
values = unpack_from(fmt, data)
if values[:len(MAGIC)] != MAGIC:
raise Exception("Bad magic number in header")
return PSF2(*values[len(MAGIC):])
def print_glyph(header, data):
bw = (header.width + 7) // 8
@@ -13,15 +28,16 @@ def print_glyph(header, data):
def display_font(filename):
font = PSF2.load(filename)
print(font.header)
data = open(filename, 'rb').read()
for glyph in font:
if glyph.empty():
print("{}: BLANK".format(glyph.description()))
else:
print("{}:".format(glyph.description()))
print_glyph(font.header, glyph.data)
header = read_header(data)
print(header)
c = header.charsize
for i in range(0, header.count):
n = i * c + header.offset
print("Glyph {}:".format(i))
print_glyph(header, data[n:n+c])
if __name__ == "__main__":

View File

@@ -1,27 +0,0 @@
#!/usr/bin/env python3
from fontpsf import PSF2
def print_header(filename):
font = PSF2.load(filename)
print("#pragma once")
print(f"// This file was autogenerated by psf_to_cpp.py from {font.filename}\n")
print(f"const uint8_t font_glyph_size = {font.charsize};")
print(f"const uint8_t font_glyph_width = {font.dimension[0]};")
print(f"const uint8_t font_glyph_height = {font.dimension[1]};")
print(f"const uint16_t font_glyph_count = {font.count};\n")
print('const uint8_t font_glyph_data[] = {')
for glyph in font:
print(" ", "".join([f"0x{b:02x}," for b in glyph.data]), end="")
print(" // {}".format(glyph.description()))
print("};")
if __name__ == "__main__":
import sys
for filename in sys.argv[1:]:
print_header(filename)

View File

@@ -28,7 +28,6 @@ warnflags = $
-Wno-unused-result $
-Wno-deprecated-declarations $
-Wno-unused-function $
-Wno-address-of-packed-member $
-Werror
ccflags = $
@@ -44,14 +43,14 @@ ccflags = $
$warnflags
asflags = $
-I${srcroot}/src/include $
-DVERSION_MAJOR={{ version_major }} $
-DVERSION_MINOR={{ version_minor }} $
-DVERSION_PATCH={{ version_patch }} $
-DVERSION_GITSHA=0x{{ version_sha }} $
-I${srcroot}/src/include
-DVERSION_GITSHA=0x{{ version_sha }}
cflags = -std=c11
cxxflags = -std=c++17
cxxflags = -std=c++14
libs =
rule c
@@ -68,7 +67,7 @@ rule dump_c_run
description = Dumping C arguments for $target
command = $
echo "#!/bin/bash" > $out; $
echo '$cc $ccflags $cflags $$*' >> $out; $
echo '$cc $ccflags $cflags $$*' > $out; $
chmod a+x $out
rule cpp
@@ -85,7 +84,7 @@ rule dump_cpp_run
description = Dumping C++ arguments for $target
command = $
echo "#!/bin/bash" > $out; $
echo '$cc $cxxflags $ccflags $$*' >> $out; $
echo '$cc $cxxflags $ccflags $$*' > $out; $
chmod a+x $out
rule s
@@ -119,9 +118,9 @@ rule dump
description = Dumping decompiled $name
command = objdump -DSC -M intel $in > $out
rule makest
description = Making symbol table
command = nm $in | ${srcroot}/scripts/build_symbol_table.py $out
rule makerd
description = Making init ramdisk
command = $builddir/native/makerd $in $out
rule makeefi
description = Converting $name
@@ -187,18 +186,13 @@ build $builddir/fatroot/jsix.elf : cp $builddir/jsix.elf
build $builddir/fatroot/efi/boot/bootx64.efi : cp $builddir/boot/boot.efi
name = bootloader to FAT image
build $builddir/fatroot/nulldrv.elf : cp $builddir/user/nulldrv.elf
name = null driver to FAT image
build $builddir/fatroot/fb.elf : cp $builddir/user/fb.elf
name = fb driver to FAT image
build ${builddir}/fatroot/symbol_table.dat : makest ${builddir}/jsix.elf
build $builddir/fatroot/initrd.img : makerd ${srcroot}/assets/initrd.toml | $
${builddir}/host/libvdso.so $
${builddir}/native/makerd $
${builddir}/user/nulldrv
build $builddir/jsix.img : makefat | $
$builddir/fatroot/symbol_table.dat $
$builddir/fatroot/nulldrv.elf $
$builddir/fatroot/fb.elf $
$builddir/fatroot/initrd.img $
$builddir/fatroot/jsix.elf $
$builddir/fatroot/efi/boot/bootx64.efi
name = jsix.img

View File

@@ -3,10 +3,23 @@
{{ super() }}
ccflags = $ccflags $
-g3 $
-DKERNEL_FILENAME=L\"jsix.elf\" $
-I${srcroot}/external/include $
-I${srcroot}/external/include/X64
-DGNU_EFI_USE_MS_ABI $
-DHAVE_USE_MS_ABI $
-DEFI_DEBUG=0 $
-DEFI_DEBUG_CLEAR_MEMORY=0 $
-DBOOTLOADER_DEBUG
ldflags = $ldflags $
-T ${srcroot}/src/arch/x86_64/boot.ld $
-shared
{% endblock %}
{% block extra %}
build $builddir/boot.efi : makeefi ${builddir}/{{ module.output }}
name = boot.efi
{% endblock %}

View File

@@ -5,7 +5,6 @@
asflags = $asflags -I${srcroot}/src/kernel/
libs = $libs
ldflags = $ldflags -T ${srcroot}/src/arch/x86_64/kernel.ld
ccflags = $ccflags -I${srcroot}/external
{% endblock %}

View File

@@ -0,0 +1,9 @@
{% extends "exe.default.j2" %}
{% block variables %}
{{ super() }}
ccflags = $ccflags -fPIC -mcmodel=large
ldflags = $ldflags -shared -znotext -T ${srcroot}/src/arch/x86_64/vdso.ld
{% endblock %}
# vim: ft=ninja et ts=4 sts=4 sw=4

View File

@@ -3,7 +3,7 @@
{% block binaries %}
cc = clang
cxx = clang++
ld = clang++
ld = ld
ar = ar
nasm = nasm
objcopy = objcopy
@@ -12,25 +12,27 @@ objcopy = objcopy
{% block variables %}
ccflags = $ccflags $
-I $srcroot/external $
--target=x86_64-unknown-windows $
-ggdb $
-nostdlib $
-ffreestanding $
-nodefaultlibs $
-fno-builtin $
-mno-sse $
-fno-omit-frame-pointer $
-mno-red-zone $
-fshort-wchar $
-fno-omit-frame-pointer $
-ggdb
-D__ELF__ $
-fPIC
cxxflags = $cxxflags $
-fno-rtti $
-fno-exceptions
-fno-exceptions $
-fno-rtti $
ldflags = $ldflags $
--target=x86_64-unknown-windows $
-g $
-nostdlib $
-Wl,-entry:efi_main $
-Wl,-subsystem:efi_application $
-fuse-ld=lld-link $
-g
-Bsymbolic $
-nostartfiles
{% endblock %}

View File

@@ -22,10 +22,5 @@ build ${builddir}/cpp.defs : dump_cpp_defs | {{ buildfile }}
build ${builddir}/c.run : dump_c_run | {{ buildfile }}
build ${builddir}/cpp.run : dump_cpp_run | {{ buildfile }}
default ${builddir}/c.defs
default ${builddir}/cpp.defs
default ${builddir}/c.run
default ${builddir}/cpp.run
# vim: ft=ninja et ts=4 sts=4 sw=4

View File

@@ -24,7 +24,6 @@ ccflags = $ccflags $
-D__ELF__ $
-D__JSIX__ $
-isystem${srcroot}/sysroot/include $
-isystem${srcroot}/src/libraries/libc/include $
--sysroot="${srcroot}/sysroot"
cxxflags = $cxxflags $

View File

@@ -23,7 +23,6 @@ ccflags = $ccflags $
-D__ELF__ $
-D__JSIX__ $
-isystem${srcroot}/sysroot/include $
-isystem${srcroot}/src/libraries/libc/include $
--sysroot="${srcroot}/sysroot"
cxxflags = $cxxflags $
@@ -39,6 +38,9 @@ ldflags = $ldflags $
--sysroot="${srcroot}/sysroot" $
-L "${srcroot}/sysroot/lib" $
libs = $libs $
-lc
{% endblock %}
# vim: ft=ninja et ts=4 sts=4 sw=4

79
src/arch/x86_64/boot.ld Normal file
View File

@@ -0,0 +1,79 @@
/* Linker script originally from GNU-EFI project
* https://sourceforge.net/p/gnu-efi/
*/
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SECTIONS
{
. = 0;
ImageBase = .;
/* .hash and/or .gnu.hash MUST come first! */
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
. = ALIGN(4096);
.eh_frame :
{
*(.eh_frame)
}
. = ALIGN(4096);
.text :
{
_text = .;
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
. = ALIGN(16);
}
_etext = .;
_text_size = . - _text;
. = ALIGN(4096);
.reloc :
{
*(.reloc)
}
. = ALIGN(4096);
.data :
{
_data = .;
*(.rodata*)
*(.got.plt)
*(.got)
*(.data*)
*(.sdata)
/* the EFI loader doesn't seem to like a .bss section, so we stick
it all into .data: */
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
*(.rel.local)
}
.note.gnu.build-id : { *(.note.gnu.build-id) }
_edata = .;
_data_size = . - _etext;
. = ALIGN(4096);
.dynamic : { *(.dynamic) }
. = ALIGN(4096);
.rela :
{
*(.rela.data*)
*(.rela.got)
*(.rela.stab)
}
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
. = ALIGN(4096);
.ignored.reloc :
{
*(.rela.reloc)
*(.eh_frame)
*(.note.GNU-stack)
}
.comment 0 : { *(.comment) }
}

View File

@@ -1,7 +1,8 @@
ENTRY(_kernel_start)
ENTRY(_start)
SECTIONS
{
. = 0xFFFF800000000000;
OFFSET = 0xFFFFFF0000000000;
. = OFFSET + 0x100000;
.header : {
__header_start = .;
@@ -19,12 +20,6 @@ SECTIONS
*(.rodata)
}
.ctors : ALIGN(8) {
__ctors = .;
KEEP(*(.ctors))
__ctors_end = .;
}
.bss ALIGN(4096) : {
__bss_start = .;
*(.bss)

73
src/arch/x86_64/vdso.ld Normal file
View File

@@ -0,0 +1,73 @@
PHDRS {
headers PT_PHDR FLAGS(4) FILEHDR PHDRS ;
rodata PT_LOAD FLAGS(4) ;
text PT_LOAD FLAGS(5) ;
dynamic PT_DYNAMIC FLAGS(4) ;
note PT_NOTE ;
eh_frame PT_GNU_EH_FRAME ;
}
SECTIONS {
. = SIZEOF_HEADERS;
/DISCARD/ : {
*(.got*)
*(.plt*)
*(.note.*)
*(.hash*)
*(.debug*)
}
.illegal.relocations : {
*(.rel*)
}
.illegal.writeable : {
*(.data*)
*(.bss*)
}
.rodata : {
*(.rodata*)
} :rodata
.dynamic : {
*(.dynamic)
} :dynamic
.dynsym : {
*(.dynsym*)
} :rodata :dynamic
.dynstr : {
*(.dynstr*)
} :rodata :dynamic
.gnu.hash : {
*(.gnu.hash*)
} :rodata
.eh_frame_hdr : {
__eh_frame_start = .;
KEEP(*(.eh_frame))
__eh_frame_end = .;
KEEP(*(.eh_frame_hdr))
} :eh_frame
.shstrtab : {
*(.shstrtab)
}
.text ALIGN(0x1000) : {
*(.text*)
*(.init*)
*(.fini*)
. = ALIGN(0x1000);
} :text
ASSERT(SIZEOF(.illegal.relocations) == 0,
"Code has introduced relocations into the VDSO")
ASSERT(SIZEOF(.illegal.writeable) == 0,
"Code has introduced writeable data into the VDSO")
}

View File

@@ -1,152 +1,94 @@
#include <stddef.h>
#include <stdint.h>
#include <uefi/types.h>
#include <uefi/graphics.h>
#include <uefi/protos/graphics_output.h>
#include "console.h"
#include "error.h"
#ifndef GIT_VERSION_WIDE
#define GIT_VERSION_WIDE L"no version"
#endif
namespace boot {
#include "guids.h"
#include "utility.h"
size_t ROWS = 0;
size_t COLS = 0;
console *console::s_console = nullptr;
static EFI_SIMPLE_TEXT_OUT_PROTOCOL *m_out = 0;
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'};
static size_t
wstrlen(const wchar_t *s)
console::console(EFI_SYSTEM_TABLE *system_table) :
m_rows(0),
m_cols(0),
m_out(nullptr)
{
size_t count = 0;
while (s && *s++) count++;
return count;
}
console::console(uefi::boot_services *bs, uefi::protos::simple_text_output *out) :
m_rows {0},
m_cols {0},
m_out {out},
m_fb {0, 0}
{
pick_mode(bs);
try_or_raise(
m_out->query_mode(m_out->mode->mode, &m_cols, &m_rows),
L"Failed to get text output mode.");
try_or_raise(
m_out->clear_screen(),
L"Failed to clear screen");
m_out->set_attribute(uefi::attribute::light_cyan);
m_out->output_string(L"jsix loader ");
m_out->set_attribute(uefi::attribute::light_magenta);
m_out->output_string(GIT_VERSION_WIDE);
m_out->set_attribute(uefi::attribute::light_gray);
m_out->output_string(L" booting...\r\n");
if (m_fb.type != kernel::args::fb_type::none) {
wchar_t const * type = nullptr;
switch (m_fb.type) {
case kernel::args::fb_type::rgb8:
type = L"rgb8";
break;
case kernel::args::fb_type::bgr8:
type = L"bgr8";
break;
default:
type = L"unknown";
}
printf(L"Found framebuffer: %dx%d[%d] type %s @0x%x\r\n",
m_fb.horizontal, m_fb.vertical, m_fb.scanline, type, m_fb.phys_addr);
} else {
printf(L"No framebuffer found.\r\n");
}
s_console = this;
m_boot = system_table->BootServices;
m_out = system_table->ConOut;
}
void
console::pick_mode(uefi::boot_services *bs)
EFI_STATUS
console::initialize(const wchar_t *version)
{
uefi::status status;
uefi::protos::graphics_output *gfx_out_proto;
uefi::guid guid = uefi::protos::graphics_output::guid;
EFI_STATUS status;
m_fb.type = kernel::args::fb_type::none;
// Might not find a video device at all, so ignore not found errors
status = pick_mode();
if (status != EFI_NOT_FOUND)
CHECK_EFI_STATUS_OR_FAIL(status);
uefi::status has_gop = bs->locate_protocol(&guid, nullptr,
(void **)&gfx_out_proto);
status = m_out->QueryMode(m_out, m_out->Mode->Mode, &m_cols, &m_rows);
CHECK_EFI_STATUS_OR_RETURN(status, "QueryMode");
if (has_gop != uefi::status::success)
// No video output found, skip it
return;
status = m_out->ClearScreen(m_out);
CHECK_EFI_STATUS_OR_RETURN(status, "ClearScreen");
const uint32_t modes = gfx_out_proto->mode->max_mode;
uint32_t best = gfx_out_proto->mode->mode;
m_out->SetAttribute(m_out, EFI_LIGHTCYAN);
m_out->OutputString(m_out, (wchar_t *)L"jsix loader ");
uefi::graphics_output_mode_info *info =
(uefi::graphics_output_mode_info *)gfx_out_proto->mode;
m_out->SetAttribute(m_out, EFI_LIGHTMAGENTA);
m_out->OutputString(m_out, (wchar_t *)version);
uint32_t res = info->horizontal_resolution * info->vertical_resolution;
int pixmode = static_cast<int>(info->pixel_format);
m_out->SetAttribute(m_out, EFI_LIGHTGRAY);
m_out->OutputString(m_out, (wchar_t *)L" booting...\r\n\n");
return status;
}
EFI_STATUS
console::pick_mode()
{
EFI_STATUS status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gfx_out_proto;
status = m_boot->LocateProtocol(&guid_gfx_out, NULL, (void **)&gfx_out_proto);
CHECK_EFI_STATUS_OR_RETURN(status, "LocateProtocol gfx");
const uint32_t modes = gfx_out_proto->Mode->MaxMode;
uint32_t best = gfx_out_proto->Mode->Mode;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info =
(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *)gfx_out_proto->Mode;
uint32_t res = info->HorizontalResolution * info->VerticalResolution;
int is_fb = info->PixelFormat != PixelBltOnly;
for (uint32_t i = 0; i < modes; ++i) {
size_t size = 0;
try_or_raise(
gfx_out_proto->query_mode(i, &size, &info),
L"Failed to find a graphics mode the driver claimed to support");
status = gfx_out_proto->QueryMode(gfx_out_proto, i, &size, &info);
CHECK_EFI_STATUS_OR_RETURN(status, "QueryMode");
#ifdef MAX_HRES
if (info->horizontal_resolution > MAX_HRES) continue;
if (info->HorizontalResolution > MAX_HRES) continue;
#endif
const uint32_t new_res = info->horizontal_resolution * info->vertical_resolution;
int new_pixmode = static_cast<int>(info->pixel_format);
const uint32_t new_res = info->HorizontalResolution * info->VerticalResolution;
const int new_is_fb = info->PixelFormat == PixelBltOnly;
if (new_pixmode <= pixmode && new_res >= res) {
if (new_is_fb > is_fb && new_res >= res) {
best = i;
res = new_res;
pixmode = new_pixmode;
}
}
try_or_raise(
gfx_out_proto->set_mode(best),
L"Failed to set graphics mode");
if (pixmode <= static_cast<int>(uefi::pixel_format::bgr8)) {
m_fb.phys_addr = gfx_out_proto->mode->frame_buffer_base;
m_fb.size = gfx_out_proto->mode->frame_buffer_size;
m_fb.vertical = gfx_out_proto->mode->info->vertical_resolution;
m_fb.horizontal = gfx_out_proto->mode->info->horizontal_resolution;
m_fb.scanline = gfx_out_proto->mode->info->pixels_per_scanline;
switch (gfx_out_proto->mode->info->pixel_format) {
case uefi::pixel_format::rgb8:
m_fb.type = kernel::args::fb_type::rgb8;
break;
case uefi::pixel_format::bgr8:
m_fb.type = kernel::args::fb_type::bgr8;
break;
default:
m_fb.type = kernel::args::fb_type::none;
}
}
status = gfx_out_proto->SetMode(gfx_out_proto, best);
CHECK_EFI_STATUS_OR_RETURN(status, "SetMode %d/%d", best, modes);
return EFI_SUCCESS;
}
size_t
@@ -155,11 +97,11 @@ console::print_hex(uint32_t n) const
wchar_t buffer[9];
wchar_t *p = buffer;
for (int i = 7; i >= 0; --i) {
uint8_t nibble = (n >> (i*4)) & 0xf;
uint8_t nibble = (n & (0xf << (i*4))) >> (i*4);
*p++ = digits[nibble];
}
*p = 0;
m_out->output_string(buffer);
m_out->OutputString(m_out, buffer);
return 8;
}
@@ -169,11 +111,11 @@ console::print_long_hex(uint64_t n) const
wchar_t buffer[17];
wchar_t *p = buffer;
for (int i = 15; i >= 0; --i) {
uint8_t nibble = (n >> (i*4)) & 0xf;
uint8_t nibble = (n & (0xf << (i*4))) >> (i*4);
*p++ = digits[nibble];
}
*p = 0;
m_out->output_string(buffer);
m_out->OutputString(m_out, buffer);
return 16;
}
@@ -188,7 +130,7 @@ console::print_dec(uint32_t n) const
n /= 10;
} while (n != 0);
m_out->output_string(++p);
m_out->OutputString(m_out, ++p);
return 10 - (p - buffer);
}
@@ -203,7 +145,7 @@ console::print_long_dec(uint64_t n) const
n /= 10;
} while (n != 0);
m_out->output_string(++p);
m_out->OutputString(m_out, ++p);
return 20 - (p - buffer);
}
@@ -223,14 +165,14 @@ console::vprintf(const wchar_t *fmt, va_list args) const
}
*w = 0;
m_out->output_string(buffer);
m_out->OutputString(m_out, buffer);
w = buffer;
r++; // chomp the %
switch (*r++) {
case L'%':
m_out->output_string(const_cast<wchar_t*>(L"%"));
m_out->OutputString(m_out, const_cast<wchar_t*>(L"%"));
count++;
break;
@@ -247,7 +189,7 @@ console::vprintf(const wchar_t *fmt, va_list args) const
{
wchar_t *s = va_arg(args, wchar_t*);
count += wstrlen(s);
m_out->output_string(s);
m_out->OutputString(m_out, s);
}
break;
@@ -273,7 +215,7 @@ console::vprintf(const wchar_t *fmt, va_list args) const
}
*w = 0;
m_out->output_string(buffer);
m_out->OutputString(m_out, buffer);
return count;
}
@@ -301,4 +243,91 @@ console::print(const wchar_t *fmt, ...)
return result;
}
} // namespace boot
void
console::status_begin(const wchar_t *message) const
{
m_out->SetAttribute(m_out, EFI_LIGHTGRAY);
m_out->OutputString(m_out, (wchar_t *)message);
}
void
console::status_ok() const
{
m_out->SetAttribute(m_out, EFI_LIGHTGRAY);
m_out->OutputString(m_out, (wchar_t *)L"[");
m_out->SetAttribute(m_out, EFI_GREEN);
m_out->OutputString(m_out, (wchar_t *)L" ok ");
m_out->SetAttribute(m_out, EFI_LIGHTGRAY);
m_out->OutputString(m_out, (wchar_t *)L"]\r\n");
}
void
console::status_fail(const wchar_t *error) const
{
m_out->SetAttribute(m_out, EFI_LIGHTGRAY);
m_out->OutputString(m_out, (wchar_t *)L"[");
m_out->SetAttribute(m_out, EFI_LIGHTRED);
m_out->OutputString(m_out, (wchar_t *)L"failed");
m_out->SetAttribute(m_out, EFI_LIGHTGRAY);
m_out->OutputString(m_out, (wchar_t *)L"]\r\n");
m_out->SetAttribute(m_out, EFI_RED);
m_out->OutputString(m_out, (wchar_t *)error);
m_out->SetAttribute(m_out, EFI_LIGHTGRAY);
m_out->OutputString(m_out, (wchar_t *)L"\r\n");
}
EFI_STATUS
con_get_framebuffer(
EFI_BOOT_SERVICES *bootsvc,
void **buffer,
size_t *buffer_size,
uint32_t *hres,
uint32_t *vres,
uint32_t *rmask,
uint32_t *gmask,
uint32_t *bmask)
{
EFI_STATUS status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
status = bootsvc->LocateProtocol(&guid_gfx_out, NULL, (void **)&gop);
if (status != EFI_NOT_FOUND) {
CHECK_EFI_STATUS_OR_RETURN(status, "LocateProtocol gfx");
*buffer = (void *)gop->Mode->FrameBufferBase;
*buffer_size = gop->Mode->FrameBufferSize;
*hres = gop->Mode->Info->HorizontalResolution;
*vres = gop->Mode->Info->VerticalResolution;
switch (gop->Mode->Info->PixelFormat) {
case PixelRedGreenBlueReserved8BitPerColor:
*rmask = 0x0000ff;
*gmask = 0x00ff00;
*bmask = 0xff0000;
return EFI_SUCCESS;
case PixelBlueGreenRedReserved8BitPerColor:
*bmask = 0x0000ff;
*gmask = 0x00ff00;
*rmask = 0xff0000;
return EFI_SUCCESS;
case PixelBitMask:
*rmask = gop->Mode->Info->PixelInformation.RedMask;
*gmask = gop->Mode->Info->PixelInformation.GreenMask;
*bmask = gop->Mode->Info->PixelInformation.BlueMask;
return EFI_SUCCESS;
default:
// Not a framebuffer, fall through to zeroing out
// values below.
break;
}
}
*buffer = NULL;
*buffer_size = *hres = *vres = 0;
*rmask = *gmask = *bmask = 0;
return EFI_SUCCESS;
}

View File

@@ -1,22 +1,18 @@
/// \file console.h
/// Text output handler
#pragma once
#include <stdarg.h>
#include <stddef.h>
#include <uefi/boot_services.h>
#include <uefi/protos/simple_text_output.h>
#include "kernel_args.h"
#include "types.h"
#include <efi/efi.h>
namespace boot {
/// Object providing basic output functionality to the UEFI console
class console
{
public:
using framebuffer = kernel::args::framebuffer;
console(EFI_SYSTEM_TABLE *system_table);
console(uefi::boot_services *bs, uefi::protos::simple_text_output *out);
EFI_STATUS initialize(const wchar_t *version);
void status_begin(const wchar_t *message) const;
void status_fail(const wchar_t *error) const;
void status_ok() const;
size_t print_hex(uint32_t n) const;
size_t print_dec(uint32_t n) const;
@@ -24,22 +20,27 @@ public:
size_t print_long_dec(uint64_t n) const;
size_t printf(const wchar_t *fmt, ...) const;
const framebuffer & fb() const { return m_fb; };
static console & get() { return *s_console; }
static const console & get() { return *s_console; }
static size_t print(const wchar_t *fmt, ...);
private:
friend class status_line;
void pick_mode(uefi::boot_services *bs);
EFI_STATUS pick_mode();
size_t vprintf(const wchar_t *fmt, va_list args) const;
size_t m_rows, m_cols;
uefi::protos::simple_text_output *m_out;
framebuffer m_fb;
EFI_BOOT_SERVICES *m_boot;
EFI_SIMPLE_TEXT_OUT_PROTOCOL *m_out;
static console *s_console;
};
} // namespace boot
EFI_STATUS
con_get_framebuffer(
EFI_BOOT_SERVICES *bootsvc,
void **buffer,
size_t *buffer_size,
uint32_t *hres,
uint32_t *vres,
uint32_t *rmask,
uint32_t *gmask,
uint32_t *bmask);

85
src/boot/crt0.s Normal file
View File

@@ -0,0 +1,85 @@
; crt0-efi-x86_64.S - x86_64 EFI startup code.
; Copyright (C) 1999 Hewlett-Packard Co.
; Contributed by David Mosberger <davidm@hpl.hp.com>.
; Copyright (C) 2005 Intel Co.
; Contributed by Fenghua Yu <fenghua.yu@intel.com>.
;
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
;
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above
; copyright notice, this list of conditions and the following
; disclaimer in the documentation and/or other materials
; provided with the distribution.
; * Neither the name of Hewlett-Packard Co. nor the names of its
; contributors may be used to endorse or promote products derived
; from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
; BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
; OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
; TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
; THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
; SUCH DAMAGE.
;
; 2018-05-05 Converted to NASM syntax by Justin C. Miller
extern ImageBase
extern _DYNAMIC
extern _relocate
extern efi_main
section .text
align 4
global _start
_start:
sub rsp, 8
push rcx
push rdx
; These are already in RDI/RSI from EFI calling us, right? -justin
;lea rdi, [ImageBase]
;lea rsi, [_DYNAMIC]
pop rcx
pop rdx
push rcx
push rdx
call _relocate
pop rdi
pop rsi
call efi_main
add rsp, 8
.exit:
ret
; hand-craft a dummy .reloc section so EFI knows it's a relocatable executable:
section .data
dummy:
dd 0
%define IMAGE_REL_ABSOLUTE 0
section .reloc
label1:
dd 0 ; Page RVA
dd 10 ; Block Size (2*4+2)
dw (IMAGE_REL_ABSOLUTE<<12) + 0 ; reloc for dummy

View File

@@ -1,32 +1,46 @@
/// \file elf.h
/// Definitions and related constants for ELF64 structures
#pragma once
#include <stdint.h>
namespace boot {
namespace elf {
#ifndef ELF_VERSION
#define ELF_VERSION 1
#endif
constexpr uint8_t version = 1;
constexpr uint8_t word_size = 2;
constexpr uint8_t endianness = 1;
constexpr uint8_t os_abi = 0;
constexpr uint16_t machine = 0x3e;
#ifndef ELF_WORDSIZE
#define ELF_WORDSIZE 2
#endif
const unsigned PT_LOAD = 1;
const unsigned ST_PROGBITS = 1;
const unsigned ST_NOBITS = 8;
const unsigned long SHF_ALLOC = 0x2;
#ifndef ELF_ENDIAN
#define ELF_ENDIAN 1
#endif
struct header
#ifndef ELF_OSABI
#define ELF_OSABI 0
#endif
#ifndef ELF_MACHINE
#define ELF_MACHINE 0x3e
#endif
const unsigned ELF_PT_LOAD = 1;
const unsigned ELF_ST_PROGBITS = 1;
const unsigned ELF_ST_NOBITS = 8;
const unsigned long ELF_SHF_ALLOC = 0x2;
struct elf_ident
{
char magic[4];
uint8_t word_size;
uint8_t endianness;
uint8_t header_version;
uint8_t version;
uint8_t os_abi;
uint64_t reserved;
} __attribute__ ((packed));
struct elf_header
{
struct elf_ident ident;
uint16_t type;
uint16_t machine;
@@ -50,7 +64,7 @@ struct header
uint16_t sh_str_idx;
} __attribute__ ((packed));
struct program_header
struct elf_program_header
{
uint32_t type;
uint32_t flags;
@@ -65,7 +79,7 @@ struct program_header
uint64_t align;
} __attribute__ ((packed));
struct section_header
struct elf_section_header
{
uint32_t name;
uint32_t type;
@@ -78,6 +92,3 @@ struct section_header
uint64_t align;
uint64_t entry_size;
} __attribute__ ((packed));
} // namespace elf
} // namespace boot

View File

@@ -1,70 +0,0 @@
#include "error.h"
#include "console.h"
#include "kernel_args.h"
#include "status.h"
namespace boot {
namespace error {
struct error_code_desc {
uefi::status code;
const wchar_t *name;
};
struct error_code_desc error_table[] = {
#define STATUS_ERROR(name, num) { uefi::status::name, L#name },
#define STATUS_WARNING(name, num) { uefi::status::name, L#name },
#include "uefi/errors.inc"
#undef STATUS_ERROR
#undef STATUS_WARNING
{ uefi::status::success, nullptr }
};
const wchar_t *
message(uefi::status status)
{
int32_t i = -1;
while (error_table[++i].name != nullptr) {
if (error_table[i].code == status) return error_table[i].name;
}
if (uefi::is_error(status))
return L"Unknown Error";
else
return L"Unknown Warning";
}
[[ noreturn ]] static void
cpu_assert(uefi::status s, const wchar_t *message, size_t line)
{
asm volatile (
"movq $0xeeeeeeebadbadbad, %%r8;"
"movq %0, %%r9;"
"movq %1, %%r10;"
"movq %2, %%r11;"
"movq $0, %%rdx;"
"divq %%rdx;"
:
: "r"((uint64_t)s), "r"(message), "r"(line)
: "rax", "rdx", "r8", "r9", "r10");
while (1) asm("hlt");
}
[[ noreturn ]] void
raise(uefi::status status, const wchar_t *message, size_t line)
{
if(status_line::fail(message, status))
while (1) asm("hlt");
else
cpu_assert(status, message, line);
}
} // namespace error
} // namespace boot
void debug_break()
{
volatile int go = 0;
while (!go);
}

View File

@@ -1,33 +0,0 @@
/// \file error.h
/// Error handling definitions
#pragma once
#include <stddef.h>
#include <uefi/types.h>
namespace boot {
class console;
namespace error {
/// Halt or exit the program with the given error status/message
[[ noreturn ]] void raise(uefi::status status, const wchar_t *message, size_t line = 0);
const wchar_t * message(uefi::status status);
} // namespace error
} // namespace boot
/// Debugging psuedo-breakpoint.
void debug_break();
/// Helper macro to raise an error if an operation fails.
/// \arg s An expression evaluating to a UEFI status
/// \arg m The error message to use on failure
#define try_or_raise(s, m) \
do { \
uefi::status _s = (s); \
if (uefi::is_error(_s)) ::boot::error::raise(_s, (m), __LINE__); \
} while(0)

View File

@@ -1,114 +0,0 @@
#include <uefi/types.h>
#include <uefi/protos/file.h>
#include <uefi/protos/file_info.h>
#include <uefi/protos/loaded_image.h>
#include <uefi/protos/simple_file_system.h>
#include "fs.h"
#include "console.h"
#include "error.h"
#include "memory.h"
#include "status.h"
namespace boot {
namespace fs {
file::file(uefi::protos::file *f, uefi::boot_services *bs) :
m_file(f),
m_bs(bs)
{
}
file::file(file &o) :
m_file(o.m_file),
m_bs(o.m_bs)
{
o.m_file = nullptr;
}
file::file(file &&o) :
m_file(o.m_file),
m_bs(o.m_bs)
{
o.m_file = nullptr;
}
file::~file()
{
if (m_file)
m_file->close();
}
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, m_bs);
}
buffer
file::load(uefi::memory_type mem_type)
{
uint8_t info_buf[sizeof(uefi::protos::file_info) + 100];
size_t size = sizeof(info_buf);
uefi::guid info_guid = uefi::protos::file_info::guid;
try_or_raise(
m_file->get_info(&info_guid, &size, &info_buf),
L"Could not get file info");
uefi::protos::file_info *info =
reinterpret_cast<uefi::protos::file_info*>(&info_buf);
size_t pages = memory::bytes_to_pages(info->file_size);
void *data = nullptr;
try_or_raise(
m_bs->allocate_pages(
uefi::allocate_type::any_pages,
mem_type, pages, &data),
L"Could not allocate pages to load file");
size = info->file_size;
try_or_raise(
m_file->read(&size, data),
L"Could not read from file");
return { .size = size, .data = data };
}
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, bs);
}
} // namespace fs
} // namespace boot

View File

@@ -1,45 +0,0 @@
/// \file fs.h
/// Definitions for dealing with UEFI's disk access functions
#pragma once
#include <uefi/types.h>
#include <uefi/boot_services.h>
#include <uefi/protos/file.h>
#include "types.h"
namespace boot {
namespace fs {
/// A file or directory in a filesystem.
class file
{
public:
file(file &&o);
file(file &o);
~file();
/// Open another file or directory, relative to this one.
/// \arg path Relative path to the target file from this one
file open(const wchar_t *path);
/// Load the contents of this file into memory.
/// \arg mem_type The UEFI memory type to use for allocation
/// \returns A buffer describing the loaded memory. The
/// memory will be page-aligned.
buffer load(uefi::memory_type mem_type = uefi::memory_type::loader_data);
private:
friend file get_boot_volume(uefi::handle, uefi::boot_services*);
file(uefi::protos::file *f, uefi::boot_services *bs);
uefi::protos::file *m_file;
uefi::boot_services *m_bs;
};
/// Get the filesystem this loader was loaded from.
/// \returns A `file` object representing the root directory of the volume
file get_boot_volume(uefi::handle image, uefi::boot_services *bs);
} // namespace fs
} // namespace boot

13
src/boot/guids.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include "guids.h"
#define GUID(dw, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, name) \
EFI_GUID name __attribute__((section(".rodata"))) = {dw, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}
#include "guids.inc"
#undef GUID
int is_guid(EFI_GUID *a, EFI_GUID *b)
{
uint64_t *ai = (uint64_t *)a;
uint64_t *bi = (uint64_t *)b;
return ai[0] == bi[0] && ai[1] == bi[1];
}

8
src/boot/guids.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
#include <efi/efi.h>
int is_guid(EFI_GUID *a, EFI_GUID *b);
#define GUID(dw, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, name) extern EFI_GUID name
#include "guids.inc"
#undef GUID

11
src/boot/guids.inc Normal file
View File

@@ -0,0 +1,11 @@
GUID(0xeb9d2d30,0x2d88,0x11d3,0x9a,0x16,0x00,0x90,0x27,0x3f,0xc1,0x4d, guid_acpi1);
GUID(0x8868e871,0xe4f1,0x11d3,0xbc,0x22,0x00,0x80,0xc7,0x3c,0x88,0x81, guid_acpi2);
GUID(0x09576e92,0x6d3f,0x11d2,0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b, guid_file_info);
GUID(0x9042a9de,0x23dc,0x4a38,0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a, guid_gfx_out);
GUID(0x964e5b22,0x6459,0x11d2,0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b, guid_simple_filesystem);
GUID(0x09576e91,0x6d3f,0x11d2,0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b, guid_device_path);
GUID(0x8b843e20,0x8132,0x4852,0x90,0xcc,0x55,0x1a,0x4e,0x4a,0x7f,0x1c, guid_device_path_to_text);
GUID(0x10d0669c,0x9ec6,0x4268,0xbc,0x48,0xff,0x74,0x75,0x21,0xfe,0x07, guid_jsix_vendor);
// vim: ft=c

View File

@@ -1,81 +0,0 @@
#include "hardware.h"
#include "console.h"
#include "error.h"
#include "status.h"
namespace boot {
namespace hw {
void *
find_acpi_table(uefi::system_table *st)
{
status_line status(L"Searching for ACPI table");
// Find ACPI tables. Ignore ACPI 1.0 if a 2.0 table is found.
uintptr_t acpi1_table = 0;
for (size_t i = 0; i < st->number_of_table_entries; ++i) {
uefi::configuration_table *table = &st->configuration_table[i];
// If we find an ACPI 2.0 table, return it immediately
if (table->vendor_guid == uefi::vendor_guids::acpi2)
return table->vendor_table;
if (table->vendor_guid == uefi::vendor_guids::acpi1) {
// Mark a v1 table with the LSB high
acpi1_table = reinterpret_cast<uintptr_t>(table->vendor_table);
acpi1_table |= 1;
}
}
if (!acpi1_table) {
error::raise(uefi::status::not_found, L"Could not find ACPI table");
} else if (acpi1_table & 1) {
status_line::warn(L"Only found ACPI 1.0 table");
}
return reinterpret_cast<void*>(acpi1_table);
}
static uint64_t
rdmsr(uint32_t addr)
{
uint32_t low, high;
__asm__ __volatile__ ("rdmsr" : "=a"(low), "=d"(high) : "c"(addr));
return (static_cast<uint64_t>(high) << 32) | low;
}
static void
wrmsr(uint32_t addr, uint64_t value)
{
uint32_t low = value & 0xffffffff;
uint32_t high = value >> 32;
__asm__ __volatile__ ("wrmsr" :: "c"(addr), "a"(low), "d"(high));
}
void
setup_control_regs()
{
uint64_t cr4 = 0;
asm volatile ( "mov %%cr4, %0" : "=r" (cr4) );
cr4 |=
0x000080 | // Enable global pages
0x000200 | // Enable FXSAVE/FXRSTOR
0x010000 | // Enable FSGSBASE
0x020000 | // Enable PCIDs
0;
asm volatile ( "mov %0, %%cr4" :: "r" (cr4) );
// Set up IA32_EFER
constexpr uint32_t IA32_EFER = 0xC0000080;
uint64_t efer = rdmsr(IA32_EFER);
efer |=
0x0001 | // Enable SYSCALL
0x0800 | // Enable NX bit
0;
wrmsr(IA32_EFER, efer);
}
} // namespace hw
} // namespace boot

View File

@@ -1,20 +0,0 @@
/// \file hardware.h
/// Functions and definitions for detecting and dealing with hardware
#pragma once
#include <uefi/tables.h>
namespace boot {
namespace hw {
/// Find the ACPI table in the system configuration tables
/// and return a pointer to it. If only an ACPI 1.0 table is
/// available, the returned pointer will have its least
/// significant bit set to 1.
void * find_acpi_table(uefi::system_table *st);
/// Enable CPU options in CR4 etc for the kernel starting state.
void setup_control_regs();
} // namespace hw
} // namespace boot

View File

@@ -1,117 +1,298 @@
#include <uefi/boot_services.h>
#include <uefi/types.h>
#include "loader.h"
#include "console.h"
#include "elf.h"
#include "error.h"
#include "fs.h"
#include "guids.h"
#include "loader.h"
#include "memory.h"
#include "paging.h"
#include "status.h"
#include "utility.h"
namespace args = kernel::args;
#define PAGE_SIZE 0x1000
namespace boot {
namespace loader {
static wchar_t kernel_name[] = KERNEL_FILENAME;
static wchar_t initrd_name[] = INITRD_FILENAME;
buffer
load_file(
fs::file &disk,
const wchar_t *name,
const wchar_t *path,
uefi::memory_type type)
EFI_STATUS
loader_alloc_aligned(
EFI_BOOT_SERVICES *bootsvc,
EFI_MEMORY_TYPE mem_type,
size_t *length,
void **pages)
{
status_line status(L"Loading file", name);
EFI_STATUS status;
EFI_PHYSICAL_ADDRESS addr;
fs::file file = disk.open(path);
buffer b = file.load(type);
size_t alignment = PAGE_SIZE;
while (alignment < *length)
alignment *= 2;
//console::print(L" Loaded at: 0x%lx, %d bytes\r\n", b.data, b.size);
return b;
}
size_t page_count = alignment / PAGE_SIZE;
*length = alignment;
con_debug(L"Trying to find %d aligned pages for %x", page_count, mem_type);
static bool
is_elfheader_valid(const elf::header *header)
{
return
header->magic[0] == 0x7f &&
header->magic[1] == 'E' &&
header->magic[2] == 'L' &&
header->magic[3] == 'F' &&
header->word_size == elf::word_size &&
header->endianness == elf::endianness &&
header->os_abi == elf::os_abi &&
header->machine == elf::machine &&
header->header_version == elf::version;
}
status = bootsvc->AllocatePages(AllocateAnyPages, mem_type, page_count * 2, &addr);
CHECK_EFI_STATUS_OR_RETURN(status, L"Allocating %d pages for alignment", page_count * 2);
con_debug(L" Found %d pages at %lx", page_count * 2, addr);
void
load_program(
args::program &program,
const wchar_t *name,
buffer data,
uefi::boot_services *bs)
{
status_line status(L"Loading program:", name);
const elf::header *header = reinterpret_cast<const elf::header*>(data.data);
EFI_PHYSICAL_ADDRESS aligned = addr;
aligned = ((aligned - 1) & ~(alignment - 1)) + alignment;
con_debug(L" Aligning %lx to %lx", addr, aligned);
if (data.size < sizeof(elf::header) || !is_elfheader_valid(header))
error::raise(uefi::status::load_error, L"ELF file not valid");
size_t before =
(reinterpret_cast<uint64_t>(aligned) -
reinterpret_cast<uint64_t>(addr)) /
PAGE_SIZE;
uintptr_t prog_base = uintptr_t(-1);
uintptr_t prog_end = 0;
for (int i = 0; i < header->ph_num; ++i) {
ptrdiff_t offset = header->ph_offset + i * header->ph_entsize;
const elf::program_header *pheader =
offset_ptr<elf::program_header>(data.data, offset);
if (pheader->type != elf::PT_LOAD)
continue;
uintptr_t end = pheader->vaddr + pheader->mem_size;
if (pheader->vaddr < prog_base) prog_base = pheader->vaddr;
if (end > prog_end) prog_end = end;
if (before) {
con_debug(L" Freeing %d initial pages", before);
bootsvc->FreePages(addr, before);
}
size_t total_size = prog_end - prog_base;
size_t num_pages = memory::bytes_to_pages(total_size);
void *pages = nullptr;
try_or_raise(
bs->allocate_pages(uefi::allocate_type::any_pages,
uefi::memory_type::loader_data, num_pages, &pages),
L"Failed allocating space for program");
bs->set_mem(pages, total_size, 0);
program.base = prog_base;
program.total_size = total_size;
program.num_sections = 0;
for (int i = 0; i < header->ph_num; ++i) {
ptrdiff_t offset = header->ph_offset + i * header->ph_entsize;
const elf::program_header *pheader =
offset_ptr<elf::program_header>(data.data, offset);
if (pheader->type != elf::PT_LOAD)
continue;
args::program_section &section = program.sections[program.num_sections++];
void *src_start = offset_ptr<void>(data.data, pheader->offset);
void *dest_start = offset_ptr<void>(pages, pheader->vaddr - prog_base);
bs->copy_mem(dest_start, src_start, pheader->file_size);
section.phys_addr = reinterpret_cast<uintptr_t>(dest_start);
section.virt_addr = pheader->vaddr;
section.size = pheader->mem_size;
section.type = static_cast<args::section_flags>(pheader->flags);
size_t after = page_count - before;
if (after) {
EFI_PHYSICAL_ADDRESS end =
reinterpret_cast<EFI_PHYSICAL_ADDRESS>(
reinterpret_cast<uint64_t>(aligned) +
page_count * PAGE_SIZE);
con_debug(L" Freeing %d remaining pages", after);
bootsvc->FreePages(end, after);
}
program.entrypoint = header->entrypoint;
*pages = (void *)aligned;
return EFI_SUCCESS;
}
} // namespace loader
} // namespace boot
EFI_STATUS
loader_alloc_pages(
EFI_BOOT_SERVICES *bootsvc,
EFI_MEMORY_TYPE mem_type,
size_t *length,
void **pages)
{
EFI_STATUS status;
size_t page_count = ((*length - 1) / PAGE_SIZE) + 1;
EFI_PHYSICAL_ADDRESS addr = (EFI_PHYSICAL_ADDRESS)*pages;
con_debug(L"Trying to find %d non-aligned pages for %x at %lx",
page_count, mem_type, addr);
status = bootsvc->AllocatePages(AllocateAddress, mem_type, page_count, &addr);
CHECK_EFI_STATUS_OR_RETURN(status,
L"Allocating %d kernel pages type %x",
page_count, mem_type);
*length = page_count * PAGE_SIZE;
*pages = (void *)addr;
return EFI_SUCCESS;
}
EFI_STATUS
loader_load_initrd(
EFI_BOOT_SERVICES *bootsvc,
EFI_FILE_PROTOCOL *root,
struct loader_data *data)
{
EFI_STATUS status;
EFI_FILE_PROTOCOL *file = NULL;
status = root->Open(root, &file, (wchar_t *)initrd_name, EFI_FILE_MODE_READ,
EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
if (status == EFI_NOT_FOUND)
return status;
CHECK_EFI_STATUS_OR_RETURN(status, L"Opening file %s", initrd_name);
char info[sizeof(EFI_FILE_INFO) + 100];
size_t info_length = sizeof(info);
status = file->GetInfo(file, &guid_file_info, &info_length, info);
CHECK_EFI_STATUS_OR_RETURN(status, L"Getting file info");
data->initrd_length = ((EFI_FILE_INFO *)info)->FileSize;
status = loader_alloc_aligned(
bootsvc,
memtype_initrd,
&data->initrd_length,
&data->initrd);
CHECK_EFI_STATUS_OR_RETURN(status, L"Allocating pages");
status = file->Read(file, &data->initrd_length, data->initrd);
CHECK_EFI_STATUS_OR_RETURN(status, L"Reading file");
status = file->Close(file);
CHECK_EFI_STATUS_OR_RETURN(status, L"Closing file handle");
return EFI_SUCCESS;
}
EFI_STATUS
loader_load_elf(
EFI_BOOT_SERVICES *bootsvc,
EFI_FILE_PROTOCOL *root,
struct loader_data *data)
{
EFI_STATUS status;
con_debug(L"Opening kernel file %s", (wchar_t *)kernel_name);
EFI_FILE_PROTOCOL *file = NULL;
status = root->Open(root, &file, (wchar_t *)kernel_name, EFI_FILE_MODE_READ,
EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
if (status == EFI_NOT_FOUND)
return status;
uint64_t length = 0;
data->kernel = 0;
data->kernel_entry = 0;
data->kernel_length = 0;
CHECK_EFI_STATUS_OR_RETURN(status, L"Opening file %s", kernel_name);
struct elf_header header;
length = sizeof(struct elf_header);
status = file->Read(file, &length, &header);
CHECK_EFI_STATUS_OR_RETURN(status, L"Reading ELF header");
con_debug(L"Read %u bytes of ELF header", length);
if (length < sizeof(struct elf_header))
CHECK_EFI_STATUS_OR_RETURN(EFI_LOAD_ERROR, L"Incomplete read of ELF header");
static const char expected[] = {0x7f, 'E', 'L', 'F'};
for (int i = 0; i < sizeof(expected); ++i) {
if (header.ident.magic[i] != expected[i])
CHECK_EFI_STATUS_OR_RETURN(EFI_LOAD_ERROR, L"Bad ELF magic number");
}
if (header.ident.word_size != ELF_WORDSIZE)
CHECK_EFI_STATUS_OR_RETURN(EFI_LOAD_ERROR, L"ELF load error: 32 bit ELF not supported");
if (header.ph_entsize != sizeof(struct elf_program_header))
CHECK_EFI_STATUS_OR_RETURN(EFI_LOAD_ERROR, L"ELF load error: program header size mismatch");
if (header.ident.version != ELF_VERSION ||
header.version != ELF_VERSION)
CHECK_EFI_STATUS_OR_RETURN(EFI_LOAD_ERROR, L"ELF load error: wrong ELF version");
if (header.ident.endianness != 1 ||
header.ident.os_abi != 0 ||
header.machine != 0x3e)
CHECK_EFI_STATUS_OR_RETURN(EFI_LOAD_ERROR, L"ELF load error: wrong machine architecture");
con_debug(L"ELF is valid, entrypoint %lx", header.entrypoint);
data->kernel_entry = (void *)header.entrypoint;
struct elf_program_header prog_header;
for (int i = 0; i < header.ph_num; ++i) {
status = file->SetPosition(file, header.ph_offset + i * header.ph_entsize);
CHECK_EFI_STATUS_OR_RETURN(status, L"Setting ELF file position");
length = header.ph_entsize;
status = file->Read(file, &length, &prog_header);
CHECK_EFI_STATUS_OR_RETURN(status, L"Reading ELF program header");
if (prog_header.type != ELF_PT_LOAD) continue;
length = prog_header.mem_size;
void *addr = (void *)(prog_header.vaddr - KERNEL_VIRT_ADDRESS);
status = loader_alloc_pages(bootsvc, memtype_kernel, &length, &addr);
CHECK_EFI_STATUS_OR_RETURN(status, L"Allocating kernel pages");
if (data->kernel == 0)
data->kernel = addr;
data->kernel_length = (uint64_t)addr + length - (uint64_t)data->kernel;
}
con_debug(L"Read %d ELF program headers", header.ph_num);
struct elf_section_header sec_header;
for (int i = 0; i < header.sh_num; ++i) {
status = file->SetPosition(file, header.sh_offset + i * header.sh_entsize);
CHECK_EFI_STATUS_OR_RETURN(status, L"Setting ELF file position");
length = header.sh_entsize;
status = file->Read(file, &length, &sec_header);
CHECK_EFI_STATUS_OR_RETURN(status, L"Reading ELF section header");
if ((sec_header.flags & ELF_SHF_ALLOC) == 0) {
continue;
}
void *addr = (void *)(sec_header.addr - KERNEL_VIRT_ADDRESS);
if (sec_header.type == ELF_ST_PROGBITS) {
status = file->SetPosition(file, sec_header.offset);
CHECK_EFI_STATUS_OR_RETURN(status, L"Setting ELF file position");
length = sec_header.size;
status = file->Read(file, &length, addr);
CHECK_EFI_STATUS_OR_RETURN(status, L"Reading file");
} else if (sec_header.type == ELF_ST_NOBITS) {
bootsvc->SetMem(addr, sec_header.size, 0);
}
}
con_debug(L"Read %d ELF section headers", header.ph_num);
status = file->Close(file);
CHECK_EFI_STATUS_OR_RETURN(status, L"Closing file handle");
return EFI_SUCCESS;
}
EFI_STATUS
loader_load_kernel(
EFI_BOOT_SERVICES *bootsvc,
struct loader_data *data)
{
if (data == NULL)
CHECK_EFI_STATUS_OR_RETURN(EFI_INVALID_PARAMETER, L"NULL loader_data");
EFI_STATUS status;
EFI_HANDLE *handles = NULL;
size_t handleCount = 0;
status = bootsvc->LocateHandleBuffer(ByProtocol, &guid_simple_filesystem, NULL, &handleCount, &handles);
CHECK_EFI_STATUS_OR_RETURN(status, L"LocateHandleBuffer");
for (unsigned i = 0; i < handleCount; ++i) {
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fileSystem = NULL;
status = bootsvc->HandleProtocol(handles[i], &guid_simple_filesystem, (void **)&fileSystem);
CHECK_EFI_STATUS_OR_RETURN(status, L"HandleProtocol");
EFI_FILE_PROTOCOL *root = NULL;
status = fileSystem->OpenVolume(fileSystem, &root);
CHECK_EFI_STATUS_OR_RETURN(status, L"OpenVolume");
status = loader_load_elf(bootsvc, root, data);
if (status == EFI_NOT_FOUND)
continue;
CHECK_EFI_STATUS_OR_RETURN(status, L"loader_load_elf: %s", kernel_name);
data->data = (void *)((uint64_t)data->kernel + data->kernel_length);
data->data_length += PAGE_SIZE; // extra page for map growth
status = loader_alloc_aligned(
bootsvc,
memtype_data,
&data->data_length,
&data->data);
CHECK_EFI_STATUS_OR_RETURN(status, L"loader_alloc_aligned: kernel data");
data->initrd = (void *)((uint64_t)data->data + data->data_length);
status = loader_load_initrd(bootsvc, root, data);
CHECK_EFI_STATUS_OR_RETURN(status, L"loader_load_file: %s", initrd_name);
return EFI_SUCCESS;
}
return EFI_NOT_FOUND;
}

View File

@@ -1,41 +1,35 @@
/// \file loader.h
/// Definitions for loading the kernel into memory
#pragma once
#include <efi/efi.h>
#include <stddef.h>
#include <uefi/boot_services.h>
#define PAGE_SIZE 0x1000
#include "kernel_args.h"
#include "memory.h"
#include "types.h"
#ifndef KERNEL_PHYS_ADDRESS
#define KERNEL_PHYS_ADDRESS 0x100000
#endif
namespace boot {
#ifndef KERNEL_VIRT_ADDRESS
#define KERNEL_VIRT_ADDRESS 0xFFFFFF0000000000
#endif
namespace fs { class file; }
#ifndef KERNEL_FILENAME
#define KERNEL_FILENAME L"kernel.elf"
#endif
namespace loader {
#ifndef INITRD_FILENAME
#define INITRD_FILENAME L"initrd.img"
#endif
/// Load a file from disk into memory.
/// \arg disk The opened UEFI filesystem to load from
/// \arg name Name of the module (informational only)
/// \arg path Path on `disk` of the file to load
/// \arg type Memory type to use for allocation
buffer
load_file(
fs::file &disk,
const wchar_t *name,
const wchar_t *path,
uefi::memory_type type = uefi::memory_type::loader_data);
struct loader_data {
void *kernel;
void *kernel_entry;
size_t kernel_length;
/// Parse and load an ELF file in memory into a loaded image.
/// \arg program The program structure to fill
/// \arg data Buffer of the ELF file in memory
/// \arg bs Boot services
void
load_program(
kernel::args::program &program,
const wchar_t *name,
buffer data,
uefi::boot_services *bs);
void *initrd;
size_t initrd_length;
} // namespace loader
} // namespace boot
void *data;
size_t data_length;
};
EFI_STATUS loader_load_kernel(EFI_BOOT_SERVICES *bootsvc, struct loader_data *data);

View File

@@ -1,213 +1,227 @@
#include <uefi/types.h>
#include <uefi/guid.h>
#include <uefi/tables.h>
#include <uefi/protos/simple_text_output.h>
#include <stdalign.h>
#include <stddef.h>
#include <stdint.h>
#include <efi/efi.h>
#include "console.h"
#include "cpu/cpu.h"
#include "error.h"
#include "fs.h"
#include "hardware.h"
#include "guids.h"
#include "kernel_args.h"
#include "loader.h"
#include "memory.h"
#include "paging.h"
#include "status.h"
#include "utility.h"
#include "kernel_args.h"
#ifndef SCRATCH_PAGES
#define SCRATCH_PAGES 64
#endif
namespace kernel {
#include "kernel_memory.h"
}
#ifndef GIT_VERSION_WIDE
#define GIT_VERSION_WIDE L"no version"
#endif
namespace args = kernel::args;
#define KERNEL_HEADER_MAGIC 0x600db007
#define KERNEL_HEADER_VERSION 1
namespace boot {
#pragma pack(push, 1)
struct kernel_header {
uint32_t magic;
uint16_t version;
uint16_t length;
constexpr int max_modules = 5; // Max modules to allocate room for
constexpr int max_programs = 5; // Max programs to allocate room for
struct program_desc
{
const wchar_t *name;
const wchar_t *path;
uint8_t major;
uint8_t minor;
uint16_t patch;
uint32_t gitsha;
};
#pragma pack(pop)
const program_desc program_list[] = {
{L"kernel", L"jsix.elf"},
{L"null driver", L"nulldrv.elf"},
{L"fb driver", L"fb.elf"},
};
using kernel_entry = void (*)(kernel_args *);
/// Change a pointer to point to the higher-half linear-offset version
/// of the address it points to.
template <typename T>
void change_pointer(T *&pointer)
static void
type_to_wchar(wchar_t *into, uint32_t type)
{
pointer = offset_ptr<T>(pointer, kernel::memory::page_offset);
for (int j=0; j<4; ++j)
into[j] = static_cast<wchar_t>(reinterpret_cast<char *>(&type)[j]);
}
/// Allocate space for kernel args. Allocates enough space from pool
/// memory for the args header and the module and program headers.
args::header *
allocate_args_structure(
uefi::boot_services *bs,
size_t max_modules,
size_t max_programs)
{
status_line status {L"Setting up kernel args memory"};
EFI_STATUS
detect_debug_mode(EFI_RUNTIME_SERVICES *run, kernel_args *header) {
wchar_t var_name[] = L"debug";
args::header *args = nullptr;
EFI_STATUS status;
uint8_t debug = 0;
UINTN var_size = sizeof(debug);
size_t args_size =
sizeof(args::header) + // The header itself
max_modules * sizeof(args::module) + // The module structures
max_programs * sizeof(args::program); // The program structures
#ifdef __JSIX_SET_DEBUG_UEFI_VAR__
debug = __JSIX_SET_DEBUG_UEFI_VAR__;
uint32_t attrs =
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS;
status = run->SetVariable(
var_name,
&guid_jsix_vendor,
attrs,
var_size,
&debug);
CHECK_EFI_STATUS_OR_RETURN(status, "detect_debug_mode::SetVariable");
#endif
try_or_raise(
bs->allocate_pool(uefi::memory_type::loader_data, args_size,
reinterpret_cast<void**>(&args)),
L"Could not allocate argument memory");
status = run->GetVariable(
var_name,
&guid_jsix_vendor,
nullptr,
&var_size,
&debug);
CHECK_EFI_STATUS_OR_RETURN(status, "detect_debug_mode::GetVariable");
bs->set_mem(args, args_size, 0);
if (debug)
header->flags |= JSIX_FLAG_DEBUG;
args->modules =
reinterpret_cast<args::module*>(args + 1);
args->num_modules = 0;
args->programs =
reinterpret_cast<args::program*>(args->modules + max_modules);
args->num_programs = 0;
return args;
return EFI_SUCCESS;
}
/// Add a module to the kernel args list
inline void
add_module(args::header *args, args::mod_type type, buffer &data)
extern "C" EFI_STATUS
efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
{
args::module &m = args->modules[args->num_modules++];
m.type = type;
m.location = data.data;
m.size = data.size;
}
EFI_STATUS status;
EFI_BOOT_SERVICES *bootsvc = system_table->BootServices;
EFI_RUNTIME_SERVICES *runsvc = system_table->RuntimeServices;
/// Check that all required cpu features are supported
void
check_cpu_supported()
{
status_line status {L"Checking CPU features"};
console con(system_table);
cpu::cpu_id cpu;
uint64_t missing = cpu.missing();
if (missing) {
#define CPU_FEATURE_OPT(...)
#define CPU_FEATURE_REQ(name, ...) \
if (!cpu.has_feature(cpu::feature::name)) { \
status::fail(L"CPU required feature " L ## #name, uefi::status::unsupported); \
// When checking console initialization, use CHECK_EFI_STATUS_OR_RETURN
// because we can't be sure if the console was fully set up
status = con.initialize(GIT_VERSION_WIDE);
CHECK_EFI_STATUS_OR_RETURN(status, "console::initialize");
// From here on out, we can use CHECK_EFI_STATUS_OR_FAIL instead
memory_init_pointer_fixup(bootsvc, runsvc, SCRATCH_PAGES);
// Find ACPI tables. Ignore ACPI 1.0 if a 2.0 table is found.
//
void *acpi_table = NULL;
for (size_t i=0; i<system_table->NumberOfTableEntries; ++i) {
EFI_CONFIGURATION_TABLE *efi_table = &system_table->ConfigurationTable[i];
if (is_guid(&efi_table->VendorGuid, &guid_acpi2)) {
acpi_table = efi_table->VendorTable;
break;
} else if (is_guid(&efi_table->VendorGuid, &guid_acpi1)) {
// Mark a v1 table with the LSB high
acpi_table = (void *)((intptr_t)efi_table->VendorTable | 0x1);
}
#include "cpu/features.inc"
#undef CPU_FEATURE_REQ
#undef CPU_FEATURE_OPT
error::raise(uefi::status::unsupported, L"CPU not supported");
}
}
/// The main procedure for the portion of the loader that runs while
/// UEFI is still in control of the machine. (ie, while the loader still
/// has access to boot services.
args::header *
uefi_preboot(uefi::handle image, uefi::system_table *st)
{
status_line status {L"Performing UEFI pre-boot"};
uefi::boot_services *bs = st->boot_services;
uefi::runtime_services *rs = st->runtime_services;
memory::init_pointer_fixup(bs, rs);
args::header *args =
allocate_args_structure(bs, max_modules, max_programs);
args->magic = args::magic;
args->version = args::version;
args->runtime_services = rs;
args->acpi_table = hw::find_acpi_table(st);
paging::allocate_tables(args, bs);
memory::mark_pointer_fixup(&args->runtime_services);
fs::file disk = fs::get_boot_volume(image, bs);
buffer symbols = loader::load_file(disk, L"symbol table", L"symbol_table.dat",
uefi::memory_type::loader_data);
add_module(args, args::mod_type::symbol_table, symbols);
for (auto &desc : program_list) {
buffer buf = loader::load_file(disk, desc.name, desc.path);
args::program &program = args->programs[args->num_programs++];
loader::load_program(program, desc.name, buf, bs);
}
return args;
// Compute necessary number of data pages
//
size_t data_length = 0;
status = memory_get_map_length(bootsvc, &data_length);
CHECK_EFI_STATUS_OR_FAIL(status);
size_t header_size = sizeof(kernel_args);
const size_t header_align = alignof(kernel_args);
if (header_size % header_align)
header_size += header_align - (header_size % header_align);
data_length += header_size;
// Load the kernel image from disk and check it
//
console::print(L"Loading kernel into memory...\r\n");
struct loader_data load;
load.data_length = data_length;
status = loader_load_kernel(bootsvc, &load);
CHECK_EFI_STATUS_OR_FAIL(status);
console::print(L" %x image bytes at 0x%x\r\n", load.kernel_length, load.kernel);
console::print(L" %x data bytes at 0x%x\r\n", load.data_length, load.data);
console::print(L" %x initrd bytes at 0x%x\r\n", load.initrd_length, load.initrd);
struct kernel_header *version = (struct kernel_header *)load.kernel;
if (version->magic != KERNEL_HEADER_MAGIC) {
console::print(L" bad magic %x\r\n", version->magic);
CHECK_EFI_STATUS_OR_FAIL(EFI_CRC_ERROR);
}
console::print(L" Kernel version %d.%d.%d %x%s\r\n",
version->major, version->minor, version->patch, version->gitsha & 0x0fffffff,
version->gitsha & 0xf0000000 ? L"*" : L"");
console::print(L" Entrypoint 0x%x\r\n", load.kernel_entry);
kernel_entry kernel_main =
reinterpret_cast<kernel_entry>(load.kernel_entry);
memory_mark_pointer_fixup((void **)&kernel_main);
// Set up the kernel data pages to pass to the kernel
//
struct kernel_args *data_header = (struct kernel_args *)load.data;
memory_mark_pointer_fixup((void **)&data_header);
data_header->magic = DATA_HEADER_MAGIC;
data_header->version = DATA_HEADER_VERSION;
data_header->length = sizeof(struct kernel_args);
data_header->scratch_pages = SCRATCH_PAGES;
data_header->flags = 0;
data_header->initrd = load.initrd;
data_header->initrd_length = load.initrd_length;
memory_mark_pointer_fixup((void **)&data_header->initrd);
data_header->data = load.data;
data_header->data_length = load.data_length;
memory_mark_pointer_fixup((void **)&data_header->data);
data_header->memory_map = (EFI_MEMORY_DESCRIPTOR *)(data_header + 1);
memory_mark_pointer_fixup((void **)&data_header->memory_map);
data_header->runtime = runsvc;
memory_mark_pointer_fixup((void **)&data_header->runtime);
data_header->acpi_table = acpi_table;
memory_mark_pointer_fixup((void **)&data_header->acpi_table);
data_header->_reserved0 = 0;
data_header->_reserved1 = 0;
// Figure out the framebuffer (if any) and add that to the data header
//
status = con_get_framebuffer(
bootsvc,
&data_header->frame_buffer,
&data_header->frame_buffer_length,
&data_header->hres,
&data_header->vres,
&data_header->rmask,
&data_header->gmask,
&data_header->bmask);
CHECK_EFI_STATUS_OR_FAIL(status);
memory_mark_pointer_fixup((void **)&data_header->frame_buffer);
// Save the memory map and tell the firmware we're taking control.
//
struct memory_map map;
map.length = (load.data_length - header_size);
map.entries =
reinterpret_cast<EFI_MEMORY_DESCRIPTOR *>(data_header->memory_map);
status = memory_get_map(bootsvc, &map);
CHECK_EFI_STATUS_OR_FAIL(status);
data_header->memory_map_length = map.length;
data_header->memory_map_desc_size = map.size;
detect_debug_mode(runsvc, data_header);
// bootsvc->Stall(5000000);
status = bootsvc->ExitBootServices(image_handle, map.key);
CHECK_EFI_STATUS_OR_ASSERT(status, 0);
memory_virtualize(runsvc, &map);
// Hand control to the kernel
//
kernel_main(data_header);
return EFI_LOAD_ERROR;
}
memory::efi_mem_map
uefi_exit(args::header *args, uefi::handle image, uefi::boot_services *bs)
{
status_line status {L"Exiting UEFI", nullptr, false};
memory::efi_mem_map map =
memory::build_kernel_mem_map(args, bs);
try_or_raise(
bs->exit_boot_services(image, map.key),
L"Failed to exit boot services");
return map;
}
} // namespace boot
/// The UEFI entrypoint for the loader.
extern "C" uefi::status
efi_main(uefi::handle image, uefi::system_table *st)
{
using namespace boot;
console con(st->boot_services, st->con_out);
check_cpu_supported();
args::header *args = uefi_preboot(image, st);
memory::efi_mem_map map = uefi_exit(args, image, st->boot_services);
args->video = con.fb();
status_bar status {con.fb()}; // Switch to fb status display
// Map the kernel to the appropriate address
args::program &kernel = args->programs[0];
for (auto &section : kernel.sections)
if (section.size)
paging::map_section(args, section);
memory::fix_frame_blocks(args);
kernel::entrypoint kentry =
reinterpret_cast<kernel::entrypoint>(kernel.entrypoint);
status.next();
hw::setup_control_regs();
memory::virtualize(args->pml4, map, st->runtime_services);
status.next();
change_pointer(args->pml4);
status.next();
kentry(args);
debug_break();
return uefi::status::unsupported;
}

View File

@@ -1,384 +1,215 @@
#include <stddef.h>
#include <uefi/types.h>
#include "kernel_memory.h"
#include "console.h"
#include "error.h"
#include "loader.h"
#include "memory.h"
#include "paging.h"
#include "status.h"
#include "utility.h"
namespace boot {
namespace memory {
const EFI_MEMORY_TYPE memtype_kernel = static_cast<EFI_MEMORY_TYPE>(0x80000000);
const EFI_MEMORY_TYPE memtype_data = static_cast<EFI_MEMORY_TYPE>(0x80000001);
const EFI_MEMORY_TYPE memtype_initrd = static_cast<EFI_MEMORY_TYPE>(0x80000002);
const EFI_MEMORY_TYPE memtype_scratch = static_cast<EFI_MEMORY_TYPE>(0x80000003);
using mem_entry = kernel::args::mem_entry;
using mem_type = kernel::args::mem_type;
using frame_block = kernel::args::frame_block;
using kernel::args::frames_per_block;
#define INCREMENT_DESC(p, b) (EFI_MEMORY_DESCRIPTOR*)(((uint8_t*)(p))+(b))
size_t fixup_pointer_index = 0;
void **fixup_pointers[64];
uint64_t *new_pml4 = 0;
static const wchar_t *memory_type_names[] = {
L"reserved memory type",
L"loader code",
L"loader data",
L"boot services code",
L"boot services data",
L"runtime services code",
L"runtime services data",
L"conventional memory",
L"unusable memory",
L"acpi reclaim memory",
L"acpi memory nvs",
L"memory mapped io",
L"memory mapped io port space",
L"pal code",
L"persistent memory"
};
static const wchar_t *kernel_memory_type_names[] = {
L"free",
L"pending",
L"acpi",
L"uefi_runtime",
L"mmio",
L"persistent"
const wchar_t *memory_type_names[] = {
L"EfiReservedMemoryType",
L"EfiLoaderCode",
L"EfiLoaderData",
L"EfiBootServicesCode",
L"EfiBootServicesData",
L"EfiRuntimeServicesCode",
L"EfiRuntimeServicesData",
L"EfiConventionalMemory",
L"EfiUnusableMemory",
L"EfiACPIReclaimMemory",
L"EfiACPIMemoryNVS",
L"EfiMemoryMappedIO",
L"EfiMemoryMappedIOPortSpace",
L"EfiPalCode",
L"EfiPersistentMemory",
};
static const wchar_t *
memory_type_name(uefi::memory_type t)
memory_type_name(UINT32 value)
{
if (t < uefi::memory_type::max_memory_type)
return memory_type_names[static_cast<uint32_t>(t)];
return L"Bad Type Value";
if (value >= (sizeof(memory_type_names) / sizeof(wchar_t *))) {
switch (value) {
case memtype_kernel: return L"Kernel Data";
case memtype_data: return L"Kernel Data";
case memtype_initrd: return L"Initial Ramdisk";
case memtype_scratch: return L"Kernel Scratch Space";
default: return L"Bad Type Value";
}
}
return memory_type_names[value];
}
static const wchar_t *
kernel_memory_type_name(kernel::args::mem_type t)
void EFIAPI
memory_update_marked_addresses(EFI_EVENT UNUSED *event, void *context)
{
return kernel_memory_type_names[static_cast<uint32_t>(t)];
}
void
update_marked_addresses(uefi::event, void *context)
{
uefi::runtime_services *rs =
reinterpret_cast<uefi::runtime_services*>(context);
EFI_RUNTIME_SERVICES *runsvc = (EFI_RUNTIME_SERVICES*)context;
for (size_t i = 0; i < fixup_pointer_index; ++i) {
if (fixup_pointers[i])
rs->convert_pointer(0, fixup_pointers[i]);
runsvc->ConvertPointer(0, fixup_pointers[i]);
}
}
void
init_pointer_fixup(uefi::boot_services *bs, uefi::runtime_services *rs)
EFI_STATUS
memory_init_pointer_fixup(EFI_BOOT_SERVICES *bootsvc, EFI_RUNTIME_SERVICES *runsvc, unsigned scratch_pages)
{
status_line status(L"Initializing pointer virtualization event");
EFI_STATUS status;
EFI_EVENT event;
uefi::event event;
bs->set_mem(&fixup_pointers, sizeof(fixup_pointers), 0);
fixup_pointer_index = 0;
status = bootsvc->CreateEvent(
EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
TPL_CALLBACK,
(EFI_EVENT_NOTIFY)&memory_update_marked_addresses,
runsvc,
&event);
try_or_raise(
bs->create_event(
uefi::evt::signal_virtual_address_change,
uefi::tpl::callback,
(uefi::event_notify)&update_marked_addresses,
rs,
&event),
L"Error creating memory virtualization event");
CHECK_EFI_STATUS_OR_RETURN(status, "Failed to initialize pointer update event.");
// Reserve a page for our replacement PML4, plus some pages for the kernel to use
// as page tables while it gets started.
EFI_PHYSICAL_ADDRESS addr = 0;
status = bootsvc->AllocatePages(AllocateAnyPages, memtype_scratch, scratch_pages, &addr);
CHECK_EFI_STATUS_OR_RETURN(status, "Failed to allocate page table pages.");
new_pml4 = (uint64_t *)addr;
return EFI_SUCCESS;
}
void
mark_pointer_fixup(void **p)
memory_mark_pointer_fixup(void **p)
{
if (fixup_pointer_index == 0) {
const size_t count = sizeof(fixup_pointers) / sizeof(void*);
for (size_t i = 0; i < count; ++i) fixup_pointers[i] = 0;
}
fixup_pointers[fixup_pointer_index++] = p;
}
bool
can_merge(mem_entry &prev, mem_type type, uefi::memory_descriptor *next)
void
copy_desc(EFI_MEMORY_DESCRIPTOR *src, EFI_MEMORY_DESCRIPTOR *dst, size_t len)
{
return
prev.type == type &&
prev.start + (page_size * prev.pages) == next->physical_start &&
prev.attr == (next->attribute & 0xffffffff);
uint8_t *srcb = (uint8_t *)src;
uint8_t *dstb = (uint8_t *)dst;
uint8_t *endb = srcb + len;
while (srcb < endb)
*dstb++ = *srcb++;
}
EFI_STATUS
memory_get_map_length(EFI_BOOT_SERVICES *bootsvc, size_t *size)
{
if (size == NULL)
return EFI_INVALID_PARAMETER;
EFI_STATUS status;
size_t key, desc_size;
uint32_t desc_version;
*size = 0;
status = bootsvc->GetMemoryMap(size, 0, &key, &desc_size, &desc_version);
if (status != EFI_BUFFER_TOO_SMALL) {
CHECK_EFI_STATUS_OR_RETURN(status, "Failed to get memory map size");
}
return EFI_SUCCESS;
}
EFI_STATUS
memory_get_map(EFI_BOOT_SERVICES *bootsvc, struct memory_map *map)
{
EFI_STATUS status;
if (map == NULL)
return EFI_INVALID_PARAMETER;
size_t needs_size = 0;
status = memory_get_map_length(bootsvc, &needs_size);
if (EFI_ERROR(status)) return status;
if (map->length < needs_size)
return EFI_BUFFER_TOO_SMALL;
status = bootsvc->GetMemoryMap(&map->length, map->entries, &map->key, &map->size, &map->version);
CHECK_EFI_STATUS_OR_RETURN(status, "Failed to load memory map");
return EFI_SUCCESS;
}
EFI_STATUS
memory_dump_map(struct memory_map *map)
{
if (map == NULL)
return EFI_INVALID_PARAMETER;
const size_t count = map->length / map->size;
console::print(L"Memory map:\n");
console::print(L"\t Descriptor Count: %d (%d bytes)\n", count, map->length);
console::print(L"\t Descriptor Size: %d bytes\n", map->size);
console::print(L"\t Type offset: %d\n\n", offsetof(EFI_MEMORY_DESCRIPTOR, Type));
EFI_MEMORY_DESCRIPTOR *end = INCREMENT_DESC(map->entries, map->length);
EFI_MEMORY_DESCRIPTOR *d = map->entries;
while (d < end) {
int runtime = (d->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME;
console::print(L"%s%s ", memory_type_name(d->Type), runtime ? L"*" : L" ");
console::print(L"%lx ", d->PhysicalStart);
console::print(L"%lx ", d->VirtualStart);
console::print(L"[%4d]\n", d->NumberOfPages);
d = INCREMENT_DESC(d, map->size);
}
return EFI_SUCCESS;
}
void
get_uefi_mappings(efi_mem_map &map, uefi::boot_services *bs)
memory_virtualize(EFI_RUNTIME_SERVICES *runsvc, struct memory_map *map)
{
size_t length = map.total;
uefi::status status = bs->get_memory_map(
&length, map.entries, &map.key, &map.size, &map.version);
map.length = length;
memory_mark_pointer_fixup((void **)&runsvc);
memory_mark_pointer_fixup((void **)&map);
if (status == uefi::status::success)
return;
// Get the pointer to the start of PML4
uint64_t* cr3 = 0;
__asm__ __volatile__ ( "mov %%cr3, %0" : "=r" (cr3) );
if (status != uefi::status::buffer_too_small)
error::raise(status, L"Error getting memory map size");
// PML4 is indexed with bits 39:47 of the virtual address
uint64_t offset = (KERNEL_VIRT_ADDRESS >> 39) & 0x1ff;
if (map.entries) {
try_or_raise(
bs->free_pool(reinterpret_cast<void*>(map.entries)),
L"Freeing previous memory map space");
// Double map the lower half pages that are present into the higher half
for (unsigned i = 0; i < offset; ++i) {
if (cr3[i] & 0x1)
new_pml4[i] = new_pml4[offset+i] = cr3[i];
else
new_pml4[i] = new_pml4[offset+i] = 0;
}
map.total = length + 10*map.size;
// Write our new PML4 pointer back to CR3
__asm__ __volatile__ ( "mov %0, %%cr3" :: "r" (new_pml4) );
try_or_raise(
bs->allocate_pool(
uefi::memory_type::loader_data, map.total,
reinterpret_cast<void**>(&map.entries)),
L"Allocating space for memory map");
EFI_MEMORY_DESCRIPTOR *end = INCREMENT_DESC(map->entries, map->length);
EFI_MEMORY_DESCRIPTOR *d = map->entries;
while (d < end) {
switch (d->Type) {
case memtype_kernel:
case memtype_data:
case memtype_initrd:
case memtype_scratch:
d->Attribute |= EFI_MEMORY_RUNTIME;
d->VirtualStart = d->PhysicalStart + KERNEL_VIRT_ADDRESS;
map.length = map.total;
try_or_raise(
bs->get_memory_map(&map.length, map.entries, &map.key, &map.size, &map.version),
L"Getting UEFI memory map");
}
inline size_t bitmap_size(size_t frames) { return (frames + 63) / 64; }
inline size_t num_blocks(size_t frames) { return (frames + (frames_per_block-1)) / frames_per_block; }
void
build_kernel_frame_blocks(const mem_entry *map, size_t nent, kernel::args::header *args, uefi::boot_services *bs)
{
status_line status {L"Creating kernel frame accounting map"};
size_t block_count = 0;
size_t total_bitmap_size = 0;
for (size_t i = 0; i < nent; ++i) {
const mem_entry &ent = map[i];
if (ent.type != mem_type::free)
continue;
block_count += num_blocks(ent.pages);
total_bitmap_size += bitmap_size(ent.pages) * sizeof(uint64_t);
}
size_t total_size = block_count * sizeof(frame_block) + total_bitmap_size;
frame_block *blocks = nullptr;
try_or_raise(
bs->allocate_pages(
uefi::allocate_type::any_pages,
uefi::memory_type::loader_data,
bytes_to_pages(total_size),
reinterpret_cast<void**>(&blocks)),
L"Error allocating kernel frame block space");
frame_block *next_block = blocks;
for (size_t i = 0; i < nent; ++i) {
const mem_entry &ent = map[i];
if (ent.type != mem_type::free)
continue;
size_t page_count = ent.pages;
uintptr_t base_addr = ent.start;
while (page_count) {
frame_block *blk = next_block++;
bs->set_mem(blk, sizeof(frame_block), 0);
blk->attrs = ent.attr;
blk->base = base_addr;
base_addr += frames_per_block * page_size;
if (page_count >= frames_per_block) {
page_count -= frames_per_block;
blk->count = frames_per_block;
blk->map1 = ~0ull;
bs->set_mem(blk->map2, sizeof(blk->map2), 0xff);
} else {
blk->count = page_count;
unsigned i = 0;
uint64_t b1 = (page_count + 4095) / 4096;
blk->map1 = (1 << b1) - 1;
uint64_t b2 = (page_count + 63) / 64;
uint64_t b2q = b2 / 64;
uint64_t b2r = b2 % 64;
bs->set_mem(blk->map2, b2q, 0xff);
blk->map2[b2q] = (1 << b2r) - 1;
break;
default:
if (d->Attribute & EFI_MEMORY_RUNTIME) {
d->VirtualStart = d->PhysicalStart + KERNEL_VIRT_ADDRESS;
}
}
d = INCREMENT_DESC(d, map->size);
}
uint64_t *bitmap = reinterpret_cast<uint64_t*>(next_block);
bs->set_mem(bitmap, total_bitmap_size, 0);
for (unsigned i = 0; i < block_count; ++i) {
frame_block &blk = blocks[i];
blk.bitmap = bitmap;
size_t b = blk.count / 64;
size_t r = blk.count % 64;
bs->set_mem(blk.bitmap, b*8, 0xff);
blk.bitmap[b] = (1 << r) - 1;
bitmap += bitmap_size(blk.count);
}
args->frame_block_count = block_count;
args->frame_block_pages = bytes_to_pages(total_size);
args->frame_blocks = blocks;
runsvc->SetVirtualAddressMap(map->length, map->size, map->version, map->entries);
}
void
fix_frame_blocks(kernel::args::header *args)
{
// Map the frame blocks to the appropriate address
paging::map_pages(args,
reinterpret_cast<uintptr_t>(args->frame_blocks),
::memory::bitmap_start,
args->frame_block_pages,
true, false);
uintptr_t offset = ::memory::bitmap_start -
reinterpret_cast<uintptr_t>(args->frame_blocks);
for (unsigned i = 0; i < args->frame_block_count; ++i) {
frame_block &blk = args->frame_blocks[i];
blk.bitmap = reinterpret_cast<uint64_t*>(
reinterpret_cast<uintptr_t>(blk.bitmap) + offset);
}
}
efi_mem_map
build_kernel_mem_map(kernel::args::header *args, uefi::boot_services *bs)
{
status_line status {L"Creating kernel memory map"};
efi_mem_map map;
get_uefi_mappings(map, bs);
size_t map_size = map.num_entries() * sizeof(mem_entry);
kernel::args::mem_entry *kernel_map = nullptr;
try_or_raise(
bs->allocate_pages(
uefi::allocate_type::any_pages,
uefi::memory_type::loader_data,
bytes_to_pages(map_size),
reinterpret_cast<void**>(&kernel_map)),
L"Error allocating kernel memory map module space");
bs->set_mem(kernel_map, map_size, 0);
get_uefi_mappings(map, bs);
size_t nent = 0;
bool first = true;
for (auto desc : map) {
/*
// EFI map dump
console::print(L" eRange %lx (%lx) %x(%s) [%lu]\r\n",
desc->physical_start, desc->attribute, desc->type, memory_type_name(desc->type), desc->number_of_pages);
*/
mem_type type;
switch (desc->type) {
case uefi::memory_type::reserved:
case uefi::memory_type::unusable_memory:
case uefi::memory_type::acpi_memory_nvs:
case uefi::memory_type::pal_code:
continue;
case uefi::memory_type::loader_code:
case uefi::memory_type::boot_services_code:
case uefi::memory_type::boot_services_data:
case uefi::memory_type::conventional_memory:
case uefi::memory_type::loader_data:
type = mem_type::free;
break;
case uefi::memory_type::runtime_services_code:
case uefi::memory_type::runtime_services_data:
type = mem_type::uefi_runtime;
break;
case uefi::memory_type::acpi_reclaim_memory:
type = mem_type::acpi;
break;
case uefi::memory_type::memory_mapped_io:
case uefi::memory_type::memory_mapped_io_port_space:
type = mem_type::mmio;
break;
case uefi::memory_type::persistent_memory:
type = mem_type::persistent;
break;
default:
error::raise(
uefi::status::invalid_parameter,
L"Got an unexpected memory type from UEFI memory map");
}
// TODO: validate uefi's map is sorted
if (first) {
first = false;
mem_entry &ent = kernel_map[nent++];
ent.start = desc->physical_start;
ent.pages = desc->number_of_pages;
ent.type = type;
ent.attr = (desc->attribute & 0xffffffff);
continue;
}
mem_entry &prev = kernel_map[nent - 1];
if (can_merge(prev, type, desc)) {
prev.pages += desc->number_of_pages;
} else {
mem_entry &next = kernel_map[nent++];
next.start = desc->physical_start;
next.pages = desc->number_of_pages;
next.type = type;
next.attr = (desc->attribute & 0xffffffff);
}
}
// Give just the actually-set entries in the header
args->mem_map = kernel_map;
args->map_count = nent;
/*
// kernel map dump
for (unsigned i = 0; i < nent; ++i) {
const kernel::args::mem_entry &e = kernel_map[i];
console::print(L" kRange %lx (%lx) %x(%s) [%lu]\r\n",
e.start, e.attr, e.type, kernel_memory_type_name(e.type), e.pages);
}
*/
build_kernel_frame_blocks(kernel_map, nent, args, bs);
get_uefi_mappings(map, bs);
return map;
}
void
virtualize(void *pml4, efi_mem_map &map, uefi::runtime_services *rs)
{
paging::add_current_mappings(reinterpret_cast<paging::page_table*>(pml4));
for (auto desc : map)
desc->virtual_start = desc->physical_start + ::memory::page_offset;
// Write our new PML4 pointer to CR3
asm volatile ( "mov %0, %%cr3" :: "r" (pml4) );
__sync_synchronize();
try_or_raise(
rs->set_virtual_address_map(
map.length, map.size, map.version, map.entries),
L"Error setting virtual address map");
}
} // namespace boot
} // namespace memory

View File

@@ -1,84 +1,27 @@
/// \file memory.h
/// Memory-related constants and functions.
#pragma once
#include <uefi/boot_services.h>
#include <uefi/runtime_services.h>
#include <stdint.h>
#include "kernel_args.h"
#include "pointer_manipulation.h"
#include <efi/efi.h>
namespace boot {
namespace memory {
extern const EFI_MEMORY_TYPE memtype_kernel;
extern const EFI_MEMORY_TYPE memtype_data;
extern const EFI_MEMORY_TYPE memtype_initrd;
extern const EFI_MEMORY_TYPE memtype_scratch;
/// UEFI specifies that pages are always 4 KiB.
constexpr size_t page_size = 0x1000;
/// Get the number of pages needed to hold `bytes` bytes
inline constexpr size_t bytes_to_pages(size_t bytes) {
return ((bytes - 1) / page_size) + 1;
}
/// \defgroup pointer_fixup
/// Memory virtualization pointer fixup functions. Handles changing affected pointers
/// when calling UEFI's `set_virtual_address_map` function to change the location of
/// runtime services in virtual memory.
/// @{
/// Set up the pointer fixup UEFI events. This registers the necessary callbacks for
/// runtime services to call when `set_virtual_address_map` is called.
void init_pointer_fixup(uefi::boot_services *bs, uefi::runtime_services *rs);
/// Mark a given pointer as needing to be updated when doing pointer fixup.
void mark_pointer_fixup(void **p);
/// @}
/// Struct that represents UEFI's memory map. Contains a pointer to the map data
/// as well as the data on how to read it.
struct efi_mem_map
{
using desc = uefi::memory_descriptor;
using iterator = offset_iterator<desc>;
size_t length; ///< Total length of the map data
size_t total; ///< Total allocated space for map data
size_t size; ///< Size of an entry in the array
size_t key; ///< Key for detecting changes
uint32_t version; ///< Version of the `memory_descriptor` struct
desc *entries; ///< The array of UEFI descriptors
efi_mem_map() : length(0), total(0), size(0), key(0), version(0), entries(nullptr) {}
/// Get the count of entries in the array
inline size_t num_entries() const { return length / size; }
/// Return an iterator to the beginning of the array
iterator begin() { return iterator(entries, size); }
/// Return an iterator to the end of the array
iterator end() { return offset_ptr<desc>(entries, length); }
struct memory_map {
size_t length;
size_t size;
size_t key;
uint32_t version;
EFI_MEMORY_DESCRIPTOR *entries;
};
/// Add the kernel's memory map as a module to the kernel args.
/// \returns The uefi memory map used to build the kernel map
efi_mem_map build_kernel_mem_map(kernel::args::header *args, uefi::boot_services *bs);
EFI_STATUS memory_init_pointer_fixup(
EFI_BOOT_SERVICES *bootsvc,
EFI_RUNTIME_SERVICES *runsvc,
unsigned scratch_pages);
void memory_mark_pointer_fixup(void **p);
/// Create the kernel frame allocation maps
void build_kernel_frame_blocks(
const kernel::args::mem_entry *map, size_t nent,
kernel::args::header *args, uefi::boot_services *bs);
EFI_STATUS memory_get_map_length(EFI_BOOT_SERVICES *bootsvc, size_t *size);
EFI_STATUS memory_get_map(EFI_BOOT_SERVICES *bootsvc, struct memory_map *map);
EFI_STATUS memory_dump_map(struct memory_map *map);
/// Map the frame allocation maps to the right spot and fix up pointers
void fix_frame_blocks(kernel::args::header *args);
/// Activate the given memory mappings. Sets the given page tables live as well
/// as informs UEFI runtime services of the new mappings.
/// \arg pml4 The root page table for the new mappings
/// \arg map The UEFI memory map, used to update runtime services
void virtualize(
void *pml4,
efi_mem_map &map,
uefi::runtime_services *rs);
} // namespace boot
} // namespace memory
void memory_virtualize(EFI_RUNTIME_SERVICES *runsvc, struct memory_map *map);

View File

@@ -1,287 +0,0 @@
#include "kernel_memory.h"
#include "console.h"
#include "error.h"
#include "loader.h"
#include "memory.h"
#include "paging.h"
#include "pointer_manipulation.h"
#include "status.h"
namespace boot {
namespace paging {
using memory::page_size;
using ::memory::pml4e_kernel;
using ::memory::table_entries;
// Flags: 0 0 0 1 0 0 0 0 0 0 0 1 = 0x0101
// IGN | | | | | | | | +- Present
// | | | | | | | +--- Writeable
// | | | | | | +----- Usermode access (supervisor only)
// | | | | | +------- PWT (determining memory type for page)
// | | | | +---------- PCD (determining memory type for page)
// | | | +------------ Accessed flag (not accessed yet)
// | | +-------------- Dirty (not dirtied yet)
// | +---------------- PAT (determining memory type for page)
// +------------------- Global
/// Page table entry flags for entries pointing at a page
constexpr uint64_t page_flags = 0x101;
// Flags: 0 0 0 0 1 1 0 0 0 1 0 1 1 = 0x018b
// | IGN | | | | | | | | +- Present
// | | | | | | | | +--- Writeable
// | | | | | | | +----- Supervisor only
// | | | | | | +------- PWT (determining memory type for page)
// | | | | | +---------- PCD (determining memory type for page)
// | | | | +------------ Accessed flag (not accessed yet)
// | | | +-------------- Dirty (not dirtied yet)
// | | +---------------- Page size (1GiB page)
// | +------------------- Global
// +---------------------------- PAT (determining memory type for page)
/// Page table entry flags for entries pointing at a huge page
constexpr uint64_t huge_page_flags = 0x18b;
// Flags: 0 0 0 0 0 0 0 0 0 0 1 1 = 0x0003
// IGNORED | | | | | | | +- Present
// | | | | | | +--- Writeable
// | | | | | +----- Usermode access (Supervisor only)
// | | | | +------- PWT (determining memory type for pdpt)
// | | | +---------- PCD (determining memory type for pdpt)
// | | +------------ Accessed flag (not accessed yet)
// | +-------------- Ignored
// +---------------- Reserved 0 (Table pointer, not page)
/// Page table entry flags for entries pointing at another table
constexpr uint64_t table_flags = 0x003;
/// Iterator over page table entries.
template <unsigned D = 4>
class page_entry_iterator
{
public:
/// Constructor.
/// \arg virt Virtual address this iterator is starting at
/// \arg pml4 Root of the page tables to iterate
/// \arg page_cache Pointer to pages that can be used for page tables
/// \arg page_count Number of pages pointed to by `page_cache`
page_entry_iterator(
uintptr_t virt,
page_table *pml4,
void *&page_cache,
size_t &cache_count) :
m_page_cache(page_cache),
m_cache_count(cache_count)
{
m_table[0] = pml4;
for (unsigned i = 0; i < D; ++i) {
m_index[i] = static_cast<uint16_t>((virt >> (12 + 9*(3-i))) & 0x1ff);
ensure_table(i);
}
}
uintptr_t vaddress() const {
uintptr_t address = 0;
for (unsigned i = 0; i < D; ++i)
address |= static_cast<uintptr_t>(m_index[i]) << (12 + 9*(3-i));
if (address & (1ull<<47)) // canonicalize the address
address |= (0xffffull<<48);
return address;
}
void increment()
{
for (unsigned i = D - 1; i >= 0; --i) {
if (++m_index[i] <= 511) {
for (unsigned j = i + 1; j < D; ++j)
ensure_table(j);
return;
}
m_index[i] = 0;
}
}
uint64_t & operator*() { return entry(D-1); }
private:
inline uint64_t & entry(unsigned level) { return m_table[level]->entries[m_index[level]]; }
void ensure_table(unsigned level)
{
// We're only dealing with D levels of paging, and
// there must always be a PML4.
if (level < 1 || level >= D)
return;
// Entry in the parent that points to the table we want
uint64_t & parent_ent = entry(level - 1);
if (!(parent_ent & 1)) {
if (!m_cache_count--)
error::raise(uefi::status::out_of_resources, L"Page table cache empty", 0x7ab1e5);
page_table *table = reinterpret_cast<page_table*>(m_page_cache);
m_page_cache = offset_ptr<void>(m_page_cache, page_size);
parent_ent = (reinterpret_cast<uintptr_t>(table) & ~0xfffull) | table_flags;
m_table[level] = table;
} else {
m_table[level] = reinterpret_cast<page_table*>(parent_ent & ~0xfffull);
}
}
void *&m_page_cache;
size_t &m_cache_count;
page_table *m_table[D];
uint16_t m_index[D];
};
static void
add_offset_mappings(page_table *pml4, void *&page_cache, size_t &num_pages)
{
uintptr_t phys = 0;
uintptr_t virt = ::memory::page_offset; // Start of offset-mapped area
size_t pages = 64 * 1024; // 64 TiB of 1 GiB pages
constexpr size_t GiB = 0x40000000ull;
page_entry_iterator<2> iterator{
virt, pml4,
page_cache,
num_pages};
while (true) {
*iterator = phys | huge_page_flags;
if (--pages == 0)
break;
iterator.increment();
phys += GiB;
}
}
static void
add_kernel_pds(page_table *pml4, void *&page_cache, size_t &num_pages)
{
for (unsigned i = pml4e_kernel; i < table_entries; ++i) {
pml4->set(i, page_cache, table_flags);
page_cache = offset_ptr<void>(page_cache, page_size);
num_pages--;
}
}
void
add_current_mappings(page_table *new_pml4)
{
// Get the pointer to the current PML4
page_table *old_pml4 = 0;
asm volatile ( "mov %%cr3, %0" : "=r" (old_pml4) );
// Only copy mappings in the lower half
for (int i = 0; i < ::memory::pml4e_kernel; ++i) {
uint64_t entry = old_pml4->entries[i];
if (entry & 1)
new_pml4->entries[i] = entry;
}
}
void
allocate_tables(kernel::args::header *args, uefi::boot_services *bs)
{
status_line status(L"Allocating initial page tables");
static constexpr size_t pd_tables = 256; // number of pages for kernelspace PDs
static constexpr size_t extra_tables = 64; // number of extra pages
// number of pages for kernelspace PDs + PML4
static constexpr size_t kernel_tables = pd_tables + 1;
static constexpr size_t tables_needed = kernel_tables + extra_tables;
void *addr = nullptr;
try_or_raise(
bs->allocate_pages(
uefi::allocate_type::any_pages,
uefi::memory_type::loader_data,
tables_needed,
&addr),
L"Error allocating page table pages.");
bs->set_mem(addr, tables_needed*page_size, 0);
page_table *pml4 = reinterpret_cast<page_table*>(addr);
args->pml4 = pml4;
args->table_pages = tables_needed;
args->table_count = tables_needed - 1;
args->page_tables = offset_ptr<void>(addr, page_size);
console::print(L" First page (pml4) at: 0x%lx\r\n", pml4);
add_kernel_pds(pml4, args->page_tables, args->table_count);
add_offset_mappings(pml4, args->page_tables, args->table_count);
//console::print(L" Set up initial mappings, %d spare tables.\r\n", args->table_count);
}
template <typename E>
constexpr bool has_flag(E set, E flag) {
return
(static_cast<uint64_t>(set) & static_cast<uint64_t>(flag)) ==
static_cast<uint64_t>(flag);
}
void
map_pages(
kernel::args::header *args,
uintptr_t phys, uintptr_t virt,
size_t count, bool write_flag, bool exe_flag)
{
if (!count)
return;
paging::page_table *pml4 =
reinterpret_cast<paging::page_table*>(args->pml4);
page_entry_iterator<4> iterator{
virt, pml4,
args->page_tables,
args->table_count};
uint64_t flags = page_flags;
if (!exe_flag)
flags |= (1ull << 63); // set NX bit
if (write_flag)
flags |= 2;
while (true) {
*iterator = phys | flags;
if (--count == 0)
break;
iterator.increment();
phys += page_size;
}
}
void
map_section(
kernel::args::header *args,
const kernel::args::program_section &section)
{
using kernel::args::section_flags;
size_t pages = memory::bytes_to_pages(section.size);
map_pages(
args,
section.phys_addr,
section.virt_addr,
pages,
has_flag(section.type, section_flags::write),
has_flag(section.type, section_flags::execute));
}
} // namespace paging
} // namespace boot

View File

@@ -1,59 +0,0 @@
#pragma once
/// \file paging.h
/// Page table structure and related definitions
#include <stdint.h>
#include <uefi/boot_services.h>
#include "kernel_args.h"
namespace boot {
namespace paging {
/// Struct to allow easy accessing of a memory page being used as a page table.
struct page_table
{
uint64_t entries[512];
inline page_table * get(int i, uint16_t *flags = nullptr) const {
uint64_t entry = entries[i];
if ((entry & 1) == 0) return nullptr;
if (flags) *flags = entry & 0xfff;
return reinterpret_cast<page_table *>(entry & ~0xfffull);
}
inline void set(int i, void *p, uint16_t flags) {
entries[i] = reinterpret_cast<uint64_t>(p) | (flags & 0xfff);
}
};
/// Allocate memory to be used for initial page tables. Initial offset-mapped
/// page tables are pre-filled. All pages are saved as a module in kernel args
/// and kernel args' `page_table_cache` and `num_free_tables` are updated with
/// the leftover space.
void allocate_tables(
kernel::args::header *args,
uefi::boot_services *bs);
/// Copy existing page table entries to a new page table. Does not do a deep
/// copy - the new PML4 is updated to point to the existing next-level page
/// tables in the current PML4.
void add_current_mappings(page_table *new_pml4);
/// Map physical memory pages to virtual addresses in the given page tables.
/// \arg args The kernel args header, used for the page table cache and pml4
/// \arg section The program section to load
void map_pages(
kernel::args::header *args,
uintptr_t phys, uintptr_t virt,
size_t count, bool write_flag, bool exe_flag);
/// Map a program section in physical memory to its virtual address in the
/// given page tables.
/// \arg args The kernel args header, used for the page table cache and pml4
/// \arg section The program section to load
void map_section(
kernel::args::header *args,
const kernel::args::program_section &section);
} // namespace paging
} // namespace boot

View File

@@ -1,41 +0,0 @@
/// \file pointer_manipulation.h
/// Helper functions and types for doing type-safe byte-wise pointer math.
#pragma once
namespace boot {
/// Return a pointer offset from `input` by `offset` bytes.
/// \tparam T Cast the return value to a pointer to `T`
/// \tparam S The type pointed to by the `input` pointer
template <typename T, typename S>
inline T* offset_ptr(S* input, ptrdiff_t offset) {
return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(input) + offset);
}
/// Iterator for an array of `T` whose size is known at runtime
/// \tparam T Type of the objects in the array, whose size might not be
/// what is returned by sizeof(T).
template <typename T>
class offset_iterator
{
public:
/// Constructor.
/// \arg t Pointer to the first item in the array
/// \arg off Offset applied to reach successive items. Default is 0,
/// which creates an effectively constant iterator.
offset_iterator(T* t, size_t off=0) : m_t(t), m_off(off) {}
T* operator++() { m_t = offset_ptr<T>(m_t, m_off); return m_t; }
T* operator++(int) { T* tmp = m_t; operator++(); return tmp; }
bool operator==(T* p) { return p == m_t; }
T* operator*() const { return m_t; }
operator T*() const { return m_t; }
T* operator->() const { return m_t; }
private:
T* m_t;
size_t m_off;
};
} // namespace boot

97
src/boot/reloc.cpp Normal file
View File

@@ -0,0 +1,97 @@
/* reloc_x86_64.c - position independent x86_64 ELF shared object relocator
Copyright (C) 1999 Hewlett-Packard Co.
Contributed by David Mosberger <davidm@hpl.hp.com>.
Copyright (C) 2005 Intel Co.
Contributed by Fenghua Yu <fenghua.yu@intel.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of Hewlett-Packard Co. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include <efi/efi.h>
#include <elf.h>
extern "C"
EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn,
EFI_HANDLE image EFI_UNUSED,
EFI_SYSTEM_TABLE *systab EFI_UNUSED)
{
long relsz = 0, relent = 0;
Elf64_Rel *rel = 0;
unsigned long *addr;
int i;
for (i = 0; dyn[i].d_tag != DT_NULL; ++i) {
switch (dyn[i].d_tag) {
case DT_RELA:
rel = (Elf64_Rel*)
((unsigned long)dyn[i].d_un.d_ptr
+ ldbase);
break;
case DT_RELASZ:
relsz = dyn[i].d_un.d_val;
break;
case DT_RELAENT:
relent = dyn[i].d_un.d_val;
break;
default:
break;
}
}
if (!rel && relent == 0)
return EFI_SUCCESS;
if (!rel || relent == 0)
return EFI_LOAD_ERROR;
while (relsz > 0) {
/* apply the relocs */
switch (ELF64_R_TYPE (rel->r_info)) {
case R_X86_64_NONE:
break;
case R_X86_64_RELATIVE:
addr = (unsigned long *)
(ldbase + rel->r_offset);
*addr += ldbase;
break;
default:
break;
}
rel = (Elf64_Rel*) ((char *) rel + relent);
relsz -= relent;
}
return EFI_SUCCESS;
}

View File

@@ -1,265 +0,0 @@
#include <uefi/types.h>
#include <uefi/graphics.h>
#include "console.h"
#include "error.h"
#include "kernel_args.h"
#include "status.h"
constexpr int num_boxes = 30;
namespace boot {
static constexpr int level_ok = 0;
static constexpr int level_warn = 1;
static constexpr int level_fail = 2;
static const wchar_t *level_tags[] = {
L" ok ",
L" warn ",
L"failed"
};
static const uefi::attribute level_colors[] = {
uefi::attribute::green,
uefi::attribute::brown,
uefi::attribute::light_red
};
status *status::s_current = nullptr;
unsigned status::s_current_type = 0;
unsigned status_bar::s_count = 0;
status_line::status_line(const wchar_t *message, const wchar_t *context, bool fails_clean) :
status(fails_clean),
m_level(level_ok),
m_depth(0),
m_outer(nullptr)
{
if (status::s_current_type == status_line::type) {
m_outer = static_cast<status_line*>(s_current);
m_depth = (m_outer ? 1 + m_outer->m_depth : 0);
}
s_current = this;
s_current_type = status_line::type;
auto out = console::get().m_out;
m_line = out->mode->cursor_row;
int indent = 2 * m_depth;
out->set_cursor_position(indent, m_line);
out->set_attribute(uefi::attribute::light_gray);
out->output_string(message);
if (context) {
out->output_string(L": ");
out->output_string(context);
}
out->output_string(L"\r\n");
print_status_tag();
}
status_line::~status_line()
{
if (s_current != this)
error::raise(uefi::status::unsupported, L"Destroying non-current status_line");
if (m_outer && m_level > m_outer->m_level) {
m_outer->m_level = m_level;
m_outer->print_status_tag();
}
s_current = m_outer;
}
void
status_line::print_status_tag()
{
auto out = console::get().m_out;
int row = out->mode->cursor_row;
int col = out->mode->cursor_column;
uefi::attribute color = level_colors[m_level];
const wchar_t *tag = level_tags[m_level];
out->set_cursor_position(50, m_line);
out->set_attribute(uefi::attribute::light_gray);
out->output_string(L"[");
out->set_attribute(color);
out->output_string(tag);
out->set_attribute(uefi::attribute::light_gray);
out->output_string(L"]\r\n");
out->set_cursor_position(col, row);
}
void
status_line::do_warn(const wchar_t *message, uefi::status status)
{
auto out = console::get().m_out;
int row = out->mode->cursor_row;
if (m_level < level_warn) {
m_level = level_warn;
print_status_tag();
}
int indent = 2 + 2 * m_depth;
out->set_cursor_position(indent, row);
out->set_attribute(uefi::attribute::yellow);
out->output_string(message);
const wchar_t *error = error::message(status);
if (error) {
out->output_string(L": ");
out->output_string(error);
}
out->set_attribute(uefi::attribute::light_gray);
out->output_string(L"\r\n");
}
void
status_line::do_fail(const wchar_t *message, uefi::status status)
{
auto out = console::get().m_out;
int row = out->mode->cursor_row;
if (m_level < level_fail) {
m_level = level_fail;
print_status_tag();
}
int indent = 2 + 2 * m_depth;
out->set_cursor_position(indent, row);
out->set_attribute(uefi::attribute::red);
out->output_string(message);
const wchar_t *error = error::message(status);
if (error) {
out->output_string(L": ");
out->output_string(error);
}
out->set_attribute(uefi::attribute::light_gray);
out->output_string(L"\r\n");
}
status_bar::status_bar(kernel::args::framebuffer const &fb) :
status(fb.size),
m_outer(nullptr)
{
m_size = (fb.vertical / num_boxes) - 1;
m_top = fb.vertical - m_size;
m_horiz = fb.horizontal;
m_fb = reinterpret_cast<uint32_t*>(fb.phys_addr);
m_type = static_cast<uint16_t>(fb.type);
next();
if (status::s_current_type == status_bar::type)
m_outer = static_cast<status_bar*>(s_current);
s_current = this;
s_current_type = status_bar::type;
}
status_bar::~status_bar()
{
if (s_current != this)
error::raise(uefi::status::unsupported, L"Destroying non-current status_bar");
draw_box();
s_current = m_outer;
}
void
status_bar::do_warn(const wchar_t *message, uefi::status status)
{
m_status = status;
if (m_level < level_warn) {
m_level = level_warn;
draw_box();
}
}
void
status_bar::do_fail(const wchar_t *message, uefi::status status)
{
m_status = status;
if (m_level < level_fail) {
m_level = level_fail;
draw_box();
}
}
static uint32_t
make_color(uint8_t r, uint8_t g, uint8_t b, uint16_t type)
{
switch (static_cast<kernel::args::fb_type>(type)) {
case kernel::args::fb_type::bgr8:
return
(static_cast<uint32_t>(b) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(r) << 16);
case kernel::args::fb_type::rgb8:
return
(static_cast<uint32_t>(r) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(b) << 16);
default:
return 0;
}
}
void
status_bar::draw_box()
{
static const uint32_t colors[] = {0x909090, 0xf0f0f0};
constexpr unsigned ncolors = sizeof(colors) / sizeof(uint32_t);
if (m_fb == nullptr)
return;
unsigned x0 = m_current * m_size;
unsigned x1 = x0 + m_size - 3;
unsigned y0 = m_top;
unsigned y1 = m_top + m_size - 3;
uint32_t color = 0;
switch (m_level) {
case level_ok:
color = colors[m_current % ncolors];
break;
case level_warn:
color = make_color(0xff, 0xb2, 0x34, m_type);
break;
case level_fail:
color = make_color(0xfb, 0x0a, 0x1e, m_type);
break;
default:
color = 0;
}
for (unsigned y = y0; y < y1; ++y)
for (unsigned x = x0; x < x1; ++x)
m_fb[y * m_horiz + x] = color;
if (m_level > level_ok) {
unsigned nbars = static_cast<uint64_t>(m_status) & 0xffff;
constexpr unsigned bar_height = 4;
for (unsigned i = 1; i <= nbars; ++i) {
y0 = m_top - 2 * i * bar_height;
y1 = y0 + bar_height;
for (unsigned y = y0; y < y1; ++y)
for (unsigned x = x0; x < x1; ++x)
m_fb[y * m_horiz + x] = color;
}
}
}
} // namespace boot

View File

@@ -1,131 +0,0 @@
/// \file status.h
/// Status message and indicator handling
#pragma once
#include <stdint.h>
#include <uefi/types.h>
namespace kernel {
namespace args {
class framebuffer;
}
}
namespace boot {
// Abstract base class for status reporters.
class status
{
public:
status(bool fails_clean = true) : m_fails_clean(fails_clean) {}
virtual void do_warn(const wchar_t *message, uefi::status status) = 0;
virtual void do_fail(const wchar_t *message, uefi::status status) = 0;
/// Set the state to warning, and print a message. If the state is already at
/// warning or error, the state is unchanged but the message is still printed.
/// \arg message The warning message to print, if text is supported
/// \arg status If set, the error or warning code that should be represented
/// \returns True if there was a status handler to display the warning
inline static bool warn(const wchar_t *message, uefi::status status = uefi::status::success) {
if (!s_current) return false;
s_current->do_warn(message, status);
return s_current->m_fails_clean;
}
/// Set the state to error, and print a message. If the state is already at
/// error, the state is unchanged but the message is still printed.
/// \arg message The error message to print, if text is supported
/// \arg status The error or warning code that should be represented
/// \returns True if there was a status handler to display the failure
inline static bool fail(const wchar_t *message, uefi::status status) {
if (!s_current) return false;
s_current->do_fail(message, status);
return s_current->m_fails_clean;
}
protected:
static status *s_current;
static unsigned s_current_type;
private:
bool m_fails_clean;
};
/// Scoped status line reporter. Prints a message and an "OK" if no errors
/// or warnings were reported before destruction, otherwise reports the
/// error or warning.
class status_line :
public status
{
public:
constexpr static unsigned type = 1;
/// Constructor.
/// \arg message Description of the operation in progress
/// \arg context If non-null, printed after `message` and a colon
/// \arg fails_clean If true, this object can handle printing failure
status_line(
const wchar_t *message,
const wchar_t *context = nullptr,
bool fails_clean = true);
~status_line();
virtual void do_warn(const wchar_t *message, uefi::status status) override;
virtual void do_fail(const wchar_t *message, uefi::status status) override;
private:
void print_status_tag();
size_t m_line;
int m_level;
int m_depth;
status_line *m_outer;
};
/// Scoped status bar reporter. Draws a row of boxes along the bottom of
/// the screen, turning one red if there's an error in that step.
class status_bar :
public status
{
public:
constexpr static unsigned type = 2;
using framebuffer = kernel::args::framebuffer;
/// Constructor.
/// \arg fb The framebuffer descriptor to draw to
status_bar(kernel::args::framebuffer const &fb);
~status_bar();
virtual void do_warn(const wchar_t *message, uefi::status status) override;
virtual void do_fail(const wchar_t *message, uefi::status status) override;
inline void next() {
m_current = s_count++;
m_level = 0;
m_status = uefi::status::success;
draw_box();
}
private:
void draw_box();
uint32_t *m_fb;
uint32_t m_size;
uint32_t m_top;
uint32_t m_horiz;
int m_level;
uefi::status m_status;
uint16_t m_type;
uint16_t m_current;
status_bar *m_outer;
static unsigned s_count;
};
} // namespace boot

View File

@@ -1,39 +0,0 @@
#include <stdint.h>
#include "error.h"
extern "C" {
/// Basic memcpy() implementation for clang. Clang requires freestanding code
/// implement memcpy(), as it may emit references to it. This basic memcpy is
/// not the most efficient, but will get linked if no other memcpy exists.
__attribute__ ((__weak__))
void *memcpy(void *dest, const void *src, size_t n)
{
uint8_t *cdest = reinterpret_cast<uint8_t*>(dest);
const uint8_t *csrc = reinterpret_cast<const uint8_t*>(src);
for (size_t i = 0; i < n; ++i)
cdest[i] = csrc[i];
return dest;
}
/// Basic memset() implementation for clang. Clang requires freestanding code
/// implement memset(), as it may emit references to it. This basic memset is
/// not the most efficient, but will get linked if no other memcpy exists.
__attribute__ ((__weak__))
void *memset(void *dest, int c, size_t n)
{
uint8_t *cdest = reinterpret_cast<uint8_t*>(dest);
for (size_t i = 0; i < n; ++i)
cdest[i] = static_cast<uint8_t>(c);
return dest;
}
int _purecall()
{
::boot::error::raise(uefi::status::unsupported, L"Pure virtual call");
}
} // extern "C"
void operator delete (void *) {}

View File

@@ -1,13 +0,0 @@
/// \file types.h
/// Definitions of shared types used throughout the bootloader
#pragma once
namespace boot {
struct buffer
{
size_t size;
void *data;
};
} // namespace boot

71
src/boot/utility.cpp Normal file
View File

@@ -0,0 +1,71 @@
#include "utility.h"
struct error_code_desc {
EFI_STATUS code;
const wchar_t *name;
};
// Based off the gnu-efi table
struct error_code_desc error_table[] = {
{ EFI_SUCCESS, L"Success" },
{ EFI_LOAD_ERROR, L"Load Error" },
{ EFI_INVALID_PARAMETER, L"Invalid Parameter" },
{ EFI_UNSUPPORTED, L"Unsupported" },
{ EFI_BAD_BUFFER_SIZE, L"Bad Buffer Size" },
{ EFI_BUFFER_TOO_SMALL, L"Buffer Too Small" },
{ EFI_NOT_READY, L"Not Ready" },
{ EFI_DEVICE_ERROR, L"Device Error" },
{ EFI_WRITE_PROTECTED, L"Write Protected" },
{ EFI_OUT_OF_RESOURCES, L"Out of Resources" },
{ EFI_VOLUME_CORRUPTED, L"Volume Corrupt" },
{ EFI_VOLUME_FULL, L"Volume Full" },
{ EFI_NO_MEDIA, L"No Media" },
{ EFI_MEDIA_CHANGED, L"Media changed" },
{ EFI_NOT_FOUND, L"Not Found" },
{ EFI_ACCESS_DENIED, L"Access Denied" },
{ EFI_NO_RESPONSE, L"No Response" },
{ EFI_NO_MAPPING, L"No mapping" },
{ EFI_TIMEOUT, L"Time out" },
{ EFI_NOT_STARTED, L"Not started" },
{ EFI_ALREADY_STARTED, L"Already started" },
{ EFI_ABORTED, L"Aborted" },
{ EFI_ICMP_ERROR, L"ICMP Error" },
{ EFI_TFTP_ERROR, L"TFTP Error" },
{ EFI_PROTOCOL_ERROR, L"Protocol Error" },
{ EFI_INCOMPATIBLE_VERSION, L"Incompatible Version" },
{ EFI_SECURITY_VIOLATION, L"Security Policy Violation" },
{ EFI_CRC_ERROR, L"CRC Error" },
{ EFI_END_OF_MEDIA, L"End of Media" },
{ EFI_END_OF_FILE, L"End of File" },
{ EFI_INVALID_LANGUAGE, L"Invalid Languages" },
{ EFI_COMPROMISED_DATA, L"Compromised Data" },
{ EFI_WARN_UNKOWN_GLYPH, L"Warning Unknown Glyph" },
{ EFI_WARN_DELETE_FAILURE, L"Warning Delete Failure" },
{ EFI_WARN_WRITE_FAILURE, L"Warning Write Failure" },
{ EFI_WARN_BUFFER_TOO_SMALL, L"Warning Buffer Too Small" },
{ 0, NULL }
};
const wchar_t *
util_error_message(EFI_STATUS status)
{
int32_t i = -1;
while (error_table[++i].name != NULL) {
if (error_table[i].code == status) return error_table[i].name;
}
if (EFI_ERROR(status))
return L"Unknown Error";
else
return L"Unknown Warning";
}
size_t
wstrlen(const wchar_t *s)
{
size_t count = 0;
while (s && *s++) count++;
return count;
}

40
src/boot/utility.h Normal file
View File

@@ -0,0 +1,40 @@
#include <stddef.h>
#include <efi/efi.h>
#include "console.h"
#define UNUSED __attribute__((unused))
size_t wstrlen(const wchar_t *s);
const wchar_t *util_error_message(EFI_STATUS status);
#define CHECK_EFI_STATUS_OR_RETURN(s, msg, ...) \
if (EFI_ERROR((s))) { \
console::print(L"ERROR: " msg L": %s\r\n", ##__VA_ARGS__, util_error_message(s)); \
return (s); \
}
#define CHECK_EFI_STATUS_OR_FAIL(s) \
if (EFI_ERROR((s))) { \
console::get().status_fail(util_error_message(s)); \
while (1) __asm__("hlt"); \
}
#define CHECK_EFI_STATUS_OR_ASSERT(s, d) \
if (EFI_ERROR((s))) { \
__asm__ __volatile__( \
"movq %0, %%r8;" \
"movq %1, %%r9;" \
"movq %2, %%r10;" \
"movq $0, %%rdx;" \
"divq %%rdx;" \
: \
: "r"((uint64_t)s), "r"((uint64_t)d), "r"((uint64_t)__LINE__) \
: "rax", "rdx", "r8", "r9", "r10"); \
}
#ifdef BOOTLOADER_DEBUG
#define con_debug(msg, ...) console::print(L"DEBUG: " msg L"\r\n", __VA_ARGS__)
#else
#define con_debug(msg, ...)
#endif

View File

@@ -1,390 +0,0 @@
0x72, 0xb5, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xf8, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
0x22, 0x20, 0x20, 0xf8, 0x20, 0x20, 0x72, 0x8c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x7e, 0x24, 0x24,
0x24, 0x7e, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08,
0x1e, 0x20, 0x20, 0x1c, 0x02, 0x02, 0x3c, 0x08, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x30, 0x49, 0x4a, 0x34, 0x08, 0x16, 0x29, 0x49, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x31,
0x49, 0x46, 0x46, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08,
0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x24, 0x18, 0x7e, 0x18, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x7f, 0x08, 0x08, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08,
0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
0x42, 0x46, 0x4a, 0x52, 0x62, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x02, 0x02, 0x04,
0x08, 0x10, 0x20, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e,
0x04, 0x08, 0x1c, 0x02, 0x02, 0x02, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x0c, 0x14, 0x24, 0x44, 0x7e, 0x04, 0x04, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x7c, 0x02,
0x02, 0x02, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
0x20, 0x40, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x3c,
0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
0x42, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x04, 0x38, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04,
0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02,
0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42,
0x02, 0x04, 0x08, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x22, 0x41, 0x4f, 0x51, 0x51, 0x51, 0x53, 0x4d, 0x40,
0x20, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x42, 0x42, 0x42,
0x7e, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c,
0x42, 0x42, 0x42, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1e, 0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x20, 0x1e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x42, 0x42, 0x42,
0x42, 0x42, 0x44, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e,
0x40, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x20, 0x40, 0x40, 0x46,
0x42, 0x42, 0x22, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42,
0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42,
0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x42, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x63, 0x55, 0x49, 0x49,
0x41, 0x41, 0x41, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42,
0x62, 0x52, 0x4a, 0x46, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x7c,
0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x04, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x48, 0x44, 0x42, 0x42,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x40, 0x40, 0x20, 0x18,
0x04, 0x02, 0x02, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42,
0x24, 0x24, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41,
0x41, 0x41, 0x41, 0x49, 0x49, 0x49, 0x55, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x14, 0x08, 0x14, 0x22, 0x41, 0x41,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x14, 0x08,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e,
0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1e, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10,
0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x78, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x78, 0x00, 0x00,
0x00, 0x00, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7c, 0x42, 0x42,
0x42, 0x42, 0x42, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42,
0x7e, 0x40, 0x40, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x10,
0x10, 0x7e, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e,
0x02, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7c, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08,
0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x04, 0x00, 0x1c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x38, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x44, 0x48, 0x50,
0x70, 0x48, 0x44, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c,
0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x42, 0x42,
0x42, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x2e, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x40, 0x20, 0x18, 0x04, 0x02, 0x7c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x7e, 0x10, 0x10,
0x10, 0x10, 0x10, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x24, 0x24, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x41,
0x49, 0x49, 0x55, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x41, 0x22, 0x14, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e,
0x02, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x04, 0x08,
0x10, 0x20, 0x40, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x10, 0x10,
0x10, 0x10, 0x10, 0xe0, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0e, 0x00, 0x00,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x00, 0x00, 0x00, 0x70, 0x08, 0x08, 0x08, 0x08, 0x08, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x70, 0x00, 0x00, 0x00, 0x00, 0x31, 0x49,
0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,
0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x08, 0x08,
0x1c, 0x22, 0x40, 0x40, 0x40, 0x22, 0x1c, 0x08, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1c, 0x22, 0x20, 0x20, 0xf8, 0x20, 0x20, 0x72, 0x8c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x3c, 0x24, 0x24,
0x24, 0x3c, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41,
0x22, 0x14, 0x08, 0x3e, 0x08, 0x3e, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x08, 0x08,
0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1c, 0x22, 0x41, 0x4d, 0x51, 0x51, 0x4d, 0x41, 0x22,
0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x09, 0x12, 0x24, 0x48, 0x24, 0x12, 0x09, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x08, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x24, 0x12, 0x09, 0x12, 0x24, 0x48,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00,
0x00, 0x08, 0x10, 0x20, 0x40, 0x42, 0x3c, 0x00, 0x20, 0x10, 0x00, 0x18,
0x18, 0x24, 0x24, 0x24, 0x7e, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00,
0x04, 0x08, 0x00, 0x18, 0x18, 0x24, 0x24, 0x24, 0x7e, 0x42, 0x42, 0x42,
0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x00, 0x18, 0x18, 0x24, 0x24, 0x24,
0x7e, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x18,
0x18, 0x24, 0x24, 0x24, 0x7e, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00,
0x24, 0x24, 0x00, 0x18, 0x18, 0x24, 0x24, 0x24, 0x7e, 0x42, 0x42, 0x42,
0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x24,
0x7e, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x14, 0x14, 0x24, 0x27, 0x3c, 0x44, 0x44, 0x47, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1e, 0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x20, 0x1e,
0x08, 0x08, 0x30, 0x00, 0x20, 0x10, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x7c,
0x40, 0x40, 0x40, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x7e,
0x40, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x18, 0x24, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x7c,
0x40, 0x40, 0x40, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x3e,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x04, 0x08, 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x00, 0x3e,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x22, 0x21, 0x21, 0x79, 0x21, 0x21, 0x22, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x42, 0x62, 0x52, 0x4a, 0x46,
0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x1c,
0x22, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x04, 0x08, 0x00, 0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c,
0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x00, 0x1c, 0x22, 0x41, 0x41, 0x41,
0x41, 0x41, 0x22, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x1c,
0x22, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x24, 0x24, 0x00, 0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x14,
0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3c,
0x42, 0x46, 0x4a, 0x52, 0x62, 0x42, 0x42, 0x3c, 0x40, 0x00, 0x00, 0x00,
0x20, 0x10, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x00, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x24, 0x24, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x41, 0x41, 0x22, 0x14, 0x08,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
0x40, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x42, 0x44, 0x4c, 0x42, 0x42, 0x42, 0x44, 0x58,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x00, 0x3c, 0x02, 0x02,
0x3e, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08,
0x00, 0x3c, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x24, 0x00, 0x00, 0x3c, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x3c, 0x02, 0x02,
0x3e, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24,
0x00, 0x3c, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x18, 0x24, 0x24, 0x18, 0x00, 0x3c, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x09, 0x39,
0x4f, 0x48, 0x48, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x08, 0x08, 0x30, 0x00,
0x00, 0x00, 0x20, 0x10, 0x00, 0x3c, 0x42, 0x42, 0x7e, 0x40, 0x40, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x3c, 0x42, 0x42,
0x7e, 0x40, 0x40, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x7e, 0x40, 0x40, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x24, 0x24, 0x00, 0x3c, 0x42, 0x42, 0x7e, 0x40, 0x40, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x38, 0x08, 0x08,
0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08,
0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x24, 0x00, 0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x00, 0x38, 0x08, 0x08,
0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x1a,
0x01, 0x1d, 0x23, 0x41, 0x41, 0x41, 0x22, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x32, 0x4c, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x3c, 0x42, 0x42,
0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x24, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x3c, 0x42, 0x42,
0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3c, 0x46, 0x4a,
0x52, 0x62, 0x42, 0x3c, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10,
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x08, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x00, 0x00, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24,
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x08, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e,
0x02, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x5c, 0x62, 0x41,
0x41, 0x41, 0x62, 0x5c, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x24, 0x24,
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x3c, 0x00,
0xff, 0xff, 0xe2, 0x96, 0x92, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc2, 0xb0,
0xff, 0xff, 0xff, 0xff, 0xe2, 0x94, 0x98, 0xff, 0xe2, 0x94, 0x90, 0xff,
0xe2, 0x94, 0x8c, 0xff, 0xe2, 0x94, 0x94, 0xff, 0xe2, 0x94, 0xbc, 0xff,
0xff, 0xff, 0xe2, 0x94, 0x80, 0xff, 0xff, 0xff, 0xe2, 0x94, 0x9c, 0xff,
0xe2, 0x94, 0xa4, 0xff, 0xe2, 0x94, 0xb4, 0xff, 0xe2, 0x94, 0xac, 0xff,
0xe2, 0x94, 0x82, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc2, 0xa3, 0xff, 0xff,
0x20, 0xff, 0x21, 0xff, 0x22, 0xff, 0x23, 0xff, 0x24, 0xff, 0x25, 0xff,
0x26, 0xff, 0x27, 0xff, 0x28, 0xff, 0x29, 0xff, 0x2a, 0xff, 0x2b, 0xff,
0x2c, 0xff, 0x2d, 0xff, 0x2e, 0xff, 0x2f, 0xff, 0x30, 0xff, 0x31, 0xff,
0x32, 0xff, 0x33, 0xff, 0x34, 0xff, 0x35, 0xff, 0x36, 0xff, 0x37, 0xff,
0x38, 0xff, 0x39, 0xff, 0x3a, 0xff, 0x3b, 0xff, 0x3c, 0xff, 0x3d, 0xff,
0x3e, 0xff, 0x3f, 0xff, 0x40, 0xff, 0x41, 0xff, 0x42, 0xff, 0x43, 0xff,
0x44, 0xff, 0x45, 0xff, 0x46, 0xff, 0x47, 0xff, 0x48, 0xff, 0x49, 0xff,
0x4a, 0xff, 0x4b, 0xff, 0x4c, 0xff, 0x4d, 0xff, 0x4e, 0xff, 0x4f, 0xff,
0x50, 0xff, 0x51, 0xff, 0x52, 0xff, 0x53, 0xff, 0x54, 0xff, 0x55, 0xff,
0x56, 0xff, 0x57, 0xff, 0x58, 0xff, 0x59, 0xff, 0x5a, 0xff, 0x5b, 0xff,
0x5c, 0xff, 0x5d, 0xff, 0x5e, 0xff, 0x5f, 0xff, 0x60, 0xff, 0x61, 0xff,
0x62, 0xff, 0x63, 0xff, 0x64, 0xff, 0x65, 0xff, 0x66, 0xff, 0x67, 0xff,
0x68, 0xff, 0x69, 0xff, 0x6a, 0xff, 0x6b, 0xff, 0x6c, 0xff, 0x6d, 0xff,
0x6e, 0xff, 0x6f, 0xff, 0x70, 0xff, 0x71, 0xff, 0x72, 0xff, 0x73, 0xff,
0x74, 0xff, 0x75, 0xff, 0x76, 0xff, 0x77, 0xff, 0x78, 0xff, 0x79, 0xff,
0x7a, 0xff, 0x7b, 0xff, 0x7c, 0xff, 0x7d, 0xff, 0x7e, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc2, 0xa0, 0xff, 0xc2, 0xa1,
0xff, 0xc2, 0xa2, 0xff, 0xc2, 0xa3, 0xff, 0xc2, 0xa4, 0xff, 0xc2, 0xa5,
0xff, 0xc2, 0xa6, 0xff, 0xff, 0xc2, 0xa8, 0xff, 0xc2, 0xa9, 0xff, 0xff,
0xc2, 0xab, 0xff, 0xff, 0xc2, 0xad, 0xff, 0xff, 0xff, 0xc2, 0xb0, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc2, 0xb8, 0xff, 0xff, 0xff,
0xc2, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xc2, 0xbf, 0xff, 0xc3, 0x80, 0xff,
0xc3, 0x81, 0xff, 0xc3, 0x82, 0xff, 0xc3, 0x83, 0xff, 0xc3, 0x84, 0xff,
0xc3, 0x85, 0xff, 0xc3, 0x86, 0xff, 0xc3, 0x87, 0xff, 0xc3, 0x88, 0xff,
0xc3, 0x89, 0xff, 0xc3, 0x8a, 0xff, 0xc3, 0x8b, 0xff, 0xc3, 0x8c, 0xff,
0xc3, 0x8d, 0xff, 0xc3, 0x8e, 0xff, 0xc3, 0x8f, 0xff, 0xc3, 0x90, 0xff,
0xc3, 0x91, 0xff, 0xc3, 0x92, 0xff, 0xc3, 0x93, 0xff, 0xc3, 0x94, 0xff,
0xc3, 0x95, 0xff, 0xc3, 0x96, 0xff, 0xc3, 0x97, 0xff, 0xc3, 0x98, 0xff,
0xc3, 0x99, 0xff, 0xc3, 0x9a, 0xff, 0xc3, 0x9b, 0xff, 0xc3, 0x9c, 0xff,
0xc3, 0x9d, 0xff, 0xc3, 0x9e, 0xff, 0xc3, 0x9f, 0xff, 0xc3, 0xa0, 0xff,
0xc3, 0xa1, 0xff, 0xc3, 0xa2, 0xff, 0xc3, 0xa3, 0xff, 0xc3, 0xa4, 0xff,
0xc3, 0xa5, 0xff, 0xc3, 0xa6, 0xff, 0xc3, 0xa7, 0xff, 0xc3, 0xa8, 0xff,
0xc3, 0xa9, 0xff, 0xc3, 0xaa, 0xff, 0xc3, 0xab, 0xff, 0xc3, 0xac, 0xff,
0xc3, 0xad, 0xff, 0xc3, 0xae, 0xff, 0xc3, 0xaf, 0xff, 0xc3, 0xb0, 0xff,
0xc3, 0xb1, 0xff, 0xc3, 0xb2, 0xff, 0xc3, 0xb3, 0xff, 0xc3, 0xb4, 0xff,
0xc3, 0xb5, 0xff, 0xc3, 0xb6, 0xff, 0xc3, 0xb7, 0xff, 0xc3, 0xb8, 0xff,
0xc3, 0xb9, 0xff, 0xc3, 0xba, 0xff, 0xc3, 0xbb, 0xff, 0xc3, 0xbc, 0xff,
0xc3, 0xbd, 0xff, 0xc3, 0xbe, 0xff, 0xc3, 0xbf, 0xff

View File

@@ -1,33 +0,0 @@
#pragma once
#include <stdint.h>
#include "screen.h"
class font
{
public:
/// Constructor.
/// \arg data The font data to load. If null, will load the default
/// built-in font.
font(void const *data = nullptr);
unsigned glyph_bytes() const { return m_sizey * ((m_sizex + 7) / 8); }
unsigned count() const { return m_count; }
unsigned width() const { return m_sizex; }
unsigned height() const { return m_sizey; }
bool valid() const { return m_count > 0; }
void draw_glyph(
screen &s,
uint32_t glyph,
screen::pixel_t fg,
screen::pixel_t bg,
unsigned x,
unsigned y) const;
private:
unsigned m_sizex, m_sizey;
unsigned m_count;
uint8_t const *m_data;
};

View File

@@ -1,170 +0,0 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "j6/init.h"
#include "j6/errors.h"
#include "j6/flags.h"
#include "j6/signals.h"
#include "j6/syscalls.h"
#include "j6/types.h"
#include "font.h"
#include "screen.h"
#include "scrollback.h"
extern "C" {
int main(int, const char **);
void _get_init(size_t *initc, struct j6_init_value **initv);
}
extern j6_handle_t __handle_sys;
extern j6_handle_t __handle_self;
struct entry
{
uint8_t bytes;
uint8_t area;
uint8_t severity;
uint8_t sequence;
char message[0];
};
void
draw_stuff(screen &scr, font &fnt)
{
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
unsigned h = fnt.height();
unsigned w = fnt.width();
unsigned lines = scr.height()/h;
unsigned columns = scr.width()/w;
for (unsigned y = 0; y < lines; ++y) {
for (unsigned x = 0; x < columns; ++x) {
char d = (x + y * columns) % 10 + '0';
fnt.draw_glyph(scr, d, fg, bg, x*w, y*h);
}
}
for (unsigned y = 0; y < scr.height(); ++y) {
for (unsigned x = 0; x < scr.width(); x += 61) {
scr.draw_pixel(x, y, 0xffffff);
}
}
}
int
main(int argc, const char **argv)
{
j6_system_log("fb driver starting");
size_t initc = 0;
j6_init_value *initv = nullptr;
_get_init(&initc, &initv);
j6_init_framebuffer *fb = nullptr;
for (unsigned i = 0; i < initc; ++i) {
if (initv[i].type == j6_init_desc_framebuffer) {
fb = reinterpret_cast<j6_init_framebuffer*>(initv[i].data);
break;
}
}
if (!fb || fb->addr == 0) {
j6_system_log("fb driver didn't find a framebuffer, exiting");
return 1;
}
j6_handle_t fb_handle = j6_handle_invalid;
uint32_t flags =
j6_vm_flag_write |
j6_vm_flag_write_combine;
j6_status_t s = j6_system_map_mmio(__handle_sys, &fb_handle, fb->addr, fb->size, flags);
if (s != j6_status_ok) {
return s;
}
s = j6_vma_map(fb_handle, __handle_self, fb->addr);
if (s != j6_status_ok) {
return s;
}
const screen::pixel_order order = (fb->flags & 1) ?
screen::pixel_order::bgr8 : screen::pixel_order::rgb8;
screen scr(
reinterpret_cast<void*>(fb->addr),
fb->horizontal,
fb->vertical,
fb->scanline,
order);
font fnt;
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
scr.fill(bg);
scr.update();
draw_stuff(scr, fnt);
scr.update();
/*
constexpr int margin = 2;
const unsigned xstride = (margin + fnt.width());
const unsigned ystride = (margin + fnt.height());
const unsigned rows = (scr.height() - margin) / ystride;
const unsigned cols = (scr.width() - margin) / xstride;
scrollback scroll(rows, cols);
int pending = 0;
constexpr int pending_threshold = 10;
j6_handle_t sys = __handle_sys;
size_t buffer_size = 0;
void *message_buffer = nullptr;
while (true) {
size_t size = buffer_size;
j6_status_t s = j6_system_get_log(sys, message_buffer, &size);
if (s == j6_err_insufficient) {
free(message_buffer);
message_buffer = malloc(size);
buffer_size = size;
continue;
} else if (s != j6_status_ok) {
j6_system_log("fb driver got error from get_log, quitting");
return s;
}
if (size > 0) {
entry *e = reinterpret_cast<entry*>(message_buffer);
size_t eom = e->bytes - sizeof(entry);
e->message[eom] = 0;
scroll.add_line(e->message, eom);
if (++pending > pending_threshold) {
scroll.render(scr, fnt);
scr.update();
pending = 0;
}
} else {
if (pending) {
scroll.render(scr, fnt);
scr.update();
pending = 0;
}
}
}
*/
j6_system_log("fb driver done, exiting");
return 0;
}

View File

@@ -1,58 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include "screen.h"
screen::screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanline, pixel_order order) :
m_fb(static_cast<volatile pixel_t *>(addr)),
m_order(order),
m_scanline(scanline),
m_resx(hres),
m_resy(vres)
{
m_back = reinterpret_cast<pixel_t*>(malloc(scanline*vres*sizeof(pixel_t)));
//m_back = const_cast<pixel_t*>(m_fb);
}
screen::pixel_t
screen::color(uint8_t r, uint8_t g, uint8_t b) const
{
switch (m_order) {
case pixel_order::bgr8:
return
(static_cast<uint32_t>(b) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(r) << 16);
case pixel_order::rgb8:
return
(static_cast<uint32_t>(r) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(b) << 16);
}
}
void
screen::fill(pixel_t color)
{
const size_t len = m_scanline * m_resy;
asm volatile ( "rep stosl" : :
"a"(color), "c"(len), "D"(m_back) );
}
void
screen::update()
{
/*
const size_t len = m_scanline * m_resy * sizeof(pixel_t);
asm volatile ( "rep movsb" : :
"c"(len), "S"(m_back), "D"(m_fb) );
*/
const size_t len = m_scanline * m_resy;
for (size_t i = 0; i < len; ++i) {
m_fb[i] = m_back[i];
/*
for (int j = 0; j < 10000; ++j)
volatile char c = j;
*/
}
}

View File

@@ -1,38 +0,0 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
class screen
{
public:
using pixel_t = uint32_t;
enum class pixel_order : uint8_t { bgr8, rgb8, };
screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanline, pixel_order order);
unsigned width() const { return m_resx; }
unsigned height() const { return m_resy; }
pixel_t color(uint8_t r, uint8_t g, uint8_t b) const;
void fill(pixel_t color);
inline void draw_pixel(unsigned x, unsigned y, pixel_t color) {
const size_t index = x + y * m_scanline;
if (x > m_resx || y > m_resy)
return;
m_back[index] = color;
}
void update();
private:
volatile pixel_t *m_fb;
pixel_t *m_back;
pixel_order m_order;
unsigned m_scanline;
unsigned m_resx, m_resy;
screen() = delete;
};

View File

@@ -1,54 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include "font.h"
#include "screen.h"
#include "scrollback.h"
scrollback::scrollback(unsigned lines, unsigned cols, unsigned margin) :
m_rows {lines},
m_cols {cols},
m_count {0},
m_margin {margin}
{
m_data = reinterpret_cast<char*>(malloc(lines*cols));
memset(m_data, ' ', lines*cols);
}
void
scrollback::add_line(const char *line, size_t len)
{
unsigned i = m_count++ % m_rows;
if (len > m_cols)
len = m_cols;
char *start = m_data + (i * m_cols);
memcpy(start, line, len);
if (len < m_cols)
memset(start + len, ' ', m_cols - len);
}
char *
scrollback::get_line(unsigned i)
{
unsigned line = (i + m_count) % m_rows;
return &m_data[line*m_cols];
}
void
scrollback::render(screen &scr, font &fnt)
{
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
const unsigned xstride = (m_margin + fnt.width());
const unsigned ystride = (m_margin + fnt.height());
for (unsigned y = 0; y < m_rows; ++y) {
char *line = &m_data[y*m_cols];
for (unsigned x = 0; x < m_cols; ++x) {
fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride);
}
}
}

View File

@@ -1,25 +0,0 @@
#pragma once
/// \file scrollback.h
class screen;
class font;
class scrollback
{
public:
scrollback(unsigned lines, unsigned cols, unsigned margin = 2);
void add_line(const char *line, size_t len);
char * get_line(unsigned i);
void render(screen &scr, font &fnt);
private:
char *m_data;
unsigned m_rows, m_cols;
unsigned m_start;
unsigned m_count;
unsigned m_margin;
};

View File

@@ -1,22 +0,0 @@
#include "io.h"
uint8_t
inb(uint16_t port)
{
uint8_t val;
__asm__ __volatile__ ( "inb %1, %0" : "=a"(val) : "Nd"(port) );
return val;
}
void
outb(uint16_t port, uint8_t val)
{
__asm__ __volatile__ ( "outb %0, %1" :: "a"(val), "Nd"(port) );
}
void
io_wait(unsigned times)
{
for (unsigned i = 0; i < times; ++i)
outb(0x80, 0);
}

View File

@@ -1,24 +0,0 @@
#pragma once
#include <stdint.h>
extern "C" {
/// Read a byte from an IO port.
/// \arg port The address of the IO port
/// \returns One byte read from the port
uint8_t inb(uint16_t port);
/// Write a byte to an IO port.
/// \arg port The addres of the IO port
/// \arg val The byte to write
void outb(uint16_t port, uint8_t val);
/// Pause briefly by doing IO to port 0x80
/// \arg times Number of times to delay by writing
void io_wait(unsigned times = 1);
}
constexpr uint16_t COM1 = 0x03f8;
constexpr uint16_t COM2 = 0x02f8;

View File

@@ -3,141 +3,36 @@
#include "j6/types.h"
#include "j6/errors.h"
#include "j6/signals.h"
#include "j6/syscalls.h"
#include "io.h"
#include "serial.h"
char inbuf[1024];
extern j6_handle_t __handle_sys;
j6_handle_t endp = j6_handle_invalid;
extern "C" {
j6_status_t getpid(uint64_t *);
j6_status_t fork(uint64_t *);
j6_status_t sleep(uint64_t til);
j6_status_t debug();
j6_status_t message(const char *msg);
int main(int, const char **);
}
void
thread_proc()
{
j6_system_log("sub thread starting");
char buffer[512];
size_t len = sizeof(buffer);
j6_tag_t tag = 0;
j6_status_t result = j6_endpoint_receive(endp, &tag, &len, (void*)buffer);
if (result != j6_status_ok)
j6_thread_exit(result);
j6_system_log("sub thread received message");
for (int i = 0; i < len; ++i)
if (buffer[i] >= 'A' && buffer[i] <= 'Z')
buffer[i] += 0x20;
tag++;
result = j6_endpoint_send(endp, tag, len, (void*)buffer);
if (result != j6_status_ok)
j6_thread_exit(result);
j6_system_log("sub thread sent message");
for (int i = 1; i < 5; ++i)
j6_thread_sleep(i*10);
j6_system_log("sub thread exiting");
j6_thread_exit(0);
}
int
main(int argc, const char **argv)
{
j6_handle_t child = j6_handle_invalid;
j6_signal_t out = 0;
uint64_t pid = 0;
uint64_t child = 0;
j6_system_log("main thread starting");
for (int i = 0; i < argc; ++i)
j6_system_log(argv[i]);
void *base = malloc(0x1000);
if (!base)
return 1;
uint64_t *vma_ptr = reinterpret_cast<uint64_t*>(base);
for (int i = 0; i < 3; ++i)
vma_ptr[i*100] = uint64_t(i);
j6_system_log("main thread wrote to memory area");
j6_status_t result = j6_endpoint_create(&endp);
j6_status_t result = fork(&child);
if (result != j6_status_ok)
return result;
j6_system_log("main thread created endpoint");
message("hello from nulldrv!");
result = j6_thread_create(reinterpret_cast<void*>(&thread_proc), &child);
result = getpid(&pid);
if (result != j6_status_ok)
return result;
j6_system_log("main thread created sub thread");
for (int i = 1; i < 5; ++i)
sleep(i*10);
char message[] = "MAIN THREAD SUCCESSFULLY CALLED SENDRECV IF THIS IS LOWERCASE";
size_t size = sizeof(message);
j6_tag_t tag = 16;
result = j6_endpoint_sendrecv(endp, &tag, &size, (void*)message);
if (result != j6_status_ok)
return result;
if (tag != 17)
j6_system_log("GOT WRONG TAG FROM SENDRECV");
result = j6_system_bind_irq(__handle_sys, endp, 3);
if (result != j6_status_ok)
return result;
j6_system_log(message);
j6_system_log("main thread waiting on child");
result = j6_object_wait(child, -1ull, &out);
if (result != j6_status_ok)
return result;
j6_system_log("main thread creating a new process");
j6_handle_t child_proc = j6_handle_invalid;
result = j6_process_create(&child_proc);
if (result != j6_status_ok)
return result;
j6_system_log("main testing irqs");
serial_port com2(COM2);
const char *fgseq = "\x1b[2J";
while (*fgseq)
com2.write(*fgseq++);
for (int i = 0; i < 10; ++i)
com2.write('%');
size_t len = 0;
while (true) {
result = j6_endpoint_receive(endp, &tag, &len, nullptr);
if (result != j6_status_ok)
return result;
if (j6_tag_is_irq(tag))
j6_system_log("main thread got irq!");
}
j6_system_log("main thread closing endpoint");
result = j6_object_close(endp);
if (result != j6_status_ok)
return result;
j6_system_log("main thread done, exiting");
return 0;
return pid;
}

View File

@@ -0,0 +1,81 @@
section .bss
mymessage:
resq 1024
extern main
extern exit
section .text
global getpid
getpid:
push rbp
mov rbp, rsp
; address of out var should already be in rdi
mov rax, 0x13 ; getpid syscall
syscall ; result is now already in rax, so just return
pop rbp
ret
global debug
debug:
push rbp
mov rbp, rsp
mov rax, 0x00 ; debug syscall
syscall
pop rbp
ret
global sleep
sleep:
push rbp
mov rbp, rsp
mov rax, 0x16 ; sleep syscall
syscall
pop rbp
ret
global fork
fork:
push rbp
mov rbp, rsp
; address of out var should already be in rdi
mov rax, 0x12
syscall ; result left in rax
pop rbp
ret
global message
message:
push rbp
mov rbp, rsp
; message should already be in rdi
mov rax, 0x14
syscall
pop rbp
ret
global _start
_start:
xor rbp, rbp ; Sentinel rbp
push rbp
push rbp
mov rbp, rsp
mov rdi, 0
mov rsi, 0
call main
mov rdi, rax
call exit

View File

@@ -1,41 +0,0 @@
#include "io.h"
#include "serial.h"
serial_port::serial_port() :
m_port(0)
{
}
serial_port::serial_port(uint16_t port) :
m_port(port)
{
outb(port + 1, 0x00); // Disable all interrupts
outb(port + 3, 0x80); // Enable the Divisor Latch Access Bit
outb(port + 0, 0x01); // Divisor low bit: 1 (115200 baud)
outb(port + 1, 0x00); // Divisor high bit
outb(port + 3, 0x03); // 8-N-1
outb(port + 2, 0xe7); // Clear and enable FIFO, enable 64 byte, 56 byte trigger
outb(port + 4, 0x0b); // Data terminal ready, Request to send, aux output 2 (irq enable)
outb(port + 1, 0x03); // Enable interrupts
}
bool serial_port::read_ready() { return (inb(m_port + 5) & 0x01) != 0; }
bool serial_port::write_ready() {
uint8_t lsr = inb(m_port + 5);
return (lsr & 0x20) != 0;
}
char
serial_port::read() {
while (!read_ready());
return inb(m_port);
}
void
serial_port::write(char c) {
while (!write_ready());
outb(m_port, c);
}

View File

@@ -1,26 +0,0 @@
#pragma once
/// \file serial.h
/// Declarations related to serial ports.
#include <stdint.h>
#define serial_port nulldrv_serial_port
class serial_port
{
public:
/// Constructor.
/// \arg port The IO address of the serial port
serial_port(uint16_t port);
serial_port();
void write(char c);
char read();
private:
uint16_t m_port;
bool read_ready();
bool write_ready();
};

62
src/include/efi/efi.h Normal file
View File

@@ -0,0 +1,62 @@
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
efi.h
Abstract:
Public EFI header files
Revision History
--*/
// Add a predefined macro to detect usage of the library
#ifndef _GNU_EFI
#define _GNU_EFI
#endif
//
// Build flags on input
// EFI32
// EFI_DEBUG - Enable debugging code
// EFI_NT_EMULATOR - Building for running under NT
//
#ifndef _EFI_INCLUDE_
#define _EFI_INCLUDE_
#define EFI_FIRMWARE_VENDOR L"INTEL"
#define EFI_FIRMWARE_MAJOR_REVISION 12
#define EFI_FIRMWARE_MINOR_REVISION 33
#define EFI_FIRMWARE_REVISION ((EFI_FIRMWARE_MAJOR_REVISION <<16) | (EFI_FIRMWARE_MINOR_REVISION))
#include <efi/efibind.h>
#include <efi/eficompiler.h>
#include <efi/efidef.h>
#include <efi/efidevp.h>
#include <efi/efipciio.h>
#include <efi/efiprot.h>
#include <efi/eficon.h>
#include <efi/efiser.h>
#include <efi/efi_nii.h>
#include <efi/efipxebc.h>
#include <efi/efinet.h>
#include <efi/efiapi.h>
#include <efi/efifs.h>
#include <efi/efierr.h>
#include <efi/efiui.h>
#include <efi/efiip.h>
#include <efi/efiudp.h>
#include <efi/efitcp.h>
#include <efi/efipoint.h>
#include <efi/efisetjmp.h>
#endif

78
src/include/efi/efi_nii.h Normal file
View File

@@ -0,0 +1,78 @@
#ifndef _EFI_NII_H
#define _EFI_NII_H
/*++
Copyright (c) 2000 Intel Corporation
Module name:
efi_nii.h
Abstract:
Revision history:
2000-Feb-18 M(f)J GUID updated.
Structure order changed for machine word alignment.
Added StringId[4] to structure.
2000-Feb-14 M(f)J Genesis.
--*/
#define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID \
{ 0xE18541CD, 0xF755, 0x4f73, {0x92, 0x8D, 0x64, 0x3C, 0x8A, 0x79, 0xB2, 0x29} }
#define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION 0x00010000
#define EFI_NETWORK_INTERFACE_IDENTIFIER_INTERFACE_REVISION EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION
typedef enum {
EfiNetworkInterfaceUndi = 1
} EFI_NETWORK_INTERFACE_TYPE;
typedef struct _EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL {
UINT64 Revision;
// Revision of the network interface identifier protocol interface.
UINT64 ID;
// Address of the first byte of the identifying structure for this
// network interface. This is set to zero if there is no structure.
//
// For PXE/UNDI this is the first byte of the !PXE structure.
UINT64 ImageAddr;
// Address of the UNrelocated driver/ROM image. This is set
// to zero if there is no driver/ROM image.
//
// For 16-bit UNDI, this is the first byte of the option ROM in
// upper memory.
//
// For 32/64-bit S/W UNDI, this is the first byte of the EFI ROM
// image.
//
// For H/W UNDI, this is set to zero.
UINT32 ImageSize;
// Size of the UNrelocated driver/ROM image of this network interface.
// This is set to zero if there is no driver/ROM image.
CHAR8 StringId[4];
// 4 char ASCII string to go in class identifier (option 60) in DHCP
// and Boot Server discover packets.
// For EfiNetworkInterfaceUndi this field is "UNDI".
// For EfiNetworkInterfaceSnp this field is "SNPN".
UINT8 Type;
UINT8 MajorVer;
UINT8 MinorVer;
// Information to be placed into the PXE DHCP and Discover packets.
// This is the network interface type and version number that will
// be placed into DHCP option 94 (client network interface identifier).
BOOLEAN Ipv6Supported;
UINT8 IfNum; // interface number to be used with pxeid structure
} EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL, EFI_NETWORK_INTERFACE_IDENTIFIER_INTERFACE;
// Note: Because it conflicted with the EDK2 struct name, the
// 'EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL' GUID definition,
// from older versions of gnu-efi, is now obsoleted.
// Use 'EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID' instead.
#endif // _EFI_NII_H

1743
src/include/efi/efi_pxe.h Normal file

File diff suppressed because it is too large Load Diff

967
src/include/efi/efiapi.h Normal file
View File

@@ -0,0 +1,967 @@
#ifndef _EFI_API_H
#define _EFI_API_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
efiapi.h
Abstract:
Global EFI runtime & boot service interfaces
Revision History
--*/
//
// EFI Specification Revision
//
#define EFI_SPECIFICATION_MAJOR_REVISION 1
#define EFI_SPECIFICATION_MINOR_REVISION 02
//
// Declare forward referenced data structures
//
INTERFACE_DECL(_EFI_SYSTEM_TABLE);
//
// EFI Memory
//
typedef
EFI_STATUS
(EFIAPI *EFI_ALLOCATE_PAGES) (
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN NoPages,
OUT EFI_PHYSICAL_ADDRESS *Memory
);
typedef
EFI_STATUS
(EFIAPI *EFI_FREE_PAGES) (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages
);
typedef
EFI_STATUS
(EFIAPI *EFI_GET_MEMORY_MAP) (
IN OUT UINTN *MemoryMapSize,
IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,
OUT UINTN *MapKey,
OUT UINTN *DescriptorSize,
OUT UINT32 *DescriptorVersion
);
#define NextMemoryDescriptor(Ptr,Size) ((EFI_MEMORY_DESCRIPTOR *) (((UINT8 *) Ptr) + Size))
typedef
EFI_STATUS
(EFIAPI *EFI_ALLOCATE_POOL) (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN Size,
OUT VOID **Buffer
);
typedef
EFI_STATUS
(EFIAPI *EFI_FREE_POOL) (
IN VOID *Buffer
);
typedef
EFI_STATUS
(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP) (
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *VirtualMap
);
#define EFI_OPTIONAL_PTR 0x00000001
#define EFI_INTERNAL_FNC 0x00000002 // Pointer to internal runtime fnc
#define EFI_INTERNAL_PTR 0x00000004 // Pointer to internal runtime data
typedef
EFI_STATUS
(EFIAPI *EFI_CONVERT_POINTER) (
IN UINTN DebugDisposition,
IN OUT VOID **Address
);
//
// EFI Events
//
#define EVT_TIMER 0x80000000
#define EVT_RUNTIME 0x40000000
#define EVT_RUNTIME_CONTEXT 0x20000000
#define EVT_NOTIFY_WAIT 0x00000100
#define EVT_NOTIFY_SIGNAL 0x00000200
#define EVT_SIGNAL_EXIT_BOOT_SERVICES 0x00000201
#define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
#define EVT_EFI_SIGNAL_MASK 0x000000FF
#define EVT_EFI_SIGNAL_MAX 4
#define EFI_EVENT_TIMER EVT_TIMER
#define EFI_EVENT_RUNTIME EVT_RUNTIME
#define EFI_EVENT_RUNTIME_CONTEXT EVT_RUNTIME_CONTEXT
#define EFI_EVENT_NOTIFY_WAIT EVT_NOTIFY_WAIT
#define EFI_EVENT_NOTIFY_SIGNAL EVT_NOTIFY_SIGNAL
#define EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES EVT_SIGNAL_EXIT_BOOT_SERVICES
#define EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
#define EFI_EVENT_EFI_SIGNAL_MASK EVT_EFI_SIGNAL_MASK
#define EFI_EVENT_EFI_SIGNAL_MAX EVT_EFI_SIGNAL_MAX
typedef
VOID
(EFIAPI *EFI_EVENT_NOTIFY) (
IN EFI_EVENT Event,
IN VOID *Context
);
typedef
EFI_STATUS
(EFIAPI *EFI_CREATE_EVENT) (
IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction,
IN VOID *NotifyContext,
OUT EFI_EVENT *Event
);
typedef enum {
TimerCancel,
TimerPeriodic,
TimerRelative,
TimerTypeMax
} EFI_TIMER_DELAY;
typedef
EFI_STATUS
(EFIAPI *EFI_SET_TIMER) (
IN EFI_EVENT Event,
IN EFI_TIMER_DELAY Type,
IN UINT64 TriggerTime
);
typedef
EFI_STATUS
(EFIAPI *EFI_SIGNAL_EVENT) (
IN EFI_EVENT Event
);
typedef
EFI_STATUS
(EFIAPI *EFI_WAIT_FOR_EVENT) (
IN UINTN NumberOfEvents,
IN EFI_EVENT *Event,
OUT UINTN *Index
);
typedef
EFI_STATUS
(EFIAPI *EFI_CLOSE_EVENT) (
IN EFI_EVENT Event
);
typedef
EFI_STATUS
(EFIAPI *EFI_CHECK_EVENT) (
IN EFI_EVENT Event
);
//
// Task priority level
//
#define TPL_APPLICATION 4
#define TPL_CALLBACK 8
#define TPL_NOTIFY 16
#define TPL_HIGH_LEVEL 31
#define EFI_TPL_APPLICATION TPL_APPLICATION
#define EFI_TPL_CALLBACK TPL_CALLBACK
#define EFI_TPL_NOTIFY TPL_NOTIFY
#define EFI_TPL_HIGH_LEVEL TPL_HIGH_LEVEL
typedef
EFI_TPL
(EFIAPI *EFI_RAISE_TPL) (
IN EFI_TPL NewTpl
);
typedef
VOID
(EFIAPI *EFI_RESTORE_TPL) (
IN EFI_TPL OldTpl
);
//
// EFI platform varibles
//
#define EFI_GLOBAL_VARIABLE \
{ 0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C} }
// Variable attributes
#define EFI_VARIABLE_NON_VOLATILE 0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
#define EFI_VARIABLE_APPEND_WRITE 0x00000040
// Variable size limitation
#define EFI_MAXIMUM_VARIABLE_SIZE 1024
typedef
EFI_STATUS
(EFIAPI *EFI_GET_VARIABLE) (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN *DataSize,
OUT VOID *Data
);
typedef
EFI_STATUS
(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME) (
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid
);
typedef
EFI_STATUS
(EFIAPI *EFI_SET_VARIABLE) (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
);
//
// EFI Time
//
typedef struct {
UINT32 Resolution; // 1e-6 parts per million
UINT32 Accuracy; // hertz
BOOLEAN SetsToZero; // Set clears sub-second time
} EFI_TIME_CAPABILITIES;
typedef
EFI_STATUS
(EFIAPI *EFI_GET_TIME) (
OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_SET_TIME) (
IN EFI_TIME *Time
);
typedef
EFI_STATUS
(EFIAPI *EFI_GET_WAKEUP_TIME) (
OUT BOOLEAN *Enabled,
OUT BOOLEAN *Pending,
OUT EFI_TIME *Time
);
typedef
EFI_STATUS
(EFIAPI *EFI_SET_WAKEUP_TIME) (
IN BOOLEAN Enable,
IN EFI_TIME *Time OPTIONAL
);
//
// Image functions
//
// PE32+ Subsystem type for EFI images
#if !defined(IMAGE_SUBSYSTEM_EFI_APPLICATION)
#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
#endif
// PE32+ Machine type for EFI images
#if !defined(EFI_IMAGE_MACHINE_IA32)
#define EFI_IMAGE_MACHINE_IA32 0x014c
#endif
#if !defined(EFI_IMAGE_MACHINE_IA64)
#define EFI_IMAGE_MACHINE_IA64 0x0200
#endif
#if !defined(EFI_IMAGE_MACHINE_EBC)
#define EFI_IMAGE_MACHINE_EBC 0x0EBC
#endif
#if !defined(EFI_IMAGE_MACHINE_X64)
#define EFI_IMAGE_MACHINE_X64 0x8664
#endif
#if !defined(EFI_IMAGE_MACHINE_ARMTHUMB_MIXED)
#define EFI_IMAGE_MACHINE_ARMTHUMB_MIXED 0x01C2
#endif
#if !defined(EFI_IMAGE_MACHINE_AARCH64)
#define EFI_IMAGE_MACHINE_AARCH64 0xAA64
#endif
// Image Entry prototype
typedef
EFI_STATUS
(EFIAPI *EFI_IMAGE_ENTRY_POINT) (
IN EFI_HANDLE ImageHandle,
IN struct _EFI_SYSTEM_TABLE *SystemTable
);
typedef
EFI_STATUS
(EFIAPI *EFI_IMAGE_LOAD) (
IN BOOLEAN BootPolicy,
IN EFI_HANDLE ParentImageHandle,
IN EFI_DEVICE_PATH *FilePath,
IN VOID *SourceBuffer OPTIONAL,
IN UINTN SourceSize,
OUT EFI_HANDLE *ImageHandle
);
typedef
EFI_STATUS
(EFIAPI *EFI_IMAGE_START) (
IN EFI_HANDLE ImageHandle,
OUT UINTN *ExitDataSize,
OUT CHAR16 **ExitData OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_EXIT) (
IN EFI_HANDLE ImageHandle,
IN EFI_STATUS ExitStatus,
IN UINTN ExitDataSize,
IN CHAR16 *ExitData OPTIONAL
);
// Image handle
/*#define LOADED_IMAGE_PROTOCOL \
{ 0x5B1B31A1, 0x9562, 0x11d2, {0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B} }
#define EFI_IMAGE_INFORMATION_REVISION 0x1000
typedef struct {
UINT32 Revision;
EFI_HANDLE ParentHandle;
struct _EFI_SYSTEM_TABLE *SystemTable;
// Source location of image
EFI_HANDLE DeviceHandle;
EFI_DEVICE_PATH *FilePath;
VOID *Reserved;
// Images load options
UINT32 LoadOptionsSize;
VOID *LoadOptions;
// Location of where image was loaded
VOID *ImageBase;
UINT64 ImageSize;
EFI_MEMORY_TYPE ImageCodeType;
EFI_MEMORY_TYPE ImageDataType;
// If the driver image supports a dynamic unload request
EFI_IMAGE_UNLOAD Unload;
} EFI_LOADED_IMAGE;*/
typedef
EFI_STATUS
(EFIAPI *EFI_EXIT_BOOT_SERVICES) (
IN EFI_HANDLE ImageHandle,
IN UINTN MapKey
);
//
// Misc
//
typedef
EFI_STATUS
(EFIAPI *EFI_STALL) (
IN UINTN Microseconds
);
typedef
EFI_STATUS
(EFIAPI *EFI_SET_WATCHDOG_TIMER) (
IN UINTN Timeout,
IN UINT64 WatchdogCode,
IN UINTN DataSize,
IN CHAR16 *WatchdogData OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_CONNECT_CONTROLLER) (
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE *DriverImageHandle OPTIONAL,
IN EFI_DEVICE_PATH *RemainingDevicePath OPTIONAL,
IN BOOLEAN Recursive
);
typedef
EFI_STATUS
(EFIAPI *EFI_DISCONNECT_CONTROLLER) (
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE DriverImageHandle OPTIONAL,
IN EFI_HANDLE ChildHandle OPTIONAL
);
#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002
#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004
#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010
#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020
typedef
EFI_STATUS
(EFIAPI *EFI_OPEN_PROTOCOL) (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
OUT VOID **Interface OPTIONAL,
IN EFI_HANDLE AgentHandle,
IN EFI_HANDLE ControllerHandle,
IN UINT32 Attributes
);
typedef
EFI_STATUS
(EFIAPI *EFI_CLOSE_PROTOCOL) (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
IN EFI_HANDLE AgentHandle,
IN EFI_HANDLE ControllerHandle
);
typedef struct {
EFI_HANDLE AgentHandle;
EFI_HANDLE ControllerHandle;
UINT32 Attributes;
UINT32 OpenCount;
} EFI_OPEN_PROTOCOL_INFORMATION_ENTRY;
typedef
EFI_STATUS
(EFIAPI *EFI_OPEN_PROTOCOL_INFORMATION) (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
OUT UINTN *EntryCount
);
typedef
EFI_STATUS
(EFIAPI *EFI_PROTOCOLS_PER_HANDLE) (
IN EFI_HANDLE Handle,
OUT EFI_GUID ***ProtocolBuffer,
OUT UINTN *ProtocolBufferCount
);
typedef enum {
AllHandles,
ByRegisterNotify,
ByProtocol
} EFI_LOCATE_SEARCH_TYPE;
typedef
EFI_STATUS
(EFIAPI *EFI_LOCATE_HANDLE_BUFFER) (
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *NoHandles,
OUT EFI_HANDLE **Buffer
);
typedef
EFI_STATUS
(EFIAPI *EFI_LOCATE_PROTOCOL) (
IN EFI_GUID *Protocol,
IN VOID *Registration OPTIONAL,
OUT VOID **Interface
);
typedef
EFI_STATUS
(EFIAPI *EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
IN OUT EFI_HANDLE *Handle,
...
);
typedef
EFI_STATUS
(EFIAPI *EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
IN OUT EFI_HANDLE Handle,
...
);
typedef
EFI_STATUS
(EFIAPI *EFI_CALCULATE_CRC32) (
IN VOID *Data,
IN UINTN DataSize,
OUT UINT32 *Crc32
);
typedef
VOID
(EFIAPI *EFI_COPY_MEM) (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
);
typedef
VOID
(EFIAPI *EFI_SET_MEM) (
IN VOID *Buffer,
IN UINTN Size,
IN UINT8 Value
);
typedef
EFI_STATUS
(EFIAPI *EFI_CREATE_EVENT_EX) (
IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN const VOID *NotifyContext OPTIONAL,
IN const EFI_GUID EventGroup OPTIONAL,
OUT EFI_EVENT *Event
);
typedef enum {
EfiResetCold,
EfiResetWarm,
EfiResetShutdown
} EFI_RESET_TYPE;
typedef
EFI_STATUS
(EFIAPI *EFI_RESET_SYSTEM) (
IN EFI_RESET_TYPE ResetType,
IN EFI_STATUS ResetStatus,
IN UINTN DataSize,
IN CHAR16 *ResetData OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT) (
OUT UINT64 *Count
);
typedef
EFI_STATUS
(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT) (
OUT UINT32 *HighCount
);
typedef struct {
UINT64 Length;
union {
EFI_PHYSICAL_ADDRESS DataBlock;
EFI_PHYSICAL_ADDRESS ContinuationPointer;
} Union;
} EFI_CAPSULE_BLOCK_DESCRIPTOR;
typedef struct {
EFI_GUID CapsuleGuid;
UINT32 HeaderSize;
UINT32 Flags;
UINT32 CapsuleImageSize;
} EFI_CAPSULE_HEADER;
#define CAPSULE_FLAGS_PERSIST_ACROSS_RESET 0x00010000
#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000
#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000
typedef
EFI_STATUS
(EFIAPI *EFI_UPDATE_CAPSULE) (
IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
IN UINTN CapsuleCount,
IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES) (
IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
IN UINTN CapsuleCount,
OUT UINT64 *MaximumCapsuleSize,
OUT EFI_RESET_TYPE *ResetType
);
typedef
EFI_STATUS
(EFIAPI *EFI_QUERY_VARIABLE_INFO) (
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize
);
//
// Protocol handler functions
//
typedef enum {
EFI_NATIVE_INTERFACE,
EFI_PCODE_INTERFACE
} EFI_INTERFACE_TYPE;
typedef
EFI_STATUS
(EFIAPI *EFI_INSTALL_PROTOCOL_INTERFACE) (
IN OUT EFI_HANDLE *Handle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface
);
typedef
EFI_STATUS
(EFIAPI *EFI_REINSTALL_PROTOCOL_INTERFACE) (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
IN VOID *OldInterface,
IN VOID *NewInterface
);
typedef
EFI_STATUS
(EFIAPI *EFI_UNINSTALL_PROTOCOL_INTERFACE) (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
);
typedef
EFI_STATUS
(EFIAPI *EFI_HANDLE_PROTOCOL) (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
OUT VOID **Interface
);
typedef
EFI_STATUS
(EFIAPI *EFI_REGISTER_PROTOCOL_NOTIFY) (
IN EFI_GUID *Protocol,
IN EFI_EVENT Event,
OUT VOID **Registration
);
typedef
EFI_STATUS
(EFIAPI *EFI_LOCATE_HANDLE) (
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer
);
typedef
EFI_STATUS
(EFIAPI *EFI_LOCATE_DEVICE_PATH) (
IN EFI_GUID *Protocol,
IN OUT EFI_DEVICE_PATH **DevicePath,
OUT EFI_HANDLE *Device
);
typedef
EFI_STATUS
(EFIAPI *EFI_INSTALL_CONFIGURATION_TABLE) (
IN EFI_GUID *Guid,
IN VOID *Table
);
typedef
EFI_STATUS
(EFIAPI *EFI_RESERVED_SERVICE) (
);
//
// Standard EFI table header
//
typedef struct _EFI_TABLE_HEADER {
UINT64 Signature;
UINT32 Revision;
UINT32 HeaderSize;
UINT32 CRC32;
UINT32 Reserved;
} EFI_TABLE_HEADER;
//
// EFI Runtime Serivces Table
//
#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552
#define EFI_RUNTIME_SERVICES_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION)
typedef struct {
EFI_TABLE_HEADER Hdr;
//
// Time services
//
EFI_GET_TIME GetTime;
EFI_SET_TIME SetTime;
EFI_GET_WAKEUP_TIME GetWakeupTime;
EFI_SET_WAKEUP_TIME SetWakeupTime;
//
// Virtual memory services
//
EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap;
EFI_CONVERT_POINTER ConvertPointer;
//
// Variable serviers
//
EFI_GET_VARIABLE GetVariable;
EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName;
EFI_SET_VARIABLE SetVariable;
//
// Misc
//
EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount;
EFI_RESET_SYSTEM ResetSystem;
EFI_UPDATE_CAPSULE UpdateCapsule;
EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;
EFI_QUERY_VARIABLE_INFO QueryVariableInfo;
} EFI_RUNTIME_SERVICES;
//
// EFI Boot Services Table
//
#define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
#define EFI_BOOT_SERVICES_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION)
typedef struct _EFI_BOOT_SERVICES {
EFI_TABLE_HEADER Hdr;
//
// Task priority functions
//
EFI_RAISE_TPL RaiseTPL;
EFI_RESTORE_TPL RestoreTPL;
//
// Memory functions
//
EFI_ALLOCATE_PAGES AllocatePages;
EFI_FREE_PAGES FreePages;
EFI_GET_MEMORY_MAP GetMemoryMap;
EFI_ALLOCATE_POOL AllocatePool;
EFI_FREE_POOL FreePool;
//
// Event & timer functions
//
EFI_CREATE_EVENT CreateEvent;
EFI_SET_TIMER SetTimer;
EFI_WAIT_FOR_EVENT WaitForEvent;
EFI_SIGNAL_EVENT SignalEvent;
EFI_CLOSE_EVENT CloseEvent;
EFI_CHECK_EVENT CheckEvent;
//
// Protocol handler functions
//
EFI_INSTALL_PROTOCOL_INTERFACE InstallProtocolInterface;
EFI_REINSTALL_PROTOCOL_INTERFACE ReinstallProtocolInterface;
EFI_UNINSTALL_PROTOCOL_INTERFACE UninstallProtocolInterface;
EFI_HANDLE_PROTOCOL HandleProtocol;
EFI_HANDLE_PROTOCOL PCHandleProtocol;
EFI_REGISTER_PROTOCOL_NOTIFY RegisterProtocolNotify;
EFI_LOCATE_HANDLE LocateHandle;
EFI_LOCATE_DEVICE_PATH LocateDevicePath;
EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable;
//
// Image functions
//
EFI_IMAGE_LOAD LoadImage;
EFI_IMAGE_START StartImage;
EFI_EXIT Exit;
EFI_IMAGE_UNLOAD UnloadImage;
EFI_EXIT_BOOT_SERVICES ExitBootServices;
//
// Misc functions
//
EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount;
EFI_STALL Stall;
EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;
//
// DriverSupport Services
//
EFI_CONNECT_CONTROLLER ConnectController;
EFI_DISCONNECT_CONTROLLER DisconnectController;
//
// Open and Close Protocol Services
//
EFI_OPEN_PROTOCOL OpenProtocol;
EFI_CLOSE_PROTOCOL CloseProtocol;
EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation;
//
// Library Services
//
EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle;
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer;
EFI_LOCATE_PROTOCOL LocateProtocol;
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces;
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces;
//
// 32-bit CRC Services
//
EFI_CALCULATE_CRC32 CalculateCrc32;
//
// Misc Services
//
EFI_COPY_MEM CopyMem;
EFI_SET_MEM SetMem;
EFI_CREATE_EVENT_EX CreateEventEx;
} EFI_BOOT_SERVICES;
//
// EFI Configuration Table and GUID definitions
//
#define MPS_TABLE_GUID \
{ 0xeb9d2d2f, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
#define ACPI_TABLE_GUID \
{ 0xeb9d2d30, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
#define ACPI_20_TABLE_GUID \
{ 0x8868e871, 0xe4f1, 0x11d3, {0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81} }
#define SMBIOS_TABLE_GUID \
{ 0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
#define SMBIOS3_TABLE_GUID \
{ 0xf2fd1544, 0x9794, 0x4a2c, {0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94} }
#define SAL_SYSTEM_TABLE_GUID \
{ 0xeb9d2d32, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
typedef struct _EFI_CONFIGURATION_TABLE {
EFI_GUID VendorGuid;
VOID *VendorTable;
} EFI_CONFIGURATION_TABLE;
//
// EFI System Table
//
#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
#define EFI_SYSTEM_TABLE_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION)
typedef struct _EFI_SYSTEM_TABLE {
EFI_TABLE_HEADER Hdr;
CHAR16 *FirmwareVendor;
UINT32 FirmwareRevision;
EFI_HANDLE ConsoleInHandle;
SIMPLE_INPUT_INTERFACE *ConIn;
EFI_HANDLE ConsoleOutHandle;
SIMPLE_TEXT_OUTPUT_INTERFACE *ConOut;
EFI_HANDLE StandardErrorHandle;
SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr;
EFI_RUNTIME_SERVICES *RuntimeServices;
EFI_BOOT_SERVICES *BootServices;
UINTN NumberOfTableEntries;
EFI_CONFIGURATION_TABLE *ConfigurationTable;
} EFI_SYSTEM_TABLE;
#endif

View File

@@ -0,0 +1,30 @@
/*++
Copyright (c) 2016 Pete Batard <pete@akeo.ie>
Module Name:
eficompiler.h
Abstract:
Compiler specific adjustments
--*/
#ifdef _MSC_EXTENSIONS
#define EFI_UNUSED
#else
#define EFI_UNUSED __attribute__((__unused__))
#endif
#ifdef _MSC_EXTENSIONS
#define ALIGN(x) __declspec(align(x))
#else
#define ALIGN(x) __attribute__((__aligned__(x)))
#endif
/* Also add a catch-all on __attribute__() for MS compilers */
#ifdef _MSC_EXTENSIONS
#define __attribute__(x)
#endif

306
src/include/efi/eficon.h Normal file
View File

@@ -0,0 +1,306 @@
#ifndef _EFI_CON_H
#define _EFI_CON_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
eficon.h
Abstract:
EFI console protocols
Revision History
--*/
//
// Text output protocol
//
#define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \
{ 0x387477c2, 0x69c7, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
#define SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID
INTERFACE_DECL(_SIMPLE_TEXT_OUTPUT_INTERFACE);
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_RESET) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
IN BOOLEAN ExtendedVerification
);
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_OUTPUT_STRING) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
IN CHAR16 *String
);
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_TEST_STRING) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
IN CHAR16 *String
);
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_QUERY_MODE) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
IN UINTN ModeNumber,
OUT UINTN *Columns,
OUT UINTN *Rows
);
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_SET_MODE) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
IN UINTN ModeNumber
);
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_SET_ATTRIBUTE) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
IN UINTN Attribute
);
#define EFI_BLACK 0x00
#define EFI_BLUE 0x01
#define EFI_GREEN 0x02
#define EFI_CYAN (EFI_BLUE | EFI_GREEN)
#define EFI_RED 0x04
#define EFI_MAGENTA (EFI_BLUE | EFI_RED)
#define EFI_BROWN (EFI_GREEN | EFI_RED)
#define EFI_LIGHTGRAY (EFI_BLUE | EFI_GREEN | EFI_RED)
#define EFI_BRIGHT 0x08
#define EFI_DARKGRAY (EFI_BRIGHT)
#define EFI_LIGHTBLUE (EFI_BLUE | EFI_BRIGHT)
#define EFI_LIGHTGREEN (EFI_GREEN | EFI_BRIGHT)
#define EFI_LIGHTCYAN (EFI_CYAN | EFI_BRIGHT)
#define EFI_LIGHTRED (EFI_RED | EFI_BRIGHT)
#define EFI_LIGHTMAGENTA (EFI_MAGENTA | EFI_BRIGHT)
#define EFI_YELLOW (EFI_BROWN | EFI_BRIGHT)
#define EFI_WHITE (EFI_BLUE | EFI_GREEN | EFI_RED | EFI_BRIGHT)
#define EFI_TEXT_ATTR(f,b) ((f) | ((b) << 4))
#define EFI_BACKGROUND_BLACK 0x00
#define EFI_BACKGROUND_BLUE 0x10
#define EFI_BACKGROUND_GREEN 0x20
#define EFI_BACKGROUND_CYAN (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_GREEN)
#define EFI_BACKGROUND_RED 0x40
#define EFI_BACKGROUND_MAGENTA (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_RED)
#define EFI_BACKGROUND_BROWN (EFI_BACKGROUND_GREEN | EFI_BACKGROUND_RED)
#define EFI_BACKGROUND_LIGHTGRAY (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_GREEN | EFI_BACKGROUND_RED)
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_CLEAR_SCREEN) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This
);
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_SET_CURSOR_POSITION) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
IN UINTN Column,
IN UINTN Row
);
typedef
EFI_STATUS
(EFIAPI *EFI_TEXT_ENABLE_CURSOR) (
IN struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
IN BOOLEAN Enable
);
typedef struct {
INT32 MaxMode;
// current settings
INT32 Mode;
INT32 Attribute;
INT32 CursorColumn;
INT32 CursorRow;
BOOLEAN CursorVisible;
} SIMPLE_TEXT_OUTPUT_MODE;
typedef struct _SIMPLE_TEXT_OUTPUT_INTERFACE {
EFI_TEXT_RESET Reset;
EFI_TEXT_OUTPUT_STRING OutputString;
EFI_TEXT_TEST_STRING TestString;
EFI_TEXT_QUERY_MODE QueryMode;
EFI_TEXT_SET_MODE SetMode;
EFI_TEXT_SET_ATTRIBUTE SetAttribute;
EFI_TEXT_CLEAR_SCREEN ClearScreen;
EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition;
EFI_TEXT_ENABLE_CURSOR EnableCursor;
// Current mode
SIMPLE_TEXT_OUTPUT_MODE *Mode;
} SIMPLE_TEXT_OUTPUT_INTERFACE, EFI_SIMPLE_TEXT_OUT_PROTOCOL;
//
// Define's for required EFI Unicode Box Draw character
//
#define BOXDRAW_HORIZONTAL 0x2500
#define BOXDRAW_VERTICAL 0x2502
#define BOXDRAW_DOWN_RIGHT 0x250c
#define BOXDRAW_DOWN_LEFT 0x2510
#define BOXDRAW_UP_RIGHT 0x2514
#define BOXDRAW_UP_LEFT 0x2518
#define BOXDRAW_VERTICAL_RIGHT 0x251c
#define BOXDRAW_VERTICAL_LEFT 0x2524
#define BOXDRAW_DOWN_HORIZONTAL 0x252c
#define BOXDRAW_UP_HORIZONTAL 0x2534
#define BOXDRAW_VERTICAL_HORIZONTAL 0x253c
#define BOXDRAW_DOUBLE_HORIZONTAL 0x2550
#define BOXDRAW_DOUBLE_VERTICAL 0x2551
#define BOXDRAW_DOWN_RIGHT_DOUBLE 0x2552
#define BOXDRAW_DOWN_DOUBLE_RIGHT 0x2553
#define BOXDRAW_DOUBLE_DOWN_RIGHT 0x2554
#define BOXDRAW_DOWN_LEFT_DOUBLE 0x2555
#define BOXDRAW_DOWN_DOUBLE_LEFT 0x2556
#define BOXDRAW_DOUBLE_DOWN_LEFT 0x2557
#define BOXDRAW_UP_RIGHT_DOUBLE 0x2558
#define BOXDRAW_UP_DOUBLE_RIGHT 0x2559
#define BOXDRAW_DOUBLE_UP_RIGHT 0x255a
#define BOXDRAW_UP_LEFT_DOUBLE 0x255b
#define BOXDRAW_UP_DOUBLE_LEFT 0x255c
#define BOXDRAW_DOUBLE_UP_LEFT 0x255d
#define BOXDRAW_VERTICAL_RIGHT_DOUBLE 0x255e
#define BOXDRAW_VERTICAL_DOUBLE_RIGHT 0x255f
#define BOXDRAW_DOUBLE_VERTICAL_RIGHT 0x2560
#define BOXDRAW_VERTICAL_LEFT_DOUBLE 0x2561
#define BOXDRAW_VERTICAL_DOUBLE_LEFT 0x2562
#define BOXDRAW_DOUBLE_VERTICAL_LEFT 0x2563
#define BOXDRAW_DOWN_HORIZONTAL_DOUBLE 0x2564
#define BOXDRAW_DOWN_DOUBLE_HORIZONTAL 0x2565
#define BOXDRAW_DOUBLE_DOWN_HORIZONTAL 0x2566
#define BOXDRAW_UP_HORIZONTAL_DOUBLE 0x2567
#define BOXDRAW_UP_DOUBLE_HORIZONTAL 0x2568
#define BOXDRAW_DOUBLE_UP_HORIZONTAL 0x2569
#define BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE 0x256a
#define BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL 0x256b
#define BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL 0x256c
//
// EFI Required Block Elements Code Chart
//
#define BLOCKELEMENT_FULL_BLOCK 0x2588
#define BLOCKELEMENT_LIGHT_SHADE 0x2591
//
// EFI Required Geometric Shapes Code Chart
//
#define GEOMETRICSHAPE_UP_TRIANGLE 0x25b2
#define GEOMETRICSHAPE_RIGHT_TRIANGLE 0x25ba
#define GEOMETRICSHAPE_DOWN_TRIANGLE 0x25bc
#define GEOMETRICSHAPE_LEFT_TRIANGLE 0x25c4
//
// EFI Required Arrow shapes
//
#define ARROW_UP 0x2191
#define ARROW_DOWN 0x2193
//
// Text input protocol
//
#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \
{ 0x387477c1, 0x69c7, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
#define SIMPLE_TEXT_INPUT_PROTOCOL EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID
INTERFACE_DECL(_SIMPLE_INPUT_INTERFACE);
typedef struct {
UINT16 ScanCode;
CHAR16 UnicodeChar;
} EFI_INPUT_KEY;
//
// Baseline unicode control chars
//
#define CHAR_NULL 0x0000
#define CHAR_BACKSPACE 0x0008
#define CHAR_TAB 0x0009
#define CHAR_LINEFEED 0x000A
#define CHAR_CARRIAGE_RETURN 0x000D
//
// Scan codes for base line keys
//
#define SCAN_NULL 0x0000
#define SCAN_UP 0x0001
#define SCAN_DOWN 0x0002
#define SCAN_RIGHT 0x0003
#define SCAN_LEFT 0x0004
#define SCAN_HOME 0x0005
#define SCAN_END 0x0006
#define SCAN_INSERT 0x0007
#define SCAN_DELETE 0x0008
#define SCAN_PAGE_UP 0x0009
#define SCAN_PAGE_DOWN 0x000A
#define SCAN_F1 0x000B
#define SCAN_F2 0x000C
#define SCAN_F3 0x000D
#define SCAN_F4 0x000E
#define SCAN_F5 0x000F
#define SCAN_F6 0x0010
#define SCAN_F7 0x0011
#define SCAN_F8 0x0012
#define SCAN_F9 0x0013
#define SCAN_F10 0x0014
#define SCAN_F11 0x0015
#define SCAN_F12 0x0016
#define SCAN_ESC 0x0017
typedef
EFI_STATUS
(EFIAPI *EFI_INPUT_RESET) (
IN struct _SIMPLE_INPUT_INTERFACE *This,
IN BOOLEAN ExtendedVerification
);
typedef
EFI_STATUS
(EFIAPI *EFI_INPUT_READ_KEY) (
IN struct _SIMPLE_INPUT_INTERFACE *This,
OUT EFI_INPUT_KEY *Key
);
typedef struct _SIMPLE_INPUT_INTERFACE {
EFI_INPUT_RESET Reset;
EFI_INPUT_READ_KEY ReadKeyStroke;
EFI_EVENT WaitForKey;
} SIMPLE_INPUT_INTERFACE, EFI_SIMPLE_TEXT_IN_PROTOCOL;
#endif

620
src/include/efi/efidebug.h Normal file
View File

@@ -0,0 +1,620 @@
#ifndef _EFI_DEBUG_H
#define _EFI_DEBUG_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
efidebug.h
Abstract:
EFI library debug functions
Revision History
--*/
extern UINTN EFIDebug;
#if EFI_DEBUG
#define DBGASSERT(a) DbgAssert(__FILE__, __LINE__, #a)
#define DEBUG(a) DbgPrint a
#else
#define DBGASSERT(a)
#define DEBUG(a)
#endif
#if EFI_DEBUG_CLEAR_MEMORY
#define DBGSETMEM(a,l) SetMem(a,l,(CHAR8)BAD_POINTER)
#else
#define DBGSETMEM(a,l)
#endif
#define D_INIT 0x00000001 // Initialization style messages
#define D_WARN 0x00000002 // Warnings
#define D_LOAD 0x00000004 // Load events
#define D_FS 0x00000008 // EFI File system
#define D_POOL 0x00000010 // Alloc & Free's
#define D_PAGE 0x00000020 // Alloc & Free's
#define D_INFO 0x00000040 // Verbose
#define D_VAR 0x00000100 // Variable
#define D_PARSE 0x00000200 // Command parsing
#define D_BM 0x00000400 // Boot manager
#define D_BLKIO 0x00001000 // BlkIo Driver
#define D_BLKIO_ULTRA 0x00002000 // BlkIo Driver
#define D_NET 0x00004000 // SNI Driver
#define D_NET_ULTRA 0x00008000 // SNI Driver
#define D_TXTIN 0x00010000 // Simple Input Driver
#define D_TXTOUT 0x00020000 // Simple Text Output Driver
#define D_ERROR_ATA 0x00040000 // ATA error messages
#define D_ERROR 0x80000000 // Error
#define D_RESERVED 0x7fffC880 // Bits not reserved above
//
// Current Debug level of the system, value of EFIDebug
//
//#define EFI_DBUG_MASK (D_ERROR | D_WARN | D_LOAD | D_BLKIO | D_INIT)
#define EFI_DBUG_MASK (D_ERROR)
//
//
//
#if EFI_DEBUG
#define ASSERT(a) if(!(a)) DBGASSERT(a)
#define ASSERT_LOCKED(l) if(!(l)->Lock) DBGASSERT(l not locked)
#define ASSERT_STRUCT(p,t) DBGASSERT(t not structure), p
#else
#define ASSERT(a)
#define ASSERT_LOCKED(l)
#define ASSERT_STRUCT(p,t)
#endif
//
// Prototypes
//
INTN
DbgAssert (
CONST CHAR8 *file,
INTN lineno,
CONST CHAR8 *string
);
INTN
DbgPrint (
INTN mask,
CONST CHAR8 *format,
...
);
//
// Instruction Set Architectures definitions for debuggers
//
typedef INTN EFI_EXCEPTION_TYPE;
// IA32
#define EXCEPT_IA32_DIVIDE_ERROR 0
#define EXCEPT_IA32_DEBUG 1
#define EXCEPT_IA32_NMI 2
#define EXCEPT_IA32_BREAKPOINT 3
#define EXCEPT_IA32_OVERFLOW 4
#define EXCEPT_IA32_BOUND 5
#define EXCEPT_IA32_INVALID_OPCODE 6
#define EXCEPT_IA32_DOUBLE_FAULT 8
#define EXCEPT_IA32_INVALID_TSS 10
#define EXCEPT_IA32_SEG_NOT_PRESENT 11
#define EXCEPT_IA32_STACK_FAULT 12
#define EXCEPT_IA32_GP_FAULT 13
#define EXCEPT_IA32_PAGE_FAULT 14
#define EXCEPT_IA32_FP_ERROR 16
#define EXCEPT_IA32_ALIGNMENT_CHECK 17
#define EXCEPT_IA32_MACHINE_CHECK 18
#define EXCEPT_IA32_SIMD 19
typedef struct {
UINT16 Fcw;
UINT16 Fsw;
UINT16 Ftw;
UINT16 Opcode;
UINT32 Eip;
UINT16 Cs;
UINT16 Reserved1;
UINT32 DataOffset;
UINT16 Ds;
UINT8 Reserved2[10];
UINT8 St0Mm0[10], Reserved3[6];
UINT8 St1Mm1[10], Reserved4[6];
UINT8 St2Mm2[10], Reserved5[6];
UINT8 St3Mm3[10], Reserved6[6];
UINT8 St4Mm4[10], Reserved7[6];
UINT8 St5Mm5[10], Reserved8[6];
UINT8 St6Mm6[10], Reserved9[6];
UINT8 St7Mm7[10], Reserved10[6];
UINT8 Xmm0[16];
UINT8 Xmm1[16];
UINT8 Xmm2[16];
UINT8 Xmm3[16];
UINT8 Xmm4[16];
UINT8 Xmm5[16];
UINT8 Xmm6[16];
UINT8 Xmm7[16];
UINT8 Reserved11[14 * 16];
} EFI_FX_SAVE_STATE_IA32;
typedef struct {
UINT32 ExceptionData;
EFI_FX_SAVE_STATE_IA32 FxSaveState;
UINT32 Dr0;
UINT32 Dr1;
UINT32 Dr2;
UINT32 Dr3;
UINT32 Dr6;
UINT32 Dr7;
UINT32 Cr0;
UINT32 Cr1;
UINT32 Cr2;
UINT32 Cr3;
UINT32 Cr4;
UINT32 Eflags;
UINT32 Ldtr;
UINT32 Tr;
UINT32 Gdtr[2];
UINT32 Idtr[2];
UINT32 Eip;
UINT32 Gs;
UINT32 Fs;
UINT32 Es;
UINT32 Ds;
UINT32 Cs;
UINT32 Ss;
UINT32 Edi;
UINT32 Esi;
UINT32 Ebp;
UINT32 Esp;
UINT32 Ebx;
UINT32 Edx;
UINT32 Ecx;
UINT32 Eax;
} EFI_SYSTEM_CONTEXT_IA32;
// X64
#define EXCEPT_X64_DIVIDE_ERROR 0
#define EXCEPT_X64_DEBUG 1
#define EXCEPT_X64_NMI 2
#define EXCEPT_X64_BREAKPOINT 3
#define EXCEPT_X64_OVERFLOW 4
#define EXCEPT_X64_BOUND 5
#define EXCEPT_X64_INVALID_OPCODE 6
#define EXCEPT_X64_DOUBLE_FAULT 8
#define EXCEPT_X64_INVALID_TSS 10
#define EXCEPT_X64_SEG_NOT_PRESENT 11
#define EXCEPT_X64_STACK_FAULT 12
#define EXCEPT_X64_GP_FAULT 13
#define EXCEPT_X64_PAGE_FAULT 14
#define EXCEPT_X64_FP_ERROR 16
#define EXCEPT_X64_ALIGNMENT_CHECK 17
#define EXCEPT_X64_MACHINE_CHECK 18
#define EXCEPT_X64_SIMD 19
typedef struct {
UINT16 Fcw;
UINT16 Fsw;
UINT16 Ftw;
UINT16 Opcode;
UINT64 Rip;
UINT64 DataOffset;
UINT8 Reserved1[8];
UINT8 St0Mm0[10], Reserved2[6];
UINT8 St1Mm1[10], Reserved3[6];
UINT8 St2Mm2[10], Reserved4[6];
UINT8 St3Mm3[10], Reserved5[6];
UINT8 St4Mm4[10], Reserved6[6];
UINT8 St5Mm5[10], Reserved7[6];
UINT8 St6Mm6[10], Reserved8[6];
UINT8 St7Mm7[10], Reserved9[6];
UINT8 Xmm0[16];
UINT8 Xmm1[16];
UINT8 Xmm2[16];
UINT8 Xmm3[16];
UINT8 Xmm4[16];
UINT8 Xmm5[16];
UINT8 Xmm6[16];
UINT8 Xmm7[16];
UINT8 Reserved11[14 * 16];
} EFI_FX_SAVE_STATE_X64;
typedef struct {
UINT64 ExceptionData;
EFI_FX_SAVE_STATE_X64 FxSaveState;
UINT64 Dr0;
UINT64 Dr1;
UINT64 Dr2;
UINT64 Dr3;
UINT64 Dr6;
UINT64 Dr7;
UINT64 Cr0;
UINT64 Cr1;
UINT64 Cr2;
UINT64 Cr3;
UINT64 Cr4;
UINT64 Cr8;
UINT64 Rflags;
UINT64 Ldtr;
UINT64 Tr;
UINT64 Gdtr[2];
UINT64 Idtr[2];
UINT64 Rip;
UINT64 Gs;
UINT64 Fs;
UINT64 Es;
UINT64 Ds;
UINT64 Cs;
UINT64 Ss;
UINT64 Rdi;
UINT64 Rsi;
UINT64 Rbp;
UINT64 Rsp;
UINT64 Rbx;
UINT64 Rdx;
UINT64 Rcx;
UINT64 Rax;
UINT64 R8;
UINT64 R9;
UINT64 R10;
UINT64 R11;
UINT64 R12;
UINT64 R13;
UINT64 R14;
UINT64 R15;
} EFI_SYSTEM_CONTEXT_X64;
/// IA64
#define EXCEPT_IPF_VHTP_TRANSLATION 0
#define EXCEPT_IPF_INSTRUCTION_TLB 1
#define EXCEPT_IPF_DATA_TLB 2
#define EXCEPT_IPF_ALT_INSTRUCTION_TLB 3
#define EXCEPT_IPF_ALT_DATA_TLB 4
#define EXCEPT_IPF_DATA_NESTED_TLB 5
#define EXCEPT_IPF_INSTRUCTION_KEY_MISSED 6
#define EXCEPT_IPF_DATA_KEY_MISSED 7
#define EXCEPT_IPF_DIRTY_BIT 8
#define EXCEPT_IPF_INSTRUCTION_ACCESS_BIT 9
#define EXCEPT_IPF_DATA_ACCESS_BIT 10
#define EXCEPT_IPF_BREAKPOINT 11
#define EXCEPT_IPF_EXTERNAL_INTERRUPT 12
#define EXCEPT_IPF_PAGE_NOT_PRESENT 20
#define EXCEPT_IPF_KEY_PERMISSION 21
#define EXCEPT_IPF_INSTRUCTION_ACCESS_RIGHTS 22
#define EXCEPT_IPF_DATA_ACCESS_RIGHTS 23
#define EXCEPT_IPF_GENERAL_EXCEPTION 24
#define EXCEPT_IPF_DISABLED_FP_REGISTER 25
#define EXCEPT_IPF_NAT_CONSUMPTION 26
#define EXCEPT_IPF_SPECULATION 27
#define EXCEPT_IPF_DEBUG 29
#define EXCEPT_IPF_UNALIGNED_REFERENCE 30
#define EXCEPT_IPF_UNSUPPORTED_DATA_REFERENCE 31
#define EXCEPT_IPF_FP_FAULT 32
#define EXCEPT_IPF_FP_TRAP 33
#define EXCEPT_IPF_LOWER_PRIVILEGE_TRANSFER_TRAP 34
#define EXCEPT_IPF_TAKEN_BRANCH 35
#define EXCEPT_IPF_SINGLE_STEP 36
#define EXCEPT_IPF_IA32_EXCEPTION 45
#define EXCEPT_IPF_IA32_INTERCEPT 46
#define EXCEPT_IPF_IA32_INTERRUPT 47
typedef struct {
UINT64 Reserved;
UINT64 R1;
UINT64 R2;
UINT64 R3;
UINT64 R4;
UINT64 R5;
UINT64 R6;
UINT64 R7;
UINT64 R8;
UINT64 R9;
UINT64 R10;
UINT64 R11;
UINT64 R12;
UINT64 R13;
UINT64 R14;
UINT64 R15;
UINT64 R16;
UINT64 R17;
UINT64 R18;
UINT64 R19;
UINT64 R20;
UINT64 R21;
UINT64 R22;
UINT64 R23;
UINT64 R24;
UINT64 R25;
UINT64 R26;
UINT64 R27;
UINT64 R28;
UINT64 R29;
UINT64 R30;
UINT64 R31;
UINT64 F2[2];
UINT64 F3[2];
UINT64 F4[2];
UINT64 F5[2];
UINT64 F6[2];
UINT64 F7[2];
UINT64 F8[2];
UINT64 F9[2];
UINT64 F10[2];
UINT64 F11[2];
UINT64 F12[2];
UINT64 F13[2];
UINT64 F14[2];
UINT64 F15[2];
UINT64 F16[2];
UINT64 F17[2];
UINT64 F18[2];
UINT64 F19[2];
UINT64 F20[2];
UINT64 F21[2];
UINT64 F22[2];
UINT64 F23[2];
UINT64 F24[2];
UINT64 F25[2];
UINT64 F26[2];
UINT64 F27[2];
UINT64 F28[2];
UINT64 F29[2];
UINT64 F30[2];
UINT64 F31[2];
UINT64 Pr;
UINT64 B0;
UINT64 B1;
UINT64 B2;
UINT64 B3;
UINT64 B4;
UINT64 B5;
UINT64 B6;
UINT64 B7;
UINT64 ArRsc;
UINT64 ArBsp;
UINT64 ArBspstore;
UINT64 ArRnat;
UINT64 ArFcr;
UINT64 ArEflag;
UINT64 ArCsd;
UINT64 ArSsd;
UINT64 ArCflg;
UINT64 ArFsr;
UINT64 ArFir;
UINT64 ArFdr;
UINT64 ArCcv;
UINT64 ArUnat;
UINT64 ArFpsr;
UINT64 ArPfs;
UINT64 ArLc;
UINT64 ArEc;
UINT64 CrDcr;
UINT64 CrItm;
UINT64 CrIva;
UINT64 CrPta;
UINT64 CrIpsr;
UINT64 CrIsr;
UINT64 CrIip;
UINT64 CrIfa;
UINT64 CrItir;
UINT64 CrIipa;
UINT64 CrIfs;
UINT64 CrIim;
UINT64 CrIha;
UINT64 Dbr0;
UINT64 Dbr1;
UINT64 Dbr2;
UINT64 Dbr3;
UINT64 Dbr4;
UINT64 Dbr5;
UINT64 Dbr6;
UINT64 Dbr7;
UINT64 Ibr0;
UINT64 Ibr1;
UINT64 Ibr2;
UINT64 Ibr3;
UINT64 Ibr4;
UINT64 Ibr5;
UINT64 Ibr6;
UINT64 Ibr7;
UINT64 IntNat;
} EFI_SYSTEM_CONTEXT_IPF;
// EBC
#define EXCEPT_EBC_UNDEFINED 0
#define EXCEPT_EBC_DIVIDE_ERROR 1
#define EXCEPT_EBC_DEBUG 2
#define EXCEPT_EBC_BREAKPOINT 3
#define EXCEPT_EBC_OVERFLOW 4
#define EXCEPT_EBC_INVALID_OPCODE 5
#define EXCEPT_EBC_STACK_FAULT 6
#define EXCEPT_EBC_ALIGNMENT_CHECK 7
#define EXCEPT_EBC_INSTRUCTION_ENCODING 8
#define EXCEPT_EBC_BAD_BREAK 9
#define EXCEPT_EBC_STEP 10
#define MAX_EBC_EXCEPTION EXCEPT_EBC_STEP
typedef struct {
UINT64 R0;
UINT64 R1;
UINT64 R2;
UINT64 R3;
UINT64 R4;
UINT64 R5;
UINT64 R6;
UINT64 R7;
UINT64 Flags;
UINT64 ControlFlags;
UINT64 Ip;
} EFI_SYSTEM_CONTEXT_EBC;
// ARM
#define EXCEPT_ARM_RESET 0
#define EXCEPT_ARM_UNDEFINED_INSTRUCTION 1
#define EXCEPT_ARM_SOFTWARE_INTERRUPT 2
#define EXCEPT_ARM_PREFETCH_ABORT 3
#define EXCEPT_ARM_DATA_ABORT 4
#define EXCEPT_ARM_RESERVED 5
#define EXCEPT_ARM_IRQ 6
#define EXCEPT_ARM_FIQ 7
#define MAX_ARM_EXCEPTION EXCEPT_ARM_FIQ
typedef struct {
UINT32 R0;
UINT32 R1;
UINT32 R2;
UINT32 R3;
UINT32 R4;
UINT32 R5;
UINT32 R6;
UINT32 R7;
UINT32 R8;
UINT32 R9;
UINT32 R10;
UINT32 R11;
UINT32 R12;
UINT32 SP;
UINT32 LR;
UINT32 PC;
UINT32 CPSR;
UINT32 DFSR;
UINT32 DFAR;
UINT32 IFSR;
UINT32 IFAR;
} EFI_SYSTEM_CONTEXT_ARM;
typedef union {
EFI_SYSTEM_CONTEXT_EBC *SystemContextEbc;
EFI_SYSTEM_CONTEXT_IA32 *SystemContextIa32;
EFI_SYSTEM_CONTEXT_X64 *SystemContextX64;
EFI_SYSTEM_CONTEXT_IPF *SystemContextIpf;
EFI_SYSTEM_CONTEXT_ARM *SystemContextArm;
} EFI_SYSTEM_CONTEXT;
typedef
VOID
(EFIAPI *EFI_EXCEPTION_CALLBACK)(
IN EFI_EXCEPTION_TYPE ExceptionType,
IN OUT EFI_SYSTEM_CONTEXT SystemContext);
typedef
VOID
(EFIAPI *EFI_PERIODIC_CALLBACK)(
IN OUT EFI_SYSTEM_CONTEXT SystemContext);
typedef enum {
IsaIa32 = EFI_IMAGE_MACHINE_IA32,
IsaX64 = EFI_IMAGE_MACHINE_X64,
IsaIpf = EFI_IMAGE_MACHINE_IA64,
IsaEbc = EFI_IMAGE_MACHINE_EBC,
IsaArm = EFI_IMAGE_MACHINE_ARMTHUMB_MIXED,
// IsaArm64 = EFI_IMAGE_MACHINE_AARCH64
} EFI_INSTRUCTION_SET_ARCHITECTURE;
//
// DEBUG_IMAGE_INFO
//
#define EFI_DEBUG_IMAGE_INFO_TABLE_GUID \
{ 0x49152e77, 0x1ada, 0x4764, {0xb7, 0xa2, 0x7a, 0xfe, 0xfe, 0xd9, 0x5e, 0x8b} }
#define EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS 0x01
#define EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED 0x02
#define EFI_DEBUG_IMAGE_INFO_INITIAL_SIZE (EFI_PAGE_SIZE / sizeof (UINTN))
#define EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL 0x01
typedef struct {
UINT64 Signature;
EFI_PHYSICAL_ADDRESS EfiSystemTableBase;
UINT32 Crc32;
} EFI_SYSTEM_TABLE_POINTER;
typedef struct {
UINT32 ImageInfoType;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolInstance;
EFI_HANDLE *ImageHandle;
} EFI_DEBUG_IMAGE_INFO_NORMAL;
typedef union {
UINT32 *ImageInfoType;
EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage;
} EFI_DEBUG_IMAGE_INFO;
typedef struct {
volatile UINT32 UpdateStatus;
UINT32 TableSize;
EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
} EFI_DEBUG_IMAGE_INFO_TABLE_HEADER;
//
// EFI_DEBUGGER_PROTOCOL
//
#define EFI_DEBUG_SUPPORT_PROTOCOL_GUID \
{ 0x2755590c, 0x6f3c, 0x42fa, {0x9e, 0xa4, 0xa3, 0xba, 0x54, 0x3c, 0xda, 0x25} }
INTERFACE_DECL(_EFI_DEBUG_SUPPORT_PROTOCOL);
typedef
EFI_STATUS
(EFIAPI *EFI_GET_MAXIMUM_PROCESSOR_INDEX)(
IN struct _EFI_DEBUG_SUPPORT_PROTOCOL *This,
OUT UINTN *MaxProcessorIndex);
typedef
EFI_STATUS
(EFIAPI *EFI_REGISTER_PERIODIC_CALLBACK)(
IN struct _EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_PERIODIC_CALLBACK PeriodicCallback);
typedef
EFI_STATUS
(EFIAPI *EFI_REGISTER_EXCEPTION_CALLBACK)(
IN struct _EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_EXCEPTION_CALLBACK ExceptionCallback,
IN EFI_EXCEPTION_TYPE ExceptionType);
typedef
EFI_STATUS
(EFIAPI *EFI_INVALIDATE_INSTRUCTION_CACHE)(
IN struct _EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN VOID *Start,
IN UINT64 Length);
typedef struct _EFI_DEBUG_SUPPORT_PROTOCOL {
EFI_INSTRUCTION_SET_ARCHITECTURE Isa;
EFI_GET_MAXIMUM_PROCESSOR_INDEX GetMaximumProcessorIndex;
EFI_REGISTER_PERIODIC_CALLBACK RegisterPeriodicCallback;
EFI_REGISTER_EXCEPTION_CALLBACK RegisterExceptionCallback;
EFI_INVALIDATE_INSTRUCTION_CACHE InvalidateInstructionCache;
} EFI_DEBUG_SUPPORT_PROTOCOL;
#endif

220
src/include/efi/efidef.h Normal file
View File

@@ -0,0 +1,220 @@
#ifndef _EFI_DEF_H
#define _EFI_DEF_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
efidef.h
Abstract:
EFI definitions
Revision History
--*/
typedef wchar_t CHAR16;
typedef char CHAR8;
typedef uint8_t BOOLEAN;
#ifndef CONST
#define CONST const
#endif
#ifndef TRUE
#define TRUE ((BOOLEAN) 1)
#define FALSE ((BOOLEAN) 0)
#endif
#ifndef NULL
#define NULL ((VOID *) 0)
#endif
typedef UINTN EFI_STATUS;
typedef UINT64 EFI_LBA;
typedef UINTN EFI_TPL;
typedef VOID *EFI_HANDLE;
typedef VOID *EFI_EVENT;
//
// Prototype argument decoration for EFI parameters to indicate
// their direction
//
// IN - argument is passed into the function
// OUT - argument (pointer) is returned from the function
// OPTIONAL - argument is optional
//
#ifndef IN
#define IN
#define OUT
#define OPTIONAL
#endif
//
// A GUID
//
typedef struct {
UINT32 Data1;
UINT16 Data2;
UINT16 Data3;
UINT8 Data4[8];
} EFI_GUID;
//
// Time
//
typedef struct {
UINT16 Year; // 1998 - 20XX
UINT8 Month; // 1 - 12
UINT8 Day; // 1 - 31
UINT8 Hour; // 0 - 23
UINT8 Minute; // 0 - 59
UINT8 Second; // 0 - 59
UINT8 Pad1;
UINT32 Nanosecond; // 0 - 999,999,999
INT16 TimeZone; // -1440 to 1440 or 2047
UINT8 Daylight;
UINT8 Pad2;
} EFI_TIME;
// Bit definitions for EFI_TIME.Daylight
#define EFI_TIME_ADJUST_DAYLIGHT 0x01
#define EFI_TIME_IN_DAYLIGHT 0x02
// Value definition for EFI_TIME.TimeZone
#define EFI_UNSPECIFIED_TIMEZONE 0x07FF
//
// Networking
//
typedef struct {
UINT8 Addr[4];
} EFI_IPv4_ADDRESS;
typedef struct {
UINT8 Addr[16];
} EFI_IPv6_ADDRESS;
typedef struct {
UINT8 Addr[32];
} EFI_MAC_ADDRESS;
typedef struct {
UINT32 ReceivedQueueTimeoutValue;
UINT32 TransmitQueueTimeoutValue;
UINT16 ProtocolTypeFilter;
BOOLEAN EnableUnicastReceive;
BOOLEAN EnableMulticastReceive;
BOOLEAN EnableBroadcastReceive;
BOOLEAN EnablePromiscuousReceive;
BOOLEAN FlushQueuesOnReset;
BOOLEAN EnableReceiveTimestamps;
BOOLEAN DisableBackgroundPolling;
} EFI_MANAGED_NETWORK_CONFIG_DATA;
//
// Memory
//
typedef UINT64 EFI_PHYSICAL_ADDRESS;
typedef UINT64 EFI_VIRTUAL_ADDRESS;
typedef enum {
AllocateAnyPages,
AllocateMaxAddress,
AllocateAddress,
MaxAllocateType
} EFI_ALLOCATE_TYPE;
//Preseve the attr on any range supplied.
//ConventialMemory must have WB,SR,SW when supplied.
//When allocating from ConventialMemory always make it WB,SR,SW
//When returning to ConventialMemory always make it WB,SR,SW
//When getting the memory map, or on RT for runtime types
typedef enum {
EfiReservedMemoryType,
EfiLoaderCode,
EfiLoaderData,
EfiBootServicesCode,
EfiBootServicesData,
EfiRuntimeServicesCode,
EfiRuntimeServicesData,
EfiConventionalMemory,
EfiUnusableMemory,
EfiACPIReclaimMemory,
EfiACPIMemoryNVS,
EfiMemoryMappedIO,
EfiMemoryMappedIOPortSpace,
EfiPalCode,
EfiMaxMemoryType
} EFI_MEMORY_TYPE;
// possible caching types for the memory range
#define EFI_MEMORY_UC 0x0000000000000001
#define EFI_MEMORY_WC 0x0000000000000002
#define EFI_MEMORY_WT 0x0000000000000004
#define EFI_MEMORY_WB 0x0000000000000008
#define EFI_MEMORY_UCE 0x0000000000000010
// physical memory protection on range
#define EFI_MEMORY_WP 0x0000000000001000
#define EFI_MEMORY_RP 0x0000000000002000
#define EFI_MEMORY_XP 0x0000000000004000
// range requires a runtime mapping
#define EFI_MEMORY_RUNTIME 0x8000000000000000
#define EFI_MEMORY_DESCRIPTOR_VERSION 1
typedef struct {
UINT32 Type; // Field size is 32 bits followed by 32 bit pad
UINT32 Pad;
EFI_PHYSICAL_ADDRESS PhysicalStart; // Field size is 64 bits
EFI_VIRTUAL_ADDRESS VirtualStart; // Field size is 64 bits
UINT64 NumberOfPages; // Field size is 64 bits
UINT64 Attribute; // Field size is 64 bits
} EFI_MEMORY_DESCRIPTOR;
//
// International Language
//
typedef UINT8 ISO_639_2;
#define ISO_639_2_ENTRY_SIZE 3
//
//
//
#define EFI_PAGE_SIZE 4096
#define EFI_PAGE_MASK 0xFFF
#define EFI_PAGE_SHIFT 12
#define EFI_SIZE_TO_PAGES(a) \
( ((a) >> EFI_PAGE_SHIFT) + ((a) & EFI_PAGE_MASK ? 1 : 0) )
#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001
#define EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION 0x0000000000000002
#define EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED \
0x0000000000000004
#define EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED \
0x0000000000000008
#define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED \
0x0000000000000010
#endif

582
src/include/efi/efidevp.h Normal file
View File

@@ -0,0 +1,582 @@
#ifndef _DEVPATH_H
#define _DEVPATH_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
devpath.h
Abstract:
Defines for parsing the EFI Device Path structures
Revision History
--*/
//
// Device Path structures - Section C
//
typedef struct _EFI_DEVICE_PATH_PROTOCOL {
UINT8 Type;
UINT8 SubType;
UINT8 Length[2];
} EFI_DEVICE_PATH_PROTOCOL;
typedef struct _EFI_DEVICE_PATH_PROTOCOL _EFI_DEVICE_PATH;
typedef EFI_DEVICE_PATH_PROTOCOL EFI_DEVICE_PATH;
#define EFI_DP_TYPE_MASK 0x7F
#define EFI_DP_TYPE_UNPACKED 0x80
//#define END_DEVICE_PATH_TYPE 0xff
#define END_DEVICE_PATH_TYPE 0x7f
//#define END_DEVICE_PATH_TYPE_UNPACKED 0x7f
#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff
#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01
#define END_DEVICE_PATH_LENGTH (sizeof(EFI_DEVICE_PATH_PROTOCOL))
#define DP_IS_END_TYPE(a)
#define DP_IS_END_SUBTYPE(a) ( ((a)->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE )
#define DevicePathType(a) ( ((a)->Type) & EFI_DP_TYPE_MASK )
#define DevicePathSubType(a) ( (a)->SubType )
#define DevicePathNodeLength(a) ( ((a)->Length[0]) | ((a)->Length[1] << 8) )
#define NextDevicePathNode(a) ( (EFI_DEVICE_PATH_PROTOCOL *) ( ((UINT8 *) (a)) + DevicePathNodeLength(a)))
//#define IsDevicePathEndType(a) ( DevicePathType(a) == END_DEVICE_PATH_TYPE_UNPACKED )
#define IsDevicePathEndType(a) ( DevicePathType(a) == END_DEVICE_PATH_TYPE )
#define IsDevicePathEndSubType(a) ( (a)->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE )
#define IsDevicePathEnd(a) ( IsDevicePathEndType(a) && IsDevicePathEndSubType(a) )
#define IsDevicePathUnpacked(a) ( (a)->Type & EFI_DP_TYPE_UNPACKED )
#define SetDevicePathNodeLength(a,l) { \
(a)->Length[0] = (UINT8) (l); \
(a)->Length[1] = (UINT8) ((l) >> 8); \
}
#define SetDevicePathEndNode(a) { \
(a)->Type = END_DEVICE_PATH_TYPE; \
(a)->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; \
(a)->Length[0] = sizeof(EFI_DEVICE_PATH_PROTOCOL); \
(a)->Length[1] = 0; \
}
/*
* Hardware Device Path (UEFI 2.4 specification, version 2.4 § 9.3.2.)
*/
#define HARDWARE_DEVICE_PATH 0x01
#define HW_PCI_DP 0x01
typedef struct _PCI_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT8 Function;
UINT8 Device;
} PCI_DEVICE_PATH;
#define HW_PCCARD_DP 0x02
typedef struct _PCCARD_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT8 FunctionNumber ;
} PCCARD_DEVICE_PATH;
#define HW_MEMMAP_DP 0x03
typedef struct _MEMMAP_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 MemoryType;
EFI_PHYSICAL_ADDRESS StartingAddress;
EFI_PHYSICAL_ADDRESS EndingAddress;
} MEMMAP_DEVICE_PATH;
#define HW_VENDOR_DP 0x04
typedef struct _VENDOR_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
EFI_GUID Guid;
} VENDOR_DEVICE_PATH;
#define UNKNOWN_DEVICE_GUID \
{ 0xcf31fac5, 0xc24e, 0x11d2, {0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b} }
typedef struct _UKNOWN_DEVICE_VENDOR_DP {
VENDOR_DEVICE_PATH DevicePath;
UINT8 LegacyDriveLetter;
} UNKNOWN_DEVICE_VENDOR_DEVICE_PATH;
#define HW_CONTROLLER_DP 0x05
typedef struct _CONTROLLER_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 Controller;
} CONTROLLER_DEVICE_PATH;
/*
* ACPI Device Path (UEFI 2.4 specification, version 2.4 § 9.3.3 and 9.3.4.)
*/
#define ACPI_DEVICE_PATH 0x02
#define ACPI_DP 0x01
typedef struct _ACPI_HID_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 HID;
UINT32 UID;
} ACPI_HID_DEVICE_PATH;
#define EXPANDED_ACPI_DP 0x02
typedef struct _EXPANDED_ACPI_HID_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 HID;
UINT32 UID;
UINT32 CID;
UINT8 HidStr[1];
} EXPANDED_ACPI_HID_DEVICE_PATH;
#define ACPI_ADR_DP 3
typedef struct _ACPI_ADR_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
UINT32 ADR ;
} ACPI_ADR_DEVICE_PATH ;
//
// EISA ID Macro
// EISA ID Definition 32-bits
// bits[15:0] - three character compressed ASCII EISA ID.
// bits[31:16] - binary number
// Compressed ASCII is 5 bits per character 0b00001 = 'A' 0b11010 = 'Z'
//
#define PNP_EISA_ID_CONST 0x41d0
#define EISA_ID(_Name, _Num) ((UINT32) ((_Name) | (_Num) << 16))
#define EISA_PNP_ID(_PNPId) (EISA_ID(PNP_EISA_ID_CONST, (_PNPId)))
#define PNP_EISA_ID_MASK 0xffff
#define EISA_ID_TO_NUM(_Id) ((_Id) >> 16)
/*
* Messaging Device Path (UEFI 2.4 specification, version 2.4 § 9.3.5.)
*/
#define MESSAGING_DEVICE_PATH 0x03
#define MSG_ATAPI_DP 0x01
typedef struct _ATAPI_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT8 PrimarySecondary;
UINT8 SlaveMaster;
UINT16 Lun;
} ATAPI_DEVICE_PATH;
#define MSG_SCSI_DP 0x02
typedef struct _SCSI_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT16 Pun;
UINT16 Lun;
} SCSI_DEVICE_PATH;
#define MSG_FIBRECHANNEL_DP 0x03
typedef struct _FIBRECHANNEL_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 Reserved;
UINT64 WWN;
UINT64 Lun;
} FIBRECHANNEL_DEVICE_PATH;
/**
* Fibre Channel Ex SubType.
* UEFI 2.0 specification version 2.4 § 9.3.5.6.
*/
#define MSG_FIBRECHANNELEX_DP 21
typedef struct _FIBRECHANNELEX_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
UINT32 Reserved ;
UINT8 WWN[ 8 ] ; /* World Wide Name */
UINT8 Lun[ 8 ] ; /* Logical unit, T-10 SCSI Architecture Model 4 specification */
} FIBRECHANNELEX_DEVICE_PATH ;
#define MSG_1394_DP 0x04
typedef struct _F1394_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 Reserved;
UINT64 Guid;
} F1394_DEVICE_PATH;
#define MSG_USB_DP 0x05
typedef struct _USB_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT8 Port;
UINT8 Endpoint;
} USB_DEVICE_PATH;
/**
* SATA Device Path SubType.
* UEFI 2.0 specification version 2.4 § 9.3.5.6.
*/
#define MSG_SATA_DP 18
typedef struct _SATA_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
UINT16 HBAPortNumber ;
UINT16 PortMultiplierPortNumber ;
UINT16 Lun ; /* Logical Unit Number */
} SATA_DEVICE_PATH ;
/**
* USB WWID Device Path SubType.
* UEFI 2.0 specification version 2.4 § 9.3.5.7.
*/
#define MSG_USB_WWID_DP 16
typedef struct _USB_WWID_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
UINT16 InterfaceNumber ;
UINT16 VendorId ;
UINT16 ProductId ;
CHAR16 SerialNumber[ 1 ] ; /* UTF-16 characters of the USB serial number */
} USB_WWID_DEVICE_PATH ;
/**
* Device Logical Unit SubType.
* UEFI 2.0 specification version 2.4 § 9.3.5.8.
*/
#define MSG_DEVICE_LOGICAL_UNIT_DP 17
typedef struct _DEVICE_LOGICAL_UNIT_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
UINT8 Lun ; /* Logical Unit Number */
} DEVICE_LOGICAL_UNIT_DEVICE_PATH ;
#define MSG_USB_CLASS_DP 0x0F
typedef struct _USB_CLASS_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT16 VendorId;
UINT16 ProductId;
UINT8 DeviceClass;
UINT8 DeviceSubclass;
UINT8 DeviceProtocol;
} USB_CLASS_DEVICE_PATH;
#define MSG_I2O_DP 0x06
typedef struct _I2O_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 Tid;
} I2O_DEVICE_PATH;
#define MSG_MAC_ADDR_DP 0x0b
typedef struct _MAC_ADDR_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
EFI_MAC_ADDRESS MacAddress;
UINT8 IfType;
} MAC_ADDR_DEVICE_PATH;
#define MSG_IPv4_DP 0x0c
typedef struct _IPv4_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
EFI_IPv4_ADDRESS LocalIpAddress;
EFI_IPv4_ADDRESS RemoteIpAddress;
UINT16 LocalPort;
UINT16 RemotePort;
UINT16 Protocol;
BOOLEAN StaticIpAddress;
/* new from UEFI version 2, code must check Length field in Header */
EFI_IPv4_ADDRESS GatewayIpAddress ;
EFI_IPv4_ADDRESS SubnetMask ;
} IPv4_DEVICE_PATH;
#define MSG_IPv6_DP 0x0d
typedef struct _IPv6_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
EFI_IPv6_ADDRESS LocalIpAddress;
EFI_IPv6_ADDRESS RemoteIpAddress;
UINT16 LocalPort;
UINT16 RemotePort;
UINT16 Protocol;
BOOLEAN IPAddressOrigin ;
/* new from UEFI version 2, code must check Length field in Header */
UINT8 PrefixLength ;
EFI_IPv6_ADDRESS GatewayIpAddress ;
} IPv6_DEVICE_PATH;
/**
* Uniform Resource Identifiers SubType.
* UEFI 2.0 specification version 2.4C § 9.3.5.23.
*/
#define MSG_URI_DP 24
typedef struct _URI_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
CHAR8 Uri[1];
} URI_DEVICE_PATH;
/**
* Device Logical Unit SubType.
* UEFI 2.0 specification version 2.4 § 9.3.5.8.
*/
#define MSG_VLAN_DP 20
typedef struct _VLAN_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
UINT16 VlanId ;
} VLAN_DEVICE_PATH;
#define MSG_INFINIBAND_DP 0x09
typedef struct _INFINIBAND_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 ResourceFlags ;
UINT64 PortGid ;
UINT64 ServiceId ;
UINT64 TargetPortId ;
UINT64 DeviceId ;
} INFINIBAND_DEVICE_PATH;
#define MSG_UART_DP 0x0e
typedef struct _UART_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 Reserved;
UINT64 BaudRate;
UINT8 DataBits;
UINT8 Parity;
UINT8 StopBits;
} UART_DEVICE_PATH;
#define MSG_VENDOR_DP 0x0A
/* Use VENDOR_DEVICE_PATH struct */
#define EFI_PC_ANSI_GUID \
{ 0xe0c14753, 0xf9be, 0x11d2, {0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
#define DEVICE_PATH_MESSAGING_PC_ANSI EFI_PC_ANSI_GUID
#define EFI_VT_100_GUID \
{ 0xdfa66065, 0xb419, 0x11d3, {0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
#define DEVICE_PATH_MESSAGING_VT_100 EFI_VT_100_GUID
#define EFI_VT_100_PLUS_GUID \
{ 0x7baec70b, 0x57e0, 0x4c76, {0x8e, 0x87, 0x2f, 0x9e, 0x28, 0x08, 0x83, 0x43} }
#define DEVICE_PATH_MESSAGING_VT_100_PLUS EFI_VT_100_PLUS_GUID
#define EFI_VT_UTF8_GUID \
{ 0xad15a0d6, 0x8bec, 0x4acf, {0xa0, 0x73, 0xd0, 0x1d, 0xe7, 0x7e, 0x2d, 0x88} }
#define DEVICE_PATH_MESSAGING_VT_UTF8 EFI_VT_UTF8_GUID
/*
* Media Device Path (UEFI 2.4 specification, version 2.4 § 9.3.6.)
*/
#define MEDIA_DEVICE_PATH 0x04
#define MEDIA_HARDDRIVE_DP 0x01
typedef struct _HARDDRIVE_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 PartitionNumber;
UINT64 PartitionStart;
UINT64 PartitionSize;
UINT8 Signature[16];
UINT8 MBRType;
UINT8 SignatureType;
} HARDDRIVE_DEVICE_PATH;
#define MBR_TYPE_PCAT 0x01
#define MBR_TYPE_EFI_PARTITION_TABLE_HEADER 0x02
#define SIGNATURE_TYPE_MBR 0x01
#define SIGNATURE_TYPE_GUID 0x02
#define MEDIA_CDROM_DP 0x02
typedef struct _CDROM_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT32 BootEntry;
UINT64 PartitionStart;
UINT64 PartitionSize;
} CDROM_DEVICE_PATH;
#define MEDIA_VENDOR_DP 0x03
/* Use VENDOR_DEVICE_PATH struct */
#define MEDIA_FILEPATH_DP 0x04
typedef struct _FILEPATH_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
CHAR16 PathName[1];
} FILEPATH_DEVICE_PATH;
#define SIZE_OF_FILEPATH_DEVICE_PATH EFI_FIELD_OFFSET(FILEPATH_DEVICE_PATH,PathName)
#define MEDIA_PROTOCOL_DP 0x05
typedef struct _MEDIA_PROTOCOL_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
EFI_GUID Protocol;
} MEDIA_PROTOCOL_DEVICE_PATH;
/**
* PIWG Firmware File SubType.
* UEFI 2.0 specification version 2.4 § 9.3.6.6.
*/
#define MEDIA_PIWG_FW_FILE_DP 6
typedef struct _MEDIA_FW_VOL_FILEPATH_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
EFI_GUID FvFileName ;
} MEDIA_FW_VOL_FILEPATH_DEVICE_PATH ;
/**
* PIWG Firmware Volume Device Path SubType.
* UEFI 2.0 specification version 2.4 § 9.3.6.7.
*/
#define MEDIA_PIWG_FW_VOL_DP 7
typedef struct _MEDIA_FW_VOL_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
EFI_GUID FvName ;
} MEDIA_FW_VOL_DEVICE_PATH ;
/**
* Media relative offset range device path.
* UEFI 2.0 specification version 2.4 § 9.3.6.8.
*/
#define MEDIA_RELATIVE_OFFSET_RANGE_DP 8
typedef struct _MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header ;
UINT32 Reserved ;
UINT64 StartingOffset ;
UINT64 EndingOffset ;
} MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH ;
/*
* BIOS Boot Specification Device Path (UEFI 2.4 specification, version 2.4 § 9.3.7.)
*/
#define BBS_DEVICE_PATH 0x05
#define BBS_BBS_DP 0x01
typedef struct _BBS_BBS_DEVICE_PATH {
EFI_DEVICE_PATH_PROTOCOL Header;
UINT16 DeviceType;
UINT16 StatusFlag;
CHAR8 String[1];
} BBS_BBS_DEVICE_PATH;
/* DeviceType definitions - from BBS specification */
#define BBS_TYPE_FLOPPY 0x01
#define BBS_TYPE_HARDDRIVE 0x02
#define BBS_TYPE_CDROM 0x03
#define BBS_TYPE_PCMCIA 0x04
#define BBS_TYPE_USB 0x05
#define BBS_TYPE_EMBEDDED_NETWORK 0x06
#define BBS_TYPE_DEV 0x80
#define BBS_TYPE_UNKNOWN 0xFF
typedef union {
EFI_DEVICE_PATH_PROTOCOL DevPath;
PCI_DEVICE_PATH Pci;
PCCARD_DEVICE_PATH PcCard;
MEMMAP_DEVICE_PATH MemMap;
VENDOR_DEVICE_PATH Vendor;
UNKNOWN_DEVICE_VENDOR_DEVICE_PATH UnknownVendor;
CONTROLLER_DEVICE_PATH Controller;
ACPI_HID_DEVICE_PATH Acpi;
ATAPI_DEVICE_PATH Atapi;
SCSI_DEVICE_PATH Scsi;
FIBRECHANNEL_DEVICE_PATH FibreChannel;
F1394_DEVICE_PATH F1394;
USB_DEVICE_PATH Usb;
USB_CLASS_DEVICE_PATH UsbClass;
I2O_DEVICE_PATH I2O;
MAC_ADDR_DEVICE_PATH MacAddr;
IPv4_DEVICE_PATH Ipv4;
IPv6_DEVICE_PATH Ipv6;
URI_DEVICE_PATH Uri;
INFINIBAND_DEVICE_PATH InfiniBand;
UART_DEVICE_PATH Uart;
HARDDRIVE_DEVICE_PATH HardDrive;
CDROM_DEVICE_PATH CD;
FILEPATH_DEVICE_PATH FilePath;
MEDIA_PROTOCOL_DEVICE_PATH MediaProtocol;
BBS_BBS_DEVICE_PATH Bbs;
} EFI_DEV_PATH;
typedef union {
EFI_DEVICE_PATH_PROTOCOL *DevPath;
PCI_DEVICE_PATH *Pci;
PCCARD_DEVICE_PATH *PcCard;
MEMMAP_DEVICE_PATH *MemMap;
VENDOR_DEVICE_PATH *Vendor;
UNKNOWN_DEVICE_VENDOR_DEVICE_PATH *UnknownVendor;
CONTROLLER_DEVICE_PATH *Controller;
ACPI_HID_DEVICE_PATH *Acpi;
ATAPI_DEVICE_PATH *Atapi;
SCSI_DEVICE_PATH *Scsi;
FIBRECHANNEL_DEVICE_PATH *FibreChannel;
F1394_DEVICE_PATH *F1394;
USB_DEVICE_PATH *Usb;
USB_CLASS_DEVICE_PATH *UsbClass;
I2O_DEVICE_PATH *I2O;
MAC_ADDR_DEVICE_PATH *MacAddr;
IPv4_DEVICE_PATH *Ipv4;
IPv6_DEVICE_PATH *Ipv6;
URI_DEVICE_PATH *Uri;
INFINIBAND_DEVICE_PATH *InfiniBand;
UART_DEVICE_PATH *Uart;
HARDDRIVE_DEVICE_PATH *HardDrive;
FILEPATH_DEVICE_PATH *FilePath;
MEDIA_PROTOCOL_DEVICE_PATH *MediaProtocol;
CDROM_DEVICE_PATH *CD;
BBS_BBS_DEVICE_PATH *Bbs;
} EFI_DEV_PATH_PTR;
#define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
{ 0x8b843e20, 0x8132, 0x4852, {0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c} }
typedef
CHAR16*
(EFIAPI *EFI_DEVICE_PATH_TO_TEXT_NODE) (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
IN BOOLEAN DisplayOnly,
IN BOOLEAN AllowShortcuts
);
typedef
CHAR16*
(EFIAPI *EFI_DEVICE_PATH_TO_TEXT_PATH) (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN BOOLEAN DisplayOnly,
IN BOOLEAN AllowShortcuts
);
typedef struct _EFI_DEVICE_PATH_TO_TEXT_PROTOCOL {
EFI_DEVICE_PATH_TO_TEXT_NODE ConvertDeviceNodeToText;
EFI_DEVICE_PATH_TO_TEXT_PATH ConvertDevicePathToText;
} EFI_DEVICE_PATH_TO_TEXT_PROTOCOL;
#define EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID \
{ 0x5c99a21, 0xc70f, 0x4ad2, {0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e} }
typedef
EFI_DEVICE_PATH_PROTOCOL*
(EFIAPI *EFI_DEVICE_PATH_FROM_TEXT_NODE) (
IN CONST CHAR16 *TextDeviceNode
);
typedef
EFI_DEVICE_PATH_PROTOCOL*
(EFIAPI *EFI_DEVICE_PATH_FROM_TEXT_PATH) (
IN CONST CHAR16 *TextDevicePath
);
typedef struct {
EFI_DEVICE_PATH_FROM_TEXT_NODE ConvertTextToDeviceNode;
EFI_DEVICE_PATH_FROM_TEXT_PATH ConvertTextToDevicePath;
} EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL;
#endif

67
src/include/efi/efierr.h Normal file
View File

@@ -0,0 +1,67 @@
#ifndef _EFI_ERR_H
#define _EFI_ERR_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
efierr.h
Abstract:
EFI error codes
Revision History
--*/
#define EFIWARN(a) (a)
#define EFI_ERROR(a) (((INTN) a) < 0)
#define EFI_SUCCESS 0
#define EFI_LOAD_ERROR EFIERR(1)
#define EFI_INVALID_PARAMETER EFIERR(2)
#define EFI_UNSUPPORTED EFIERR(3)
#define EFI_BAD_BUFFER_SIZE EFIERR(4)
#define EFI_BUFFER_TOO_SMALL EFIERR(5)
#define EFI_NOT_READY EFIERR(6)
#define EFI_DEVICE_ERROR EFIERR(7)
#define EFI_WRITE_PROTECTED EFIERR(8)
#define EFI_OUT_OF_RESOURCES EFIERR(9)
#define EFI_VOLUME_CORRUPTED EFIERR(10)
#define EFI_VOLUME_FULL EFIERR(11)
#define EFI_NO_MEDIA EFIERR(12)
#define EFI_MEDIA_CHANGED EFIERR(13)
#define EFI_NOT_FOUND EFIERR(14)
#define EFI_ACCESS_DENIED EFIERR(15)
#define EFI_NO_RESPONSE EFIERR(16)
#define EFI_NO_MAPPING EFIERR(17)
#define EFI_TIMEOUT EFIERR(18)
#define EFI_NOT_STARTED EFIERR(19)
#define EFI_ALREADY_STARTED EFIERR(20)
#define EFI_ABORTED EFIERR(21)
#define EFI_ICMP_ERROR EFIERR(22)
#define EFI_TFTP_ERROR EFIERR(23)
#define EFI_PROTOCOL_ERROR EFIERR(24)
#define EFI_INCOMPATIBLE_VERSION EFIERR(25)
#define EFI_SECURITY_VIOLATION EFIERR(26)
#define EFI_CRC_ERROR EFIERR(27)
#define EFI_END_OF_MEDIA EFIERR(28)
#define EFI_END_OF_FILE EFIERR(31)
#define EFI_INVALID_LANGUAGE EFIERR(32)
#define EFI_COMPROMISED_DATA EFIERR(33)
#define EFI_WARN_UNKOWN_GLYPH EFIWARN(1)
#define EFI_WARN_DELETE_FAILURE EFIWARN(2)
#define EFI_WARN_WRITE_FAILURE EFIWARN(3)
#define EFI_WARN_BUFFER_TOO_SMALL EFIWARN(4)
#endif

116
src/include/efi/efifs.h Normal file
View File

@@ -0,0 +1,116 @@
#ifndef _EFI_FS_H
#define _EFI_FS_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
efifs.h
Abstract:
EFI File System structures
Revision History
--*/
//
// EFI Partition header (normaly starts in LBA 1)
//
#define EFI_PARTITION_SIGNATURE 0x5053595320494249
#define EFI_PARTITION_REVISION 0x00010001
#define MIN_EFI_PARTITION_BLOCK_SIZE 512
#define EFI_PARTITION_LBA 1
typedef struct _EFI_PARTITION_HEADER {
EFI_TABLE_HEADER Hdr;
UINT32 DirectoryAllocationNumber;
UINT32 BlockSize;
EFI_LBA FirstUsableLba;
EFI_LBA LastUsableLba;
EFI_LBA UnusableSpace;
EFI_LBA FreeSpace;
EFI_LBA RootFile;
EFI_LBA SecutiryFile;
} EFI_PARTITION_HEADER;
//
// File header
//
#define EFI_FILE_HEADER_SIGNATURE 0x454c494620494249
#define EFI_FILE_HEADER_REVISION 0x00010000
#define EFI_FILE_STRING_SIZE 260
typedef struct _EFI_FILE_HEADER {
EFI_TABLE_HEADER Hdr;
UINT32 Class;
UINT32 LBALOffset;
EFI_LBA Parent;
UINT64 FileSize;
UINT64 FileAttributes;
EFI_TIME FileCreateTime;
EFI_TIME FileModificationTime;
EFI_GUID VendorGuid;
CHAR16 FileString[EFI_FILE_STRING_SIZE];
} EFI_FILE_HEADER;
//
// Return the file's first LBAL which is in the same
// logical block as the file header
//
#define EFI_FILE_LBAL(a) ((EFI_LBAL *) (((CHAR8 *) (a)) + (a)->LBALOffset))
#define EFI_FILE_CLASS_FREE_SPACE 1
#define EFI_FILE_CLASS_EMPTY 2
#define EFI_FILE_CLASS_NORMAL 3
//
// Logical Block Address List - the fundemental block
// description structure
//
#define EFI_LBAL_SIGNATURE 0x4c41424c20494249
#define EFI_LBAL_REVISION 0x00010000
typedef struct _EFI_LBAL {
EFI_TABLE_HEADER Hdr;
UINT32 Class;
EFI_LBA Parent;
EFI_LBA Next;
UINT32 ArraySize;
UINT32 ArrayCount;
} EFI_LBAL;
// Array size
#define EFI_LBAL_ARRAY_SIZE(lbal,offs,blks) \
(((blks) - (offs) - (lbal)->Hdr.HeaderSize) / sizeof(EFI_RL))
//
// Logical Block run-length
//
typedef struct {
EFI_LBA Start;
UINT64 Length;
} EFI_RL;
//
// Return the run-length structure from an LBAL header
//
#define EFI_LBAL_RL(a) ((EFI_RL*) (((CHAR8 *) (a)) + (a)->Hdr.HeaderSize))
#endif

68
src/include/efi/efigpt.h Normal file
View File

@@ -0,0 +1,68 @@
#ifndef _EFI_GPT_H
#define _EFI_GPT_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
EfiGpt.h
Abstract:
Include file for EFI partitioning scheme
Revision History
--*/
#define PRIMARY_PART_HEADER_LBA 1
typedef struct {
EFI_TABLE_HEADER Header;
EFI_LBA MyLBA;
EFI_LBA AlternateLBA;
EFI_LBA FirstUsableLBA;
EFI_LBA LastUsableLBA;
EFI_GUID DiskGUID;
EFI_LBA PartitionEntryLBA;
UINT32 NumberOfPartitionEntries;
UINT32 SizeOfPartitionEntry;
UINT32 PartitionEntryArrayCRC32;
} EFI_PARTITION_TABLE_HEADER;
#define EFI_PTAB_HEADER_ID "EFI PART"
typedef struct {
EFI_GUID PartitionTypeGUID;
EFI_GUID UniquePartitionGUID;
EFI_LBA StartingLBA;
EFI_LBA EndingLBA;
UINT64 Attributes;
CHAR16 PartitionName[36];
} EFI_PARTITION_ENTRY;
//
// EFI Partition Attributes
//
#define EFI_PART_USED_BY_EFI 0x0000000000000001
#define EFI_PART_REQUIRED_TO_FUNCTION 0x0000000000000002
#define EFI_PART_USED_BY_OS 0x0000000000000004
#define EFI_PART_REQUIRED_BY_OS 0x0000000000000008
#define EFI_PART_BACKUP_REQUIRED 0x0000000000000010
#define EFI_PART_USER_DATA 0x0000000000000020
#define EFI_PART_CRITICAL_USER_DATA 0x0000000000000040
#define EFI_PART_REDUNDANT_PARTITION 0x0000000000000080
#define EFI_PART_TYPE_UNUSED_GUID \
{ 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }
#define EFI_PART_TYPE_EFI_SYSTEM_PART_GUID \
{ 0xc12a7328, 0xf81f, 0x11d2, {0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b} }
#define EFI_PART_TYPE_LEGACY_MBR_GUID \
{ 0x024dee41, 0x33e7, 0x11d3, {0x9d, 0x69, 0x00, 0x08, 0xc7, 0x81, 0xf3, 0x9f} }
#endif

459
src/include/efi/efiip.h Normal file
View File

@@ -0,0 +1,459 @@
#ifndef _EFI_IP_H
#define _EFI_IP_H
/*++
Copyright (c) 2013 Intel Corporation
--*/
#define EFI_IP4_SERVICE_BINDING_PROTOCOL \
{0xc51711e7,0xb4bf,0x404a,{0xbf,0xb8,0x0a,0x04, 0x8e,0xf1,0xff,0xe4}}
#define EFI_IP4_PROTOCOL \
{0x41d94cd2,0x35b6,0x455a,{0x82,0x58,0xd4,0xe5,0x13,0x34,0xaa,0xdd}}
#define EFI_IP6_SERVICE_BINDING_PROTOCOL \
{0xec835dd3,0xfe0f,0x617b,{0xa6,0x21,0xb3,0x50,0xc3,0xe1,0x33,0x88}}
#define EFI_IP6_PROTOCOL \
{0x2c8759d5,0x5c2d,0x66ef,{0x92,0x5f,0xb6,0x6c,0x10,0x19,0x57,0xe2}}
INTERFACE_DECL(_EFI_IP4);
INTERFACE_DECL(_EFI_IP6);
typedef struct {
EFI_HANDLE InstanceHandle;
EFI_IPv4_ADDRESS Ip4Address;
EFI_IPv4_ADDRESS SubnetMask;
} EFI_IP4_ADDRESS_PAIR;
typedef struct {
EFI_HANDLE DriverHandle;
UINT32 AddressCount;
EFI_IP4_ADDRESS_PAIR AddressPairs[1];
} EFI_IP4_VARIABLE_DATA;
typedef struct {
UINT8 DefaultProtocol;
BOOLEAN AcceptAnyProtocol;
BOOLEAN AcceptIcmpErrors;
BOOLEAN AcceptBroadcast;
BOOLEAN AcceptPromiscuous;
BOOLEAN UseDefaultAddress;
EFI_IPv4_ADDRESS StationAddress;
EFI_IPv4_ADDRESS SubnetMask;
UINT8 TypeOfService;
UINT8 TimeToLive;
BOOLEAN DoNotFragment;
BOOLEAN RawData;
UINT32 ReceiveTimeout;
UINT32 TransmitTimeout;
} EFI_IP4_CONFIG_DATA;
typedef struct {
EFI_IPv4_ADDRESS SubnetAddress;
EFI_IPv4_ADDRESS SubnetMask;
EFI_IPv4_ADDRESS GatewayAddress;
} EFI_IP4_ROUTE_TABLE;
typedef struct {
UINT8 Type;
UINT8 Code;
} EFI_IP4_ICMP_TYPE;
typedef struct {
BOOLEAN IsStarted;
UINT32 MaxPacketSize;
EFI_IP4_CONFIG_DATA ConfigData;
BOOLEAN IsConfigured;
UINT32 GroupCount;
EFI_IPv4_ADDRESS *GroupTable;
UINT32 RouteCount;
EFI_IP4_ROUTE_TABLE *RouteTable;
UINT32 IcmpTypeCount;
EFI_IP4_ICMP_TYPE *IcmpTypeList;
} EFI_IP4_MODE_DATA;
typedef
EFI_STATUS
(EFIAPI *EFI_IP4_GET_MODE_DATA) (
IN struct _EFI_IP4 *This,
OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,
OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP4_CONFIGURE) (
IN struct _EFI_IP4 *This,
IN EFI_IP4_CONFIG_DATA *IpConfigData OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP4_GROUPS) (
IN struct _EFI_IP4 *This,
IN BOOLEAN JoinFlag,
IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP4_ROUTES) (
IN struct _EFI_IP4 *This,
IN BOOLEAN DeleteRoute,
IN EFI_IPv4_ADDRESS *SubnetAddress,
IN EFI_IPv4_ADDRESS *SubnetMask,
IN EFI_IPv4_ADDRESS *GatewayAddress
);
#pragma pack(1)
typedef struct {
UINT8 HeaderLength:4;
UINT8 Version:4;
UINT8 TypeOfService;
UINT16 TotalLength;
UINT16 Identification;
UINT16 Fragmentation;
UINT8 TimeToLive;
UINT8 Protocol;
UINT16 Checksum;
EFI_IPv4_ADDRESS SourceAddress;
EFI_IPv4_ADDRESS DestinationAddress;
} EFI_IP4_HEADER;
#pragma pack()
typedef struct {
UINT32 FragmentLength;
VOID *FragmentBuffer;
} EFI_IP4_FRAGMENT_DATA;
typedef struct {
EFI_TIME TimeStamp;
EFI_EVENT RecycleSignal;
UINT32 HeaderLength;
EFI_IP4_HEADER *Header;
UINT32 OptionsLength;
VOID *Options;
UINT32 DataLength;
UINT32 FragmentCount;
EFI_IP4_FRAGMENT_DATA FragmentTable[1];
} EFI_IP4_RECEIVE_DATA;
typedef struct {
EFI_IPv4_ADDRESS SourceAddress;
EFI_IPv4_ADDRESS GatewayAddress;
UINT8 Protocol;
UINT8 TypeOfService;
UINT8 TimeToLive;
BOOLEAN DoNotFragment;
} EFI_IP4_OVERRIDE_DATA;
typedef struct {
EFI_IPv4_ADDRESS DestinationAddress;
EFI_IP4_OVERRIDE_DATA *OverrideData;
UINT32 OptionsLength;
VOID *OptionsBuffer;
UINT32 TotalDataLength;
UINT32 FragmentCount;
EFI_IP4_FRAGMENT_DATA FragmentTable[1];
} EFI_IP4_TRANSMIT_DATA;
typedef struct {
EFI_EVENT Event;
EFI_STATUS Status;
union {
EFI_IP4_RECEIVE_DATA *RxData;
EFI_IP4_TRANSMIT_DATA *TxData;
} Packet;
} EFI_IP4_COMPLETION_TOKEN;
typedef
EFI_STATUS
(EFIAPI *EFI_IP4_TRANSMIT) (
IN struct _EFI_IP4 *This,
IN EFI_IP4_COMPLETION_TOKEN *Token
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP4_RECEIVE) (
IN struct _EFI_IP4 *This,
IN EFI_IP4_COMPLETION_TOKEN *Token
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP4_CANCEL)(
IN struct _EFI_IP4 *This,
IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP4_POLL) (
IN struct _EFI_IP4 *This
);
typedef struct _EFI_IP4 {
EFI_IP4_GET_MODE_DATA GetModeData;
EFI_IP4_CONFIGURE Configure;
EFI_IP4_GROUPS Groups;
EFI_IP4_ROUTES Routes;
EFI_IP4_TRANSMIT Transmit;
EFI_IP4_RECEIVE Receive;
EFI_IP4_CANCEL Cancel;
EFI_IP4_POLL Poll;
} EFI_IP4;
typedef struct {
UINT8 DefaultProtocol;
BOOLEAN AcceptAnyProtocol;
BOOLEAN AcceptIcmpErrors;
BOOLEAN AcceptPromiscuous;
EFI_IPv6_ADDRESS DestinationAddress;
EFI_IPv6_ADDRESS StationAddress;
UINT8 TrafficClass;
UINT8 HopLimit;
UINT32 FlowLabel;
UINT32 ReceiveTimeout;
UINT32 TransmitTimeout;
} EFI_IP6_CONFIG_DATA;
typedef struct {
EFI_IPv6_ADDRESS Address;
UINT8 PrefixLength;
} EFI_IP6_ADDRESS_INFO;
typedef struct {
EFI_IPv6_ADDRESS Gateway;
EFI_IPv6_ADDRESS Destination;
UINT8 PrefixLength;
} EFI_IP6_ROUTE_TABLE;
typedef enum {
EfiNeighborInComplete,
EfiNeighborReachable,
EfiNeighborStale,
EfiNeighborDelay,
EfiNeighborProbe
} EFI_IP6_NEIGHBOR_STATE;
typedef struct {
EFI_IPv6_ADDRESS Neighbor;
EFI_MAC_ADDRESS LinkAddress;
EFI_IP6_NEIGHBOR_STATE State;
} EFI_IP6_NEIGHBOR_CACHE;
typedef struct {
UINT8 Type;
UINT8 Code;
} EFI_IP6_ICMP_TYPE;
//***********************************************************
// ICMPv6 type definitions for error messages
//***********************************************************
#define ICMP_V6_DEST_UNREACHABLE 0x1
#define ICMP_V6_PACKET_TOO_BIG 0x2
#define ICMP_V6_TIME_EXCEEDED 0x3
#define ICMP_V6_PARAMETER_PROBLEM 0x4
//***********************************************************
// ICMPv6 type definition for informational messages
//***********************************************************
#define ICMP_V6_ECHO_REQUEST 0x80
#define ICMP_V6_ECHO_REPLY 0x81
#define ICMP_V6_LISTENER_QUERY 0x82
#define ICMP_V6_LISTENER_REPORT 0x83
#define ICMP_V6_LISTENER_DONE 0x84
#define ICMP_V6_ROUTER_SOLICIT 0x85
#define ICMP_V6_ROUTER_ADVERTISE 0x86
#define ICMP_V6_NEIGHBOR_SOLICIT 0x87
#define ICMP_V6_NEIGHBOR_ADVERTISE 0x88
#define ICMP_V6_REDIRECT 0x89
#define ICMP_V6_LISTENER_REPORT_2 0x8F
//***********************************************************
// ICMPv6 code definitions for ICMP_V6_DEST_UNREACHABLE
//***********************************************************
#define ICMP_V6_NO_ROUTE_TO_DEST 0x0
#define ICMP_V6_COMM_PROHIBITED 0x1
#define ICMP_V6_BEYOND_SCOPE 0x2
#define ICMP_V6_ADDR_UNREACHABLE 0x3
#define ICMP_V6_PORT_UNREACHABLE 0x4
#define ICMP_V6_SOURCE_ADDR_FAILED 0x5
#define ICMP_V6_ROUTE_REJECTED 0x6
//***********************************************************
// ICMPv6 code definitions for ICMP_V6_TIME_EXCEEDED
//***********************************************************
#define ICMP_V6_TIMEOUT_HOP_LIMIT 0x0
#define ICMP_V6_TIMEOUT_REASSEMBLE 0x1
//***********************************************************
// ICMPv6 code definitions for ICMP_V6_PARAMETER_PROBLEM
//***********************************************************
#define ICMP_V6_ERRONEOUS_HEADER 0x0
#define ICMP_V6_UNRECOGNIZE_NEXT_HDR 0x1
#define ICMP_V6_UNRECOGNIZE_OPTION 0x2
typedef struct {
BOOLEAN IsStarted;
UINT32 MaxPacketSize;
EFI_IP6_CONFIG_DATA ConfigData;
BOOLEAN IsConfigured;
UINT32 AddressCount;
EFI_IP6_ADDRESS_INFO *AddressList;
UINT32 GroupCount;
EFI_IPv6_ADDRESS *GroupTable;
UINT32 RouteCount;
EFI_IP6_ROUTE_TABLE *RouteTable;
UINT32 NeighborCount;
EFI_IP6_NEIGHBOR_CACHE *NeighborCache;
UINT32 PrefixCount;
EFI_IP6_ADDRESS_INFO *PrefixTable;
UINT32 IcmpTypeCount;
EFI_IP6_ICMP_TYPE *IcmpTypeList;
} EFI_IP6_MODE_DATA;
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_GET_MODE_DATA) (
IN struct _EFI_IP6 *This,
OUT EFI_IP6_MODE_DATA *Ip6ModeData OPTIONAL,
OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_CONFIGURE) (
IN struct _EFI_IP6 *This,
IN EFI_IP6_CONFIG_DATA *Ip6ConfigData OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_GROUPS) (
IN struct _EFI_IP6 *This,
IN BOOLEAN JoinFlag,
IN EFI_IPv6_ADDRESS *GroupAddress OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_ROUTES) (
IN struct _EFI_IP6 *This,
IN BOOLEAN DeleteRoute,
IN EFI_IPv6_ADDRESS *Destination OPTIONAL,
IN UINT8 PrefixLength,
IN EFI_IPv6_ADDRESS *GatewayAddress OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_NEIGHBORS) (
IN struct _EFI_IP6 *This,
IN BOOLEAN DeleteFlag,
IN EFI_IPv6_ADDRESS *TargetIp6Address,
IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL,
IN UINT32 Timeout,
IN BOOLEAN Override
);
typedef struct _EFI_IP6_FRAGMENT_DATA {
UINT32 FragmentLength;
VOID *FragmentBuffer;
} EFI_IP6_FRAGMENT_DATA;
typedef struct _EFI_IP6_OVERRIDE_DATA {
UINT8 Protocol;
UINT8 HopLimit;
UINT32 FlowLabel;
} EFI_IP6_OVERRIDE_DATA;
typedef struct _EFI_IP6_TRANSMIT_DATA {
EFI_IPv6_ADDRESS DestinationAddress;
EFI_IP6_OVERRIDE_DATA *OverrideData;
UINT32 ExtHdrsLength;
VOID *ExtHdrs;
UINT8 NextHeader;
UINT32 DataLength;
UINT32 FragmentCount;
EFI_IP6_FRAGMENT_DATA FragmentTable[1];
} EFI_IP6_TRANSMIT_DATA;
#pragma pack(1)
typedef struct _EFI_IP6_HEADER {
UINT8 TrafficClassH:4;
UINT8 Version:4;
UINT8 FlowLabelH:4;
UINT8 TrafficClassL:4;
UINT16 FlowLabelL;
UINT16 PayloadLength;
UINT8 NextHeader;
UINT8 HopLimit;
EFI_IPv6_ADDRESS SourceAddress;
EFI_IPv6_ADDRESS DestinationAddress;
} EFI_IP6_HEADER;
#pragma pack()
typedef struct _EFI_IP6_RECEIVE_DATA {
EFI_TIME TimeStamp;
EFI_EVENT RecycleSignal;
UINT32 HeaderLength;
EFI_IP6_HEADER *Header;
UINT32 DataLength;
UINT32 FragmentCount;
EFI_IP6_FRAGMENT_DATA FragmentTable[1];
} EFI_IP6_RECEIVE_DATA;
typedef struct {
EFI_EVENT Event;
EFI_STATUS Status;
union {
EFI_IP6_RECEIVE_DATA *RxData;
EFI_IP6_TRANSMIT_DATA *TxData;
} Packet;
} EFI_IP6_COMPLETION_TOKEN;
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_TRANSMIT) (
IN struct _EFI_IP6 *This,
IN EFI_IP6_COMPLETION_TOKEN *Token
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_RECEIVE) (
IN struct _EFI_IP6 *This,
IN EFI_IP6_COMPLETION_TOKEN *Token
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_CANCEL)(
IN struct _EFI_IP6 *This,
IN EFI_IP6_COMPLETION_TOKEN *Token OPTIONAL
);
typedef
EFI_STATUS
(EFIAPI *EFI_IP6_POLL) (
IN struct _EFI_IP6 *This
);
typedef struct _EFI_IP6 {
EFI_IP6_GET_MODE_DATA GetModeData;
EFI_IP6_CONFIGURE Configure;
EFI_IP6_GROUPS Groups;
EFI_IP6_ROUTES Routes;
EFI_IP6_NEIGHBORS Neighbors;
EFI_IP6_TRANSMIT Transmit;
EFI_IP6_RECEIVE Receive;
EFI_IP6_CANCEL Cancel;
EFI_IP6_POLL Poll;
} EFI_IP6;
#endif /* _EFI_IP_H */

1036
src/include/efi/efilib.h Normal file

File diff suppressed because it is too large Load Diff

177
src/include/efi/efilink.h Normal file
View File

@@ -0,0 +1,177 @@
#ifndef _EFI_LINK_H
#define _EFI_LINK_H
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
link.h (renamed efilink.h to avoid conflicts)
Abstract:
EFI link list macro's
Revision History
--*/
#ifndef EFI_NT_EMUL
//
// List entry - doubly linked list
//
typedef struct _LIST_ENTRY {
struct _LIST_ENTRY *Flink;
struct _LIST_ENTRY *Blink;
} LIST_ENTRY;
#endif
//
// VOID
// InitializeListHead(
// LIST_ENTRY *ListHead
// );
//
#define InitializeListHead(ListHead) \
(ListHead)->Flink = ListHead; \
(ListHead)->Blink = ListHead;
//
// BOOLEAN
// IsListEmpty(
// PLIST_ENTRY ListHead
// );
//
#define IsListEmpty(ListHead) \
((ListHead)->Flink == (ListHead))
//
// VOID
// RemoveEntryList(
// PLIST_ENTRY Entry
// );
//
#define _RemoveEntryList(Entry) { \
LIST_ENTRY *_Blink, *_Flink; \
_Flink = (Entry)->Flink; \
_Blink = (Entry)->Blink; \
_Blink->Flink = _Flink; \
_Flink->Blink = _Blink; \
}
#if EFI_DEBUG
#define RemoveEntryList(Entry) \
_RemoveEntryList(Entry); \
(Entry)->Flink = (LIST_ENTRY *) BAD_POINTER; \
(Entry)->Blink = (LIST_ENTRY *) BAD_POINTER;
#else
#define RemoveEntryList(Entry) \
_RemoveEntryList(Entry);
#endif
//
// VOID
// InsertTailList(
// PLIST_ENTRY ListHead,
// PLIST_ENTRY Entry
// );
//
#define InsertTailList(ListHead,Entry) {\
LIST_ENTRY *_ListHead, *_Blink; \
_ListHead = (ListHead); \
_Blink = _ListHead->Blink; \
(Entry)->Flink = _ListHead; \
(Entry)->Blink = _Blink; \
_Blink->Flink = (Entry); \
_ListHead->Blink = (Entry); \
}
//
// VOID
// InsertHeadList(
// PLIST_ENTRY ListHead,
// PLIST_ENTRY Entry
// );
//
#define InsertHeadList(ListHead,Entry) {\
LIST_ENTRY *_ListHead, *_Flink; \
_ListHead = (ListHead); \
_Flink = _ListHead->Flink; \
(Entry)->Flink = _Flink; \
(Entry)->Blink = _ListHead; \
_Flink->Blink = (Entry); \
_ListHead->Flink = (Entry); \
}
// VOID
// SwapListEntries(
// PLIST_ENTRY Entry1,
// PLIST_ENTRY Entry2
// );
//
// Put Entry2 before Entry1
//
#define SwapListEntries(Entry1,Entry2) {\
LIST_ENTRY *Entry1Flink, *Entry1Blink; \
LIST_ENTRY *Entry2Flink, *Entry2Blink; \
Entry2Flink = (Entry2)->Flink; \
Entry2Blink = (Entry2)->Blink; \
Entry1Flink = (Entry1)->Flink; \
Entry1Blink = (Entry1)->Blink; \
Entry2Blink->Flink = Entry2Flink; \
Entry2Flink->Blink = Entry2Blink; \
(Entry2)->Flink = Entry1; \
(Entry2)->Blink = Entry1Blink; \
Entry1Blink->Flink = (Entry2); \
(Entry1)->Blink = (Entry2); \
}
//
// EFI_FIELD_OFFSET - returns the byte offset to a field within a structure
//
#define EFI_FIELD_OFFSET(TYPE,Field) ((UINTN)(intptr_t)(&(((TYPE *) 0)->Field)))
//
// CONTAINING_RECORD - returns a pointer to the structure
// from one of it's elements.
//
#define _CR(Record, TYPE, Field) \
((TYPE *) ( (CHAR8 *)(Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
#if EFI_DEBUG
#define CR(Record, TYPE, Field, Sig) \
_CR(Record, TYPE, Field)->Signature != Sig ? \
(TYPE *) ASSERT_STRUCT(_CR(Record, TYPE, Field), Record) : \
_CR(Record, TYPE, Field)
#else
#define CR(Record, TYPE, Field, Signature) \
_CR(Record, TYPE, Field)
#endif
//
// A lock structure
//
typedef struct _FLOCK {
EFI_TPL Tpl;
EFI_TPL OwnerTpl;
UINTN Lock;
} FLOCK;
#endif

Some files were not shown because too many files have changed in this diff Show More