Page 1 of 1

how to create img?

Posted: Tue Nov 11, 2008 10:51 am
by teemsu
This is a simple c kernel from basickernel.

Code: Select all

;============kernel_start.asm file
[BITS 32]
[global start]
[extern _k_main] ; this is in the c file

start:
  call _k_main

  cli  ; stop interrupts
  hlt ; halt the CPU

And use NASM for make kernel_start.o

Code: Select all

nasm -f aout kernel_start.asm -o ks.o
OK I get ks.o file.
Create simple kernel.c

Code: Select all

;============kernel.c file
#define WHITE_TXT 0x07 // white on black text

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

k_main() // like main in a normal C program
{
	k_clear_screen();
	k_printf("Hi!\nWelcome to Andaman", 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);
};
USE DJGPP for make kernel.o

Code: Select all

gcc -c kernel.c -o kernel.o
Create link.ld

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text  0xFF800000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :
  { 					
    *(.bss)
  }
}

Make kernel.bin

Code: Select all

ld -T link.ld -o kernel.bin ks.o kernel.o
Now I have 6 files

Code: Select all

kernel.bin
kernel.c
kernel.o
kernel_start.asm
ks.o
link.ld
How to create img file for test on VMWare?

Re: simple c kernel

Posted: Tue Nov 11, 2008 10:57 am
by AJ
Hi,

This is in the DJGPP installation instructions. You need to set the environment variable DJGPP to [YourDJGPPInstallPath]\djgpp.env. The DJGPP install path also needs to be added to your PATH environment variable.

And before someone else gets there - you may find that you hit some stubmling blocks later and would like to create a GCC Cross-Compiler ;)

Cheers,
Adam

Re: simple c kernel

Posted: Wed Nov 12, 2008 1:25 am
by teemsu
I install DJGPP to C drive. (C:\djgpp)

Re: simple c kernel

Posted: Wed Nov 12, 2008 2:42 am
by AJ
teemsu wrote:I install DJGPP to C drive. (C:\djgpp)
Well done.

Did my previous answer work (has it stopped giving that error after adding DJGPP to your environment variables)?

Cheers,
Adam

Re: simple c kernel

Posted: Wed Nov 12, 2008 3:41 am
by teemsu
I read readme.1st.

Code: Select all

   * For Windows 2000 or Windows XP systems:

     - Right-click "My Computer", then select "Properties";
     - Select the "Advanced" tab, then click "Environment Variables" button;
     - Edit the PATH system variable to add the DJGPP bin subdirectory;
       (if you are not an administrator, add the DJGPP bin directory to
       the user PATH variable - or create one with only this directory
       since it is added to the system path);
     - Add a new variable DJGPP and set its value to the full path
       name of the DJGPP.ENV file as explained below.
This is OK?

Code: Select all

C:\djgpp\bin>gcc -c kernel.c -o kernel.o
kernel.c:50:3: warning: no newline at end of file

Re: simple c kernel

Posted: Wed Nov 12, 2008 4:02 am
by AJ
:roll:
DJGPP Installation Page wrote:When properly installed, you should have a c:\djgpp\bin directory, and in it should be at least gcc.exe, as.exe, and stubify.exe. If all the files are in c:\djgpp with no subdirectories, or you see directories like c:\djgpp\djdev203\, you need to delete everything and try a different unzip program.

Make sure you use the djgpp's unzip32, or some other unzip that doesn't support long file names. If you install with WinNT long file names, C++ programs won't compile. Another option is to use pkunzip instead (see the MS-DOS install instructions) or read the FAQ about the NameNumericTail registry key.

Right-click My Computer, select Properties. Select the Advanced tab, then the Environment Variables button. Edit the Path (or PATH, whichever exists) system variable to include C:\DJGPP\BIN at the front. (If you are not an administrator, add it to the PATH variable in the User Variables section, or add a new PATH user environment variable which contains only C:\DJGPP\BIN) Add a new variable DJGPP set to C:\DJGPP\DJGPP.ENV (system variable if possible, user variable if not an administrator) .

You'll need to close and reopen your MS-DOS windows for these changes to take effect.

Rather than edit your autoexec files and/or global environment, you may wish to create a djgpp shortcut instead. To do this, create a c:\djgpp\djgpp.bat that has lines like this:

@echo off
set PATH=c:\djgpp\bin;%PATH%
set DJGPP=c:\djgpp\djgpp.env
chdir c:\djgpp\mystuff (or any other directory)
command

(you can replace that last line with any other shell you'd like)

Re: simple c kernel

Posted: Wed Nov 12, 2008 4:07 am
by babylon2233
teemsu wrote:I read readme.1st.

This is OK?

Code: Select all

C:\djgpp\bin>gcc -c kernel.c -o kernel.o
kernel.c:50:3: warning: no newline at end of file
Of course. It just a warning.

Re: simple c kernel

Posted: Wed Nov 12, 2008 5:46 am
by Combuster
It complains about your code, rather than the installation procedure :D

Re: how to create img?

Posted: Wed Nov 12, 2008 2:22 pm
by Love4Boobies
I never even knew that there's a warning about this :P Is it just me, or is it kind of pointless to have it?

Re: how to create img?

Posted: Wed Nov 12, 2008 2:37 pm
by Combuster
no it is a useful warning:

Code: Select all

#ifndef header
#define header

// no newline at the end here
#endif

Code: Select all

#include "header1.h"
#include "header2."
will break because the include gets expanded like this

Code: Select all

// no newline at the end here
#endif#ifndef header2
#define header2
...