open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
958 stars 157 forks source link

__saveregs keyword means 3 different things in 3 different places? #667

Closed tkchia closed 3 years ago

tkchia commented 3 years ago

Good day,

I have been trying to use Open Watcom's __saveregs keyword, but I am confused about what it is supposed to do.

The User's Guide (cguide.pdf) says

Open Watcom C/C++ recognizes the __saveregs keyword which is an attribute used by C/C++ compilers to describe a function that must save and restore all registers.

while the Language Reference (clr.pdf) says

The __saveregs keyword may be used with functions. It is provided for compatibility with Microsoft C, and has no effect in Open Watcom Cⁱ⁶ and C³².

Meanwhile, for the actual implementation of __saveregs (as of 2.0 beta May 17 2020), it seems the compiler does add some code to save registers --- but only the segment registers.

I think it will be good to clear up what the "correct" intended meaning of __saveregs really is.

Thank you!

jmalak commented 3 years ago

Thanks for this report. It is really wrong in "Language reference" guide. __saveregs means to save all segment registers.

tkchia commented 3 years ago

Hello @jmalak,

Is __saveregs supposed to save other registers too --- e.g. the general purpose registers and flags register?

Thank you!

jmalak commented 3 years ago

No it is only for segment register. If you want to save all registers and flags then you can specify function with __interrupt modifier and specify INTPACK structure as parameter then you can access all register on entry and on exit.

void __interrupt int10( union INTPACK r )

Use of such function is described in OW guide.

tkchia commented 3 years ago

Hello @jmalak,

Thanks for the clarification!