I am on Ubuntu and I made a simple bootloader that just simply print a character.
It works well on qemu-system-i386
It looks like this:
start:
mov ah, 0x0e
mov al, '~'
int 0x10
jmp $
times 510-($-$$) db 0
db 0x55
db 0xaa
And I build with
fasm loader.asm img.bin
then check if my usb is available:
lsblk
after check that my usb is available at /dev/sdc, I ran
sudo dd if=img.bin of=/dev/sdc
sync
And finally check if dd wrote well:
dd if=/dev/sdc bs=512 count=1 > f
ndisasm -b 16 f
above ndisasm print:
00000000 B40E mov ah,0xe
00000002 B07E mov al,0x7e
00000004 CD10 int 0x10
00000006 EBFE jmp short 0x6
00000008 0000 add [bx+si],al
0000000A 0000 add [bx+si],al
repeats 0000...
000001FE 55 push bp
000001FF AA stosb
Now, I put this usb to real laptop with 32bit processor(Pentium M).
but it reboots again and again.
So, my question is: can I guess my usb broken?
I don't know if this related with my problem but.. here is one more thing: When I ran follow commands without usb inserted,
dd if=/dev/sdc bs=512 count=1 > f
ndisasm -b 16 f
above ndisasm print:
00000000 B40E mov ah,0xe
00000002 B07E mov al,0x7e
00000004 CD10 int 0x10
00000006 EBFE jmp short 0x6
00000008 0000 add [bx+si],al
0000000A 0000 add [bx+si],al
repeats 0000...
000001FE 55 push bp
000001FF AA stosb
as if I inserted usb memory stick.
Will you give me some advice?
Thanks. (I tried hard to formulate a clear, and useful question. If it's not, please let me know.)
EDIT: I tested with BPB. The source code looks like this(nop added):
jmp start
nop
bpbOEM db "TEST "
bpbBytesPerSector: DW 512
bpbSectorsPerCluster: DB 1
bpbReservedSectors: DW 1
bpbNumberOfFATs: DB 2
bpbRootEntries: DW 224
bpbTotalSectors: DW 2880
bpbMedia: DB 0xF0
bpbSectorsPerFAT: DW 9
bpbSectorsPerTrack: DW 18
bpbHeadsPerCylinder: DW 2
bpbHiddenSectors: DD 0
bpbTotalSectorsBig: DD 0
bsDriveNumber: DB 0
bsUnused: DB 0
bsExtBootSignature: DB 0x00
bsSerialNumber: DD 0x00000000
bsVolumeLabel: DB " "
bsFileSystem: DB " "
start:
mov ah, 0x0e
mov al, '~'
int 0x10
jmp $
times 510-($-$$) db 0
db 0x55
db 0xaa
I ran:
fasm loader.asm img.bin
lsblk
sudo dd if=img.bin of=/dev/sdc
sync
dd if=/dev/sdc bs=512 count=1 > f
ndisasm -b 16 f
and it prints:
00000000 EB3B jmp short 0x3d
00000002 54 push sp
00000003 45 inc bp
00000004 53 push bx
00000005 54 push sp
00000006 2020 and [bx+si],ah
00000008 2020 and [bx+si],ah
0000000A 0002 add [bp+si],al
0000000C 0101 add [bx+di],ax
0000000E 0002 add [bp+si],al
00000010 E000 loopne 0x12
00000012 40 inc ax
00000013 0BF0 or si,ax
00000015 0900 or [bx+si],ax
00000017 1200 adc al,[bx+si]
00000019 0200 add al,[bx+si]
0000001B 0000 add [bx+si],al
0000001D 0000 add [bx+si],al
0000001F 0000 add [bx+si],al
00000021 0000 add [bx+si],al
00000023 0000 add [bx+si],al
00000025 0000 add [bx+si],al
00000027 0000 add [bx+si],al
00000029 0020 add [bx+si],ah
0000002B 2020 and [bx+si],ah
0000002D 2020 and [bx+si],ah
0000002F 2020 and [bx+si],ah
00000031 2020 and [bx+si],ah
00000033 2020 and [bx+si],ah
00000035 2020 and [bx+si],ah
00000037 2020 and [bx+si],ah
00000039 2020 and [bx+si],ah
0000003B 2020 and [bx+si],ah
0000003D B40E mov ah,0xe
0000003F B07E mov al,0x7e
00000041 CD10 int 0x10
00000043 EBFE jmp short 0x43
repeats 0000...
000001FD 0055AA add [di-0x56],dl
And the result was same. The real machine reboots again and again.
EDIT2: This is a bootloader that beeps. It worked on different usb, same computer.
bits 16
org 0x7c00
jmp main
main:
mov ax, 3
int 0x10
mov ah, 0x0e
mov al, 'A'
int 0x10
mov al, 0xb6
out 0x43, al
mov al, 0xa9
out 0x42, al
mov al, 0x04
out 0x42, al
in al, 0x61
mov ah, al
or al, 011b
test al, ah
je done
out 0x61, al
done:
jmp $
times 510-($-$$) db 0
db 0x55
db 0xaa
times 1474560 - ($-$$) db 0