diff --git a/CHANGELOG.org b/CHANGELOG.org index ab26d99..fb72e1d 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -17,6 +17,8 @@ * Current ** Added Added support for envp in cc_x86.s +Added support for --POSIX-MODE to allow cross-platform testing to be easier +Expanded the disassembler's support of HALCODE to include POSIX instructions ** Changed Reduced stack usage thanks to akkartik diff --git a/High_level_prototypes/disasm.c b/High_level_prototypes/disasm.c index 929b68d..b95b7bb 100644 --- a/High_level_prototypes/disasm.c +++ b/High_level_prototypes/disasm.c @@ -1384,6 +1384,11 @@ void decode_HALCODE(struct Instruction* c) strncpy(Name, "EXIT", 19); break; } + case 0x00003F: /* UNAME */ + { + strncpy(Name, "UNAME", 19); + break; + } case 0x00005A: /* CHMOD */ { strncpy(Name, "CHMOD", 19); diff --git a/ISA_HEX_Map.org b/ISA_HEX_Map.org index c9f1c13..c9db01b 100644 --- a/ISA_HEX_Map.org +++ b/ISA_HEX_Map.org @@ -471,6 +471,7 @@ mappings have been exposed for use. | 42 00 00 03 | FCLOSE | close(int FD) using R0 | | 42 00 00 08 | FSEEK | seek(int FD, off_t OFFSET, int WHENCE) using R0, R1 and R2 respectively | | 42 00 00 3C | EXIT | exit(int ERROR_CODE) using R0 | +| 42 00 00 3F | UNAME | uname(struct utsname* BUF) using R0 | | 42 00 00 5A | CHMOD | chmod(char* PATHNAME, int MODE) using R0 and R1 respectively | |-------------+--------+----------------------------------------------------------------------------| | 42 10 01 00 | FGETC | read 1 byte into register 0 from device who's ID is in register 1 | diff --git a/vm.h b/vm.h index 06cfa0d..37a59f8 100644 --- a/vm.h +++ b/vm.h @@ -29,6 +29,7 @@ typedef __uint256_t unsigned_vm_register; #define umax 256 #define imax 255 #define reg_size 32 +#define arch_name "knight256-base" #elif VM128 typedef __int256_t signed_wide_register; typedef __uint256_t unsigned_wide_register; @@ -37,6 +38,7 @@ typedef __uint128_t unsigned_vm_register; #define umax 128 #define imax 127 #define reg_size 16 +#define arch_name "knight128-base" #elif VM64 typedef __int128_t signed_wide_register; typedef __uint128_t unsigned_wide_register; @@ -45,6 +47,7 @@ typedef uint64_t unsigned_vm_register; #define umax 64 #define imax 63 #define reg_size 8 +#define arch_name "knight64-base" #elif VM32 typedef int64_t signed_wide_register; typedef uint64_t unsigned_wide_register; @@ -53,6 +56,7 @@ typedef uint32_t unsigned_vm_register; #define umax 32 #define imax 31 #define reg_size 4 +#define arch_name "knight32-base" #else typedef int32_t signed_wide_register; typedef uint32_t unsigned_wide_register; @@ -61,6 +65,7 @@ typedef uint16_t unsigned_vm_register; #define umax 16 #define imax 15 #define reg_size 2 +#define arch_name "knight16-base" #endif /* Virtual machine state */ @@ -96,6 +101,7 @@ struct Instruction /* Prototypes for functions in vm_instructions.c*/ void vm_EXIT(struct lilith* vm, uint64_t performance_counter); void vm_CHMOD(struct lilith* vm); +void vm_UNAME(struct lilith* vm); void vm_FOPEN(struct lilith* vm); void vm_FOPEN_READ(struct lilith* vm); void vm_FOPEN_WRITE(struct lilith* vm); diff --git a/vm_decode.c b/vm_decode.c index 733dcad..f4818b0 100644 --- a/vm_decode.c +++ b/vm_decode.c @@ -280,6 +280,17 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) vm_EXIT(vm, performance_counter); break; } + case 0x00003F: /* UNAME */ + { + #ifdef DEBUG + strncpy(Name, "UNAME", 19); + #elif TRACE + record_trace("UNAME"); + #endif + + vm_UNAME(vm); + break; + } case 0x00005A: /* CHMOD */ { #ifdef DEBUG diff --git a/vm_instructions.c b/vm_instructions.c index a390003..138d56e 100644 --- a/vm_instructions.c +++ b/vm_instructions.c @@ -55,6 +55,16 @@ void writeout_bytes(struct lilith* vm, unsigned_vm_register pointer, unsigned_vm } } +void writeout_string(struct lilith* vm, char* s, unsigned_vm_register pointer) +{ + while(0 != s[0]) + { + vm->memory[pointer] = s[0]; + pointer = pointer + 1; + s = s + 1; + } +} + /* Allow the use of native data format for Register operations */ unsigned_vm_register readin_bytes(struct lilith* vm, unsigned_vm_register pointer, bool Signed, int count) { @@ -154,6 +164,15 @@ void vm_CHMOD(struct lilith* vm) free(s); } +void vm_UNAME(struct lilith* vm) +{ + writeout_string(vm, "sysname", vm->reg[0]); + writeout_string(vm, "nodename", vm->reg[0] + 65); + writeout_string(vm, "release", vm->reg[0] + 130); + writeout_string(vm, "version", vm->reg[0] + 195); + writeout_string(vm, arch_name, vm->reg[0] + 260); +} + void vm_FOPEN(struct lilith* vm) { char* s = string_copy(vm, vm->reg[0]);