Commit graph

39 commits

Author SHA1 Message Date
Jan Nieuwenhuizen e4d0298d1b
core: Support fork, waitpid, execve.
* stage0/x86.M1 (SYS_fork, SYS_waitpid, SYS_execve): New define.
* lib/linux-gcc.c (fork, waitpid, execve): New function.
* lib/linux-mes.c (fork, waitpid, execve): New function.
* lib/libc.c (wait): New function.
* include/unistd.h (fork, execve): Declare.
* include/sys/wait.h (waitpid, wait): Declare.
* module/mes/posix.mes (search-path, execlp, system*, waitpid): New function.
* src/posix.c (primitive_fork, execl): New function.
2018-05-24 19:54:42 +02:00
Jan Nieuwenhuizen b4d1c40aa8
mescc: Tinycc support: Unsigned comparison.
* stage0/x86.M1 (ja32, jae32, jb32, jbe32): New macro.
* module/mes/as-i386.mes (i386:jump-a, i386:jump-ae, i386:jump-b,
  i386:jump-be): Use it in new function.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (test-jump-label->info): Use them to
  support unsigned comparison.
* scaffold/tests/7s-unsigned-compare.c: Test it.
* build-aux/check-mescc.sh (tests): Run it.
2018-05-19 11:41:53 +02:00
Jan Nieuwenhuizen 4faeece057
mescc: Tinycc support: Char and short sign extend.
* module/mes/as-i386.mes (i386:accu*n->local, i386:byte-accu->local+n,
  i386:word-accu->local+n): Remove.
  (i386:byte-accu, i386:signed-byte-accu, i386:word-accu,
  i386:signed-word-accu): New function.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (accu->local+n-text): Simplify.
  (mem->accu, convert-accu): New function.
  (expr->accu): Use them.
* stage0/x86.M1 (mov____%al,0x32(%ebp), mov____%al,0x8(%ebp),
  mov____%ax,0x32(%ebp), mov____%ax,0x8(%ebp), movzbl_0x32(%ebp),%eax,
  movzbl_0x8(%ebp),%eax, movzwl_0x32(%ebp),%eax,
  movzwl_0x8(%ebp),%eax): Deprecate.
* scaffold/tests/7r-sign-extend.c: Test it.
* build-aux/check-mescc.sh (tests): Run it.
2018-05-18 23:58:10 +02:00
Jan Nieuwenhuizen 0f87473105
mescc: Tinycc support: Support bit-fields.
* module/language/c99/compiler.mes (struct->fields): Support bit-fields.
  (ast->type):
  (field-field):
  (field-offset):
  (expr->accu*):
  (expr->accu):
  (struct-field):
  (->size):
* module/language/c99/info.scm (<bit-field>): New type.
* stage0/x86.M1 (and____$i32,%eax, and____(%edx),%eax,
  mov____(%edx),%eax, or____(%edx),%eax): New macro.
* module/mes/as-i386.mes (i386:base-mem->accu): Use
  it.
  (i386:accu-and, i386:accu-and-base-mem, i386:accu-or-base-mem): New
  function.
* module/mes/as-i386.scm: Export them.
* scaffold/tests/7q-bit-field.c: Test it.
* build-aux/check-mescc.sh (tests): Run it.
2018-05-13 17:05:28 +02:00
Jan Nieuwenhuizen 979406f3a6
mlibc: Add ioctl.
* stage0/x86.M1 (SYS_ioctl): New define.
* lib/linux-mes.c (ioctl): New syscall.
* lib/linux-gcc.c (ioctl): New syscall.
* include/sys/ioctl.h: New file.
2018-04-22 11:42:47 +02:00
Jan Nieuwenhuizen ad135d3752 doc: Release udpate.
* HACKING: Update.
* INSTALL: Update.
* NEWS: Update.
* README: Update.
* doc/ANNOUNCE-0.12: New file.
* throughout: (janneke) coming out.
2017-11-21 19:22:26 +01:00
Jan Nieuwenhuizen 4ce75e8f4b mescc: Tinycc support: Respect word size better.
* stage0/x86.M1 (movzwl_0x32(%ebp),%eax,movzwl_0x8(%ebp),%eax): New
  define.
