flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Universal Single Method USB Flash Drive Boot and Run

Author
Thread Post new topic Reply to topic
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 05 Feb 2011, 20:35
The time line above shows the results of my current ongoing testing for universal single method USB flash drive boot and run.
    1. The USB flash drive was first released commercially in 2000, so any PC before then can't be expected to boot
    and run from USB flash drive.
    2. All three major BIOS (Phoenix acquired Award in 1998 but operates as separate divisions) with a date after mid
    2004 can be expected to universal single method USB flash drive boot and run (green squares).
    3. The red squares indicate the latest BIOS date for PC's with USB ports without USB booting capability.
    4. Only 6 PC's are required for the test to complete the time line. The others merely confirm the time line.

I've currently tested 10 different PC's (not including the 3 with USB ports but no setup for USB booting).
It should be noted that the universal single method USB flash drive boot and run is not a claim but rather an investigation.
It should also be noted that there exists BIOS in the gaps (whites squares) that have setup only for USB-FDD which I have
yet to test. Also there may be BIOS with USB-ZIP and no USB-HDD which may work with the single partition MBR.
The 3 requirements for universal single method USB flash drive boot and run are:
    An MBR table with a minimal single partition entry (the actual partition volume need not exist - the sector at LBA 63
    should be zeroed out for the test).
    Use the int 13h extended functions.
    The boot sector 0AA55h signature at 510h.

The following simple real mode code can be used for the test. Assemble and transfer the 2 sectors starting at LBA 0. The boot
sector loads the second sector to 600h using the int 13h extended read and jumps to it. The BIOS date at 0FFFF5h is pushed
onto the stack in reverse followed by a space, colon and the drive letter of the boot identifier which is then displayed
on screen.
Note: the code will assemble in FASM or NASM.
Code:
org 7C00h
  xor ax, ax
  mov ds, ax

  mov ss, ax
  mov sp, 7C00h                 ; optional stack initialization

  mov al, dl
  test al, 80h
  jne .1
  add al, 'A'
  jmp .2
.1:
  and al, 7fh
  add al, 'C'
.2:
  mov si, drive
  mov [si], al
  call print                    ; display boot identifier
  
  mov si, disk_address_packet
  mov ah, 42h
  int 13h
  jnc .3
  mov si, error
  call print
  jmp $
.3:
  jmp 0:600h
print:
  mov ah, 0Eh
  xor bh, bh
.1:
  mov al, [si]
  lea si, [si+1]
  test al, al
  je .2
  int 10h
  jmp .1
.2:
  ret
disk_address_packet:
  dw 10h                        ; size of packet
  dw 1                          ; number of sectors
  dw 600h, 0                    ; buffer offset, segment
  dq 1                          ; LBA
drive:
  db 'A:', 13, 10, 0
error:
  db 'int 13h failed!', 0
times 446-($-$$)                  db 0
  db 0                          ; status
  db 0, 0, 0                    ; H, S, C of first block - not required
  db 0Bh                        ; partition type
  db 0, 0, 0                    ; H, S, C of last block - not required
  dd 63                         ; LBA of first sector
  dd 67521                      ; number of blocks (33 MB - hidden)
times (16*3)                      db 0
                                  dw 0AA55h
second_stage:
  test dl, 80h
  jne .1
  add dl, 'A'
  jmp .2
.1:
  and dl, 7fh
  add dl, 'C'
.2:
  push 0
  push 0FFFFh                   ; BIOS date at 0FFFF5h
  pop es
  mov cx, 8                     ; 02/03/11 - month/day/year
  mov si, 12                    ; start at last digit
.3:
  mov al, [es:si]
  lea si, [si-1]
  push ax
  sub cx, 1
  jne .3
  push WORD ' '
  push WORD ':'
  push dx
  xor bh, bh
.4:
  pop ax
  test al, al
  je .5
  mov ah, 0Eh
  int 10h
  jmp .4
.5:
  xor ax, ax
  int 16h
  int 19h
  times 512-($-second_stage)      db 0    

EDIT: Added optional stack initialization, suggested by Mac2004
EDIT: Modified the code to display the boot identifier while still in the boot sector, as identified by Dex4u
EDIT: Modified the code to include error checking for int 13h, as suggested by Dex4u

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com


Last edited by Mike Gonta on 29 Jul 2013, 23:30; edited 6 times in total
Post 05 Feb 2011, 20:35
View user's profile Send private message Visit poster's website Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 06 Feb 2011, 05:34
Thank you for your example! I'll be testing it with my pc's later.

One question about the code:

