Page 1 of 1

Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 11:59 am
by drunkenfox
I decided to go back to OS development starting with a basic DOS system. However, the code doesn't seem to print "Starting OT-DOS..". When running in virtual box the cursor will move down a few lines, but it won't continue from there. I'm using DJGPP for the C/++ compiler. Here is the code:

build.bat

Code: Select all

nasm -f aout ot.asm -o entry.o
gcc -c ot.c -o ot.o
ld -T link.ld -o OT.SYS entry.o ot.o
copy OT.SYS  A:\OT.SYS
pause
ot.asm

Code: Select all

bits 16					; we are still in real mode
global start
extern _k_main

; we are loaded at linear address 0x10000
start:
	call _k_main ;call our c source
	
	cli
	hlt ;stop execution
ot.c

Code: Select all

void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);


k_main() // like main in a normal C program
{
	//k_clear_screen();
	k_printf("Starting OT-DOS..", 0);
};

void k_clear_screen() // clear the entire text screen
{
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;
	while(i < (80*25*2))
	{
		vidmem[i]=' ';
		i++;
		vidmem[i]=WHITE_TXT;
		i++;
	};
};

unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;

	i=(line*80*2);

	while(*message!=0)
	{
		if(*message=='\n') // check for a new line
		{
			line++;
			i=(line*80*2);
			*message++;
		} else {
			vidmem[i]=*message;
			*message++;
			i++;
			vidmem[i]=WHITE_TXT;
			i++;
		};
	};

	return(1);
};
And finally, the linker script

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text  0x010000 : {
    code = .; _code = .; __code = .;
    *(.text)
  }
  .data  : {
    data = .; _data = .; __data = .;
    *(.data)
  }
  .bss  :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
  }
  end = .; _end = .; __end = .;
}
It compiles without errors, and I know it loads the kernel because I used an assembler version earlier. Much help would be appreciated.

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 12:08 pm
by Griwes

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 12:10 pm
by bluemoon
Are you sure you want to mess with aout and obj format, and 16-bit & 32-bit code(*) at the same time?

My advice is, forget all these code and follow the tutorial on this site - it's much cleaner.

*) gcc -c ot.c -o ot.o will generate 32/64bit code on most host environment unless you have an extraordinary setup

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 12:15 pm
by drunkenfox
Adding .rodata directives to the linker script didn't make a difference.

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 12:23 pm
by drunkenfox
Nor did changing video mode to 80x25, still a blank screen.

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 12:32 pm
by Kazinsal
I don't see a definition of WHITE_TXT anywhere.

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 12:41 pm
by drunkenfox
Blacklight wrote:I don't see a definition of WHITE_TXT anywhere.
It's there, I just forgot to copy the very top part of ot.c

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 12:51 pm
by mnovotny
Try declaring vidmem as volatile to make sure compiler is not optimizing it. Somehow.

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 12:55 pm
by drunkenfox
Sigh.. nothing seems to work.

Re: Very simple realmode kernel not printing

Posted: Tue Nov 20, 2012 7:03 pm
by drunkenfox
Disregard this post, I found an alternative.