critical...yes! errors...Absolutly!

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
datajack

critical...yes! errors...Absolutly!

Post by datajack »

when i compile my os it dosent run, here is the code

Code: Select all

//main.c
#include <system.h>

unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count)
{
    const char *sp = (const char *)src;
    char *dp = (char *)dest;
    for(; count != 0; count--) *dp++ = *sp++;
    return dest;
}

unsigned char *memset(unsigned char *dest, unsigned char val, int count)
{
    char *temp = (char *)dest;
    for( ; count != 0; count--) *temp++ = val;
    return dest;
}

unsigned short *memsetw(unsigned short *dest, unsigned short val, int count)
{
    unsigned short *temp = (unsigned short *)dest;
    for( ; count != 0; count--) *temp++ = val;
    return dest;
}

int strlen(const char *str)
{
    int retval;
    for(retval = 0; *str != '\0'; str++) retval++;
    return retval;
}

unsigned char inportb (unsigned short _port)
{
    unsigned char rv;
    __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
    return rv;
}

void outportb (unsigned short _port, unsigned char _data)
{
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}

void main()
{
    init_video();

    puts("Hello World!\n");

    for (;;);
}
im not sure if init_video(); runs at bootime nor the puts function...

Code: Select all

//start.asm
[BITS 32]

global start
start:
   mov esp, _sys_stack
   jmp stublet


ALIGN 4
mboot:
   MULTIBOOT_PAGE_ALIGN   equ 1<<0
   MULTIBOOT_MEMORY_INFO   equ 1<<1
   MULTIBOOT_AOUT_KLUDGE   equ 1<<16
   MULTIBOOT_HEADER_MAGIC   equ 0x1BADB002
   MULTIBOOT_HEADER_FLAGS   equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
   MULTIBOOT_CHECKSUM   equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
EXTERN code, bss, end

   dd MULTIBOOT_HEADER_MAGIC
   dd MULTIBOOT_HEADER_FLAGS
   dd MULTIBOOT_CHECKSUM



   dd mboot
   dd code
   dd bss
   dd end
   dd start


stublet:
   extern _main
   call _main
   jmp$


SECTION .bss
   resb 8192
_sys_stack:
-----------------

Code: Select all

//scrn.c
#include <system.h>

unsigned short *textmemptr;
int attrib = 0x0F;
int csr_x = 0, csr_y = 0;

void scroll(void)
{
   unsigned blank, temp;
   blank = 0x20 | (attrib << 8);

   if(csr_y >= 25)
   {
      temp = csr_y - 25 + 1;
      memcpy (textmemptr, textmemptr + temp * 80, (25 - temp) * 80 * 2);
      memsetw (textmemptr + (25 - temp) * 80, blank, 80);
      csr_y = 25 - 1;
   }
}

void move_csr(void)
{
   unsigned temp;
   
   temp = csr_y * 80 + csr_x;
   outportb (0x3D4, 14);
   outportb (0x3D5, temp >> 8);
   outportb (0x3D4, 15);
   outportb (0x3d5, temp);
}

void cls()
{
   unsigned blank;
   int i;

   blank = 0x20 | (attrib << 8);
   for(i = 0; i<25;i++)
      memsetw (textmemptr + i * 80, blank, 80);
   
   csr_x = 0;
   csr_y = 0;
   move_csr();
}

void putch(unsigned char c)
{
   unsigned short *where;
   unsigned att = attrib << 8;

   if(c == 0x08)
   {
      if(csr_x !=0) csr_x--;
   }
   
   else if(c == 0x09)
   {
      csr_x = (csr_x + 8) & ~(8 - 1);
   }
   else if(c == '\r')
   {
      csr_x = 0;
   }
   else if(c == '\n')
   {
      csr_x = 0;
      csr_y++;
   }
   else if(c >= ' ')
   {
      where = textmemptr + (csr_y * 80 + csr_x);
      *where = c | att;
      csr_x++;
   }
   if(csr_x >= 80)
   {
      csr_x = 0;
      csr_y++;
   }
   scroll();
   move_csr();
}

void puts(unsigned char *text)
{
   int i;

   for (i = 0; i < strlen(text); i++)
   {
      putch(text[i]);
   }
}

void settextcolor(unsigned char forecolor, unsigned char backcolor)
{
   attrib = (backcolor << 4 ) | (forecolor & 0x0F);
}

void init_video(void)
{
   textmemptr = (unsigned short *)0xB800;
   cls();
}
--------
link.ld

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
   .text phys : AT(phys) {
      code = .;
      *(.text)
      . = ALIGN(4096);
   }

   .data : AT(phys + (data - code)) {
      data = .;
      *(.data)
      . = ALIGN(4096);
   }

   .bss : AT(phys + (bss - code)) {
      bss = .;
      *(.bss)
      . = ALIGN(4096);
   }
   end = .;
}
--------
build.bat

Code: Select all

nasmw -f aout -o start.o start.asm
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o scrn.o scrn.c


ld -T link2.ld -o kernel.bin start.o main.o scrn.o
pause
when the os boots off the flopy, it does not execute cls, but im not sure of init_video...does anyone know whats wrong?
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:critical...yes! errors...Absolutly!

Post by nick8325 »

Datajack Keeper wrote:

Code: Select all

//scrn.c
void init_video(void)
{
???textmemptr = (unsigned short *)0xB800;
???cls();
}
That should be 0xB8000, i think.
datajack

Re:critical...yes! errors...Absolutly!

Post by datajack »

lol, surprised i missed that :) thanks ^__^ it works now!
Post Reply