Earlier when I came here I had only a minimal set of utilities and a WinXP comp.. Now i'm here and serious, with kubuntu (and Internet!!!!) and willing to learn all of that dd, mov, eax, and bochs stuff. Here is my delemia: I have a C++ Program, have no idea how to make a simple bootloader for it.
From other questions it boiled down to these:
Initialize the FAT filesystem
Start the program.
I need to know what dd and asm commands to use in terminal too as I have had a bad history with bochs and dd (all on windows).
I also lost that verbatim bootloader as I got a new computer because my old hard drive died...
I have the standard GNU Bitutils, if I need to ill figure out how to instll NASM/MASM oh whatever it is.
If there is a way to take some of GCC (C/C++ Compiler not Collection) asm output and use it with this that would be nice.
Thanks In Advance For Your Help.

Recommended Answers

i use pure assembly, ur willing to run with that?

Jump to Post

All 4 Replies

i use pure assembly, ur willing to run with that?

Interfacing with C would probably make the boot-loader bloated, I have read on basic boot loaders but generally give ether info on 'How To Use GRUB For Your OS' or it is all cryptic, not like normal assembly cryptic but like 'I Expect You Are A Computer Scientist From The 80's When Some People Understood Machine Language' cryptic.
I Have NASM installed, now, and cant wait. I don't like OOP ether so that shouldn't get in the way to much; my main problems isn't concepts ether; its acctualy figuring out how to do them.
For Example: The Stack It Where You Put Stuff Used As Arguments or To Use An Untouchable Register for memory.
Sorry For Me Going Everwhere but i install quem (qume?) and like it more than bochs if that makes a difference.

I use NASM to compile pure assembly on Linux.

The program with pure assembly works with some things that looks like the PE Struct, as the definitions must be stored at the .data section, if is a variable, use .data?
the code starts at .code, i like to put an inline function named "start", but thats not necessary.

About the BootLoader,
i made a topic about that some years ago but it was in portuguese(im brazilian), if you want the link please PM me
The computers, when you turn them on, it automatically checks the first 512 bytes of the HD to see if it has an OS, if it finds an OS, it loads the this 512 bytes into the address 0000:7C00(HEX)(PS: YES, thats an relative address), another thing you should know, is that you'll always have to control the interrupts of the computer from you BIOS, you should check this website to know the interrupts list:
Interrupts List

If your OS has more than 512 bytes, the space that the hardware allocated for you wont me enough, so you'll need to have a loader, heres an example:

org 7C00h                       ;organize the offset
;inicialização da pilha  
mov     ax, 07C0h                 
mov     ss, ax                  ;sets SS to 07C0
mov     sp, 03FEh               ;sets to the top of the stack
;seta segmento de dados  
xor     ax, ax                  
mov     ds, ax                  ;sets the data segment to 0 
;altera o modo de vídeo  
mov     ah, 00h                 ;subfunction to video
mov     al, 03h                 ;03h = 80x25, 16 colors
int     10h                     ;video interrupt
;le dados do disquete  
mov     ah, 02h                 ;read subfunction
mov     al, 1                   ;number of sections to read
mov     ch, 0                   ;cylinder
mov     cl, 2                   ;sector 
mov     dh, 0                   ;head
mov     dl, 0                   ;drive ( 00h = A: ) 
mov     bx, 0800h               ;ES:BX selects the memory location
mov     es, bx                  ;where the data will be written
mov     bx, 0                   ;0800:0000h ( ES = 0800h, BX = 0000h ) 
jmp     0800h:0000h             ;jump to the kernel location

After that you will need to build up a kernel, heres an example:

org 0000h                       
push cs                       
pop ds                          ;DS = CS  
call clearscreen                   
lea si, Mensagem                      
mov ah, 0Eh                     
    mov al, [si]                ;move para AL o caractere em SI  
    cmp al, 0h                 
    jz terminou                
    int 10h                     ;video interrupt 
    inc si                                           
    jmp repetição               ;repeat the loop untill finds 0
mov ah, 0h                      ;wait for an ASync state 
int 16h                         ;keyboard interrupt
mov ax, 0040h                   ;reboot method                   
mov ds, ax                      ;the value of 0040:0072h_                            
mov w.[0072h], 1234h            
jmp 0FFFFh:0000h                ;FFFF:0000h 
clearscreen proc                
    mov     ah, 06h              
    mov     al, 0               ;cleans the screen 
    mov     bh, 0000_1111b      ;sets the collors 
    mov     ch, 0              
    mov     cl, 0               
mov     dh, 19h            
    mov     dl, 50h             
    int     10h                 ;video interrupt
    popa                        ;reput the values
    ret                         ;returns the code
clearscreen endp

After the kernel then what? How would I start my program? How would I put this in an IMg file?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.