Kernel using C
- nitinjavakid
- Member
- Posts: 65
- Joined: Sat Oct 21, 2006 11:28 am
- Location: Exams over!
- Contact:
Now I am a bit confused. I mean using pure nasm, the object files do not seem to produce any extra code except .text. I used objdump ks.o -D.Combuster wrote:Uh, the answer is a few posts back? Back where I told you what happens when no .data and .bss were present?nitinjavakid wrote:Also, plz tell me how .bss .data and .rodata would help?
Regards
Nitin
Nitin
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
If you read it thoroughly you'd have seen that those sections were required by C code. Since you still want to use that, its better to have them in place already.
Not that it matters at the moment.
For now, I suggest you use bochs' debugger to see wether your code is indeed linked at 0x9000 and if it's not do what most people do: build two separate binaries.
Not that it matters at the moment.
For now, I suggest you use bochs' debugger to see wether your code is indeed linked at 0x9000 and if it's not do what most people do: build two separate binaries.
When linking your code add this switch to ld . It will show you where your code is aligned to, and the different sections
--Michael
Code: Select all
-Map map.txt
--Michael
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
I can't help but notice the lack of the 'org' keyword anywhere...
Also,
Firstly, I have no idea why your kernel needs to be sector-aligned... Secondly, you should have a 'section .data' or something like that before all the declarations.
Hope this helps.
Also,
Code: Select all
gdt dd 0,0 ; entry 0 is always unused
code db 0xff, 0xff, 0, 0, 0, 10011010b, 11000000b, 0 ; code buffer
datastack db 0xff, 0xff, 0, 0, 0, 10010010b, 11001111b, 0 ; data buffer
gdt_end:
gdtinfo:
dw gdt_end - gdt - 1
dd gdt
check:
db 'q'
times 512-($-$$) db 0
Hope this helps.
- nitinjavakid
- Member
- Posts: 65
- Joined: Sat Oct 21, 2006 11:28 am
- Location: Exams over!
- Contact:
Well I had some rest and got a great idea.
Although very primitive, its well structures ![Very Happy :D](./images/smilies/icon_biggrin.gif)
files:
temp.asm - this loades the kernel in the second and the following sector, activates pmode and jumps to 08h:0x9000 where it has loaded the remaining kernel, quite simple i guess
kernel.c - this is the actual thing
, damn I cant stop smiling as i write this ![Smile :)](./images/smilies/icon_smile.gif)
link.ld
doit.sh
to the temp.asm I added only the old [org 0x7C00]. I mean it can be dont the over way as well by assigning ds and stuff.
Anyways, success atlast. Roma Victor!!!!
![Smile :)](./images/smilies/icon_smile.gif)
![Very Happy :D](./images/smilies/icon_biggrin.gif)
files:
temp.asm - this loades the kernel in the second and the following sector, activates pmode and jumps to 08h:0x9000 where it has loaded the remaining kernel, quite simple i guess
kernel.c - this is the actual thing
![Smile :)](./images/smilies/icon_smile.gif)
![Smile :)](./images/smilies/icon_smile.gif)
link.ld
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(_k_main)
SECTIONS
{
. = 0x9000;
.text : {*(.text)}
}
Code: Select all
nasm -f bin temp.asm -o loader.bin
gcc -c kernel.c -o kernel.o -nostdlib
ld -T link.ld -o main.bin kernel.o -Map map.txt
cat loader.bin main.bin > kernel.bin
Anyways, success atlast. Roma Victor!!!!
Regards
Nitin
Nitin