LWDR (Light Weight D Runtime) for Microcontrollers v0.2.3

Iain Buclaw ibuclaw at gdcproject.org
Mon May 31 11:16:01 UTC 2021


On Monday, 31 May 2021 at 01:05:03 UTC, Dylan Graham wrote:
> On Sunday, 30 May 2021 at 17:31:37 UTC, Dukc wrote:
>> On Sunday, 30 May 2021 at 14:28:25 UTC, Dylan Graham wrote:
>>>
>>> It works by providing a series of barebones API hooks (alloc, 
>>> dealloc, assert, etc) (defined in `rtoslink.d`), which you 
>>> must implement and/or point to your RTOS implementation.
>>
>> Quickly looking, the implementation looks very portable, save 
>> for exceptions. with `rtoslink.d`, this will probably enable a 
>> lot of stuff on any platform without DRuntime. Not just 
>> microcontrollers. If I'm right, you just did a BIG service for 
>> D on bare-metal.
>>
>
> Exceptions are a nightmare. It works for GDC with GCC code. My 
> codebase uses GCC for its C (ST toolchain), so I need to write 
> some code that can take LDC's exception handling and make it 
> compatible with how GCC operates. So, it looks like there will 
> be multiple exception handling implementations (LDC with GCC 
> backend, LDC with clang backend, GDC with GCC backend). I wish 
> D had something like Zig's error handling.
>
> Otherwise, thank you! It was designed to be agnostic as much as 
> possible. I didn't know it'd help out for more than just 
> microcontrollers :)

Good to see this work come to fruition.  First thing I stumbled 
across was a 
[mispelling](https://github.com/0dyl/LWDR/blob/eb5de110ba2cff4bd0e654e8a68b59fc5eb76157/source/rtoslink.d#L14) of one of the RTOS hooks.

Regarding exceptions, apart from one small detail I'd have 
thought that GDC and LDC would be compatible, as both just use 
libunwind.  Said small detail are the name of the entry-points 
for the "throw" and "personality" routines.  Both of which can be 
sorted out trivially with some stubs to forward from one to the 
other.

```
extern(C) void _d_throw(Throwable o) { return _d_throw_common(o); 
}
extern(C) void _d_throw_exception(Throwable o) { return 
_d_throw_common(o); }

extern(C) void _d_throw_common(Throwable o)
{
    pragma(inline, false);
    // Implementation here: tail merging should take care of the 
entrypoints.
}
```


More information about the Digitalmars-d-announce mailing list