* module/mes/as-i386.mes (i386:push-word-local-de-ref,
  i386:word-local->accu): New function.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (push-local-de-ref): Respect word size.
  (ident->accu): Likewise.
2017-12-03 16:33:35 +01:00
Jan Nieuwenhuizen 74c4197467 mescc: Mescc-tools support: char foo[BAR] = {'a', 'b', 'c'}.
* stage0/x86.M1 (mov____%al,0x8(%ebp), mov____%al,0x32(%ebp),
  mov____%ax,0x8(%ebp), mov____%ax,0x32(%ebp)): New define.
* module/mes/as-i386.mes (i386:accu->local+n,i386:byte-accu->local+n,
  i386:word-accu->local+n): New function.
* module/language/c99/compiler.mes (accu->local+n): New function.
  (initzer->data): Return char as single byte.
  (decl->info): Support char foo[BAR] = {'a', 'b', 'c'}.
* scaffold/tests/66-local-char-array.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-11-27 19:51:18 +01:00
Jan Nieuwenhuizen 49d01a46fa mlibc: Mescc-tools support: chmod.
* stage0/x86.M1 (SYS_chmod): New define.
* lib/libc-gcc.c (chmod): New function.
* lib/libc-mes.c (chmod): New function.
2017-11-26 18:45:10 +01:00
Jan Nieuwenhuizen e8884d83e1 mlibc: GNU Gcc support: setjmp, longjmp.
* stage0/x86.M1 (jmp____*%ebx): New macro.
  (mov____0x8(%ebp),%ebp): New macro.
  (mov____0x8(%ebp),%esp): New macro.
* include/setjmp.h (jmp_buf): Redefine as struct.
* lib/libc-mes+tcc.c (longjmp, setjmp): Implement.
* scaffold/tests/80-setjmp.c: Test it.
* make.scm ("80-setjmp"): Build it.
* .gitignore: Ignore *.tcc-guile.
2017-11-26 13:10:46 +01:00
Jan Nieuwenhuizen 7619190d5c build: compile crt1.c, libc-mesc.c and <input>.c separately.
* mlibc/crt1.c: New file.
* mlibc/libc-mes.c (_start): Remove.
* mlibc/libc-gcc.c (_start): Remove.
* make.scm (LINK.hex2, bin.mescc): Move from guile/guix/make.scm.
* guile/guix/make.scm (LINK.hex2, bin.mescc): Remove.
2017-09-10 16:59:43 +02:00
Jan Nieuwenhuizen 29acdfa2a7 mescc: Tinycc support: refactor _start.
* mlibc/libc-mes.c (_start): Refactor.
  (_env): Remove.
* stage0/x86.M1:
2017-09-03 08:18:18 +02:00
Jan Nieuwenhuizen b16c9dbf16 mescc: Tinycc support: word array assignment.
* stage0/x86.M1 (movzwl_(%eax),%eax): New define.
* module/mes/as-i386.mes (i386:word-mem->accu): New function.
* module/mes/as-i386.scm: Export it.
* module/language/c99/compiler.mes (expr->accu): word array assignment.
  (expr->accu*): word array assignment.
* scaffold/tests/7a-struct-char-array.c (test): Test it.
2017-08-08 10:00:13 +02:00
Jan Nieuwenhuizen 11d240e756 mescc: Tinycc support: struct assign by value.
* module/language/c99/compiler.mes (base->ident): Remove.
  (accu->ident): Use them to support assign of size >4 by value.
* scaffold/tests/7h-struct-assign.c: Test it.
* make.scm (add-scaffold-test): Build it.
* module/mes/as-i386.mes (i386:base->local): Remove.
  (i386:accu*n->local):
  (i386:accu*n->label): New functions.
* module/mes/as-i386.scm: Export them.
* stage0/x86.M1: (mov____%ebx,0x32):
  (mov____%ebx,0x32(%ebp)):
  (mov____%ebx,0x8(%ebp)):
  (mov____%ebx,0x8(%edx)):
  (mov____%ecx,0x32(%ebp)):
  (mov____%ecx,0x8(%ebp)):
  (mov____0x32(%eax),%ebx):
  (mov____0x32(%eax),%ecx):
  (mov____0x8(%eax),%ebx): New define.
