Bootloader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Bootloader

Post by seingh »

Hello everyone, I'm new in this forum and in the development of operating systems ^ ^ (XD)
I wanted to ask how to create a custom bootloader ... or better to say how to recognize it from qemu xD.
In short, the boot loader code is this:
Boot.asm:

Code: Select all

global loader
[BITS 32]
extern _kmain
section .text
   LEA SI,[msg]

   MOV AH,0Eh
print:  MOV AL,[SI]         
   CMP AL,0         
   JZ done      
   INT 10h      
        INC SI         
   JMP print

; wait for 'any key':
done:   ;MOV AH,0       
       ;INT 16h     
call _kmain

   MOV  AX,0040h
   MOV  DS,AX
   MOV  word[0072h],0000h.
   JMP  0FFFFh:0000h   

msg    DB  'Benvenuto in patronum OS.',13,10
; end boot1
qemu in windows but does not recognize it ... in ubuntu I need to use "qemu-kernel kernel.bin" instead in windows if I type the same command (with qemu installed) nothing happens ...

Sorry for my **** English, I'm Italian ^ ^
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Re: Bootloader

Post by seingh »

berkus wrote:You seem to lack the boot loader signature at the end.
I did not understand what you are saying, please write in another way, I'm sorry.
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Re: Bootloader

Post by seingh »

berkus wrote:I assume you have read the Bootloader wiki article, so you know about the BIOS boot signature. There's even an example how to define one.
oh, i haven't read it....

EDIT: After reading the article, I see that do not there is a big difference between that article and "my" ( excepted that the code in the article is in 16 bit and my is in 32 bit, there is also the difference that he does not call any C code, which I will be obliged to do (because I do not know very well asm) )
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: Bootloader

Post by b.zaar »

seingh wrote:
berkus wrote:I assume you have read the Bootloader wiki article, so you know about the BIOS boot signature. There's even an example how to define one.
oh, i haven't read it....

EDIT: After reading the article, I see that do not there is a big difference between that article and "my" ( excepted that the code in the article is in 16 bit and my is in 32 bit, there is also the difference that he does not call any C code, which I will be obliged to do (because I do not know very well asm) )
You can't use 32 bit code in a boot sector, the cpu is running in 16 bit mode until you enter protected mode.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Re: Bootloader

Post by seingh »

b.zaar wrote:
seingh wrote:
berkus wrote:I assume you have read the Bootloader wiki article, so you know about the BIOS boot signature. There's even an example how to define one.
oh, i haven't read it....

EDIT: After reading the article, I see that do not there is a big difference between that article and "my" ( excepted that the code in the article is in 16 bit and my is in 32 bit, there is also the difference that he does not call any C code, which I will be obliged to do (because I do not know very well asm) )
You can't use 32 bit code in a boot sector, the cpu is running in 16 bit mode until you enter protected mode.
I solved it this way:

Code: Select all

global loader 
extern kmain
MODULEALIGN equ  1<<0           
MEMINFO     equ  1<<1        
FLAGS       equ  MODULEALIGN | MEMINFO  
MAGIC       equ    0x1BADB002          
CHECKSUM    equ -(MAGIC + FLAGS)    
 
section .text
align 4
MultiBootHeader:
   dd MAGIC
   dd FLAGS
   dd CHECKSUM

STACKSIZE equ 0x4000             
 
loader:
   mov esp, stack+STACKSIZE       
   push eax                        
   push ebx                       
 
   call  kmain                   
 
   cli
hang:
   hlt                            
   jmp   hang
 
section .bss
align 4
stack:
   resb STACKSIZE                 
thank you anyway ^ ^
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Bootloader

Post by Gigasoft »

That isn't a bootloader. It is the entry point and multiboot header for a multiboot executable.
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Re: Bootloader

Post by seingh »

Gigasoft wrote:That isn't a bootloader. It is the entry point and multiboot header for a multiboot executable.
What? I tried this code in QEMU with the string "qemu -kernel kernel.bin" (after compiling a "kernel.bin" file ) and it works...
It do what I want: it calls a C function from Assembler in the computer boot. And with this I think it's a bootloader.
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: Bootloader

Post by shikhin »

/me shakes his head - this is what happens to people who just aimlessly copy code from some website, without even understanding what it does. :roll:
http://shikhin.in/

Current status: Gandr.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Bootloader

Post by Chandra »

What? I tried this code in QEMU with the string "qemu -kernel kernel.bin" (after compiling a "kernel.bin" file ) and it works...
It do what I want: it calls a C function from Assembler in the computer boot. And with this I think it's a bootloader.
Do you have any idea what -kernel option does? It's a good practice to examine the water level before diving into this huge sea. Do care to search before complaining.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Re: Bootloader

Post by seingh »

Shikhin wrote:/me shakes his head - this is what happens to people who just aimlessly copy code from some website, without even understanding what it does. :roll:
I already said that I do not know well the assembly, or rather not know anything about assembler.
It is true that I copied that code from a site ... but this does not mean anything.

Chandra wrote:
What? I tried this code in QEMU with the string "qemu -kernel kernel.bin" (after compiling a "kernel.bin" file ) and it works...
It do what I want: it calls a C function from Assembler in the computer boot. And with this I think it's a bootloader.
Do you have any idea what -kernel option does? It's a good practice to examine the water level before diving into this huge sea. Do care to search before complaining.
Yes, it is obvious that I know what are the functions that I say.
It's needless to say ****.

berkus wrote:This isn't a bootloader, it's just a multiboot entry point which can be loaded by multiboot-compatible bootloader.
Sorry, but it works without another bootloader ( such as grub ).
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Bootloader

Post by neon »

I wanted to ask how to create a custom bootloader
You asked about creating a bootloader. This isnt a bootloader, stop calling it one.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Re: Bootloader

Post by seingh »

neon wrote:
I wanted to ask how to create a custom bootloader
You asked about creating a bootloader. This isnt a bootloader, stop calling it one.
ok XD
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Re: Bootloader

Post by seingh »

berkus wrote:
seingh wrote:Sorry, but it works without another bootloader ( such as grub ).
Well, you're wrong here. Try to boot it on a real hardware, then we'll talk.

Or you can try booting it in bochs. All the same.
I tried it on my pc and it do not work...
That means that I must use grub -.-
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: Bootloader

Post by shikhin »

Accepting that you are wrong is the first step to start learning. And stating that everyone except you is wrong is the first step to damage your reputation.

I warned you. 8)
http://shikhin.in/

Current status: Gandr.
seingh
Posts: 11
Joined: Wed Apr 27, 2011 10:02 am

Re: Bootloader

Post by seingh »

Shikhin wrote:Accepting that you are wrong is the first step to start learning. And stating that everyone except you is wrong is the first step to damage your reputation.

I warned you. 8)
OK, sorry
Post Reply