Brans kernel development

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.
Post Reply
vibhory2j

Brans kernel development

Post 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.
Kemp

Re:Brans kernel development

Post 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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Brans kernel development

Post 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.
vibhory2j

Re:Brans kernel development

Post by vibhory2j »

what happens when we call symbol or any function symbol in a C program which is declared in a assembly language program.
AR

Re:Brans kernel development

Post 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;
}
vibhory2j

Re:Brans kernel development

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Brans kernel development

Post 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.
Every good solution is obvious once you've found it.
Post Reply