├── BUILDS
├── LICENSE
├── README.md
├── TODO
├── buildutils.sh
├── compiler
├── addressof.bas
├── arrays.bas
├── cmp.bas
├── div.bas
├── example.bas
├── float.bas
├── func.bas
├── getc.bas
├── hello.bas
├── if.bas
├── include.hb
├── input.bas
├── nativelib.bas
├── preproc.bas
├── readme.txt
├── recur.bas
├── string.bas
├── struct.bas
├── t++.c
├── tbc.c
├── test_func_lib.bas
└── while.bas
├── disasm
├── build.sh
├── cgen.c
├── readme.txt
├── readrex.c
├── rexdump.c
└── rexpack.c
├── docs
├── Building.html
├── CPU.html
├── ConfigureScript.html
├── DynamicLinking.html
├── ExceptionHandling.html
├── Format.html
├── Memory.html
├── Multithreading.html
├── NativeLinking.html
├── Opcodes.html
├── Porting.html
├── REX.html
├── REXCall.html
├── Syscalls.html
├── T++.html
├── data
│ ├── CREDITS.txt
│ ├── background.jpg
│ └── logo.png
├── libR3X.html
└── notes.txt
├── fasm
├── examples
│ ├── elfexe
│ │ ├── dynamic
│ │ │ ├── elf.inc
│ │ │ ├── hello
│ │ │ ├── hello.asm
│ │ │ ├── hello64
│ │ │ ├── hello64.asm
│ │ │ ├── import32.inc
│ │ │ ├── import64.inc
│ │ │ └── proc32.inc
│ │ ├── hello
│ │ ├── hello.asm
│ │ ├── hello64
│ │ └── hello64.asm
│ ├── elfobj
│ │ ├── msgdemo.asm
│ │ ├── msgdemo.o
│ │ ├── writemsg.asm
│ │ └── writemsg.o
│ └── libcdemo
│ │ ├── ccall.inc
│ │ ├── libcdemo.asm
│ │ └── libcdemo.o
├── fasm.txt
├── license.txt
├── source
│ ├── DOS
│ │ ├── fasm.asm
│ │ ├── modes.inc
│ │ └── system.inc
│ ├── Linux
│ │ ├── fasm.asm
│ │ └── system.inc
│ ├── Win32
│ │ ├── fasm.asm
│ │ └── system.inc
│ ├── assemble.inc
│ ├── avx.inc
│ ├── errors.inc
│ ├── exprcalc.inc
│ ├── exprpars.inc
│ ├── formats.inc
│ ├── libc
│ │ ├── fasm.asm
│ │ └── system.inc
│ ├── messages.inc
│ ├── parser.inc
│ ├── preproce.inc
│ ├── symbdump.inc
│ ├── tables.inc
│ ├── variable.inc
│ ├── version.inc
│ └── x86_64.inc
├── tools
│ ├── dos
│ │ ├── listing.asm
│ │ ├── loader.inc
│ │ ├── prepsrc.asm
│ │ ├── symbols.asm
│ │ └── system.inc
│ ├── libc
│ │ ├── ccall.inc
│ │ ├── listing.asm
│ │ ├── prepsrc.asm
│ │ ├── symbols.asm
│ │ └── system.inc
│ ├── listing.inc
│ ├── prepsrc.inc
│ ├── readme.txt
│ ├── symbols.inc
│ └── win32
│ │ ├── listing.asm
│ │ ├── prepsrc.asm
│ │ ├── symbols.asm
│ │ └── system.inc
└── whatsnew.txt
├── llvm
└── lib
│ └── Target
│ ├── R3X
│ └── R3XTargetMachine.cpp
│ └── llvm.txt
├── server
├── build.sh
├── readme.txt
└── server.c
└── src
├── 128x128.png
├── bios.c
├── build.sh
├── cpu.c
├── disassemble.c
├── dispatcher.c
├── dynamic.c
├── exception.c
├── font.c
├── format.c
├── garbagecollector.c
├── graphics.c
├── include
├── big_endian.h
├── nt_malloc.h
├── r3x_bios.h
├── r3x_checksum_generator.h
├── r3x_cpu.h
├── r3x_disassemble.h
├── r3x_dispatcher.h
├── r3x_dynamic.h
├── r3x_exception.h
├── r3x_format.h
├── r3x_garbage_collector.h
├── r3x_graphics.h
├── r3x_memory.h
├── r3x_native.h
├── r3x_object.h
├── r3x_opcode_table.h
├── r3x_opcodes.h
├── r3x_pack.h
├── r3x_script.h
├── r3x_stack.h
├── r3x_stacktrace.h
├── r3x_stream.h
├── r3x_version.h
├── system.h
└── win32
│ ├── dbghelp.h
│ └── dlfcn.h
├── lib
├── gl
│ ├── gl.bas
│ ├── rxgl.c
│ └── rxgl.h
├── include
│ ├── nt_malloc.h
│ └── virtual-machine.h
├── ntmalloc
│ └── nt_malloc.c
├── rstdlib
│ ├── include
│ │ └── rstdlib.h
│ ├── ircbot.bas
│ ├── readme.txt
│ ├── rmath.c
│ ├── rsocket.c
│ ├── rstdlib.c
│ └── stdlibtest.bas
└── rxvmlib
│ └── rxvmlib.c
├── main.c
├── memory.c
├── native.c
├── object.c
├── packageloader.c
├── programs
├── args.il
├── asshole.il
├── bios.il
├── dynamiclib.il
├── example.il
├── exception.il
├── hello.il
├── jmp.il
├── libR3X
│ ├── corelib.pkg
│ ├── dynR3X.pkg
│ ├── libR3X.pkg
│ ├── r3x_asm.pkg
│ └── simplelib.pkg
├── math.il
├── mylib.c
├── nativelib.il
├── overflow.il
├── perf.il
├── r3x_ex.il
├── rfc.il
├── simplelib.il
├── stack.il
├── stream.il
├── symbols.exe
└── symbols.il
├── rfc.c
├── script.c
├── stack.c
├── stream.c
└── win32
└── dlfcn.c
/BUILDS:
--------------------------------------------------------------------------------
1 | Builds with the following compilers:
2 | gcc 4.8.1
3 | gcc 4.8.2
4 | gcc 4.9.0
5 | gcc 4.9.1
6 | gcc 5.1.0
7 | clang 3.5
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 Benderx2,
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | * Neither the name of R3X nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 | NOTE:
30 |
31 | The files src/win32/dlfcn.c and src/include/win32/dlfcn.h have been taken from
32 | github.com/dlfcn-win32/dlfcn-win32
33 |
34 | The file src/inclue/win32/dbghelp.h has been taken from mingw64's headers.
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | R3X Virtual Machine
2 | ===
3 | A virtual machine which functions as a portable runtime for applications.
4 | Please see: http://benderx2.github.io/R3X/ for more information
5 | 
6 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | TODO: Stuff that needs to be done
2 | HI = High priority, ME = Medium, LO = Low.
3 | [HI] 1. Remove shitty build.sh and use a proper build system.
4 | [LO] 2. Remove useless comments
5 | [ME] 3. Don't USE redundant typecasts
6 | [ME] 4. Proper whitespacing
7 | [X] 5. Remove 'r3x_' prefix from source files -- Fixed
8 | [X] 6. Make typecasting mechanism local. -- Fixed
9 | [HI] 7. Print errors to stderr not to stdout.
10 | [HI] 8. 'fopen' returns null on not just file ceasing to exist. Add a proper message
11 | [ME] 9. Stop using different case styles, use either normal_case, CamelCase, or cameCase.
12 | [X] 10. Use something like a debug macro, to fix nt_malloc_init -- Fixed
13 | [LO] 11. Stop using swear words.
14 | [X] 12. Stop using multiple printfs --- Fixed
15 | [ME] 13. Fix identation
16 | [HI] 14. Remove useless 'else' statements
17 | [LO] 15. Remove offensive error messages (Keep it down)
18 | [HI] 16. Use a standard header for endianess (), remove big_endian.h
19 | [Too high to describe] 17. Write standard-compliant code.
20 | [X] 18. Rewrite include guards, to not use reserved prefixes. -- Fixed
21 | [HI] 19. Rewrite big_endian.h to use
22 | [HI] 20. Remove all references to R3X_BIG_ENDIAN, and use a common function to read a 32-bit integer from memory.
23 | [ME] 21. Show message for big endian machines too. Use a common function to read as above. -- Partially Fixed
24 | [HI] 22. Remove the little malloc wrapper. It's problematic.
25 | [ME] 23. Remove /fasm/ directory and use git's submodule system to link it to fasm's repository.
26 | [HI] 24. Use strdup() instead of manually using malloc to create duplicate of strings
27 | [ME] 25. Remove useless binaries from /src/ directory.
28 | [ME] 26. Use the current directory, (and not the executable directory) for devenv.
29 | [HI] 27. Don't use strncmp for comparision, since it works without error on things like ("helpppppppp" instead of showing an error message)
30 | [HI] 28. Update "r3x_version.h" to simply have 1 name for all architectures, use standard functions to detect system rather than manually specifying it.
31 | [Too high to describe] 29. Improve code overall, try to make it more readable, at the same time run with decent performance.
32 | [X] 30. Exit on not receiving arguments --> Fixed.
33 | [HI] 31. Use size_t instead of 'int' while comparing return values from strlen.
34 | [X] 32. Add license headers in each file. Maybe remove the license in "help" option too. -- Fixed
35 | [X] 33. Add a stack overflow check. --Fixed
36 | Thanks to guys at #osdev for these suggestions!
37 | Want to report something? Head to the issues section.
38 |
--------------------------------------------------------------------------------
/buildutils.sh:
--------------------------------------------------------------------------------
1 | # Build utilites for R3X
2 | export CC=gcc
3 | cd disasm
4 | ./build.sh
5 | mv ./readrex $PREFIX
6 | mv ./rexdump $PREFIX
7 | mv ./cgen $PREFIX
8 | cd ..
9 | cd compiler
10 | $CC -std=gnu99 -g tbc.c -o tbc
11 | $CC -std=gnu99 t++.c -o t++ -D RX_PREFIX="\"$PREFIX\""
12 | mv ./tbc $PREFIX
13 | mv ./t++ $PREFIX
14 | cd ../src
15 | cd programs
16 | cp -r ./libR3X/ $PREFIX
17 | cd ..
18 | cd ..
19 | cd $PREFIX
20 | mkdir -p include
21 | cp -r ../src/lib/rstdlib/include/rstdlib.h ./include/
22 | export STDLIB_R3X="$PREFIX/include"
23 |
--------------------------------------------------------------------------------
/compiler/addressof.bas:
--------------------------------------------------------------------------------
1 | function x(0)
2 | print "hello, world from x!"
3 | return 0
4 | endf
5 | function y(2)
6 | let FirstArgument = $1
7 | let SecondArgument = $2
8 | print "first arg: "; FirstArgument
9 | print "second arg: "; SecondArgument
10 | return 5
11 | endf
12 | function main(0)
13 | let a = addressof(@x)
14 | let q = addressof(a)
15 | /* Call address a with 0 arguments */
16 | @raw_call(a, 0)
17 | let a = addressof(@y)
18 | /* Call address a with 3 arguments */
19 | let c = @raw_call(a, 2, 15, 27+22)
20 | print "return value from y ="; c
21 | end
22 | endf
23 |
--------------------------------------------------------------------------------
/compiler/arrays.bas:
--------------------------------------------------------------------------------
1 | function main(0)
2 | print "Array stuff00"
3 | goto mylabel
4 | :mylabel
5 | // Allocate 4 bytes for S.
6 | let buffer = alloc(4)
7 | let B=100
8 | // int32_ptr = 32-bit array access, int16_ptr = 16-bit array access, int8_ptr = 8-bit array access
9 | // 122233 = Decimal 0xFFF2FFF = Hex, 0b10101111 = Binary, 0o23339 = Octal
10 | let int32_ptr(buffer) = 1098143098+0xFF
11 | let X = int16_ptr(buffer)
12 | print "(uint16_t)S[0] and (uint32_t)S[0] = "; X, int32_ptr(buffer)
13 | let mystr = "Hello, World!"
14 | let int8_ptr(mystr+13) = 0
15 | print $mystr
16 | let firstvariable = int8_ptr(mystr)
17 | print "first char: "; firstvariable
18 | let S = 0
19 | end
20 | endf
21 |
--------------------------------------------------------------------------------
/compiler/cmp.bas:
--------------------------------------------------------------------------------
1 | function main(0)
2 | let a = (5 <= 8) && (5 := 6)
3 | print "Checking if 5 is less than 8 and 5 is equal to 6 lol. (Should be 0): " ; a
4 | let qvar = 1
5 | let ivar = 3
6 | if((qvar := 1) && (ivar != 2)) goto we_are_cool
7 | end
8 | :we_are_cool
9 | print "we are cool!"
10 | end
11 | endf
12 |
--------------------------------------------------------------------------------
/compiler/div.bas:
--------------------------------------------------------------------------------
1 | function main(0)
2 | print "Testing Division and bitwise"
3 | goto mylabel
4 | print "Testing division"
5 | :mylabel
6 | let X = 21
7 | let Y = 5
8 | let Z = X / Y
9 | let R = X%Y
10 | print "Mod: "; R
11 | print "Div: "; Z
12 | let A = 50 & 2
13 | let Q = left_shift(50, 2)
14 | let C = not(Q)
15 | print "Or: "; A
16 | print "Q, C = "; Q, C
17 | input Y
18 | print "Y = "; Y
19 | print Y
20 | asm "push 0"
21 | asm "exit"
22 | endf
23 |
--------------------------------------------------------------------------------
/compiler/example.bas:
--------------------------------------------------------------------------------
1 | function main(0)
2 | // Fibonacci generator
3 | let I = 1
4 | let X = 1
5 | let Y = 0
6 | while I <= 10
7 | print "FIB: "; I, X
8 |
9 | let Z = X
10 | let X = X + Y
11 | let Y = Z
12 |
13 | let I = I + 1
14 |
15 | endw
16 | asm ".data \{ mystr : db 'Thank You!', 0 \}"
17 | asm "push mystr"
18 | asm "syscall SYSCALL_PUTS"
19 | end
20 | endf
21 |
--------------------------------------------------------------------------------
/compiler/float.bas:
--------------------------------------------------------------------------------
1 | function main(0)
2 | print "floating point test"
3 | // sorry bros and sis, due to this typelessness, you just fkn use different operators.
4 | let A = mul_f(11.5, add_f(30.567, 23.01))
5 | // round off and convert to int32.
6 | let rounded_a = conv_i(A)
7 | // can convert the rounded value back too. tho the mantissa will be lost.
8 | let rounded_a_as_float = conv_f(rounded_a)
9 | // use '%' prefix for print float stuff
10 | print "result of adding 30.567, 23.01 and the multiplying with 11.5 and rounding it off as int32 "; %A, rounded_a
11 | end
12 | endf
13 |
--------------------------------------------------------------------------------
/compiler/func.bas:
--------------------------------------------------------------------------------
1 | /* this is a global variable */
2 | global myglobal
3 | function x(3)
4 | let i = add_f(add_f(2.4, mul_f(3.5, 4.6)), 5.6)
5 | print "float i = "; %i
6 | print "I'm a function take takes 3 args"
7 | let a = $1
8 | print "the number got in the first arg is: "; a
9 | /* NOTE: $2 + 15 is something different than the below
10 | $2 + 15 means load the 17th argument! This is largely different
11 | from load the 2nd argument and add 15! */
12 | let b = $2
13 | let b = b + 15
14 | print "the number got in the second arg + 15 is :"; b
15 | let f = 5
16 | print "f in this scope is: "; f
17 | let a = $3
18 | return a
19 | endf
20 | function add2numbers(2)
21 | let a = $1
22 | let b = $2
23 | return a + b
24 | endf
25 | function subtract2numbers(2)
26 | let a = $1
27 | let b = $2
28 | return a - b
29 | endf
30 | function misc(0)
31 | let f = 0
32 | print "value of global variable"; myglobal
33 | print "f in this scope is"; f
34 | /* Dont FORGET TO RETURN! else cause undefined behaviour lol */
35 | return 0
36 | endf
37 | function main(0)
38 | let myglobal = 5
39 | let xxx = 0
40 | let y_z = 0
41 | let f = 1
42 | @misc()
43 | let c = 24
44 | let retval = @x(100, 200, c * 5 + 2)
45 | print "return value: "; retval
46 | if (retval := c*5+2) goto correct
47 | print "lol, this failed."
48 | end
49 | :correct
50 | print "lol it's right"
51 | print "f in this scope is: "; f
52 | print "adding 2 numbers: 57 and 90+5"
53 | let result = @add2numbers(57, (90+5))
54 | print "result = "; result
55 | print "subtracting 2 numbers: 30 and 10"
56 | let result = @subtract2numbers(30, 10)
57 | print "result = "; result
58 | end
59 | endf
60 |
--------------------------------------------------------------------------------
/compiler/getc.bas:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | function main(0)
4 | print "press a key and this program will react. press Q and it will quit"
5 | let a = 0
6 | :check_key
7 | let a = @r_getc()
8 | if(a := 0) goto check_key
9 | if((a := 'Q') || (a := 'q')) asm "exit"
10 | print "you pressed key no.:"; a
11 | goto check_key
12 | endf
13 |
--------------------------------------------------------------------------------
/compiler/hello.bas:
--------------------------------------------------------------------------------
1 | /* Compile as: t++ -s hello.bas -o hello.exe */
2 | extern (test_func, "test_func.ro", 0)
3 | function main(0)
4 | @test_func()
5 | print "Hello World!"
6 | let a = 5
7 | if ( a := 5 ) print "a is 5!"
8 | print "press any key to continue!"
9 | end
10 | endf
11 |
--------------------------------------------------------------------------------
/compiler/if.bas:
--------------------------------------------------------------------------------
1 | function main(0)
2 | print "If stuff"
3 | // Allocate 256 bytes for buffer
4 | let buffer = alloc(256)
5 | let int16_ptr(buffer) := 0xFF44
6 | if (int8_ptr(buffer) := 0x44) goto yes
7 | print "Uh, error!"
8 | end
9 | :yes
10 | print "Yay, little endian!"
11 | end
12 | endf
13 |
--------------------------------------------------------------------------------
/compiler/include.hb:
--------------------------------------------------------------------------------
1 | #define ADD_X_Y(x, y) (x + y)
2 |
--------------------------------------------------------------------------------
/compiler/input.bas:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | function main(0)
4 | print "Hello, World!"
5 | print "Welcome to my First Program"
6 | print "Type something: (11 characters):"
7 | let string = alloc(12)
8 | input string, 12
9 | print "You typed: "; $string
10 | end
11 | endf
12 |
--------------------------------------------------------------------------------
/compiler/nativelib.bas:
--------------------------------------------------------------------------------
1 | native(myfunc, "./mylib.so", 1)
2 |
3 | function main(0)
4 | print "calling function from mylib.so"
5 | let asshole = @myfunc("Hello, This is the string from the main function!")
6 | print "i got (hopefully that evil number):"; asshole
7 | let myshit = 6 + 322 + 1139
8 | let stuff = myshit * 6
9 | print "stuff: "; stuff
10 | end
11 | endf
12 |
--------------------------------------------------------------------------------
/compiler/preproc.bas:
--------------------------------------------------------------------------------
1 | #include "include.hb"
2 | function main(0)
3 | print "I'm a preprocessor test!"
4 | let resultofexpr = ADD_X_Y(20, 50)
5 | end
6 | endf
7 |
--------------------------------------------------------------------------------
/compiler/readme.txt:
--------------------------------------------------------------------------------
1 | See docs/BASIC.html
2 |
--------------------------------------------------------------------------------
/compiler/recur.bas:
--------------------------------------------------------------------------------
1 | function factorial(1)
2 | let number = $1
3 | if (number <= 1) goto func_return
4 | return number*@factorial(number-1)
5 | :func_return
6 | return 1
7 | endf
8 |
9 | function main(0)
10 | let fact = @factorial(9)
11 | print "factorial of 9: "; fact
12 | end
13 | endf
14 |
--------------------------------------------------------------------------------
/compiler/string.bas:
--------------------------------------------------------------------------------
1 | function strlen(1)
2 | let i = 0
3 | let s = $1
4 | while (int8_ptr(s+i) != 0)
5 | let i = i+1
6 | endw
7 | return i
8 | endf
9 | function strcpy(2)
10 | let Source = $1
11 | let Destination = $2
12 | let i = 0
13 | while(1)
14 | print "lulz"
15 | if(int8_ptr(Source+i) := 0) goto finish
16 | let int8_ptr(Destination+i) = int8_ptr(Source+i)
17 | let i = i + 1
18 | endw
19 | :finish
20 | return 0
21 | endf
22 | function strcmp(2)
23 | let str01 = $1
24 | let str02 = $2
25 | let i = 0
26 | if (@strlen(str01) != @strlen(str02)) return 1
27 | while(i <= @strlen(str01))
28 | let a = int8_ptr(str01+i)
29 | let b = int8_ptr(str02+i)
30 | print a
31 | print b
32 | if ((int8_ptr(str01+i)) != (int8_ptr(str02+i))) return 1
33 | let i = i + 1
34 | endw
35 | return 0
36 | endf
37 | function main(0)
38 | let strlen_ = @strlen("hello")
39 | print strlen_
40 | let is_equal_or_not = @strcmp("hello", "hello")
41 | if (is_equal_or_not := 0) goto yay
42 | print "string doesnt work"; is_equal_or_not
43 | end
44 | :yay
45 | print "string works"
46 | let x = @strlen("hello")
47 | let x = alloc(7)
48 | @strcpy("hello", x)
49 | print "strcpy: "; x
50 | print $x
51 | end
52 | endf
53 |
--------------------------------------------------------------------------------
/compiler/struct.bas:
--------------------------------------------------------------------------------
1 | #define exec_load_addr 0x100000
2 | struct mystruct(1)
3 | int32 header
4 | ends
5 | struct mystruct02(3)
6 | int8 member1
7 | int16 member2
8 | int32 member3
9 | ends
10 | function main(0)
11 | let myvar = alloc(sizeof(mystruct02))
12 | let [struct mystruct02]myvar.member1 = 0x34
13 | let [struct mystruct02]myvar.member2 = 32768
14 | let [struct mystruct02]myvar.member3 = 0xDEADBEEF
15 | if ([struct mystruct](exec_load_addr).header := 0xBA5EBA11) goto success
16 | print "not loaded using compliant header"
17 | end
18 | :success
19 | print "compliant header detected!"
20 | print "size of mystruct02: "; sizeof(mystruct02)
21 | print "member 1 ="; [struct mystruct02]myvar.member1
22 | print "member 2 ="; [struct mystruct02]myvar.member2
23 | print "member 3 ="; [struct mystruct02]myvar.member3
24 | end
25 | endf
26 |
--------------------------------------------------------------------------------
/compiler/test_func_lib.bas:
--------------------------------------------------------------------------------
1 | /* Compile as: t++ -s test_func_lib.bas -o test_func.ro -d */
2 | function addnumbers(2)
3 | let A = $1
4 | let B = $2
5 | let C = A+B
6 | return C
7 | endf
8 | function test_func(0)
9 | print "hello, world from ro!"
10 | let num = @addnumbers(58,62)
11 | print "result: "; num
12 | return 0
13 | endf
14 |
--------------------------------------------------------------------------------
/compiler/while.bas:
--------------------------------------------------------------------------------
1 | function main(0)
2 | let X = 0x0
3 | while (X <= 5)
4 | print "Doing a while loop till 5 "; X
5 | let X = X+1
6 | endw
7 | end
8 | endf
9 |
--------------------------------------------------------------------------------
/disasm/build.sh:
--------------------------------------------------------------------------------
1 | export CC='gcc'
2 | export CFLAGS='-Wall -Wextra -std=gnu99 -I../src/include'
3 | $CC $CFLAGS rexdump.c -o rexdump
4 | $CC $CFLAGS readrex.c -o readrex
5 | $CC $CFLAGS cgen.c -o cgen
6 |
--------------------------------------------------------------------------------
/disasm/cgen.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include "../src/include/r3x_format.h"
6 | #include "../src/include/r3x_checksum_generator.h"
7 | char* ExecutableName = NULL;
8 |
9 | void ParseArguments(int argc, char* argv[]);
10 |
11 | int main(int argc, char* argv[]) {
12 | ParseArguments(argc, argv);
13 | if(ExecutableName==NULL) {
14 | printf("Pass -h option for help\n");
15 | exit(0);
16 | }
17 | FILE* InputFile = fopen(ExecutableName, "r+b");
18 | if(InputFile == NULL) {
19 | fprintf(stderr, "cgen: cannot open: %s\n", ExecutableName);
20 | exit(0);
21 | }
22 | fseek(InputFile, 0L, SEEK_END);
23 | unsigned int FileSize = ftell(InputFile);
24 | fseek(InputFile, 0L, SEEK_SET);
25 | uint8_t* FileBuf = malloc(FileSize+1);
26 | if(fread(FileBuf, sizeof(uint8_t), FileSize, InputFile)!=FileSize){
27 | fprintf(stderr, "cgen: unable to read %u bytes from file: %s\n", FileSize, ExecutableName);
28 | exit(0);
29 | }
30 | r3x_header_t* Header = (r3x_header_t*)&FileBuf[0];
31 | if(Header->checksum != 0) {
32 | fprintf(stderr, "Error: Checksum already exists\n");
33 | exit(0);
34 | }
35 | fseek(InputFile, offsetof(r3x_header_t, checksum), SEEK_SET);
36 | uint32_t CRC32Checksum = GenerateChecksumCRC32(FileBuf, FileSize);
37 | fwrite(&CRC32Checksum, sizeof(uint32_t), 1, InputFile);
38 | printf("Generated checksum: %u\n", CRC32Checksum);
39 | printf("Checksum written to file\n");
40 | return 0;
41 | }
42 | void ParseArguments(int argc, char* argv[]) {
43 | int i = 0;
44 | for(i = 0; i < argc; i++) {
45 | if(!strcmp(argv[i], "-exe")) {
46 | if(i+1 < argc) {
47 | ExecutableName = argv[i+1];
48 | } else {
49 | printf("-exe option: Executable not specified\n");
50 | }
51 | } else if(!strcmp(argv[i], "-h")) {
52 | printf("cgen - Checksum generator for R3X programs.\n");
53 | printf("Generates a CRC32 checksum for an R3X executable\n");
54 | printf("Usage: cgen -exe \n");
55 | exit(0);
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/disasm/readme.txt:
--------------------------------------------------------------------------------
1 | This folder contains a couple of tools for the R3X Virtual Machine.
2 | There are three files in this directory:
3 | readrex.c - Useful for reading and parsing headers of shared libraries/executables
4 | rexdump.c - Useful for disassembling executables (shared libraries not currently supported)
5 | cgen.c - Generates a checksum of the executable, the checksum generated uses crc32 and hence is not cryptographically
6 | secure.
7 | Pass the '-h' option to the program for help.
8 |
--------------------------------------------------------------------------------
/disasm/rexpack.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/disasm/rexpack.c
--------------------------------------------------------------------------------
/docs/Building.html:
--------------------------------------------------------------------------------
1 | ```html
2 |
3 |
4 |
5 |
6 |
12 |
13 |
REX Virtual Machine Documentation
14 |
Building and running the Virtual Machine
15 | REX uses a bash script ("src/build.sh"), to configure and compile itself.
16 | In order to build it properly on your system, follow the instructions below:
17 | 1. Please ensure you've a bash (or compatible) shell for your host system.
18 | 2. Install the GNU C compiler. (For ARM the compiler is the arm-linux-gnueabi suite)
19 | 3. Next install the required libraries: libSDL, libSDL_ttf, and OpenGL for the target
20 | 4. With the 0.71b build script, you can simply build using
21 |
24 | Here is the description of what you may need to modify in the build script for non-developmental purposes
25 |
export TARGET="ARCHNAME"
26 | Replace "ARCHNAME" with the name of your target architecture
27 | Current options are:
28 | x86_32 - 32-bit x86 Linux
29 | x86_64 - 64-bit x86 Linux
30 | aarch64 - 64-bit ARM (little endian) Linux
31 | aarch64-big - 64-bit ARM (big endian) Linux
32 | ppc - 32/64-bit PPC Linux (Depending upon toolchain)
33 |
export USEGL="yes"
34 | Set to empty ("") if you don't want to use graphical features of REX (note: This currently has bugs, especially with multithreading, which need to be fixed)
35 |
export USEDYNAMIC="yes"
36 | Set to empty ("") if you don't want to use dynamic linking with native libraries for REX.
37 |
export USEOPTIMIZE="yes"
38 | Set to empty ("") if you don't want to use internal untested optimizations. (Required pthread support)
39 |
export OFLAGS="-O2"
40 | Optimization flags, set to -O0 for no optimization, -O3 for better optimization
41 |
export DFLAGS="-g"
42 | Set to empty ("") if you don't want debugging information in the binary
43 | 5. From the command line, run build.sh (with executable permissions)
44 | 6. The binary must be in /bin64, /bin32, /binAARCH64, depending upon target
45 | 7. "cd" to the directory, and run with: ./rxvm.out -exe [name of exe]
46 | You can also use the "-f" option to specify frequency in Kilohertz (KHz) like this: -f 1.5
47 |
Options
48 | There are a few options that can be used while invoking the VM, here is a list of them:
49 |
-exe [exename]
50 | Specifies the executable file to be used
51 |
-stack [stack size]
52 | Specifies the number of 32-bit integers that the stack is allowed to hold
53 |
-h, --help
54 | Displays licensing information and help
55 |
-f [frequency]
56 | Specifies what frequency to use in Kilohertz. The CPU runs in real time if no frequency is given. (ONLY IF COMPILED WITH -D R_DEBUG)
57 |
-s
58 | Runs the VM in client mode. NOTE: Should only be used by servers while invoking the VM.
59 |
-w
60 | Specify width of screen while using VM. Should be divisible by 16. (Works only if compiled with REX_GRAPHICS)
61 |
-h
62 | Specify height of screen while using VM. Should be divisible by 16. (Works only if compiled with REX_GRAPHICS)
63 |
-fo
64 | Specifiy a bitmap font in PNG format.
65 |
-fh
66 | Specify font height
67 |
-fw
68 | Specify font width
69 |
-fs
70 | Specify font scale [Floating Point Number]
71 |
-args "arguments"
72 | Specify program arguments
73 |
-rs scriptname
74 | Specify R3X configure script. (NOTE: The command line options will be overwritten by the scripts' ones')
75 |
56 | (NOTE: The "end:" is not needed, but is recommended.)
57 |
58 | You can also use enviroment variables in strings, for example executable: "$EXEC_FILE_NAME" will set the executable to the enviroment variable
59 | pointed by "EXEC_FILE_NAME".
60 |
--------------------------------------------------------------------------------
/docs/DynamicLinking.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
REX Virtual Machine Documentation
13 |
Dynamic Linking
14 |
15 |
Using the REX dynamic linker
16 |
REX Object format (*.ro)
17 | The REX Object format is used by REX shared libraries to export functions to a REX executable
18 | The header is defined in src/r3x_dynamic.h:11<
19 |
30 | TODO: Add description.
31 |
Your first dynamic library
32 | Writing a dynamic library is easy, here's an example:
33 |
34 | include 'libR3X/dynR3X.inc'
35 | .text {
36 | function test_func
37 | ; Dynamically loaded libraries must
38 | ; be relocatable that is, position independent.
39 | loadr R1, str01
40 | ; Load address of library is in R20
41 | addrr R1, R20
42 | pushr R1
43 | syscall SYSCALL_PUTS
44 | pop
45 | loadr R0, word_data
46 | addrr R0, R20
47 | lodsw
48 | pushr R1
49 | syscall SYSCALL_PUTI
50 | pop
51 | push 0xA
52 | syscall SYSCALL_PUTCH
53 | pop
54 | ; Return back!
55 | ret
56 | endfunction test_func
57 | .data {
58 | str01: db 'Hello from dynamic library! I can read stuff from addresses! word_data=', 0
59 | word_data: dw 65532
60 | dd 0xFFF3FFFF
61 | }
62 | end
63 |
64 | Your code must be position-independent as shown above! As you see, R20 is the "physical" address where your
65 | library is loaded, you should add R20 to all internal address references before doing a load/store operation,
66 | as shown above.
67 |
OPTION 1: Manually load the library and execute it:
68 |
Loading a dynamic library
69 | Loading a dynamic library is simple, simply do:
70 | pushstring "lib.ro"
71 | syscall SYSCALL_LOADDYNAMIC
72 |
73 | The library's handle will be pushed to stack. Make SURE to store it! Since this will be used to call functions.
74 |
The calldynamic instruction
75 | The calldynamic instruction is used to call a function from a library. Use it like this:
76 |
77 | push [library handle] -- Handle that you got from the above syscall
78 | pushstring [function name] -- "test_func" for the above example.
79 | calldynamic
80 |
91 | The library will be loaded automatically by the VM, and you won't have to store and do crazy things manually!
92 |
--------------------------------------------------------------------------------
/docs/ExceptionHandling.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
REX Virtual Machine Documentation
13 |
Exception Handling
14 | Exception Handling in the REX architecture is in it's very early stages, however
15 | it is fully functional.
16 |
Kinds of exceptions
17 | As of now, there are 3 types of exceptions that can be handled, they are given below
18 | INVALID_ACCESS - Invalid Memory Access
19 | INVALID_OPCODE - Invalid Instruction
20 | INVALID_ARITH - Invalid arithmetic operation (usually a divide by 0)
21 | R_EXCEP - Program defined exception
22 |
Handling Exceptions
23 | Exceptions can be handled by assigning them with specific handlers, using the "catch" instruction.
24 | Example Usage:
25 |
32 | The INVALID_ACCESS/INVALID_OPCODE exceptions are caused when a program does an invalid memory access or
33 | executes an unknown instruction. But there are a third type of exception as shown above: "R_EXCEP"
34 | The 'throw' instruction is used to intentionally cause an exception. Example usage show below:
35 |
40 | One advice would be to 'pop' out the exception ID at the start of the handler, which would make the error_code at the top of stack.
41 | An example is shown in src/programs/exception.asm
42 |
The 'handle' instruction
43 | The 'handle' instruction informs the CPU that the exception has been handled successfully. When an exception is thrown, the CPU
44 | sets the Exception Flag (EXF) to true. This means that any exception that is caused when the exception flag is set to true, would
45 | make the VM shutdown. This helps when the exception handlers themselves are bogus.
46 | Before resuming execution, the exception handler, must execute the 'handle' instruction, which sets the exception flag to false.
47 | If you fail to do this, the VM would simply shutdown with a "bad handler" message, if another exception is caused
48 |
49 |
Stack Overflow
50 | When a program causes a stack overflow exception, the virtual machine will simply return control to the debugger, giving a message
51 | telling the user that the stack has exceeded it's limit. The size of the stack can be specified using the "-stack" option. Please
52 | see the "Building and Running" section about this option. The default stack size of assumed to be 262144 32-bit integers
53 |
54 |
55 |
--------------------------------------------------------------------------------
/docs/Memory.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
REX Virtual Machine Documentation
13 |
Memory
14 |
Introduction
15 |
16 | When it comes to virtual machines, memory is the first thing that needs to be take care of. Under the REX architecture,
17 | memory can be accessed using several instructions. More information found on the "CPU Instructions" page.
18 |
19 | Since REX is currently a primitive CPU there is no support for virtual memory, and hence all addresses
20 | accessed by the CPU are physical. It would be useful to note however, that the CPU does provide protection against
21 | malicious programs which attempt to access memory outside the allocated region.
22 |
23 |
Stack
24 |
25 | At the core of the REX architecture, lies the stack, a memory region containing data, pushed onto by the program.
26 | The stack is the single unit being responsible for storing data required for arithmetic operations,
27 | system calls, memory operations and so on. Since REX is a more of a stack-based machine (but it does have registers), the
28 | stack is a very important aspect of the CPU, and hence direct access to the stack is prohibited. The stack does not
29 | lie within the application memory. Access to the stack can be done using several instructions: push, pop, pushr, popr, loads etc.
30 | Please see the "CPU Instructions" page about what instructions are used to access the stack.
31 |
32 | The REX CPU uses a totally different stack for return addresses, this ensures that the return address is not corrupted
33 | throughout simple operations which forget to pop out values. Please do note that it is a bad pratice to not pop out used
34 | data after use on the stack, and it wastes memory.
35 |
36 |
Memory Security
37 |
38 | The R3X architecture uses a system of memory "blocks", each block has a total length of 4096 bytes and has an attribute.
39 | The blocks can have one of the following attributes:
40 | 1. RX_EXEC
41 | R3X Execute: This block is executable, it cannot be modified or be read from.
42 | 2. RX_RW
43 | R3X Readable/Writeable: This block is readable/writeable but not executable.
44 | 3. RX_RONLY
45 | R3X Read-Only: This block is read-only, not executable.
46 | 4. RX_NOEXIST:
47 | R3X Non-Existent: Even though this block exists, it has been kept hidden from program. It is unreadable, unwriteable, and unexecutable
48 | The program's sections are required to be 4096-byte aligned, the VM maps the first 4096 bytes of memory and the program's text section as executable,
49 | while the data, symbol, and bss sections are marked as read-write.
50 | SYSCALL_ALLOC returns a page with attributes RX_RW.
51 | When a dynamic library is loaded, it's text sections are marked as RX_EXEC, and the rest as RX_RW.
52 | Writing to an non-writable section will cause a CPU_INVALID_ACCESS, while executing code in an non-executable will cause an immediate shutdown.
53 |
54 |
Reserved Memory
55 |
56 | The REX architecture reserves all memory under the program load point, and access memory below is considered undefined behaviour. The program load point is implementation defined, however all implementations are required to define
57 | the constant R3_LOAD_POINT as the load address.
58 |
59 | Also, the first 512-bytes are reserved globally, regardless of the implementation, the first 512-bytes MUST be reserved
60 | for the system BIOS.
61 |
14 | The REX CPU supports multithreading through the CPU Dispatcher which dispatches jobs to the CPU's Root Domain.
15 | The CPU's root domain is made up of sub-domains which contain threading information
16 | To dispatch a job to a sub-domain, simply do: (libR3X):
17 |
24 | To exit from a job, use System.Quit, (note that the exit instruction works differently for the "main" domain and other domains, when the main
25 | domain exits all sub-domains are closed, but when a sub-domain exits, no modification is done to the other domains
26 | Planned support for pausing, and exitting tasks from the main domain..
27 |
--------------------------------------------------------------------------------
/docs/NativeLinking.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
REX Virtual Machine Documentation
13 |
Native Linking
14 | REX programs are written in byte code, but can also use native code if required, through shared objects.
15 | This is known as native linking.
16 | The disadvantage of native linking is that the library needs to be rewritten/recompiled for a new platform.
17 | Please note that native linking is an experimental feature, and can be subject to changes in future
18 |
Writing a shared library
19 | First, get a copy of "virtual-machine.h" and "stack.o" located in src/programs/rex.
20 | Then compile r3x_stack.c to an object file.
21 | Then write your library like this:
22 |
37 | Having a start function is mandatory, this will save your CPU pointer which the VM passes, now you can
38 | use this pointer to do operations on the CPU when your function is called.
39 | Compile the library using:
40 |
55 | Or if you use T++, then refer to that page.
56 | An example is given in /src/programs/mylib.c and /src/programs/nativelib.il
57 | (Note that on Windows systems the extension is usually .DLL.)
58 |
59 |
--------------------------------------------------------------------------------
/docs/REX.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
REX Virtual Machine Documentation
13 |
Preface
14 | The sole purpose of this documentation is to give a programmer an idea of how
15 | the REX architecture performs and functions and it's respective goals.
16 | It is also meant to give an overview of the technical aspects of the archi-
17 | -tecture.
18 |
Note: All bit representations in this document are in little-endian format.
19 |
Note2: This document is spefically written for R3X Virtual Machine 0.4.6b BASICPie
14 | The REX Calling convention is the standard convention by which REX programs are supposed to communicate
15 | to external / internal methods.
16 |
17 | For arguments the convention uses the data stack of a domain, the arguments are to be push in ascending order,
18 | that is, the first argument is pushed first, the second is pushed second, and so on.
19 |
20 | For this mechanism to work properly, the caller MUST know the total number of arguments to be given to the method.
21 |
22 | Next, the caller must increment the stack pointer by 4, by pushing 4 registers to the data stack. They can be any 4 out of the 20 registers provided
23 | This is used to preserve registers during the call.
24 |
25 | The return value from the function is stored in R7.
26 | An example is given below (in assembly):
27 |
28 | push 1
29 | push 2
30 | push 3
31 | ; Push 4 items to stack.
32 | ; They can be regs as well, if you want to save their values
33 | push 0
34 | push 0
35 | push 0
36 | push 0
37 |
38 | call add3numbers
39 |
40 | popn 4
41 | ; Pop out the number of args on stack
42 | popn 3
43 | ...
44 | function add3numbers
45 | ; load first argument from stack
46 | loadr R8, 4+3
47 | loadsr R8
48 | loadr R7, R8
49 | ; Load second argument from stack
50 | loadr R8, 4+2
51 | loadsr R8
52 | addrr R7, R8
53 | ; Load third argument from stack
54 | loadr R8, 4+1
55 | loadsr R8
56 | addr R7, R8
57 | ; Return
58 | ret
59 | ...
60 |
14 | The syscall instruction is provided by the CPU, however what it means is totally implementation defined.
15 | Due to this, REX programs will have huge problems while running on different implementations, to solve this problem
16 | the standard defines certain system calls which need to be present in every implementation.
17 | The following system calls are to be defined in every implementation which conforms to the REX standard.
18 | SYSCALL_PUTCH - Print an 8-bit ASCII character pushed to stack to stdout or any other graphics device assumed to be stdout
19 | SYSCALL_PUTS - Print an unformatted string to program's stdout or any other graphics device which is assumed to be stdout.
20 | SYSCALL_PUTI/SYSCALL_PUTF - Print an integer/float pushed to stack to stdout or any other graphics device assumed to be stdout
21 | SYSCALL_GETC - Get a character from stdin or an input device assumed to be stdin.
22 | SYSCALL_ATOI - Convert string which is pointed by the last value pushed to stack, and push the converted value to stack.
23 | SYSCALL_ALLOC - Allocate one page. The size of one segment is implementation defined. All implementations are required to define a constant "R3_SEGMENT_SIZE"
24 | SYSCALL_DISPATCH - Dispatch a background job, whose instruction pointer is pushed to stack.
25 | SYSCALL_LOADDYANMIC - Load a dynamic library and push it's handle.
26 | SYSCALL_OPENSTREAM - Opens a stream, whose name is pushed to stack, and then pushes the file handle to stack.
27 | SYSCALL_SEEKSTREAM - Sets pointer in stream. The arguments are in the following order:
28 |
36 | SYSCALL_TELLSTREAM - Pushes current pointer of a stream whose handle is pushed to stack
37 | SYSCALL_CLOSESTREAM - Closes an open stream whose handle is pushed to stack
38 |
Non standard syscalls
39 | SYSCALL_GETCPUCLOCK - Returns current CPU time (pushes to stack).
40 | SYSCALL_GETCLOCKSPERSEC - Return how many CPU clocks are equivalent to 1 second (pushes to stack)
41 | SYSCALL_GETARGS - Return address of the string which contains program arguments.
42 |
43 |
44 |
--------------------------------------------------------------------------------
/docs/data/CREDITS.txt:
--------------------------------------------------------------------------------
1 | I do not own the "background.jpg" file located in the current directory.
2 | Source: http://www.elegantthemes.com/blog/freebie-of-the-week/20-free-background-images-for-wordpress
3 | As of Thursday 25th December 2014, the page says:
4 | "......These images are released as Open Source under the GPL (GNU General Public License) 2.0......"
5 | Please find a copy of the GPLv2 here: www.gnu.org/licenses/gpl-2.0.html
6 |
7 | "logo.png" file created using cooltext.com.
8 |
--------------------------------------------------------------------------------
/docs/data/background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/docs/data/background.jpg
--------------------------------------------------------------------------------
/docs/data/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/docs/data/logo.png
--------------------------------------------------------------------------------
/docs/libR3X.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
REX Virtual Machine Documentation
13 |
libR3X - REX Standard Library
14 | libR3X is a library provided by the offical REX CPU implementation, it contains useful macro instructions and defines that can used by the
15 | program.
16 | The current implementation provides the following functions:
17 |
18 | Console.Write "String" - Writes an unformatted string to stdout or graphics device assumed to be stdout.
19 | Console.NewLine - Writes a newline character to stdout or graphics device assumed to be stdout.
20 | Console.WriteFloat - Writes an IEEE754 floating point number pushed on stack to stdout or graphics device assumed to be stdout.
21 | Console.WriteInt - Writes a 32-bit integer pushed on stack to stdout or graphics device assumed to be stdout.
22 | Console.WritePointer addr - Write an unformatted string pointer by "addr", to stdout or graphics device assumed to be stdout.
23 | Console.WaitKey - Waits for keypress and returns.
24 | Console.GetInput size, addr - Get input from console into string pointed by "addr", with size "size".
25 | Memcpy dest, src, len - Copies a chunk of memory.
26 | MemcpyR - Copies a chunck of memory but uses registers. R0 = dest, R1 = src, R2 = len
27 | System.AllocatePage - Allocate 1 segment of memory.
28 | System.Quit status - Quit with Status.
29 | Stack.Push, Stack,Pop, Stack.PushRegister, Stack.PopRegister - Class based push, pop, pushr and popr functions.
30 | StoreInt addr, int | StoreByte addr, byte Stores an 8/32-bit value in "int" to address pointed by "addr"
31 | System.DispatchJob jobaddr - Dispatch a job with IP of "jobaddr"
32 |
Constans
33 | libR3X also defines a few constants that the programs can use
34 | SEEK_SET, SEEK_CUR, SEEK_END: Values to be passed to "syscall SYSCALL_SEEKSTREAM"
35 | R_FALSE, R_TRUE: Boolean values.
36 | M_PI, M_E: e and pi constants.
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/docs/notes.txt:
--------------------------------------------------------------------------------
1 | notes: random notes written by me for reference
2 |
3 |
4 | 1. garbage collection:
5 |
6 | i'd like to implement garbage collection as soon as possible, but it's kinda challenging,
7 | because of the design of the virtual machine. firstly, the vm is very simple when it comes
8 | to the instruction set, everything on the stack is just an integer, there are no types or whatever.
9 |
10 | but it would still be possible, if somehow i could update the vm about the state of variables etc.
11 |
12 | the plan would roughly be like:
13 |
14 | --> allocate variable
15 | --> call a specific "function" called gc_add
16 | --> gc_add will add the variable and the pointer to the list
17 | -->
18 |
--------------------------------------------------------------------------------
/fasm/examples/elfexe/dynamic/elf.inc:
--------------------------------------------------------------------------------
1 |
2 | macro Elf32_Sym name,value,size,bind,type,other,shndx
3 | {
4 | dd name+0
5 | dd value+0
6 | dd size+0
7 | db (bind+0) shl 4 + (type+0)
8 | db other+0
9 | dw shndx+0
10 | }
11 |
12 | virtual at 0
13 | Elf32_Sym
14 | sizeof.Elf32_Sym = $
15 | end virtual
16 |
17 | macro Elf32_Rel offset,symbol,type
18 | {
19 | dd offset+0
20 | dd (symbol+0) shl 8 + (type+0)
21 | }
22 |
23 | virtual at 0
24 | Elf32_Rel
25 | sizeof.Elf32_Rel = $
26 | end virtual
27 |
28 | macro Elf32_Rela offset,symbol,type,addend
29 | {
30 | dd offset+0
31 | dd (symbol+0) shl 8 + (type+0)
32 | dd addend+0
33 | }
34 |
35 | virtual at 0
36 | Elf32_Rela
37 | sizeof.Elf32_Rela = $
38 | end virtual
39 |
40 | macro Elf64_Sym name,value,size,bind,type,other,shndx
41 | {
42 | dd name+0
43 | db (bind+0) shl 4 + (type+0)
44 | db other+0
45 | dw shndx+0
46 | dq value+0
47 | dq size+0
48 | }
49 |
50 | virtual at 0
51 | Elf64_Sym
52 | sizeof.Elf64_Sym = $
53 | end virtual
54 |
55 | macro Elf64_Rel offset,symbol,type
56 | {
57 | dq offset+0
58 | dq (symbol+0) shl 32 + (type+0)
59 | }
60 |
61 | virtual at 0
62 | Elf64_Rel
63 | sizeof.Elf64_Rel = $
64 | end virtual
65 |
66 | macro Elf64_Rela offset,symbol,type,addend
67 | {
68 | dq offset+0
69 | dq (symbol+0) shl 32 + (type+0)
70 | dq addend+0
71 | }
72 |
73 | virtual at 0
74 | Elf64_Rela
75 | sizeof.Elf64_Rela = $
76 | end virtual
77 |
78 | DT_NULL = 0
79 | DT_NEEDED = 1
80 | DT_HASH = 4
81 | DT_STRTAB = 5
82 | DT_SYMTAB = 6
83 | DT_RELA = 7
84 | DT_RELASZ = 8
85 | DT_RELAENT = 9
86 | DT_STRSZ = 10
87 | DT_SYMENT = 11
88 | DT_REL = 17
89 | DT_RELSZ = 18
90 | DT_RELENT = 19
91 |
92 | STB_LOCAL = 0
93 | STB_GLOBAL = 1
94 | STB_WEAK = 2
95 |
96 | STT_NOTYPE = 0
97 | STT_OBJECT = 1
98 | STT_FUNC = 2
99 | STT_SECTION = 3
100 | STT_FILE = 4
101 |
102 | R_386_NONE = 0
103 | R_386_32 = 1
104 | R_386_PC32 = 2
105 | R_386_GOT32 = 3
106 | R_386_PLT32 = 4
107 | R_386_COPY = 5
108 | R_386_GLOB_DAT = 6
109 | R_386_JMP_SLOT = 7
110 | R_386_RELATIVE = 8
111 | R_386_GOTOFF = 9
112 | R_386_GOTPC = 10
113 |
114 | R_X86_64_NONE = 0
115 | R_X86_64_64 = 1
116 | R_X86_64_PC32 = 2
117 | R_X86_64_GOT32 = 3
118 | R_X86_64_PLT32 = 4
119 | R_X86_64_COPY = 5
120 | R_X86_64_GLOB_DAT = 6
121 | R_X86_64_JUMP_SLOT = 7
122 | R_X86_64_RELATIVE = 8
123 | R_X86_64_GOTPCREL = 9
124 | R_X86_64_32 = 10
125 | R_X86_64_32S = 11
126 | R_X86_64_16 = 12
127 | R_X86_64_PC16 = 13
128 | R_X86_64_8 = 14
129 | R_X86_64_PC8 = 15
130 | R_X86_64_DPTMOD64 = 16
131 | R_X86_64_DTPOFF64 = 17
132 | R_X86_64_TPOFF64 = 18
133 | R_X86_64_TLSGD = 19
134 | R_X86_64_TLSLD = 20
135 | R_X86_64_DTPOFF32 = 21
136 | R_X86_64_GOTTPOFF = 22
137 | R_X86_64_TPOFF32 = 23
138 | R_X86_64_PC64 = 24
139 | R_X86_64_GOTOFF64 = 25
140 | R_X86_64_GOTPC32 = 26
141 |
--------------------------------------------------------------------------------
/fasm/examples/elfexe/dynamic/hello:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/fasm/examples/elfexe/dynamic/hello
--------------------------------------------------------------------------------
/fasm/examples/elfexe/dynamic/hello.asm:
--------------------------------------------------------------------------------
1 |
2 | format ELF executable 3
3 | entry start
4 |
5 | include 'import32.inc'
6 | include 'proc32.inc'
7 |
8 | interpreter '/lib/ld-linux.so.2'
9 | needed 'libc.so.6'
10 | import printf,exit
11 |
12 | segment readable executable
13 |
14 | start:
15 | cinvoke printf,msg
16 | cinvoke exit
17 |
18 | segment readable writeable
19 |
20 | msg db 'Hello world!',0xA,0
21 |
--------------------------------------------------------------------------------
/fasm/examples/elfexe/dynamic/hello64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/fasm/examples/elfexe/dynamic/hello64
--------------------------------------------------------------------------------
/fasm/examples/elfexe/dynamic/hello64.asm:
--------------------------------------------------------------------------------
1 |
2 | format ELF64 executable 3
3 | entry start
4 |
5 | include 'import64.inc'
6 |
7 | interpreter '/lib64/ld-linux-x86-64.so.2'
8 | needed 'libc.so.6'
9 | import printf,exit
10 |
11 | segment readable executable
12 |
13 | start:
14 |
15 | lea rdi,[msg]
16 | xor eax,eax
17 | call [printf]
18 |
19 | call [exit]
20 |
21 | segment readable writeable
22 |
23 | msg db 'Hello world!',0xA,0
24 |
--------------------------------------------------------------------------------
/fasm/examples/elfexe/dynamic/import32.inc:
--------------------------------------------------------------------------------
1 |
2 | include 'elf.inc'
3 |
4 | macro interpreter [library]
5 | {
6 | segment interpreter readable
7 | db library,0
8 | }
9 |
10 | macro needed [library]
11 | {
12 | local str
13 | match needed,needed@dynamic \{ define needed@dynamic needed,str:library \}
14 | match ,needed@dynamic \{ define needed@dynamic str:library \}
15 | }
16 | define needed@dynamic
17 |
18 | macro import [name]
19 | {
20 | common
21 | local strtab,strsz,symtab,rel,relsz,hash
22 | segment dynamic readable
23 | match needed,needed@dynamic
24 | \{ irp item,needed \\{ match str:library,item \\\{ dd DT_NEEDED,str-strtab \\\} \\} \}
25 | dd DT_STRTAB,strtab
26 | dd DT_STRSZ,strsz
27 | dd DT_SYMTAB,symtab
28 | dd DT_SYMENT,sizeof.Elf32_Sym
29 | dd DT_REL,rel
30 | dd DT_RELSZ,relsz
31 | dd DT_RELENT,sizeof.Elf32_Rel
32 | dd DT_HASH,hash
33 | dd DT_NULL,0
34 | segment readable writeable
35 | symtab: Elf32_Sym
36 | forward
37 | local fstr
38 | Elf32_Sym fstr-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
39 | common
40 | rel:
41 | local counter
42 | counter = 1
43 | forward
44 | Elf32_Rel name,counter,R_386_32
45 | counter = counter+1
46 | common
47 | relsz = $-rel
48 | hash:
49 | dd 1,counter
50 | dd 0
51 | repeat counter
52 | if %=counter
53 | dd 0
54 | else
55 | dd %
56 | end if
57 | end repeat
58 | strtab db 0
59 | forward
60 | fstr db `name,0
61 | common
62 | match needed,needed@dynamic
63 | \{ irp item,needed \\{ match str:library,item \\\{ str db library,0 \\\} \\} \}
64 | strsz = $-strtab
65 | forward
66 | name dd 0
67 | }
68 |
--------------------------------------------------------------------------------
/fasm/examples/elfexe/dynamic/import64.inc:
--------------------------------------------------------------------------------
1 |
2 | include 'elf.inc'
3 |
4 | macro interpreter [library]
5 | {
6 | segment interpreter readable
7 | db library,0
8 | }
9 |
10 | macro needed [library]
11 | {
12 | local str
13 | match needed,needed@dynamic \{ define needed@dynamic needed,str:library \}
14 | match ,needed@dynamic \{ define needed@dynamic str:library \}
15 | }
16 | define needed@dynamic
17 |
18 | macro import [name]
19 | {
20 | common
21 | local strtab,strsz,symtab,rel,relsz,hash
22 | segment dynamic readable
23 | match needed,needed@dynamic
24 | \{ irp item,needed \\{ match str:library,item \\\{ dq DT_NEEDED,str-strtab \\\} \\} \}
25 | dq DT_STRTAB,strtab
26 | dq DT_STRSZ,strsz
27 | dq DT_SYMTAB,symtab
28 | dq DT_SYMENT,sizeof.Elf64_Sym
29 | dq DT_RELA,rela
30 | dq DT_RELASZ,relasz
31 | dq DT_RELAENT,sizeof.Elf64_Rela
32 | dq DT_HASH,hash
33 | dq DT_NULL,0
34 | segment readable writeable
35 | symtab: Elf64_Sym
36 | forward
37 | local fstr
38 | Elf64_Sym fstr-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
39 | common
40 | rela:
41 | local counter
42 | counter = 1
43 | forward
44 | Elf64_Rela name,counter,R_X86_64_64
45 | counter = counter+1
46 | common
47 | relasz = $-rela
48 | hash:
49 | dd 1,counter
50 | dd 0
51 | repeat counter
52 | if %=counter
53 | dd 0
54 | else
55 | dd %
56 | end if
57 | end repeat
58 | strtab db 0
59 | forward
60 | fstr db `name,0
61 | common
62 | match needed,needed@dynamic
63 | \{ irp item,needed \\{ match str:library,item \\\{ str db library,0 \\\} \\} \}
64 | strsz = $-strtab
65 | forward
66 | name dq 0
67 | }
68 |
--------------------------------------------------------------------------------
/fasm/examples/elfexe/hello:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/fasm/examples/elfexe/hello
--------------------------------------------------------------------------------
/fasm/examples/elfexe/hello.asm:
--------------------------------------------------------------------------------
1 |
2 | ; fasm demonstration of writing simple ELF executable
3 |
4 | format ELF executable 3
5 | entry start
6 |
7 | segment readable executable
8 |
9 | start:
10 |
11 | mov eax,4
12 | mov ebx,1
13 | mov ecx,msg
14 | mov edx,msg_size
15 | int 0x80
16 |
17 | mov eax,1
18 | xor ebx,ebx
19 | int 0x80
20 |
21 | segment readable writeable
22 |
23 | msg db 'Hello world!',0xA
24 | msg_size = $-msg
25 |
--------------------------------------------------------------------------------
/fasm/examples/elfexe/hello64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/fasm/examples/elfexe/hello64
--------------------------------------------------------------------------------
/fasm/examples/elfexe/hello64.asm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/fasm/examples/elfexe/hello64.asm
--------------------------------------------------------------------------------
/fasm/examples/elfobj/msgdemo.asm:
--------------------------------------------------------------------------------
1 |
2 | ; fasm demonstration of assembling object files
3 |
4 | ; compile the program using commands like:
5 | ; fasm msgdemo.asm msgdemo.o
6 | ; fasm writemsg.asm writemsg.o
7 | ; ld msgdemo.o writemsg.o -o msgdemo
8 |
9 | format ELF
10 |
11 | section '.text' executable
12 |
13 | public _start
14 | _start:
15 |
16 | extrn writemsg
17 |
18 | mov esi,msg
19 | call writemsg
20 |
21 | mov eax,1
22 | xor ebx,ebx
23 | int 0x80
24 |
25 | section '.data' writeable
26 |
27 | msg db "Elves are coming!",0xA,0
28 |
--------------------------------------------------------------------------------
/fasm/examples/elfobj/msgdemo.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/fasm/examples/elfobj/msgdemo.o
--------------------------------------------------------------------------------
/fasm/examples/elfobj/writemsg.asm:
--------------------------------------------------------------------------------
1 |
2 | format ELF
3 |
4 | section '.text' executable
5 |
6 | public writemsg
7 |
8 | writemsg:
9 | mov ecx,esi
10 | find_end:
11 | lodsb
12 | or al,al
13 | jnz find_end
14 | mov edx,esi
15 | sub edx,ecx
16 | mov eax,4
17 | mov ebx,1
18 | int 0x80
19 | ret
20 |
--------------------------------------------------------------------------------
/fasm/examples/elfobj/writemsg.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/fasm/examples/elfobj/writemsg.o
--------------------------------------------------------------------------------
/fasm/examples/libcdemo/ccall.inc:
--------------------------------------------------------------------------------
1 |
2 | macro ccall proc,[arg]
3 | { common
4 | local size
5 | size = 0
6 | mov ebp,esp
7 | if ~ arg eq
8 | forward
9 | size = size + 4
10 | common
11 | sub esp,size
12 | end if
13 | and esp,-16
14 | if ~ arg eq
15 | add esp,size
16 | reverse
17 | pushd arg
18 | common
19 | end if
20 | call proc
21 | mov esp,ebp }
22 |
23 |
--------------------------------------------------------------------------------
/fasm/examples/libcdemo/libcdemo.asm:
--------------------------------------------------------------------------------
1 |
2 | ; fasm example of using the C library in Unix systems
3 |
4 | ; compile the source with commands like:
5 | ; fasm libcdemo.asm libcdemo.o
6 | ; gcc libcdemo.o -o libcdemo
7 | ; strip libcdemo
8 |
9 | format ELF
10 |
11 | include 'ccall.inc'
12 |
13 | section '.text' executable
14 |
15 | public main
16 | extrn printf
17 | extrn getpid
18 |
19 | main:
20 | call getpid
21 | ccall printf, msg,eax
22 | ret
23 |
24 | section '.data' writeable
25 |
26 | msg db "Current process ID is %d.",0xA,0
27 |
--------------------------------------------------------------------------------
/fasm/examples/libcdemo/libcdemo.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Benderx2/R3X/f45118d3d9b5c462dc45121742d6e514b1bfe3ed/fasm/examples/libcdemo/libcdemo.o
--------------------------------------------------------------------------------
/fasm/license.txt:
--------------------------------------------------------------------------------
1 |
2 | flat assembler version 1.71
3 | Copyright (c) 1999-2013, Tomasz Grysztar.
4 | All rights reserved.
5 |
6 | This program is free for commercial and non-commercial use as long as
7 | the following conditions are adhered to.
8 |
9 | Copyright remains Tomasz Grysztar, and as such any Copyright notices
10 | in the code are not to be removed.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are
14 | met:
15 |
16 | 1. Redistributions of source code must retain the above copyright notice,
17 | this list of conditions and the following disclaimer.
18 | 2. Redistributions in binary form must reproduce the above copyright
19 | notice, this list of conditions and the following disclaimer in the
20 | documentation and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | The licence and distribution terms for any publically available
35 | version or derivative of this code cannot be changed. i.e. this code
36 | cannot simply be copied and put under another distribution licence
37 | (including the GNU Public Licence).
38 |
--------------------------------------------------------------------------------
/fasm/source/messages.inc:
--------------------------------------------------------------------------------
1 |
2 | ; flat assembler core
3 | ; Copyright (c) 1999-2014, Tomasz Grysztar.
4 | ; All rights reserved.
5 |
6 | _out_of_memory db 'out of memory',0
7 | _stack_overflow db 'out of stack space',0
8 | _main_file_not_found db 'source file not found',0
9 | _unexpected_end_of_file db 'unexpected end of file',0
10 | _code_cannot_be_generated db 'code cannot be generated',0
11 | _format_limitations_exceeded db 'format limitations exceeded',0
12 | _invalid_definition db 'invalid definition provided',0
13 | _write_failed db 'write failed',0
14 | _file_not_found db 'file not found',0
15 | _error_reading_file db 'error reading file',0
16 | _invalid_file_format db 'invalid file format',0
17 | _invalid_macro_arguments db 'invalid macro arguments',0
18 | _incomplete_macro db 'incomplete macro',0
19 | _unexpected_characters db 'unexpected characters',0
20 | _invalid_argument db 'invalid argument',0
21 | _illegal_instruction db 'illegal instruction',0
22 | _invalid_operand db 'invalid operand',0
23 | _invalid_operand_size db 'invalid size of operand',0
24 | _operand_size_not_specified db 'operand size not specified',0
25 | _operand_sizes_do_not_match db 'operand sizes do not match',0
26 | _invalid_address_size db 'invalid size of address value',0
27 | _address_sizes_do_not_agree db 'address sizes do not agree',0
28 | _disallowed_combination_of_registers db 'disallowed combination of registers',0
29 | _long_immediate_not_encodable db 'not encodable with long immediate',0
30 | _relative_jump_out_of_range db 'relative jump out of range',0
31 | _invalid_expression db 'invalid expression',0
32 | _invalid_address db 'invalid address',0
33 | _invalid_value db 'invalid value',0
34 | _value_out_of_range db 'value out of range',0
35 | _undefined_symbol db 'undefined symbol',0
36 | _symbol_out_of_scope_1 db 'symbol',0
37 | _symbol_out_of_scope_2 db 'out of scope',0
38 | _invalid_use_of_symbol db 'invalid use of symbol',0
39 | _name_too_long db 'name too long',0
40 | _invalid_name db 'invalid name',0
41 | _reserved_word_used_as_symbol db 'reserved word used as symbol',0
42 | _symbol_already_defined db 'symbol already defined',0
43 | _missing_end_quote db 'missing end quote',0
44 | _missing_end_directive db 'missing end directive',0
45 | _unexpected_instruction db 'unexpected instruction',0
46 | _extra_characters_on_line db 'extra characters on line',0
47 | _section_not_aligned_enough db 'section is not aligned enough',0
48 | _setting_already_specified db 'setting already specified',0
49 | _data_already_defined db 'data already defined',0
50 | _too_many_repeats db 'too many repeats',0
51 | _invoked_error db 'error directive encountered in source file',0
52 | _assertion_failed db 'assertion failed',0
53 |
--------------------------------------------------------------------------------
/fasm/source/variable.inc:
--------------------------------------------------------------------------------
1 |
2 | ; flat assembler core variables
3 | ; Copyright (c) 1999-2014, Tomasz Grysztar.
4 | ; All rights reserved.
5 |
6 | ; Variables which have to be set up by interface:
7 |
8 | memory_start dd ?
9 | memory_end dd ?
10 |
11 | additional_memory dd ?
12 | additional_memory_end dd ?
13 |
14 | stack_limit dd ?
15 |
16 | input_file dd ?
17 | output_file dd ?
18 | symbols_file dd ?
19 |
20 | passes_limit dw ?
21 |
22 | ; Internal core variables:
23 |
24 | current_pass dw ?
25 |
26 | include_paths dd ?
27 | free_additional_memory dd ?
28 | source_start dd ?
29 | code_start dd ?
30 | code_size dd ?
31 | real_code_size dd ?
32 | written_size dd ?
33 | headers_size dd ?
34 |
35 | current_line dd ?
36 | macro_line dd ?
37 | macro_block dd ?
38 | macro_block_line dd ?
39 | macro_block_line_number dd ?
40 | macro_symbols dd ?
41 | struc_name dd ?
42 | struc_label dd ?
43 | instant_macro_start dd ?
44 | parameters_end dd ?
45 | locals_counter rb 8
46 | current_locals_prefix dd ?
47 | anonymous_reverse dd ?
48 | anonymous_forward dd ?
49 | labels_list dd ?
50 | label_hash dd ?
51 | label_leaf dd ?
52 | hash_tree dd ?
53 | addressing_space dd ?
54 | undefined_data_start dd ?
55 | undefined_data_end dd ?
56 | counter dd ?
57 | counter_limit dd ?
58 | error_info dd ?
59 | error_line dd ?
60 | error dd ?
61 | tagged_blocks dd ?
62 | structures_buffer dd ?
63 | number_start dd ?
64 | current_offset dd ?
65 | value dq ?
66 | fp_value rd 8
67 | adjustment dq ?
68 | symbol_identifier dd ?
69 | address_symbol dd ?
70 | address_high dd ?
71 | format_flags dd ?
72 | resolver_flags dd ?
73 | symbols_stream dd ?
74 | number_of_relocations dd ?
75 | number_of_sections dd ?
76 | stub_size dd ?
77 | stub_file dd ?
78 | current_section dd ?
79 | machine dw ?
80 | subsystem dw ?
81 | subsystem_version dd ?
82 | image_base dd ?
83 | image_base_high dd ?
84 | resource_data dd ?
85 | resource_size dd ?
86 | actual_fixups_size dd ?
87 | reserved_fixups dd ?
88 | reserved_fixups_size dd ?
89 | last_fixup_base dd ?
90 | last_fixup_header dd ?
91 | parenthesis_stack dd ?
92 | blocks_stack dd ?
93 | parsed_lines dd ?
94 | logical_value_parentheses dd ?
95 | file_extension dd ?
96 |
97 | operand_size db ?
98 | size_override db ?
99 | operand_prefix db ?
100 | opcode_prefix db ?
101 | rex_prefix db ?
102 | vex_required db ?
103 | vex_register db ?
104 | immediate_size db ?
105 |
106 | base_code db ?
107 | extended_code db ?
108 | supplemental_code db ?
109 | postbyte_register db ?
110 | segment_register db ?
111 | xop_opcode_map db ?
112 |
113 | mmx_size db ?
114 | jump_type db ?
115 | push_size db ?
116 | value_size db ?
117 | address_size db ?
118 | label_size db ?
119 | size_declared db ?
120 |
121 | value_undefined db ?
122 | value_constant db ?
123 | value_type db ?
124 | value_sign db ?
125 | fp_sign db ?
126 | fp_format db ?
127 | address_sign db ?
128 | compare_type db ?
129 | logical_value_wrapping db ?
130 | next_pass_needed db ?
131 | output_format db ?
132 | code_type db ?
133 | adjustment_sign db ?
134 |
135 | macro_status db ?
136 | default_argument_value db ?
137 | prefixed_instruction db ?
138 | formatter_symbols_allowed db ?
139 | free_address_range db ?
140 |
141 |
142 | characters rb 100h
143 | converted rb 100h
144 | message rb 200h
145 |
--------------------------------------------------------------------------------
/fasm/source/version.inc:
--------------------------------------------------------------------------------
1 |
2 | ; flat assembler version 1.71
3 | ; Copyright (c) 1999-2014, Tomasz Grysztar.
4 | ; All rights reserved.
5 | ;
6 | ; This programs is free for commercial and non-commercial use as long as
7 | ; the following conditions are adhered to.
8 | ;
9 | ; Redistribution and use in source and binary forms, with or without
10 | ; modification, are permitted provided that the following conditions are
11 | ; met:
12 | ;
13 | ; 1. Redistributions of source code must retain the above copyright notice,
14 | ; this list of conditions and the following disclaimer.
15 | ; 2. Redistributions in binary form must reproduce the above copyright
16 | ; notice, this list of conditions and the following disclaimer in the
17 | ; documentation and/or other materials provided with the distribution.
18 | ;
19 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 | ; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 | ; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
23 | ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 | ; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | ; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | ; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | ;
31 | ; The licence and distribution terms for any publically available
32 | ; version or derivative of this code cannot be changed. i.e. this code
33 | ; cannot simply be copied and put under another distribution licence
34 | ; (including the GNU Public Licence).
35 |
36 | VERSION_STRING equ "1.71.22"
37 |
38 | VERSION_MAJOR = 1
39 | VERSION_MINOR = 71
40 |
--------------------------------------------------------------------------------
/fasm/tools/dos/loader.inc:
--------------------------------------------------------------------------------
1 |
2 | segment loader use16
3 |
4 | init:
5 |
6 | mov ax,1687h
7 | int 2Fh
8 | or ax,ax ; DPMI installed?
9 | jnz short no_dpmi
10 | test bl,1 ; 32-bit programs supported?
11 | jz short no_dpmi
12 | mov word [cs:mode_switch],di
13 | mov word [cs:mode_switch+2],es
14 | mov bx,si ; allocate memory for DPMI data
15 | mov ah,48h
16 | int 21h
17 | jnc init_protected_mode
18 | init_failed:
19 | call init_error
20 | db 'error: DPMI initialization failed.',0Dh,0Ah,0
21 | no_dpmi:
22 | call init_error
23 | db 'error: 32-bit DPMI services are not available.',0Dh,0Ah,0
24 | init_error:
25 | pop si
26 | push cs
27 | pop ds
28 | display_error:
29 | lodsb
30 | test al,al
31 | jz short error_finish
32 | mov dl,al
33 | mov ah,2
34 | int 21h
35 | jmp short display_error
36 | error_finish:
37 | mov ax,4CFFh
38 | int 21h
39 | init_protected_mode:
40 | mov es,ax
41 | mov ds,[ds:2Ch]
42 | mov ax,1
43 | call far [cs:mode_switch] ; switch to protected mode
44 | jc init_failed
45 | mov cx,1
46 | xor ax,ax
47 | int 31h ; allocate descriptor for code
48 | jc init_failed
49 | mov si,ax
50 | xor ax,ax
51 | int 31h ; allocate descriptor for data
52 | jc init_failed
53 | mov di,ax
54 | mov dx,cs
55 | lar cx,dx
56 | shr cx,8
57 | or cx,0C000h
58 | mov bx,si
59 | mov ax,9
60 | int 31h ; set code descriptor access rights
61 | jc init_failed
62 | mov dx,ds
63 | lar cx,dx
64 | shr cx,8
65 | or cx,0C000h
66 | mov bx,di
67 | int 31h ; set data descriptor access rights
68 | jc init_failed
69 | mov ecx,main
70 | shl ecx,4
71 | mov dx,cx
72 | shr ecx,16
73 | mov ax,7
74 | int 31h ; set data descriptor base address
75 | jc init_failed
76 | mov bx,si
77 | int 31h ; set code descriptor base address
78 | jc init_failed
79 | mov cx,0FFFFh
80 | mov dx,0FFFFh
81 | mov ax,8 ; set segment limit to 4 GB
82 | int 31h
83 | jc init_failed
84 | mov bx,di
85 | int 31h
86 | jc init_failed
87 | mov ax,ds
88 | mov ds,di
89 | mov [psp_selector],es
90 | mov [environment_selector],ax
91 | cli
92 | mov ss,di
93 | mov esp,stack_top
94 | sti
95 | mov es,di
96 | xor eax,eax
97 | mov [memory_handles_count],eax
98 | push si
99 | push start
100 | retf
101 |
102 | mode_switch dd ?
103 |
--------------------------------------------------------------------------------
/fasm/tools/dos/prepsrc.asm:
--------------------------------------------------------------------------------
1 |
2 | format MZ
3 | heap 0
4 | stack 8000h
5 | entry loader:init
6 |
7 | include 'loader.inc'
8 |
9 | segment main use32
10 |
11 | start:
12 |
13 | call get_params
14 | jnc make_dump
15 |
16 | mov esi,_usage
17 | call display_string
18 | mov ax,4C02h
19 | int 21h
20 |
21 | make_dump:
22 | call preprocessed_source
23 | mov ax,4C00h
24 | int 21h
25 |
26 | error:
27 | mov esi,_error_prefix
28 | call display_string
29 | pop esi
30 | call display_string
31 | mov esi,_error_suffix
32 | call display_string
33 | mov ax,4C00h
34 | int 21h
35 |
36 | get_params:
37 | push ds
38 | mov ds,[psp_selector]
39 | mov esi,81h
40 | mov edi,params
41 | find_param:
42 | lodsb
43 | cmp al,20h
44 | je find_param
45 | cmp al,0Dh
46 | je all_params
47 | or al,al
48 | jz all_params
49 | cmp [es:input_file],0
50 | jne get_output_file
51 | mov [es:input_file],edi
52 | jmp process_param
53 | get_output_file:
54 | cmp [es:output_file],0
55 | jne bad_params
56 | mov [es:output_file],edi
57 | process_param:
58 | cmp al,22h
59 | je string_param
60 | copy_param:
61 | stosb
62 | lodsb
63 | cmp al,20h
64 | je param_end
65 | cmp al,0Dh
66 | je param_end
67 | or al,al
68 | jz param_end
69 | jmp copy_param
70 | string_param:
71 | lodsb
72 | cmp al,22h
73 | je string_param_end
74 | cmp al,0Dh
75 | je param_end
76 | or al,al
77 | jz param_end
78 | stosb
79 | jmp string_param
80 | bad_params_value:
81 | stc
82 | ret
83 | param_end:
84 | dec esi
85 | string_param_end:
86 | xor al,al
87 | stosb
88 | jmp find_param
89 | all_params:
90 | xor al,al
91 | stosb
92 | pop ds
93 | cmp [input_file],0
94 | je bad_params
95 | cmp [output_file],0
96 | je bad_params
97 | clc
98 | ret
99 | bad_params:
100 | stc
101 | ret
102 |
103 | include 'system.inc'
104 |
105 | include '..\prepsrc.inc'
106 |
107 | _usage db 'preprocessed source dumper for flat assembler',0Dh,0Ah
108 | db 'usage: prepsrc