This shows you the differences between two versions of the page.
blog:pushbx:2022:0826_dual_code_segments_mechanisms [2022-08-26 01:21:03 +0200 Aug Fri] ecm created |
blog:pushbx:2022:0826_dual_code_segments_mechanisms [2022-08-26 21:37:33 +0200 Aug Fri] (current) ecm boot-loaded, far-like mode switching reworded, section_of for unused symbols, example |
||
---|---|---|---|
Line 41: | Line 41: | ||
for three reasons: | for three reasons: | ||
- | - Allowing boot loaded mode where no MZ loader is used. | + | - Allowing boot-loaded mode where no MZ loader is used. |
- Allowing the debugger to be compressed without parsing relocations into the depacker. | - Allowing the debugger to be compressed without parsing relocations into the depacker. | ||
- Allowing to dynamically determine the layout and placement of the code segments at run time instead of leaving them fixed relative to the PSP. | - Allowing to dynamically determine the layout and placement of the code segments at run time instead of leaving them fixed relative to the PSP. | ||
Line 73: | Line 73: | ||
The dual return helper examines the index and replaces it | The dual return helper examines the index and replaces it | ||
by the desired segment or selector to which to return. | by the desired segment or selector to which to return. | ||
- | This complication | + | This complication |
- | which switch modes in the debugger' | + | to switch modes |
+ | (from Real/ | ||
+ | The possible need for this was determined | ||
+ | important enough | ||
+ | although no current users are known. | ||
The index supports both modes. | The index supports both modes. | ||
An actual segment or selector value is inserted to replace | An actual segment or selector value is inserted to replace | ||
Line 89: | Line 93: | ||
The '' | The '' | ||
to verify that the correct section was specified. | to verify that the correct section was specified. | ||
+ | |||
+ | '' | ||
+ | does not exist, for example when it is not included | ||
+ | due to the current build options. | ||
+ | A label specified with the '' | ||
+ | however, must correspond to an earlier use of '' | ||
+ | |||
+ | |||
+ | ===== Examples ===== | ||
+ | |||
+ | This example is based on | ||
+ | [[https:// | ||
+ | that introduced the dual code sections support. | ||
+ | This is what the '' | ||
+ | as a normal, near-callable function | ||
+ | within the single '' | ||
+ | |||
+ | < | ||
+ | lframe near | ||
+ | lpar word, sign | ||
+ | lenter | ||
+ | mov ax, word [bp + ?sign] | ||
+ | mov di, msg.bu_relocated.sign | ||
+ | call hexword | ||
+ | mov dx, msg.bu_relocated | ||
+ | call putsz | ||
+ | lleave | ||
+ | lret</ | ||
+ | |||
+ | Note that this hardcodes a near stack frame. And this is how it would be called: | ||
+ | |||
+ | < | ||
+ | push ax | ||
+ | call bu_relocated</ | ||
+ | |||
+ | Next, here's how to change it to a dual-callable function | ||
+ | which goes into the '' | ||
+ | if that is used: | ||
+ | |||
+ | < | ||
+ | usesection lDEBUG_CODE2 | ||
+ | %endif | ||
+ | |||
+ | section_of bu_relocated | ||
+ | dualfunction | ||
+ | bu_relocated: | ||
+ | lframe dualdistance | ||
+ | lpar word, sign | ||
+ | lenter | ||
+ | mov ax, word [bp + ?sign] | ||
+ | mov di, msg.bu_relocated.sign | ||
+ | nearcall hexword | ||
+ | mov dx, msg.bu_relocated | ||
+ | nearcall putsz | ||
+ | lleave | ||
+ | dualreturn | ||
+ | lret</ | ||
+ | |||
+ | And this is a caller: | ||
+ | |||
+ | < | ||
+ | push ax | ||
+ | dualcall bu_relocated</ | ||
+ | |||
+ | Note the uses of '' | ||
+ | When this source is compiled with dual code segments enabled, | ||
+ | the distance of the stack frame will be far instead. | ||
+ | If the build is DPMI-capable then | ||
+ | the '' | ||
+ | will push a far-like return address, | ||
+ | which the '' | ||
+ | convert into a segmented far return address. | ||
+ | The '' | ||
+ | |||
+ | Converting function calls to use the '' | ||
+ | only involves replacing plain '' | ||
+ | by the '' | ||
+ | as well as specifying the correct sections | ||
+ | with '' | ||
+ | As mentioned, a function must not use '' | ||
+ | on its stack in order to call it using '' | ||
+ | |||
{{tag> | {{tag> |