Page 1 of 1

problem on integrating i386-stub.c in my kernel

Posted: Fri Aug 01, 2008 10:15 pm
by crasher
I wrote a simple kernel which sets up gdt, idt, enables paging and print a few message.
I want to use this kernel to learn how to do remote debugging with gdb . So I integrate i386-stub.c
from gdb-6.8 tar ball. i386-stub.c needs stdio.h and string.h. So i modify the include path in my makefile

Code: Select all

INCLUDE_PATH=$(CURDIR)/include /usr/include
CFLAGS =  -g -fno-stack-protector -O -fstrength-reduce -fomit-frame-pointer -finline-functions   -I$(INCLUDE_PATH)
CFLAGS += -nostdinc -fno-builtin
CFLAGS += -iwithprefix include
The gcc compiler cannot find stdio.h and string.h yet.

I have my own functions like "puts" in this kernel. Is it possible I don't need remove the directives "-nostdinc and -fno-builtin"
and I can still compile i386-stub.c successfully?

Another question is I noticed there is a variable "_registers" in i386-stub.c. Is it defined in one of the required header files?

Re: problem on integrating i386-stub.c in my kernel

Posted: Fri Aug 01, 2008 10:41 pm
by samueldotj
The gcc compiler cannot find stdio.h and string.h yet.
May be your makefile is not correct.

In my stub I removed the stdio.h and included my own header file which has declaration of kprintf.( and ofcourse I replaced all the printf with kprintf)
Another question is I noticed there is a variable "_registers" in i386-stub.c. Is it defined in one of the required header files?
registers variable is defined inside i386-stub.c( in my stub it is at line 130)
I have my own functions like "puts" in this kernel. Is it possible I don't need remove the directives "-nostdinc and -fno-builtin"
and I can still compile i386-stub.c successfully?
Your kernel should implement putDebugChar() and getDebugChar(), so you should keep -nostdinc and -fno-builtin.

Sam

Re: problem on integrating i386-stub.c in my kernel

Posted: Sat Aug 02, 2008 12:13 am
by crasher
in i386-stub.c, it uses stderr as an input parameter to printf. How should I deal with this if I remove stdio.h in i386-stub.c

Re: problem on integrating i386-stub.c in my kernel

Posted: Sat Aug 02, 2008 3:46 am
by JamesM
crasher wrote:in i386-stub.c, it uses stderr as an input parameter to printf. How should I deal with this if I remove stdio.h in i386-stub.c
Firstly, I'd assume it uses stderr as an input parameter to fprintf, not printf.

Secondly, replace any reference to fprintf or printf with your printk function (or whatever you named it). You obviously won't have file descriptors yet...

Re: problem on integrating i386-stub.c in my kernel

Posted: Thu Aug 04, 2011 5:33 am
by Kunalnitin
Hi Guys,

This thread seems to be dead now but still I am posting a question related to compiling 1386-stub.c file.

I want to build debugging support for my experimental kernel. But I am unable to compile the stub code with gcc4.5 because it contains inline assembly code written with old convention.

I am hopeful that some of you too must have faced this problem and must have resolved it till now. Otherwise the last resort looks like to understand the code re-write it.

Thanks.

Re: problem on integrating i386-stub.c in my kernel

Posted: Thu Aug 04, 2011 5:47 am
by bluemoon
What debugging capability you need?
Did you considered bochs's debug facility or qemu's gdb stub?

Re: problem on integrating i386-stub.c in my kernel

Posted: Thu Aug 04, 2011 5:50 am
by Kunalnitin
1. I have an OS kernel that I can run on bochs/qemu as well as on native hardware (Intel core processors).
2. While running on bochs I can easily debug it with the help of inbuilt gdb-stub.
3. Now, I want to debug my OS while it is running on a native system. It's a very thin OS and it is headless (no shell support is there).

For [3] I thought it would be good if I could "port" i386-stub.c provided by GDB and then use GDB remotely to debug the system.