Xv6 with picoc & Linkage editor
v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
|
00001 #include <stdio.h> 00002 #include <string.h> 00003 #include <stdlib.h> 00004 #include <libelf/libelf.h> 00005 #include <libelf/gelf.h> 00006 #include "ld.h" 00007 void init(Node **add_list){ 00008 *add_list = NULL; 00009 } 00010 Node *ispresent(Node *list,char *string){ 00011 Node *p; 00012 p = list; 00013 while(p ){ 00014 if(!strcmp(p->name,string)) 00015 return p; 00016 p = p->next; 00017 } 00018 return NULL; 00019 } 00020 void traverse(Node *list){ 00021 Node *p; 00022 p = list; 00023 while(p){ 00024 printf("%s %d %d\n",p->name,(int)p->symbol->st_value,p->argindex); 00025 p = p->next; 00026 } 00027 } 00028 int delete(Node **list,char *string){ 00029 Node *p,*q; 00030 p = *list; 00031 q = p->next; 00032 if(!p){ 00033 /*empty list*/ 00034 00035 printf("empty delete\n"); 00036 return -1; 00037 } 00038 if(!strcmp(p->name,string)){ 00039 00040 /*if element is at first position */ 00041 00042 *list = q; 00043 free(p); 00044 return 0; 00045 } 00046 while(q){ 00047 if(!strcmp(q->name,string)){ 00048 p->next = q->next; 00049 free(q); 00050 return 0; 00051 } 00052 p = q; 00053 q = q->next; 00054 } 00055 return -1; 00056 } 00057 void insert(Node **list,GElf_Sym *symbol,char *string,int argindex){ 00058 Node *p,*tmp; 00059 p = (Node *)malloc(sizeof(Node)); 00060 00061 strcpy(p->name,string); 00062 p->argindex = argindex; 00063 p->symbol = symbol; 00064 p->next = NULL; 00065 00066 if(symbol == NULL){ 00067 printf("couldnot insert\n"); 00068 return ; 00069 } 00070 00071 if(!(*list)){ 00072 /*void inesrtion*/ 00073 *list = p; 00074 }else{ 00075 /*normal operation*/ 00076 tmp = *list; 00077 while(tmp->next != NULL){ 00078 tmp = tmp->next; 00079 } 00080 tmp->next = p; 00081 } 00082 } 00083 /* 00084 void f(Node **list){ 00085 GElf_Sym *symbol = (GElf_Sym *)malloc(sizeof(GElf_Sym) * 1); 00086 00087 char str[16] = "dhanesh"; 00088 insert(list,symbol,str); 00089 char str1[16] = "arole"; 00090 insert(list,symbol,str1); 00091 char str2[16] = "calcutta"; 00092 insert(list,symbol,str2); 00093 char str3[16] = "finance"; 00094 insert(list,symbol,str3); 00095 00096 }*/ 00097 /* 00098 void f1(Node **list,Node **list1){ 00099 Node *u = NULL; 00100 while(u = getnextNode(*list,u)){ 00101 printf("%s \n",u->name,(int)(u->symbol)->st_size); 00102 insert(list1,u->symbol,u->name); 00103 delete(list,u->name); 00104 } 00105 } 00106 int main(){ 00107 00108 Node *list; 00109 Node *list1; 00110 init(&list); 00111 init(&list1); 00112 f(&list); 00113 f1(&list,&list1); 00114 traverse(list1); 00115 }*/