cirosantilli2 / issues

Hello! If you have anything to say to me, feel free to open an issue, and I will reply. For gem5 issues, prefer asking on Stack Overflow or the mailing list: https://www.gem5.org/mailing_lists/ or: https://github.com/cirosantilli2/gem5-issues
1 stars 0 forks source link

How to add a X86 instruction in gem5? #19

Open Taya666 opened 3 years ago

Taya666 commented 3 years ago

Hello cirosantilli2, I want to add a new X86 instruction in gem5. But it is so hard to trace how gem5 deal with instruction. I try to grep the source code and trace an instruction. But it is so hard to know where to start because gem5 generates related c++ code from .isa files. I can't figure out which source code is generated by gem5 and which is written by the coder. Could you give me some advice? Thank you so much!

cirosantilli2 commented 3 years ago

Taya,

I can't figure out which source code is generated by gem5 and which is written by the coder.

This part is fundamental: generated files won't be symlinks, in-tree files are symlinks.

As mentioned at https://cirosantilli.com/linux-kernel-module-cheat/#gem5-code-generation you can use grep -I -r build/ to exclude symlinks and binaries, and even more importantly (added now)

find build -type f

And overview of generated code can be found at: https://cirosantilli.com/linux-kernel-module-cheat/#gem5-instruction-definitions but that is very easy to figure out once you understand the symlink thing, don't be discouraged.

After that however instructions tend to be very similar between one another, and so their Python ISA code is very well factored, so it can be hard to find which Python code generates what. You really have to grep for part of instructions or the key line that they do at times.

Taya666 commented 3 years ago

Taya,

I can't figure out which source code is generated by gem5 and which is written by the coder.

This part is fundamental: generated files won't be symlinks, in-tree files are symlinks.

As mentioned at https://cirosantilli.com/linux-kernel-module-cheat/#gem5-code-generation you can use grep -I -r build/ to exclude symlinks and binaries, and even more importantly (added now)

find build -type f

And overview of generated code can be found at: https://cirosantilli.com/linux-kernel-module-cheat/#gem5-instruction-definitions but that is very easy to figure out once you understand the symlink thing, don't be discouraged.

After that however instructions tend to be very similar between one another, and so their Python ISA code is very well factored, so it can be hard to find which Python code generates what. You really have to grep for part of instructions or the key line that they do at times.

Thank you so much for your advice! I have learned how to add new instruction. But I am now getting stuck in using my new instruction in my program. How could I use my new ISA instruction in c/c++ program?

Taya666 commented 3 years ago

Taya,

I can't figure out which source code is generated by gem5 and which is written by the coder.

This part is fundamental: generated files won't be symlinks, in-tree files are symlinks. As mentioned at https://cirosantilli.com/linux-kernel-module-cheat/#gem5-code-generation you can use grep -I -r build/ to exclude symlinks and binaries, and even more importantly (added now)

find build -type f

And overview of generated code can be found at: https://cirosantilli.com/linux-kernel-module-cheat/#gem5-instruction-definitions but that is very easy to figure out once you understand the symlink thing, don't be discouraged. After that however instructions tend to be very similar between one another, and so their Python ISA code is very well factored, so it can be hard to find which Python code generates what. You really have to grep for part of instructions or the key line that they do at times.

Thank you so much for your advice! I have learned how to add new instruction. But I am now getting stuck in using my new instruction in my program. How could I use my new ISA instruction in c/c++ program?

Ok, I know how to do this by using the asm volatile(".byte... Thanks for your advice. It is really helpful.

cirosantilli2 commented 3 years ago

Great news!!

minhson commented 2 years ago

Taya,

I can't figure out which source code is generated by gem5 and which is written by the coder.

This part is fundamental: generated files won't be symlinks, in-tree files are symlinks. As mentioned at https://cirosantilli.com/linux-kernel-module-cheat/#gem5-code-generation you can use grep -I -r build/ to exclude symlinks and binaries, and even more importantly (added now)

find build -type f

And overview of generated code can be found at: https://cirosantilli.com/linux-kernel-module-cheat/#gem5-instruction-definitions but that is very easy to figure out once you understand the symlink thing, don't be discouraged. After that however instructions tend to be very similar between one another, and so their Python ISA code is very well factored, so it can be hard to find which Python code generates what. You really have to grep for part of instructions or the key line that they do at times.

Thank you so much for your advice! I have learned how to add new instruction. But I am now getting stuck in using my new instruction in my program. How could I use my new ISA instruction in c/c++ program?

Ok, I know how to do this by using the asm volatile(".byte... Thanks for your advice. It is really helpful.

Hello Taya666, Could you guide me on how to use my new ISA instruction in the c/c++ program in gem5? You mentioned "asm volatile(".byte", but i still do not know how to use it!

Thanks a lot!

cirosantilli2 commented 2 years ago

https://github.com/cirosantilli/linux-kernel-module-cheat/blob/b0f4f5ec4aac29d96aae2b0d1ad51da26f797218/userland/arch/x86_64/inline_asm/inc.c

cirosantilli2 commented 2 years ago

And https://stackoverflow.com/questions/7290318/what-is-the-use-of-byte-assembler-directive-in-gnu-assembly/33361074#33361074

minhson commented 2 years ago

Thank you for your information!

urev commented 2 years ago

I wonder how isa_parser.py generates the AddImm class. I found nothing related to AddImm class in the *.isa files. Can you give me some clues? @Taya666 @cirosantilli2

cirosantilli2 commented 2 years ago

gem5 C++ from ISA generation is very generic, they use unbarred Python string manipulation + some built-in insanity on the ISA parser.

If a full identifier is not found, you should try to grep for smaller parts of it, like \bimm\b and \badd\b case insensitive.