problem on integrating i386-stub.c in my kernel

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
crasher
Posts: 21
Joined: Mon Jan 21, 2008 4:02 am

problem on integrating i386-stub.c in my kernel

Post 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?
User avatar
samueldotj
Member
Member
Posts: 32
Joined: Mon Nov 13, 2006 12:24 am

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

Post 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
crasher
Posts: 21
Joined: Mon Jan 21, 2008 4:02 am

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

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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...
Kunalnitin
Posts: 7
Joined: Thu Jul 28, 2011 6:10 am

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

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

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

Post by bluemoon »

What debugging capability you need?
Did you considered bochs's debug facility or qemu's gdb stub?
Kunalnitin
Posts: 7
Joined: Thu Jul 28, 2011 6:10 am

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

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