EddyDean
Visitor
|
Compilation, linking and using grub - 2007/06/21 15:20
Hello everyone,
First of all I'd like to introduce myself. Hello, I'm EddyDean (well, not really...), 15 years old, living in the Netherlands. I started programming when I was 11, in QBasic. Later I switched to several other languages including C, C++, Perl, PHP, ASM, Java and Visual Basic. A few days ago I decided that it was a great, if not brilliant plan to start creating my own OS. I have a few great plans in my mind, but I know I might never finish it.
I have one problem though: I don't have a floppy drive, and I can't seem to be able to tell grub to load my kernel. The "kernel" I'm using is a copy-paste of one of the tutorials I read (don't worry, I understand the code). It's one part ASM:
loader.s:
| Code: |
global _loader ; making entry point visible to linker
extern _main ; _main is defined elsewhere
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
section .text
align 4
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
; reserve initial kernel stack space
STACKSIZE equ 0x4000 ; that's 16k.
_loader:
mov esp, stack+STACKSIZE ; set up the stack
push eax ; pass Multiboot magic number
push ebx ; pass Multiboot info structure
call _main ; call kernel proper
hlt ; halt machine should kernel return
section .bss
align 32
stack:
resb STACKSIZE ; reserve 16k stack on a quadword boundary
|
And one part C (umm... Yeah...)
kernel.c
| Code: |
void _main( void* mbd, unsigned int magic )
{
// write your kernel here
}
|
And there is a linker script:
linker.ld:
| Code: |
ENTRY (_loader)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
|
I compile the ASM code with nasm (to ELF)
The C code withy gcc (with loads of parameters to not include any default libraries)
The I link the while thing together using ld.
Now I have a file named booter (o yeah)
dd if=/dev/zero of=floppy.disk bs=18k count=80
cat stage1 stage2 booter >files
dd if=files of=floppy.disk conv=notrunc
Then I boot floppy.disk in Bochs, it shows me a nice grub prompt, and then... Nothing. I can't do root (fd0) and then kernel /booter because it can't find the file
find * shows nothing. Where did my kernel go?
As I said before: I do not have a floppy drive. I do have a CD-ROM drive that can use rewriteable CDs. I would actually prefer creating a partition (fat12/16/32 will do as a filesystem, I don't need anything fancy), where I can just copy the kernel and grub to and boot from it. How hard is this to do, and how do I find more information about it?
I am using a fully updated FreeBSD 6.1-RELEASE system.
Thanks in advance,
EddyDean
|