Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FEOSSTDIO module with basic stdio.h functions
- Loading branch information
Showing
25 changed files
with
308 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "feos.h" | ||
#include "fxe.h" | ||
#include <sys/fcntl.h> | ||
#include <unistd.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
FILE* FeOS_GetStdin() | ||
{ | ||
return stdin; | ||
} | ||
|
||
FILE* FeOS_GetStdout() | ||
{ | ||
return stdout; | ||
} | ||
|
||
FILE* FeOS_GetStderr() | ||
{ | ||
return stderr; | ||
} | ||
|
||
BEGIN_TABLE(FEOSSTDIO) | ||
ADD_FUNC(FeOS_GetStdin), | ||
ADD_FUNC(FeOS_GetStdout), | ||
ADD_FUNC(FeOS_GetStderr), | ||
|
||
// Basic I/O | ||
ADD_FUNC(fopen), | ||
ADD_FUNC(freopen), | ||
ADD_FUNC(fclose), | ||
ADD_FUNC(fwrite), | ||
ADD_FUNC(fread), | ||
ADD_FUNC(feof), | ||
ADD_FUNC(fseek), | ||
ADD_FUNC(ftell), | ||
ADD_FUNC(fflush), | ||
ADD_FUNC(ferror), | ||
|
||
// Formatting | ||
ADD_FUNC_ALIAS(vfiprintf, vfprintf), | ||
ADD_FUNC_ALIAS(vsiprintf, vsprintf), | ||
ADD_FUNC_ALIAS(vfiscanf, vfscanf), | ||
ADD_FUNC_ALIAS(vsiscanf, vsscanf), | ||
|
||
// Strings and chars | ||
ADD_FUNC(fgetc), ADD_FUNC(fputc), | ||
ADD_FUNC(fgets), ADD_FUNC(fputs) | ||
END_TABLE(FEOSSTDIO) | ||
|
||
extern void* _inst_FEOSSTDIO; | ||
|
||
fxe_runtime_header _header_FEOSSTDIO = | ||
{ | ||
&_inst_FEOSSTDIO, // hThis | ||
"FEOSSTDIO", // name | ||
1, // refcount | ||
-1, // file | ||
NULL, // entrypoint | ||
MAKE_EXPORTSTRUCT(FEOSSTDIO), // exp | ||
{ 0, NULL }, // imp | ||
NULL, // next | ||
NULL // prev | ||
}; | ||
|
||
void* _inst_FEOSSTDIO = &_header_FEOSSTDIO; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.SUFFIXES: | ||
|
||
MODULE := $(shell basename $(CURDIR)) | ||
|
||
FUNCS := \ | ||
FeOS_GetStdin \ | ||
FeOS_GetStdout \ | ||
FeOS_GetStderr \ | ||
fopen \ | ||
freopen \ | ||
fclose \ | ||
fwrite \ | ||
fread \ | ||
feof \ | ||
fseek \ | ||
ftell \ | ||
fflush \ | ||
ferror \ | ||
vfprintf \ | ||
vsprintf \ | ||
vfscanf \ | ||
vsscanf \ | ||
fgetc \ | ||
fputc \ | ||
fgets \ | ||
fputs | ||
|
||
SFILES := $(addsuffix .s, $(FUNCS)) | ||
|
||
.PHONY: all clean | ||
|
||
all: $(SFILES) | ||
|
||
%.s: | ||
@echo $@ | ||
@printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ | ||
@printf ".global __imp_%b\n" $(@:.s=) >> $@ | ||
@printf ".hidden __imp_%b\n" $(@:.s=) >> $@ | ||
@printf ".global %b\n" $(@:.s=) >> $@ | ||
@printf ".hidden %b\n" $(@:.s=) >> $@ | ||
@printf "%b:\n" $(@:.s=) >> $@ | ||
@printf "\tldr r12, [pc]\n" >> $@ | ||
@printf "\tbx r12\n" >> $@ | ||
@printf "__imp_%b:\n" $(@:.s=) >> $@ | ||
@printf "\t.word 0" >> $@ | ||
|
||
clean: | ||
@rm -fr $(SFILES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
int fprintf(FILE* f, const char* fmt, ...) | ||
{ | ||
va_list v; | ||
va_start(v, fmt); | ||
int rc = vfprintf(f, fmt, v); | ||
va_end(v); | ||
return rc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
int fscanf(FILE* f, const char* fmt, ...) | ||
{ | ||
va_list v; | ||
va_start(v, fmt); | ||
int rc = vfscanf(f, fmt, v); | ||
va_end(v); | ||
return rc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
|
||
int getchar() | ||
{ | ||
return fgetc(stdin); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
|
||
char* gets(char* buf) | ||
{ | ||
return fgets(buf, 1024, stdin); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
int printf(const char* fmt, ...) | ||
{ | ||
va_list v; | ||
va_start(v, fmt); | ||
int rc = vprintf(fmt, v); | ||
va_end(v); | ||
return rc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
|
||
int putchar(int ch) | ||
{ | ||
return fputc(ch, stdout); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
int puts(const char* str) | ||
{ | ||
FILE* f = stdout; | ||
|
||
int rc = fputs(str, f); | ||
fputc('\n', f); | ||
return rc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
|
||
void rewind(FILE* f) | ||
{ | ||
fseek(f, 0, SEEK_SET); | ||
} |
Oops, something went wrong.