Should you set up a proper stack poister? I see no
stack being initialized.

regards
mac2004
Post 06 Feb 2011, 05:34
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 06 Feb 2011, 07:06
I tested the code on some of my pc's. Some pc's boot ok, but one pc wasn't
even capable of detecting it as an existent drive. I have done usb booting on all of those pc's previously.

regards
mac2004
Post 06 Feb 2011, 07:06
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 06 Feb 2011, 10:14
Mac2004 wrote:
I see no stack being initialized.
Hi Mac2004,

The BIOS sets up a small stack for internal use, makes subroutine and int calls before loading the boot sector.
This stack should be sufficient for boot sector use. However, since we are not testing that particular urban legend I've
updated the code.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 06 Feb 2011, 10:14
View user's profile Send private message Visit poster's website Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 06 Feb 2011, 10:24
Mac2004 wrote:
I tested the code on some of my pc's. Some pc's boot ok,
Hi Mac2004,

Thanks for testing.
Could you PM me with the BIOS maker and BIOS date so that I can update the time line?
Mac2004 wrote:
but one pc wasn't even capable of detecting it as an existent drive. I have done usb booting on all of those pc's previously.

What is the BIOS Maker and BIOS date? What is the booting setup?

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 06 Feb 2011, 10:24
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 06 Feb 2011, 15:46
I have tested your code on Some of my PC's, all that used hdd emulation worked find.
But all that used floppy emulation did not boot.
By add a BPB they worked fine, just as i posted here

http://board.flatassembler.net/topic.php?t=12469
Post 06 Feb 2011, 15:46
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 06 Feb 2011, 16:16
Dex4u wrote:
I have tested your code on Some of my PC's, all that used hdd emulation worked find.
Hi Dex4u,

Thank you for testing.
Can you PM me the results (BIOS maker and BIOS date) to update the time line?
Dex4u wrote:
But all that used floppy emulation did not boot.
By add a BPB they worked fine, just as i posted here
http://board.flatassembler.net/topic.php?t=12469
Do they only have a USB-FDD option?
What is the BIOS maker and BIOS date?
Did you add the BPD to my test code?
Everything boots - The exception to this is if the BIOS emulates the USB flash drive as HDD it will require the boot
signature.
I've modified the code to display the boot identifier while still in the boot sector. This way even if the second stage is not
loaded the basic booting can be proven.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 06 Feb 2011, 16:16
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 06 Feb 2011, 16:34
Will do.
PS: You should also test for error after this
Code:
 mov si, disk_address_packet
  mov ah, 42h
  int 13h 
    
Post 06 Feb 2011, 16:34
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 06 Feb 2011, 17:04
Dex4u wrote:
PS: You should also test for error after this
Code:
 mov si, disk_address_packet
  mov ah, 42h
  int 13h 
    

Hi Dex4u,

The BIOS Enhanced Disk Drive Specification Version 3.0 was written in 1998, I'm generalizing that any PC that can
USB flash drive boot and run can use the int 13h extended instructions.
I've modified the code to include error checking for int 13h.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 06 Feb 2011, 17:04
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 07 Feb 2011, 09:56
Tested:
Code:
Dell D830, BIOS revision A15 (Dell?, graphical BIOS)
  C: 01/04/10
Lenovo SL500, BIOS version 1.19 (AMI)
    C: 12/25/08
HP nx7010, BIOS revision F.33 (HP?)
      C: 02/21/04
HP nc8230, BIOS revision F.11 (HP?)
      C: 05/01/06
HP 8510p, BIOS revision F.14 (HP?)
       C: 08/19/08
HP 6550b, BIOS revision F.02 (HP?, graphical BIOS)
       Does not work (BIOS date: 08/10/10)
    

I wonder why the newest HP does not work. In the BIOS I can tell it to boot from USBFDD USBHDD and even SD-card. It just falls through to HDD any way.
Post 07 Feb 2011, 09:56
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
steve6375



Joined: 30 Jan 2011
Posts: 3
Location: GB
steve6375 11 Feb 2011, 23:43
http://sites.google.com/site/rmprepusb/tutorials/diagnose-bios may be of interest? Assembler source code is included in the download of the full Beta version.
Post 11 Feb 2011, 23:43
View user's profile Send private message Reply with quote
christiandy



Joined: 03 Mar 2011
Posts: 25
Location: 101
christiandy 06 Mar 2011, 18:26
Hi Mike Gonta,
can you explain me about data address packet, I've seen the reference but still don't understand
Post 06 Mar 2011, 18:26
View user's profile Send private message AIM Address Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.