My Problem:
----------
I have these files
Kernel.c
--------
void print(char *text)
{
char *vidmem = (char *)0xB8000;
while(*text != 0)
{
*vidmem = *text;
vidmem++;
*vidmem = 0x07;
vidmem++;
text++;
}
}
void Dmain()
{
print("Hello World !!!");
}
Start.asm
---------
extern _Dmain
global _main
[SEGMENT .text]
[BITS 32]
_main:
call _Dmain
mov ax,0x0
ret
hlt
link.ld
-------
SECTIONS
{
.text 0x00100000 :
{
*(.text)
}
}
---------------------
Now I created coff files from these files and they are kernel.o and start.o.
And then I linked them using ld using the following command
ld -T link.ld kernel.o start.o --oformat binary -o kernel.bin
Now when I try to load my kernel I get a triple fault exception (definitely not what I expected).
I don't know what's the problem - something tells me that the problem is in my linker script.
Can someone tell me how to get 16-bit output from gcc( I tried the asm(".code16gcc") - didn't work)
Please help me.
cheers
ksk
Help me boot my kernel
RE:Help me boot my kernel
Hi,
1)
- call _Dmain
- mov ax,0x0
- ret // this may not be needed, it may coz reboot if u r in pmode
- hlt
2) if u r losding the kernel after setting up the pmode, then u have to use the seg selector to write 2 the video memory, u shouldn't write like this.
it doesn't matter if u r producing 16 or 32 bit code, better write ur own bootloader.
rgds,
YogaRamanan.T
1)
- call _Dmain
- mov ax,0x0
- ret // this may not be needed, it may coz reboot if u r in pmode
- hlt
2) if u r losding the kernel after setting up the pmode, then u have to use the seg selector to write 2 the video memory, u shouldn't write like this.
it doesn't matter if u r producing 16 or 32 bit code, better write ur own bootloader.
rgds,
YogaRamanan.T
RE:Help me boot my kernel
I dont think you should have the
mov ax,0
ret
instead use
cli
hlt
and try using GRUB to boot the file
mov ax,0
ret
instead use
cli
hlt
and try using GRUB to boot the file
Only Human
RE:Help me boot my kernel
After actually reading your code just put ENTRY(_main) in your linker script.
Also in your link.ld you should have this OUTPUT_FORMAT("binary")
so link.ld should look like this
OUTPUT_FORMAT("binary")
ENTRY(_main)
SECTIONS
{
.text 0x00100000 :
{
*(.text)
}
}
also your linking it wrong:
ld -T link.ld start.o kernel.o --oformat binary -o kernel.bin
that is the right way.
or if you want it all in one file you could do this
void Dmain(void)
{
print("Hello, World\n");
asm(
"mov %ax,$0 \n"
"cli \n"
"hlt");
}
and in link.ld
ENTRY(_Dmain)
and you wouldnt need start.asm
I did it in my kernel and it works fine
Althought its just a suggestion.
Good Luck
--KERNEL PANIC--
SystemHalted
Also in your link.ld you should have this OUTPUT_FORMAT("binary")
so link.ld should look like this
OUTPUT_FORMAT("binary")
ENTRY(_main)
SECTIONS
{
.text 0x00100000 :
{
*(.text)
}
}
also your linking it wrong:
ld -T link.ld start.o kernel.o --oformat binary -o kernel.bin
that is the right way.
or if you want it all in one file you could do this
void Dmain(void)
{
print("Hello, World\n");
asm(
"mov %ax,$0 \n"
"cli \n"
"hlt");
}
and in link.ld
ENTRY(_Dmain)
and you wouldnt need start.asm
I did it in my kernel and it works fine
Althought its just a suggestion.
Good Luck
--KERNEL PANIC--
SystemHalted