Error adding new functions

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
maurotram
Posts: 15
Joined: Mon Nov 25, 2019 1:05 pm
Location: Italy

Error adding new functions

Post 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?
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Error adding new functions

Post 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.
User avatar
iansjack
Member
Member
Posts: 4705
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Error adding new functions

Post 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.
Post Reply