asm/common: move sys_mmap macro to proc

This commit is contained in:
Denis Drakhnia 2024-01-11 08:19:17 +02:00
parent 40e4388767
commit 4faaad866c
7 changed files with 115 additions and 63 deletions

View File

@ -1,3 +1,6 @@
src = files('start.S')
src = files(
'start.S',
'mmap.S',
)
common_lib = static_library('common', src, include_directories : inc_dir)

40
tests/asm/common/mmap.S Normal file
View File

@ -0,0 +1,40 @@
#include "common/mmap.h"
// Arguments:
// %r0 addr
// %r1 len
// %r2 prot
// %r3 flags
// %r4 fd
// %r5 offset
.global sys_mmap
.type sys_mmap, #function
.align 8
sys_mmap:
{
setwd wsz=8, nfx=1
setbn rsz=3, rbs=4, rcur=0
sdisp %ctpr1, 0x3
nop 2
}
{
addd,0 0, NR_mmap, %b[0]
addd,1 0, %r0, %b[1]
addd,2 0, %r1, %b[2]
addd,3 0, %r2, %b[3]
addd,4 0, %r3, %b[4]
addd,5 0, %r4, %b[5]
}
{
addd,1 0, %r5, %b[6]
call %ctpr1, wbs=4
}
{
return %ctpr3
addd,0 0, %b[0], %r0
nop 5
}
{
ct %ctpr3
}
.size sys_mmap, . - sys_mmap

View File

@ -5,12 +5,9 @@
# define __iset__ 1
#endif
#define NR_exit 1
#define NR_write 4
#define NR_mmap 90
#define NR_rt_sigaction 174
#define NR_rt_sigreturn 173
#define NR_access_hw_stacks 254
#define PAGE_SIZE 4096
#include "common/syscall_nr.h"
#define SCRATCH_REG0 %g23
#define SCRATCH_REG1 %g22
@ -90,58 +87,6 @@
sys_exit 77
.endm
#define PAGE_SIZE 4096
#define MAP_SHARED 0x000001
#define MAP_PRIVATE 0x000002
#define MAP_SHARED_VALIDATE 0x000003
#define MAP_ANONYMOUS 0x000010 /* don't use a file */
#define MAP_FIXED 0x000100 /* Interpret addr exactly */
#define MAP_DENYWRITE 0x000800 /* ETXTBSY */
#define MAP_GROWSDOWN 0x001000 /* stack-like segment */
#define MAP_GROWSUP 0x002000 /* register stack-like segment */
#define MAP_EXECUTABLE 0x004000 /* mark it as an executable */
#define MAP_LOCKED 0x008000 /* pages are locked */
#define MAP_NORESERVE 0x010000 /* don't check for reservations */
#define MAP_POPULATE 0x020000 /* populate (prefault) pagetables */
#define MAP_NONBLOCK 0x040000 /* do not block on IO */
#define MAP_FIRST32 0x080000 /* in protected mode map in */
/* first 2 ** 32 area */
#define MAP_WRITECOMBINED 0x100000 /* Write combine */
#define MAP_HUGETLB 0x200000 /* create a huge page mapping */
#define MAP_FIXED_NOREPLACE 0x400000 /* MAP_FIXED which doesn't unmap */
/* underlying mapping */
#define MAP_STACK MAP_GROWSDOWN
#define PROT_READ 0x1 /* page can be read */
#define PROT_WRITE 0x2 /* page can be written */
#define PROT_EXEC 0x4 /* page can be executed */
#define PROT_SEM 0x8 /* page may be used for atomic ops */
#define PROT_NONE 0x0 /* page can not be accessed */
.macro sys_mmap ret, addr, len, prot, flags, fd=-1, offset=0
{
setwd wsz=8, nfx=1
setbn rsz=3, rbs=4, rcur=0
sdisp %ctpr1, 0x3
}
addd,0 0, NR_mmap, %b[0]
{
addd,0 0, \addr, %b[1]
addd,1 0, \len, %b[2]
}
{
addd,0 0, \prot, %b[3]
addd,1 0, \flags, %b[4]
}
{
addd,0 0, \fd, %b[5]
addd,1 0, \offset, %b[6]
}
call %ctpr1, wbs=4
addd,0 0, %b[0], \ret
.endm
#define write(MSG) \
.pushsection ".rodata"; \
local(str):; \

