Skip to content

Commit e424df5

Browse files
authored
Merge pull request #91 from ReturnInfinity/UEFI_EDID
UEFI EDID support
2 parents 3633cb4 + 16fa1e5 commit e424df5

1 file changed

Lines changed: 76 additions & 5 deletions

File tree

src/boot/uefi.asm

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
; dd if=PAYLOAD of=BOOTX64.EFI bs=4096 seek=1 conv=notrunc > /dev/null 2>&1
1212
; =============================================================================
1313

14-
; Set the desired screen resolution values below
15-
Horizontal_Resolution equ 1024
16-
Vertical_Resolution equ 768
1714

1815
BITS 64
1916
ORG 0x00400000
@@ -158,6 +155,65 @@ nextentry:
158155
lodsq ; Load the address of the ACPI table
159156
mov [ACPI], rax ; Save the address
160157

158+
; Find the interface to EFI_EDID_ACTIVE_PROTOCOL_GUID via its GUID
159+
mov rcx, EFI_EDID_ACTIVE_PROTOCOL_GUID ; IN EFI_GUID *Protocol
160+
mov rdx, 0 ; IN VOID *Registration OPTIONAL
161+
mov r8, EDID ; OUT VOID **Interface
162+
mov rax, [BS]
163+
mov rax, [rax + EFI_BOOT_SERVICES_LOCATEPROTOCOL]
164+
call rax
165+
cmp rax, EFI_SUCCESS
166+
je get_EDID ; If it exists, process EDID
167+
168+
; Find the interface to EFI_EDID_DISCOVERED_PROTOCOL_GUID via its GUID
169+
mov rcx, EFI_EDID_DISCOVERED_PROTOCOL_GUID ; IN EFI_GUID *Protocol
170+
mov rdx, 0 ; IN VOID *Registration OPTIONAL
171+
mov r8, EDID ; OUT VOID **Interface
172+
mov rax, [BS]
173+
mov rax, [rax + EFI_BOOT_SERVICES_LOCATEPROTOCOL]
174+
call rax
175+
cmp rax, EFI_SUCCESS
176+
je get_EDID ; If it exists, process EDID
177+
jmp use_GOP ; If not found, or other error, use GOP
178+
179+
; Gather preferred screen resolution
180+
get_EDID:
181+
; Parse the EDID information
182+
; 0 UINT32 - SizeOfEdid
183+
; 4 UINT8 - *Edid
184+
mov rax, [EDID]
185+
mov ebx, [rax]
186+
cmp ebx, 128 ; Minimum size of 128 bytes
187+
jb use_GOP ; Fail out to GOP with default resolution
188+
mov rbx, [rax+8] ; Pointer to EDID. Why not +4?
189+
mov rax, [rbx] ; Load RAX with EDID header
190+
mov rcx, 0x00FFFFFFFFFFFF00 ; Required EDID header
191+
cmp rax, rcx ; Verify 8-byte header at 0x00 is 0x00FFFFFFFFFFFF00
192+
jne use_GOP ; Fail out to GOP with default resolution
193+
; Preferred Timing Mode starts at 0x36
194+
; 0x38 - Lower 8 bits of Horizontal pixels in bits 7:0
195+
; 0x3A - Upper 4 bits of Horizontal pixels in bits 7:4
196+
; 0x3B - Lower 8 bits of Vertical pixels in bits 7:0
197+
; 0x3D - Upper 4 bits of Vertical pixels in bits 7:4
198+
xor eax, eax
199+
xor ecx, ecx
200+
mov al, [rbx+0x38]
201+
mov cl, [rbx+0x3A]
202+
and cl, 0xF0 ; Keep bits 7:4
203+
shl ecx, 4
204+
or eax, ecx
205+
mov [Horizontal_Resolution], eax
206+
xor eax, eax
207+
xor ecx, ecx
208+
mov al, [rbx+0x3B]
209+
mov cl, [rbx+0x3D]
210+
and cl, 0xF0 ; Keep bits 7:4
211+
shl ecx, 4
212+
or eax, ecx
213+
mov [Vertical_Resolution], eax
214+
215+
; Set video to desired resolution. By default it is 1024x768 unless EDID was found
216+
use_GOP:
161217
; Find the interface to GRAPHICS_OUTPUT_PROTOCOL via its GUID
162218
mov rcx, EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID ; IN EFI_GUID *Protocol
163219
mov rdx, 0 ; IN VOID *Registration OPTIONAL
@@ -203,10 +259,10 @@ vid_query:
203259
mov rsi, [vid_info]
204260
lodsd ; UINT32 - Version
205261
lodsd ; UINT32 - HorizontalResolution
206-
cmp eax, Horizontal_Resolution
262+
cmp eax, [Horizontal_Resolution]
207263
jne next_video_mode
208264
lodsd ; UINT32 - VerticalResolution
209-
cmp eax, Vertical_Resolution
265+
cmp eax, [Vertical_Resolution]
210266
jne next_video_mode
211267
lodsd ; EFI_GRAPHICS_PIXEL_FORMAT - PixelFormat (UINT32)
212268
bt eax, 0 ; Bit 0 is set for 32-bit colour mode
@@ -339,6 +395,8 @@ get_memmap:
339395
stosq ; EFI_MEMORY_DESCRIPTOR version
340396
mov rax, [ACPI]
341397
stosq ; ACPI Table Address
398+
mov rax, [EDID]
399+
stosq ; EDID Data (Size and Address)
342400

343401
; Set screen to black before jumping to Pure64
344402
mov rdi, [FB]
@@ -436,6 +494,7 @@ CONFIG: dq 0 ; Config Table address
436494
ACPI: dq 0 ; ACPI table address
437495
OUTPUT: dq 0 ; Output services
438496
VIDEO: dq 0 ; Video services
497+
EDID: dq 0
439498
FB: dq 0 ; Frame buffer base address
440499
FBS: dq 0 ; Frame buffer size
441500
HR: dq 0 ; Horizontal Resolution
@@ -452,12 +511,24 @@ vid_index: dq 0
452511
vid_max: dq 0
453512
vid_size: dq 0
454513
vid_info: dq 0
514+
Horizontal_Resolution: dd 1024 ; Default resolution X - If no EDID found
515+
Vertical_Resolution: dd 768 ; Default resolution Y - If no EDID found
455516

456517
ACPI_TABLE_GUID:
457518
dd 0xeb9d2d30
458519
dw 0x2d88, 0x11d3
459520
db 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d
460521

522+
EFI_EDID_ACTIVE_PROTOCOL_GUID:
523+
dd 0xbd8c1056
524+
dw 0x9f36, 0x44ec
525+
db 0x92, 0xa8, 0xa6, 0x33, 0x7f, 0x81, 0x79, 0x86
526+
527+
EFI_EDID_DISCOVERED_PROTOCOL_GUID:
528+
dd 0x1c0c34f6
529+
dw 0xd380, 0x41fa
530+
db 0xa0, 0x49, 0x8a, 0xd0, 0x6c, 0x1a, 0x66, 0xaa
531+
461532
EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID:
462533
dd 0x9042a9de
463534
dw 0x23dc, 0x4a38

0 commit comments

Comments
 (0)