Compare commits

...

13 Commits

Author SHA1 Message Date
Jan (janneke) Nieuwenhuizen b14c2cbab6 WIP ARM: Use mes-style crt1.M1. 2022-09-14 18:04:53 +02:00
Jan (janneke) Nieuwenhuizen 3536aa5f0d doc: Update `PORTING'.
* PORTING (Setup environment): Update guile, gcc-toolchain, pin
nyacc@1.00.2.
2022-09-14 18:04:53 +02:00
Jan (janneke) Nieuwenhuizen a3f70c9a5b Revert "ARM: Use explicit remainder in __mesabi_uldiv call."
This reverts commit 7706fa7b80210f1439914a51ef74eb2a7a69fe6e.
2022-09-14 18:04:53 +02:00
Jan (janneke) Nieuwenhuizen 72d4d0cdaf ARM: Use explicit remainder in __mesabi_uldiv call.
This inexplicably fixes a segfault in tcc-boot0.

* module/mescc/armv4/as.scm (armv4:r0/r1): Instead of using "push 0",
use explicit slot for remainder.
2022-09-14 18:04:53 +02:00
Jan (janneke) Nieuwenhuizen b33626f261 Revert "ARM: Fix unsigned modulo."
This reverts commit 980a18a98125ccd9ef263bb9ca0141c968f7f72e.
2022-09-14 18:04:53 +02:00
Jan (janneke) Nieuwenhuizen ab377dad52 ARM: Fix unsigned modulo.
* lib/arm-mes/arm.M1 (mov____%esp,%r3): New macro.
* module/mescc/armv4/as.scm (armv4:r0%r1): Use it to avoid overwriting
%r0 before caling __mesabi_uldiv.
2022-09-14 18:04:53 +02:00
Jan (janneke) Nieuwenhuizen f9a9713e5f test: Add 60-math-modulo.c.
* lib/tests/scaffold/60-math-modulo.c: New test.
* build-aux/check-mescc.sh (mes_tests): Add it.
2022-09-14 18:04:53 +02:00
Jan (janneke) Nieuwenhuizen f4dfe0ef7e ARM core: Revert to modulo from v0.23.
This inexplicably fixes tcc-boot0.

* src/math.c (modulo): Use v0.23 implementation.
2022-09-14 18:02:36 +02:00
Jan (janneke) Nieuwenhuizen 7d183c2c98 Revert "mescc: Use unsigned type for sizeof expression."
This breaks tcc-boot0 on ARM.

This reverts commit fac6a873f7.
2022-09-14 18:02:36 +02:00
Jan (janneke) Nieuwenhuizen 25cbc48686 Revert "mescc: Only use signed division when numerator is signed."
This breaks tcc-boot0 on ARM.

This reverts commit 348dcbcbd7.
2022-09-14 18:02:36 +02:00
Jan (janneke) Nieuwenhuizen 7a4ed0d535 ARM: ntoab: Do not include __mesabi_uldiv for bootstrap tcc.
* lib/mes/ntoab.c (__mesabi_uldiv): Exclude for tinycc arm bootstrap.
2022-09-14 18:02:36 +02:00
Jan (janneke) Nieuwenhuizen a64e292ce2 build: Also use stage0_cpu detection in bootstrap.sh build.
* build-aux/build-scaffold.sh: Include cflags.sh.
(stage0_cpu): Move to...
* build-aux/cflags.sh (stage0_cpu): ...here.
* build-aux/build.sh.in (stage0_cpu): Remove.
2022-09-12 10:25:51 +02:00
Jan (janneke) Nieuwenhuizen 688b4ffbb6 kaem: Fix version.
* src/symbol.c (MES_VERSION): Update to 0.24.
2022-09-12 10:25:51 +02:00
12 changed files with 162 additions and 68 deletions

View File

@ -22,7 +22,7 @@ to your config.scm and run guix system reconfigure.
For example (note: ARM is no longer a 'port', see HACKING)
#+BEGIN_SRC bash
guix shell --system=armhf-linux --pure bash coreutils diffutils findutils gawk gcc-toolchain@7 grep git guile@2.2 gzip help2man make mescc-tools nyacc openssh-sans-x pkg-config sed tar texinfo
guix shell --system=armhf-linux --pure bash coreutils diffutils findutils gawk gcc-toolchain grep git guile gzip help2man make mescc-tools nyacc openssh-sans-x pkg-config sed tar texinfo
#+END_SRC
** Try it

View File

@ -1,7 +1,7 @@
#! /bin/sh
# GNU Mes --- Maxwell Equations of Software
# Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
# Copyright © 2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
#
# This file is part of GNU Mes.
#
@ -29,6 +29,7 @@ fi
. ./config.sh
. ${srcdest}build-aux/trace.sh
. ${srcdest}build-aux/cflags.sh
if $courageous; then
set +e
@ -42,25 +43,6 @@ else
}
fi
case "$mes_cpu" in
arm)
stage0_arch=40
stage0_cpu=armv7l
;;
x86_64)
stage0_arch=2
stage0_cpu=amd64
;;
x86)
stage0_arch=1
stage0_cpu=x86
;;
*)
stage0_arch=1
stage0_cpu=$mes_cpu
;;
esac
trace "CCLD ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/exit-42.S" $CC\
-nostdlib\
-g\

View File

@ -38,25 +38,6 @@ set -u
. ./config.sh
. ${srcdest}build-aux/cflags.sh
case "$mes_cpu" in
arm)
stage0_arch=40
stage0_cpu=armv7l
;;
x86_64)
stage0_arch=2
stage0_cpu=amd64
;;
x86)
stage0_arch=1
stage0_cpu=x86
;;
*)
stage0_arch=1
stage0_cpu=$mes_cpu
;;
esac
if $courageous; then
echo "Applying courage"
set +e

View File

@ -1,5 +1,5 @@
# GNU Mes --- Maxwell Equations of Software
# Copyright © 2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
# Copyright © 2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
#
# This file is part of GNU Mes.
#
@ -16,6 +16,25 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
case "$mes_cpu" in
arm)
stage0_arch=40
stage0_cpu=armv7l
;;
x86_64)
stage0_arch=2
stage0_cpu=amd64
;;
x86)
stage0_arch=1
stage0_cpu=x86
;;
*)
stage0_arch=1
stage0_cpu=$mes_cpu
;;
esac
AM_CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdest}include

View File

@ -1,7 +1,7 @@
#! /bin/sh
# GNU Mes --- Maxwell Equations of Software
# Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
# Copyright © 2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
#
# This file is part of GNU Mes.
#
@ -117,6 +117,7 @@ lib/tests/scaffold/54-argv.c
lib/tests/scaffold/55-char-array.c
lib/tests/scaffold/60-math.c
lib/tests/scaffold/60-math-itoa.c
lib/tests/scaffold/60-math-modulo.c
lib/tests/scaffold/61-array.c
lib/tests/scaffold/62-array.c
lib/tests/scaffold/63-struct.c

View File

@ -31,6 +31,7 @@ DEFINE add____$i8,%r0 0090e2 # adds r0, r0, #xx; ADDSI = immediate op1 '09' op
# 1090e2 # adds r1, r0, #xx; ADDSI = immediate op1 '09' op2 'e2'
DEFINE add____$i8,%r1 1091e2 # adds r1, r1, #xx
DEFINE add____$i8,%r13 d09de2 # adds r13, r13, #xx
DEFINE add____$i8,%ebp e28cc0 # adds ip, ip, #xx
DEFINE sub____$i8,%r0 0050e2 # subs r0, r0, #xx
DEFINE sub____$i8,%r1 1051e2 # subs r1, r1, #xx
DEFINE add____%r0,%r0 000090e0 # adds r0, r0, r0

View File

@ -1,6 +1,7 @@
### GNU Mes --- Maxwell Equations of Software
### Copyright (C) 2016 Jeremiah Orians
### Copyright © 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
### Copyright © 2017,2018,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
### Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
###
### This file is part of GNU Mes.
###
@ -17,6 +18,47 @@
### You should have received a copy of the GNU General Public License
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
:UNUSED_start
;; ??? from M2
'0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer
push___%lr
push___%ebp
mov____%esp,%ebp
allocate_stack_4180
!0 mov____$i8,%r0
mov____%r0,0x32 &GLOBAL___stdin
!1 mov____$i8,%r0
mov____%r0,0x32 &GLOBAL___stdout
!2 mov____$i8,%r0
mov____%r0,0x32 &GLOBAL___stderr
!8 ldr____%r0,(%fp,+#$i8)
mov____%fp,%r1
!12 add____%r1,$i8
add____%r2,%r1,%r0,lsl#2
!4 add____%r2,$i8
mov____%r2,0x32 &GLOBAL_environ
; M2-Planet calling convention pushes forward
push___%r0 ; argc
push___%r1 ; argv
push___%r2 ; environ
!4 add____$i8,%ebp ;M2-Planet calling convention
^~FUNCTION_main bl
!0x0 add____$i8,%esp
!0x0 cmp____$i8,%r0
SYS_exit mov____$i8,%r7
swi____$0
:__start_loop
wfi
!0x1 mov____$i8,%r0
!0x0 cmp____$i8,%r0
^~__start_loop b
mov____%ebp,%esp
pop____%ebp
ret
:_start
'0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -23,7 +23,7 @@
#include <stdlib.h>
#include <string.h>
#if __M2_PLANET__ || !(__MESC__ && __arm__)
#if __M2_PLANET__ || (!(__MESC__ && __arm__) && !(__TINYC__ && __arm__ && BOOTSTRAP))
size_t
__mesabi_uldiv (size_t a, size_t b, size_t *remainder)
{

View File

@ -0,0 +1,79 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <mes/lib.h>
int
main ()
{
int i;
oputs ("\n");
oputs ("t: 1 % 2\n");
i = 1 % 2;
if (i != 1)
return 1;
oputs ("t: 2 % 4\n");
i = 2 % 4;
if (i != 2)
return 2;
oputs ("t: 3 % 4\n");
i = 3 % 4;
if (i != 3)
return 3;
oputs ("t: 1 % 256\n");
i = 1 % 256;
if (i != 1)
return 4;
unsigned u;
oputs ("\n");
oputs ("t: 1U % 2\n");
u = 1 % 2;
if (u != 1)
return 5;
oputs ("t: 2U % 4\n");
u = 2 % 4;
if (u != 2)
return 6;
oputs ("t: 3U % 4\n");
u = 3 % 4;
if (u != 3)
return 7;
oputs ("t: 1U % 256\n");
u = 1 % 256;
if (u != 1)
return 8;
return 0;
}

View File

@ -143,8 +143,8 @@
((type-name ,type) (ast->type type info))
((type-spec ,type) (ast->type type info))
((sizeof-expr ,expr) (get-type "unsigned" info))
((sizeof-type ,type) (get-type "unsigned" info))
((sizeof-expr ,expr) (get-type "default" info))
((sizeof-type ,type) (get-type "default" info))
((string ,string) (make-c-array (get-type "char" info) (1+ (string-length string))))
@ -1218,9 +1218,9 @@
((rshift ,a ,b) ((binop->r info) a b 'r0>>r1))
((div ,a ,b)
((binop->r info) a b 'r0/r1
(signed? (ast->type a info))))
(or (signed? (ast->type a info)) (signed? (ast->type b info)))))
((mod ,a ,b) ((binop->r info) a b 'r0%r1
(signed? (ast->type a info))))
(or (signed? (ast->type a info)) (signed? (ast->type b info)))))
((mul ,a ,b) ((binop->r info) a b 'r0*r1))
((not ,expr)
@ -1361,7 +1361,7 @@
info)))
(info (expr->register a info))
(info (append-text info (wrap-as (as info 'swap-r0-r1))))
(signed? (signed? type))
(signed? (or (signed? type) (signed? type-b)))
(info (append-text info (cond ((equal? op "+=") (wrap-as (as info 'r0+r1)))
((equal? op "-=") (wrap-as (as info 'r0-r1)))
((equal? op "*=") (wrap-as (as info 'r0*r1)))

View File

@ -191,24 +191,13 @@ modulo (struct scm *a, struct scm *b)
assert_number ("modulo", a);
assert_number ("modulo", b);
long n = a->value;
long v = b->value;
if (v == 0)
long d = b->value;
if (d == 0)
error (cstring_to_symbol ("divide-by-zero"), a);
int sign_p = 0;
size_t w = v;
if (v < 0)
{
sign_p = 1;
w = -v;
}
while (n < 0)
n = n + w;
size_t u = n;
if (u != 0)
u = u % w;
n = u;
if (sign_p)
n = -n;
n = n + d;
if (n != 0)
n = n % d;
return make_number (n);
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -23,7 +23,7 @@
#include <string.h>
// char const *MES_VERSION = "0.23";
// char const *MES_VERSION = "0.24";
#if __M2_PLANET__
#define M2_CELL_SIZE 12