I have tested your code, with the changed linker script and the changed start.asm! I tried to load it with GRUB and got a message like "unsupported executable"...
After this I changed the linker script again and set the OUTPUT_FORMAT to "elf32-i386" instead of "binary" and it works:
Code: Select all
/*OUTPUT_ARCH ( "i386" )
OUTPUT_FORMAT("binary")*/
OUTPUT_FORMAT(elf32-i386)
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
/*Set the virtual address:*/
. = phys;
/*
* http://wiki.osdev.org/Grub_Error_13
*/
/* .__mbHeader will begin @ 'phys' */
.__mbHeader : AT ( ADDR( .__mbHeader ) ) {
/* mboot = .;*/
*(.__mbHeader)
}
.text ALIGN(4096) : AT(ADDR(.text)) {
code = .;
*(.text)
*(.rodata)
}
.data ALIGN(4096) : AT(ADDR(.data)) /*Voila*/
{
data = .;
*(.data)
}
.bss ALIGN(4096) : AT ( ADDR (.bss) )
{
bss = .;
*(.bss)
}
end = .;
}
start.asm
Code: Select all
; This is the kernel's entry point. We could either call main here,
; or we can use this to setup the stack or other nice stuff, like
; perhaps setting up the GDT and segments. Please note that interrupts
; are disabled at this point: More on interrupts later!
[BITS 32]
SECTION .__mbHeader
; 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)
EXTERN code, bss, end
; 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
dd code
dd bss
dd end
dd start
SECTION .data
;;this is our GDT entry
gdt_ptr_struct:
dw gdt_end - gdt - 1 ; size of the GDT
dd gdt ; linear address of GDT
;dw 0x0;the gdt structure must be 8 bytes aligned?
ALIGN 4
gdt:
;we set five gdt entries.Why 5? well, we have a code and data segment descriptor for the kernel, code and data segment descriptors for user mode, and a null entry. This must be present, or bad things will happen.
dd 0, 0 ; null gate
db 0xFF, 0xFF, 0, 0, 0, 0x9A, 0xCF, 0x00 ; code selector 0x08: base 0x00000000, limit 0xFFFFFFFF, type 0x9A, granularity 0xCF
db 0xFF, 0xFF, 0, 0, 0, 0x92, 0xCF, 0x00 ; data selector 0x10: base 0x00000000, limit 0xFFFFFFFF, type 0x92, granularity 0xCF
db 0xFF, 0xFF, 0, 0, 0, 0x92, 0xCF, 0x00 ; user mode code selector 0x18: base 0x00000000, limit 0xFFFFFFFF, type 0xFA, granularity 0xCF
db 0xFF, 0xFF, 0, 0, 0, 0x92, 0xCF, 0x00 ; user mode data selector 0x20: base 0x00000000, limit 0xFFFFFFFF, type 0xF2, granularity 0xCF
gdt_end:
section .text
global start
extern main
;...
Hope it helps...
Cheers Christian
PS:
You have to use "aout" when you use flat binaries. So you could build your kernel as elf by changing your linker script or as flat binary but then you have to correct the file called compile.sh:
Code: Select all
#...
nasm -f aout -o start.o start.asm
#...