Very simple realmode kernel not printing

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
User avatar
drunkenfox
Member
Member
Posts: 46
Joined: Tue Mar 13, 2012 10:46 pm

Very simple realmode kernel not printing

Post 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.
;goodbye OS, hello BIOS
mov eax, FFFFFFF0h
jmp eax
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: Very simple realmode kernel not printing

Post by Griwes »

Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Very simple realmode kernel not printing

Post 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
User avatar
drunkenfox
Member
Member
Posts: 46
Joined: Tue Mar 13, 2012 10:46 pm

Re: Very simple realmode kernel not printing

Post by drunkenfox »

Adding .rodata directives to the linker script didn't make a difference.
;goodbye OS, hello BIOS
mov eax, FFFFFFF0h
jmp eax
User avatar
drunkenfox
Member
Member
Posts: 46
Joined: Tue Mar 13, 2012 10:46 pm

Re: Very simple realmode kernel not printing

Post by drunkenfox »

Nor did changing video mode to 80x25, still a blank screen.
;goodbye OS, hello BIOS
mov eax, FFFFFFF0h
jmp eax
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Very simple realmode kernel not printing

Post by Kazinsal »

I don't see a definition of WHITE_TXT anywhere.
User avatar
drunkenfox
Member
Member
Posts: 46
Joined: Tue Mar 13, 2012 10:46 pm

Re: Very simple realmode kernel not printing

Post 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
;goodbye OS, hello BIOS
mov eax, FFFFFFF0h
jmp eax
User avatar
mnovotny
Member
Member
Posts: 27
Joined: Mon Aug 10, 2009 2:54 am
Location: Slovakia

Re: Very simple realmode kernel not printing

Post by mnovotny »

Try declaring vidmem as volatile to make sure compiler is not optimizing it. Somehow.
Keep the world with all its sin
It's not fit for livin' in
User avatar
drunkenfox
Member
Member
Posts: 46
Joined: Tue Mar 13, 2012 10:46 pm

Re: Very simple realmode kernel not printing

Post by drunkenfox »

Sigh.. nothing seems to work.
;goodbye OS, hello BIOS
mov eax, FFFFFFF0h
jmp eax
User avatar
drunkenfox
Member
Member
Posts: 46
Joined: Tue Mar 13, 2012 10:46 pm

Re: Very simple realmode kernel not printing

Post by drunkenfox »

Disregard this post, I found an alternative.
;goodbye OS, hello BIOS
mov eax, FFFFFFF0h
jmp eax
Post Reply