main
Allen Webster 2023-09-29 18:13:13 -07:00
commit c74e30f008
14 changed files with 1328 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.DS_Store
build/*

BIN
OVMF.fd Normal file

Binary file not shown.

11
build.bat Normal file
View File

@ -0,0 +1,11 @@
@echo off
if not exist build mkdir build
pushd build
cl /nologo /FC /GS- /c /I.. ../example/lil_uefi_example.c
link /nologo /ENTRY:EfiMain /ALIGN:16 /SUBSYSTEM:EFI_APPLICATION /OUT:bootx64.efi lil_uefi_example.obj
if not exist EFI mkdir EFI
if not exist EFI\BOOT mkdir EFI\BOOT
copy bootx64.efi EFI\BOOT\bootx64.efi
popd

View File

@ -0,0 +1,49 @@
// Lil' UEFI Example
#include "lil_uefi/lil_uefi.h"
#define ArrayCount(a) ((sizeof(a)) / sizeof((a)[0]))
EFI_UINTN
EfiMain(EFI_HANDLE handle, EFI_SYSTEM_TABLE *system_table){
// rjf: grab boot services
EFI_BOOT_SERVICES *boot_services = system_table->BootServices;
// rjf: grab graphics output protocol
EFI_GUID gfx_out_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gfx_out_prot = 0;
EFI_STATUS gfx_out_prot_locate_status = boot_services->LocateProtocol(&gfx_out_guid, 0, &gfx_out_prot);
// rjf: set gfx out protocol mode to zero
gfx_out_prot->SetMode(gfx_out_prot, 0);
// rjf: grab frame buffer info
EFI_UINT64 frame_buffer_addr = gfx_out_prot->Mode->frame_buffer_base;
EFI_UINT64 frame_buffer_size = gfx_out_prot->Mode->frame_buffer_size;
// rjf: get memory map
EFI_MEMORY_DESCRIPTOR memory_descriptors[64] = {0};
EFI_UINT64 mmap_size = ArrayCount(memory_descriptors);
EFI_UINT64 map_key = 0;
EFI_UINT64 descriptor_size = 0;
EFI_UINT32 descriptor_version = 0;
EFI_STATUS memory_map_get_status = boot_services->GetMemoryMap(&mmap_size, memory_descriptors,
&map_key, &descriptor_size,
&descriptor_version);
// rjf: fill frame buffer
for(EFI_UINT64 display_idx = 0;; display_idx += 1)
{
EFI_UINT32*frame_buffer = (EFI_UINT32*)frame_buffer_addr;
for(EFI_UINT64 idx = 0; idx < frame_buffer_size/4; idx += 1)
{
EFI_UINT32 r = (display_idx) % 255;
EFI_UINT32 g = (display_idx + 128) % 255;
EFI_UINT32 b = (display_idx + 64) % 255;
frame_buffer[idx] = 0 | (r << 16) | (g << 8) | (b);
}
}
return(0);
}

1134
lil_uefi/lil_uefi.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
// SPEC: Section 4.4 (gives order of the table)
// SPEC: Section 7.1, 7.2, 7.3, 7.4, 7.5 (gives signatures of the functions)
X(RaiseTPL, EFI_TPL, (EFI_TPL new_tpl))
X(RestoreTPL, void, (EFI_TPL old_tpl))
X(AllocatePages, EFI_STATUS, (EFI_ALLOCATE_TYPE type, EFI_MEMORY_TYPE memory_type, EFI_UINTN pages, EFI_PHYSICAL_ADDRESS *memory))
X(FreePages, EFI_STATUS, (EFI_PHYSICAL_ADDRESS memory, EFI_UINTN pages))
X(GetMemoryMap, EFI_STATUS, (EFI_UINTN *size_inout, EFI_MEMORY_DESCRIPTOR *descriptors_inout, EFI_UINTN *map_key_out, EFI_UINTN *descriptor_size_out, EFI_UINT32 *descriptor_version_out))
X(AllocatePool, EFI_STATUS, (EFI_MEMORY_TYPE pool_type, EFI_UINTN size, void **buffer))
X(FreePool, EFI_STATUS, (void *buffer))
X(CreateEvent, EFI_STATUS, (EFI_UINT32 type, EFI_TPL notify_tpl, EFI_EVENT_NOTIFY_FUNCITON *notify_function, void* notify_context, EFI_EVENT *event_out))
X(SetTimer, EFI_STATUS, (EFI_EVENT event, EFI_TIMER_DELAY delay_type, EFI_UINT64 trigger_time))
X(WaitForEvent, EFI_STATUS, (EFI_UINTN number_of_events, EFI_EVENT *event, EFI_UINTN *index))
X(SignalEvent, EFI_STATUS, (EFI_EVENT event))
X(CloseEvent, EFI_STATUS, (EFI_EVENT event))
X(CheckEvent, EFI_STATUS, (EFI_EVENT event))
X(InstallProtocolInterface, EFI_STATUS, (EFI_HANDLE *handle, EFI_GUID *protocol, EFI_INTERFACE_TYPE interface_type, void* interface))
X(ReinstallProtocolInterface, EFI_STATUS, (EFI_HANDLE *handle, EFI_GUID *protocol, void* old_interface, void* new_interface))
X(UninstallProtocolInterface, EFI_STATUS, (EFI_HANDLE handle, EFI_GUID *protocol, void* interface))
X(HandleProtocol, EFI_STATUS, (EFI_HANDLE handle, EFI_GUID *protocol, void **interface))
X(Reserved, void, (void))
X(RegisterProtocolNotify, EFI_STATUS, (EFI_GUID *protocol, EFI_EVENT event, void **registration))
X(LocateHandle, EFI_STATUS, (EFI_LOCATE_SEARCH_TYPE search_type, EFI_GUID *protocol, void *search_key, EFI_UINTN *buffer_size, EFI_HANDLE *buffer))
X(LocateDevicePath, EFI_STATUS, (EFI_GUID *protocol, struct EFI_DEVICE_PATH_PROTOCOL **device_path, EFI_HANDLE *device))
X(InstallConfigurationTable, EFI_HANDLE, (EFI_GUID *guid, void *table))
X(LoadImage, EFI_STATUS, (EFI_BOOLEAN boot_policy, EFI_HANDLE parent_image_handle, struct EFI_DEVICE_PATH_PROTOCOL *device_path, void *source_buffer, EFI_UINTN source_size, EFI_HANDLE *image_handle_out))
X(StartImage, EFI_STATUS, (EFI_HANDLE image_handle, EFI_UINTN *exit_data_size, EFI_UINT16 **exit_data))
X(Exit, EFI_STATUS, (EFI_HANDLE image_handle, EFI_STATUS exit_status, EFI_UINTN exit_data_size, EFI_UINT16 *exit_data))
X(UnloadImage, EFI_STATUS, (EFI_HANDLE image_handle))
X(ExitBootServices, EFI_STATUS, (EFI_HANDLE image_handle, EFI_UINTN map_key))
X(GetNextMonotonicCount, EFI_STATUS, (EFI_UINT64 *count_out))
X(Stall, EFI_STATUS, (EFI_UINTN microseconds))
X(SetWatchdogTimer, EFI_STATUS, (EFI_UINTN timeout, EFI_UINT64 watchdog_code, EFI_UINTN data_size, EFI_UINT16 *watchdog_data))
X(ConnectController, EFI_STATUS, (EFI_HANDLE controller_handle, EFI_HANDLE *driver_image_handle, struct EFI_DEVICE_PATH_PROTOCOL *remaining_device_path, EFI_BOOLEAN recursive))
X(DisconnectController, EFI_STATUS, (EFI_HANDLE controller_handle, EFI_HANDLE driver_image_handle, EFI_HANDLE child_handle))
X(OpenProtocol, EFI_STATUS, (EFI_HANDLE handle, EFI_GUID *protocol, void **interface, EFI_HANDLE agent_handle, EFI_HANDLE controller_handle, EFI_UINT32 attributes))
X(CloseProtocol, EFI_STATUS, (EFI_HANDLE handle, EFI_GUID *protocol, EFI_HANDLE agent_handle, EFI_HANDLE controller_handle))
X(OpenProtocolInformation, EFI_STATUS, (EFI_HANDLE handle, EFI_GUID *protocol, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **entry_buffer, EFI_UINTN *entry_count))
X(ProtocolsPerHandle, EFI_STATUS, (EFI_HANDLE handle, EFI_GUID ***protocol_buffer, EFI_UINTN *protocol_buffer_count))
X(LocateHandleBuffer, EFI_STATUS, (EFI_LOCATE_SEARCH_TYPE search_type, EFI_GUID *protocol, void *search_key, EFI_UINTN *handle_count, EFI_HANDLE **buffer))
X(LocateProtocol, EFI_STATUS, (EFI_GUID *protocol, void *registration, void **interface))
X(InstallMultipleProtocolInterfaces, EFI_STATUS, (EFI_HANDLE *handle, ...))
X(UninstallMultipleProtocolInterfaces, EFI_STATUS, (EFI_HANDLE handle, ...))
X(CalculateCrc32, EFI_STATUS, (void *data, EFI_UINTN data_size, EFI_UINT32 *crc32_out))
X(CopyMem, void, (void *destination, void *source, EFI_UINTN length))
X(SetMem, void, (void *buffer, EFI_UINTN size, EFI_UINT8 value))
X(CreateEventEx, EFI_STATUS, (EFI_UINT32 type, EFI_TPL notify_tpl, EFI_EVENT_NOTIFY_FUNCITON *notify_function, void *notify_context, EFI_GUID *event_group, EFI_EVENT *event_out))

View File

@ -0,0 +1,4 @@
// SPEC: Section 12.9
X(QueryMode, EFI_STATUS, (struct EFI_GRAPHICS_OUTPUT_PROTOCOL *prot, EFI_UINT32 mode_number, EFI_UINTN *size_of_info, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **info))
X(SetMode, EFI_STATUS, (struct EFI_GRAPHICS_OUTPUT_PROTOCOL *prot, EFI_UINT32 mode_number))
X(Blt, EFI_STATUS, (struct EFI_GRAPHICS_OUTPUT_PROTOCOL *prot, EFI_UINT32 *buffer, EFI_GRAPHICS_OUTPUT_BLT_OPERATION blt_operation, EFI_UINTN src_x, EFI_UINTN src_y, EFI_UINTN dst_x, EFI_UINTN dst_y, EFI_UINTN width, EFI_UINTN height, EFI_UINTN src_stride))

View File

@ -0,0 +1,16 @@
// SPEC: Section 4.5 (gives order of the table)
// SPEC: Section 8.1, 8.2, 8.3, 8.4, 8.5 (gives signatures of the functions)
X(GetTime, EFI_STATUS, (EFI_TIME *time_out, EFI_TIME_CAPABILITIES *capabilities_out))
X(SetTime, EFI_STATUS, (EFI_TIME *time))
X(GetWakeupTime, EFI_STATUS, (EFI_BOOLEAN *enabled_out, EFI_BOOLEAN *pending_out, EFI_TIME *time_out))
X(SetWakeupTime, EFI_STATUS, (EFI_BOOLEAN enable, EFI_TIME *time))
X(SetVirtualAddressMap, EFI_STATUS, (EFI_UINTN memory_map_size, EFI_UINTN descriptor_size, EFI_UINT32 descriptor_version, EFI_MEMORY_DESCRIPTOR *virtual_map))
X(ConvertPointer, EFI_STATUS, (EFI_UINTN debug_disposition, void **address))
X(GetVariable, EFI_STATUS, (EFI_UINT16 *variable_name, EFI_GUID *vendor_guid, EFI_UINT32 *attributes_out, EFI_UINTN *data_size, void *data))
X(GetNextVariableName, EFI_STATUS, (EFI_UINTN *variable_name_size, EFI_UINT16 *variable_name, EFI_GUID *vendor_guid))
X(SetVariable, EFI_STATUS, (EFI_UINT16 *variable_name, EFI_GUID *vendor_guid, EFI_UINT32 attributes, EFI_UINTN data_size, void *data))
X(GetNextHighMonotonicCount, EFI_STATUS, (EFI_UINT32 *high_count))
X(ResetSystem, EFI_STATUS, (EFI_RESET_TYPE reset_type, EFI_STATUS reset_status, EFI_UINTN data_size, void *reset_data))
X(UpdateCapsule, EFI_STATUS, (EFI_CAPSULE_HEADER **capsule_header_array, EFI_UINTN capsule_count, EFI_PHYSICAL_ADDRESS scatter_gather_list))
X(QueryCapsuleCapabilities, EFI_STATUS, (EFI_CAPSULE_HEADER **capsule_header_array, EFI_UINTN capsule_count, EFI_UINT64 *max_capsule_size, EFI_RESET_TYPE *reset_type))
X(QueryVariableInfo, EFI_STATUS, (EFI_UINT32 attributes, EFI_UINT64 *max_variable_storage_size, EFI_UINT64 *remaining_variable_storage_size, EFI_UINT64 *maximum_variable_size))

View File

@ -0,0 +1,3 @@
// SPEC: Section 12.5
X(Reset, EFI_STATUS, (struct EFI_SIMPLE_POINTER_PROTOCOL *prot, EFI_BOOLEAN extended_verification))
X(GetState, EFI_STATUS, (struct EFI_SIMPLE_POINTER_PROTOCOL *prot, EFI_SIMPLE_POINTER_STATE *out_state))

View File

@ -0,0 +1,3 @@
// SPEC: Section 12.3
X(Reset, EFI_STATUS, (struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL *prot, EFI_BOOLEAN extended_verification))
X(ReadKeyStroke, EFI_STATUS, (struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL *prot, EFI_INPUT_KEY *key))

View File

@ -0,0 +1,10 @@
// SPEC: Section 12.4
X(Reset, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot, EFI_BOOLEAN extended_verification))
X(OutputString, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot, EFI_UINT16 *string))
X(TestString, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot, EFI_UINT16 *string))
X(QueryMode, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot, EFI_UINTN mode_number, EFI_UINTN *columns, EFI_UINTN *rows))
X(SetMode, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot, EFI_UINTN mode_number))
X(SetAttribute, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot, EFI_UINTN attribute))
X(ClearScreen, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot))
X(SetCursorPosition, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot, EFI_UINTN column, EFI_UINTN row))
X(EnableCursor, EFI_STATUS, (struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *prot, EFI_BOOLEAN visible))

View File

@ -0,0 +1,14 @@
// SPEC: Section 17.1.1
X(GetCapability, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 *max_speed, EFI_UINT8 *port_number, EFI_UINT8 *is_64bit_capable))
X(Reset, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT16 attributes))
X(GetState, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_USB_HC_STATE *out_state))
X(SetState, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_USB_HC_STATE state))
X(ControlTransfer, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 device_address, EFI_UINT8 device_speed, EFI_UINTN max_packet_length, EFI_USB_DEVICE_REQUEST *request, EFI_USB_DATA_DIRECTION transfer_direction, void *data, EFI_UINTN *data_length, EFI_UINTN timeout, EFI_USB2_HC_TRANSACTION_TRANSLATOR *translator, EFI_UINT32 *transfer_result))
X(BulkTransfer, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 device_address, EFI_UINT8 endpoint_address, EFI_UINT8 device_speed, EFI_UINTN max_packet_length, EFI_UINT8 data_buffers_number, void *data[EFI_USB_MAX_BULK_BUFFER_NUM], EFI_UINTN *data_length, EFI_UINT8 *data_toggle, EFI_UINTN timeout, EFI_USB2_HC_TRANSACTION_TRANSLATOR *translator, EFI_UINT32 *transfer_result))
X(AsyncInterruptTransfer, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 device_address, EFI_UINT8 endpoint_address, EFI_UINT8 device_speed, EFI_UINTN max_packet_length, EFI_BOOLEAN is_new_transfer, EFI_UINT8 *data_toggle, EFI_UINTN polling_interval, EFI_UINTN data_length, EFI_USB2_HC_TRANSACTION_TRANSLATOR *translator, EFI_ASYNC_USB_TRANSFER_CALLBACK *callback, void *context))
X(SyncInterruptTransfer, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 device_address, EFI_UINT8 endpoint_address, EFI_UINT8 device_speed, EFI_UINTN max_packet_length, void *data, EFI_UINTN *data_length, EFI_UINT8 *data_toggle, EFI_UINTN timeout, EFI_USB2_HC_TRANSACTION_TRANSLATOR *translator, EFI_UINT32 *transfer_result))
X(IsochronousTransfer, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 device_address, EFI_UINT8 endpoint_address, EFI_UINT8 device_speed, EFI_UINTN max_packet_length, EFI_UINT8 data_buffers_number, void *data[EFI_USB_MAX_ISO_BUFFER_NUM], EFI_UINTN data_length, EFI_USB2_HC_TRANSACTION_TRANSLATOR *translator, EFI_UINT32 *transfer_result))
X(AsyncIsochronousTransfer, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 device_address, EFI_UINT8 endpoint_address, EFI_UINT8 device_speed, EFI_UINTN max_packet_length, EFI_UINT8 data_buffers_number, void *data[EFI_USB_MAX_ISO_BUFFER_NUM], EFI_UINTN data_length, EFI_USB2_HC_TRANSACTION_TRANSLATOR *translator, EFI_ASYNC_USB_TRANSFER_CALLBACK isochronous_callback, void *context))
X(GetRootHubPortStatus, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 port_number, EFI_USB_PORT_STATUS *port_status))
X(SetRootHubPortFeature, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 port_number, EFI_USB_PORT_FEATURE port_feature))
X(ClearRootHubPortFeature, EFI_STATUS, (struct EFI_USB2_HC_PROTOCOL *prot, EFI_UINT8 port_number, EFI_USB_PORT_FEATURE port_feature))

33
project.4coder Normal file
View File

@ -0,0 +1,33 @@
version(2);
project_name = "JamOS";
patterns = {
"*.c",
"*.cpp",
"*.h",
"*.m",
"*.bat",
"*.sh",
"*.4coder",
};
blacklist_patterns = {
".*",
};
load_paths_base = {
{ ".", .relative = true, .recursive = true, },
};
load_paths = {
.win = load_paths_base,
.linux = load_paths_base,
.mac = load_paths_base,
};
commands = {
.build = { .out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.win = "build.bat", },
.run = { .out = "*run*", .footer_panel = false, .save_dirty_files = true,
.win = "run.bat", },
};
fkey_command = {
.F1 = "build",
.F2 = "run",
};

3
run.bat Normal file
View File

@ -0,0 +1,3 @@
@echo off
start "" "qemu" -serial stdio -bios OVMF.fd -drive format=raw,file=fat:rw:build