View File

@ -0,0 +1,49 @@
#ifndef COMMON_MMAP_H
#define COMMON_MMAP_H
#include "common/syscall_nr.h"
#define MAP_SHARED 0x000001
#define MAP_PRIVATE 0x000002
#define MAP_SHARED_VALIDATE 0x000003
#define MAP_ANONYMOUS 0x000010 /* don't use a file */
#define MAP_FIXED 0x000100 /* Interpret addr exactly */
#define MAP_DENYWRITE 0x000800 /* ETXTBSY */
#define MAP_GROWSDOWN 0x001000 /* stack-like segment */
#define MAP_GROWSUP 0x002000 /* register stack-like segment */
#define MAP_EXECUTABLE 0x004000 /* mark it as an executable */
#define MAP_LOCKED 0x008000 /* pages are locked */
#define MAP_NORESERVE 0x010000 /* don't check for reservations */
#define MAP_POPULATE 0x020000 /* populate (prefault) pagetables */
#define MAP_NONBLOCK 0x040000 /* do not block on IO */
#define MAP_FIRST32 0x080000 /* in protected mode map in */
/* first 2 ** 32 area */
#define MAP_WRITECOMBINED 0x100000 /* Write combine */
#define MAP_HUGETLB 0x200000 /* create a huge page mapping */
#define MAP_FIXED_NOREPLACE 0x400000 /* MAP_FIXED which doesn't unmap */
/* underlying mapping */
#define MAP_STACK MAP_GROWSDOWN
#define PROT_READ 0x1 /* page can be read */
#define PROT_WRITE 0x2 /* page can be written */
#define PROT_EXEC 0x4 /* page can be executed */
#define PROT_SEM 0x8 /* page may be used for atomic ops */
#define PROT_NONE 0x0 /* page can not be accessed */
#define sys_mmap(ret, addr, len, prot, flags) \
{ \
disp %ctpr1, sys_mmap; \
addd,0 0, addr, %b[0]; \
addd,1 0, len, %b[1]; \
} \
{ \
addd,0 0, prot, %b[2]; \
addd,1 0, flags, %b[3]; \
subd,2 0, 1, %b[4]; \
addd,3 0, 0, %b[5]; \
nop 3 \
} \
call %ctpr1, wbs=4; \
addd,0 0, %b[0], ret
#endif // COMMON_MMAP_H

View File

@ -0,0 +1,11 @@
#ifndef COMMON_SYSCALL_NR_H
#define COMMON_SYSCALL_NR_H
#define NR_exit 1
#define NR_write 4
#define NR_mmap 90
#define NR_rt_sigaction 174
#define NR_rt_sigreturn 173
#define NR_access_hw_stacks 254
#endif // COMMON_SYSCALL_NR_H

View File

@ -1,3 +1,5 @@
#include "common/mmap.h"
#include "test_start.S"
#ifndef MIN_VER
@ -11,9 +13,9 @@
#if __iset__ >= MIN_VER && __iset__ < MAX_VER
setwd wsz=8, nfx=0
sys_mmap %r0, 0, PAGE_SIZE * 3, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS
sys_mmap(%r0, 0, PAGE_SIZE * 3, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS)
addd,0 %r0, PAGE_SIZE, %r0
sys_mmap %r0, %r0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED
sys_mmap(%r0, %r0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED)
subd,0 0, 1, %r1
stb,2 %r1, [ %r0 ]

View File

@ -1,3 +1,5 @@
#include "common/mmap.h"
#include "test_start.S"
#ifndef MIN_VER
@ -11,9 +13,9 @@
#if __iset__ >= MIN_VER && __iset__ < MAX_VER
setwd wsz=8, nfx=0
sys_mmap %r0, 0, PAGE_SIZE * 3, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS
sys_mmap(%r0, 0, PAGE_SIZE * 3, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS)
addd,0 %r0, PAGE_SIZE, %r0
sys_mmap %r0, %r0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED
sys_mmap(%r0, %r0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED)
subd,0 0, 1, %r1
stb,2 %r1, [ %r0 ]