0

Is NASM incompatible with certain hardware configurations?

the following code runs on Qemu and an Intel Pentium system, however, when it's run on a Intel Celeron based computer, the HP Compaq dc7600 in particular, the system claims that the volume is not valid, stating Non-System disk or disk error. is this a system configuration error, if it is, what would I need to change? (8.4 in datasheet).

[BITS 16]

main:
    cli
    hlt  

times 510 - ($-$$) db 0
dw 0xAA55

the system is booting from a binary file created with nasm -fbin mbr.asm -o mbr.bin and is written to a usb drive with dd if=mbr.bin of=/dev/sdb

jwen
  • 79
  • 8
  • 2
    Is this being placed on floppy media or hard disk on the HP system (USB device or real floppy/HD media?). It is possible if this is on a hard drive that the BIOS is looking for a partition table in the boot sector with at least one partition marked active. – Michael Petch Nov 01 '22 at 04:33
  • 2
    NASM just puts what you tell it to in the output file. The right question to ask is whether your computer is compatible with legacy 16-bit BIOS MBR bootloaders (e.g. compat support modules have to be enabled in modern EFI firmware, although your system might be old enough that it can only boot as legacy BIOS). And whether you've correctly created one (you have, if you assemble this with `nasm -f bin foo.asm`), and whether you've correctly put that boot sector on a disk the computer will try to boot from (we have no idea because you left that part out of your [mcve]) – Peter Cordes Nov 01 '22 at 04:42
  • @PeterCordes : The computer system in question goes back to the mid 2000s and is using a legacy BIOS. He has put a minimal example in his question. He has a cli/hlt + boto sig and his BIOS isn't recognizing it as valid media despite it having a boot signature (0xaa55). I have a suspicion that this is either BIOS configuration issue or he's using a BIOS that is looking for somehting specific in the boot sector – Michael Petch Nov 01 '22 at 04:43
  • @MichaelPetch: A [mcve] would include details on all the steps that lead to the problem, including building the source to a binary and putting it on some media for the machine to boot from. A MCVE does not just mean the source code itself, especially in a question asking about it working on one machine but not another. If I had the same model of machine and wanted to reproduce the problem, I'd have to make up a lot of steps on my own. – Peter Cordes Nov 01 '22 at 04:46
  • I think you can assume it is being built as a binary since it works on one device and no the other. There are definitely BIOSes out there that require more than a boot signature to be recognized as bootable media. It is also possible that he has one of these BIOSes that boots floppy media but wants to detect floppy media by looking for a valid BIOS Data Block (often looking for a JMP as first instruction). I think this is going to come down to a BIOS config issue or BIOS peculiarities and issues with the fact that this boot sector isn't really representative of bootable media. – Michael Petch Nov 01 '22 at 04:48
  • Knowing the kind of media that is being booted will likely be key to helping. – Michael Petch Nov 01 '22 at 04:51
  • 2
    I'd start by using the code from this answer which has both a BIOS Parameter Block and Partition Table with an active partition marked: https://stackoverflow.com/a/74128252/3857942 . The question - does that work? If so it might give us an idea what kind of problem you have, like whether the problem is a BIOS setting or whether your BIOS may be overly smart in trying to detect valid bootable media. – Michael Petch Nov 01 '22 at 05:27
  • I'd also be curious to know how you write the bootloader to the media you are booting. Do you do that from Windows or Linux or some other means? – Michael Petch Nov 01 '22 at 05:33
  • One possible BIOS config issue would be the boot order. Are you booting other drives first and another device in the HP has a non system disk and is stopping before you it reaches the device that your boot sector is on? Make sure the boot order has the device you are testing listed first. – Michael Petch Nov 01 '22 at 06:00
  • 1
    the post was edited for more information regarding how the drive was written, thank you @michael-petch. turns out there was no partition table on the disk, witch was something that this system requires for a medium to appear bootable. – jwen Nov 01 '22 at 14:14
  • Yeah, booting as hard drive and having a bootable partition was often needed by BIOSes to identify media as bootable. Often 0xaa55 at the end wasn't enough. I assume you were booting as a hard drive. – Michael Petch Nov 01 '22 at 15:02

1 Answers1

3

Some BIOS's require a partition to be set in order to reconize a device as bootable. the following is the absolute minimal code required to get the system to boot:

[ORG 0x7c00]
[BITS 16]

main:
    cli
    hlt


times 494 - ($ - $$) db 0x00 ; Padding to 512 bytes

; Partitions table for a MBR

partition_table_1:
    db 0x80 ; Status, 0x80 means active
    db 0x00 ; First Absolute Sector CHS
    db 0x00 ; 
    db 0x00 ;  
    db 0x00 ; Partition Type
    db 0x00 ; Last Absolute Sector CHS
    db 0x00 ; 
    db 0x00 ; 
    dd 0x00000001 ; First Absolute Sector LBA
    dd 0x00000200 ; Number of Sectors

dw 0xAA55 ; Boot signature required to boot

thanks to the comment posted by Michael Petch, take a look at his comment for a more complete example.

jwen
  • 79
  • 8