Re: Rudimentary vCPU support for the lcc C compiler
Posted: 27 Apr 2019, 19:48
A place for Gigatron builders and hackers
https://forum.gigatron.io/
Code: Select all
$ make lcc
mkdir -p Utils/lcc/build
cd Utils/lcc && env HOSTFILE=etc/gt1h.c make all
cc -g -c -Isrc -o build/main.o src/main.c
cc -g -c -Isrc -o build/alloc.o src/alloc.c
cc -g -c -Isrc -o build/bind.o src/bind.c
cc -g -c -Isrc -o build/dag.o src/dag.c
[
...lots of output and compiler warnings snipped...
]
cp rt.py build/rt.py
cp asm.py build/asm.py
$
Code: Select all
$ make Libs/Example.gt1
Utils/lcc/build/lcc -ILibs -c Libs/sys/ClearScreen.c -o Libs/sys/ClearScreen.o
Utils/lcc/build/lcc -ILibs -c Libs/sys/Newline.c -o Libs/sys/Newline.o
Utils/lcc/build/lcc -ILibs -c Libs/sys/Random.c -o Libs/sys/Random.o
Utils/lcc/build/lcc -ILibs -c Libs/stdio/putchar.c -o Libs/stdio/putchar.o
Utils/lcc/build/lcc -ILibs -c Libs/stdio/puts.c -o Libs/stdio/puts.o
Utils/lcc/build/lcc -ILibs -c Libs/Example.c -o Libs/Example.o
Utils/lcc/build/lcc -ILibs Libs/sys/ClearScreen.o Libs/sys/Newline.o Libs/sys/Random.o Libs/stdio/putchar.o Libs/stdio/puts.o Libs/Example.o -o Libs/Example.gt1
$ ls -l Libs/Example.gt1
-rw-r----- 1 marcelk staff 743 Apr 29 22:59 Libs/Example.gt1
$
Libs/Example.c uses these functions to write a welcome message to the screen and format some numbers before turning itself into a TV Typewriter. Many of the flags and format specifiers are working already. For example:libc: printf/sprintf family
- Example.c: demonstrate sprintf and printf for %d, %u, %s and %c
- lcc: change argument order to support va_arg() (issue #62)
- lcc: caller of variadic function pops the "extra" arguments
- lcc: fix bug in swapping comparison operands (issue #63)
- stdarg: va_start, va_arg, v_end (and va_sarg, see comments issue #62)
- ctype: isdigit
- stdio: fprintf, fputc, fputs, printf, putchar, puts, snprint, vfprintf, vprintf, vsnprintf, vsprintf
- Makefile: fix mixup between LCC and native compiler
Code: Select all
ClearScreen();
// Demo printf and varargs
printf("%d %d %u\n", 1972, -327, UINT_MAX);
printf("%07d %07d %07u\n", 1972, -327, UINT_MAX);
printf("%+7d %+7d %+7u\n", 1972, -327, UINT_MAX);
printf("%+07d %+07d %+07u\n", 1972, -327, UINT_MAX);
puts("Ready");
Code: Select all
a * (b / c); // won't work yet.
This also works on Ubuntu desktop and even Ubuntu on Windows 10 (Linux shell). First I tried to clone the repository on Windows, but gcc threw many strange errors. After that, cloned it right on the Linux shell, installed bison (sudo apt install bison) and it worked. Not sure what else needs to be installed, because I already had Python et al installed there.marcelk wrote: ↑29 Apr 2019, 21:15 With one command from the root directory of the gigatron-rom repository we can build lcc:All of lcc is now in a the directory Utils/lcc/build/. The compiler has many subprograms and files, with lcc itself being the driver for it all. We can simply keep everything there.Code: Select all
$ make lcc mkdir -p Utils/lcc/build cd Utils/lcc && env HOSTFILE=etc/gt1h.c make all cc -g -c -Isrc -o build/main.o src/main.c cc -g -c -Isrc -o build/alloc.o src/alloc.c cc -g -c -Isrc -o build/bind.o src/bind.c cc -g -c -Isrc -o build/dag.o src/dag.c [ ...lots of output and compiler warnings snipped... ] cp rt.py build/rt.py cp asm.py build/asm.py $
Next compile the test program. The Gigatron backend requires Python 3.6 or up to be installed on the system.
Now we have a program that we can send to a Gigatron with Utils/sendFile.py (Python 2...!), or load into an emulator.Code: Select all
$ make Libs/Example.gt1 Utils/lcc/build/lcc -ILibs -c Libs/sys/ClearScreen.c -o Libs/sys/ClearScreen.o Utils/lcc/build/lcc -ILibs -c Libs/sys/Newline.c -o Libs/sys/Newline.o Utils/lcc/build/lcc -ILibs -c Libs/sys/Random.c -o Libs/sys/Random.o Utils/lcc/build/lcc -ILibs -c Libs/stdio/putchar.c -o Libs/stdio/putchar.o Utils/lcc/build/lcc -ILibs -c Libs/stdio/puts.c -o Libs/stdio/puts.o Utils/lcc/build/lcc -ILibs -c Libs/Example.c -o Libs/Example.o Utils/lcc/build/lcc -ILibs Libs/sys/ClearScreen.o Libs/sys/Newline.o Libs/sys/Random.o Libs/stdio/putchar.o Libs/stdio/puts.o Libs/Example.o -o Libs/Example.gt1 $ ls -l Libs/Example.gt1 -rw-r----- 1 marcelk staff 743 Apr 29 22:59 Libs/Example.gt1 $
[Edit: updated paths for changes made afterwards]