flat assembler
Message board for the users of flat assembler.

Index > OS Construction > How can make my program boot from floppy?

Author
Thread Post new topic Reply to topic
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 15 Nov 2004, 13:20
Hi!
Well, I'm really new to assembler, but I want to make simple hello world app, witch will load from floppy!

As far ask I know I need to use: ORG 7C00h instead of ORG 256. But what next?
Code:
ORG 7C00hmov ah, 9mov dx, msgint 21hint 20hmsg DB "Hello World$"    

What else do I need to include into my source code, so it would be able to boot from floppy? And next thing. What application do I need to use to write my program on the boot sector of floppy? I use Linux, but I also have DOS! Right now I'm learning Assembly into DOS! Thank you!
Post 15 Nov 2004, 13:20
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 15 Nov 2004, 14:51
1) You will need a 512-byte header (for booting) that ends with 55AA
2) You need to write it in the boot sector
3) Then you'd have to write your program to other sectors.
Search the forums - there are some tutorials about it.
Post 15 Nov 2004, 14:51
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 15 Nov 2004, 15:37
Thank you, but...
The only thing I found is this: http://board.flatassembler.net/topic.php?t=2120
After I compile this code, how can I write it on floppy so it will boot from it?

And if my apps size is bigger than 512 bytes, I need to make two apps?
1. boot loader
2. my app?

Thank you!
Post 15 Nov 2004, 15:37
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 15 Nov 2004, 16:55
Try this code assemble as a bin file.
Code:
;************************************; \\|//; (@ @); ASHLEY4.; Put test.bin on boot sector; with rawrite.; Assemble with fasm; c:\fasm test.asm test.bin;;************************************org 0x7C00use16;****************************; Realmode startup code.;****************************start:        xor   ax,ax        mov   ds,ax        mov   es,ax        mov   ss,ax        mov   sp,0x7C00writesometext:        mov   ax,0xB800   mov   es,ax        lea   si,[msg0]        mov   di,(80 * 1 + 2) * 2                 mov   cx,28        cld        rep   movsb              jmp   $  msg0        db "  H E L L O   W O R L D !   " ;*************************************; Make program 510 byte's + 0xaa55;*************************************            times 510- ($-start)  db 0dw 0xaa55     


Also you can not use dos int for boot code ( dos is not loaded ), bios int are ok in realmode.

Or you can do it the easy way and get bootprog.zip, get it and info on it from here:
http://alexfru.chat.ru/epm.html

Hope this helps.

PS: In the above code you must have the same spacer between the letters of the string, as these are the color bytes.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.


Last edited by ASHLEY4 on 15 Nov 2004, 17:55; edited 2 times in total
Post 15 Nov 2004, 16:55
View user's profile Send private message Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 15 Nov 2004, 17:25
Thank you very much! But how can I write it on the floppy??? What tool can I use on DOS or Linux?
Post 15 Nov 2004, 17:25
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 15 Nov 2004, 17:44
rawrite for dos, run the program it will say name of image, you type test.bin and press enter, it will ask for drive you type A: and press enter, it then says put a floppy in the A: drive and press enter.
And when the floppy light is out you can reboot and try it.

http://www.tux.org/pub/dos/rawrite/
Get rawrite.exe

NOTES:
Make show the bin file is in the same dir, as rawrite, or so once your write to the floppy in this way, it will need to format the floppy to use it in win/linux.
So make shore you do not have any thing on the disk you want.

PS: The OS forum may be a better place to ask OS/boot ? Wink.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 15 Nov 2004, 17:44
View user's profile Send private message Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 15 Nov 2004, 19:18
OK, thank you very much!!! Can't wait to make it boot!!!
Post 15 Nov 2004, 19:18
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 15 Nov 2004, 23:47
Kristian_ wrote:
Hi!
Well, I'm really new to assembler, but I want to make simple hello world app, witch will load from floppy!

As far ask I know I need to use: ORG 7C00h instead of ORG 256. But what next?
Code:
ORG 7C00h
mov ah, 9
mov dx, msg
int 21h
int 20h

msg DB "Hello World$"
    


well, from the begining, you can't use dos function as you are not running any operating system during bootup.
you should use bios function instead. (ah=0xe; int 10h)
btw .: where do you wanna exit with int 20h? Very Happy
Post 15 Nov 2004, 23:47
View user's profile Send private message Visit poster's website Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 16 Nov 2004, 04:43
Thank you!
Quote:
btw .: where do you wanna exit with int 20h? Very Happy

I never fought about it! Embarassed As far as I understood I can't just exit! I need to reboot right? About thous BIOS calls, BIOS allready have pre-created fonts, and I can use them in real mode for displaying strings?

