Page 3 of 3

Posted: Wed Jun 27, 2007 5:44 am
by exkor
print out on the screen address of your check variable, while you are in 16 bit segment.

Posted: Wed Jun 27, 2007 5:44 am
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.

Posted: Wed Jun 27, 2007 7:58 am
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.

Posted: Wed Jun 27, 2007 8:19 am
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

Posted: Wed Jun 27, 2007 8:15 pm
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.

Posted: Wed Jun 27, 2007 8:22 pm
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!!!!