Page 1 of 1

Brans kernel development

Posted: Tue Oct 25, 2005 3:24 pm
by vibhory2j
Hi, all

i am learning kernel development throuugh the excellent bran's kernel development tutorials on osdever.net. although the code has compiled and executed after some tweaking but i have some problems. here are they..

1. my confusion is in the very first tut where we simply call the main() in the C file in our kernel setup assembly program.
peice of code :-

extern _k_main ; i have changed the name of the main function
; in c file
call _k_main

gives error on compilation :- invalid reference to _k_main.

and when i change this code to :-

extern k_main
call k_main

this code compiles and excecutes fine.

2. the second one is in the print onscreen section. i have compiles the print.c files as it is. all goes fine but when i execute it in bochs it does not prints anything.

3. this one is not related to kernel dev. does anyone know how to create floppy images in linux without use of any floppy's (i have a floppy drive). i have searched a lot regarding on google and net but found nothing. if anyone knows please let me know.

thanks in advance for any help.

Re:Brans kernel development

Posted: Tue Oct 25, 2005 3:37 pm
by Kemp
Question 3 has been answered repeatedly on the forums and in the OSFAQ (click the banner at the top).

For question 1 I'd assume it has something to do with leading underscores meaning various things, but I'm not too sure on the details right now. I know they can be used to mark out public procedures and suchlike.

Re:Brans kernel development

Posted: Wed Oct 26, 2005 1:28 am
by Candy
Kemp wrote: For question 1 I'd assume it has something to do with leading underscores meaning various things, but I'm not too sure on the details right now. I know they can be used to mark out public procedures and suchlike.
Some old systems (IIRC COFF and a.out) prepend an underscore to names before compiling them. So if you do use that, use an underscore in assembly. Otherwise, strip the underscore. There's a specific compiler flag for gcc to control whether or not to produce a leading underscore.

Re:Brans kernel development

Posted: Wed Oct 26, 2005 2:50 am
by vibhory2j
what happens when we call symbol or any function symbol in a C program which is declared in a assembly language program.

Re:Brans kernel development

Posted: Wed Oct 26, 2005 3:34 am
by AR
vibhory2j wrote: what happens when we call symbol or any function symbol in a C program which is declared in a assembly language program.
What do you mean?

Code: Select all

GLOBAL AddFour
AddFour:
push ebp
mov ebp, esp

mov eax, [ebp + 4]
add eax, 4

pop ebp
ret

Code: Select all

extern int AddFour(int Value);

int main()
{
   printf("AddFour=%d\n", AddFour(52));
   return 0;
}

Re:Brans kernel development

Posted: Thu Oct 27, 2005 6:45 am
by vibhory2j
suppose we have declared a function in assembly and if we want to call it in a C program than is it required to prefix an underscore (_) with the name of that function in the calling C program.

so in the code given above is it required to append a _ infront the function AddFour.

Re:Brans kernel development

Posted: Thu Oct 27, 2005 7:30 am
by Solar
That's dependent on your platform, and there's a GCC command line option to control GCC's behaviour as Candy wrote earlier.

Write a function in Assembler and assemble it (say, to a.out). Then disassemble it with objdump -d a.out and find whether the function name has been prepended with an underscore.

Then write a call to that function in C and see if it links by default.

If it doesn't link, either fix your toolchain or use -fleading_underscore / -fno-leading-underscore to control GCC's behaviour.