Started to provide an example posix HALCODE interface on the pattern

of AMD64 Linux syscalls
This commit is contained in:
Jeremiah Orians 2019-03-01 20:24:55 -05:00
parent 5493a77697
commit 50cdb0c046
No known key found for this signature in database
GPG Key ID: 5410E91C14959E87
4 changed files with 233 additions and 90 deletions

View File

@ -453,13 +453,28 @@ DO NOT USE.
42 hh hh hh is the HALCODE callID, invalid HALCODE SHOULD NOT BE USED.
*** HALCODE Reserved for Operating Systems
The following block contains both instructions that are reserved for Operating systems and for internal use by Operating systems
The following block contains both instructions that are reserved for Operating
systems and for internal use by Operating systems. When initialized by the
Operating system, the HALCODEs are tagged with a priviledge mode, if the binary
is not also tagged with permissions for that mode, an illegal instruction trap
occurs when the HALCODE is decoded.
| Hex | Name |
|-------------+----------|
| 42 00 xx xx | Reserved |
| ... | Reserved |
| 42 0F xx xx | Reserved |
The default reserved Block: 42000000-420FFFFF; however all HALCODEs can be remapped,
replaced and repurposed by the Operating system after initialization and you should
refer to your system documentation from your Operating system provider to know what
mappings have been exposed for use.
**** Example posix mapping
| Hex | Name | Comment |
|-------------+--------+----------------------------------------------------------------------------|
| 42 00 00 02 | FOPEN | open(char* FILENAME, int FLAGS, int MODE) using R0, R1 and R2 respectively |
| 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 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 |
| 42 10 02 00 | FPUTC | write 1 byte from register 0 to device who's ID is in register 1 |
*** Tape console HALCODE
This HALCODE is used for interacting with any tape console attached to the system.
@ -539,7 +554,6 @@ The following 3 devices must exist with the following exact IDs
| ... | Reserved |
| 42 FF FF FF | Reserved |
** Reserved Block 1
At this time these instructions only produce a warning; but could do anything.
DO NOT USE.

3
vm.h
View File

@ -94,6 +94,9 @@ 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_FOPEN(struct lilith* vm);
void vm_FOPEN_READ(struct lilith* vm);
void vm_FOPEN_WRITE(struct lilith* vm);
void vm_FCLOSE(struct lilith* vm);

View File

@ -232,6 +232,97 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c)
char Name[20] = "ILLEGAL_HALCODE";
#endif
if(POSIX_MODE)
{
switch(c->HAL_CODE)
{
case 0x000002: /* fopen */
{
#ifdef DEBUG
strncpy(Name, "FOPEN", 19);
#elif TRACE
record_trace("FOPEN");
#endif
vm_FOPEN(vm);
break;
}
case 0x000003: /* fclose */
{
#ifdef DEBUG
strncpy(Name, "FCLOSE", 19);
#elif TRACE
record_trace("FCLOSE");
#endif
vm_FCLOSE(vm);
break;
}
case 0x000008: /* fseek */
{
#ifdef DEBUG
strncpy(Name, "FSEEK", 19);
#elif TRACE
record_trace("FSEEK");
#endif
vm_FSEEK(vm);
break;
}
case 0x00003C: /* EXIT */
{
#ifdef DEBUG
strncpy(Name, "EXIT", 19);
#elif TRACE
record_trace("EXIT");
#endif
vm_EXIT(vm, performance_counter);
break;
}
case 0x00005A: /* EXIT */
{
#ifdef DEBUG
strncpy(Name, "CHMOD", 19);
#elif TRACE
record_trace("CHMOD");
#endif
vm_CHMOD(vm);
break;
}
case 0x100100: /* fgetc */
{
#ifdef DEBUG
strncpy(Name, "FGETC", 19);
#elif TRACE
record_trace("FGETC");
#endif
vm_FGETC(vm);
break;
}
case 0x100200: /* fputc */
{
#ifdef DEBUG
strncpy(Name, "FPUTC", 19);
#elif TRACE
record_trace("FPUTC");
#endif
vm_FPUTC(vm);
break;
}
default:
{
fprintf(stderr, "Invalid HALCODE\nComputer Program has Halted\n");
illegal_instruction(vm, c);
break;
}
}
}
else
{
switch(c->HAL_CODE)
{
case 0x100000: /* fopen_read */
@ -329,6 +420,7 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c)
break;
}
}
}
#ifdef DEBUG
fprintf(stdout, "# %s\n", Name);

View File

@ -134,6 +134,40 @@ char* string_copy(struct lilith* vm, signed_vm_register address)
return r;
}
void vm_EXIT(struct lilith* vm, uint64_t performance_counter)
{
vm->halted = true;
fprintf(stderr, "Computer Program has Halted\nAfter Executing %lu instructions\n", performance_counter);
#ifdef TRACE
record_trace("HALT");
print_traces();
#endif
exit(vm->reg[0]);
}
void vm_CHMOD(struct lilith* vm)
{
char* s = string_copy(vm, vm->reg[0]);
chmod(s, vm->reg[1]);
free(s);
}
void vm_FOPEN(struct lilith* vm)
{
struct stat sb;
char* s = string_copy(vm, vm->reg[0]);
if(-1 == stat(s, &sb))
{
fprintf(stderr, "File named %s does not exist\n", s);
exit(EXIT_FAILURE);
}
vm->reg[0] = open(s, vm->reg[1], vm->reg[2]);
free(s);
}
void vm_FOPEN_READ(struct lilith* vm)
{
struct stat sb;