user5100101
user5100101

Reputation:

It is possible to call kernel with this ASM bootloader? How?

I made a little bootloader. Now I want to load the C++ kernel. Can I use my little bootloader for this?

   [BITS 16]
   [ORG 0x7C00]
   [extern _start_kernel]

   MOV SI, LoadString
   CALL String
   CALL _start_kernel




   JMP $ 

   Print:
   MOV AH, 0x0E
   MOV BH, 0x00
   MOV BL, 0x07


   INT 0x10
   RET

   String:
   characters:
   MOV AL, [SI]
   INC SI
   OR AL, AL
   JZ stopPrint
   CALL Print
   JMP characters
   stopPrint
   RET


   LoadString db 'Loading...', 0


   TIMES 510 - ($ - $$) db 0
   DW 0xAA55

This is very simple bootloader and this is first time when i make bootloader(with tutorial). I use NASM in windows to compile asm code.

Upvotes: 1

Views: 483

Answers (2)

Razor
Razor

Reputation: 1794

If you would like to call an external function inside your kernel, you need to first have it declared in your kernel file and then call it from your bootloader. You will also need a linker file that links the kernel to the bootloader all into a seperate binary file that can then be booted using GRUB. Visit this site which shows you how to make your bootloader start executing from the kernel and then linking it using a linker file. You may need to have GCC cross-compiler if you have linux and if you are planning to use the code on that site.

Upvotes: 0

Fifoernik
Fifoernik

Reputation: 9899

Now i want to load c++ kernel. Can i use my little asm bootloader for this?

Not with the code that you've written because in a bootloader it is your responsability to actually bring the kernel file into memory. Just declaring an external label [extern _start_kernel] won't do any good.
Search the forum and you will find examples that manage this.

A note on your efforts so far.
Because you wrote [ORG 0x7C00] you want your addresses to be relative to linear address 0. Here also it is your responsability to make sure that the segment registers are setup accordingly. You need to add to your code:

xor ax, ax
mov ds, ax
MOV SI, LoadString

Upvotes: 2

Related Questions