2017-08-06 18:49:19 +02:00
Jan Nieuwenhuizen 12b41e0e86 mescc: Tinycc support: byte and word struct fields.
* stage0/x86.M1 (mov____%al,0x8(%edx)):
  (mov____%ax,(%edx)):
  (mov____%ax,0x32(%edx)):
  (mov____%ax,0x8(%edx)):
  (movzbl_0x32(%eax),%eax):
  (movzbl_0x8(%eax),%eax):
  (movzwl_0x32(%eax),%eax):
  (movzwl_0x8(%eax),%eax): New define.
* module/mes/as-i386.mes (i386:word-accu->base-mem):
  (i386:byte-accu->base-mem+n):
  (i386:word-accu->base-mem+n):
  (i386:byte-mem+n->accu):
  (i386:word-mem+n->accu): New function.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (struct-field): Use actual size for
  simple types (WAS: 4).
  (decl->info):
  (expr->accu): Respect byte and word struct field sizes.
* scaffold/tests/7g-struct-byte-word-field.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-08-06 12:27:16 +02:00
Jan Nieuwenhuizen 949e320622 mescc: Tinycc support: ((unsigned char*)str)[0].
* module/language/c99/compiler.mes (expr->accu): Consider size of
  expr array deref.
* stage0/x86.M1 (movzbl_0x32(%ebp),%eax): New define.
* scaffold/tests/7d-cast-char.c: Test it.
2017-08-04 11:34:01 +02:00
Jan Nieuwenhuizen 042022419e mescc: Tinycc support: fix accu value after comparison.
* stage0/x86.M1 (setg___%al,, setge__%al, setl___%al, setle__%al): New
  defines.
* module/mes/as-i386.mes (i386:g?->accu, i386:ge?->accu,
  i386:l?->accu, i386:le?->accu, i386:jumpl, i386:jumple): New functions.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (expr->accu): Use them to fix accu
  value after comparisons.
  (test-jump-label->info): Update comparison jumps.
2017-07-29 20:46:16 +02:00
Jan Nieuwenhuizen 683d5bf1d2 mescc: Tinycc support: foo.bar = foo.baz = bla.
* module/language/c99/compiler.mes (expr->base*): New function.
 (expr->accu): Use it to have value in accu for assignments.
* scaffold/tests/77-pointer-assign.c (test): Test it.
* stage0/x86.M1 (mov____%ecx,(%edx), mov___(%eax),%ecx): New define.
* module/mes/as-i386.mes (accu-mem->base->mem): New function.
  (i386:byte-base->accu-mem+n):
  (i386:byte-base->accu-mem):
  (i386:base-mem->accu-mem):
  (i386:base->accu-mem):
  (i386:value->accu-mem+n):
  (i386:value->accu-mem):
  (i386:accu->base-mem+n):
  (i386:byte-accu->base-mem):
  (i386:accu->base-mem): Rename from accu-address, base-address.
  Update callers.
* module/mes/as-i386.scm (mes): Update exports.
2017-07-28 22:45:32 +02:00
Jan Nieuwenhuizen 03eadd6fa6 mescc: Tinycc support: bugfix foo % bar.
* stage0/x86.M1 (mov____%edx,%ebx): Typo
  (idiv___%ebx): Replace div____%ebx.
* module/mes/as-i386.mes (i386:accu/base): Update.
  (i386:accu%base): Update.
