From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 6952 invoked from network); 26 Jul 2023 22:46:45 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 26 Jul 2023 22:46:45 -0000 Received: from mail.posixcafe.org ([45.76.19.58]) by 9front; Wed Jul 26 18:43:39 -0400 2023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posixcafe.org; s=20200506; t=1690411615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BphckIQ2b9d63EQjfuoVVSmFt6nFMQqr9o4jeeZDBZg=; b=BafIvxikRAr0Q687aPKvAZoL8+Hw1bDob5edbr98MXlkTwtALT8PKr2qMi1AcnMd4W0Uhy NaJP3IGuWsLy6PEhhCthTBc1YPu9szmiv0/Qr/tBaftUYC7vey3YDUzT8ze+1i05bZp5Xw w7lOmTfJ4C1nQd8xKNVjx/R9TgOAWJg= Received: from [192.168.168.123] ( [207.45.82.38]) by mail.posixcafe.org (OpenSMTPD) with ESMTPSA id ea4efd81 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <9front@9front.org>; Wed, 26 Jul 2023 17:46:54 -0500 (CDT) Message-ID: Date: Wed, 26 Jul 2023 17:43:36 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: 9front@9front.org From: Jacob Moody Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: package-oriented SQL extension-oriented deep-learning-oriented module Subject: [9front] [PATCH] first attempt at libmach tests Reply-To: 9front@9front.org Precedence: bulk Before attempting to add thumb support I think it would be nice to have some basic tests for the current architectures that we ship compilers for. If there is other things that people feel should be tested please let me know. Thank you, Moody diff 53b322fc31bd0086336f6ca529338dd5125a9dcb uncommitted --- /dev/null +++ b/sys/src/libmach/test/bss.c @@ -1,0 +1,1 @@ +char bsssymbol[32]; --- /dev/null +++ b/sys/src/libmach/test/executable.c @@ -1,0 +1,126 @@ +#include +#include +#include +#include + +static struct { + char *name; + char c; + char *asm[3]; +} exectab[] = { + { "386", '8', { + "SUBL $48,SP", + "MOVW $9,AX", + "JMP _main+7(SB)", + }}, + + { "amd64", '6', { + "SUBQ $50,SP", + "MOVW $9,AX", + "JMP _main+8(SB)", + }}, + + { "arm", '5', { + "MOVW.W R14,#-4c(R13)", + "MOVW $#9,R2", + "B _main+8", + }}, + + { "arm64", '7', { + "SUB $96,SP,SP", + "MOVZW $9,R2", + "B _main+8(SB)", + }}, + + { "mips", 'v', { + "ADD $-4c,R29", + "MOVW $9,R2", + "JMP _main+8(SB)", + }}, + + { "spim", '0', { + "ADD $-4c,R29", + "MOVW $9,R2", + "JMP _main+8(SB)", + }}, + + { "sparc", 'k', { + "SUB $50, R1", + "MOVW $9, R2", + "BA _main+8(SB)", + }}, + + { "power", 'q', { + "SUB $80,R1", + "MOVW $9,R2", + "B _main+8", + }}, +}; + +void +main(void) +{ + int i, fd; + int j, n; + Fhdr f; + Symbol sy, sy2; + char buf[128]; + char buf2[128]; + Map *m; + + for(i = 0; i < nelem(exectab); i++){ + snprint(buf, sizeof buf, "./%c.out", exectab[i].c); + fd = open(buf, OREAD); + if(fd < 0) + sysfatal("open: %r"); + if(crackhdr(fd, &f) != 1) + sysfatal("crackhdr: %r"); + machbytype(f.type); + m = newmap(nil, 0); + if(m == nil) + sysfatal("newmap: %r"); + m = loadmap(m, fd, &f); + if(m == nil) + sysfatal("loadmap: %r"); + if(syminit(fd, &f) < 0) + sysfatal("syminit: %r"); + + snprint(buf2, sizeof buf2, "/sys/src/libmach/test/%c.s", exectab[i].c); + filesym(0, buf, sizeof buf); + if(strcmp(buf, buf2) != 0) + sysfatal("invalid source symbols"); + + if(textsym(&sy, 0) != 1 || strcmp(sy.name, "_main") != 0) + sysfatal("no _main symbol"); + if(textsym(&sy2, 1) != 1 || strcmp(sy2.name, "etext") != 0) + sysfatal("no etext symbol"); + if(textsym(&sy2, 2) != 0) + sysfatal("extra text symbol: %s", sy2.name); + + if(sy.value != f.entry) + sysfatal("_main is not the entrypoint"); + + n = 0; + for(j = 0; j < nelem(exectab[i].asm); j++){ + n += machdata->das(m, sy.value+n, 0, buf, sizeof buf); + if(n < 0) + sysfatal("das: %r"); + if(strcmp(exectab[i].asm[j], buf) != 0) + sysfatal("das mismatch %s vs %s", exectab[i].asm[j], buf); + } + + n = 0; + for(j = 0; ; j++){ + if(globalsym(&sy2, j) != 1) + break; + if(strcmp(sy2.name, "datsymbol") == 0) + n |= 0x1; + if(strcmp(sy2.name, "bsssymbol") == 0) + n |= 0x2; + } + if(n != 3) + sysfatal("missing datsymbol or bsssymbol: %d", n); + close(fd); + } + exits(nil); +} --- /dev/null +++ b/sys/src/libmach/test/genasm.rc @@ -1,0 +1,14 @@ +#!/bin/rc + +word=$1 +reg=$2 +br=$3 +echo ' +#define NPRIVATES 16 +GLOBL datsymbol(SB), 1, $'^$word^' + +TEXT _main(SB), 1, $(2*'^$word^'+NPRIVATES*4) + MOVW $9, '^$reg^' +loop: + '^$br^' loop +' --- /dev/null +++ b/sys/src/libmach/test/mkfile @@ -1,0 +1,43 @@ + $target + +8.s: + genasm.rc 4 AX JMP > $target + +5.s: + genasm.rc 4 R2 B > $target + +7.s: + genasm.rc 8 R2 B > $target + +k.s: + genasm.rc 4 R2 JMP > $target + +q.s: + genasm.rc 4 R2 BR > $target + +v.s: + genasm.rc 4 R2 JMP > $target + +0.s: + genasm.rc 4 R2 JMP > $target