void silverstack_irAlLabel(t_nombre_etiqueta etiqueta) { int salir = 0; int dir_instruccion; char buffer[pcb.size_etiquetas_index]; msg_solicitud_bytes.base = pcb.etiquetas_index; msg_solicitud_bytes.offset = 0; msg_solicitud_bytes.tamanio = pcb.size_etiquetas_index; msg_cambio_proceso_activo.id_programa = pcb.unique_id; mensaje.tipo = SOLICITUDBYTES; send(sockUmv, &mensaje, sizeof(t_mensaje), 0); send(sockUmv, &msg_cambio_proceso_activo, sizeof(t_msg_cambio_proceso_activo), 0); send(sockUmv, &msg_solicitud_bytes, sizeof(t_msg_solicitud_bytes), 0); if (recv(sockUmv, &mensaje, sizeof(t_mensaje), 0) == 0) { log_error(logger, "UMV desconectada."); depuracion(SIGINT); } if (recv(sockUmv, &buffer, sizeof(buffer), 0) == 0) { log_error(logger, "UMV desconectada."); depuracion(SIGINT); } dir_instruccion = metadata_buscar_etiqueta(etiqueta, buffer, pcb.size_etiquetas_index); pcb.program_counter = dir_instruccion - 1; }
void irAlLabel(t_nombre_etiqueta etiqueta) { if (SEG_flag == 1) return; char** partes = string_split(etiqueta, "\n"); etiqueta = partes[0]; //Controla si el diccionario es vacio if (dicc_etiquetas == NULL ) { //Si es vacio, solicita el indice de etiquetas a la umv t_struct_sol_bytes * sol_ind_etiquetas = malloc(sizeof(t_struct_sol_bytes)); //primero debe solicitar nuevamente el indice de etiquetas a la UMV sol_ind_etiquetas->base = var_ind_etiquetas; sol_ind_etiquetas->offset = 0; sol_ind_etiquetas->tamanio = var_tamanio_etiquetas; socket_enviar(sockUMV, D_STRUCT_SOL_BYTES, sol_ind_etiquetas); free(sol_ind_etiquetas); void * structRecibido; t_tipoEstructura tipoStruct; //Recibe respuesta de la UMV socket_recibir(sockUMV, &tipoStruct, &structRecibido); //Valida respuesta de la UMV if (tipoStruct != D_STRUCT_RESPUESTA_UMV) { printf("Tipo incorrecto\n"); free(structRecibido); return; } uint32_t temp_tamanio; void * temp_buffer; //Arma el diccionario con lo recibido de la UMV temp_buffer = ((t_struct_respuesta_umv*) structRecibido)->buffer; temp_tamanio = ((t_struct_respuesta_umv*) structRecibido)->tamano_buffer; dicc_etiquetas = malloc(temp_tamanio); int tamanio_instruccion; tamanio_instruccion = ((t_struct_respuesta_umv*) structRecibido)->tamano_buffer; if (tamanio_instruccion == sizeof(int)) { int*respuesta = malloc(sizeof(int)); memcpy(respuesta, ((t_struct_respuesta_umv*) structRecibido)->buffer, tamanio_instruccion); int valor1 = *respuesta; if (valor1 < 0) { excepcion_UMV(0); log_escribir(archLog,"Se termina de ejecutar una instruccion",INFO,"Se produjo una excepcion de umv en irAlLabel"); return; } } memcpy(dicc_etiquetas, temp_buffer, temp_tamanio); // aca dicc_etiquetas me cargo con el char* IMPRIMIR nada mas free(temp_buffer); free(structRecibido); } //NO TENDRIA QUE SER TODAS LAS ETIQUETAS? printf("irAlLabel\n"); log_escribir(archLog,"Se termina de ejecutar una instruccion",INFO,"Se ejecuto irAlLabel"); temp_counter = metadata_buscar_etiqueta(etiqueta, dicc_etiquetas, var_tamanio_etiquetas); //se asigna al program counter temp_counter = temp_counter - 1; //Se libera espacio alocado free(partes[0]); free(partes[1]); free(partes); }
void llamarSinRetorno(t_nombre_etiqueta etiqueta){ int32_t pos_retorno; /*Preserva el contexto de ejecución actual para poder retornar luego al mismo.*/ preservarContexto(); //actualizo las estructuras pcb->dir_cont_actual = pcb->dir_cont_actual + (5*pcb->cant_var_cont_actual)+8;//todo probar q ande pcb->cant_var_cont_actual = 0; regenerar_dicc_var(); pos_retorno = metadata_buscar_etiqueta(etiqueta, etiquetas, pcb->tam_indice_etiquetas); pcb->program_counter = pos_retorno; txt_write_in_file(cpu_file_log, "Llamando sin retorno a etiqueta\n"); printf(" Llamando sin retorno a etiqueta:%s, con pos_PC:%i\n", etiqueta, pos_retorno); }
void llamarConRetorno(t_nombre_etiqueta etiqueta, t_puntero donde_retornar){ log_info(logger,"Primitiva: llamarConRetorno\n"); t_stack*stackAux=malloc(sizeof(t_stack)); stackAux->args=list_create(); stackAux->vars=list_create(); stackAux->cantArgs=0; stackAux->cantVars=0; stackAux->retVar.pag=donde_retornar/tamanioPagina; stackAux->retVar.offset=donde_retornar%tamanioPagina; stackAux->retPos=pcb->PC+1; pcb->SP=list_add(pcb->indiceDeStack,stackAux); pcb->tamanioIndiceStack++; pcb->PC=metadata_buscar_etiqueta(etiqueta,pcb->indiceDeEtiquetas.etiquetas,pcb->indiceDeEtiquetas.etiquetas_size); flagSaltoLinea=1; }
void irAlLabel(t_nombre_etiqueta nombre_etiqueta){//revisar // primer instruccion ejecutable de etiqueta y -1 en caso de error char *etiq_sin_blancos = sacar_caracteres_escape(nombre_etiqueta); //t_puntero_instruccion pos_etiqueta= metadata_buscar_etiqueta("inicio", etiquetas, pcb->tam_indice_etiquetas); t_puntero_instruccion pos_etiqueta= metadata_buscar_etiqueta(etiq_sin_blancos, etiquetas, pcb->tam_indice_etiquetas); if(pos_etiqueta != -1){ pcb->program_counter = pos_etiqueta; txt_write_in_file(cpu_file_log, "Yendo al label \n"); printf(" Yendo al label con pos: %i, con nombre: %s, \n",pos_etiqueta, etiq_sin_blancos); }else{ txt_write_in_file(cpu_file_log, "Hubo un error en la busqueda de la etiqueta\n"); printf(" ERROR en la busqueda de la etiqueta:%s \n",etiq_sin_blancos); finalizarContexto(ERROR); } free(etiq_sin_blancos); }
void primitiva_irAlLabel(t_nombre_etiqueta nombreEtiqueta){ t_puntero_instruccion siguienteInstruc; if(!g_expulsar){ printf("===>PRIMITIVA: irAlLabel -%s-\n",nombreEtiqueta); log_debug(g_logger,":::primitiva_irAlLabel -%s-:::",nombreEtiqueta); siguienteInstruc=metadata_buscar_etiqueta(nombreEtiqueta,g_infoEtiquetas,g_pcb.tamanio_indice_etiquetas); if(siguienteInstruc==-1){ //ERROR printf(" --->ERRoR en la busqueda de la etiqueta:%s en el chaR*etiquetas\n",nombreEtiqueta); }else{ //cambiar la linea de ejecucion a siguienteInstruc printf(" metadata_buscar_etiqueta() dio: siguienteInstruccion:%i\n",siguienteInstruc); g_pcb.program_counter=siguienteInstruc; } } }
void llamarConRetorno(t_nombre_etiqueta etiqueta, t_puntero donde_retornar){ int32_t base, offset, tam, pos_retorno; //preservar el contexto, agrega al segmento stack la dir de memoria del contexto anterior y la cantidad de variables del contex anterior preservarContexto(); //aca le digo a la umv q me guarde en el stack la dir de la variable a la q tengo q asignarle el valor retornado por la "funcion" base = pcb->dir_seg_stack; offset = pcb->dir_cont_actual - base + (pcb->cant_var_cont_actual*5)+8; tam = sizeof(int32_t); char *buffer = copiar_int_to_buffer(donde_retornar); enviar_men_cpu_umv_destruir(ALM_BYTES, base, offset, tam, buffer); free(buffer); t_men_comun *r_alm = socket_recv_comun(socketUmv); if(r_alm->tipo == R_ALM_BYTES){ txt_write_in_file(cpu_file_log, "Se almaceno la direccion de retorno \n"); printf(" Se almaceno la direccion de retorno\n"); //actualizo las estructuras pcb->dir_cont_actual = pcb->dir_seg_stack+offset+4; pcb->cant_var_cont_actual = 0; regenerar_dicc_var(); pos_retorno = metadata_buscar_etiqueta(etiqueta, etiquetas, pcb->tam_indice_etiquetas); pcb->program_counter = pos_retorno; txt_write_in_file(cpu_file_log, "Llamando con retorno a la etiqueta\n"); printf(" Llamando con retorno a etiqueta %s, pos_PC:%i\n", etiqueta, pos_retorno); return; } if(r_alm->tipo == SEGMEN_FAULT){ finalizarContexto(SEGMEN_FAULT); return; } printf(" ERROR tipo de dato:%i, recibido es erroneo\n", r_alm->tipo); }
void irAlLabel(t_nombre_etiqueta t_nombre_etiqueta){ log_info(logger,"Primitiva: IrALabel\n"); pcb->PC= metadata_buscar_etiqueta(t_nombre_etiqueta,pcb->indiceDeEtiquetas.etiquetas,pcb->indiceDeEtiquetas.etiquetas_size); flagSaltoLinea=1; }
void irAlLabel(t_nombre_etiqueta etiqueta) { if(status_check() != EXECUTING) return; actual_pcb->program_counter = metadata_buscar_etiqueta(etiqueta, actual_pcb->etiquetas, (size_t) actual_pcb->etiquetas_size) - 1; }