{"action":"created","comment":{"url":"https://api.github.com/repos/radare/radare2/pulls/comments/79140047","id":79140047,"diff_hunk":"@@ -17,35 +17,274 @@\n \n #define\tAVR_SOFTCAST(x,y) (x+(y*0x100))\n \n+typedef struct _cpu_models_tag_ {\n+\tchar *model;\n+\tint pc_bits;\n+\tint pc_mask;\n+\tint pc_size;\n+\tint eeprom_size;\n+} CPU_MODEL;\n+\n+typedef void (*inst_handler_t) (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, int *fail, CPU_MODEL *cpu);\n+\n+typedef struct _opcodes_tag_ {\n+\tchar *name;\n+\tint mask;\n+\tint selector;\n+\tinst_handler_t handler;\n+\tint cycles;\n+\tint size;\n+\tint type;\n+} OPCODE_DESC;\n+\n+#define CPU_MODEL_DECL(model, pc_bits, eeprom_sz)\t\t\t\\\n+\t{\t\t\t\t\t\t\t\t\\\n+\t\tmodel,\t\t\t\t\t\t\t\\\n+\t\t(pc_bits),\t\t\t\t\t\t\\\n+\t\t(~((~0) << (pc_bits))), \t\t\t\t\\\n+\t\t((pc_bits) >> 3) + (((pc_bits) & 0x07) ? 1 : 0),\t\\\n+\t\teeprom_sz\t\t\t\t\t\t\\\n+\t}\n+\n+#define INST_HANDLER(OPCODE_NAME)\tstatic void _inst__ ## OPCODE_NAME (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, int *fail, CPU_MODEL *cpu)\n+#define INST_DECL(OP, M, SL, C, SZ, T)\t{ #OP, (M), (SL), _inst__ ## OP, (C), (SZ), R_ANAL_OP_TYPE_ ## T }\n+#define INST_LAST\t\t\t{ \"unknown\", 0, 0, (void *) 0, 2, 1, R_ANAL_OP_TYPE_UNK      }\n+\n+#define INST_CALL(OPCODE_NAME)\t\t_inst__ ## OPCODE_NAME (anal, op, addr, buf, len, fail, cpu)\n+#define INST_INVALID\t\t\t{ *fail = 1; return; }\n+#define INST_ASSERT(x)\t\t\t{ if (!(x)) { INST_INVALID; } }\n+\n+CPU_MODEL cpu_models[] = {\n+\tCPU_MODEL_DECL (\"ATmega48\",   11, 512),\n+\tCPU_MODEL_DECL (\"ATmega8\",    12, 512),\n+\tCPU_MODEL_DECL (\"ATmega88\",   12, 512),\n+\tCPU_MODEL_DECL (\"ATmega168\",  13, 512),\n+\tCPU_MODEL_DECL (\"ATmega640\",  16, 512),\n+\tCPU_MODEL_DECL (\"ATmega1280\", 16, 512),\n+\tCPU_MODEL_DECL (\"ATmega1281\", 16, 512),\n+\tCPU_MODEL_DECL (\"ATmega2560\", 22, 512),\n+\tCPU_MODEL_DECL (\"ATmega2561\", 22, 512),\n+\tCPU_MODEL_DECL ((char *) 0,   16, 512)\n+};\n+\n+INST_HANDLER (cp) {\n+\t// CP Rd, Rr\n+\tint r = (buf[0]        & 0x0f) | ((buf[1] << 3) & 0x10);\n+\tint d = ((buf[0] >> 4) & 0x0f) | ((buf[1] << 4) & 0x10);\n+\tr_strbuf_setf (\n+\t\t&op->esil,\n+\t\t\"r%d,r%d,==,\"\t\t\t// compare Rr vs Rd\n+\t\t\",\"\t\t\t\t// clean stack result\n+\t\t\"$z,zf,=,\"\t\t\t// zero flag (zf)\n+\t\t\"r%d,r%d,^,0x08,&,!,!,hf,=,\"\t// half carry flag (hf)\n+\t\t\"r%d,r%d,^,0x80,&,!,!,cf,=,\"\t// carry flag (cf)\n+\t\t\"$o,vf,=,\"\t\t\t// overflow flag (vf)\n+\t\t\"r%d,r%d,-,0x80,&,!,!,nf,=,\"\t// neg flg: result's MSB is set\n+\t\t\"vf,nf,^,sf,=\",\t\t\t// sign flag: xor(vf, nf)\n+\t\tr, d, r, d, r, d, r, d);\n+\t\t//\"r%d,r%d,==,\"\t\t\t// compare Rr vs Rd\n+\t\t//\"$z,zf,=,\"\t\t\t// zero flag (zf)\n+\t\t//\"$b3,hf,=,\"\t\t\t// half carry flag (hf)\n+\t\t//\"$b8,cf,=,\"\t\t\t// carry flag (cf)\n+\t\t//\"$o,vf,=,\"\t\t\t// overflow flag (vf)\n+\t\t//\"r%d,r%d,-,0x80,&,!,!,nf,=,\"\t// neg flg: result's MSB is set\n+\t\t//\"vf,nf,^,sf,=\",\t\t\t// sign flag: xor(vf, nf)\n+}\n+\n+INST_HANDLER (cpc) {\n+\tint r = (buf[0]        & 0x0f) | ((buf[1] << 3) & 0x10);\n+\tint d = ((buf[0] >> 4) & 0x0f) | ((buf[1] << 4) & 0x10);\n+\tr_strbuf_setf (\n+\t\t&op->esil,\n+\t\t\"r%d,cf,r%d,-,0xff,&,-,\"\t// ((Rd - C) & 0xff) - Rr\n+\t\t\"0x80,&,!,!,nf,=,\"\t\t// nef flg: result's MSB is set\n+\t\t\"r%d,cf,r%d,-,0xff,&,==,\"\t// ((Rd - C) & 0xff) == Rr\n+\t\t\"$z,zf,=,\"\t\t\t// zero flag\n+\t\t\"$b8,cf,=,\"\t\t\t// carry flag\n+\t\t\"$b3,hf,=,\"\t\t\t// half carry flag\n+\t\t\"$o,vf,=,\"\t\t\t// overflow flag\n+\t\t\"vf,nf,^,sf,=\",\t\t\t// sign flag : xor(vf, nf)\n+\t\tr, d, r, d);\n+}\n+\n+// ALIAS: Opcode (clr) when Rra and Rrb are the same\n+INST_HANDLER (eor) {\n+\tint d = ((buf[0] & 0xf0) >> 4) | ((buf[1] & 1) << 4);\n+\tint r = (buf[0] & 0xf) | ((buf[1] & 2) << 3);\n+\tr_strbuf_setf (&op->esil, \"r%d,r%d,^=,$z,zf,=,r%d,0x80,&,!,!,nf,=,nf,sf,=,0,vf,=\", r, d, d);\n+}\n+\n+INST_HANDLER (movw) {\n+\tint d = (buf[0] & 0xf0) >> 3;\n+\tint r = (buf[0] & 0x0f) << 1;\n+\tr_strbuf_setf (&op->esil, \"r%d,r%d,=,r%d,r%d,=\", r, d, r + 1, d + 1);\n+}\n+\n+INST_HANDLER (nop) {\n+}\n+\n+INST_HANDLER (out) {\n+\tint r = ((buf[0] >> 4) & 0x0f) | ((buf[1] & 0x01) << 4);\n+\tint v = (buf[0] & 0x0f) | (((buf[1] >> 1) & 0x03) << 4);\n+\top->type2 = 1;\n+\top->val = v;\n+\tswitch (v) {\n+\tcase 0x3f: /* SREG */ r_strbuf_setf (&op->esil, \"r%d,sreg,=\", r); break;\n+\tcase 0x3e: /* SPH  */ r_strbuf_setf (&op->esil, \"r%d,sph,=\",  r); break;\n+\tcase 0x3d: /* SPL  */ r_strbuf_setf (&op->esil, \"r%d,spl,=\",  r); break;\n+\tdefault:\n+\t\tr_strbuf_setf (&op->esil, \"2,$\");\n+\t}\n+}\n+\n+INST_HANDLER (rcall) {\n+\tut32 offset;","path":"libr/anal/p/anal_avr.c","position":125,"original_position":125,"commit_id":"8ab68f56682ccdf80c1304e08109d9f6632590a1","original_commit_id":"8ab68f56682ccdf80c1304e08109d9f6632590a1","user":{"login":"killabytenow","id":1439575,"avatar_url":"https://avatars.githubusercontent.com/u/1439575?v=3","gravatar_id":"","url":"https://api.github.com/users/killabytenow","html_url":"https://github.com/killabytenow","followers_url":"https://api.github.com/users/killabytenow/followers","following_url":"https://api.github.com/users/killabytenow/following{/other_user}","gists_url":"https://api.github.com/users/killabytenow/gists{/gist_id}","starred_url":"https://api.github.com/users/killabytenow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/killabytenow/subscriptions","organizations_url":"https://api.github.com/users/killabytenow/orgs","repos_url":"https://api.github.com/users/killabytenow/repos","events_url":"https://api.github.com/users/killabytenow/events{/privacy}","received_events_url":"https://api.github.com/users/killabytenow/received_events","type":"User","site_admin":false},"body":"fixed","created_at":"2016-09-16T10:01:39Z","updated_at":"2016-09-16T10:01:39Z","html_url":"https://github.com/radare/radare2/pull/5783#discussion_r79140047","pull_request_url":"https://api.github.com/repos/radare/radare2/pulls/5783","_links":{"self":{"href":"https://api.github.com/repos/radare/radare2/pulls/comments/79140047"},"html":{"href":"https://github.com/radare/radare2/pull/5783#discussion_r79140047"},"pull_request":{"href":"https://api.github.com/repos/radare/radare2/pulls/5783"}}},"pull_request":{"url":"https://api.github.com/repos/radare/radare2/pulls/5783","id":85546168,"html_url":"https://github.com/radare/radare2/pull/5783","diff_url":"https://github.com/radare/radare2/pull/5783.diff","patch_url":"https://github.com/radare/radare2/pull/5783.patch","issue_url":"https://api.github.com/repos/radare/radare2/issues/5783","number":5783,"state":"open","locked":false,"title":"New opcodes and operations in AVR anal plugin.","user":{"login":"killabytenow","id":1439575,"avatar_url":"https://avatars.githubusercontent.com/u/1439575?v=3","gravatar_id":"","url":"https://api.github.com/users/killabytenow","html_url":"https://github.com/killabytenow","followers_url":"https://api.github.com/users/killabytenow/followers","following_url":"https://api.github.com/users/killabytenow/following{/other_user}","gists_url":"https://api.github.com/users/killabytenow/gists{/gist_id}","starred_url":"https://api.github.com/users/killabytenow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/killabytenow/subscriptions","organizations_url":"https://api.github.com/users/killabytenow/orgs","repos_url":"https://api.github.com/users/killabytenow/repos","events_url":"https://api.github.com/users/killabytenow/events{/privacy}","received_events_url":"https://api.github.com/users/killabytenow/received_events","type":"User","site_admin":false},"body":"Here follows a pull request for starting a rewriting and refactorization of the AVR anal plugin. Currently is not complete but it establishes the base that I will follow next days/commits.\r\n\r\nAnyway is better than previous implementation and now it is executing some little AVR programs.\r\n\r\nIf you want to test it, doesnt forget to execute the following statements before:\r\n\r\naeim 0x00010000 0x01ff eeprom\r\naeim 0x00010200 0xffff sram\r\n","created_at":"2016-09-16T09:54:16Z","updated_at":"2016-09-16T10:01:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de820b2653c3dc8994e444be3297e8d98bd8f210","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/radare/radare2/pulls/5783/commits","review_comments_url":"https://api.github.com/repos/radare/radare2/pulls/5783/comments","review_comment_url":"https://api.github.com/repos/radare/radare2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/radare/radare2/issues/5783/comments","statuses_url":"https://api.github.com/repos/radare/radare2/statuses/8ab68f56682ccdf80c1304e08109d9f6632590a1","head":{"label":"killabytenow:ramera","ref":"ramera","sha":"8ab68f56682ccdf80c1304e08109d9f6632590a1","user":{"login":"killabytenow","id":1439575,"avatar_url":"https://avatars.githubusercontent.com/u/1439575?v=3","gravatar_id":"","url":"https://api.github.com/users/killabytenow","html_url":"https://github.com/killabytenow","followers_url":"https://api.github.com/users/killabytenow/followers","following_url":"https://api.github.com/users/killabytenow/following{/other_user}","gists_url":"https://api.github.com/users/killabytenow/gists{/gist_id}","starred_url":"https://api.github.com/users/killabytenow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/killabytenow/subscriptions","organizations_url":"https://api.github.com/users/killabytenow/orgs","repos_url":"https://api.github.com/users/killabytenow/repos","events_url":"https://api.github.com/users/killabytenow/events{/privacy}","received_events_url":"https://api.github.com/users/killabytenow/received_events","type":"User","site_admin":false},"repo":{"id":68368204,"name":"radare2","full_name":"killabytenow/radare2","owner":{"login":"killabytenow","id":1439575,"avatar_url":"https://avatars.githubusercontent.com/u/1439575?v=3","gravatar_id":"","url":"https://api.github.com/users/killabytenow","html_url":"https://github.com/killabytenow","followers_url":"https://api.github.com/users/killabytenow/followers","following_url":"https://api.github.com/users/killabytenow/following{/other_user}","gists_url":"https://api.github.com/users/killabytenow/gists{/gist_id}","starred_url":"https://api.github.com/users/killabytenow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/killabytenow/subscriptions","organizations_url":"https://api.github.com/users/killabytenow/orgs","repos_url":"https://api.github.com/users/killabytenow/repos","events_url":"https://api.github.com/users/killabytenow/events{/privacy}","received_events_url":"https://api.github.com/users/killabytenow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/killabytenow/radare2","description":"unix-like reverse engineering framework and commandline tools","fork":true,"url":"https://api.github.com/repos/killabytenow/radare2","forks_url":"https://api.github.com/repos/killabytenow/radare2/forks","keys_url":"https://api.github.com/repos/killabytenow/radare2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/killabytenow/radare2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/killabytenow/radare2/teams","hooks_url":"https://api.github.com/repos/killabytenow/radare2/hooks","issue_events_url":"https://api.github.com/repos/killabytenow/radare2/issues/events{/number}","events_url":"https://api.github.com/repos/killabytenow/radare2/events","assignees_url":"https://api.github.com/repos/killabytenow/radare2/assignees{/user}","branches_url":"https://api.github.com/repos/killabytenow/radare2/branches{/branch}","tags_url":"https://api.github.com/repos/killabytenow/radare2/tags","blobs_url":"https://api.github.com/repos/killabytenow/radare2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/killabytenow/radare2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/killabytenow/radare2/git/refs{/sha}","trees_url":"https://api.github.com/repos/killabytenow/radare2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/killabytenow/radare2/statuses/{sha}","languages_url":"https://api.github.com/repos/killabytenow/radare2/languages","stargazers_url":"https://api.github.com/repos/killabytenow/radare2/stargazers","contributors_url":"https://api.github.com/repos/killabytenow/radare2/contributors","subscribers_url":"https://api.github.com/repos/killabytenow/radare2/subscribers","subscription_url":"https://api.github.com/repos/killabytenow/radare2/subscription","commits_url":"https://api.github.com/repos/killabytenow/radare2/commits{/sha}","git_commits_url":"https://api.github.com/repos/killabytenow/radare2/git/commits{/sha}","comments_url":"https://api.github.com/repos/killabytenow/radare2/comments{/number}","issue_comment_url":"https://api.github.com/repos/killabytenow/radare2/issues/comments{/number}","contents_url":"https://api.github.com/repos/killabytenow/radare2/contents/{+path}","compare_url":"https://api.github.com/repos/killabytenow/radare2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/killabytenow/radare2/merges","archive_url":"https://api.github.com/repos/killabytenow/radare2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/killabytenow/radare2/downloads","issues_url":"https://api.github.com/repos/killabytenow/radare2/issues{/number}","pulls_url":"https://api.github.com/repos/killabytenow/radare2/pulls{/number}","milestones_url":"https://api.github.com/repos/killabytenow/radare2/milestones{/number}","notifications_url":"https://api.github.com/repos/killabytenow/radare2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/killabytenow/radare2/labels{/name}","releases_url":"https://api.github.com/repos/killabytenow/radare2/releases{/id}","deployments_url":"https://api.github.com/repos/killabytenow/radare2/deployments","created_at":"2016-09-16T09:35:33Z","updated_at":"2016-09-16T09:35:43Z","pushed_at":"2016-09-16T09:53:23Z","git_url":"git://github.com/killabytenow/radare2.git","ssh_url":"git@github.com:killabytenow/radare2.git","clone_url":"https://github.com/killabytenow/radare2.git","svn_url":"https://github.com/killabytenow/radare2","homepage":"http://www.radare.org/","size":80572,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"radare:master","ref":"master","sha":"f596505c1751bfc4c61a22f1b318c3d288b1b27a","user":{"login":"radare","id":917142,"avatar_url":"https://avatars.githubusercontent.com/u/917142?v=3","gravatar_id":"","url":"https://api.github.com/users/radare","html_url":"https://github.com/radare","followers_url":"https://api.github.com/users/radare/followers","following_url":"https://api.github.com/users/radare/following{/other_user}","gists_url":"https://api.github.com/users/radare/gists{/gist_id}","starred_url":"https://api.github.com/users/radare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radare/subscriptions","organizations_url":"https://api.github.com/users/radare/orgs","repos_url":"https://api.github.com/users/radare/repos","events_url":"https://api.github.com/users/radare/events{/privacy}","received_events_url":"https://api.github.com/users/radare/received_events","type":"User","site_admin":false},"repo":{"id":4869294,"name":"radare2","full_name":"radare/radare2","owner":{"login":"radare","id":917142,"avatar_url":"https://avatars.githubusercontent.com/u/917142?v=3","gravatar_id":"","url":"https://api.github.com/users/radare","html_url":"https://github.com/radare","followers_url":"https://api.github.com/users/radare/followers","following_url":"https://api.github.com/users/radare/following{/other_user}","gists_url":"https://api.github.com/users/radare/gists{/gist_id}","starred_url":"https://api.github.com/users/radare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radare/subscriptions","organizations_url":"https://api.github.com/users/radare/orgs","repos_url":"https://api.github.com/users/radare/repos","events_url":"https://api.github.com/users/radare/events{/privacy}","received_events_url":"https://api.github.com/users/radare/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/radare/radare2","description":"unix-like reverse engineering framework and commandline tools","fork":false,"url":"https://api.github.com/repos/radare/radare2","forks_url":"https://api.github.com/repos/radare/radare2/forks","keys_url":"https://api.github.com/repos/radare/radare2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/radare/radare2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/radare/radare2/teams","hooks_url":"https://api.github.com/repos/radare/radare2/hooks","issue_events_url":"https://api.github.com/repos/radare/radare2/issues/events{/number}","events_url":"https://api.github.com/repos/radare/radare2/events","assignees_url":"https://api.github.com/repos/radare/radare2/assignees{/user}","branches_url":"https://api.github.com/repos/radare/radare2/branches{/branch}","tags_url":"https://api.github.com/repos/radare/radare2/tags","blobs_url":"https://api.github.com/repos/radare/radare2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/radare/radare2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/radare/radare2/git/refs{/sha}","trees_url":"https://api.github.com/repos/radare/radare2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/radare/radare2/statuses/{sha}","languages_url":"https://api.github.com/repos/radare/radare2/languages","stargazers_url":"https://api.github.com/repos/radare/radare2/stargazers","contributors_url":"https://api.github.com/repos/radare/radare2/contributors","subscribers_url":"https://api.github.com/repos/radare/radare2/subscribers","subscription_url":"https://api.github.com/repos/radare/radare2/subscription","commits_url":"https://api.github.com/repos/radare/radare2/commits{/sha}","git_commits_url":"https://api.github.com/repos/radare/radare2/git/commits{/sha}","comments_url":"https://api.github.com/repos/radare/radare2/comments{/number}","issue_comment_url":"https://api.github.com/repos/radare/radare2/issues/comments{/number}","contents_url":"https://api.github.com/repos/radare/radare2/contents/{+path}","compare_url":"https://api.github.com/repos/radare/radare2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/radare/radare2/merges","archive_url":"https://api.github.com/repos/radare/radare2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/radare/radare2/downloads","issues_url":"https://api.github.com/repos/radare/radare2/issues{/number}","pulls_url":"https://api.github.com/repos/radare/radare2/pulls{/number}","milestones_url":"https://api.github.com/repos/radare/radare2/milestones{/number}","notifications_url":"https://api.github.com/repos/radare/radare2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/radare/radare2/labels{/name}","releases_url":"https://api.github.com/repos/radare/radare2/releases{/id}","deployments_url":"https://api.github.com/repos/radare/radare2/deployments","created_at":"2012-07-03T07:42:26Z","updated_at":"2016-09-16T08:21:33Z","pushed_at":"2016-09-16T09:54:16Z","git_url":"git://github.com/radare/radare2.git","ssh_url":"git@github.com:radare/radare2.git","clone_url":"https://github.com/radare/radare2.git","svn_url":"https://github.com/radare/radare2","homepage":"http://www.radare.org/","size":80572,"stargazers_count":3233,"watchers_count":3233,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":731,"mirror_url":null,"open_issues_count":820,"forks":731,"open_issues":820,"watchers":3233,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/radare/radare2/pulls/5783"},"html":{"href":"https://github.com/radare/radare2/pull/5783"},"issue":{"href":"https://api.github.com/repos/radare/radare2/issues/5783"},"comments":{"href":"https://api.github.com/repos/radare/radare2/issues/5783/comments"},"review_comments":{"href":"https://api.github.com/repos/radare/radare2/pulls/5783/comments"},"review_comment":{"href":"https://api.github.com/repos/radare/radare2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/radare/radare2/pulls/5783/commits"},"statuses":{"href":"https://api.github.com/repos/radare/radare2/statuses/8ab68f56682ccdf80c1304e08109d9f6632590a1"}}}}
{"actor":{"display_login":"killabytenow"}}