To get to this point, I appended the entry in the libc makefile which describes which freestanding files to build, to include inb.o and outb.o, and made a header file called io.h in the include folder of libc, as well as inb.c and outb.c in libc/io. I included stddef in all of the files, so I'm not sure why the compiler doesn't recognise the types uint8_t and uint16_t?
Below are the changes I made to meaty skeleton:
New files:
Code: Select all
libc/
include/
io.h
io/
inb.c
Code: Select all
libc/
Makefile
Code: Select all
/* libc/include/io.h */
#ifndef _IO_H
#define _IO_H 1
#include <sys/cdefs.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
uint8_t inb(uint16_t port);
#ifdef __cplusplus
}
#endif
#endif
Code: Select all
/* libc/io/inb.c */
#include <io.h>
uint8_t inb(uint16_t port) {
uint8_t result;
asm("in %%dx, %%ax;"
:"=a" (result)
: "d" (port)
);
return (uint8_t)result;
}
Code: Select all
Lots of other stuff
...
FREEOBJS:=\
$(ARCH_FREEOBJS) \
stdio/printf.o \
stdio/putchar.o \
stdio/puts.o \
stdlib/abort.o \
string/memcmp.o \
string/memcpy.o \
string/memmove.o \
string/memset.o \
string/strlen.o \
io/inb.o \
...
More stuff
Code: Select all
Skipping to where it actually compiles my object file
...
i686-elf-gcc --sysroot=/home/Daniel/OS_Stuff/meaty-skeleton/sysroot -isystem=/usr/include -c io/inb.c -o io/inb.o -std=gnu11 -O2 -g -Wall -Wextra -D__is_myos_libc -Iinclude
In file included from io/inb.c:1:0:
include/io.h:12:2: error: unknown type name 'uint8_t'
uint8_t inb(uint16_t port);
^
include/io.h:12:14: error: unknown type name 'uint16_t'
uint8_t inb(uint16_t port);
^
include/io.h:13:11: error: unknown type name 'uint16_t'
void inb(uint16_t port, uint16_t value);
^
include/io.h:13:26: error: unknown type name 'uint16_t'
void inb(uint16_t port, uint16_t value);
^
io/inb.c:3:1: error: unknown type name 'uint8_t'
uint8_t inb(uint16_t port) {
^
io/inb.c:3:13: error: unknown type name 'uint16_t'
uint8_t inb(uint16_t port) {
^
Makefile:67: recipe for target 'io/inb.o' failed
make: *** [io/inb.o] Error 1
make: Leaving directory '/home/Daniel/OS_Stuff/meaty-skeleton/libc'
I'm using a 64 bit windows 8.1 computer with cygwin, compiling with an i386-elf cross compiler (although I have to use grub-mkrescue on a virtual machine) and I can upload a zip or tarball of the project if you really need it, but I'm hoping somebody can spot the problem or suggest some troubleshooting techniques I could use based on what they see in this post.