Page 1 of 1

booting from usb problem

Posted: Sat Nov 21, 2015 5:53 am
by fkernel002
Hi,I am a beginner. The problem is my code works on bochs but not on my computer.
I use following commands to create an image of my code. its just a simple code prints 'Hello' on screen.

Code: Select all

nasm -f bin printhello.asm -o boot.bin
dd if=boot.bin of=boot.img
Then i use this image on bochs and it prints message onto screen. Now i wanted to see the result on my computer without emulator.
I used the following command to write image on my usb.

Code: Select all

sudo dd if=boot.img of=/dev/sdb
Then i formatted the usb with FAT32 and used hexdump command to check it. i can see my code on first sector of usb.
If you ask why i formatted after writing image because if i format first then write my code BIOS doesnt see my usb as bootable device.
I reboot my computer and choose usb to boot from. when press enter nothing happens and boot device selection screen comes again. when i select usb and press enter again it boots to my regular operating system but not my code. I am using ubuntu 15.10. i have done a lot of research but couldnt find any solution. I installed ubuntu on my computer with same usb before. My print code is below.

Code: Select all

mov al,'H'
mov ah,0x0E
int 0x10
mov al,'e'
mov ah,0x0E
int 0x10
mov al,'l'
mov ah,0x0E
int 0x10
mov al,'l'
mov ah,0x0E
int 0x10
mov al,'o'
mov ah,0x0E
int 0x10

hang:
	jmp hang
times 510-($-$$) db 0
db 0x55
db 0xAA

Re: booting from usb problem

Posted: Sat Nov 21, 2015 6:11 am
by Octocontrabass
In order for your USB drive to be bootable, you must include either a valid partition table or a valid BPB. Since you have neither, some BIOSes will misbehave in a variety of ways.

It looks like your BIOS refuses to boot the device if it lacks the expected partition table or BPB.

Re: booting from usb problem

Posted: Sat Nov 21, 2015 6:14 am
by Brendan
Hi,

80*25 text mode only costs about 4000 bytes of display memory; so if a video card has more memory than that it can handle multiple "display pages" and let you switch between them quickly. The BIOS functions are designed for this. For example; "int 0x10, ah=0x0E" can be used to write characters to any "display page" (and not just the currently visible one), where the value you put in BH determines which "display page" you want to write characters to.

Of course your code doesn't set BH to anything, so you're writing characters to an unknown display page (which would only be the currently visible display page if/when you're lucky).


Cheers,

Brendan

Re: booting from usb problem

Posted: Sat Nov 21, 2015 6:41 am
by fkernel002
Hi, i have added the code to set active display and tried it on bochs and it works but still not working on my computer. Can i assume that it is probably about partition tables or bpb? and writing method into usb is not wrong? Actually i just wanted to see whether i can run my code on my computer before moving on. Is there any example code that doesnt change harddisk contents so i can write onto usb and run. for example like writing text on screen but a working one :)

Code: Select all

mov al,0x01 ; page number
mov ah,0x05 ;
int 0x10    ; activate page 1
mov bh,0x01 ; write to page 1
mov al,'H'
mov ah,0x0E
int 0x10
mov al,'e'
mov ah,0x0E
int 0x10
mov al,'l'
mov ah,0x0E
int 0x10
mov al,'l'
mov ah,0x0E
int 0x10
mov al,'o'
mov ah,0x0E
int 0x10

hang:
	jmp hang
times 510-($-$$) db 0
db 0x55
db 0xAA

Re: booting from usb problem

Posted: Sat Nov 21, 2015 7:18 am
by fkernel002
I got it working finally. I checked the contents of the first sector on usb. As you said there were no partition table entries after 446 bytes, it was all zeros. I used Disks program on ubuntu. There was an option as 'bootable' so i selected it. Then checked it with hexdump and saw it's added partition table entries on first sector. But i also had to change BIOS option and enable CSM. When i enabled CSM a new usb bootable device appeared on the list and i booted from it. I'm not sure if only enabling CSM is enough with no partition table entries i will try it later. thanks for your help :]