Multiboot For Flat Exe
- os.hacker64
- Member
- Posts: 149
- Joined: Mon Feb 11, 2008 4:43 pm
- Location: Limbo City,Afterlife
Multiboot For Flat Exe
This is probably the most noobish question on the planet, but how might I set up the multiboot header for a flat binary file to be loaded by grub? Some of the address fields confuse me a bit. Are there any examples out there?
- os.hacker64
- Member
- Posts: 149
- Joined: Mon Feb 11, 2008 4:43 pm
- Location: Limbo City,Afterlife
Here is a sample 32-bit kernel to boot with GRUB.
It loads at the first physical Megabyte. If you want to change it you will have to adjust ORG and every 1048576 occurrence.
The stack is placed at the start of the second physical Megabyte.
It will just boot immediately, the kernel will just write a purple character at the top of the 80x25 text screen and will halt.
Attached there is the floppy image and the source code to this sample kernel, useful if you want to make your own flat binary kernel. Note that it's a floppy image and you should copy it with rawwrite, dd, cat, etc.
It loads at the first physical Megabyte. If you want to change it you will have to adjust ORG and every 1048576 occurrence.
The stack is placed at the start of the second physical Megabyte.
It will just boot immediately, the kernel will just write a purple character at the top of the 80x25 text screen and will halt.
Attached there is the floppy image and the source code to this sample kernel, useful if you want to make your own flat binary kernel. Note that it's a floppy image and you should copy it with rawwrite, dd, cat, etc.
Code: Select all
bits 32
org 1048576
kernelstart:
mov esp,1048576*2 ; This points the stack to our new stack area
jmp stublet
; This part MUST be 4byte aligned, so we solve that issue using 'ALIGN 4'
ALIGN 4
mboot:
; Multiboot macros to make a few lines later more readable
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
; This is the GRUB Multiboot header. A boot signature
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
; AOUT kludge - must be physical addresses. Make a note of these:
; The linker script fills in the data for these ones!
dd mboot ;GRUB Multiboot Header
dd 1048576 ;Kernel Base Address
dd 1048576+kernelsize ;Kernel End Address
dd 1048576+kernelsize ;BSS End Address (can be same as Kernel End Address)
dd stublet ;Kernel Entry Point
; This is an endless loop here. Make a note of this: Later on, we
; will insert an 'extern _main', followed by 'call _main', right
; before the 'jmp $'.
stublet:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cli
mov word[0xB8001],"X "
hlt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
kernelsize equ $-kernelstart
- Attachments
-
- grub_flat_image.zip
- (43.81 KiB) Downloaded 13 times
- os.hacker64
- Member
- Posts: 149
- Joined: Mon Feb 11, 2008 4:43 pm
- Location: Limbo City,Afterlife
I tried changing that code so that it would work in FASM. Here it is:
- Attachments
-
- kernel.asm
- Here's what I have in FASM
- (487 Bytes) Downloaded 57 times