If I want to create something bigger than just a small app (if I need to access more than 1MB of RAM, I will need to use Protected mode? And since I can't use BIOS calls in Protected mode, I will need to create my own fonts and characters with Pixels, and since I can't use BIOS I will need to write directly to Video memory to display pixels? Thank you!
Post 16 Nov 2004, 04:43
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 16 Nov 2004, 06:02
This code will put you in pmode (not tested)
Code:
;************************************; \\|//; (@ @); ASHLEY4.; Put test.bin on boot sector; with rawrite.; Assemble with fasm; c:\fasm test.asm test.bin;************************************org 0x7C00use16;****************************; Realmode startup code.;****************************start:        xor   ax,ax        mov   ds,ax        mov   es,ax        mov   ss,ax        mov   sp,0x7C00;*****************************; Setting up, to enter pmode.;*****************************        cli         lgdt  [gdtr]                mov   eax, cr0        or    al,0x1         mov   cr0,eax         jmp   0x10: protected;*****************************; Pmode. Wink;*****************************use32protected:        mov   ax,0x8        mov   ds,ax        mov   es,ax        mov   ss,ax        mov   esp,0x7C00;*****************************; Turn floppy off (if space).;*****************************        mov   dx,3F2h        mov   al,0        out   dx,al        lea esi,[msg0]                  mov edi,0xB8000 + (80 * 3 + 4) * 2            mov   ecx,28  cld   rep movsb        jmp   $;*************************************; GDT. ;*************************************gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CFsys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CFgdt_end:gdtr:        dw gdt_end - gdt - 1                                                  dd gdt;*************************************; Data. ;*************************************msg0        db "  H E L L O   W O R L D !   " ;*************************************; Make program 510 byte's + 0xaa55;*************************************            times 510- ($-start)  db 0dw 0xaa55     


You do not need to make you own fonts for pmode textmode, only if you use vesa.
put it on the disk as before.
NOTE: you can not use int's, with this code as it is.

PS: In boot code to start with you can just do this:
Code:
LetsStayHere:         jmp  LetsStayHere     

You can then just switch off your pc, because you can not exit in any other way, from a basic boot/os.

PPS: To get more ram, you will need to enable A20, in the above code.
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 16 Nov 2004, 06:02
View user's profile Send private message Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 16 Nov 2004, 15:32
Thank you very much! But I have a problem! I try to write this bin on floppy, but when I rebooted my comp., my drive is starting to read the floppy and make some strange sounds for 3 seconds and just boots into lilo (boot manager). I try it on 4 floppy disks, but still the same sound. Can I burn it on CD? Then I try to install MenuetOS on floppy so I downloaded installer, but after the installation, the same result! My HDD is set into 4 partitions:
1. Linux ext3
2.Linux ext3
3.Linux Swap
4. fat32

Can I somehow put it on the first sector of fat32 partition? My BIOS is set to load first from floppy, but I can't seem to understand why can't it read! I can read/write data and everthing works, but doesn't work for booting! And thank you for the source!!!
Post 16 Nov 2004, 15:32
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 16 Nov 2004, 16:57
NO! DO NOT TRY and put it on your hdd, it is not a good idea to touch your hdd, when testing code.
Is there not a floppy option in lilo menu ?.
Have you got any thing to boot from A: drive ?
Maybe doubler check bios floppy boot.

PS: If you have vesa 2 on your pc, you can try down loading a small demo of a atapi driver, just burn it to cd and boot, this will test if you can burn it to cd, its a iso.
it called "DemoVesa.zip" get here: http://www.falconrybells.co.uk/

PPS: I have try test.bin on all my pc and it works,so as now been tested.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 16 Nov 2004, 16:57
View user's profile Send private message Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 16 Nov 2004, 18:39
Thank you! I burned DemoVesa.zip, but after I restarted my computer, the CD booted, first it detected like Floppy drive, next it like changed resolution, but there was only blank screen and the cd led was blinking, but nothing happened, Does it has to be this way? Thanx!

P.S: Thank you for moving this post!
Post 16 Nov 2004, 18:39
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 16 Nov 2004, 20:27
If it went to a black screen with no cursor, then you can boot cd's ok. so you can make a bootable cd from the floppy image.

Some cd do not read very well from cd-rw and others do not read very well cd-r at boot time, also try to boot more time and try pressing the A key when the cd light goes out, to retest "DemoVesa" also theres a menuetos iso,i think.

ps: i did not move your post here.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 16 Nov 2004, 20:27
View user's profile Send private message Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 23 Nov 2004, 17:18
Thanx!
Well, your code is great and working, but too complicated for me to understand, but I got very simple boot code ready, but I have some questions:

Code:
org 0x7C00
use 16                          ; does this mean 16 bit?

      start:
           mov ax, 0x0003     
           int 0x10

times 510-($-start) db 0    ; this makes program 512 bytes long, but why does it says times 510 not 512?
                                          ; and after this line executes, it goto start label ? and where can I read more about this times function and its syntax? 
dw 0xAA5                          ; what does this mean?
    


Thank you!
Post 23 Nov 2004, 17:18
View user's profile Send private message Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu 23 Nov 2004, 18:44
use 16 ; does this mean 16 bit?
yes, it means.

times 510-($-start) db 0 ; this makes program 512 bytes long, but why does it says times 510 not 512?
because after that there is one other word=2 bytes:

dw 0xAA5 ; what does this mean?
it's for the PC to see, that this floppy is bootable.
Post 23 Nov 2004, 18:44
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 23 Nov 2004, 20:47
510 + 0xAA55 = 512 bytes Wink.
here a link to a simple hello boot programs, may help.
http://osdev.neopages.net/tutorials/hello_btldr.php?the_id=85
NOTE: use this if you use fasm
Code:
org 0x7C00use 16                          ; does this mean 16 bit?start:    
and this
Code:
    times 510-($-start) db 0    dw 0xAA55     

As the code in the link users nasm.

ps: remember to put jmp $
at the end, and Y have you done, set text mode, ? you should not need to set this.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 23 Nov 2004, 20:47
View user's profile Send private message Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_ 23 Nov 2004, 22:18
Thank you very much!!! Smile
Post 23 Nov 2004, 22:18
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.