BetaArchive Logo
Total Current Archive Size: 4925.26GB in 15820 files
Navigation Home Screenshots Image Uploader Server Info FTP Servers Wiki Forum RSS Feed Rules Please Donate
UP: 5d, 11h, 11m | CPU: 7% | MEM: 4138MB of 12279MB used
{The community for beta collectors}

Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPost subject: [Tut] Making your own bootloader        Posted: Sat Apr 21, 2012 9:28 pm 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Thu Apr 19, 2012 7:18 am

Posts
88

Location
The Democratic People's Republic of Korea

Favourite OS
ArchLinux GNU/Linux distro
Hi BA!

I will show you how to make an sample bootloader that doesn't load anything and how to expand it.

1. You'll need NASM for compilation.

2. First we need to start with that lines:
Code:
[BITS 16]   ;16bit - it means it will be 16 bit code
[ORG 0x7C00]    ;offset - it's RAM memory offset, it will write code to RAM starting of this

This is very important!

3. Okay, now let start coop with bios (in this case we will change video mode for drawing):
Code:
MOV AH, 0x00 ; change video mode
MOV AL, 0x13 ; 0x13
INT 0x10 ; interrupt

Interrupt is just like function call and AH and AL are just like arguments.
MOV - set register to provided value

4. Now we'll call function that will be written after this:
Code:
CALL DrawTenLines   ;lets draw


And we will hang the program forever:
Code:
JMP $       ;hang it


Main difference between JMP and CALL:
JMP jumps to code, CALL does the same and returns back if meets RET.

5. Now DrawOneLine function, take a look:
Code:
DrawOneLine:
MOV CX, 0x00 ;x = 0

nextpixel:
INT 0x10 ;Video interrupt - BIOS
ADD CX, 0x01 ;add one :D
CMP CX, 10 ;if (x == 10) {
JE exitfunc ;exit function } else {
JNE nextpixel ;next pixel }
exitfunc: ;exit :D
RET

In C:
Code:
void DrawOneLine() {
int x = 0;
while (x != 10) {
setPixel(x, y, WHITE);
x++;
}
}


But - we don't set y... and colors:
Code:
DrawTenLines: ;draw some lines
MOV AH, 0x0C ;func number - WritePixelOnScreen [wiki]
MOV AL, 0x0F ;color - Magenta
MOV BH, 0x00 ;page no
MOV DX, 0x00 ;y = 0
CALL DrawOneLine
MOV DX, 0x01 ;y = 1
CALL DrawOneLine
MOV DX, 0x02 ;y = 2
CALL DrawOneLine
MOV DX, 0x03 ;y = 3
CALL DrawOneLine
MOV DX, 0x04 ;y = 4
CALL DrawOneLine
MOV DX, 0x05 ;y = 5
CALL DrawOneLine
MOV DX, 0x06 ;y = 6
CALL DrawOneLine
MOV DX, 0x07 ;y = 7
CALL DrawOneLine
MOV DX, 0x08 ;y = 8
CALL DrawOneLine
MOV DX, 0x09 ;y = 9
CALL DrawOneLine
RET


5. Okay, now we have code, but it's still not bootloader. It doesn't have one main thing:
Code:
TIMES 510 - ($ - $$) db 0   ;filler
DW 0xAA55           ;boot signature


Yep, a boot signature, it looks like UŞ in ASCII.

Okay, now - how to compile it?

Type this (if you installed NASM):
Code:
nasm -f bin boot.asm -o boot.bin


Downloads:
ASM code file - http://djmati11.com/uploads/Random.stuff/boot2.asm
BIN compiled file (ready to use) - http://djmati11.com/uploads/Random.stuff/boot2.bin

Edition fixed (optimized) by marmmm:
ASM code file - http://djmati11.com/uploads/Random.stuff/boot3.asm
ASM mirror: http://marm.homepage.t-online.de/files/boot2.asm
BIN compiled file (ready to use) - http://djmati11.com/uploads/Random.stuff/boot3.bin

Ready to use bootdisks for VirtualBox (*.vdi):
djmati11's version - http://djmati11.com/uploads/Random.stuff/boot2.vdi
marmmm's version - http://djmati11.com/uploads/Random.stuff/boot3.vdi

How to use it?
viewtopic.php?f=39&t=24565 - on real machine
viewtopic.php?f=39&t=24552 - on VirtualBox virtual machine

Thanks for Martin's advices.

Now, you should search what is 0x10 interrupt, I will answer:
0x10 is BIOS interrupts - graphical functions.
Code:
MOV AH, 0x00 ; change video mode

AH is registry for function id.

