Here are two files: mboot.inc and mbtest.asm.
=-=-=-=-=-= mboot.inc -=-=-=-=-=
; (C) 2003 ybx aka Juras Benesz, http://ybx.narod.ru
; -=- Multiboot structures -=-
; Use absolute freely but at your own risk!
; I'm not responsible for anything.
struc multiboot_info
{
.flags dd ?
.mem_lower dd ?
.mem_upper dd ?
.boot_device rb 4
.cmdline dd ?
.mods_count dd ?
.mods_addr dd ?
;-- ELF specific info:
.num dd ?
.size_ dd ?
.addr_ dd ?
.shndx dd ?
;----
.mmap_length dd ?
.mmap_addr dd ?
.size=$-.flags
}
struct multiboot_info
struc mod_list
{
.mod_start dd ?
.mod_end dd ? ; (mod_end-mod_start)=len
.string dd ?
.reserved_ dd ?
}
struct mod_list
struc addr_range
{
.size_ dd ?
.BaseAddrLow dd ?
.BaseAddrHigh dd ?
.LengthLow dd ?
.LengthHigh dd ?
.Type_ dd ? ; =1 if useable
}
struct addr_range
-=-=-=-=-=-=-=-=-=- end of mboot.inc -=-=-=-=-
-=-=-=-=-=-=-=-==-=- mbtest.asm -=-=-=-=-=-=-=-
; (c) 2003 ybx aka Juras Benesz, http://ybx.narod.ru
; -=- Simple Multiboot test -=- Primitive OS Kernel
; Use absolute freely but at your own risk!
; I'm not responsible for anything.
format binary
org 0x220000 ; the best place to load our kernel to.
use32 ; the kernel will be run in 32-bit protected mode,
; that is a cool standard called Multiboot.
; see http://www.nilo.org/multiboot.html
; Use GRUB to run our kernel.
; Or use X.exe from www.sf.net/projects/oslib
; for real-mode DOS (like FreeDOS) to run our kernel as well.
; --- Tomasz's useful macro:
macro struct name
{ virtual at 0
name name
sizeof.#name = $ - name
name equ sizeof.#name
end virtual }
; -- some my definitions of multiboot structures for you
include 'mboot.inc'
; _start doesn't mean a program entry. it's simply the start
; of the kernel image. This label is used in the Multiboot header.
; The entry point is defined in the header below.
_start:
; multiboot header
MBFLAGS=0x03 or (1 shl 16) ; 4KB aligned modules etc., full memory info,
; use special header (see below)
dd 0x1BADB002 ; multiboot signature
dd MBFLAGS ; 4kb page aligment for modules, supply memory info
dd -0x1BADB002-MBFLAGS ; checksum=-(FLAGS+0x1BADB002)
; other data - that is the additional (optional) header which helps to load
; the kernel.
dd _start ; header_addr
dd _start ; load_addr
dd _end_data ; load_end_addr
dd _end ; bss_end_addr
dd Kernel_Start ; entry
; end of header
Kernel_Start:
; MultiBoot-compliant loader (e.g. GRUB or X.exe) provides info in registers:
; EBX=multiboot_info
; EAX=0x2BADB002 - check if it's really Multiboot loader
;- copy mb info - some stuff for you
mov esi,ebx
mov edi,mb_info
cld
mov ecx,sizeof.multiboot_info
rep movsb
;- now mb info is saved, but needs a deeper processing:
;- memory map, modules etc.
;- i won't do it for you.
; here we should prepare the environment to be more safe
mov esp,Kernel_Stack
; - here is the best place to setup GDT, IDT...
; but i won't do it
mov edi,0xB8000
mov esi,hello_str
mov ecx,hello_str_len
cld
@@:
lodsb
stosb
inc edi
loop @r
hlt ; interrupts are disabled so we can HANG here
; -- data
hello_str db 'Hello world!'
hello_str_len=$-hello_str
_end_data: ; -- end of CODE+DATA
;--- bss --- place r*, d* ? directives here, so that you'll have a BSS.
mb_info multiboot_info ; just a dummy
rb 32768 ; our own stack
Kernel_Stack:
_end: ; end of BSS - here's the virtual and logical end.
-=-=-=-=- end of mbtest.asm -=-=-=-=-=-=-