/***************************************** 函数原型: INT8U DEBUG_BUF_PRINT(INT8U Src[],INT16U SrcLen,INT8U Flag) 函数功能: 打印调试信息,可以将Src缓冲区中的变量打print出来 入口参数: Src,源数据缓冲区 SrcLen,源数据长度 Flag,0表示按十六进制方式打印,1表示按十进制方式打印 Num,没Num个数字打一个换行符 出口参数:打印信息长度 ******************************************/ void DEBUG_BUF_PRINT(INT8U Src[], INT16U SrcLen, INT8U Flag, INT8U Num) { INT16U i; //if(Check_Debug_En() EQ 0)//不是工厂状态不打印 //return; if(OS_Debug_Print_En() EQ 0) return; i = 0; if(Flag EQ PRINT_HEX) //hex打印 { for(i = 0; i < SrcLen; i++) { if(Num != 0 && i % Num EQ 0) OS_Debug_Print("\r\n"); OS_Debug_Print("%2x ", Src[i]); } } else//%d { for(i = 0; i < SrcLen; i++) { if(Num != 0 && i % Num EQ 0) OS_Debug_Print("\r\n"); OS_Debug_Print("%3d ", Src[i]); } } return; }
/***************************************** 函数原型: INT16U DEBUG_PRINT(char *format,...) 函数功能: 打印调试信息,可以将调试信息打印到串口或IAR的i/o窗口中 入口参数:参数列表 出口参数:打印信息长度 ******************************************/ void _Debug_Print(char* format, ...) { va_list ap; INT8U Task_ID; //if(Check_Debug_En() EQ 0)//不是工厂状态不打印 //return; if(OS_Debug_Print_En() EQ 0) return; if(OS_Get_Cur_Task_Num() EQ 0) { OS_Debug_Print("\r\nMAIN:"); } else { Task_ID = OS_Get_Cur_Task_ID(); OS_Debug_Print("\r\n%s:", OS_Get_Task_Name(Task_ID)); } va_start(ap, format); OS_vsPrintf(format, ap); va_end(ap); return; }
//检查任务的上下文是否正确,注意:该函数中不能调用操作系统提供的调用 //只有OS_USE_CS该宏为1时,该函数才有意义 void OS_Check_Task_Env(void) { OS_INT8U Next_Task_ID; if(OS_CHECK_STRUCT_HT(Task_Info) EQ 0)//检查Task_Info的头和尾 OS_ASSERT_FAILED(); //如果要系统速度更快,可把校验和相关屏蔽,只保留头尾检验 #if OS_CS_EN>0 OS_SET_STRUCT_SUM(Tcb[Task_Info.Cur_Task_ID]); #endif Next_Task_ID=(Task_Info.Cur_Task_ID+1)%Task_Info.Cur_Task_Num;//下个任务的ID //如果要系统速度更快,可把校验和相关屏蔽,只保留头尾检验 #if OS_CS_EN>0 if(OS_CHECK_STRUCT_SUM(Tcb[Next_Task_ID]) EQ 0)//检查校验和 { OS_ASSERT_FAILED(); OS_Debug_Print("\r\nOS:Tcb[%d] sum error",Next_Task_ID); } #endif if(OS_CHECK_STRUCT_HT(Tcb[Next_Task_ID]) EQ 0)//检查头尾字节 { OS_ASSERT_FAILED(); OS_Debug_Print("\r\nOS:Tcb[%d] head or tail check error",Next_Task_ID); } if(OS_Check_Task_Stk(Next_Task_ID) EQ 0)//检查堆栈的头和尾 { OS_ASSERT_FAILED(); OS_Debug_Print("\r\nOS:Task %d stack error",Next_Task_ID); } }
//打印任务相关的信息,堆栈剩余字节数 void OS_Task_Info_Print(void) { OS_INT8U i,Task_Num; OS_Debug_Print("\r\nOS:Task remaining stack bytes:"); Task_Num = OS_Get_Cur_Task_Num(); for(i=0;i<Task_Num;i++) OS_Debug_Print("\r\n Task %d:%d",i,OS_Get_Task_Stk_Left(i)); }
// Terminate Process void OS_Proc_Terminate(Process *Proc) { // Data Block *wsk = (Block*)OS_List_GetLast(&Proc->Blocks); #if OS_DEBUG == 1 OS_Debug_Print("Killing process %s, PID=%d", Proc->Name, Proc->PID); #endif // Remove process from list OS_List_Remove(&Processes, Proc); // Clean blocks while(wsk != Null) { // Clean block data free(wsk->Data); // Remove block from list OS_List_RemoveLast(&Proc->Blocks); // Get last block wsk = (Block*)OS_List_GetLast(&Proc->Blocks); } // Clean memory Proc->Status = OS_PROC_TERMINATED; free(Proc); }
void Main_Init_Print() { Assert_Info.Flag=0;//防止函数重入报错 INIT_STRUCT_VAR(Assert_Info); Init_DebugChanel_PUCK(1); //初始化调试串口,需判定工厂状态 OS_Debug_Print("\r\n---------------SYSTEM START----------------"); //上电后强制打印复位信息 OS_Debug_Print("\r\n---------------SYSTEM START----------------"); //上电后强制打印复位信息 OS_Debug_Print("\r\n---------------SYSTEM START----------------"); //上电后强制打印复位信息 OS_Debug_Print("\r\n----------Version:%s----------",COMM_PROTO_VERSION); //上电后强制打印复位信息 Print_Reset_Source(); OS_Assert_Ctrl(0xFF);//前8个任务全部打开断言 ASSERT(A_WARNING,0);//显示复位前的函数调用轨迹 Close_DebugChanel_PUCK(1); //关闭调试串口,需判定工厂状态 }
//对任务环境的检测 void OS_Task_Info_Check(void) { OS_INT8U i; #if OS_TICK_ISR_EN>0 if(OS_CHECK_STRUCT_HT(Tick_ISR_Flag) EQ 0) { OS_ASSERT_FAILED(); OS_Debug_Print("\r\nOS:Tick_ISR_Flag head or tail check error"); } #endif if(OS_CHECK_STRUCT_HT(Task_Info) EQ 0) { OS_ASSERT_FAILED(); OS_Debug_Print("\r\nOS:Task Info head or tail check error"); } #if OS_CS_EN>0 if(OS_CHECK_STRUCT_SUM(Task_Info) EQ 0) { OS_ASSERT_FAILED(); OS_Debug_Print("\r\nOS:Task_Info CS check error"); } #endif for(i=0;i<OS_TASK_NUM;i++) { if(OS_CHECK_STRUCT_HT(Tcb[i]) EQ 0) { OS_ASSERT_FAILED(); OS_Debug_Print("\r\nOS:Task %d env head or tail check error", i); } #if OS_CS_EN>0 if(OS_CHECK_STRUCT_SUM(Tcb[i]) EQ 0) { OS_ASSERT_FAILED(); OS_Debug_Print("\r\nOS:Task %d env CS check error", i); } #endif } }
// Create new process with name, file pointer, flags, priority and two parametrs( Param1 and Param2 will be saved in eax and ebx) Process* OS_Proc_Create(Char *Name, File *File, Byte Flag, Byte Priotity, Word Param1, Word Param2) { // Create data Process *Proc; // Allocate memory for new process Proc = (Process*)OS_Allocate(sizeof(Process)); // Set up Proc->Status = OS_PROC_SUSPENDED; Proc->Flag = Flag; Proc->Priotity = Priotity; OS_UTILS_MemoryCopy(Proc->Name, Name, OS_PROC_NameLength); Proc->Name[OS_PROC_NameLength-1] = 0; Proc->Reg[0] = Param1; Proc->Reg[1] = Param2; Proc->File = File; Proc->Current = (Block*)Null; OS_List_Init(&Proc->Blocks); Proc->PID = GetFirstFreePID(); Proc->Graphics = Null; Proc->StartTime = 0; // Check if PID is not zero if(Proc->PID == Nothing) { // Error return Null; } // Add to the list OS_List_Add(&Processes, Proc); #if OS_DEBUG == 1 OS_Debug_Print("New process created. PID=%d, Name=%s",Proc->PID, Proc->Name); #endif // Return pointner to that process return Proc; }
//打印时间 void Debug_Print_HEX_Time(INT8U Time[]) { INT8U i; if(Check_Debug_En()==0)//非调试状态不打印 return; OS_Debug_Print(" "); for(i=0;i<5;i++) { if(Time[4-i]<10) OS_Debug_Print("0"); OS_Debug_Print("%d",Time[4-i]); if(i==0 || i==1) OS_Debug_Print("-"); else if(i==2) OS_Debug_Print(" "); else if(i==3) OS_Debug_Print(":"); } //OS_Debug_Print(" "); }
//打印版本信息,格式:版本-编译时间-编译日期 void OS_Version_Info_Print(void) { OS_Debug_Print("\r\nOS:Version:%ld-%s-%s", OS_VERSION, __TIME__, __DATE__); }
//输出当前需量信息 void Debug_Print_Cur_Demand_Info() { static S_Int8U Min={CHK_BYTE,0,CHK_BYTE}; static S_Int8U Counts={CHK_BYTE,0,CHK_BYTE}; INT8U i,Rate,Re; if(Check_Debug_En()==0)//非工厂状态不打印 return; if(Cur_Time0.Time[T_MIN]==Min.Var)//每分钟执行一次该函数 return; Re=CHECK_STRUCT_VAR(Min); ASSERT(A_WARNING,1==Re); Re=CHECK_STRUCT_VAR(Counts); ASSERT(A_WARNING,1==Re); Min.Var=Cur_Time0.Time[T_MIN]; Counts.Var++; if(Counts.Var>=5)//每隔5分钟打印一次当前电能值 { Counts.Var=0; Clr_Ext_Inter_Dog(); DEBUG_PRINT(HUCK,DEBUG_1,"|-----------------------------Max_Demand-------------------------------|"); DEBUG_PRINT(HUCK,DEBUG_1,"| Rate Pos_Act Neg_Act Pos_Rea Neg_Rea Quad0_R Quad1_R Quad2_R Quad3_R |"); for(i=0;i<2;i++) { if(i==0) Rate=0; else Rate=Cur_Demand.Rate; DEBUG_PRINT(HUCK,DEBUG_1,"| %2d %7ld %7ld %7ld %7ld %7ld %7ld %7ld %7ld |",\ Rate,Cur_Demand.Demand[i].Pos_Active,Cur_Demand.Demand[i].Neg_Active,Cur_Demand.Demand[i].Pos_Reactive,Cur_Demand.Demand[i].Neg_Reactive,\ Cur_Demand.Demand[i].Quad_Reactive[0],Cur_Demand.Demand[i].Quad_Reactive[1],Cur_Demand.Demand[i].Quad_Reactive[2],Cur_Demand.Demand[i].Quad_Reactive[3]); } DEBUG_PRINT(HUCK,DEBUG_1,"|----------------------------------------------------------------------|"); OS_TimeDly_Ms(50); Clr_Ext_Inter_Dog(); DEBUG_PRINT(HUCK,DEBUG_1,"|----------------------------Demand_Time-------------------------------|"); DEBUG_PRINT(HUCK,DEBUG_1,"| Rate Pos_Active Neg_Active Pos_Reacti Neg_Reacti |"); for(i=0;i<2;i++) { if(i==0) Rate=0; else Rate=Cur_Demand.Rate; DEBUG_PRINT(HUCK,DEBUG_1,"| %2d",Rate); Debug_Print_Time((INT8U *)Cur_Demand.Demand[i].Pos_Active_Time); Debug_Print_Time((INT8U *)Cur_Demand.Demand[i].Neg_Active_Time); Debug_Print_Time((INT8U *)Cur_Demand.Demand[i].Pos_Reactive_Time); Debug_Print_Time((INT8U *)Cur_Demand.Demand[i].Neg_Reactive_Time); OS_Debug_Print(" |"); } DEBUG_PRINT(HUCK,DEBUG_1,"|----------------------------------------------------------------------|"); //暂时没有四象限无功 /* Clr_Ext_Inter_Dog(); //DEBUG_PRINT(HUCK,DEBUG_1,"|-------------------------------Demand_Time_0--------------------------|"); DEBUG_PRINT(HUCK,DEBUG_1,"| Rate Quad0_Reati Quad1_Reati Quad2_Reati Quad3_Reati |"); for(i=0;i<2;i++) { if(i==0) Rate=0; else Rate=Cur_Demand.Rate; DEBUG_PRINT(HUCK,DEBUG_1,"| %2d",Rate); Debug_Print_Time((INT8U *)Cur_Demand.Demand[i].Quad_Reactive_Time[0]); Debug_Print_Time((INT8U *)Cur_Demand.Demand[i].Quad_Reactive_Time[1]); Debug_Print_Time((INT8U *)Cur_Demand.Demand[i].Quad_Reactive_Time[2]); Debug_Print_Time((INT8U *)Cur_Demand.Demand[i].Quad_Reactive_Time[3]); OS_Debug_Print(" |"); } DEBUG_PRINT(HUCK,DEBUG_1,"|----------------------------------------------------------------------|"); */ } }
// Executes system interrupt for given Process void OS_Interrupt(Process *exe , Byte id) { //DEBUG #if OS_DEBUG_PROCESS >= 2 OS_Debug_Print("Process \'%s\' PID=%d performs interrupt id=%d", exe->Name, exe->PID, id); #endif // Switch interrupt id switch(id) { // Terminate program case 1: OS_KillProcessParent(exe); break; // Generate random number from given range <Min; Max> case 2: exe->Reg[0] = exe->Reg[2] ? (rand() % exe->Reg[2] + exe->Reg[1]) : exe->Reg[1]; break; // Get Application with given ID, ID 0 means to give current app data to structure. App struct is adress case 3: { // Cache Application structure Application *appI = Null; // Check if zero if(exe->Reg[1] == 0) { //.......................................................................... } else { // Get application with id appI = OS_App_GetAppByID(exe->Reg[1]); } // Check if valid if(appI == Null) { // No application found exe->Reg[0] = 0; } else { // Copy data OS_UTILS_MemoryCopy((void*)exe->Reg[0], appI, sizeof(Application)); } } break; // Draw string on the screen at the point case 50: OS_GPU_Print_Text(((Point*)&exe->Reg[0])->X, ((Point*)&exe->Reg[0])->Y, ((Char*)exe->Reg[1]), exe->Reg[2]); //OS_GPU_Print_Text(exe->Reg[0], exe->Reg[3], ((Char*)exe->Reg[1]), exe->Reg[2]); // OS_Debug_Print("Time: %d/%d/%d/%d:%d:%d", // current_time.RTC_Year, // current_time.RTC_Mon, // current_time.RTC_Yday, // current_time.RTC_Hour, // current_time.RTC_Min, // current_time.RTC_Sec); break; // Draw number on the screen at the point case 51: OS_GPU_Print_Word(((Point*)&exe->Reg[0])->X, ((Point*)&exe->Reg[0])->Y, exe->Reg[1], exe->Reg[2]); break; // Draw singed number on the screen at the point case 52: OS_GPU_Print_SWord(((Point*)&exe->Reg[0])->X, ((Point*)&exe->Reg[0])->Y, exe->Reg[1], exe->Reg[2]); break; // Draw floating point on the screen at the point case 53: OS_GPU_Print_Float(((Point*)&exe->Reg[0])->X, ((Point*)&exe->Reg[0])->Y, exe->Reg[1], exe->Reg[2]); break; // Draw point on the screen with color case 54: OS_GPU_SetPoint(((Point*)&exe->Reg[0])->X, ((Point*)&exe->Reg[0])->Y, exe->Reg[1]); break; default: //DEBUG #if OS_DEBUG_PROCESS >= 1 OS_Debug_Print("Invalid interrupt!"); #endif break; } }
// Executes given Process void OS_Execute(Process *exe) { // TODO // - optimalization // - safe mode // - error checking // - faster // - 16 bit offset adress in block memory // - global memory // Read command number exe->Reg[9] = OS_FS_Read(exe->File, &exe->Reg[8], 1); // Important note: Only at this time reading from file operation result is checked. if(exe->Reg[9] != FS_RESULT_OK) { //ERROR #if OS_DEBUG OS_Debug_Print("Cannot read from process file!"); #endif // Terminate program OS_KillProcessParent(exe); return; } // DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Command = %d" , exe->Reg[8] ); #endif // Main switch switch(exe->Reg[8]) { ///////////////////////////////////////////////////////////////////////////////////// // [Main section] ///////////////////////////////////////////////////////////////////////////////////// // Error case 0: //ERROR #if OS_DEBUG OS_Debug_Print("No more commands or data leak!"); #endif // Terminate program OS_KillProcessParent(exe); break; // 5 bytes - start const32 case 1: // Read size exe->Reg[8] = Read_Word(exe->File); // Allocate memory exe->Reg[9] = (Word)OS_Allocate(sizeof(Block)); // Save memory usage ((Block*)exe->Reg[9])->Size = exe->Reg[8]; // Save block pointer ((Block*)exe->Reg[9])->FP = exe->File->fptr; // When block allocates memory... if(exe->Reg[8] != 0) { // Allocate block private memory ((Block*)exe->Reg[9])->Data = OS_Allocate(exe->Reg[8]); } else { // No memory usage ((Block*)exe->Reg[9])->Data = Null; } // Add block to Process blocks list OS_List_Add(&exe->Blocks, (void*)exe->Reg[9]); // Set new block as current block exe->Current = ((Block*)exe->Reg[9]); //DEBUG #if OS_DEBUG_PROCESS >= 2 OS_Debug_Print("Starting new block, Memory usage: %d bytes", exe->Reg[8]); #endif break; // 1 byte - ret case 2: // Free block private data free(exe->Current->Data); // Free block free(exe->Current); // Remove last block from collection OS_List_RemoveLast(&exe->Blocks); // Get last block from collection exe->Current = (Block*)OS_List_GetLast(&exe->Blocks); // If no blocks more kill it if(exe->Current == Null) { //DEBUG #if OS_DEBUG_PROCESS >= 1 OS_Debug_Print("No more blocks, killing process parent"); #endif // Kill process parent OS_KillProcessParent(exe); } else { // If there is more bloks just jump in file to last position of last block OS_FS_Seek(exe->File, exe->Current->FP); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Returning to the previus block"); #endif } break; // 2 bytes - int reg case 3: // Read reg OS_FS_Read(exe->File, &exe->Reg[8], 1); // Execute interrupt OS_Interrupt(exe, exe->Reg[exe->Reg[8]]); break; // 2 bytes - int const8 case 4: // Read const8 OS_FS_Read( exe->File, &exe->Reg[8], 1); // Execute interrupt OS_Interrupt(exe, exe->Reg[8]); break; // 9+n bytes- fillmem cont32 cont32 cont8[n] case 5: // Read offset exe->Reg[8] = Read_Word(exe->File); // Read size exe->Reg[9] = Read_Word(exe->File); // Fill memory OS_FS_Read(exe->File, (Byte*)exe->Current->Data + exe->Reg[8], exe->Reg[9]); //DEBUG #if OS_DEBUG_PROCESS >= 2 OS_Debug_Print("Memory from %d, of size %d was set", exe->Reg[8], exe->Reg[9]); #endif break; // 5+n bytes- fillmem const32 cont8[n] case 6: // Read size exe->Reg[8] = Read_Word(exe->File); // Fill memory OS_FS_Read(exe->File, (Byte*)exe->Current->Data, exe->Reg[8]); //DEBUG #if OS_DEBUG_PROCESS >= 2 OS_Debug_Print("Block memory at %d, of size %d was set", exe->Current->Data, exe->Reg[8]); #endif break; ///////////////////////////////////////////////////////////////////////////////////// // [Move section] ///////////////////////////////////////////////////////////////////////////////////// // 3 bytes - mov reg reg case 20: // Read 1st register id OS_FS_Read(exe->File, &exe->Reg[8], 1); // Read 2nd register id OS_FS_Read(exe->File, &exe->Reg[9], 1); // Copy data exe->Reg[exe->Reg[8]] = exe->Reg[exe->Reg[9]]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To register %d was moved %d from register %d", exe->Reg[8], exe->Reg[exe->Reg[8]], exe->Reg[9]); #endif break; /* // 3 bytes - mov !byte! reg [reg] case 21: // Read reg OS_FS_Read(exe->File, &exe->Reg[8], 1); // Read reg OS_FS_Read(exe->File, &exe->Reg[9], 1); // Copy data exe->Reg[exe->Reg[8]] = *(exe->Reg[exe->Reg[9]]); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To register %d was moved %d from memory %d pointed by register %d", exe->Reg[8], exe->Reg[exe->Reg[8]], exe->Reg[exe->Reg[9]], exe->Reg[9]); #endif break; // 21 - 3 - mov !byte! reg [reg] - przenosi 1 bajt danych z komorki o adresie zawartym w rejestrze 2 do rejestru 1 // 22 - 3 - mov short reg [reg] - przenosi 2 bajty danych z komorki o adresie zawartym w rejestrze 2 do rejestru 1 // 23 - 3 - mov word reg [reg] - przenosi 4 bajty danych z komorki o adresie zawartym w rejestrze 2 do rejestru 1 // 24 - 3 - mov !byte! [reg] reg - przenosi 1 bajt danych z rejestru do komorki o adresie zawartym w rejestrze // 25 - 3 - mov short [reg] reg - przenosi 2 bajty danych z rejestru do komorki o adresie zawartym w rejestrze // 26 - 3 - mov word [reg] reg - przenosi 4 bajty danych z rejestru do komorki o adresie zawartym w rejestrze */ // 6 bytes - mov !byte! reg mem case 27: // Read register id OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read mem exe->Reg[9] = Read_Word( exe->File ); // Write data to reg from adress exe->Reg[exe->Reg[8]] = *((Byte*)exe->Current->Data + exe->Reg[9]); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Register %d set %d from memory %d that has block offset %d", exe->Reg[8], exe->Reg[exe->Reg[8]], (Byte*)exe->Current->Data + exe->Reg[9], exe->Reg[9]); #endif break; // 6 bytes - mov short reg mem case 28: // Read register id OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read mem exe->Reg[9] = Read_Word( exe->File ); // Write data to reg from adress exe->Reg[exe->Reg[8]] = *((Short*)((Byte*)exe->Current->Data + exe->Reg[9])); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Register %d set %d from memory %d that has block offset %d", exe->Reg[8], exe->Reg[exe->Reg[8]], (Short*)exe->Current->Data + exe->Reg[9], exe->Reg[9]); #endif break; // 6 bytes - mov word reg mem case 29: // Read register id OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read mem exe->Reg[9] = Read_Word( exe->File ); // Write data to reg from adress exe->Reg[exe->Reg[8]] = *((Word*)((Byte*)exe->Current->Data + exe->Reg[9])); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Register %d set %d from memory %d that has block offset %d", exe->Reg[8], exe->Reg[exe->Reg[8]], (Word*)exe->Current->Data + exe->Reg[9], exe->Reg[9]); #endif break; // 6 bytes - mov reg [mem] case 30: // Read register id OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read [mem] exe->Reg[9] = Read_Word( exe->File ); // Write adress to reg exe->Reg[exe->Reg[8]] = ((Word)exe->Current->Data + exe->Reg[9]); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To register %d was written adress %d", exe->Reg[8], exe->Reg[exe->Reg[8]]); #endif break; // 6 bytes - mov !byte! mem reg case 31: // Read mem exe->Reg[8] = Read_Word(exe->File); // Read reg OS_FS_Read(exe->File, &exe->Reg[9], 1); // Write data *((Byte*)((Byte*)exe->Current->Data + exe->Reg[8])) = exe->Reg[exe->Reg[9]]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To memory %#x was written %d from register %d", (Byte*)((Byte*)exe->Current->Data + exe->Reg[8]), exe->Reg[exe->Reg[9]], exe->Reg[9]); #endif break; // 6 bytes - mov short mem reg case 32: // Read mem exe->Reg[8] = Read_Word(exe->File); // Read reg OS_FS_Read(exe->File, &exe->Reg[9], 1); // Write data *((Short*)((Byte*)exe->Current->Data + exe->Reg[8])) = exe->Reg[exe->Reg[9]]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To memory %#x was written %d from register %d", (Short*)((Byte*)exe->Current->Data + exe->Reg[8]), exe->Reg[exe->Reg[9]], exe->Reg[9]); #endif break; // 6 bytes - mov word mem reg case 33: // Read mem exe->Reg[8] = Read_Word(exe->File); // Read reg OS_FS_Read(exe->File, &exe->Reg[9], 1); // Write data *((Word*)((Byte*)exe->Current->Data + exe->Reg[8])) = exe->Reg[exe->Reg[9]]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To memory %#x was written %d from register %d", (Word*)((Byte*)exe->Current->Data + exe->Reg[8]), exe->Reg[exe->Reg[9]], exe->Reg[9]); #endif break; // 6 bytes - mov mem const8 case 34: // Read mem exe->Reg[8] = Read_Word( exe->File ); // Read const8 OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Write data *(((Byte*)exe->Current->Data + exe->Reg[8])) = exe->Reg[9]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To memory %#x was written %d", (Byte*)exe->Current->Data + exe->Reg[8], exe->Reg[9]); #endif break; // 7 bytes - mov mem const16 case 35: // Read mem exe->Reg[8] = Read_Word( exe->File ); // Read const16 OS_FS_Read( exe->File , &exe->Reg[9] , 2 ); // Write data *((Short*)((Byte*)exe->Current->Data + exe->Reg[8])) = Make_Short(exe->Reg[9],exe->Reg[10]); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To memory %#x was wrtten %d", (Short*)exe->Current->Data + exe->Reg[8], Make_Short(exe->Reg[9],exe->Reg[10])); #endif break; // 9 bytes - mov mem const32 case 36: // Read mem exe->Reg[8] = Read_Word( exe->File ); // Read const32 exe->Reg[9] = Read_Word( exe->File ); // Write data *((Word*)((Byte*)exe->Current->Data + exe->Reg[8])) = exe->Reg[9]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To memory %d#x was written %d", (Word*)exe->Current->Data + exe->Reg[8], exe->Reg[9]); #endif break; // 3 bytes - mov reg const8 case 37: // Read register id OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read const8 OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Write data exe->Reg[exe->Reg[8]] = exe->Reg[9]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To register %d was written %d", exe->Reg[8], exe->Reg[9]); #endif break; // 4 bytes - mov reg const16 case 38: // Read register id OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Create word and write it exe->Reg[exe->Reg[8]] = Read_Short(exe->File); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To register %d was written %d", exe->Reg[8], exe->Reg[exe->Reg[8]]); #endif break; // 6 bytes - mov reg const32 case 39: // Read register id OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read const32 exe->Reg[exe->Reg[8]] = Read_Word(exe->File); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("To register %d was written %d", exe->Reg[8], exe->Reg[exe->Reg[8]]); #endif break; ///////////////////////////////////////////////////////////////////////////////////// // [Arithmetic section] ///////////////////////////////////////////////////////////////////////////////////// // 3 bytes - add reg reg case 50: // Read 1st register OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read 2nd register OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Perform addition exe->Reg[exe->Reg[8]] = exe->Reg[exe->Reg[8]] + exe->Reg[exe->Reg[9]]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Register %d + %d, equals %d", exe->Reg[8], exe->Reg[9], exe->Reg[exe->Reg[8]]); #endif break; // 3 bytes - sub reg reg case 51: // Read 1st register OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read 2nd register OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Perform substraction exe->Reg[exe->Reg[8]] = exe->Reg[exe->Reg[8]] - exe->Reg[exe->Reg[9]]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Register %d - %d, equals %d", exe->Reg[8], exe->Reg[9], exe->Reg[exe->Reg[8]]); #endif break; // 3 bytes - mul reg reg case 52: // Read 1st register OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read 2nd register OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Perform multiplication exe->Reg[exe->Reg[8]] = exe->Reg[exe->Reg[8]] * exe->Reg[exe->Reg[9]]; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Register %d * %d, equals %d", exe->Reg[8], exe->Reg[9], exe->Reg[exe->Reg[8]]); #endif break; ///////////////////////////////////////////////////////////////////////////////////// // [Flow control section] ///////////////////////////////////////////////////////////////////////////////////// // 5 bytes - jump const32 case 90: // Read Adress exe->Reg[8] = Read_Word( exe->File ); // Save block pointer exe->Current->FP = exe->File->fptr; // Move file pointer of a file OS_FS_Seek (exe->File, exe->Reg[8]); //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Jump to %#x", exe->Reg[8]); #endif break; // 7 bytes - je reg reg const32 case 91: // Read 1st register OS_FS_Read(exe->File, &exe->Reg[8], 1); // Read 2nd register OS_FS_Read(exe->File, &exe->Reg[9], 1); // Read jump adress exe->Reg[10] = Read_Word( exe->File ); // Compare if(exe->Reg[exe->Reg[8]] == exe->Reg[exe->Reg[9]]) { // Move file pointer of a file OS_FS_Seek ( exe->File , exe->Reg[10] ); // Save block pointer exe->Current->FP = exe->File->fptr; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, and jump to %#x", exe->Reg[8], exe->Reg[9], exe->Reg[10]); #endif } else { //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, without jump", exe->Reg[8], exe->Reg[9]); #endif } break; // 7 bytes - jne reg reg const32 case 92: // Read 1st register OS_FS_Read(exe->File , &exe->Reg[8], 1); // Read 2nd register OS_FS_Read(exe->File , &exe->Reg[9], 1); // Read jump adress exe->Reg[10] = Read_Word( exe->File ); // Compare if(exe->Reg[exe->Reg[8]] != exe->Reg[exe->Reg[9]]) { // Move file pointer of a file OS_FS_Seek ( exe->File , exe->Reg[10] ); // Save block pointer exe->Current->FP = exe->File->fptr; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, and jump to %#x", exe->Reg[8], exe->Reg[9], exe->Reg[10]); #endif } else { //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, without jump", exe->Reg[8], exe->Reg[9]); #endif } break; // 7 bytes - jg reg reg const32 case 93: // Read 1st register OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read 2nd register OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Read jump adress exe->Reg[10] = Read_Word( exe->File ); // Compare if(exe->Reg[exe->Reg[8]] > exe->Reg[exe->Reg[9]]) { // Move file pointer of a file OS_FS_Seek ( exe->File , exe->Reg[10] ); // Save block pointer exe->Current->FP = exe->File->fptr; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, and jump to %#x", exe->Reg[8], exe->Reg[9], exe->Reg[10]); #endif } else { //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, without jump", exe->Reg[8], exe->Reg[9]); #endif } break; // 7 bytes - jge reg reg const32 case 94: // Read 1st register OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read 2nd register OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Read jump adress exe->Reg[10] = Read_Word( exe->File ); // Compare if(exe->Reg[exe->Reg[8]] >= exe->Reg[exe->Reg[9]]) { // Move file pointer of a file OS_FS_Seek ( exe->File , exe->Reg[10] ); // Save block pointer exe->Current->FP = exe->File->fptr; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, and jump to %#x", exe->Reg[8], exe->Reg[9], exe->Reg[10]); #endif } else { //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, without jump", exe->Reg[8], exe->Reg[9]); #endif } break; // 7 bytes - jl reg reg const32 case 95: // Read 1st register OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read 2nd register OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Read jump adress exe->Reg[10] = Read_Word( exe->File ); // Compare if(exe->Reg[exe->Reg[8]] < exe->Reg[exe->Reg[9]]) { // Move file pointer of a file OS_FS_Seek ( exe->File , exe->Reg[10] ); // Save block pointer exe->Current->FP = exe->File->fptr; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, and jump to %#x", exe->Reg[8], exe->Reg[9], exe->Reg[10]); #endif } else { //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, without jump", exe->Reg[8], exe->Reg[9]); #endif } break; // 7 bytes - jle reg reg const32 case 96: // Read 1st register OS_FS_Read( exe->File , &exe->Reg[8] , 1 ); // Read 2nd register OS_FS_Read( exe->File , &exe->Reg[9] , 1 ); // Read jump adress exe->Reg[10] = Read_Word( exe->File ); // Compare if(exe->Reg[exe->Reg[8]] <= exe->Reg[exe->Reg[9]]) { // Move file pointer of a file OS_FS_Seek ( exe->File , exe->Reg[10] ); // Save block pointer exe->Current->FP = exe->File->fptr; //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, and jump to %#x", exe->Reg[8], exe->Reg[9], exe->Reg[10]); #endif } else { //DEBUG #if OS_DEBUG_PROCESS >= 3 OS_Debug_Print("Compare register %d with %d, without jump", exe->Reg[8], exe->Reg[9]); #endif } break; //ERROR default: //ERROR #if OS_DEBUG_PROCESS >= 1 OS_Debug_Print("Unknown command!"); #endif break; } }