Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/manual/embedded.md
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,7 @@ what it calls:
string in flash. A floating-point conversion prints `?`, as avr-libc's
does without `-lprintf_flt`; EmbCC has no `printf_flt`;
- the `<avr/eeprom.h>` functions;
- `errno`, with one value for the program (AVR has no threads of its own);
- `setjmp` and `longjmp`, with a 24-byte `jmp_buf`: r2-r17, Y, the stack
pointer, SREG and the return address.

Expand Down
6 changes: 6 additions & 0 deletions lib/avr/errno.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* AVR has no threads of its own, so errno is one value for the program. */
#include <errno.h>

static int g_errno;

int *__errno_location(void) { return &g_errno; }
1 change: 1 addition & 0 deletions tests/golden/avr-libc-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ done
${CC:-cc} -w -I$D $D/host.c -o "$out/host" || fail "the host program"
"$out/host" > "$out/host.txt" || fail "the host program does not run"
{ cat <<'EOF'
errno 34
byte 22 fe word 1234 beef
dword 89abcdef qword 102030405060708 float 5
ptr world
Expand Down
4 changes: 4 additions & 0 deletions tests/golden/avr-libc-run/prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* and the _P functions, and the printf family, on QEMU's ATmega328P. */
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

Expand Down Expand Up @@ -33,6 +34,9 @@ int main(void)
UCSR0B = _BV(TXEN0);
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);

errno = ERANGE;
SHOW("errno %d", errno);

/* pgm_read_* */
SHOW("byte %x %x word %x %x", pgm_read_byte(&bytes[1]), pgm_read_byte(&bytes[3]),
pgm_read_word(&words[0]), pgm_read_word(&words[1]));
Expand Down