2017-07-28 20:36:21 +02:00
Jan Nieuwenhuizen 2e0c1c0aff mescc: Tinycc support: bugfix *(cast)foo = bar.
* module/language/c99/compiler.mes (expr->accu): Thinko for de-ref assign.
* stage0/x86.M1: Fix typos.
* module/mes/as-i386.mes: Update for typos.
* scaffold/tests/77-pointer-assign.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-07-28 15:27:25 +02:00
Jan Nieuwenhuizen 10e65b35ce mescc: Tinycc support: more function stack space.
* module/mes/as-i386.mes (function-locals): Increase local space from
  64 (16 vars) to 2*1025 + 80 (20 vars).
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen 9f60904d1c mescc: Tinycc support: lseek.
* mlibc/include/unistd.h (lseek): Declare.
* stage0/x86.M1 (SYS_lseek): New define.
* mlibc/libc-mes+tcc.c (lseek): New function.
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen 3e39c56f35 mescc: Tinycc support: unlink.
* mlibc/include/unistd.h (unlink): Declare.
* stage0/x86.M1 (SYS_unlink): New define.
* mlibc/libc-mes+tcc.c (unlink): New function.
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen 2d1623c5f0 mescc: Tinycc support: getcwd.
* mlibc/include/unistd.h (getcwd): Declare.
* stage0/x86.M1 (SYS_getcwd): New define.
* mlibc/libc-mes+tcc.c (getcwd): New function.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen ba6edad975 mescc: Tinycc support: close.
* stage0/x86.M1 (SYS_close): New define.
* mlibc/include/unistd.h (close): Declare.
* mlibc/libc-mes+tcc.c: New file.
* make.scm: Build and install it.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen accf4159a4 mescc: Tinycc support: multi-byte [local] offsets.
* stage0/x86.M1: Add 32bit variants for all 8bit instructions.
* module/mes/as-i386.mes: Use them, switch on size.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen af626da19a mescc: Naming fix.
* stage0/x86.M1 (je8): Rename from jne8.
* module/mes/as-i386.mes (i386:jump-byte-z): Update.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen eff1e97cdf mescc: Tinycc support: ~, ^=.
* module/mes/as-i386.mes (i386:accu-not): New function.
  (i386:accu-negate): Rename from i386:accu-not.
* module/mes/as-i386.scm (mes): Export them.
* module/language/c99/compiler.mes (expr->accu): Support ~, ^=.
* scaffold/tests/60-math.c (test): Test it.
* stage0/x86.M1 (not____%eax): New define.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 94b3c828d3 mescc: Refactor decl.
* module/mes/as-i386.mes (i386:mem->base, i386:nop): New functions.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes:
* stage0/x86.M1 (nop,mov____(%edx),%edx,movzbl_(%edx),%edx): New defines.
* scaffold/tests/23-pointer.c: New file.
* scaffold/tests/t.c: New file.
* make.scm: Build them.
* module/language/c99/compiler.mes (init-declr->name): Handle array.
  (init-declr->pointer): Likewise.
  (ident->accu): Simplify.
  (ident->base): Simplify.
  (ident-address->base): Typo.
  (expr->accu): Simplify.
  (decl->info): Simplify.
* mlibc/libc-mes.c (getenv): Remove superfluous statement.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen fa4fdad623 build: Remove make.
* GNUmakefile: trivial convenience-frontend to ./make.scm
* make/*.make: Remove.
* */*.make: Remove.
2017-07-02 12:03:29 +02:00
Jan Nieuwenhuizen 83a43b81b3 mescc: Produce M1 output instead of hex2.
Use: ./make.scm [TARGET]
     ./make.scm check

* stage0/x86.M1: New file.
* mlibc/mini-libc-mes.c (exit, write): Use M1 instead of .byte.
* mlibc/libc-mes.c (_start, exit, read, write, open, access, brk,
  fsync, printf): Use M1 instead of .byte.
* module/mes/as-i386.mes: Use M1.
* module/mes/make.scm: New file.
* make.scm: New file.
* guile/guix/records.scm: New File.
* guile/guix/shell-utils.scm: New file.
* module/mes/M1.mes: Rename from hex2.mes.
* module/mes/M1.scm: Rename from hex2.scm.
* scripts/mescc.mes: Update callers.
* guile/mescc.scm: Update callers.
2017-07-02 16:25:14 +02:00
Jan Nieuwenhuizen 1de0f33020 mescc: Produce object files in hex2 format, remove hex3.
* GNUmakefile (HEX2_FLAGS): New variable.
* make/mescc-guile.make ($(OUT)/$(TARGET)): Use HEX2 for linking.
* make/mescc-mes.make ($(OUT)/$(TARGET)): Likewise.
* guile/mescc.scm (main): Remove hex3 support.
* scripts/mescc.mes (main): Likewise.
* stage0/elf32-0header.hex2: New file, merging of elf32.hex and elf32-header.hex2.
* stage0/elf-0footer.hex2: New file.
* stage0/elf32-header.hex2: Rename from elf32-header-exit-42.hex2,
  repurpose as generic debug heder.
