2

I have created the following assembly file on x86:

mov ah, 0x0e 
mov al, 'H'
int 0x10
mov al, 'e'
int 0x10
mov al, 'l'
int 0x10
int 0x10 ; 'l' is still on al, remember?
mov al, 'o'
int 0x10

jmp $ ; jump to current address = infinite loop

; padding and magic number
times 510 - ($-$$) db 0
dw 0xaa55

I have compiled using nasm:

nasm -f bin boot_sect_simple.asm -o boot_sect_hello.bin

And tested the binary using qemu:

qemu-system-x86_64 boot_sect_hello.bin

Then I used dd to write the binary to the boot section of my USB stick:

sudo dd if=/Users/niclas/assembly/OS/boot_sect_hello.bin of=/dev/disk2

I have then tested after correctness:

sudo dd if=/dev/disk2 of=/dev/stdout bs=512 count=1 | hexdump

0000000 b4 0e b0 48 cd 10 b0 65 cd 10 b0 6c cd 10 cd 10
0000010 b0 6f cd 10 eb fe 00 00 00 00 00 00 00 00 00 00
0000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
00001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa
0000200

Seems right...

However, trying to find the routine in the boot menu of a modern machine does not seem to work... UEFI cannot find the stick. What have I done wrong?

Disclaimer: This is a UNIX question since I am using Unix and Unixlike Systems to make it bootable...

TVSuchty
  • 121

1 Answers1

2

The way you are using the interrupt routine is correct but only in x86 mode.

From Wikipedia:

on a modern x86 system, BIOS calls can only be performed in Real mode, or Virtual 8086 mode. v8086 is not an option in Long mode.

I believe that a modern system does not boot in real mode, so you cannot use int 10 directly. Further, EFI systems don't read boot sectors at all. This may be settable in the BIOS Setup, q.v. (-> "Legacy Boot").

Stephen Kitt
  • 434,908
Ned64
  • 8,726
  • Thank you for that answer, you re right. This should not work. However, I have replaced the boot code by a simple infinite loop. However, the boot stick does not get noticed by the bios/uefi... It does not find the code... – TVSuchty Mar 27 '20 at 09:46
  • Any system which can boot from a boot sector will end up booting in real mode. However enabling that, when it’s still possible, typically requires configuration in the EFI setup (to enable the BIOS CSM). – Stephen Kitt Mar 27 '20 at 09:51
  • @StephenKitt Thank you for the clarification Do you have a suggestion regarding this obscure problem? – TVSuchty Mar 27 '20 at 10:22
  • The answer will depend on the specific computer you’re using. Look for “legacy boot” or “compatibility boot” in your EFI setup... – Stephen Kitt Mar 27 '20 at 10:47
  • @StephenKitt Thanks for adding the information about the boot sector not being read (and executed) in the first place; I have adjusted my reply accordingly. – Ned64 Mar 27 '20 at 10:49
  • @TVSuchty What are you trying to achieve? If you are trying to make a bootable USB stick that is going to be used on different PCs, then I suggest looking into how UEFI boots. Most modern PCs boot in UEFI mode, and you will have to enable legacy mode separately. In addition, Intel announced in 2017 that they are planning to stop supporting legacy mode this year (2020). This probably also means removing Real Mode in new CPUs, too. – Johan Myréen Mar 27 '20 at 12:04
  • I am trying to create my own "Program" which can be run without any OS at all... (educational prupose) – TVSuchty Mar 27 '20 at 17:18
  • I hope this program can be booted from every x86 PC... – TVSuchty Mar 27 '20 at 17:27