Skip to content

Commit 2074d8b

Browse files
meme8383keith-packard
authored andcommitted
Use code blocks
1 parent 158e5af commit 2074d8b

File tree

1 file changed

+67
-49
lines changed

1 file changed

+67
-49
lines changed

doc/os.md

Lines changed: 67 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,47 @@ pointers, and linker aliases may be used to make all three pointers be
2323
stored in the same location. The FILE object contains function
2424
pointers for putc, getc, which might be defined as follows:
2525

26-
static int
27-
sample_putc(char c, FILE *file)
28-
{
29-
(void) file; /* Not used in this function
30-
__uart_putc(c); /* Defined by underlying system */
31-
return c;
32-
}
33-
34-
static int
35-
sample_getc(FILE *file)
36-
{
37-
unsigned char c;
38-
(void) file; /* Not used in this function */
39-
c = __uart_getc(); /* Defined by underlying system */
40-
return c;
41-
}
26+
```c
27+
static int
28+
sample_putc(char c, FILE *file)
29+
{
30+
(void) file; /* Not used in this function
31+
__uart_putc(c); /* Defined by underlying system */
32+
return c;
33+
}
34+
35+
static int
36+
sample_getc(FILE *file)
37+
{
38+
unsigned char c;
39+
(void) file; /* Not used in this function */
40+
c = __uart_getc(); /* Defined by underlying system */
41+
return c;
42+
}
43+
```
4244
4345
It also contains a pointer to an optional `flush` function, which, if
4446
provide, will be called to flush pending output to the file, e.g.,
4547
when the `fflush()` function is called:
4648
47-
static int
48-
sample_flush(FILE *file)
49-
{
50-
/* This function doesn't need to do anything */
51-
(void) file; /* Not used in this function */
52-
return 0;
53-
}
49+
```c
50+
static int
51+
sample_flush(FILE *file)
52+
{
53+
/* This function doesn't need to do anything */
54+
(void) file; /* Not used in this function */
55+
return 0;
56+
}
57+
```
5458

5559
These functions are used to initialize a FILE structure:
5660

57-
static FILE __stdio = FDEV_SETUP_STREAM(sample_putc,
58-
sample_getc,
59-
NULL,
60-
_FDEV_SETUP_RW);
61+
```c
62+
static FILE __stdio = FDEV_SETUP_STREAM(sample_putc,
63+
sample_getc,
64+
NULL,
65+
_FDEV_SETUP_RW);
66+
```
6167

6268
This defines a FILE which can read and write characters using the putc
6369
and getc functions described above, but not using any flush
@@ -73,20 +79,24 @@ supported, can be one of the following:
7379
Finally, the FILE is used to initialize the `stdin`, `stdout` and
7480
`stderr` values, the latter two of which are simply aliases to `stdin`:
7581

76-
FILE *const stdin = &__stdio;
77-
__strong_reference(stdin, stdout);
78-
__strong_reference(stdin, stderr);
82+
```c
83+
FILE *const stdin = &__stdio;
84+
__strong_reference(stdin, stdout);
85+
__strong_reference(stdin, stderr);
86+
```
7987
8088
### fopen, fdopen
8189
8290
Support for these requires malloc/free along with a handful of
8391
POSIX-compatible functions:
8492
85-
int open (const char *, int, ...);
86-
int close (int fd);
87-
ssize_t read (int fd, void *buf, size_t nbyte);
88-
ssize_t write (int fd, const void *buf, size_t nbyte);
89-
off_t lseek (int fd, off_t offset, int whence);
93+
```c
94+
int open (const char *, int, ...);
95+
int close (int fd);
96+
ssize_t read (int fd, void *buf, size_t nbyte);
97+
ssize_t write (int fd, const void *buf, size_t nbyte);
98+
off_t lseek (int fd, off_t offset, int whence);
99+
```
90100

91101
The code needed for this is built into Picolibc by default, but can be
92102
disabled by specifying `-Dposix-io=false` in the meson command line.
@@ -97,7 +107,9 @@ Exit is just a wrapper around _exit that also calls destructors and
97107
callbacks registered with atexit. To make it work, you'll need to
98108
implement the `_exit` function:
99109

100-
_Noreturn void _exit (int status);
110+
```c
111+
_Noreturn void _exit (int status);
112+
```
101113
102114
### malloc and free
103115
@@ -138,7 +150,9 @@ specified *after* libc on the linker command line. The picolibc.specs
138150
file provides a way to specify a library after libc using the
139151
`--oslib=` parameter:
140152
141-
$ gcc -o program.elf program.o --oslib=myos
153+
```sh
154+
$ gcc -o program.elf program.o --oslib=myos
155+
```
142156

143157
This will include -lmyos after -lc so that the linker can resolve
144158
functions used by picolibc from libmyos.a. You can, alternatively,
@@ -175,16 +189,18 @@ underlying system C library is used for the POSIX functions described
175189
above. To build in this mode, you'll need to override a few default
176190
picolibc configuration parameters:
177191

178-
$ meson \
179-
-Dtls-model=global-dynamic \
180-
-Dmultilib=false \
181-
-Dpicolib=false \
182-
-Dpicocrt=false \
183-
-Dposix-console=true \
184-
-Dnewlib-global-atexit=true \
185-
-Dincludedir=lib/picolibc/include \
186-
-Dlibdir=lib/picolibc/lib \
187-
-Dspecsdir=none
192+
```sh
193+
$ meson \
194+
-Dtls-model=global-dynamic \
195+
-Dmultilib=false \
196+
-Dpicolib=false \
197+
-Dpicocrt=false \
198+
-Dposix-console=true \
199+
-Dnewlib-global-atexit=true \
200+
-Dincludedir=lib/picolibc/include \
201+
-Dlibdir=lib/picolibc/lib \
202+
-Dspecsdir=none
203+
```
188204

189205
* -Dtls-model=global-dynamic makes picolibc use the default TLS model
190206
for GCC.
@@ -212,5 +228,7 @@ picolibc configuration parameters:
212228

213229
Once built, you can install and use picolibc on the host:
214230

215-
$ cc -I/usr/local/lib/picolibc/include hello-world.c \
216-
/usr/local/lib/picolibc/lib/libc.a
231+
```sh
232+
$ cc -I/usr/local/lib/picolibc/include hello-world.c \
233+
/usr/local/lib/picolibc/lib/libc.a
234+
```

0 commit comments

Comments
 (0)