Since I'm intimately working with the modules these days... I wonder (and hopefully someone else will find this useful, too): what's the real difference between .PRG and .SYS? I can see it in MODSTART.S but I don't understand it: why the division between a module and .PRG? What does Pure C startup/exit code so offensive that it had to be replaced with custom Mshrink / Pterm* ?
Is it just a size optimisation?
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?
Regarding modules and a program for the AUTO folder: The memory management has to be different, due to how the TOS boot process works. Please see the README file in the MODULES folder on GitHub. MODSTART helps dealing with this difference. Whether you use MODSTART is up to you. I provide it for convenience, to help implementing modules. If you do not use it and there are issues with your code and a potentially later version of the module API it's not my problem, though ;-).
-
mikro
- Posts: 32
- Joined: 18 May 2010, 10:09
Re: HD Driver modules: what's the difference?
After reading the README I'm even more confused. It states:
Modules implemented in assembler are launched by calling their start
address + 4. They have to free any unused memory and must terminate with
RTS. They must not execute any Pterm*() call.
On the other hand, the (C, admittelly) SAMPLE module explicitly terminates with:
Why is that? That C code must be translated to basically identical asm code which I would write if I wanted to create a simple "Hello world" so I really don't get the difference?
EDIT: Just to answer my previous question, now I see that the MODSTART.S doesn't do Mshrink(), in the contrary, it does *not* do it, it just clears the BSS segment. So that's the main difference there but I still don't get the Pterm* part.
Modules implemented in assembler are launched by calling their start
address + 4. They have to free any unused memory and must terminate with
RTS. They must not execute any Pterm*() call.
On the other hand, the (C, admittelly) SAMPLE module explicitly terminates with:
Code: Select all
/* A non-resident module has to terminate with Pterm*() */
if(isHddriverModule()) {
Pterm0();
}
EDIT: Just to answer my previous question, now I see that the MODSTART.S doesn't do Mshrink(), in the contrary, it does *not* do it, it just clears the BSS segment. So that's the main difference there but I still don't get the Pterm* part.
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
I may have to make this clearer in the README. The main point is not whether a module is in assembler or C, but whether it uses MODSTART or not, which I guess modules especially in assembler tend not to do, but should. For modules MODSTART.S overrides Pterm*, so that the regular system counterparts are not called. Please see MODSTART.S for details.
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
I have just updated the modules README to make things clearer. But even before the update it pointed out to study MODSTART.S ...
-
mikro
- Posts: 32
- Joined: 18 May 2010, 10:09
Re: HD Driver modules: what's the difference?
Oh wait. Now I see the source of my confusion. You named your custom functions in MODSTART.S as Pterm0(), Pterm() and Ptermres() and SAMPLE.C calls THESE instead of system functions from tos.h. That was... unexpected.
And to make it even more confusing, you call it only in case of isHddriverModule(), so you are not even using the fallback code to trap #1 in MODSTART.S.
I would recommend to explain this up in README as well, for the whole time I expected Pterm0() in SAMPLE.C to call the trap #1, that's why I was wondering why you can't use just Pure C's exit code.
And to make it even more confusing, you call it only in case of isHddriverModule(), so you are not even using the fallback code to trap #1 in MODSTART.S.
I would recommend to explain this up in README as well, for the whole time I expected Pterm0() in SAMPLE.C to call the trap #1, that's why I was wondering why you can't use just Pure C's exit code.
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
OK, I will later also add a note in the README. But nevertheless, reading both the README and MODSTART.S is what I recommend.
I have to use the existing names, because I have to prevent that the original functions are called in the case of a module, but not in the case of a regular program.
I have to use the existing names, because I have to prevent that the original functions are called in the case of a module, but not in the case of a regular program.
-
mikro
- Posts: 32
- Joined: 18 May 2010, 10:09
Re: HD Driver modules: what's the difference?
What prevents you from calling Pure C's exit code from MODSTART.S? You are calling there jmp __text anyway, so it already has this dependency. That way you could
1. Call just exit_wrapper() by the end of main() without any checks
2. name it exit_wrapper and not Pterm0
(IMHO you do not need to support the scenario where SAMPLE.C is compiled without MODSTART.S)
1. Call just exit_wrapper() by the end of main() without any checks
2. name it exit_wrapper and not Pterm0
(IMHO you do not need to support the scenario where SAMPLE.C is compiled without MODSTART.S)
-
uweseimet
- Site Admin
- Posts: 408
- Joined: 10 Jan 2010, 15:39
Re: HD Driver modules: what's the difference?
Is there any description about exit_wrapper()? I don't want to use undocumented features/labels as far as I can avoid it.
-
mikro
- Posts: 32
- Joined: 18 May 2010, 10:09
Re: HD Driver modules: what's the difference?
That is a made up name to make my point, so you can name it anything but Pterm0.