Man, this is a time consuming task...
Okey, here goes nothing.
[*] Is main.c #include-ing the header file containing the puts declaration ?
Of course
. #include <pkernl/screen.h> in both main.c and screen.c
[*] Aren't any outdated files left over by make ? => delete *.o and *.a everywhere.
Yes, every time I build.
[*] Try commenting out the whole body of puts, or even simply duplicating your init_screen_d() and calling it puts, and see if it links correctly (ie. is it a problem with the function's instruction, or with the declaration itself ?)
Tried them all; Empty, the same as init.. I've changed now even switched permanently to another name 'putstr' so that it couldn't confuse it with some std stuff(it shouldn't be possible, but who knows)
[*] Try objdump with various flags to see what your *.o files contain (objdump -s file.o gives you an assembly dump of the file, and you can see the different functions, so you can check it contains the right code).
Yes, objdump confirms that the function is where and what it should be(tried diffrent implementations; empty, what it should be, e.t.c)
[*] If you have access to a "real" unix machine, try compiling with the standard gnu toolchain to see if it's specific to cygwin
I mean I could get access to a real machine, but that option would take too long right now. (I know, I promise that when I get the money I will buy a computer that contains only *nix. Game programming is in the way of me doing *nix instead of Win right now)
[*] Is there a potential conflict with the standard, already existing puts ? (try gcc -fno-builtin -fno-stdlib -f... (can't remember the names but they are listed somewhere on the wiki)
As I said earlier, I have tried avoiding std syntaxes and standards(something I don't want to do though). The commandline options should be what they are. But just for clarity, here they are:
Code: Select all
i586-elf-gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -nodefaultlibs -fno-builtin -I $(INCLUDEDIR)
[*] Is your function declared "inline" or whatever (inline would likely not export the code for re-use unless you have specific gcc options) ?
Nope, not this one. I have others that do, but they should work. Nothing of inline-content is called in puts/putstr either(right now).
[*] Try reducing your case to the just two files main.c, puts.c, plus a makefile, and three functions puts, init_screen and main(), and dump the code here (as short as possible).
include/pkernl/screen.h:
Code: Select all
#ifndef _PKERNL_SCREEN_H
#define _PKERNL_SCREEN_H
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LGREY 7
#define DGREY 8
#define LBLUE 9
#define LGREEN 10
#define LCYAN 11
#define LRED 12
#define LMAGENTA 13
#define LBROWN 14
#define WHITE 15
extern void cls();
extern void putch(char c);
extern void putstr(const char *str);
extern void settextcolor(unsigned char forecolor, unsigned char backcolor);
extern void init_screen_d();
#endif //_PKERNL_SCREEN_H
src/main.c:
Code: Select all
#include <pkernl/kernel.h>
#include <pkernl/types.h>
#include <pkernl/screen.h>
void main()
{
//Initialization
init_screen_d();
putch('a');
for (;;);
}
src/drivers/char/screen.c: (GO TO THE BOTTOM)
Code: Select all
#include <pkernl/screen.h>
#include <pkernl/string.h>
#include <asm/io.h>
/* These define our textpointer, our background and foreground
* colors (attributes), and x and y cursor coordinates */
short *textmemptr;
int attrib = 0x0F;
int csr_x = 0, csr_y = 0;
/* Scrolls the screen */
void scroll(void)
{
unsigned blank, temp;
/* A blank is defined as a space... we need to give it
* backcolor too */
blank = 0x20 | (attrib << 8);
/* Row 25 is the end, this means we need to scroll up */
if(csr_y >= 25)
{
/* Move the current text chunk that makes up the screen
* back in the buffer by a line */
temp = csr_y - 25 + 1;
memcpy (textmemptr, textmemptr + temp * 80, (25 - temp) * 80 * 2);
/* Finally, we set the chunk of memory that occupies
* the last line of text to our 'blank' character */
memsetw (textmemptr + (25 - temp) * 80, blank, 80);
csr_y = 25 - 1;
}
}
/* Updates the hardware cursor: the little blinking line
* on the screen under the last character pressed! */
void move_csr(void)
{
unsigned temp;
/* The equation for finding the index in a linear
* chunk of memory can be represented by:
* Index = [(y * width) + x] */
temp = csr_y * 80 + csr_x;
/* This sends a command to indicies 14 and 15 in the
* CRT Control Register of the VGA controller. These
* are the high and low bytes of the index that show
* where the hardware cursor is to be 'blinking'. To
* learn more, look up some VGA specific
* programming documents. A great start to graphics:
* http://www.brackeen.com/home/vga */
outportb(0x3D4, 14);
outportb(0x3D5, temp >> 8);
outportb(0x3D4, 15);
outportb(0x3D5, temp);
}
/* Sets the forecolor and backcolor that we will use */
void settextcolor(unsigned char forecolor, unsigned char backcolor)
{
/* Top 4 bytes are the background, bottom 4 bytes
* are the foreground color */
attrib = (backcolor << 4) | (forecolor & 0x0F);
}
/* Clears the screen */
void cls()
{
unsigned blank;
int i;
/* Again, we need the 'short' that will be used to
* represent a space with color */
blank = 0x20 | (attrib << 8);
/* Sets the entire screen to spaces in our current
* color */
for(i = 0; i < 25; i++)
memsetw (textmemptr + i * 80, blank, 80);
/* Update out virtual cursor, and then move the
* hardware cursor */
csr_x = 0;
csr_y = 0;
move_csr();
}
/* Puts a single character on the screen */
void putch(char c)
{
short *where;
unsigned att = attrib << 8;
/* Handle a backspace, by moving the cursor back one space */
if(c == 0x08)
if(csr_x != 0)
csr_x--;
/* Handles a tab by incrementing the cursor's x, but only
* to a point that will make it divisible by 8 */
else if(c == 0x09)
csr_x = (csr_x + 8) & ~(8 - 1);
/* Handles a 'Carriage Return', which simply brings the
* cursor back to the margin */
else if(c == '\r')
csr_x = 0;
/* We handle our newlines the way DOS and the BIOS do: we
* treat it as if a 'CR' was also there, so we bring the
* cursor to the margin and we increment the 'y' value */
else if(c == '\n')
{
csr_x = 0;
csr_y++;
}
/* Any character greater than and including a space, is a
* printable character. The equation for finding the index
* in a linear chunk of memory can be represented by:
* Index = [(y * width) + x] */
else if(c >= ' ')
{
where = textmemptr + (csr_y * 80 + csr_x);
*where = c | att; /* Character AND attributes: color */
csr_x++;
}
/* If the cursor has reached the edge of the screen's width, we
* insert a new line in there */
if(csr_x >= 80)
{
csr_x = 0;
csr_y++;
}
/* Scroll the screen if needed, and finally move the cursor */
scroll();
move_csr();
}
/* Uses the above routine to output a string... */
void putstr(const char *str)
{
/*int i;
for (i = 0; i < strlen(str); i++)
putch(str[i]);*/
}
/* Sets our text-mode VGA pointer, then clears the screen for us */
void init_screen_d(void)
{
textmemptr = (short*)0xB8000;
cls();
}
[*] Try to avoid recursive make and make a flat make (or at least compile everything "by hand")
There shouldn't be anything wrong with my few makefiles; I've spent hours staring and polishing them, very thoroughly. I've
tried to do manual builds aswell. No result.
[*] Try to compile all files at once (gcc -o my-os.bin main.c puts.c file-1.c file-2.c ...).
This one is the only one I've tried but failed. That is because I get some error about crx0.o or something in the linker stage, I've read that it should be a standard library thing. I've spent minor time looking around for a "quick fix", turning stdlib of in the ld via gcc. But with no success. I, of course, use all the flags in gcc that should turn of stdlibs, which in turn should turn off ld's link to stdlibs. (Note my sloppy way of describing "standard libraries/predefined" as stdlibs).
If you do know what's causing this/what to do about it I'd be glad to test it out!