Started to provide an example posix HALCODE interface on the pattern
of AMD64 Linux syscalls
This commit is contained in:
parent
5493a77697
commit
50cdb0c046
|
@ -453,13 +453,28 @@ DO NOT USE.
|
||||||
42 hh hh hh is the HALCODE callID, invalid HALCODE SHOULD NOT BE USED.
|
42 hh hh hh is the HALCODE callID, invalid HALCODE SHOULD NOT BE USED.
|
||||||
|
|
||||||
*** HALCODE Reserved for Operating Systems
|
*** 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 |
|
The default reserved Block: 42000000-420FFFFF; however all HALCODEs can be remapped,
|
||||||
|-------------+----------|
|
replaced and repurposed by the Operating system after initialization and you should
|
||||||
| 42 00 xx xx | Reserved |
|
refer to your system documentation from your Operating system provider to know what
|
||||||
| ... | Reserved |
|
mappings have been exposed for use.
|
||||||
| 42 0F xx xx | Reserved |
|
|
||||||
|
**** 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
|
*** Tape console HALCODE
|
||||||
This HALCODE is used for interacting with any tape console attached to the system.
|
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 |
|
| ... | Reserved |
|
||||||
| 42 FF FF FF | Reserved |
|
| 42 FF FF FF | Reserved |
|
||||||
|
|
||||||
|
|
||||||
** Reserved Block 1
|
** Reserved Block 1
|
||||||
At this time these instructions only produce a warning; but could do anything.
|
At this time these instructions only produce a warning; but could do anything.
|
||||||
DO NOT USE.
|
DO NOT USE.
|
||||||
|
|
3
vm.h
3
vm.h
|
@ -94,6 +94,9 @@ struct Instruction
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Prototypes for functions in vm_instructions.c*/
|
/* 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_READ(struct lilith* vm);
|
||||||
void vm_FOPEN_WRITE(struct lilith* vm);
|
void vm_FOPEN_WRITE(struct lilith* vm);
|
||||||
void vm_FCLOSE(struct lilith* vm);
|
void vm_FCLOSE(struct lilith* vm);
|
||||||
|
|
258
vm_decode.c
258
vm_decode.c
|
@ -232,101 +232,193 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c)
|
||||||
char Name[20] = "ILLEGAL_HALCODE";
|
char Name[20] = "ILLEGAL_HALCODE";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch(c->HAL_CODE)
|
if(POSIX_MODE)
|
||||||
{
|
{
|
||||||
case 0x100000: /* fopen_read */
|
switch(c->HAL_CODE)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
case 0x000002: /* fopen */
|
||||||
strncpy(Name, "FOPEN_READ", 19);
|
{
|
||||||
#elif TRACE
|
#ifdef DEBUG
|
||||||
record_trace("FOPEN_READ");
|
strncpy(Name, "FOPEN", 19);
|
||||||
#endif
|
#elif TRACE
|
||||||
|
record_trace("FOPEN");
|
||||||
|
#endif
|
||||||
|
|
||||||
vm_FOPEN_READ(vm);
|
vm_FOPEN(vm);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x100001: /* fopen_write */
|
case 0x000003: /* fclose */
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
strncpy(Name, "FOPEN_WRITE", 19);
|
strncpy(Name, "FCLOSE", 19);
|
||||||
#elif TRACE
|
#elif TRACE
|
||||||
record_trace("FOPEN_WRITE");
|
record_trace("FCLOSE");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vm_FOPEN_WRITE(vm);
|
vm_FCLOSE(vm);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x100002: /* fclose */
|
case 0x000008: /* fseek */
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
strncpy(Name, "FCLOSE", 19);
|
strncpy(Name, "FSEEK", 19);
|
||||||
#elif TRACE
|
#elif TRACE
|
||||||
record_trace("FCLOSE");
|
record_trace("FSEEK");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vm_FCLOSE(vm);
|
vm_FSEEK(vm);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x100003: /* rewind */
|
case 0x00003C: /* EXIT */
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
strncpy(Name, "REWIND", 19);
|
strncpy(Name, "EXIT", 19);
|
||||||
#elif TRACE
|
#elif TRACE
|
||||||
record_trace("REWIND");
|
record_trace("EXIT");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vm_REWIND(vm);
|
vm_EXIT(vm, performance_counter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x100004: /* fseek */
|
case 0x00005A: /* EXIT */
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
strncpy(Name, "FSEEK", 19);
|
strncpy(Name, "CHMOD", 19);
|
||||||
#elif TRACE
|
#elif TRACE
|
||||||
record_trace("FSEEK");
|
record_trace("CHMOD");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vm_FSEEK(vm);
|
vm_CHMOD(vm);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x100100: /* fgetc */
|
case 0x100100: /* fgetc */
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
strncpy(Name, "FGETC", 19);
|
strncpy(Name, "FGETC", 19);
|
||||||
#elif TRACE
|
#elif TRACE
|
||||||
record_trace("FGETC");
|
record_trace("FGETC");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vm_FGETC(vm);
|
vm_FGETC(vm);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x100200: /* fputc */
|
case 0x100200: /* fputc */
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
strncpy(Name, "FPUTC", 19);
|
strncpy(Name, "FPUTC", 19);
|
||||||
#elif TRACE
|
#elif TRACE
|
||||||
record_trace("FPUTC");
|
record_trace("FPUTC");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vm_FPUTC(vm);
|
vm_FPUTC(vm);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid HALCODE\nComputer Program has Halted\n");
|
||||||
|
illegal_instruction(vm, c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case 0x110000: /* HAL_MEM */
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch(c->HAL_CODE)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
case 0x100000: /* fopen_read */
|
||||||
strncpy(Name, "HAL_MEM", 19);
|
{
|
||||||
#elif TRACE
|
#ifdef DEBUG
|
||||||
record_trace("HAL_MEM");
|
strncpy(Name, "FOPEN_READ", 19);
|
||||||
#endif
|
#elif TRACE
|
||||||
|
record_trace("FOPEN_READ");
|
||||||
|
#endif
|
||||||
|
|
||||||
vm_HAL_MEM(vm);
|
vm_FOPEN_READ(vm);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
case 0x100001: /* fopen_write */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Invalid HALCODE\nComputer Program has Halted\n");
|
#ifdef DEBUG
|
||||||
illegal_instruction(vm, c);
|
strncpy(Name, "FOPEN_WRITE", 19);
|
||||||
break;
|
#elif TRACE
|
||||||
|
record_trace("FOPEN_WRITE");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vm_FOPEN_WRITE(vm);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 0x100002: /* fclose */
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
strncpy(Name, "FCLOSE", 19);
|
||||||
|
#elif TRACE
|
||||||
|
record_trace("FCLOSE");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vm_FCLOSE(vm);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 0x100003: /* rewind */
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
strncpy(Name, "REWIND", 19);
|
||||||
|
#elif TRACE
|
||||||
|
record_trace("REWIND");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vm_REWIND(vm);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 0x100004: /* fseek */
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
strncpy(Name, "FSEEK", 19);
|
||||||
|
#elif TRACE
|
||||||
|
record_trace("FSEEK");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vm_FSEEK(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;
|
||||||
|
}
|
||||||
|
case 0x110000: /* HAL_MEM */
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
strncpy(Name, "HAL_MEM", 19);
|
||||||
|
#elif TRACE
|
||||||
|
record_trace("HAL_MEM");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vm_HAL_MEM(vm);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid HALCODE\nComputer Program has Halted\n");
|
||||||
|
illegal_instruction(vm, c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,40 @@ char* string_copy(struct lilith* vm, signed_vm_register address)
|
||||||
return r;
|
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)
|
void vm_FOPEN_READ(struct lilith* vm)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
Loading…
Reference in New Issue