Kernel using C

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post by exkor »

print out on the screen address of your check variable, while you are in 16 bit segment.
Last edited by exkor on Wed Jun 27, 2007 5:44 am, edited 1 time in total.
User avatar
nitinjavakid
Member
Member
Posts: 65
Joined: Sat Oct 21, 2006 11:28 am
Location: Exams over!
Contact:

Post by nitinjavakid »

Combuster wrote:
nitinjavakid wrote:Also, plz tell me how .bss .data and .rodata would help?
Uh, the answer is a few posts back? Back where I told you what happens when no .data and .bss were present?
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.
Regards


Nitin
User avatar
Combuster
Member
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:

Post by Combuster »

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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

When linking your code add this switch to ld

Code: Select all

-Map map.txt
. It will show you where your code is aligned to, and the different sections

--Michael
pcmattman
Member
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:

Post by pcmattman »

I can't help but notice the lack of the 'org' keyword anywhere...

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
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.
User avatar
nitinjavakid
Member
Member
Posts: 65
Joined: Sat Oct 21, 2006 11:28 am
Location: Exams over!
Contact:

Post by nitinjavakid »

Well I had some rest and got a great idea. :) Although very primitive, its well structures :D

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 :)

link.ld

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(_k_main)
SECTIONS
{
	. = 0x9000;
	.text : {*(.text)}	
}
doit.sh

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
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!!!!
Regards


Nitin
Post Reply