Ok, finally back at my computer.
On Thursday, March 23, 2023 at 7:25:24 PM UTC+8, wolfgang kern wrote:
> So what is the UEFI equivalent to INT13 and how can I make it boot my 
> old stuff from either CD or USB ?
As mentioned, if all you need is a bit of code loaded,
you don't need to anything at all except plonk a
bootx64.efi into \efi\boot of a FAT-formatted disk.
Here is some assembler code:
C:\devel\pdos\pdpclib\xxx3>type efi64.asm
# Written by Paul Edwards
# Released to the public domain
.code64
.intel_syntax noprefix
.globl efimain
efimain:
# ret is 1 byte, jmp is 2 bytes
# So for testing, comment out the jmp and add 2 rets
# xxx: jmp xxx
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
ret
C:\devel\pdos\pdpclib\xxx3>
The assembler can be compiled and linked like this
(with mingw64 for Windows)
C:\devel\pdos\pdpclib\xxx3>type doit.bat
x86_64-w64-mingw32-as -o efi64.o efi64.asm
x86_64-w64-mingw32-ld -s -subsystem 10 -e efimain -nostdlib -o bootx64.efi efi64.o
C:\devel\pdos\pdpclib\xxx3>
Here are two executables:
C:\vbox\x64test\efi\boot>dir
 Volume in drive C has no label.
 Volume Serial Number is 4E58-AF11
 Directory of C:\vbox\x64test\efi\boot
