OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 7:54 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: help with c code
PostPosted: Sun Feb 27, 2005 6:20 am 
ive commentated this code so people can read it and hopefully fix the problems gcc says go to 82.36.200.57/shot.jpg for a screenshot of all the problems

main.c

Code:
#include <system.h>

   int gdt_install();
   int idt_install();
   int isrs_install();
   int irq_install();
   int init_video();
   float timer_install();
   float keyboard_install();

/* copys 'count' bytes'bytes of data from 'src' to
   *  'dest', finally return 'dest' */
void *memcpy(void *dest, const void *src, size_t count)
{
    const char *sp = (const char *)src;
    char *dp = (char *)dest;
    for(; count != 0; count--) *dp++ = *sp++;
    return dest;
}

/*  sets 'count' bytes in 'dest' to 'val'.
    *  Again, return 'dest' */
void *memset(void *dest, char val, size_t count)
{
    char *temp = (char *)dest;
    for( ; count != 0; count--) *temp++ = val;
    return dest;
}
/* Same as above, but this time, we're working with a 16-bit
    *  'val' and dest pointer. Your code can be an exact copy of
    *  the above, provided that your local variables if any, are
    *  unsigned short */
unsigned short *memsetw(unsigned short *dest, unsigned short val, size_t count)
{
    unsigned short *temp = (unsigned short *)dest;
    for( ; count != 0; count--) *temp++ = val;
    return dest;
}
/* This loops through character array 'str', returning how
    *  many characters it needs to check before it finds a 0.
    *  In simple words, it returns the length in bytes of a string */
size_t strlen(const char *str)
{
    size_t retval;
    for(retval = 0; *str != '\0'; str++) retval++;
    return retval;
}
//reads I/O ports
unsigned char inportb (unsigned short _port)
{
    unsigned char rv;
    __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
    return rv;
}
//writes I/O ports
void outportb (unsigned short _port, unsigned char _data)
{
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
//simple main function
void main()
{
    int i;

    gdt_install();
    idt_install();
    isrs_install();
    irq_install();
    init_video();
    timer_install();
    keyboard_install();

    __asm__ __volatile__ ("sti");

    puts("test\n");

//    i = 10 / 0;
//    putch(i);

    for (;;);
}



system.h

Code:
#ifndef __SYSTEM_H
#define __SYSTEM_H

/* MAIN.C */
extern unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);
extern unsigned char *memset(unsigned char *dest, unsigned char val, int count);
extern unsigned short *memsetw(unsigned short *dest, unsigned short val, int count);
extern int strlen(const char *str);
extern unsigned char inportb (unsigned short _port);
extern void outportb (unsigned short _port, unsigned char _data);

#endif



Top
  
 
 Post subject: Re:help with c code
PostPosted: Sun Feb 27, 2005 7:23 am 
Learn C before writing your OS. Struggling with the language at the same time you're learning OS concepts is not fun.

Code:
  int gdt_install();
  int idt_install();
  int isrs_install();
  int irq_install();
  int init_video();
  float timer_install();
  float keyboard_install();


You declare these function prototypes, then later try and use these functions, without ever writing the functions.

Code:
extern unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);
extern unsigned char *memset(unsigned char *dest, unsigned char val, int count);
extern unsigned short *memsetw(unsigned short *dest, unsigned short val, int count);
extern int strlen(const char *str);


These function prototypes do NOT match the functions in main.c.

Code:
size_t retval;


size_t is NOT an internal compiler type. It's defined in stddef.h. Fix this by having 'typedef unsigned long size_t' somewhere before you use size_t.

***

Got bored at this point so I didn't bother checking functionality.


Top
  
 
 Post subject: Re:help with c code
PostPosted: Sun Feb 27, 2005 7:31 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 11:59 am
Posts: 1600
Location: Vienna/Austria
Hm. this ip address - is that your own server/pc?

You *do* know, that some black hats might be lured into playing some tricks on you?

BTW: i don't want to know what you've done to your previous thread so that one can't open it anymore.

_________________
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image


Top
 Profile  
 
 Post subject: Re:help with c code
PostPosted: Sun Feb 27, 2005 8:11 am 
thanks i know c++ but C is quite different


Top
  
 
 Post subject: Re:help with c code
PostPosted: Sun Feb 27, 2005 9:26 am 
beyond infinity wrote:
Hm. this ip address - is that your own server/pc?

You *do* know, that some black hats might be lured into playing some tricks on you?

BTW: i don't want to know what you've done to your previous thread so that one can't open it anymore.


when they want to hack on ip, why should they use that one.. it's easy to get the ip from a domain..

EDIT: they will get it anyway.. in every post right at the bottom is the origin IP.. ;D


Top
  
 
 Post subject: Re:help with c code
PostPosted: Mon Feb 28, 2005 2:13 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7614
Location: Germany
Erm... looking at that piece of code, I'd daresay you don't "know" C++ either.

I second Curufir: Learn the language first before tackling OS development.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 129 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group