flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Sample Multiboot kernel (for GRUB, X.exe...)

Author
Thread Post new topic Reply to topic
Juras



Joined: 18 Jun 2003
Posts: 23
Location: Belarus
Juras 19 Jul 2003, 12:49
Here are two files: mboot.inc and mbtest.asm.

=-=-=-=-=-= mboot.inc -=-=-=-=-=
Code:
; (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 -=-=-=-=-=-=-=-
Code:
; (c) 2003 ybx aka Juras Benesz, http://ybx.narod.ru
; -=- Simple Multiboot test -=- Primitive OS Kernel Wink
; 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 Wink

                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 Wink

                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 Wink
                
; -- 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 Wink


rb 32768        ; our own stack
Kernel_Stack:


_end:   ; end of BSS - here's the virtual and logical end.    
-=-=-=-=- end of mbtest.asm -=-=-=-=-=-=-

_________________
Best Regards, Juras aka Exhu (aka YBX)
Post 19 Jul 2003, 12:49
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
CodeWorld



Joined: 15 Nov 2003
Posts: 69
CodeWorld 20 Nov 2003, 10:39
Russian language:

ëîë... ïðèâà.. òû òîæå òóò =))) òóò êàêèå òî âñå ñòðàííûå Wink êàêîéòî íå ðåàëüíî îáùèòåëüíûé ôîðóì - âñå ñàìè ñ ñîáîé áåñåäóþò Wink

_________________
Image
FASM & RUS OSDEV at WWW.SYSBIN.COM (EN: ww2.sysbin.com)
Post 20 Nov 2003, 10:39
View user's profile Send private message Visit poster's website Reply with quote
Juras



Joined: 18 Jun 2003
Posts: 23
Location: Belarus
Juras 15 Apr 2004, 16:15
2Codeworld: Hey! Hi!!!! Smile)))))
Post 15 Apr 2004, 16:15
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
compilax



Joined: 18 Feb 2004
Posts: 56
compilax 14 Aug 2004, 00:41
Thanks heaps Smile I couldnt seem to make a flat binary multiboot kernel that would actually boot before! maybe the multiboot header has to be at 0 like in this one?
Post 14 Aug 2004, 00:41
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 06 Oct 2004, 12:05
Very nice; I used this to learn enough about multiboot to make RetroForth/Native multiboot compliant!
Post 06 Oct 2004, 12:05
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.