HD Driver modules: what's the difference?
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
I'm afraid I have no idea what the Pure C exit code does. Is this documented somewhere?
-
mikro
- Posts: 32
- Joined: 18 May 2010, 10:09
Re: HD Driver modules: what's the difference?
I can look it up when I get home but I'm quite confident that same as it has the __text label it also has something like __exit or so. So your MODSTART.S would check for the module, if so, ending with RTS, if not, ending it with calling __exit.
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
I don't get your point. I want to replace the original Pterm* calls, just as the README and MODSTART.S say. How can I do that when using different names?
-
mikro
- Posts: 32
- Joined: 18 May 2010, 10:09
Re: HD Driver modules: what's the difference?
I don't get what you are not getting. ;)
Right now we have:
- SAMPLE.C calling fake Pterm0() within main() if running as module, otherwise leaving to Pure C's exit code (let's assume the label is called "__exit" for now)
- MODSTART.S implementing the fake Pterm0() but SAMPLE.C still including <tos.h> because you want the function signatures (btw this is really dangerous, this wouldn't work with mintlib's osbind.h at all because it defines OS calls inline)
- we want it easier to understand what's going on there, apart from "read the source, README and watch out for every letter to avoid misunderstanding"
The solution to all of those is implementing a custom exit function, e.g. "exit_wrapper" so SAMPLE's main() would just call that at the end, no need to include <tos.h>, no need to branch based on the module presence.
exit_wrapper in MODSTART.S would then do: if (module) then do the houskeeping + rts else jmp __exit.
Does it make more sense now?
Right now we have:
- SAMPLE.C calling fake Pterm0() within main() if running as module, otherwise leaving to Pure C's exit code (let's assume the label is called "__exit" for now)
- MODSTART.S implementing the fake Pterm0() but SAMPLE.C still including <tos.h> because you want the function signatures (btw this is really dangerous, this wouldn't work with mintlib's osbind.h at all because it defines OS calls inline)
- we want it easier to understand what's going on there, apart from "read the source, README and watch out for every letter to avoid misunderstanding"
The solution to all of those is implementing a custom exit function, e.g. "exit_wrapper" so SAMPLE's main() would just call that at the end, no need to include <tos.h>, no need to branch based on the module presence.
exit_wrapper in MODSTART.S would then do: if (module) then do the houskeeping + rts else jmp __exit.
Does it make more sense now?
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
Where is __exit documented?
How would this wrapper know which Pterm* flavor has been called? The code to be exuted depends on it.
Replacing Pterm* also ensures that a module terminates correctly when it simply calls Pterm0() at it's end. This is legal, at least with TOS, isn't it? If the sample module was not checking whether it was running as a module but was just calling Pterm0(), the current approach is still fine for a module, and it would also be fine for a program in the AUTO folder.
How would this wrapper know which Pterm* flavor has been called? The code to be exuted depends on it.
Replacing Pterm* also ensures that a module terminates correctly when it simply calls Pterm0() at it's end. This is legal, at least with TOS, isn't it? If the sample module was not checking whether it was running as a module but was just calling Pterm0(), the current approach is still fine for a module, and it would also be fine for a program in the AUTO folder.
-
mikro
- Posts: 32
- Joined: 18 May 2010, 10:09
Re: HD Driver modules: what's the difference?
And is __text somewhere officially documented as free to use in your programs? So that's my argument for __exit (or whatever its name is).
===
They must not execute any Pterm*() call.
===
So they mustn't, shouldn't or could execute it? (EDIT: to avoid further arguments, yes, that was related to modules without MODSTART.S but it really doesn't add clarity to the problem)
Right now, I'm fully versed with module's quirks but I'm arguing in favour of new programmers who can be as confused as I was.
Okay, yes, true. But then you are arguing against yourself, in the very README which you recommended me to follow:uweseimet wrote: 24 Jan 2025, 14:37If the sample module was not checking whether it was running as a module but was just calling Pterm0(), the current approach is still fine for a module
===
They must not execute any Pterm*() call.
===
So they mustn't, shouldn't or could execute it? (EDIT: to avoid further arguments, yes, that was related to modules without MODSTART.S but it really doesn't add clarity to the problem)
Right now, I'm fully versed with module's quirks but I'm arguing in favour of new programmers who can be as confused as I was.
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
> And is __text somewhere officially documented as free to use in your programs?
I think I have already commented on this earlier.
You have not commented on this point, by the way:
> How would this wrapper know which Pterm* flavor has been called? The code to be exuted depends on it.
Regardless of what you are permitted or not permitted to do in a module, I wanted a certain degree of fault tolerance, which my approch provides at least for Pure C. People do not always properly read the docs.
I think I have already commented on this earlier.
You have not commented on this point, by the way:
> How would this wrapper know which Pterm* flavor has been called? The code to be exuted depends on it.
Regardless of what you are permitted or not permitted to do in a module, I wanted a certain degree of fault tolerance, which my approch provides at least for Pure C. People do not always properly read the docs.
-
mikro
- Posts: 32
- Joined: 18 May 2010, 10:09
Re: HD Driver modules: what's the difference?
By the end of the day, it will be you who is going to provide support for the modules, so sure, do what you consider best.
I was just curious about some design decisions and provided my POV on how it could be done in a more generic (albeit maybe less fault tolerant) way.
As for the Pterm flavours, of course each of them was meant to have its wrapper, so there would be three exit functions. It wasn't meant as rocket science, just to avoid the problematic Pterm0() call in main() (which, as I pointed out, is totally unusable on anything else than on Pure C so when people decide to use gcc + mintlib for module creation, many thing in README wouldn't apply anymore so there's hardly that much need for being 100% fault tolerant as it applies only to Pure C creations).
I was just curious about some design decisions and provided my POV on how it could be done in a more generic (albeit maybe less fault tolerant) way.
As for the Pterm flavours, of course each of them was meant to have its wrapper, so there would be three exit functions. It wasn't meant as rocket science, just to avoid the problematic Pterm0() call in main() (which, as I pointed out, is totally unusable on anything else than on Pure C so when people decide to use gcc + mintlib for module creation, many thing in README wouldn't apply anymore so there's hardly that much need for being 100% fault tolerant as it applies only to Pure C creations).
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
For GCC you need a different approach anyway when building modules, e.g. the stripex tool, don't you? If somebody uses GCC with the Atari I assume it is somebody who is aware of the differences between Pure C and GCC, and who knows that using GCC with the Atari might require more effort.