Path: blob/main/tests/sys/compat32/aarch64/swp_test_impl.S
39566 views
/*1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 Warner Losh4* Copyright (c) 2023 Stormshield5* Copyright (c) 2023 Klara, Inc.6*/78#include <sys/syscall.h>910#define STDOUT_FILENO 111#define SWP_MAGIC 0xffc012#define SWPB_MAGIC 0xc0c01314.text15.file "swp_test.S"16.syntax unified17.globl main18.p2align 219.type main,%function20.code 322122main:23sub sp, #0x0424/* r4 is our failed test counter */25mov r4, #02627movw r0, :lower16:.L.testheader28movt r0, :upper16:.L.testheader29ldr r1, =(.L.testheaderEnd - .L.testheader - 1)30bl print3132/* Target address */33mov r0, #0x0334str r0, [sp]35mov r0, sp3637/* Load value */38mov r1, #SWP_MAGIC3940/* swp it */41swp r0, r1, [r0]4243/* Old value should be 3 */44cmp r0, #0x0345bne 1f4647/* Check stack value */48ldr r0, [sp]49mov r1, #SWP_MAGIC50cmp r0, r151bne 1f52b 2f53541:55/* Denote the failed test */56add r4, #157/* "No" part of the notification */58movw r0, :lower16:.L.boknot59movt r0, :upper16:.L.boknot60ldr r1, =(.L.boknotEnd - .L.boknot - 1)61bl print62632:64/* Notify */65movw r0, :lower16:.L.ok166movt r0, :upper16:.L.ok167ldr r1, =(.L.ok1End - .L.ok1 - 1)68bl print6970movw r5, #SWPB_MAGIC71movt r5, #SWPB_MAGIC7273/* Using r6 as our accumulator */74mov r6, sp75/* Simplify the loop */76sub r6, #1773:78/* Restore our magic value every time */79str r5, [sp]80/* Move on to the next byte */81add r6, #18283/* swp it in */84mov r0, r685mov r1, #386swpb r0, r1, [r0]8788/* Check the old value */89cmp r0, #0xc090bne 6f9192/* Check the stack value */93ldrb r0, [r6]94cmp r0, #0x0395bne 6f9697/* Just loop over the rest of the word and check those values. */98mov r1, r699sub r1, sp100101mov r0, #0x001024:103cmp r0, r1104beq 5f105106/* Check the next byte */107ldrb r3, [sp, r0]108cmp r3, #0xc0109bne 6f1101115:112add r0, #0x01113cmp r0, #0x04114/* Hit the end, this one succeeded */115beq 7f116117/* Move on to the next byte */118b 4b1191206:121/* Denote the failed test */122add r4, #1123/* "No" part of the notification */124movw r0, :lower16:.L.boknot125movt r0, :upper16:.L.boknot126ldr r1, =(.L.boknotEnd - .L.boknot - 1)127bl print128129/* FALLTHROUGH */1307:131/* "ok" part */132movw r0, :lower16:.L.bok133movt r0, :upper16:.L.bok134ldr r1, =(.L.bokEnd - .L.bok - 1)135bl print136137/* test number */138mov r0, r6139sub r0, sp140add r0, #0x32 /* "0" + 2 because we start at test 2. */141mov r1, #0x01142str r0, [sp]143mov r0, sp144bl print145146/* boklabel */147movw r0, :lower16:.L.boklabel148movt r0, :upper16:.L.boklabel149ldr r1, =(.L.boklabelEnd - .L.boklabel - 1)150bl print151152/* index */153mov r0, r6154sub r0, sp155add r0, #0x30 /* "0" */156str r0, [sp]157mov r0, sp158mov r1, #0x01159bl print160161/* bokterm */162movw r0, :lower16:.L.bokterm163movt r0, :upper16:.L.bokterm164ldr r1, =(.L.boktermEnd - .L.bokterm - 1)165bl print166167mov r0, sp168add r0, #0x3169cmp r0, r6170bne 3b171172mov r0, r4 /* retval */173ldr r7, =SYS_exit174swi 0175176.p2align 2177.type print,%function178.code 32179print:180/* r0 - string, r1 = size */181mov r2, r1182mov r1, r0183ldr r0, =STDOUT_FILENO184ldr r7, =SYS_write185swi 0186187bx lr188189.L.testheader:190.asciz "1..5\n"191.L.testheaderEnd:192.size .L.testheader, .L.testheaderEnd - .L.testheader193194/* Maybe not the most efficient, but meh. */195.L.ok1:196.asciz "ok 1 - swp\n"197.L.ok1End:198.size .L.ok1, .L.ok1End - .L.ok1199200.L.boknot:201.asciz "not "202.L.boknotEnd:203.size .L.boknot, .L.boknotEnd - .L.boknot204.L.bok:205.asciz "ok "206.L.bokEnd:207.size .L.bok, .L.bokEnd - .L.bok208.L.boklabel:209.asciz " - swpb["210.L.boklabelEnd:211.size .L.boklabel, .L.boklabelEnd - .L.boklabel212.L.bokterm:213.asciz "]\n"214.L.boktermEnd:215.size .L.bokterm, .L.boktermEnd - .L.bokterm216217218