1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899 |
- /* Copyright (C) 2016 Jeremiah Orians
- * This file is part of stage0.
- *
- * stage0 is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * stage0 is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with stage0. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "vm.h"
- uint64_t performance_counter;
- #ifdef TRACE
- void record_trace(char* c);
- void print_traces();
- #endif
- /* Allocate and intialize memory/state */
- struct lilith* create_vm(size_t size)
- {
- performance_counter = 0;
- struct lilith* vm;
- vm = calloc(1, sizeof(struct lilith));
- vm->memory = calloc(size, sizeof(uint8_t));
- vm->amount_of_Ram = size;
- vm->halted = false;
- vm->exception = false;
- return vm;
- }
- /* Free up the memory we previously allocated */
- void destroy_vm(struct lilith* vm)
- {
- free(vm->memory);
- free(vm);
- }
- /* Validate Memory Addresses*/
- void outside_of_world(struct lilith* vm, unsigned_vm_register place, char* message)
- {
- if(vm->amount_of_Ram <= place)
- {
- fprintf(stderr, "Invalid state reached after: %lu instructions\n", performance_counter);
- fprintf(stderr, "%i: %s\n", place, message);
- vm->halted = true;
- #ifdef TRACE
- record_trace("HALT");
- print_traces();
- #endif
- exit(EXIT_FAILURE);
- }
- }
- /* Deal with illegal instructions and their encodings */
- void illegal_instruction(struct lilith* vm, struct Instruction* c)
- {
- fprintf(stderr, "Invalid instruction was received at address:%08X\n", c->ip);
- fprintf(stderr, "After %lu instructions\n", performance_counter);
- fprintf(stderr, "Unable to execute the following instruction:\n\t%s\n", c->operation);
- c->invalid = true;
- vm->halted = true;
- #ifdef DEBUG
- fprintf(stderr, "Computer Program has Halted\n");
- #endif
- #ifdef TRACE
- record_trace("HALT");
- print_traces();
- #endif
- exit(EXIT_FAILURE);
- }
- /* Deal with 4OP */
- void decode_4OP(struct Instruction* c)
- {
- c->raw_XOP = c->raw1;
- c->XOP[0] = c->operation[2];
- c->XOP[1] = c->operation[3];
- c->raw_Immediate = 0;
- c->reg0 = c->raw2/16;
- c->reg1 = c->raw2%16;
- c->reg2 = c->raw3/16;
- c->reg3 = c->raw3%16;
- }
- /* Deal with 3OP */
- void decode_3OP(struct Instruction* c)
- {
- c->raw_XOP = c->raw1*0x10 + c->raw2/16;
- c->XOP[0] = c->operation[2];
- c->XOP[1] = c->operation[3];
- c->XOP[2] = c->operation[4];
- c->raw_Immediate = 0;
- c->reg0 = c->raw2%16;
- c->reg1 = c->raw3/16;
- c->reg2 = c->raw3%16;
- }
- /* Deal with 2OP */
- void decode_2OP(struct Instruction* c)
- {
- c->raw_XOP = c->raw1*0x100 + c->raw2;
- c->XOP[0] = c->operation[2];
- c->XOP[1] = c->operation[3];
- c->XOP[2] = c->operation[4];
- c->XOP[3] = c->operation[5];
- c->raw_Immediate = 0;
- c->reg0 = c->raw3/16;
- c->reg1 = c->raw3%16;
- }
- /* Deal with 1OP */
- void decode_1OP(struct Instruction* c)
- {
- c->raw_XOP = c->raw1*0x1000 + c->raw2*0x10 + c->raw3/16;
- c->XOP[0] = c->operation[2];
- c->XOP[1] = c->operation[3];
- c->XOP[2] = c->operation[4];
- c->XOP[3] = c->operation[5];
- c->XOP[4] = c->operation[6];
- c->raw_Immediate = 0;
- c->reg0 = c->raw3%16;
- }
- /* Deal with 2OPI */
- void decode_2OPI(struct lilith* vm, struct Instruction* c)
- {
- c->raw_Immediate = (uint8_t)vm->memory[vm->ip];
- vm->ip = vm->ip + 1;
- uint8_t hold = (uint8_t)vm->memory[vm->ip];
- vm->ip = vm->ip + 1;
- c->raw_Immediate = c->raw_Immediate*0x100 + hold;
- c->Immediate[0] = c->operation[4];
- c->Immediate[1] = c->operation[5];
- c->Immediate[2] = c->operation[6];
- c->Immediate[3] = c->operation[7];
- c->reg0 = c->raw3/16;
- c->reg1 = c->raw3%16;
- }
- /* Deal with 1OPI */
- void decode_1OPI(struct lilith* vm, struct Instruction* c)
- {
- c->raw_Immediate = (uint8_t)vm->memory[vm->ip];
- vm->ip = vm->ip + 1;
- uint8_t hold = (uint8_t)vm->memory[vm->ip];
- vm->ip = vm->ip + 1;
- c->raw_Immediate = c->raw_Immediate*0x100 + hold;
- c->Immediate[0] = c->operation[4];
- c->Immediate[1] = c->operation[5];
- c->Immediate[2] = c->operation[6];
- c->Immediate[3] = c->operation[7];
- c->HAL_CODE = 0;
- c->raw_XOP = c->raw3/16;
- c->XOP[0] = c->operation[7];
- c->reg0 = c->raw3%16;
- }
- /* Deal with 0OPI */
- void decode_0OPI(struct Instruction* c)
- {
- c->raw_Immediate = c->raw2*0x100 + c->raw3;
- c->Immediate[0] = c->operation[4];
- c->Immediate[1] = c->operation[5];
- c->Immediate[2] = c->operation[6];
- c->Immediate[3] = c->operation[7];
- c->HAL_CODE = 0;
- c->raw_XOP = c->raw1;
- c->XOP[0] = c->operation[2];
- c->XOP[1] = c->operation[3];
- }
- /* Deal with Halcode */
- void decode_HALCODE(struct Instruction* c)
- {
- c->HAL_CODE = c->raw1*0x10000 + c->raw2*0x100 + c->raw3;
- }
- /* Useful unpacking functions */
- void unpack_byte(uint8_t a, char* c)
- {
- char table[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
- c[0] = table[a / 16];
- c[1] = table[a % 16];
- }
- /* Unpack the full instruction */
- void unpack_instruction(struct Instruction* c)
- {
- unpack_byte(c->raw0, &(c->operation[0]));
- unpack_byte(c->raw1, &(c->operation[2]));
- unpack_byte(c->raw2, &(c->operation[4]));
- unpack_byte(c->raw3, &(c->operation[6]));
- c->opcode[0] = c->operation[0];
- c->opcode[1] = c->operation[1];
- }
- /* Load instruction addressed at IP */
- void read_instruction(struct lilith* vm, struct Instruction *current)
- {
- memset(current, 0, sizeof(struct Instruction));
- /* Store IP for debugging */
- current->ip = vm->ip;
- outside_of_world(vm, current->ip, "READ Instruction outside of World");
- /* Read the actual bytes and increment the IP */
- current->raw0 = (uint8_t)vm->memory[vm->ip];
- vm->ip = vm->ip + 1;
- current->raw1 = (uint8_t)vm->memory[vm->ip];
- vm->ip = vm->ip + 1;
- current->raw2 = (uint8_t)vm->memory[vm->ip];
- vm->ip = vm->ip + 1;
- current->raw3 = (uint8_t)vm->memory[vm->ip];
- vm->ip = vm->ip + 1;
- unpack_instruction(current);
- }
- /* Process HALCODE instructions */
- bool eval_HALCODE(struct lilith* vm, struct Instruction* c)
- {
- #ifdef DEBUG
- char Name[20] = "ILLEGAL_HALCODE";
- #endif
- if(POSIX_MODE)
- {
- switch(c->HAL_CODE)
- {
- case 0x000000: /* sys_read */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_READ", 19);
- #elif TRACE
- record_trace("SYS_READ");
- #endif
- vm_SYS_READ(vm);
- break;
- }
- case 0x000001: /* sys_write */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_WRITE", 19);
- #elif TRACE
- record_trace("SYS_WRITE");
- #endif
- vm_SYS_WRITE(vm);
- break;
- }
- case 0x000002: /* sys_fopen */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_FOPEN", 19);
- #elif TRACE
- record_trace("SYS_FOPEN");
- #endif
- vm_SYS_FOPEN(vm);
- break;
- }
- case 0x000003: /* sys_fclose */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_FCLOSE", 19);
- #elif TRACE
- record_trace("SYS_FCLOSE");
- #endif
- vm_SYS_FCLOSE(vm);
- break;
- }
- case 0x000008: /* sys_fseek */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_FSEEK", 19);
- #elif TRACE
- record_trace("SYS_FSEEK");
- #endif
- vm_SYS_FSEEK(vm);
- break;
- }
- case 0x000015: /* sys_access */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_ACCESS", 19);
- #elif TRACE
- record_trace("SYS_ACCESS");
- #endif
- vm_SYS_ACCESS(vm);
- break;
- }
- case 0x00003C: /* sys_exit */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_EXIT", 19);
- #elif TRACE
- record_trace("SYS_EXIT");
- #endif
- vm_SYS_EXIT(vm, performance_counter);
- break;
- }
- case 0x00003F: /* sys_uname */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_UNAME", 19);
- #elif TRACE
- record_trace("SYS_UNAME");
- #endif
- vm_SYS_UNAME(vm);
- break;
- }
- case 0x00004F: /* sys_getcwd */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_GETCWD", 19);
- #elif TRACE
- record_trace("SYS_GETCWD");
- #endif
- vm_SYS_GETCWD(vm);
- break;
- }
- case 0x000050: /* sys_chdir */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_CHDIR", 19);
- #elif TRACE
- record_trace("SYS_CHDIR");
- #endif
- vm_SYS_CHDIR(vm);
- break;
- }
- case 0x000051: /* sys_fchdir */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_FCHDIR", 19);
- #elif TRACE
- record_trace("SYS_FCHDIR");
- #endif
- vm_SYS_FCHDIR(vm);
- break;
- }
- case 0x00005A: /* sys_chmod */
- {
- #ifdef DEBUG
- strncpy(Name, "SYS_CHMOD", 19);
- #elif TRACE
- record_trace("SYS_CHMOD");
- #endif
- vm_SYS_CHMOD(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 */
- {
- #ifdef DEBUG
- strncpy(Name, "FOPEN_READ", 19);
- #elif TRACE
- record_trace("FOPEN_READ");
- #endif
- vm_FOPEN_READ(vm);
- break;
- }
- case 0x100001: /* fopen_write */
- {
- #ifdef DEBUG
- strncpy(Name, "FOPEN_WRITE", 19);
- #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 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;
- }
- }
- }
- #ifdef DEBUG
- fprintf(stdout, "# %s\n", Name);
- #endif
- return false;
- }
- /* Process 4OP Integer instructions */
- bool eval_4OP_Int(struct lilith* vm, struct Instruction* c)
- {
- #ifdef DEBUG
- char Name[20] = "ILLEGAL_4OP";
- #endif
- switch(c->raw_XOP)
- {
- case 0x00: /* ADD.CI */
- {
- #ifdef DEBUG
- strncpy(Name, "ADD.CI", 19);
- #elif TRACE
- record_trace("ADD.CI");
- #endif
- ADD_CI(vm, c);
- break;
- }
- case 0x01: /* ADD.CO */
- {
- #ifdef DEBUG
- strncpy(Name, "ADD.CO", 19);
- #elif TRACE
- record_trace("ADD.CO");
- #endif
- ADD_CO(vm, c);
- break;
- }
- case 0x02: /* ADD.CIO */
- {
- #ifdef DEBUG
- strncpy(Name, "ADD.CIO", 19);
- #elif TRACE
- record_trace("ADD.CIO");
- #endif
- ADD_CIO(vm, c);
- break;
- }
- case 0x03: /* ADDU.CI */
- {
- #ifdef DEBUG
- strncpy(Name, "ADDU.CI", 19);
- #elif TRACE
- record_trace("ADDU.CI");
- #endif
- ADDU_CI(vm, c);
- break;
- }
- case 0x04: /* ADDU.CO */
- {
- #ifdef DEBUG
- strncpy(Name, "ADDU.CO", 19);
- #elif TRACE
- record_trace("ADDU.CO");
- #endif
- ADDU_CO(vm, c);
- break;
- }
- case 0x05: /* ADDU.CIO */
- {
- #ifdef DEBUG
- strncpy(Name, "ADDU.CIO", 19);
- #elif TRACE
- record_trace("ADDU.CIO");
- #endif
- ADDU_CIO(vm, c);
- break;
- }
- case 0x06: /* SUB.BI */
- {
- #ifdef DEBUG
- strncpy(Name, "SUB.BI", 19);
- #elif TRACE
- record_trace("SUB.BI");
- #endif
- SUB_BI(vm, c);
- break;
- }
- case 0x07: /* SUB.BO */
- {
- #ifdef DEBUG
- strncpy(Name, "SUB.BO", 19);
- #elif TRACE
- record_trace("SUB.BO");
- #endif
- SUB_BO(vm, c);
- break;
- }
- case 0x08: /* SUB.BIO */
- {
- #ifdef DEBUG
- strncpy(Name, "SUB.BIO", 19);
- #elif TRACE
- record_trace("SUB.BIO");
- #endif
- SUB_BIO(vm, c);
- break;
- }
- case 0x09: /* SUBU.BI */
- {
- #ifdef DEBUG
- strncpy(Name, "SUBU.BI", 19);
- #elif TRACE
- record_trace("SUBU.BI");
- #endif
- SUBU_BI(vm, c);
- break;
- }
- case 0x0A: /* SUBU.BO */
- {
- #ifdef DEBUG
- strncpy(Name, "SUBU.BO", 19);
- #elif TRACE
- record_trace("SUBU.BO");
- #endif
- SUBU_BO(vm, c);
- break;
- }
- case 0x0B: /* SUBU.BIO */
- {
- #ifdef DEBUG
- strncpy(Name, "SUBU.BIO", 19);
- #elif TRACE
- record_trace("SUBU.BIO");
- #endif
- SUBU_BIO(vm, c);
- break;
- }
- case 0x0C: /* MULTIPLY */
- {
- #ifdef DEBUG
- strncpy(Name, "MULTIPLY", 19);
- #elif TRACE
- record_trace("MULTIPLY");
- #endif
- MULTIPLY(vm, c);
- break;
- }
- case 0x0D: /* MULTIPLYU */
- {
- #ifdef DEBUG
- strncpy(Name, "MULTIPLYU", 19);
- #elif TRACE
- record_trace("MULTIPLYU");
- #endif
- MULTIPLYU(vm, c);
- break;
- }
- case 0x0E: /* DIVIDE */
- {
- #ifdef DEBUG
- strncpy(Name, "DIVIDE", 19);
- #elif TRACE
- record_trace("DIVIDE");
- #endif
- DIVIDE(vm, c);
- break;
- }
- case 0x0F: /* DIVIDEU */
- {
- #ifdef DEBUG
- strncpy(Name, "DIVIDEU", 19);
- #elif TRACE
- record_trace("DIVIDEU");
- #endif
- DIVIDEU(vm, c);
- break;
- }
- case 0x10: /* MUX */
- {
- #ifdef DEBUG
- strncpy(Name, "MUX", 19);
- #elif TRACE
- record_trace("MUX");
- #endif
- MUX(vm, c);
- break;
- }
- case 0x11: /* NMUX */
- {
- #ifdef DEBUG
- strncpy(Name, "NMUX", 19);
- #elif TRACE
- record_trace("NMUX");
- #endif
- NMUX(vm, c);
- break;
- }
- case 0x12: /* SORT */
- {
- #ifdef DEBUG
- strncpy(Name, "SORT", 19);
- #elif TRACE
- record_trace("SORT");
- #endif
- SORT(vm, c);
- break;
- }
- case 0x13: /* SORTU */
- {
- #ifdef DEBUG
- strncpy(Name, "SORTU", 19);
- #elif TRACE
- record_trace("SORTU");
- #endif
- SORTU(vm, c);
- break;
- }
- default:
- {
- illegal_instruction(vm, c);
- break;
- }
- }
- #ifdef DEBUG
- fprintf(stdout, "# %s reg%u reg%u reg%u reg%u\n", Name, c->reg0, c->reg1, c->reg2, c->reg3);
- #endif
- return false;
- }
- /* Process 3OP Integer instructions */
- bool eval_3OP_Int(struct lilith* vm, struct Instruction* c)
- {
- #ifdef DEBUG
- char Name[20] = "ILLEGAL_3OP";
- #endif
- switch(c->raw_XOP)
- {
- case 0x000: /* ADD */
- {
- #ifdef DEBUG
- strncpy(Name, "ADD", 19);
- #elif TRACE
- record_trace("ADD");
- #endif
- ADD(vm, c);
- break;
- }
- case 0x001: /* ADDU */
- {
- #ifdef DEBUG
- strncpy(Name, "ADDU", 19);
- #elif TRACE
- record_trace("ADDU");
- #endif
- ADDU(vm, c);
- break;
- }
- case 0x002: /* SUB */
- {
- #ifdef DEBUG
- strncpy(Name, "SUB", 19);
- #elif TRACE
- record_trace("SUB");
- #endif
- SUB(vm, c);
- break;
- }
- case 0x003: /* SUBU */
- {
- #ifdef DEBUG
- strncpy(Name, "SUBU", 19);
- #elif TRACE
- record_trace("SUBU");
- #endif
- SUBU(vm, c);
- break;
- }
- case 0x004: /* CMP */
- {
- #ifdef DEBUG
- strncpy(Name, "CMP", 19);
- #elif TRACE
- record_trace("CMP");
- #endif
- CMP(vm, c);
- break;
- }
- case 0x005: /* CMPU */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPU", 19);
- #elif TRACE
- record_trace("CMPU");
- #endif
- CMPU(vm, c);
- break;
- }
- case 0x006: /* MUL */
- {
- #ifdef DEBUG
- strncpy(Name, "MUL", 19);
- #elif TRACE
- record_trace("MUL");
- #endif
- MUL(vm, c);
- break;
- }
- case 0x007: /* MULH */
- {
- #ifdef DEBUG
- strncpy(Name, "MULH", 19);
- #elif TRACE
- record_trace("MULH");
- #endif
- MULH(vm, c);
- break;
- }
- case 0x008: /* MULU */
- {
- #ifdef DEBUG
- strncpy(Name, "MULU", 19);
- #elif TRACE
- record_trace("MULU");
- #endif
- MULU(vm, c);
- break;
- }
- case 0x009: /* MULUH */
- {
- #ifdef DEBUG
- strncpy(Name, "MULUH", 19);
- #elif TRACE
- record_trace("MULUH");
- #endif
- MULUH(vm, c);
- break;
- }
- case 0x00A: /* DIV */
- {
- #ifdef DEBUG
- strncpy(Name, "DIV", 19);
- #elif TRACE
- record_trace("DIV");
- #endif
- DIV(vm, c);
- break;
- }
- case 0x00B: /* MOD */
- {
- #ifdef DEBUG
- strncpy(Name, "MOD", 19);
- #elif TRACE
- record_trace("MOD");
- #endif
- MOD(vm, c);
- break;
- }
- case 0x00C: /* DIVU */
- {
- #ifdef DEBUG
- strncpy(Name, "DIVU", 19);
- #elif TRACE
- record_trace("DIVU");
- #endif
- DIVU(vm, c);
- break;
- }
- case 0x00D: /* MODU */
- {
- #ifdef DEBUG
- strncpy(Name, "MODU", 19);
- #elif TRACE
- record_trace("MODU");
- #endif
- MODU(vm, c);
- break;
- }
- case 0x010: /* MAX */
- {
- #ifdef DEBUG
- strncpy(Name, "MAX", 19);
- #elif TRACE
- record_trace("MAX");
- #endif
- MAX(vm, c);
- break;
- }
- case 0x011: /* MAXU */
- {
- #ifdef DEBUG
- strncpy(Name, "MAXU", 19);
- #elif TRACE
- record_trace("MAXU");
- #endif
- MAXU(vm, c);
- break;
- }
- case 0x012: /* MIN */
- {
- #ifdef DEBUG
- strncpy(Name, "MIN", 19);
- #elif TRACE
- record_trace("MIN");
- #endif
- MIN(vm, c);
- break;
- }
- case 0x013: /* MINU */
- {
- #ifdef DEBUG
- strncpy(Name, "MINU", 19);
- #elif TRACE
- record_trace("MINU");
- #endif
- MINU(vm, c);
- break;
- }
- case 0x014: /* PACK */
- case 0x015: /* UNPACK */
- case 0x016: /* PACK8.CO */
- case 0x017: /* PACK8U.CO */
- case 0x018: /* PACK16.CO */
- case 0x019: /* PACK16U.CO */
- case 0x01A: /* PACK32.CO */
- case 0x01B: /* PACK32U.CO */
- {
- illegal_instruction(vm, c);
- break;
- }
- case 0x020: /* AND */
- {
- #ifdef DEBUG
- strncpy(Name, "AND", 19);
- #elif TRACE
- record_trace("AND");
- #endif
- AND(vm, c);
- break;
- }
- case 0x021: /* OR */
- {
- #ifdef DEBUG
- strncpy(Name, "OR", 19);
- #elif TRACE
- record_trace("OR");
- #endif
- OR(vm, c);
- break;
- }
- case 0x022: /* XOR */
- {
- #ifdef DEBUG
- strncpy(Name, "XOR", 19);
- #elif TRACE
- record_trace("XOR");
- #endif
- XOR(vm, c);
- break;
- }
- case 0x023: /* NAND */
- {
- #ifdef DEBUG
- strncpy(Name, "NAND", 19);
- #elif TRACE
- record_trace("NAND");
- #endif
- NAND(vm, c);
- break;
- }
- case 0x024: /* NOR */
- {
- #ifdef DEBUG
- strncpy(Name, "NOR", 19);
- #elif TRACE
- record_trace("NOR");
- #endif
- NOR(vm, c);
- break;
- }
- case 0x025: /* XNOR */
- {
- #ifdef DEBUG
- strncpy(Name, "XNOR", 19);
- #elif TRACE
- record_trace("XNOR");
- #endif
- XNOR(vm, c);
- break;
- }
- case 0x026: /* MPQ */
- {
- #ifdef DEBUG
- strncpy(Name, "MPQ", 19);
- #elif TRACE
- record_trace("MPQ");
- #endif
- MPQ(vm, c);
- break;
- }
- case 0x027: /* LPQ */
- {
- #ifdef DEBUG
- strncpy(Name, "LPQ", 19);
- #elif TRACE
- record_trace("LPQ");
- #endif
- LPQ(vm, c);
- break;
- }
- case 0x028: /* CPQ */
- {
- #ifdef DEBUG
- strncpy(Name, "CPQ", 19);
- #elif TRACE
- record_trace("CPQ");
- #endif
- CPQ(vm, c);
- break;
- }
- case 0x029: /* BPQ */
- {
- #ifdef DEBUG
- strncpy(Name, "BPQ", 19);
- #elif TRACE
- record_trace("BPQ");
- #endif
- BPQ(vm, c);
- break;
- }
- case 0x030: /* SAL */
- {
- #ifdef DEBUG
- strncpy(Name, "SAL", 19);
- #elif TRACE
- record_trace("SAL");
- #endif
- SAL(vm, c);
- break;
- }
- case 0x031: /* SAR */
- {
- #ifdef DEBUG
- strncpy(Name, "SAR", 19);
- #elif TRACE
- record_trace("SAR");
- #endif
- SAR(vm, c);
- break;
- }
- case 0x032: /* SL0 */
- {
- #ifdef DEBUG
- strncpy(Name, "SL0", 19);
- #elif TRACE
- record_trace("SL0");
- #endif
- SL0(vm, c);
- break;
- }
- case 0x033: /* SR0 */
- {
- #ifdef DEBUG
- strncpy(Name, "SR0", 19);
- #elif TRACE
- record_trace("SR0");
- #endif
- SR0(vm, c);
- break;
- }
- case 0x034: /* SL1 */
- {
- #ifdef DEBUG
- strncpy(Name, "SL1", 19);
- #elif TRACE
- record_trace("SL1");
- #endif
- SL1(vm, c);
- break;
- }
- case 0x035: /* SR1 */
- {
- #ifdef DEBUG
- strncpy(Name, "SR1", 19);
- #elif TRACE
- record_trace("SR1");
- #endif
- SR1(vm, c);
- break;
- }
- case 0x036: /* ROL */
- {
- #ifdef DEBUG
- strncpy(Name, "ROL", 19);
- #elif TRACE
- record_trace("ROL");
- #endif
- ROL(vm, c);
- break;
- }
- case 0x037: /* ROR */
- {
- #ifdef DEBUG
- strncpy(Name, "ROR", 19);
- #elif TRACE
- record_trace("ROR");
- #endif
- ROR(vm, c);
- break;
- }
- case 0x038: /* LOADX */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADX", 19);
- #elif TRACE
- record_trace("LOADX");
- #endif
- LOADX(vm, c);
- break;
- }
- case 0x039: /* LOADX8 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADX8", 19);
- #elif TRACE
- record_trace("LOADX8");
- #endif
- LOADX8(vm, c);
- break;
- }
- case 0x03A: /* LOADXU8 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADXU8", 19);
- #elif TRACE
- record_trace("LOADXU8");
- #endif
- LOADXU8(vm, c);
- break;
- }
- case 0x03B: /* LOADX16 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADX16", 19);
- #elif TRACE
- record_trace("LOADX16");
- #endif
- LOADX16(vm, c);
- break;
- }
- case 0x03C: /* LOADXU16 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADXU16", 19);
- #elif TRACE
- record_trace("LOADXU16");
- #endif
- LOADXU16(vm, c);
- break;
- }
- case 0x03D: /* LOADX32 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADX32", 19);
- #elif TRACE
- record_trace("LOADX32");
- #endif
- LOADX32(vm, c);
- break;
- }
- case 0x03E: /* LOADXU32 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADXU32", 19);
- #elif TRACE
- record_trace("LOADXU32");
- #endif
- LOADXU32(vm, c);
- break;
- }
- case 0x048: /* STOREX */
- {
- #ifdef DEBUG
- strncpy(Name, "STOREX", 19);
- #elif TRACE
- record_trace("STOREX");
- #endif
- STOREX(vm, c);
- break;
- }
- case 0x049: /* STOREX8 */
- {
- #ifdef DEBUG
- strncpy(Name, "STOREX8", 19);
- #elif TRACE
- record_trace("STOREX8");
- #endif
- STOREX8(vm, c);
- break;
- }
- case 0x04A: /* STOREX16 */
- {
- #ifdef DEBUG
- strncpy(Name, "STOREX16", 19);
- #elif TRACE
- record_trace("STOREX16");
- #endif
- STOREX16(vm, c);
- break;
- }
- case 0x04B: /* STOREX32 */
- {
- #ifdef DEBUG
- strncpy(Name, "STOREX32", 19);
- #elif TRACE
- record_trace("STOREX32");
- #endif
- STOREX32(vm, c);
- break;
- }
- case 0x050: /* CMPJUMP.G */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMP.G", 19);
- #elif TRACE
- record_trace("CMPJUMP.G");
- #endif
- CMPJUMP_G(vm, c);
- break;
- }
- case 0x051: /* CMPJUMP.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMP.GE", 19);
- #elif TRACE
- record_trace("CMPJUMP.GE");
- #endif
- CMPJUMP_GE(vm, c);
- break;
- }
- case 0x052: /* CMPJUMP.E */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMP.E", 19);
- #elif TRACE
- record_trace("CMPJUMP.E");
- #endif
- CMPJUMP_E(vm, c);
- break;
- }
- case 0x053: /* CMPJUMP.NE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMP.NE", 19);
- #elif TRACE
- record_trace("CMPJUMP.NE");
- #endif
- CMPJUMP_NE(vm, c);
- break;
- }
- case 0x054: /* CMPJUMP.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMP.LE", 19);
- #elif TRACE
- record_trace("CMPJUMP.LE");
- #endif
- CMPJUMP_LE(vm, c);
- break;
- }
- case 0x055: /* CMPJUMP.L */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMP.L", 19);
- #elif TRACE
- record_trace("CMPJUMP.L");
- #endif
- CMPJUMP_L(vm, c);
- break;
- }
- case 0x060: /* CMPJUMPU.G */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPU.G", 19);
- #elif TRACE
- record_trace("CMPJUMPU.G");
- #endif
- CMPJUMPU_G(vm, c);
- break;
- }
- case 0x061: /* CMPJUMPU.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPU.GE", 19);
- #elif TRACE
- record_trace("CMPJUMPU.GE");
- #endif
- CMPJUMPU_GE(vm, c);
- break;
- }
- case 0x064: /* CMPJUMPU.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPU.LE", 19);
- #elif TRACE
- record_trace("CMPJUMPU.LE");
- #endif
- CMPJUMPU_LE(vm, c);
- break;
- }
- case 0x065: /* CMPJUMPU.L */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPU.L", 19);
- #elif TRACE
- record_trace("CMPJUMPU.L");
- #endif
- CMPJUMPU_L(vm, c);
- break;
- }
- default:
- {
- illegal_instruction(vm, c);
- break;
- }
- }
- #ifdef DEBUG
- fprintf(stdout, "# %s reg%u reg%u reg%u\n", Name, c->reg0, c->reg1, c->reg2);
- #endif
- return false;
- }
- /* Process 2OP Integer instructions */
- bool eval_2OP_Int(struct lilith* vm, struct Instruction* c)
- {
- #ifdef DEBUG
- char Name[20] = "ILLEGAL_2OP";
- #endif
- switch(c->raw_XOP)
- {
- case 0x0000: /* NEG */
- {
- #ifdef DEBUG
- strncpy(Name, "NEG", 19);
- #elif TRACE
- record_trace("NEG");
- #endif
- NEG(vm, c);
- break;
- }
- case 0x0001: /* ABS */
- {
- #ifdef DEBUG
- strncpy(Name, "ABS", 19);
- #elif TRACE
- record_trace("ABS");
- #endif
- ABS(vm, c);
- break;
- }
- case 0x0002: /* NABS */
- {
- #ifdef DEBUG
- strncpy(Name, "NABS", 19);
- #elif TRACE
- record_trace("NABS");
- #endif
- NABS(vm, c);
- break;
- }
- case 0x0003: /* SWAP */
- {
- #ifdef DEBUG
- strncpy(Name, "SWAP", 19);
- #elif TRACE
- record_trace("SWAP");
- #endif
- SWAP(vm, c);
- break;
- }
- case 0x0004: /* COPY */
- {
- #ifdef DEBUG
- strncpy(Name, "COPY", 19);
- #elif TRACE
- record_trace("COPY");
- #endif
- COPY(vm, c);
- break;
- }
- case 0x0005: /* MOVE */
- {
- #ifdef DEBUG
- strncpy(Name, "MOVE", 19);
- #elif TRACE
- record_trace("MOVE");
- #endif
- MOVE(vm, c);
- break;
- }
- case 0x0006: /* NOT */
- {
- #ifdef DEBUG
- strncpy(Name, "NOT", 19);
- #elif TRACE
- record_trace("NOT");
- #endif
- NOT(vm, c);
- break;
- }
- case 0x0100: /* BRANCH */
- {
- #ifdef DEBUG
- strncpy(Name, "BRANCH", 19);
- #elif TRACE
- record_trace("BRANCH");
- #endif
- BRANCH(vm, c);
- break;
- }
- case 0x0101: /* CALL */
- {
- #ifdef DEBUG
- strncpy(Name, "CALL", 19);
- #elif TRACE
- record_trace("CALL");
- #endif
- CALL(vm, c);
- break;
- }
- case 0x0200: /* PUSHR */
- {
- #ifdef DEBUG
- strncpy(Name, "PUSHR", 19);
- #elif TRACE
- record_trace("PUSHR");
- #endif
- PUSHR(vm, c);
- break;
- }
- case 0x0201: /* PUSH8 */
- {
- #ifdef DEBUG
- strncpy(Name, "PUSH8", 19);
- #elif TRACE
- record_trace("PUSH8");
- #endif
- PUSH8(vm, c);
- break;
- }
- case 0x0202: /* PUSH16 */
- {
- #ifdef DEBUG
- strncpy(Name, "PUSH16", 19);
- #elif TRACE
- record_trace("PUSH16");
- #endif
- PUSH16(vm, c);
- break;
- }
- case 0x0203: /* PUSH32 */
- {
- #ifdef DEBUG
- strncpy(Name, "PUSH32", 19);
- #elif TRACE
- record_trace("PUSH32");
- #endif
- PUSH32(vm, c);
- break;
- }
- case 0x0280: /* POPR */
- {
- #ifdef DEBUG
- strncpy(Name, "POPR", 19);
- #elif TRACE
- record_trace("POPR");
- #endif
- POPR(vm, c);
- break;
- }
- case 0x0281: /* POP8 */
- {
- #ifdef DEBUG
- strncpy(Name, "POP8", 19);
- #elif TRACE
- record_trace("POP8");
- #endif
- POP8(vm, c);
- break;
- }
- case 0x0282: /* POPU8 */
- {
- #ifdef DEBUG
- strncpy(Name, "POPU8", 19);
- #elif TRACE
- record_trace("POPU8");
- #endif
- POPU8(vm, c);
- break;
- }
- case 0x0283: /* POP16 */
- {
- #ifdef DEBUG
- strncpy(Name, "POP16", 19);
- #elif TRACE
- record_trace("POP16");
- #endif
- POP16(vm, c);
- break;
- }
- case 0x0284: /* POPU16 */
- {
- #ifdef DEBUG
- strncpy(Name, "POPU16", 19);
- #elif TRACE
- record_trace("POPU16");
- #endif
- POPU16(vm, c);
- break;
- }
- case 0x0285: /* POP32 */
- {
- #ifdef DEBUG
- strncpy(Name, "POP32", 19);
- #elif TRACE
- record_trace("POP32");
- #endif
- POP32(vm, c);
- break;
- }
- case 0x0286: /* POPU32 */
- {
- #ifdef DEBUG
- strncpy(Name, "POPU32", 19);
- #elif TRACE
- record_trace("POPU32");
- #endif
- POPU32(vm, c);
- break;
- }
- case 0x0300: /* CMPSKIP.G */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIP.G", 19);
- #elif TRACE
- record_trace("CMPSKIP.G");
- #endif
- CMPSKIP_G(vm, c);
- break;
- }
- case 0x0301: /* CMPSKIP.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIP.GE", 19);
- #elif TRACE
- record_trace("CMPSKIP.GE");
- #endif
- CMPSKIP_GE(vm, c);
- break;
- }
- case 0x0302: /* CMPSKIP.E */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIP.E", 19);
- #elif TRACE
- record_trace("CMPSKIP.E");
- #endif
- CMPSKIP_E(vm, c);
- break;
- }
- case 0x0303: /* CMPSKIP.NE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIP.NE", 19);
- #elif TRACE
- record_trace("CMPSKIP.NE");
- #endif
- CMPSKIP_NE(vm, c);
- break;
- }
- case 0x0304: /* CMPSKIP.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIP.LE", 19);
- #elif TRACE
- record_trace("CMPSKIP.LE");
- #endif
- CMPSKIP_LE(vm, c);
- break;
- }
- case 0x0305: /* CMPSKIP.L */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIP.L", 19);
- #elif TRACE
- record_trace("CMPSKIP.L");
- #endif
- CMPSKIP_L(vm, c);
- break;
- }
- case 0x0380: /* CMPSKIPU.G */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPU.G", 19);
- #elif TRACE
- record_trace("CMPSKIPU.G");
- #endif
- CMPSKIPU_G(vm, c);
- break;
- }
- case 0x0381: /* CMPSKIPU.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPU.GE", 19);
- #elif TRACE
- record_trace("CMPSKIPU.GE");
- #endif
- CMPSKIPU_GE(vm, c);
- break;
- }
- case 0x0384: /* CMPSKIPU.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPU.LE", 19);
- #elif TRACE
- record_trace("CMPSKIPU.LE");
- #endif
- CMPSKIPU_LE(vm, c);
- break;
- }
- case 0x0385: /* CMPSKIPU.L */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPU.L", 19);
- #elif TRACE
- record_trace("CMPSKIPU.L");
- #endif
- CMPSKIPU_L(vm, c);
- break;
- }
- default:
- {
- illegal_instruction(vm, c);
- break;
- }
- }
- #ifdef DEBUG
- fprintf(stdout, "# %s reg%u reg%u\n", Name, c->reg0, c->reg1);
- #endif
- return false;
- }
- /* Process 1OP Integer instructions */
- bool eval_1OP_Int(struct lilith* vm, struct Instruction* c)
- {
- #ifdef DEBUG
- char Name[20] = "ILLEGAL_1OP";
- #endif
- switch(c->raw_XOP)
- {
- case 0x00000: /* READPC */
- {
- #ifdef DEBUG
- strncpy(Name, "READPC", 19);
- #elif TRACE
- record_trace("READPC");
- #endif
- READPC(vm, c);
- break;
- }
- case 0x00001: /* READSCID */
- {
- #ifdef DEBUG
- strncpy(Name, "READSCID", 19);
- #elif TRACE
- record_trace("READSCID");
- #endif
- READSCID(vm, c);
- break;
- }
- case 0x00002: /* FALSE */
- {
- #ifdef DEBUG
- strncpy(Name, "FALSE", 19);
- #elif TRACE
- record_trace("FALSE");
- #endif
- FALSE(vm, c);
- break;
- }
- case 0x00003: /* TRUE */
- {
- #ifdef DEBUG
- strncpy(Name, "TRUE", 19);
- #elif TRACE
- record_trace("TRUE");
- #endif
- TRUE(vm, c);
- break;
- }
- case 0x01000: /* JSR_COROUTINE */
- {
- #ifdef DEBUG
- strncpy(Name, "JSR_COROUTINE", 19);
- #elif TRACE
- record_trace("JSR_COROUTINE");
- #endif
- JSR_COROUTINE(vm, c);
- break;
- }
- case 0x01001: /* RET */
- {
- #ifdef DEBUG
- strncpy(Name, "RET", 19);
- #elif TRACE
- record_trace("RET");
- #endif
- RET(vm, c);
- break;
- }
- case 0x02000: /* PUSHPC */
- {
- #ifdef DEBUG
- strncpy(Name, "PUSHPC", 19);
- #elif TRACE
- record_trace("PUSHPC");
- #endif
- PUSHPC(vm, c);
- break;
- }
- case 0x02001: /* POPPC */
- {
- #ifdef DEBUG
- strncpy(Name, "POPPC", 19);
- #elif TRACE
- record_trace("POPPC");
- #endif
- POPPC(vm, c);
- break;
- }
- default:
- {
- illegal_instruction(vm, c);
- break;
- }
- }
- #ifdef DEBUG
- fprintf(stdout, "# %s reg%u\n", Name, c->reg0);
- #endif
- return false;
- }
- /* Process 2OPI Integer instructions */
- bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c)
- {
- #ifdef DEBUG
- char Name[20] = "ILLEGAL_2OPI";
- #endif
- /* 0x0E ... 0x2B */
- /* 0xB0 ... 0xDF */
- switch(c->raw2)
- {
- case 0x0: /* SET.G */
- {
- #ifdef DEBUG
- strncpy(Name, "SET.G", 19);
- #elif TRACE
- record_trace("SET.G");
- #endif
- SET_G(vm, c);
- break;
- }
- case 0x1: /* SET.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "SET.GE", 19);
- #elif TRACE
- record_trace("SET.GE");
- #endif
- SET_GE(vm, c);
- break;
- }
- case 0x2: /* SET.E */
- {
- #ifdef DEBUG
- strncpy(Name, "SET.E", 19);
- #elif TRACE
- record_trace("SET.E");
- #endif
- SET_E(vm, c);
- break;
- }
- case 0x3: /* SET.NE */
- {
- #ifdef DEBUG
- strncpy(Name, "SET.NE", 19);
- #elif TRACE
- record_trace("SET.NE");
- #endif
- SET_NE(vm, c);
- break;
- }
- case 0x4: /* SET.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "SET.LE", 19);
- #elif TRACE
- record_trace("SET.LE");
- #endif
- SET_LE(vm, c);
- break;
- }
- case 0x5: /* SET.L */
- {
- #ifdef DEBUG
- strncpy(Name, "SET.L", 19);
- #elif TRACE
- record_trace("SET.L");
- #endif
- SET_L(vm, c);
- break;
- }
- case 0x0E: /* ADDI */
- {
- #ifdef DEBUG
- strncpy(Name, "ADDI", 19);
- #elif TRACE
- record_trace("ADDI");
- #endif
- ADDI(vm, c);
- break;
- }
- case 0x0F: /* ADDUI */
- {
- #ifdef DEBUG
- strncpy(Name, "ADDUI", 19);
- #elif TRACE
- record_trace("ADDUI");
- #endif
- ADDUI(vm, c);
- break;
- }
- case 0x10: /* SUBI */
- {
- #ifdef DEBUG
- strncpy(Name, "SUBI", 19);
- #elif TRACE
- record_trace("SUBI");
- #endif
- SUBI(vm, c);
- break;
- }
- case 0x11: /* SUBUI */
- {
- #ifdef DEBUG
- strncpy(Name, "SUBUI", 19);
- #elif TRACE
- record_trace("SUBUI");
- #endif
- SUBUI(vm, c);
- break;
- }
- case 0x12: /* CMPI */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPI", 19);
- #elif TRACE
- record_trace("CMPI");
- #endif
- CMPI(vm, c);
- break;
- }
- case 0x13: /* LOAD */
- {
- #ifdef DEBUG
- strncpy(Name, "LOAD", 19);
- #elif TRACE
- record_trace("LOAD");
- #endif
- LOAD(vm, c);
- break;
- }
- case 0x14: /* LOAD8 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOAD8", 19);
- #elif TRACE
- record_trace("LOAD8");
- #endif
- LOAD8(vm, c);
- break;
- }
- case 0x15: /* LOADU8 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADU8", 19);
- #elif TRACE
- record_trace("LOADU8");
- #endif
- LOADU8(vm, c);
- break;
- }
- case 0x16: /* LOAD16 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOAD16", 19);
- #elif TRACE
- record_trace("LOAD16");
- #endif
- LOAD16(vm, c);
- break;
- }
- case 0x17: /* LOADU16 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADU16", 19);
- #elif TRACE
- record_trace("LOADU16");
- #endif
- LOADU16(vm, c);
- break;
- }
- case 0x18: /* LOAD32 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOAD32", 19);
- #elif TRACE
- record_trace("LOAD32");
- #endif
- LOAD32(vm, c);
- break;
- }
- case 0x19: /* LOADU32 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADU32", 19);
- #elif TRACE
- record_trace("LOADU32");
- #endif
- LOADU32(vm, c);
- break;
- }
- case 0x1F: /* CMPUI */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPUI", 19);
- #elif TRACE
- record_trace("CMPUI");
- #endif
- CMPUI(vm, c);
- break;
- }
- case 0x20: /* STORE */
- {
- #ifdef DEBUG
- strncpy(Name, "STORE", 19);
- #elif TRACE
- record_trace("STORE");
- #endif
- STORE(vm, c);
- break;
- }
- case 0x21: /* STORE8 */
- {
- #ifdef DEBUG
- strncpy(Name, "STORE8", 19);
- #elif TRACE
- record_trace("STORE8");
- #endif
- STORE8(vm, c);
- break;
- }
- case 0x22: /* STORE16 */
- {
- #ifdef DEBUG
- strncpy(Name, "STORE16", 19);
- #elif TRACE
- record_trace("STORE16");
- #endif
- STORE16(vm, c);
- break;
- }
- case 0x23: /* STORE32 */
- {
- #ifdef DEBUG
- strncpy(Name, "STORE32", 19);
- #elif TRACE
- record_trace("STORE32");
- #endif
- STORE32(vm, c);
- break;
- }
- case 0xB0: /* ANDI */
- {
- #ifdef DEBUG
- strncpy(Name, "ANDI", 19);
- #elif TRACE
- record_trace("ANDI");
- #endif
- ANDI(vm, c);
- break;
- }
- case 0xB1: /* ORI */
- {
- #ifdef DEBUG
- strncpy(Name, "ORI", 19);
- #elif TRACE
- record_trace("ORI");
- #endif
- ORI(vm, c);
- break;
- }
- case 0xB2: /* XORI */
- {
- #ifdef DEBUG
- strncpy(Name, "XORI", 19);
- #elif TRACE
- record_trace("XORI");
- #endif
- XORI(vm, c);
- break;
- }
- case 0xB3: /* NANDI */
- {
- #ifdef DEBUG
- strncpy(Name, "NANDI", 19);
- #elif TRACE
- record_trace("NANDI");
- #endif
- NANDI(vm, c);
- break;
- }
- case 0xB4: /* NORI */
- {
- #ifdef DEBUG
- strncpy(Name, "NORI", 19);
- #elif TRACE
- record_trace("NORI");
- #endif
- NORI(vm, c);
- break;
- }
- case 0xB5: /* XNORI */
- {
- #ifdef DEBUG
- strncpy(Name, "XNORI", 19);
- #elif TRACE
- record_trace("XNORI");
- #endif
- XNORI(vm, c);
- break;
- }
- case 0xC0: /* CMPJUMPI.G */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPI.G", 19);
- #elif TRACE
- record_trace("CMPJUMPI.G");
- #endif
- CMPJUMPI_G(vm, c);
- break;
- }
- case 0xC1: /* CMPJUMPI.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPI.GE", 19);
- #elif TRACE
- record_trace("CMPJUMPI.GE");
- #endif
- CMPJUMPI_GE(vm, c);
- break;
- }
- case 0xC2: /* CMPJUMPI.E */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPI.E", 19);
- #elif TRACE
- record_trace("CMPJUMPI.E");
- #endif
- CMPJUMPI_E(vm, c);
- break;
- }
- case 0xC3: /* CMPJUMPI.NE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPI.NE", 19);
- #elif TRACE
- record_trace("CMPJUMPI.NE");
- #endif
- CMPJUMPI_NE(vm, c);
- break;
- }
- case 0xC4: /* CMPJUMPI.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPI.LE", 19);
- #elif TRACE
- record_trace("CMPJUMPI.LE");
- #endif
- CMPJUMPI_LE(vm, c);
- break;
- }
- case 0xC5: /* CMPJUMPI.L */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPI.L", 19);
- #elif TRACE
- record_trace("CMPJUMPI.L");
- #endif
- CMPJUMPI_L(vm, c);
- break;
- }
- case 0xD0: /* CMPJUMPUI.G */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPUI.G", 19);
- #elif TRACE
- record_trace("CMPJUMPUI.G");
- #endif
- CMPJUMPUI_G(vm, c);
- break;
- }
- case 0xD1: /* CMPJUMPUI.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPUI.GE", 19);
- #elif TRACE
- record_trace("CMPJUMPUI.GE");
- #endif
- CMPJUMPUI_GE(vm, c);
- break;
- }
- case 0xD4: /* CMPJUMPUI.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPUI.LE", 19);
- #elif TRACE
- record_trace("CMPJUMPUI.LE");
- #endif
- CMPJUMPUI_LE(vm, c);
- break;
- }
- case 0xD5: /* CMPJUMPUI.L */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPJUMPUI.L", 19);
- #elif TRACE
- record_trace("CMPJUMPUI.L");
- #endif
- CMPJUMPUI_L(vm, c);
- break;
- }
- default:
- {
- illegal_instruction(vm, c);
- break;
- }
- }
- #ifdef DEBUG
- fprintf(stdout, "# %s reg%u reg%u %i\n", Name, c->reg0, c->reg1, c->raw_Immediate);
- #endif
- return false;
- }
- /* Process 1OPI Integer instructions */
- bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c)
- {
- #ifdef DEBUG
- char Name[20] = "ILLEGAL_1OPI";
- #endif
- uint32_t Opcode = (c->raw2 * 16) + c->raw_XOP;
- switch(Opcode)
- {
- case 0x2C0: /* JUMP.C */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.C", 19);
- #elif TRACE
- record_trace("JUMP.C");
- #endif
- JUMP_C(vm, c);
- break;
- }
- case 0x2C1: /* JUMP.B */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.B", 19);
- #elif TRACE
- record_trace("JUMP.B");
- #endif
- JUMP_B(vm, c);
- break;
- }
- case 0x2C2: /* JUMP.O */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.O", 19);
- #elif TRACE
- record_trace("JUMP.O");
- #endif
- JUMP_O(vm, c);
- break;
- }
- case 0x2C3: /* JUMP.G */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.G", 19);
- #elif TRACE
- record_trace("JUMP.G");
- #endif
- JUMP_G(vm, c);
- break;
- }
- case 0x2C4: /* JUMP.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.GE", 19);
- #elif TRACE
- record_trace("JUMP.GE");
- #endif
- JUMP_GE(vm, c);
- break;
- }
- case 0x2C5: /* JUMP.E */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.E", 19);
- #elif TRACE
- record_trace("JUMP.E");
- #endif
- JUMP_E(vm, c);
- break;
- }
- case 0x2C6: /* JUMP.NE */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.NE", 19);
- #elif TRACE
- record_trace("JUMP.NE");
- #endif
- JUMP_NE(vm, c);
- break;
- }
- case 0x2C7: /* JUMP.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.LE", 19);
- #elif TRACE
- record_trace("JUMP.LE");
- #endif
- JUMP_LE(vm, c);
- break;
- }
- case 0x2C8: /* JUMP.L */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.L", 19);
- #elif TRACE
- record_trace("JUMP.L");
- #endif
- JUMP_L(vm, c);
- break;
- }
- case 0x2C9: /* JUMP.Z */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.Z", 19);
- #elif TRACE
- record_trace("JUMP.Z");
- #endif
- JUMP_Z(vm, c);
- break;
- }
- case 0x2CA: /* JUMP.NZ */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.NZ", 19);
- #elif TRACE
- record_trace("JUMP.NZ");
- #endif
- JUMP_NZ(vm, c);
- break;
- }
- case 0x2CB: /* JUMP.P */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.P", 19);
- #elif TRACE
- record_trace("JUMP.P");
- #endif
- JUMP_P(vm, c);
- break;
- }
- case 0x2CC: /* JUMP.NP */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP.NP", 19);
- #elif TRACE
- record_trace("JUMP.NP");
- #endif
- JUMP_NP(vm, c);
- break;
- }
- case 0x2D0: /* CALLI */
- {
- #ifdef DEBUG
- strncpy(Name, "CALLI", 19);
- #elif TRACE
- record_trace("CALLI");
- #endif
- CALLI(vm, c);
- break;
- }
- case 0x2D1: /* LOADI */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADI", 19);
- #elif TRACE
- record_trace("LOADI");
- #endif
- LOADI(vm, c);
- break;
- }
- case 0x2D2: /* LOADUI*/
- {
- #ifdef DEBUG
- strncpy(Name, "LOADUI", 19);
- #elif TRACE
- record_trace("LOADUI");
- #endif
- LOADUI(vm, c);
- break;
- }
- case 0x2D3: /* SALI */
- {
- #ifdef DEBUG
- strncpy(Name, "SALI", 19);
- #elif TRACE
- record_trace("SALI");
- #endif
- SALI(vm, c);
- break;
- }
- case 0x2D4: /* SARI */
- {
- #ifdef DEBUG
- strncpy(Name, "SARI", 19);
- #elif TRACE
- record_trace("SARI");
- #endif
- SARI(vm, c);
- break;
- }
- case 0x2D5: /* SL0I */
- {
- #ifdef DEBUG
- strncpy(Name, "SL0I", 19);
- #elif TRACE
- record_trace("SL0I");
- #endif
- SL0I(vm, c);
- break;
- }
- case 0x2D6: /* SR0I */
- {
- #ifdef DEBUG
- strncpy(Name, "SR0I", 19);
- #elif TRACE
- record_trace("SR0I");
- #endif
- SR0I(vm, c);
- break;
- }
- case 0x2D7: /* SL1I */
- {
- #ifdef DEBUG
- strncpy(Name, "SL1I", 19);
- #elif TRACE
- record_trace("SL1I");
- #endif
- SL1I(vm, c);
- break;
- }
- case 0x2D8: /* SR1I */
- {
- #ifdef DEBUG
- strncpy(Name, "SR1I", 19);
- #elif TRACE
- record_trace("SR1I");
- #endif
- SR1I(vm, c);
- break;
- }
- case 0x2E0: /* LOADR */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADR", 19);
- #elif TRACE
- record_trace("LOADR");
- #endif
- LOADR(vm, c);
- break;
- }
- case 0x2E1: /* LOADR8 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADR8", 19);
- #elif TRACE
- record_trace("LOADR8");
- #endif
- LOADR8(vm, c);
- break;
- }
- case 0x2E2: /* LOADRU8 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADRU8", 19);
- #elif TRACE
- record_trace("LOADRU8");
- #endif
- LOADRU8(vm, c);
- break;
- }
- case 0x2E3: /* LOADR16 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADR16", 19);
- #elif TRACE
- record_trace("LOADR16");
- #endif
- LOADR16(vm, c);
- break;
- }
- case 0x2E4: /* LOADRU16 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADRU16", 19);
- #elif TRACE
- record_trace("LOADRU16");
- #endif
- LOADRU16(vm, c);
- break;
- }
- case 0x2E5: /* LOADR32 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADR32", 19);
- #elif TRACE
- record_trace("LOADR32");
- #endif
- LOADR32(vm, c);
- break;
- }
- case 0x2E6: /* LOADRU32 */
- {
- #ifdef DEBUG
- strncpy(Name, "LOADRU32", 19);
- #elif TRACE
- record_trace("LOADRU32");
- #endif
- LOADRU32(vm, c);
- break;
- }
- case 0x2F0: /* STORER */
- {
- #ifdef DEBUG
- strncpy(Name, "STORER", 19);
- #elif TRACE
- record_trace("STORER");
- #endif
- STORER(vm, c);
- break;
- }
- case 0x2F1: /* STORER8 */
- {
- #ifdef DEBUG
- strncpy(Name, "STORER8", 19);
- #elif TRACE
- record_trace("STORER8");
- #endif
- STORER8(vm, c);
- break;
- }
- case 0x2F2: /* STORER16 */
- {
- #ifdef DEBUG
- strncpy(Name, "STORER16", 19);
- #elif TRACE
- record_trace("STORER16");
- #endif
- STORER16(vm, c);
- break;
- }
- case 0x2F3: /* STORER32 */
- {
- #ifdef DEBUG
- strncpy(Name, "STORER32", 19);
- #elif TRACE
- record_trace("STORER32");
- #endif
- STORER32(vm, c);
- break;
- }
- case 0xA00: /* CMPSKIPI.G */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPI.G", 19);
- #elif TRACE
- record_trace("CMPSKIPI.G");
- #endif
- CMPSKIPI_G(vm, c);
- break;
- }
- case 0xA01: /* CMPSKIPI.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPI.GE", 19);
- #elif TRACE
- record_trace("CMPSKIPI.GE");
- #endif
- CMPSKIPI_GE(vm, c);
- break;
- }
- case 0xA02: /* CMPSKIPI.E */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPI.E", 19);
- #elif TRACE
- record_trace("CMPSKIPI.E");
- #endif
- CMPSKIPI_E(vm, c);
- break;
- }
- case 0xA03: /* CMPSKIPI.NE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPI.NE", 19);
- #elif TRACE
- record_trace("CMPSKIPI.NE");
- #endif
- CMPSKIPI_NE(vm, c);
- break;
- }
- case 0xA04: /* CMPSKIPI.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPI.LE", 19);
- #elif TRACE
- record_trace("CMPSKIPI.LE");
- #endif
- CMPSKIPI_LE(vm, c);
- break;
- }
- case 0xA05: /* CMPSKIPI.L */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPI.L", 19);
- #elif TRACE
- record_trace("CMPSKIPI.L");
- #endif
- CMPSKIPI_L(vm, c);
- break;
- }
- case 0xA10: /* CMPSKIPUI.G */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPUI.G", 19);
- #elif TRACE
- record_trace("CMPSKIPUI.G");
- #endif
- CMPSKIPUI_G(vm, c);
- break;
- }
- case 0xA11: /* CMPSKIPUI.GE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPUI.GE", 19);
- #elif TRACE
- record_trace("CMPSKIPUI.GE");
- #endif
- CMPSKIPUI_GE(vm, c);
- break;
- }
- case 0xA14: /* CMPSKIPUI.LE */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPUI.LE", 19);
- #elif TRACE
- record_trace("CMPSKIPUI.LE");
- #endif
- CMPSKIPUI_LE(vm, c);
- break;
- }
- case 0xA15: /* CMPSKIPUI.L */
- {
- #ifdef DEBUG
- strncpy(Name, "CMPSKIPUI.L", 19);
- #elif TRACE
- record_trace("CMPSKIPUI.L");
- #endif
- CMPSKIPUI_L(vm, c);
- break;
- }
- default:
- {
- illegal_instruction(vm, c);
- break;
- }
- }
- #ifdef DEBUG
- fprintf(stdout, "# %s reg%u %d\n", Name, c->reg0, c->raw_Immediate);
- #endif
- return false;
- }
- /* Process 0OPI Integer instructions */
- bool eval_Integer_0OPI(struct lilith* vm, struct Instruction* c)
- {
- #ifdef DEBUG
- char Name[20] = "ILLEGAL_0OPI";
- #endif
- switch(c->raw_XOP)
- {
- case 0x00: /* JUMP */
- {
- #ifdef DEBUG
- strncpy(Name, "JUMP", 19);
- #elif TRACE
- record_trace("JUMP");
- #endif
- JUMP(vm, c);
- break;
- }
- default:
- {
- illegal_instruction(vm, c);
- break;
- }
- }
- #ifdef DEBUG
- fprintf(stdout, "# %s %d\n", Name, c->raw_Immediate);
- #endif
- return false;
- }
- /* Use Opcode to decide what to do and then have it done */
- void eval_instruction(struct lilith* vm, struct Instruction* current)
- {
- performance_counter = performance_counter + 1;
- #ifdef DEBUG
- fprintf(stdout, "Executing: %s\n", current->operation);
- usleep(1000);
- #endif
- switch(current->raw0)
- {
- case 0x00: /* Deal with NOPs */
- {
- if(0 == current->raw0 && 0 == current->raw1 && 0 == current->raw2 && 0 == current->raw3)
- {
- #ifdef TRACE
- record_trace("NOP");
- #endif
- return;
- }
- illegal_instruction(vm, current);
- }
- case 0x01: /* Integer 4OP */
- {
- decode_4OP(current);
- eval_4OP_Int(vm, current);
- break;
- }
- case 0x05: /* Integer 3OP */
- {
- decode_3OP(current);
- eval_3OP_Int(vm, current);
- break;
- }
- case 0x09: /* Integer 2OP */
- {
- decode_2OP(current);
- eval_2OP_Int(vm, current);
- break;
- }
- case 0x0D: /* Integer 1OP */
- {
- decode_1OP(current);
- eval_1OP_Int(vm, current);
- break;
- }
- case 0xE1: /* Integer 2OPI */
- {
- decode_2OPI(vm, current);
- eval_2OPI_Int(vm, current);
- break;
- }
- case 0xE0: /* Integer 1OPI */
- {
- decode_1OPI(vm, current);
- eval_Integer_1OPI(vm, current);
- break;
- }
- case 0x3C: /* Integer 0OPI */
- {
- decode_0OPI(current);
- eval_Integer_0OPI(vm, current);
- break;
- }
- case 0x42: /* HALCODE */
- {
- decode_HALCODE(current);
- eval_HALCODE(vm, current);
- break;
- }
- case 0xFF: /* Deal with HALT */
- {
- vm_HALT(vm, performance_counter);
- break;
- }
- default: /* Deal with illegal instruction */
- {
- illegal_instruction(vm, current);
- break;
- }
- }
- }
|