From 7ef5cc75cfd3cf93f7edaf2b1b02e557ae16bf7f Mon Sep 17 00:00:00 2001 From: Florian Lohoff Date: Sat, 4 Oct 2008 13:30:01 +0000 Subject: Remove arc references from common libc and add an prom abstraction --- arclib/Makefile | 4 ++-- arclib/prom.c | 13 +++++++++++++ common/Makefile | 4 ++-- common/prom.h | 4 ++++ common/stdio.c | 30 +++++++++++++++--------------- common/stdio.h | 3 +++ ext2load/Makefile | 2 +- 7 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 arclib/prom.c create mode 100644 common/prom.h diff --git a/arclib/Makefile b/arclib/Makefile index c519786..af16014 100644 --- a/arclib/Makefile +++ b/arclib/Makefile @@ -1,10 +1,10 @@ # # Copyright 1999 Silicon Graphics, Inc. # -CFLAGS += -O2 -Werror -Wall -mno-abicalls -G 0 -fno-pic +CFLAGS += -O2 -Werror -I../common -Wall -mno-abicalls -G 0 -fno-pic TARGETS = libarc.a -OBJECTS = arc.o +OBJECTS = arc.o prom.o all: $(TARGETS) diff --git a/arclib/prom.c b/arclib/prom.c new file mode 100644 index 0000000..7048e11 --- /dev/null +++ b/arclib/prom.c @@ -0,0 +1,13 @@ + +#include +#include "arc.h" +#include "prom.h" + +int prom_write(FILE stream, char *string, unsigned long len, unsigned long *rlen) { + return ArcWrite(stream, string, len, rlen); +} + +int prom_read(FILE stream, char *string, unsigned long len, unsigned long *rlen) { + return ArcRead(stream, string, len, rlen); +} + diff --git a/common/Makefile b/common/Makefile index 8a1b06a..3f780f6 100644 --- a/common/Makefile +++ b/common/Makefile @@ -1,6 +1,6 @@ SUBARCH ?= IP22 -CFLAGS += -Wall -O2 -I../arclib -mno-abicalls -G 0 -fno-pic -fno-builtin -I. -DSUBARCH=${SUBARCH} +CFLAGS += -Wall -O2 -mno-abicalls -G 0 -fno-pic -fno-builtin -I. -DSUBARCH=${SUBARCH} HOSTCC = $(CC) HOSTCFLAGS += -Wall -O2 -DSUBARCH=$(SUBARCH) @@ -15,4 +15,4 @@ libc.a: $(OBJECTS) $(AR) -crs $@ $(OBJECTS) clean: - rm -f $(OBJECTS) *~ tags + rm -f $(OBJECTS) $(TARGETS) *~ tags diff --git a/common/prom.h b/common/prom.h new file mode 100644 index 0000000..31852e9 --- /dev/null +++ b/common/prom.h @@ -0,0 +1,4 @@ + +int prom_write(FILE stream, char *buf, unsigned long len, unsigned long *rlen); +int prom_read(FILE stream, char *buf, unsigned long len, unsigned long *rlen); + diff --git a/common/stdio.c b/common/stdio.c index 2d94385..73acbb3 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -4,14 +4,14 @@ #include "string.h" #include "stdio.h" -#include +#include #include -static FILE arc_stdin = ARC_STDIN; -FILE *stdin = &arc_stdin; +static FILE stdin_file = STDIN_FILENO; +FILE *stdin = &stdin_file; -static FILE arc_stdout = ARC_STDOUT; -FILE *stdout = &arc_stdout; +static FILE stdout_file = STDOUT_FILENO; +FILE *stdout = &stdout_file; int fputs(const char *s, FILE * stream) @@ -20,8 +20,8 @@ int fputs(const char *s, FILE * stream) unsigned long count; if (strlen(s) > 0) { - status = ArcWrite(*stream, (char *) s, strlen(s), &count); - if ((status != ESUCCESS) || (count != strlen(s))) + status = prom_write(*stream, (char *) s, strlen(s), &count); + if ((status != 0) || (count != strlen(s))) return EOF; } return 0; @@ -44,8 +44,8 @@ int fgetc(FILE * stream) char ch; unsigned long count; - status = ArcRead(*stream, &ch, sizeof(CHAR), &count); - if ((status != ESUCCESS) || (count != sizeof(CHAR))) + status = prom_read(*stream, &ch, sizeof(char), &count); + if ((status != 0) || (count != sizeof(char))) return EOF; return (int) ch; } @@ -86,15 +86,15 @@ int vfprintf(FILE * stream, const char *format, va_list ap) break; } else { if (format < str) { - LONG status; - ULONG count; - ULONG len = str - format; + long status; + unsigned long count; + unsigned long len = str - format; status = - ArcWrite(*stream, + prom_write(*stream, (char *) format, len, &count); - if ((status != ESUCCESS) + if ((status != 0) || (count != len)) return EOF; count += len; @@ -207,7 +207,7 @@ int vsprintf(char* string, const char *format, va_list ap) break; } else { if (format < str) { - ULONG len = str - format; + unsigned long len = str - format; strncpy(&string[count], (char *) format, len); diff --git a/common/stdio.h b/common/stdio.h index 9ee52d3..d15603e 100644 --- a/common/stdio.h +++ b/common/stdio.h @@ -8,6 +8,9 @@ typedef unsigned long FILE; +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 + #define EOF (-1) extern FILE *stdin; diff --git a/ext2load/Makefile b/ext2load/Makefile index 3a06f08..f10d678 100644 --- a/ext2load/Makefile +++ b/ext2load/Makefile @@ -18,7 +18,7 @@ ARCLIB = $(ARCLIBDIR)/libarc.a LIBC = ../common/libc.a OBJECTS = loader.o ext2io.o conffile.o -LIBS = $(EXT2LIB) $(ARCLIB) $(LIBC) +LIBS = $(EXT2LIB) $(LIBC) $(ARCLIB) TARGETS = ext2load CFLAGS = -O2 -I$(COMMONDIR) -I$(ARCINCLUDEDIR) -I$(E2FSINCLUDEDIR) \ -- cgit v1.2.3