* stage0/elf32-footer-single-main.hex2: Rename from elf32-footer-exit-42.hex2,
  repurpose as generic debug footer for single-main source.
* stage0/exit-42.c: New file.
* stage0/stage0.make ($(OUT)/0exit-42): Test 0header, 0footer.
  ($(OUT)/exit-42.guile): Test generic debug header, footer.
* stage0/elf32.hex2: Remove.
2017-06-25 09:33:55 +02:00
Jan Nieuwenhuizen bb0f82d5aa build: Add stage0 hex2 test.
* configure (HEX2): Check for hex2 from MESCC_tools.
* INSTALL: Mention it.
* GNUmakefile (SUBDIRS): Add stage0.
* make/check-cc.make: New file.
* make/check.make: Remove CC-not-empty guard.
* scaffold/scaffold.make: Update CC check targets.
2017-06-23 20:18:09 +02:00
Jan Nieuwenhuizen afb5c207a9 stage0: Move to-be-generated part of body to footer.
* stage0/elf32-footer-exit-42.hex2: Add ELF_str, ELF_sym from body.
* stage0/elf32-body-exit-42.hex2: Remove ELF_str, ELF_sym.
2017-06-21 07:05:26 +02:00
Jan Nieuwenhuizen cfca4c5cc1 stage0: Leverage label>base in stage0 gdb header.
* stage0/elf32-header-exit-42.hex2: Replace calculated addresses with label>base.
* stage0/elf32-body-exit-42.hex2: Likewise.
2017-06-19 22:45:51 +02:00
Jan Nieuwenhuizen f63d278cec stage0: Move stage0's section-headers before text.
* stage0/elf32-header-exit-42.hex2: Add section-headers.
* stage0/elf32-body-exit-42.hex2: Update.
* stage0/elf32-footer-exit-42.hex2: Remove section-headers.
2017-06-19 09:52:27 +02:00
Jan Nieuwenhuizen 3b82abdfa5 stage0: Add stage0 hex2 gdb header and footer example.
* stage0/elf32-header-exit-42.hex2: New file.
* stage0/elf32-footer-exit-42.hex2: New file.
2017-06-18 21:06:27 +02:00
Jan Nieuwenhuizen 5bf3c92938 mescc: Remove jump calculation, use labels: prepare.
* module/language/c99/compiler.mes (test-jump-label->info): New
  function.
* module/mes/as-i386.mes (i386:jump-label-z,i386:jump-label-byte-z,
  i386:jump-label-g, i386:jump-label-ge,i386:jump-label-nz): New
  functions.
* module/mes/as-i386.scm: Export them.
2017-06-12 21:00:50 +02:00
Jan Nieuwenhuizen 1263d6e278 mescc: Write object files in hex2 or hex3 format.
* stage0/elf32.hex2: New file.
* module/mes/hex2.mes: New file.
* module/mes/hex2.scm: New file.
* module/language/c99/compiler.mes: Eradicate object lamdas.
  (current-eval, dec-xhex, function:-object->text, object->elf,
  object->objects, merge-objects, alist-add): Remove.
* module/mes/elf.mes (object->elf): New function, move from compiler.mes.
* module/mes/elf.scm: Export it.
* guile/mescc.scm (parse-opts): Add -g.
  (main): Use it.
* scripts/mescc.mes: Likewise.
* scripts/mescc-guile.make (MESCC.scm, MESLD.scm): Add -g flag.
* scripts/mescc-mes.make (MESCC.mes, MESLD.mes): Likewise.
* scaffold/m.c: Add proper includes.
* scaffold/argv.c: New file.
* scaffold/hello.c: Simplify.
* scaffold/micro-mes.c: Add proper includes.
* scaffold/t.c: Add proper includes.
2017-06-11 13:11:40 +02:00