start.asm:bunkdeath wrote:Hi to all those are helping someone like me,
I am new to this forum, and sorry, if this question is already there in forum. I tried to search for this question, but there was many such words so I got nothing.
I have a boot strap loader, and a simple kernel.
From tutorial i got that, kernel can be loaded in 3 different ways.
i) Put kernel in bootstrap loader.( But my kernel is bigger than 512 b)
ii) Specify the kernel file and load.
iii) Run form specified location.
The first one is not suitable for me as well as while coding OS.
If any one could give me any idea(with code) in any of two method(ii, ii) to load kernel file?
And I think platform does not matter while coding for OS(I think), but also, I am using x86 architecture Windows 7 OS
Thanks
Code: Select all
extern k_main
global _loader
_loader:
call k_main
cli
hlt
Code: Select all
k_main(){
char *vidmem = (char *)0xb8000;//VIDMEM pointer
int i = 0;
while(1){
vidmem[i*2] = "H";//Print H on screen
vidmem[i+1] = 0x07;//Set H color to WHITE
i++;
}
};
Use this makefile if you have troubles:
Code: Select all
all:
@nasm -f aout ./src/start.asm -o ./src/start.o
@gcc -c ./src/main.c -o ./src/main.o -fno-builtin -fno-stack-protector
ld -T link.ld -o kernel.bin ./src/start.o ./src/main.o
start.asm:
Code: Select all
global _loader ; making entry point visible to linker
extern k_main ; KernelMain
; 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
cli
mov eax, cr0
or al, 1
mov cr0, eax
push eax ; pass Multiboot magic number
push ebx ; pass Multiboot info structure
; Immediately after that you have to jump to the code segment in the GDT:
JMP 08h:k_main
hlt ; halt machine should kernel return
link.ld:
Code: Select all
ENTRY (_loader)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
grub.img: http://www.megaupload.com/?d=5J3ZFSR0