Skip to content

Commit

Permalink
Release 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
elnv committed Nov 22, 2023
1 parent 11503b8 commit e885de8
Show file tree
Hide file tree
Showing 20 changed files with 4,814 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This project includes the current released version of the **IVM64 C/C++** compil

Also it provides an assembler (```ivm64-as```) to translate the _assembly executable_ produced by the compiler to binary.

The last version is **ivm64-3.1**, which is based on **GNU CC v12.2.0**. It is suitable for the ivm64 architecture 2.0 (ivm v2.0).
The last version is **ivm64-3.2**, which is based on **GNU CC v12.2.0**. It is suitable for the ivm64 architecture 2.0 (ivm v2.0).

## Features <a name="features"></a>

Expand Down
110 changes: 110 additions & 0 deletions gcc-12.2.0-ivm64/gcc/config/ivm64/README-ivmfs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# IVM Filesystem

## Introduction
This static filesystem generator allows to recreate a read/write
in-ram file system for testing the ivm64 ecosystem.

By invoking the script ```ivm64-fsgen``` with the list of files to include in the filesystem,
it will print to stdout a C code with the file contents and some primitives
(open, read, lseek, ...) to access the files:

```ivm64-fsgen file1.c file2.c ... > ivmfs.c```

Note that files or directories are added individually to the filesystem and, therefore, to add a folder recursively you may wish to do:

```ivm64-fsgen $(find folder_name) ... > ivmfs.c```


## Compiling

Once the filesystem is generate, you can link a program with the generated C containing the filesystem, so that the primitives included in it will replace those of newlib, therefore enabling to access the
files in a stardard way:

```ivm64-gcc ivmfs.c main.c ``` ``` #compile ivmfs.c before libraries```

where main.c can be like this:
```
main(){
FILE *f = fopen("file1.txt", "r");
int n = fread(buff, 1, 5, f);
...
}
```
## Directories

By default the current work directory of the generated ivm filesystem is ```/work```. In this way, when it is invoked ```ivm64-fsgen filename```, with ```filename``` a file in the current work directory, it will be mapped in the ivm filesystem with the path ```/work/filename```.

The initial working directory is therefore ```/work``` (except when there are no files coming from the current directory in which case the working directory may be ```/```).

On the other hand, if the file name is an absolute path, the path is considered part of the name, and the corresponding directories are (re)created. So when you use ```ivm64-fsgen /path/to/file```, the file can be opened as ```open("/path/to/file",...)```, or alternatively, you can do ```chdir("/path/to"); open("file", ...)```.

Here is an example of the mapping:
```sh
# The following code generates this ivmfs tree:
# /
# ├── etc
# │   └── services
# └── work
# ├── d
# │   └── file2
# └── file1
cd /tmp/
touch file1
mkdir d
touch d/file2
# Let's include some files in the current directory and another absolute path:
# file1, d/file2 are relative to the working directory: mapped to /work
# /etc/services is absolute
ivm64-fsgen file1 d/file2 /etc/services > ivmfs.c

```


## Standard input

By default, the operations on the _standard input_ proceed with the current standard input of the console where the simulator is executed. The same happens with _standard_ and _error output_ streams.

Nevertheless, the stdin can be simulated using the file defined by the macro STDIN_FILE ("stdin" by default). In this case, if a program requires the _standard input_, it will use the content of "stdin". Basically the file STDIN_FILE is redirected to the standard input (if included in the filesystem). To this end, this script should be invoked as:

```ivm64-fsgen stdin file1.c file2.c ... > ivmfs.c ```


## Compilation options

```ivm64-gcc -DIVMFS_DEBUG ivmfs.c ... # print information for each file operation ```

```ivm64-gcc -DIVMFS_DUMPFILES ivmfs.c ... # dump a list of files when the program exits ```

```ivm64-gcc -DIVMFS_DUMPFILECONTENTS ivmfs.c ... # dump the contents of all files when the program exits ```



## Coverage

