Page 1 of 1

My first code don't work

Posted: Sat May 01, 2010 2:38 pm
by Atom
Hi guys I've a big problem,I can't start to develop my own operating system.
Can you help me?
This is my code:
Kernel.c

Code: Select all

k_main()
{

k_clear_screen();

k_printf("Carregado com sucesso...!\n2piv.0.1"", 0);

};
Start.asm

Code: Select all

[BITS 32]

[global start]
[extern _k_main]

start:

  lgdt [gdt_ptr]

  mov ax,LINEAR_DATA_SEL
  mov ds,ax
  mov es,ax
  mov ss,ax
  mov fs,ax
  mov gs,ax

  call _k_main

  jmp $

SECTION .data

gdt:
; NULL descriptor
dw 0; limit 15:0
dw 0; base 15:0
db 0; base 23:16
db 0; type
db 0; limit 19:16, flags
db 0; base 31:24

; unused descriptor
dw 0
dw 0
db 0
db 0
db 0
db 0

LINEAR_DATA_SELequ$-gdt
dw 0FFFFh
dw 0
db 0
db 92h; present, ring 0, data, expand-up, writable
db 0CFh; page-granular (4 gig limit), 32-bit
db 0

LINEAR_CODE_SELequ$-gdt
dw 0FFFFh
dw 0
db 0
db 9Ah; present,ring 0,code,non-conforming,readable
db 0CFh; page-granular (4 gig limit), 32-bit
db 0
gdt_end:

gdt_ptr:
dw gdt_end - gdt - 1
dd gdt
Video.c

Code: Select all

define WHITE_TXT 0x07



void k_clear_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)

{

char *vidmem = (char *) 0xb8000;

unsigned int i=0;



i=(line*80*2);



while(*message!=0)

{

if(*message=='\n')
{

line++;

i=(line*80*2);

*message++;

} else {

vidmem[i]=*message;

*message++;

i++;

vidmem[i]=WHITE_TXT;

i++;

};

};



return(1);

};
Kernel.ld

Code: Select all

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

Code: Select all

# Makefile for Kernel
CC:= C:\djgpp\bin\gcc       <- Aqui é definido o local onde está instalado o DJGPP
COBJS   := kernel.o video.c <- Para cada arquivo *.c criado para nosso OS
ASMOBJS:= k_entry.o         <- Para cada arquivo *.asm criado para nosso OS
OBJS:= $(COBJS) $(ASMOBJS)
CFILES  := $(COBJS:%.o=%.c)
ASMFILES:= $(ASMOBJS:%.o=%.asm)
ASM:=C:\djgpp\bin\nasm             <- Aqui é definido o local onde está instalado o NASM
LD := C:\djgpp\bin\ld      <- Aqui é definido o local onde está instalado o Link
Build.bat

Code: Select all

@echo off
del *.bin
C:\djgpp\bin\MAKE
PAUSE
When I try to build this appear that error:
Não foi possivel encontrar C:/so/*.bin
make.exe***no tragets.Stop

Thanks

Re: My first code don't work

Posted: Sun May 02, 2010 3:14 am
by Creature
Hello, you might want to read the GCC Cross-Compiler article. DJGPP is not a very good choice for OSDev (for several reasons). Once you succeeded doing that, you will probably want to read Bare Bones for more information on how to configure your linker script, compiler options, etc.

When all of that worked out, and you're still having issues, feel free to post again.