delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/26/15:18:04

Message-ID: <01BD7158.ADC3E840@arnhem-001.std.pop.tip.nl>
From: Guido <guido DOT de DOT jong AT tip DOT nl>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>
Subject: Question about "crt0.s"
Date: Sun, 26 Apr 1998 21:11:26 +-200
MIME-Version: 1.0

Hello everybody!

I'm writing an operating system using DJGPP. I encountered a problem that I think has something to do with my version of "crt0.s". In the following text I will supply you with some details. Please read through to the end so you might be able to give some advice.

I got round to writing the boot sector code and a loader program. This program loads the kernel and switches to protected mode, after which it jumps to the kernel code. No problems there.

I want to write the kernel code mainly in C. I wrote a little test program with just the "main()" like this:

void main (void)
{
	short *p;

	p = (short *) 0xb8000;
	*p = 0x0202;		/* green smiley in the upper left corner of the sceen */
	for (;;);
}

I wrote my own header code in which the segment registers and stack are being setup, the flags are reset and the main function is called. I use "ld" to link the two object files. I made a copy of the "djgpp.djl" and wrote a bogus "__main()" function to get rid of the error messages.

In the end I got this working. So I started expanding the kernel code and getting into trouble...

Whenever I try to call a function that expects parameters things go wrong, that is the function body will not be executed. I copied the body of the main function described above into a test function. It works fine as long as it doesn't take parameters. At first I thought it had to do something with the stack setup. I tried different ways to load SS:ESP and used different assemblers (AS, coming with DJGPP, and NASM). I checked and double checked the resulting code, and I can not find any problems. So I thought it might not be the stack, but maybe it is the whole "crt0.s".

As a result I have the following questions:
* What is "crt0" supposed to do? In other words: what do I have to do in my header to make it work for DJGPP?
* Is there a way to get rid of the linker script and the "__main()" function? I don't intend to use any C++ code in the kernel, so I don't need them (or do I?).
* If I can not drop the "__main()", what should I put in there? Maybe I could copy the "__main()" from the DJGPP source?
* What compiler options can I use best? I use "-ansi -Wall -O2 -fomit-frame-pointer" by default.

Of course I appreciate any suggentions and/or comments.
Thanks in advance!

Guido

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019