Thanks for your time reading my post
I have always wanted to make an OS, no matter how simple. I stubled upon this site yesterday which made me very happy! I looked around and found the bare bones tutorials which I found very helpful.
I am having a problem with the C tutorial though.
My dev environment is Windows 7 x64. I'm using nasm and gcc.
I am getting a common error it seems when using Bochs - Error: 13 Invalid or unsupported executable format
I have searched this forum for the solution and get confused about the answer. They seem to suggest using COFF for NASM and insering AOUT kludge into my loader. I have googled AOUT kludge and can't seem to see anything I can understand about it.
Here is the relavent code and batch files i'm using. Attached are screen shots of Bochs:
build.bat
(I made pad.txt using C++ writing 750 bytes to a file)
Code: Select all
"C:\Program Files (x86)\nasm\nasm" -f elf -o loader.o loader.s
C:\MinGW\bin\gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
C:\MinGW\bin\ld -T linker.ld -o kernel.bin loader.o kernel.o
del floppy.img
copy /b stage1 + stage2 + pad.txt + kernel.bin floppy.img
Code: Select all
boot: floppy
floppya: 1_44="floppy.img", status=inserted
Code: Select all
global loader ; making entry point visible to linker
extern _kmain ; kmain 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 _kmain ; call kernel proper
cli
hang:
hlt ; halt machine should kernel return
jmp hang
section .bss
align 4
stack:
resb STACKSIZE ; reserve 16k stack on a doubleword boundary
Code: Select all
void kmain( void* mbd, unsigned int magic )
{
if ( magic != 0x2BADB002 )
{
/* Something went not according to specs. Print an error */
/* message and halt, but do *not* rely on the multiboot */
/* data structure. */
}
/* You could either use multiboot.h */
/* (http://www.gnu.org/software/grub/manual/multiboot/multiboot.html#multiboot_002eh) */
/* or do your offsets yourself. The following is merely an example. */
char * boot_loader_name =(char*) ((long*)mbd)[16];
/* Print a letter to screen to see everything is working: */
unsigned char *videoram = (unsigned char *) 0xb8000;
videoram[0] = 65; /* character 'A' */
videoram[1] = 0x07; /* forground, background color. */
/* Write your kernel here. */
}
Code: Select all
ENTRY (loader)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}