diff --git a/build.lua b/build.lua index 418bc7dc0e..cbbc7cd59c 100644 --- a/build.lua +++ b/build.lua @@ -6,19 +6,21 @@ vars.ackcflags = { } vars.ackldflags = {} vars.plats = { + -- keep sorted "cpm", + "em22", "linux386", "linux68k", - "linuxppc", "linuxmips", - "msdos86", + "linuxppc", "msdos386", + "msdos86", "osx386", "osxppc", "pc86", - "rpi", "pdpv7", - "em22", + "rpi", + "spectrum", } vars.plats_with_tests = { "cpm", diff --git a/mach/z80/as/build.lua b/mach/z80/as/build.lua new file mode 100644 index 0000000000..788b768630 --- /dev/null +++ b/mach/z80/as/build.lua @@ -0,0 +1,12 @@ +bundle { + name = "headers", + srcs = { + "./mach0.c", + "./mach1.c", + "./mach2.c", + "./mach3.c", + "./mach4.c", + "./mach5.c", + } +} + diff --git a/mach/z80/cg/table b/mach/z80/cg/table index 397cecc794..053b70367f 100644 --- a/mach/z80/cg/table +++ b/mach/z80/cg/table @@ -1347,7 +1347,7 @@ gto | | remove(ALL) move({EXTENDED_ADDR,$1},HL) "call .gto" | | | -lim | | | {EXTENDED,"ignmask"} | | +lim | | | {EXTENDED,".ignmask"} | | lin | | remove(ALL) allocate(HL_REG) move({IMMEDIATE,$1},HL) "ld (hol0),hl" @@ -1369,12 +1369,12 @@ rck $1 == 2 | STACK | allocate(ALL_REG) rtt | | | | ret 0| sig | HL_REG_SCR | - "ld (trapproc),hl" - "ld hl,trapproc" + "ld (.trapproc),hl" + "ld hl,.trapproc" | HL | | sim | HL_REG | remove(MEM_ALL) "pop hl" - "ld (ignmask),hl" | | | + "ld (.ignmask),hl" | | | str $1 == 0 | | "pop iy" | | | str $1 == 1 | STACK | allocate(HL_REG) "pop hl" diff --git a/mach/z80/int/em.s b/mach/z80/int/em.s index a7e7fa3f70..cba958dc03 100644 --- a/mach/z80/int/em.s +++ b/mach/z80/int/em.s @@ -57,7 +57,7 @@ EILLINS=18 EILLSIZE=19 ECASE=20 - EMON=25 + EBADMON=25 !--------------------------- Initialization --------------------------- @@ -3615,7 +3615,7 @@ e.case: ld hl,ECASE jr 9b e.mon: - ld hl,EMON + ld hl,EBADMON jr 9b e.array: push af diff --git a/mach/z80/libem/LIST b/mach/z80/libem/LIST deleted file mode 100644 index 84c1e36dc8..0000000000 --- a/mach/z80/libem/LIST +++ /dev/null @@ -1,42 +0,0 @@ -libem_s.a -aaru.s -aar.s -aar2.s -and.s -cii.s -cms.s -cmu.s -cmu4.s -csa.s -csb.s -dvi2.s -dvi4.s -dvu2.s -dvu4.s -exg.s -gto.s -hulp.s -ior.s -laru.s -lar.s -lar2.s -los.s -mli2.s -mli4.s -rck.s -rmi2.s -saru.s -sar.s -sar2.s -sdf.s -sdl.s -set.s -str.s -sts.s -unim.s -trp.s -inn.s -xor.s -nop.s -outdec.s -ret.s diff --git a/mach/z80/libem/build.lua b/mach/z80/libem/build.lua new file mode 100644 index 0000000000..c9b2940c26 --- /dev/null +++ b/mach/z80/libem/build.lua @@ -0,0 +1,53 @@ +for _, plat in ipairs(vars.plats) do + acklibrary { + name = "lib_"..plat, + srcs = { + "./aar2.s", + "./aar.s", + "./aaru.s", + "./and.s", + "./cii.s", + "./cms.s", + "./cmu4.s", + "./cmu.s", + "./csa.s", + "./csb.s", + "./dvi2.s", + "./dvi4.s", + "./dvu2.s", + "./dvu4.s", + "./exg.s", + "./gto.s", + "./hulp.s", + "./inn.s", + "./ior.s", + "./lar2.s", + "./lar.s", + "./laru.s", + "./los.s", + "./mli2.s", + "./mli4.s", + "./nop.s", + "./outdec.s", + "./rck.s", + "./ret.s", + "./rmi2.s", + "./sar2.s", + "./sar.s", + "./saru.s", + "./sdf.s", + "./sdl.s", + "./set.s", + "./str.s", + "./sts.s", + "./trp.s", + "./unim.s", + "./xor.s", + }, + vars = { + plat = plat, + ["+ackcflags"] = {"-Imach/z80/libem"} + }, + } +end + diff --git a/mach/z80/libem/nop.s b/mach/z80/libem/nop.s index 702bd635cf..11b2471514 100644 --- a/mach/z80/libem/nop.s +++ b/mach/z80/libem/nop.s @@ -1,3 +1,4 @@ +# .define .nop .sect .text .sect .rom @@ -26,7 +27,7 @@ push de ld de,1 push de - call WRITE + call _write pop de pop de pop de diff --git a/mach/z80/libem/trp.s b/mach/z80/libem/trp.s index 4719e3ea1f..5ea5b3e129 100644 --- a/mach/z80/libem/trp.s +++ b/mach/z80/libem/trp.s @@ -19,8 +19,8 @@ push hl ! save error no on stack push bc push ix - push hl ! test bit "error no" of ignmask - ld hl,(ignmask) + push hl ! test bit "error no" of .ignmask + ld hl,(.ignmask) ex (sp),hl push hl ld hl,2 @@ -43,7 +43,7 @@ push iy ld iy,2 push iy - call WRITE + call _write pop iy pop iy pop iy diff --git a/mach/z80/libem/unim.s b/mach/z80/libem/unim.s index 7b6a1a956c..aa4c456e10 100644 --- a/mach/z80/libem/unim.s +++ b/mach/z80/libem/unim.s @@ -14,11 +14,11 @@ unimpld: ! used in dispatch table to ret e.mon: - ld hl,EMON + ld hl,EBADMON jr 9b e.rck: push af - ld a,(ignmask) + ld a,(.ignmask) bit 1,a jr nz,8f ld hl,ERANGE diff --git a/mach/z80/libend/build.lua b/mach/z80/libend/build.lua new file mode 100644 index 0000000000..bfbf21cd00 --- /dev/null +++ b/mach/z80/libend/build.lua @@ -0,0 +1,13 @@ +for _, plat in ipairs(vars.plats) do + acklibrary { + name = "lib_"..plat, + srcs = { + "./edata.s", + "./em_end.s", + "./end.s", + "./etext.s", + }, + vars = { plat = plat }, + } +end + diff --git a/mach/z80/libmon/head_em.s b/mach/z80/libmon/head_em.s index 251bd58280..d1220af4eb 100644 --- a/mach/z80/libmon/head_em.s +++ b/mach/z80/libmon/head_em.s @@ -1,4 +1,4 @@ -.define EARRAY,ERANGE,EILLINS,EILLSIZE,ECASE,EMON,EHEAP +.define EARRAY,ERANGE,EILLINS,EILLSIZE,ECASE,EBADMON,EHEAP .define hol0,trapproc,trpim,argv,hp,.reghp,envp,begbss,ignmask .define savebc,savede,savehl,saveix,saveaf,saveiy,ebadmon .define WRITE,EXIT @@ -13,7 +13,7 @@ EILLINS=18 EILLSIZE=19 ECASE=20 - EMON=25 + EBADMON=25 ebadmon=25 diff --git a/mach/z80/libsys/head_em.s b/mach/z80/libsys/head_em.s index 251bd58280..d1220af4eb 100644 --- a/mach/z80/libsys/head_em.s +++ b/mach/z80/libsys/head_em.s @@ -1,4 +1,4 @@ -.define EARRAY,ERANGE,EILLINS,EILLSIZE,ECASE,EMON,EHEAP +.define EARRAY,ERANGE,EILLINS,EILLSIZE,ECASE,EBADMON,EHEAP .define hol0,trapproc,trpim,argv,hp,.reghp,envp,begbss,ignmask .define savebc,savede,savehl,saveix,saveaf,saveiy,ebadmon .define WRITE,EXIT @@ -13,7 +13,7 @@ EILLINS=18 EILLSIZE=19 ECASE=20 - EMON=25 + EBADMON=25 ebadmon=25 diff --git a/plat/spectrum/boot.s b/plat/spectrum/boot.s new file mode 100644 index 0000000000..27dee39bb8 --- /dev/null +++ b/plat/spectrum/boot.s @@ -0,0 +1,73 @@ +# + +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .bss +STACKSIZE = 512 +.comm stack, STACKSIZE + +.sect .text +begtext: + ! We have to clear the bss. (argify requires it.) + + ld hl, endbss + push hl + ld de, begbss + sbc hl, de + ld b, h + ld c, l + dec bc + pop hl + xor a + ld (de), a + inc de + ldir + + ! Set up the stack (now it's been cleared, since it's in the BSS). + + ld sp, stack + STACKSIZE + + ! Push standard parameters. + + ld hl, envp + push hl + ld hl, argv + push hl + ld hl, 1 + push hl + + ! Go. + + call __m_a_i_n +.define EXIT, __exit +EXIT: +__exit: + jr __exit + .align 2 + +! Define symbols at the beginning of our various segments, so that we can find +! them. (Except .text, which has already been done.) + +.define begtext, begdata, begbss +.sect .data; begdata: +.sect .rom; begrom: +.sect .bss; begbss: + +! Some magic data. All EM systems need these. + +.define .ignmask, _errno, .trapproc +.comm .ignmask, 2 +.comm _errno, 2 +.comm .trapproc, 2 + +! The fake argv and env arrays. + +.sect .data +argv: .data2 exename, 0 +envp: .data2 0 +exename: .asciz 'spectrum' diff --git a/plat/spectrum/build-pkg.lua b/plat/spectrum/build-pkg.lua new file mode 100644 index 0000000000..c459a85285 --- /dev/null +++ b/plat/spectrum/build-pkg.lua @@ -0,0 +1,25 @@ +include("plat/build.lua") + +ackfile { + name = "boot", + srcs = { "./boot.s" }, + vars = { plat = "spectrum" } +} + +build_plat_libs { + name = "libs", + arch = "z80", + plat = "spectrum", +} + +installable { + name = "pkg", + map = { + "+tools", + "+libs", + "./include+pkg", + ["$(PLATIND)/spectrum/boot.o"] = "+boot", + ["$(PLATIND)/spectrum/libsys.a"] = "./libsys+lib", + } +} + diff --git a/plat/spectrum/build-tools.lua b/plat/spectrum/build-tools.lua new file mode 100644 index 0000000000..d243e336e7 --- /dev/null +++ b/plat/spectrum/build-tools.lua @@ -0,0 +1,27 @@ +include("plat/build.lua") + +build_as { + name = "as", + arch = "z80", +} + +build_cg { + name = "cg", + arch = "z80", +} + +build_top { + name = "top", + arch = "z80" +} + +return installable { + name = "tools", + map = { + ["$(PLATDEP)/spectrum/as"] = "+as", + ["$(PLATDEP)/spectrum/cg"] = "+cg", + ["$(PLATDEP)/spectrum/top"] = "+top", + ["$(PLATIND)/descr/spectrum"] = "./descr", + "util/opt+pkg", + } +} diff --git a/plat/spectrum/descr b/plat/spectrum/descr new file mode 100644 index 0000000000..eb859f71e2 --- /dev/null +++ b/plat/spectrum/descr @@ -0,0 +1,87 @@ +var w=2 +var wa=2 +var p=2 +var pa=2 +var s=2 +var sa=2 +var l=4 +var la=2 +var f=4 +var fa=2 +var d=8 +var da=2 +var x=8 +var xa=2 +var ARCH=z80 +var PLATFORM=spectrum +var PLATFORMDIR={EM}/share/ack/{PLATFORM} +var CPP_F=-D__unix +var ALIGN=-a0:1 -a1:1 -a2:1 -a3:1 -b0:0x4000 +var MACHOPT_F=-m8 + +# Override the setting in fe so that files compiled for linux386 can see +# the platform-specific headers. + +var C_INCLUDES=-I{EM}/share/ack/{PLATFORM}/include -I{EM}/share/ack/include/ansi + +name be + from .m.g + to .s + program {EM}/lib/ack/{PLATFORM}/cg + args < + stdout + need .e +end +name asopt + from .s + to .so + program {EM}/lib/ack/{PLATFORM}/top + args + optimizer + stdin + stdout +end +name as + from .s.so + to .o + program {EM}/lib/ack/{PLATFORM}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/ack/em_led + mapflag -l* LNAME={PLATFORMDIR}/lib* + mapflag -i SEPID=-b1:0 + mapflag -fp FLOATS={PLATFORMDIR}/libfp.a + args {ALIGN} {SEPID?} \ + ({RTS}:.b=-u _i_main) \ + (.e:{HEAD}={PLATFORMDIR}/boot.o) \ + ({RTS}:.ocm.bas.b={PLATFORMDIR}/c-ansi.o) \ + ({RTS}:.c={PLATFORMDIR}/c-ansi.o) \ + ({RTS}:.mod={PLATFORMDIR}/modula2.o) \ + ({RTS}:.p={PLATFORMDIR}/pascal.o) \ + -o > < \ + (.p:{TAIL}={PLATFORMDIR}/libpascal.a) \ + (.b:{TAIL}={PLATFORMDIR}/libb.a) \ + (.bas:{TAIL}={PLATFORMDIR}/libbasic.a) \ + (.mod:{TAIL}={PLATFORMDIR}/libmodula2.a) \ + (.ocm:{TAIL}={PLATFORMDIR}/liboccam.a) \ + (.ocm.bas.mod.b.c.p:{TAIL}={PLATFORMDIR}/libc.a) \ + {FLOATS?} \ + (.e:{TAIL}={PLATFORMDIR}/libem.a \ + {PLATFORMDIR}/libsys.a \ + {PLATFORMDIR}/libc.a \ + {PLATFORMDIR}/libem.a \ + {PLATFORMDIR}/libsys.a \ + {PLATFORMDIR}/libend.a) + linker +end +name cv + from .out + to .img + program {EM}/bin/aslod + args < > + outfile cpm.com +end diff --git a/plat/spectrum/include/ack/plat.h b/plat/spectrum/include/ack/plat.h new file mode 100644 index 0000000000..e8c2251a08 --- /dev/null +++ b/plat/spectrum/include/ack/plat.h @@ -0,0 +1,11 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H + +#define ACKCONF_WANT_EMULATED_TIME 0 + +#endif diff --git a/plat/spectrum/include/build.lua b/plat/spectrum/include/build.lua new file mode 100644 index 0000000000..70f1f9e741 --- /dev/null +++ b/plat/spectrum/include/build.lua @@ -0,0 +1,22 @@ +include("plat/build.lua") + +headermap = {} +packagemap = {} + +local function addheader(h) + headermap[h] = "./"..h + packagemap["$(PLATIND)/spectrum/include/"..h] = "./"..h +end + +addheader("ack/plat.h") +addheader("sys/types.h") + +acklibrary { + name = "headers", + hdrs = headermap +} + +installable { + name = "pkg", + map = packagemap +} diff --git a/plat/spectrum/include/sys/types.h b/plat/spectrum/include/sys/types.h new file mode 100644 index 0000000000..6a0c3d3db1 --- /dev/null +++ b/plat/spectrum/include/sys/types.h @@ -0,0 +1,9 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +typedef int pid_t; +typedef int mode_t; +typedef long time_t; +typedef long suseconds_t; + +#endif diff --git a/plat/spectrum/libsys/_hol0.s b/plat/spectrum/libsys/_hol0.s new file mode 100644 index 0000000000..f01566fe84 --- /dev/null +++ b/plat/spectrum/libsys/_hol0.s @@ -0,0 +1,19 @@ +# +! $Source$ +! $State$ +! $Revision$ + +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .bss + +! This data block is used to store information about the current line number +! and file. + +.define hol0 +.comm hol0, 8 diff --git a/plat/spectrum/libsys/_sys_rawread.s b/plat/spectrum/libsys/_sys_rawread.s new file mode 100644 index 0000000000..b9c784daf8 --- /dev/null +++ b/plat/spectrum/libsys/_sys_rawread.s @@ -0,0 +1,21 @@ +# +! $Source$ +! $State$ +! $Revision$ + +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + +! Reads a single byte. + +.define __sys_rawread +__sys_rawread: + xor a + ret + \ No newline at end of file diff --git a/plat/spectrum/libsys/_sys_rawwrite.s b/plat/spectrum/libsys/_sys_rawwrite.s new file mode 100644 index 0000000000..de37dc6bef --- /dev/null +++ b/plat/spectrum/libsys/_sys_rawwrite.s @@ -0,0 +1,23 @@ +# +! $Source$ +! $State$ +! $Revision$ + +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + +! Writes a single byte to the console. + +.define __sys_rawwrite +.extern __sys_rawwrite + +__sys_rawwrite: + rst 0x10 + ret + \ No newline at end of file diff --git a/plat/spectrum/libsys/_trap.s b/plat/spectrum/libsys/_trap.s new file mode 100644 index 0000000000..d93f9890eb --- /dev/null +++ b/plat/spectrum/libsys/_trap.s @@ -0,0 +1,42 @@ +# +#include "asm.h" + +.define .trp +.define EARRAY, ERANGE, ESET, EIOVFL, EFOVFL, EFUNFL, EIDIVZ, EIDIVZ +.define EFDIVZ, EIUND, EFUND, ECONV, ESTACK, EHEAP, EILLINS, EODDZ +.define ECASE, EMEMFLT, EBADPTR, EBADPC, EBADLAE, EBADMON, EBADLIN, EBADGTO +.define EUNIMPL + +! Trap routine +! Expects trap number in A, and must be called directly from the code +! where execution should resume (for those traps which support it). +! Just returns if trap has to be ignored. +! Otherwise it calls a user-defined trap handler if provided. +! When no user-defined trap handler is provided or when the user-defined +! trap handler causes a new trap, a message is printed +! and control is returned to the monitor. + + EARRAY = 0 + ERANGE = 1 + ESET = 2 + EIOVFL = 3 + EFOVFL = 4 + EFUNFL = 5 + EIDIVZ = 6 + EFDIVZ = 7 + EIUND = 8 + EFUND = 9 + ECONV = 10 + ESTACK = 16 + EHEAP = 17 + EILLINS = 18 + EODDZ = 19 + ECASE = 20 + EMEMFLT = 21 + EBADPTR = 22 + EBADPC = 23 + EBADLAE = 24 + EBADMON = 25 + EBADLIN = 26 + EBADGTO = 27 + EUNIMPL = 63 ! unimplemented em-instruction called diff --git a/plat/spectrum/libsys/asm.h b/plat/spectrum/libsys/asm.h new file mode 100644 index 0000000000..f86b911040 --- /dev/null +++ b/plat/spectrum/libsys/asm.h @@ -0,0 +1,13 @@ +#ifndef ASM_H +#define ASM_H + +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + +#endif diff --git a/plat/spectrum/libsys/brk.c b/plat/spectrum/libsys/brk.c new file mode 100644 index 0000000000..293703234b --- /dev/null +++ b/plat/spectrum/libsys/brk.c @@ -0,0 +1,59 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include + +#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */ +#define STACK_BUFFER 128 /* number of bytes to leave for stack */ + +extern char _end[1]; +static char* current = _end; + +int brk(void* newend) +{ + /* This variable is used to figure out the current stack pointer, + * by taking its address. */ + char dummy; + char* p = newend; + + if ((p > (&dummy - STACK_BUFFER)) || + (p < _end)) + { + errno = ENOMEM; + return -1; + } + + current = p; + return 0; +} + +void* sbrk(int increment) +{ + char* old; + char* new; + + if (increment == 0) + return current; + + old = current; + + new = old + increment; + + if ((increment > 0) && (new <= old)) + goto out_of_memory; + else if ((increment < 0) && (new >= old)) + goto out_of_memory; + + if (brk(new) < 0) + goto out_of_memory; + + return old; + +out_of_memory: + errno = ENOMEM; + return OUT_OF_MEMORY; +} diff --git a/plat/spectrum/libsys/build.lua b/plat/spectrum/libsys/build.lua new file mode 100644 index 0000000000..163fa05f6f --- /dev/null +++ b/plat/spectrum/libsys/build.lua @@ -0,0 +1,80 @@ +local generated = {} + +acklibrary { + name = "internal", + hdrs = { + "./asm.h", + } +} + +local trap_calls = { + "EARRAY", + "EBADGTO", + "EBADLAE", + "EBADLIN", + "EBADMON", + "EBADPC", + "EBADPTR", + "ECASE", + "ECONV", + "EFDIVZ", + "EFOVFL", + "EFUND", + "EFUNFL", + "EHEAP", + "EIDIVZ", + "EILLINS", + "EIOVFL", + "EIUND", + "EMEMFLT", + "EODDZ", + "ERANGE", + "ESET", + "ESTACK", + "EUNIMPL", + "EMON", +} + +for _, name in pairs(trap_calls) do + generated[#generated+1] = normalrule { + name = name, + ins = { "./make_trap.sh" }, + outleaves = { name..".s" }, + commands = { + "%{ins[1]} "..name:lower().." "..name.." > %{outs}" + } + } +end + +acklibrary { + name = "lib", + srcs = { + "./brk.c", + "./close.c", + "./creat.c", + "./errno.s", + "./getpid.c", + "./_hol0.s", + "./isatty.c", + "./kill.c", + "./lseek.c", + "./open.c", + "./read.c", + "./signal.c", + "./_sys_rawread.s", + "./_sys_rawwrite.s", + "./_trap.s", + "./time.c", + "./write.c", + generated + }, + deps = { + "lang/cem/libcc.ansi/headers+headers", + "plat/spectrum/include+headers", + "+internal", + }, + vars = { + plat = "spectrum" + } +} + diff --git a/plat/spectrum/libsys/close.c b/plat/spectrum/libsys/close.c new file mode 100644 index 0000000000..1c570029b5 --- /dev/null +++ b/plat/spectrum/libsys/close.c @@ -0,0 +1,14 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include + +int close(int fd) +{ + errno = EBADF; + return -1; +} diff --git a/plat/spectrum/libsys/creat.c b/plat/spectrum/libsys/creat.c new file mode 100644 index 0000000000..34ace747c0 --- /dev/null +++ b/plat/spectrum/libsys/creat.c @@ -0,0 +1,15 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include +#include "libsys.h" + +int open(const char* path, int access, ...) +{ + errno = EACCES; + return -1; +} diff --git a/plat/spectrum/libsys/errno.s b/plat/spectrum/libsys/errno.s new file mode 100644 index 0000000000..9858d2640d --- /dev/null +++ b/plat/spectrum/libsys/errno.s @@ -0,0 +1,28 @@ +# +! $Source$ +! $State$ +! $Revision$ + +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +#define D(e) .define e; e + +.sect .data + +! Define various ACK error numbers. Note that these are *not* ANSI C +! errnos, and are used for different purposes. + +D(ERANGE) = 1 +D(ESET) = 2 +D(EIDIVZ) = 6 +D(EHEAP) = 17 +D(EILLINS) = 18 +D(EODDZ) = 19 +D(ECASE) = 20 +D(EBADMON) = 25 + diff --git a/plat/spectrum/libsys/getpid.c b/plat/spectrum/libsys/getpid.c new file mode 100644 index 0000000000..5e6eb003e6 --- /dev/null +++ b/plat/spectrum/libsys/getpid.c @@ -0,0 +1,13 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include + +pid_t getpid(void) +{ + return 0; +} diff --git a/plat/spectrum/libsys/isatty.c b/plat/spectrum/libsys/isatty.c new file mode 100644 index 0000000000..ad01e343f3 --- /dev/null +++ b/plat/spectrum/libsys/isatty.c @@ -0,0 +1,13 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include + +int isatty(int fd) +{ + return 1; +} diff --git a/plat/spectrum/libsys/kill.c b/plat/spectrum/libsys/kill.c new file mode 100644 index 0000000000..4a179c47c6 --- /dev/null +++ b/plat/spectrum/libsys/kill.c @@ -0,0 +1,14 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include + +int kill(pid_t pid, int sig) +{ + errno = EINVAL; + return -1; +} diff --git a/plat/spectrum/libsys/libsys.h b/plat/spectrum/libsys/libsys.h new file mode 100644 index 0000000000..fee2fc76df --- /dev/null +++ b/plat/spectrum/libsys/libsys.h @@ -0,0 +1,16 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#ifndef LIBSYS_H +#define LIBSYS_H + +extern void _sys_rawwrite(unsigned char b); +extern unsigned char _sys_rawread(void); + +extern void _sys_write_tty(char c); + +/* extern int _sys_ttyflags; */ + +#endif diff --git a/plat/spectrum/libsys/lseek.c b/plat/spectrum/libsys/lseek.c new file mode 100644 index 0000000000..ecbc4b5207 --- /dev/null +++ b/plat/spectrum/libsys/lseek.c @@ -0,0 +1,14 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include + +off_t lseek(int fd, off_t offset, int whence) +{ + errno = EINVAL; + return -1; +} diff --git a/plat/spectrum/libsys/make_trap.sh b/plat/spectrum/libsys/make_trap.sh new file mode 100755 index 0000000000..dc37fb8ebe --- /dev/null +++ b/plat/spectrum/libsys/make_trap.sh @@ -0,0 +1,10 @@ +#!/bin/sh +cat < +#include +#include +#include "libsys.h" + +int creat(const char* path, int mode) +{ + return open(path, O_CREAT|O_WRONLY|O_TRUNC, mode); +} diff --git a/plat/spectrum/libsys/read.c b/plat/spectrum/libsys/read.c new file mode 100644 index 0000000000..c888660a4d --- /dev/null +++ b/plat/spectrum/libsys/read.c @@ -0,0 +1,43 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include +#include "libsys.h" + +ssize_t read(int fd, void* buffer, size_t count) +{ + char i; + + /* We're only allowed to read from fd 0, 1 or 2. */ + + if ((fd < 0) || (fd > 2)) + { + errno = EBADF; + return -1; + } + + /* Empty buffer? */ + + if (count == 0) + return 0; + + /* Read one byte. */ + + i = _sys_rawread(); +#if 0 + if ((i == '\r') && !(_sys_ttyflags & RAW)) + i = '\n'; + if (_sys_ttyflags & ECHO) + _sys_write_tty(i); +#endif + if (i == '\r') + i = '\n'; + _sys_write_tty(i); + + *(char*)buffer = i; + return 1; +} diff --git a/plat/spectrum/libsys/signal.c b/plat/spectrum/libsys/signal.c new file mode 100644 index 0000000000..a87b9ced24 --- /dev/null +++ b/plat/spectrum/libsys/signal.c @@ -0,0 +1,15 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include +#include +#include "libsys.h" + +sighandler_t signal(int signum, sighandler_t handler) +{ + return SIG_DFL; +} diff --git a/plat/spectrum/libsys/time.c b/plat/spectrum/libsys/time.c new file mode 100644 index 0000000000..5ef17b841e --- /dev/null +++ b/plat/spectrum/libsys/time.c @@ -0,0 +1,17 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include +#include +#include "libsys.h" + +time_t time(time_t* t) +{ + if (t) + *t = 0; + return 0; +} diff --git a/plat/spectrum/libsys/write.c b/plat/spectrum/libsys/write.c new file mode 100644 index 0000000000..064e5f487f --- /dev/null +++ b/plat/spectrum/libsys/write.c @@ -0,0 +1,48 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#include +#include +#include +#include "libsys.h" + +void _sys_write_tty(char c) +{ + _sys_rawwrite(c); +#if 0 + if ((c == '\n') && !(_sys_ttyflags & RAW)) + _sys_rawwrite('\r'); +#endif + if (c == '\n') + _sys_rawwrite('\r'); +} + +ssize_t write(int fd, void* buffer, size_t count) +{ + int i; + char* p = buffer; + + /* We're only allowed to write to fd 0, 1 or 2. */ + + if ((fd < 0) || (fd > 2)) + { + errno = EBADF; + return -1; + } + + /* Write all data. */ + + i = 0; + while (i < count) + { + _sys_write_tty(*p++); + + i++; + } + + /* No failures. */ + + return count; +}