Parameters and list of function ids and BIOS interrupts here: http://en.wikipedia.org/wiki/BIOS_interrupt_call
The best (but old) interrupt list is RBIL: http://ctyme.com/rbrown.htm

_________________
Nothing.


Last edited by djmati11 on Thu May 17, 2012 5:16 pm, edited 6 times in total.

Top  Profile
 PostPost subject: Re: [Tut] Making your own bootloader        Posted: Mon Apr 23, 2012 5:43 pm 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Thu Dec 22, 2011 2:51 pm

Posts
72

Favourite OS
NeXTStep/OpenStep
Hi,

great tutorial. You can optimize loops by using the LOOP instruction. Especially in the Functions DrawOneLine and
DrawTenLines. Don't forget to save CX when using in another function.

You should explain first two lines in more detail: BITS and ORG. They are essential for a working solution.
Also try to explain the various interrupt functions in more detail !

Would you please provide the whole source as a downloadable file ?
Would you please assemble the file as binary dump, so that members can try it on a real machine or in emulation ?

Maybe you can provide another example which actually reads sectors from disk and chainload to another partition's
bootloader !

Always like Assembler Tutorial, makes the whole forum more interesting for me !
Hope that other tutorials in Assembler follow !

I'm sure that there are people at BetaArchive which like to learn Assembler, you should try to make it as clear and
simple as possible.

Hope that helps and with regards,
Martin

_________________
Collector of old Windows SDKs (or generally of rare SDKs). My collection could be accessed here.


Top  Profile
 PostPost subject: Re: [Tut] Making your own bootloader        Posted: Mon Apr 23, 2012 6:19 pm 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Thu Apr 19, 2012 7:18 am

Posts
88

Location
The Democratic People's Republic of Korea

Favourite OS
ArchLinux GNU/Linux distro
Thank you for advices ;)

_________________
Nothing.


Top  Profile
 PostPost subject: Re: [Tut] Making your own bootloader        Posted: Mon Apr 23, 2012 7:04 pm 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Thu Dec 22, 2011 2:51 pm

Posts
72

Favourite OS
NeXTStep/OpenStep
you got a PM !

_________________
Collector of old Windows SDKs (or generally of rare SDKs). My collection could be accessed here.


Top  Profile
 PostPost subject: Re: [Tut] Making your own bootloader        Posted: Tue Apr 24, 2012 2:00 pm 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Thu Apr 19, 2012 7:18 am

Posts
88

Location
The Democratic People's Republic of Korea

Favourite OS
ArchLinux GNU/Linux distro
I've added marmmm fixed version of my example. Thank you! (I've added it before, but I'm posting this so everyone can see).

Edition fixed by marmmm:
ASM code file - http://djmati11.com/uploads/boot3.asm
ASM mirror: http://marm.homepage.t-online.de/files/boot2.asm
BIN compiled file (ready to use) - http://djmati11.com/uploads/boot3.bin

_________________
Nothing.


Top  Profile
 PostPost subject: Re: [Tut] Making your own bootloader        Posted: Wed Apr 25, 2012 6:13 pm 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Thu Dec 22, 2011 2:51 pm

Posts
72

Favourite OS
NeXTStep/OpenStep
fixed doesn't mean that djmati11's version doesn't work, my version is just a little bit optimized variant of the original.
From the functionality point of view, its exactly the same !

_________________
Collector of old Windows SDKs (or generally of rare SDKs). My collection could be accessed here.


Top  Profile
 PostPost subject: Re: [Tut] Making your own bootloader        Posted: Thu Apr 26, 2012 7:46 am 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Thu Apr 19, 2012 7:18 am

Posts
88

Location
The Democratic People's Republic of Korea

Favourite OS
ArchLinux GNU/Linux distro
Ready to use bootdisks for VirtualBox (*.vdi):
djmati11's version - http://djmati11.com/uploads/boot2.vdi
marmmm's version - http://djmati11.com/uploads/boot3.vdi

_________________
Nothing.


Top  Profile
 PostPost subject: Re: [Tut] Making your own bootloader        Posted: Tue Jul 17, 2012 5:41 am 
Newbie Beta Collector
Newbie Beta Collector
Offline

Joined
Tue Jul 17, 2012 4:47 am

Posts
36

Favourite OS
Windows NT 3.1
I have a laptop which can access a CD-ROM via a parallel port only after installing DOS drivers. Is there any way to use something like this to boot from the CD after DOS has loaded?


Top  Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 




Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

All views expressed in these forums are those of the author and do not necessarily represent the views of the BetaArchive site owner.

Powered by phpBB® Forum Software © phpBB Group

Copyright © 2006-2013

 

Sitemap | XML | RSS