This is a list of low-level primitives that are supported:
```
open openat close read write lseek
stat fstat lstat fstatat access faccessat
getcwd get_current_dir_name isatty
truncate ftruncate
mkdir mkdirat chdir fchdir getdents
unlink unlinkat rmdir
rename renameat symlink symlinkat dup dup2
readlink readlinkat realpath
```

In addition to these, common higher filesystem functions from the C standard
library implemented by newlib can be used in your C codes, such as:

```
fopen fclose fread fwrite fileno feof
printf scanf fscanf fprintf
opendir readdir scandir dirfd, ...
```

Developers need keep in mind that this filesystem provides a **relaxed** implementation of the primitives, so all the potential described in POSIX manuals may not be available.

Hard links and special file types are not yet supported. File permissions and ownership are not available either.


Date: Nov 2023
73 changes: 72 additions & 1 deletion gcc-12.2.0-ivm64/gcc/config/ivm64/as
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ locallize(){

substcmd_loc5="/${suffix_s}/ s/\(([[:space:]]*\(\(<=\|>=\|>>\|<<\|<\|>\|%\|\/\)\(s\|u\)\)\)${suffix_s}\([^[:alnum:]_\.]\|$\)/\1\5/g"

substcmd_loc_ctor="/^\(\s*EXPORT\s\+\(${Lo}\)\)/ s//#~ \0/g";
substcmd_loc_ctor="/^\(\s*EXPORT\s\+\(${Lo}\)\(\s\+\|$\)\)/ s//#~ \0/g";
fi
substcmd_loc6="s/\([[:space:]]\|=\|:\|)\|]\) /\1/g"

Expand All @@ -154,6 +154,72 @@ locallize(){
fi
}

add_ctor_dtor_signature(){
gawk ' function md5sum(s) {
command="printf \"%s\" \"" s "\" | md5sum"
command | getline l
close(command)
split(l, ll, /[[:space:]]+/)
return ll[1]
}
BEGIN{
cur_fun_name = ""
infun = 0
fundfound = 0
}
/^#:ivm64:#FUNCTION_START/{
infun = 1
funfound = 0
cur_fun_name = ""
}
# Get the name of the function, as the first label after
# "FUNCTION_START" clause
(infun) && (!funfound) && /^\s*[A-Za-z0-9_.]+\s*:\s*$/{
funfound = 1;
split($0, f, / *: */)
cur_fun_name = f[1]
#print "# cur_fun_name='" cur_fun_name "'"
}
# Print and process a NON CTOR/DTOR statements
!/^#:ivm64:#(CTOR|DTOR)/{
print $0
if (cur_fun_name) {
fbody[cur_fun_name] = fbody[cur_fun_name] "\n" $0
}
}
# Print a CTOR/DTOR clause followed by its signature
/^#:ivm64:#(CTOR|DTOR)/{
# input:
# #:ivm64:#CTOR <fun_name> <prio>
# output:
# #:ivm64:#CTOR <fun_name> <prio> <signatura>
split($0, s, / +/);
fname = s[2]
if (fname && fbody[fname]) {
fsig = md5sum(fbody[fname])
} else {
fsig = md5sum(fname)
}
print $1 " " $2 " " $3 " " fsig
}
/^#:ivm64:#FUNCTION_END/{
cur_fun_name = ""
infun = 0
funfound = 0
}
END {
}
' "$@"
}

# First of all check requirements
check_requirements

Expand Down Expand Up @@ -229,6 +295,11 @@ verbose && >&2 echo "OBJECT=$OBJECT | ASM=$ASM | OBJID=$OBJID"
# Assemble
if test -f "$ASM"
then
# Add signature to ctor/dtor clauses if any
ASMTMP="${ASM}_tmp_"
add_ctor_dtor_signature "$ASM" > "$ASMTMP"
mv "$ASMTMP" "$ASM"

# Emulating assembling by copying
echo -n > "$OBJECT"
echo "##:ivm64:obj-id: ${OBJID}" >> "$OBJECT"
Expand Down
Loading

0 comments on commit e885de8

Please sign in to comment.