Page 1 of 1

Error adding new functions

Posted: Sun Dec 01, 2019 4:27 am
by maurotram
Hi everyone, in my newly started OS project I have a problem: following the wiki Meaty Skeleton I can't add new features like this:
inline.h file

Code: Select all

#include <stdio.h>
#include <stdint.h>
#include <sys / cdefs.h>
#ifndef INLINE_H
#define INLINE_H 1
#ifdef __cplusplus
extern "C" {
#endif
static inline void outb (uint16_t port, uint8_t val):


static inline uint8_t inb (uint16_t port);

#ifdef __cplusplus
}
#endif

#endif
file outb.c

Code: Select all

#include <stdio.h>
#include <stdint.h>
#include <inline.h>
static inline void outb (uint16_t port, uint8_t val)
{
    asm volatile ("outb% 0,% 1":: "a" (val), "Nd" (port));
    / * There's an outb% al, $ imm8 encoding, for compile-time constant port numbers that fit in 8b. (N constraint).
     * Wider immediate constants would be truncated at assemble-time (e.g. "i" constraint).
     * The outb% al,% dx encoding is the only option for all other cases.
     *% 1 expands to% dx because port is a uint16_t. % w1 could be used if we had the port number a wider C type * /
}
If I try to use outb in the kernel, I get a undefined reference to 'outb' even if I add the outb.o file in the Makefile to the FREEOBJS list. Does anyone have any solution?

Re: Error adding new functions

Posted: Sun Dec 01, 2019 4:38 am
by alexfru
Learn about what static does, how it affects "visibility" of stuff.

Also, I wonder if you post your actual code (you should) because of the colon where the compiler would find it out of place and error out.

Re: Error adding new functions

Posted: Sun Dec 01, 2019 4:57 am
by iansjack
Not related to your problem, but why do you include "stdio.h" in your header file, let alone in the code file?

The suspicion - particularly because of the initial error - is that you are cut and pasting code from elsewhere without really understanding what it does.