magic8421
发表于 2024-9-4 19:26:24
本帖最后由 magic8421 于 2024-9-4 19:32 编辑
sdcc 是没有overlay功能的 翻遍了官网也没找到这功能
所以项目大一点就得用 --mode-large --stack-auto 这样
不然内部内存总是不够得
说起来你可能不信 他就是一个变量占一个内存 占完就编译不过 不存在keil那种local变量只要没有调用关系就可以共享的
大锤子
发表于 2024-9-5 10:57:37
magic8421 发表于 2024-9-4 19:26
sdcc 是没有overlay功能的 翻遍了官网也没找到这功能
所以项目大一点就得用 --mode-large --stack-auto 这 ...
应该有吧, 看啥sdcc的用户手册3.7
3.7 Overlaying
For non-reentrant functions SDCC will try to reduce internal ram space usage by overlaying parameters and local
variables of a function (if possible). Parameters and local variables of a function will be allocated to an overlayable
segment if the function has no other function calls and the function is non-reentrant and the memory model is small.
If an explicit intrinsic named address space is specified for a local variable, it will NOT be overlaid.
Note that the compiler (not the linkage editor) makes the decision for overlaying the data items. Functions that
are called from an interrupt service routine should be preceded by a #pragma nooverlay if they are not reentrant. !
Also note that the compiler does not do any processing of inline assembler code, so the compiler might incorrectly
assign local variables and parameters of a function into the overlay segment if the inline assembler code calls
other c-functions that might use the overlay. In that case the #pragma nooverlay should be used.
Parameters and local variables of functions that contain 16 or 32 bit multiplication or division will NOT be
overlaid since these are implemented using external functions, e.g.:
#pragma save
#pragma nooverlay
void set_error(unsigned char errcd)
{
P3 = errcd;
}
#pragma restore
void some_isr () __interrupt (2)
{
...
set_error(10);
...
}
In the above example the parameter errcd for the function set_error would be assigned to the overlayable segment
if the #pragma nooverlay was not present, this could cause unpredictable runtime behaviour when called from an
interrupt service routine. The #pragma nooverlay ensures that the parameters and local variables for the function
are NOT overlaid.
magic8421
发表于 2024-9-5 18:20:54
大锤子 发表于 2024-9-5 10:57
应该有吧, 看啥sdcc的用户手册3.7
3.7 Overlaying
For non-reentrant functions SDCC will try to redu ...
这段我看了啊 只有leaf function会overlay
“if the function has no other function calls ”
大锤子
发表于 2024-9-5 22:39:35
magic8421 发表于 2024-9-5 18:20
这段我看了啊 只有leaf function会overlay
“if the function has no other function calls ”
...
哦, 也没啥问题吧。 现在的单片机速度和存储都够用了。 我目前也没有接触过大到不够用的情况。 而且一般直接设置成large模式。 在使用rtos的时候也需要使用auto-stack
magic8421
发表于 2024-9-6 10:26:26
本帖最后由 magic8421 于 2024-9-6 10:31 编辑
大锤子 发表于 2024-9-5 22:39
哦, 也没啥问题吧。 现在的单片机速度和存储都够用了。 我目前也没有接触过大到不够用的情况。 而且一般 ...
large有个问题就是:当函数太复杂时会生成sloc临时变量,然而sloc是必须分配在在内部内存的,所以工程大了large也会导致无法编译 {:4_187:}
不需要太大工程rom用到20k的时候就会出现这问题sdcc太拉跨了 忍不住吐槽一下
大锤子
发表于 2024-9-6 10:43:26
magic8421 发表于 2024-9-6 10:26
large有个问题就是:当函数太复杂时会生成sloc临时变量,然而sloc是必须分配在在内部内存的,所以工程大了 ...
大佬研究这么深入,{:4_250:}
soma
发表于 2024-9-6 21:57:33
magic8421 发表于 2024-9-6 10:26
large有个问题就是:当函数太复杂时会生成sloc临时变量,然而sloc是必须分配在在内部内存的,所以工程大了 ...
看来sdcc只能玩玩啊,大项目还用不了