2023-03-23  22:17    <DIR>          .
2023-03-23  22:17    <DIR>          ..
2023-03-23  22:17             2,048 bootx64.efi
2023-03-23  22:15             2,048 loop.efi
C:\vbox\x64test\efi\boot>hexdump loop.efi
000000  4D5A9000 03000000 04000000 FFFF0000  MZ..............
000010  B8000000 00000000 40000000 00000000  ........@.......
000020  00000000 00000000 00000000 00000000  ................
000030  00000000 00000000 00000000 80000000  ................
000040  0E1FBA0E 00B409CD 21B8014C CD215468  ........!..L.!Th
000050  69732070 726F6772 616D2063 616E6E6F  is program canno
000060  74206265 2072756E 20696E20 444F5320  t be run in DOS
000070  6D6F6465 2E0D0D0A 24000000 00000000  mode....$.......
000080  50450000 64860200 F25E1C64 00000000  PE..d....^.d....
000090  00000000 F0002E02 0B020224 00020000  ...........$....
0000A0  00020000 00000000 00100000 00100000  ................
0000B0  00000040 01000000 00100000 00020000  ...@............
0000C0  04000000 00000000 05000200 00000000  ................
0000D0  00300000 00040000 79FD0000 0A006001  .0......y.....`.
0000E0  00002000 00000000 00100000 00000000  .. .............
0000F0  00001000 00000000 00100000 00000000  ................
000100  00000000 10000000 00000000 00000000  ................
000110  00200000 14000000 00000000 00000000  . ..............
000120  00000000 00000000 00000000 00000000  ................
000130  00000000 00000000 00000000 00000000  ................
000140  00000000 00000000 00000000 00000000  ................
000150  00000000 00000000 00000000 00000000  ................
000160  00000000 00000000 00000000 00000000  ................
000170  00000000 00000000 00000000 00000000  ................
000180  00000000 00000000 2E746578 74000000  .........text...
000190  60000000 00100000 00020000 00040000  `...............
0001A0  00000000 00000000 00000000 20005060  ............ .P`
0001B0  2E696461 74610000 14000000 00200000  .idata....... ..
0001C0  00020000 00060000 00000000 00000000  ................
0001D0  00000000 400030C0 00000000 00000000  ....@.0.........
0001E0  00000000 00000000 00000000 00000000  ................
0001F0  00000000 00000000 00000000 00000000  ................
000200  00000000 00000000 00000000 00000000  ................
000210  00000000 00000000 00000000 00000000  ................
000220  00000000 00000000 00000000 00000000  ................
000230  00000000 00000000 00000000 00000000  ................
000240  00000000 00000000 00000000 00000000  ................
000250  00000000 00000000 00000000 00000000  ................
000260  00000000 00000000 00000000 00000000  ................
000270  00000000 00000000 00000000 00000000  ................
000280  00000000 00000000 00000000 00000000  ................
000290  00000000 00000000 00000000 00000000  ................
0002A0  00000000 00000000 00000000 00000000  ................
0002B0  00000000 00000000 00000000 00000000  ................
0002C0  00000000 00000000 00000000 00000000  ................
0002D0  00000000 00000000 00000000 00000000  ................
0002E0  00000000 00000000 00000000 00000000  ................
0002F0  00000000 00000000 00000000 00000000  ................
000300  00000000 00000000 00000000 00000000  ................
000310  00000000 00000000 00000000 00000000  ................
000320  00000000 00000000 00000000 00000000  ................
000330  00000000 00000000 00000000 00000000  ................
000340  00000000 00000000 00000000 00000000  ................
000350  00000000 00000000 00000000 00000000  ................
000360  00000000 00000000 00000000 00000000  ................
000370  00000000 00000000 00000000 00000000  ................
000380  00000000 00000000 00000000 00000000  ................
000390  00000000 00000000 00000000 00000000  ................
0003A0  00000000 00000000 00000000 00000000  ................
0003B0  00000000 00000000 00000000 00000000  ................
0003C0  00000000 00000000 00000000 00000000  ................
0003D0  00000000 00000000 00000000 00000000  ................
0003E0  00000000 00000000 00000000 00000000  ................
0003F0  00000000 00000000 00000000 00000000  ................
000400  EBFEC3C3 C3C3C3C3 C3C3C3C3 C3C3C3C3  ................
000410  C3C3C3C3 C3C3C3C3 C3C3C3C3 C3C3C3C3  ................
000420  C3C3C3C3 C3C3C3C3 C3C3C3C3 C3C3C3C3  ................
000430  C3C3C3C3 C3C3C3C3 C3C3C3C3 C3C39090  ................
000440  FFFFFFFF FFFFFFFF 00000000 00000000  ................
000450  FFFFFFFF FFFFFFFF 00000000 00000000  ................
000460  00000000 00000000 00000000 00000000  ................
000470  00000000 00000000 00000000 00000000  ................
000480  00000000 00000000 00000000 00000000  ................
000490  00000000 00000000 00000000 00000000  ................
0004A0  00000000 00000000 00000000 00000000  ................
0004B0  00000000 00000000 00000000 00000000  ................
0004C0  00000000 00000000 00000000 00000000  ................
0004D0  00000000 00000000 00000000 00000000  ................
0004E0  00000000 00000000 00000000 00000000  ................
0004F0  00000000 00000000 00000000 00000000  ................
000500  00000000 00000000 00000000 00000000  ................
000510  00000000 00000000 00000000 00000000  ................
000520  00000000 00000000 00000000 00000000  ................
000530  00000000 00000000 00000000 00000000  ................
000540  00000000 00000000 00000000 00000000  ................
000550  00000000 00000000 00000000 00000000  ................
000560  00000000 00000000 00000000 00000000  ................
000570  00000000 00000000 00000000 00000000  ................
000580  00000000 00000000 00000000 00000000  ................
000590  00000000 00000000 00000000 00000000  ................
0005A0  00000000 00000000 00000000 00000000  ................
0005B0  00000000 00000000 00000000 00000000  ................
0005C0  00000000 00000000 00000000 00000000  ................
0005D0  00000000 00000000 00000000 00000000  ................
0005E0  00000000 00000000 00000000 00000000  ................
0005F0  00000000 00000000 00000000 00000000  ................
000600  00000000 00000000 00000000 00000000  ................
000610  00000000 00000000 00000000 00000000  ................
000620  00000000 00000000 00000000 00000000  ................
000630  00000000 00000000 00000000 00000000  ................
000640  00000000 00000000 00000000 00000000  ................
000650  00000000 00000000 00000000 00000000  ................
000660  00000000 00000000 00000000 00000000  ................
000670  00000000 00000000 00000000 00000000  ................
000680  00000000 00000000 00000000 00000000  ................
000690  00000000 00000000 00000000 00000000  ................
0006A0  00000000 00000000 00000000 00000000  ................
0006B0  00000000 00000000 00000000 00000000  ................
0006C0  00000000 00000000 00000000 00000000  ................
0006D0  00000000 00000000 00000000 00000000  ................
0006E0  00000000 00000000 00000000 00000000  ................
0006F0  00000000 00000000 00000000 00000000  ................
000700  00000000 00000000 00000000 00000000  ................
000710  00000000 00000000 00000000 00000000  ................
000720  00000000 00000000 00000000 00000000  ................
000730  00000000 00000000 00000000 00000000  ................
000740  00000000 00000000 00000000 00000000  ................
000750  00000000 00000000 00000000 00000000  ................
000760  00000000 00000000 00000000 00000000  ................
000770  00000000 00000000 00000000 00000000  ................
000780  00000000 00000000 00000000 00000000  ................
000790  00000000 00000000 00000000 00000000  ................
0007A0  00000000 00000000 00000000 00000000  ................
0007B0  00000000 00000000 00000000 00000000  ................
0007C0  00000000 00000000 00000000 00000000  ................
0007D0  00000000 00000000 00000000 00000000  ................
0007E0  00000000 00000000 00000000 00000000  ................
0007F0  00000000 00000000 00000000 00000000  ................
C:\vbox\x64test\efi\boot>
C:\vbox\x64test\efi\boot>hexdump bootx64.efi
000000  4D5A9000 03000000 04000000 FFFF0000  MZ..............
000010  B8000000 00000000 40000000 00000000  ........@.......
000020  00000000 00000000 00000000 00000000  ................
000030  00000000 00000000 00000000 80000000  ................
000040  0E1FBA0E 00B409CD 21B8014C CD215468  ........!..L.!Th
000050  69732070 726F6772 616D2063 616E6E6F  is program canno
000060  74206265 2072756E 20696E20 444F5320  t be run in DOS
000070  6D6F6465 2E0D0D0A 24000000 00000000  mode....$.......
000080  50450000 64860200 825F1C64 00000000  PE..d...._.d....
000090  00000000 F0002E02 0B020224 00020000  ...........$....
0000A0  00020000 00000000 00100000 00100000  ................
0000B0  00000040 01000000 00100000 00020000  ...@............
0000C0  04000000 00000000 05000200 00000000  ................
0000D0  00300000 00040000 E1C20000 0A006001  .0............`.
0000E0  00002000 00000000 00100000 00000000  .. .............
0000F0  00001000 00000000 00100000 00000000  ................
000100  00000000 10000000 00000000 00000000  ................
000110  00200000 14000000 00000000 00000000  . ..............
000120  00000000 00000000 00000000 00000000  ................
000130  00000000 00000000 00000000 00000000  ................
000140  00000000 00000000 00000000 00000000  ................
000150  00000000 00000000 00000000 00000000  ................
000160  00000000 00000000 00000000 00000000  ................
000170  00000000 00000000 00000000 00000000  ................
000180  00000000 00000000 2E746578 74000000  .........text...
000190  60000000 00100000 00020000 00040000  `...............
0001A0  00000000 00000000 00000000 20005060  ............ .P`
0001B0  2E696461 74610000 14000000 00200000  .idata....... ..
0001C0  00020000 00060000 00000000 00000000  ................
0001D0  00000000 400030C0 00000000 00000000  ....@.0.........
0001E0  00000000 00000000 00000000 00000000  ................
0001F0  00000000 00000000 00000000 00000000  ................
000200  00000000 00000000 00000000 00000000  ................
000210  00000000 00000000 00000000 00000000  ................
000220  00000000 00000000 00000000 00000000  ................
000230  00000000 00000000 00000000 00000000  ................
000240  00000000 00000000 00000000 00000000  ................
000250  00000000 00000000 00000000 00000000  ................
000260  00000000 00000000 00000000 00000000  ................
000270  00000000 00000000 00000000 00000000  ................
000280  00000000 00000000 00000000 00000000  ................
000290  00000000 00000000 00000000 00000000  ................
0002A0  00000000 00000000 00000000 00000000  ................
0002B0  00000000 00000000 00000000 00000000  ................
0002C0  00000000 00000000 00000000 00000000  ................
0002D0  00000000 00000000 00000000 00000000  ................
0002E0  00000000 00000000 00000000 00000000  ................
0002F0  00000000 00000000 00000000 00000000  ................
000300  00000000 00000000 00000000 00000000  ................
000310  00000000 00000000 00000000 00000000  ................
000320  00000000 00000000 00000000 00000000  ................
000330  00000000 00000000 00000000 00000000  ................
000340  00000000 00000000 00000000 00000000  ................
000350  00000000 00000000 00000000 00000000  ................
000360  00000000 00000000 00000000 00000000  ................
000370  00000000 00000000 00000000 00000000  ................
000380  00000000 00000000 00000000 00000000  ................
000390  00000000 00000000 00000000 00000000  ................
0003A0  00000000 00000000 00000000 00000000  ................
0003B0  00000000 00000000 00000000 00000000  ................
0003C0  00000000 00000000 00000000 00000000  ................
0003D0  00000000 00000000 00000000 00000000  ................
0003E0  00000000 00000000 00000000 00000000  ................
0003F0  00000000 00000000 00000000 00000000  ................
000400  C3C3C3C3 C3C3C3C3 C3C3C3C3 C3C3C3C3  ................
000410  C3C3C3C3 C3C3C3C3 C3C3C3C3 C3C3C3C3  ................
000420  C3C3C3C3 C3C3C3C3 C3C3C3C3 C3C3C3C3  ................
000430  C3C3C3C3 C3C3C3C3 C3C3C3C3 C3C39090  ................
000440  FFFFFFFF FFFFFFFF 00000000 00000000  ................
000450  FFFFFFFF FFFFFFFF 00000000 00000000  ................
000460  00000000 00000000 00000000 00000000  ................
000470  00000000 00000000 00000000 00000000  ................
000480  00000000 00000000 00000000 00000000  ................
000490  00000000 00000000 00000000 00000000  ................
0004A0  00000000 00000000 00000000 00000000  ................
0004B0  00000000 00000000 00000000 00000000  ................
0004C0  00000000 00000000 00000000 00000000  ................
0004D0  00000000 00000000 00000000 00000000  ................
0004E0  00000000 00000000 00000000 00000000  ................
0004F0  00000000 00000000 00000000 00000000  ................
000500  00000000 00000000 00000000 00000000  ................
000510  00000000 00000000 00000000 00000000  ................
000520  00000000 00000000 00000000 00000000  ................
000530  00000000 00000000 00000000 00000000  ................
000540  00000000 00000000 00000000 00000000  ................
000550  00000000 00000000 00000000 00000000  ................
000560  00000000 00000000 00000000 00000000  ................
000570  00000000 00000000 00000000 00000000  ................
000580  00000000 00000000 00000000 00000000  ................
000590  00000000 00000000 00000000 00000000  ................
0005A0  00000000 00000000 00000000 00000000  ................
0005B0  00000000 00000000 00000000 00000000  ................
0005C0  00000000 00000000 00000000 00000000  ................
0005D0  00000000 00000000 00000000 00000000  ................
0005E0  00000000 00000000 00000000 00000000  ................
0005F0  00000000 00000000 00000000 00000000  ................
000600  00000000 00000000 00000000 00000000  ................
000610  00000000 00000000 00000000 00000000  ................
000620  00000000 00000000 00000000 00000000  ................
000630  00000000 00000000 00000000 00000000  ................
000640  00000000 00000000 00000000 00000000  ................
000650  00000000 00000000 00000000 00000000  ................
000660  00000000 00000000 00000000 00000000  ................
000670  00000000 00000000 00000000 00000000  ................
000680  00000000 00000000 00000000 00000000  ................
000690  00000000 00000000 00000000 00000000  ................
0006A0  00000000 00000000 00000000 00000000  ................
0006B0  00000000 00000000 00000000 00000000  ................
0006C0  00000000 00000000 00000000 00000000  ................
0006D0  00000000 00000000 00000000 00000000  ................
0006E0  00000000 00000000 00000000 00000000  ................
0006F0  00000000 00000000 00000000 00000000  ................
000700  00000000 00000000 00000000 00000000  ................
000710  00000000 00000000 00000000 00000000  ................
000720  00000000 00000000 00000000 00000000  ................
000730  00000000 00000000 00000000 00000000  ................
000740  00000000 00000000 00000000 00000000  ................
000750  00000000 00000000 00000000 00000000  ................
000760  00000000 00000000 00000000 00000000  ................
000770  00000000 00000000 00000000 00000000  ................
000780  00000000 00000000 00000000 00000000  ................
000790  00000000 00000000 00000000 00000000  ................
0007A0  00000000 00000000 00000000 00000000  ................
0007B0  00000000 00000000 00000000 00000000  ................
0007C0  00000000 00000000 00000000 00000000  ................
0007D0  00000000 00000000 00000000 00000000  ................
0007E0  00000000 00000000 00000000 00000000  ................
0007F0  00000000 00000000 00000000 00000000  ................
C:\vbox\x64test\efi\boot>
If you rename loop.efi to bootx64.efi, you will get an
infinite loop as the first instruction.
bootx64.efi as it stands just returns immediately (via
ret) so you will return to your BIOS or a shell may be
executed or something else.
I included a whole lot of "ret" instructions as padding
so that you can zap your own machine code in to do
further testing.
I didn't use "nop" because the assembler pads with nop.
If you zap your own machine code, the required checksum
of the PE executable will change - I don't know if all/any
UEFI actually check that. The location of the checksum
is presumably one of these:
C:\vbox\x64test\efi\boot>fc /b loop.efi bootx64.efi
Comparing files loop.efi and BOOTX64.EFI
00000088: F2 82
00000089: 5E 5F
000000D8: 79 E1
000000D9: FD C2
00000400: EB C3
00000401: FE C3
That's strange - a recompilation changed both:
C:\devel\pdos\pdpclib\xxx3>fc /b \vbox\x64test\efi\boot\bootx64.efi bootx64.efi
Comparing files \VBOX\X64TEST\EFI\BOOT\bootx64.efi and BOOTX64.EFI
00000088: 82 49
00000089: 5F 64
000000D8: E1 A8
000000D9: C2 C7
Maybe the timestamp is included in the checksum.
So take a guess.
You'll presumably need to disable secure boot in the BIOS too.
Issues:
1. I'm not sure you will be in ring 0. Maybe try writing to the serial
port - I don't think you can write to b8000 because I think you
will be in graphics mode.
2. The loop will terminate after a while (minutes?) because of a
watchdog timer. There is a UEFI call to disable the watchdog.
I'm not sure you will need to do that if your bootloader does
something substantial.
3. As far as I know, most people do a UEFI call to "exit boot
services" before they start doing something substantial.
I don't know if you can bypass that.
So you may need to do 0, 1 or 2 UEFI calls.
I can provide the offsets if required:
C:\devel\pdos\pdpclib>grep -i exit efi.h
efi.h:     void *Exit;
efi.h:     void *ExitBootServices;
C:\devel\pdos\pdpclib>grep -i watchdog efi.h
efi.h: typedef EFI_STATUS (EFIAPI *EFI_SET_WATCHDOG_TIMER) (IN UINTN Timeout, IN UINT64 WatchdogCode, IN UINTN DataSize, IN CHAR16 *WatchdogData);
efi.h:     EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;
C:\devel\pdos\pdpclib>
But I've only tested the watchdog.
BFN. Paul.