PulkoMandy | 17fc759 | 2022-07-28 18:27:54 +0200 | [diff] [blame] | 1 | This chapter describes the C library usually provided with @command{vbcc}. |
| 2 | |
| 3 | |
| 4 | @section Introduction |
| 5 | |
| 6 | To execute code compiled by @command{vbcc}, a library is needed. It |
| 7 | provides basic interfaces to the underlying operating system or |
| 8 | hardware as well as a set of often used functions. |
| 9 | |
| 10 | A big part of the library is portable across all architectures. However, |
| 11 | some functions (e.g. for input/output or memory allocation) are |
| 12 | naturally dependent on the operating system or hardware. There are |
| 13 | several sections in this chapter dealing with different versions of |
| 14 | the library. |
| 15 | |
| 16 | The library itself often is split into several parts. A startup-code |
| 17 | will do useful initializations, like setting up IO, parsing the command |
| 18 | line or initializing variables and hardware. |
| 19 | |
| 20 | The biggest part of the functions will usually be stored in one library file. |
| 21 | The name and format of this file depends on the conventions of the underlying |
| 22 | system (e.g. @file{vc.lib} or @file{libvc.a}). |
| 23 | |
| 24 | Often, floating point code (if available) is stored in a different file |
| 25 | (e.g. @file{m.lib} or @file{libm.a}). If floating point is used in an |
| 26 | application, it might be necessary to explicitly link with this library |
| 27 | (e.g. by specifying @file{-lm}). |
| 28 | |
| 29 | In many cases, the include files provide special inline-code or similar |
| 30 | optimizations. Therefore, it is recommended to always include the |
| 31 | corresponding include file when using a library function. Even if it |
| 32 | is not necessary in all cases, it may affect the quality of the generated |
| 33 | code. |
| 34 | |
| 35 | The library implements the functions specified by ISO9899:1989 as well |
| 36 | as a part of the new functions from ISO9899:1999. |
| 37 | |
| 38 | @section Legal |
| 39 | |
| 40 | Most parts of this library are public domain. However, for some systems, |
| 41 | parts may be under a different license. Please consult the system |
| 42 | specific documentation. Usually, linking against this library will |
| 43 | not put any restrictions on the created executable unless otherwise |
| 44 | mentioned. |
| 45 | |
| 46 | Parts of the math library (e.g. transcendental functions) are derived |
| 47 | from Sun's free math library: |
| 48 | @example |
| 49 | * ==================================================== |
| 50 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
| 51 | * |
| 52 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
| 53 | * Permission to use, copy, modify, and distribute this |
| 54 | * software is freely granted, provided that this notice |
| 55 | * is preserved. |
| 56 | * ==================================================== |
| 57 | @end example |
| 58 | |
| 59 | @node SoftfloatHauser |
| 60 | The softfloat functions, used by some targets, are derived from John |
| 61 | Hauser's IEC/IEEE Floating-point Artithmetic Package: |
| 62 | |
| 63 | @example |
| 64 | This C source file is part of the SoftFloat IEC/IEEE Floating-point |
| 65 | Arithmetic Package, Release 2. |
| 66 | |
| 67 | Written by John R. Hauser. This work was made possible in part by the |
| 68 | International Computer Science Institute, located at Suite 600, 1947 Center |
| 69 | Street, Berkeley, California 94704. Funding was partially provided by the |
| 70 | National Science Foundation under grant MIP-9311980. The original version |
| 71 | of this code was written as part of a project to build a fixed-point vector |
| 72 | processor in collaboration with the University of California at Berkeley, |
| 73 | overseen by Profs. Nelson Morgan and John Wawrzynek. More information |
| 74 | is available through the web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ |
| 75 | arithmetic/softfloat.html'. |
| 76 | |
| 77 | THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort |
| 78 | has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT |
| 79 | TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO |
| 80 | PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY |
| 81 | AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. |
| 82 | |
| 83 | Derivative works are acceptable, even for commercial purposes, so long as |
| 84 | (1) they include prominent notice that the work is derivative, and (2) they |
| 85 | include prominent notice akin to these three paragraphs for those parts of |
| 86 | this code that are retained. |
| 87 | @end example |
| 88 | |
| 89 | |
| 90 | @section Global Variables |
| 91 | |
| 92 | @subsection timezone |
| 93 | |
| 94 | On some host operating systems vclib might be unable to determine the |
| 95 | current time zone, which is required for functions like |
| 96 | @code{mktime()} or @code{localtime()} to work. Here you can overwrite |
| 97 | the following variables: |
| 98 | |
| 99 | @table @code |
| 100 | @item long __gmtoffset |
| 101 | Offset in minutes, west of Greenwich Mean Time (GMT). |
| 102 | @item int __dstflag |
| 103 | Set to non-zero, when Daylight Saving Time is active. |
| 104 | @end table |
| 105 | |
| 106 | Targets which can determine their current time zone, will do so by |
| 107 | initializing these variables on startup. |
| 108 | |
| 109 | |
| 110 | @section Embedded Systems |
| 111 | |
| 112 | This section describes specifics of the C library for embedded systems. |
| 113 | |
| 114 | @subsection Startup |
| 115 | |
| 116 | The startup is usually split into two parts. The first part is done by |
| 117 | assembly code that produces the object file @file{lib/startup.o}. This |
| 118 | assembly code is usually provided with vbcc and may have to be adapted to |
| 119 | the hardware you are using. The key actions that have to be performed by this |
| 120 | code are: |
| 121 | |
| 122 | @table @minus |
| 123 | @item hardware initialization |
| 124 | It may be necessary to perform some hardware initialization right |
| 125 | at the beginning, e.g. to configure the memory system. This has to |
| 126 | be modified by the user. |
| 127 | |
| 128 | @item variable initializations |
| 129 | When running code from ROM, some memory sections have to be |
| 130 | initialized. Usually, the init-values of initialized variables |
| 131 | have to be copied from ROM to the data segment and the values of |
| 132 | un-initialized variables have to be cleared in the bss segment. |
| 133 | This code is usually provided in the startup code. |
| 134 | |
| 135 | @item stack pointer |
| 136 | The stack pointer has to be set to a suitable memory area. |
| 137 | The startup code |
| 138 | will set the stack pointer to the value of the pointer @code{__stack}. |
| 139 | There is a default stack provided in the C library which will be used |
| 140 | unless the application defines its own stack using, for example, the |
| 141 | following code (assuming that the stack grows downwards): |
| 142 | @example |
| 143 | #define STACKSIZE <whatever> |
| 144 | |
| 145 | static long mystack[STACKSIZE/sizeof(long)]; |
| 146 | char *__stack=((char*)mystack)+STACKSIZE; |
| 147 | @end example |
| 148 | |
| 149 | @item calling @code{__main} |
| 150 | After all the above initializations have been performed, the function |
| 151 | @code{__main()} has to be called. This function is provided by the |
| 152 | library and performs high-level initializations, if necessary (mainly |
| 153 | it calls constructors created by the linker) and will then call the |
| 154 | user @code{main()} function. Note that the library |
| 155 | may not work correctly if the user @code{main()} function is called |
| 156 | directly from the startup code. |
| 157 | |
| 158 | @end table |
| 159 | |
| 160 | @subsection Heap |
| 161 | |
| 162 | When dynamic memory management is used (e.g. by using the @code{malloc()} |
| 163 | function), a heap memory area is needed to allocate memory from. The |
| 164 | @code{malloc()} function assumes that @code{__heapptr} is a variable pointing |
| 165 | to the beginning of the heap memory and that @code{__heapsize} specifies |
| 166 | the size of the heap area in bytes. The library will provide a default heap |
| 167 | memory area that can be replaced by adding, for example, the following file |
| 168 | to the application: |
| 169 | @example |
| 170 | #define HEAPSIZE <whatever> |
| 171 | |
| 172 | char __heap[HEAPSIZE],*__heapptr=__heap; |
| 173 | size_t __heapsize=HEAPSIZE; |
| 174 | @end example |
| 175 | |
| 176 | |
| 177 | @subsection Input/Output |
| 178 | |
| 179 | The standard C input/output functions are provided also for embedded systems. |
| 180 | Reading/writing to a stream will be directed to void unless the following |
| 181 | low-level I/O-functions are provided by the application: |
| 182 | @example |
| 183 | int __open(const char *name,const char *mode); |
| 184 | void __close(int h); |
| 185 | size_t __read(int h,char *p,size_t l); |
| 186 | size_t __write(int h,const char *p,size_t l); |
| 187 | off_t __seek(int h,off_t offset,int origin); |
| 188 | @end example |
| 189 | |
| 190 | The @code{__open()} function receives a name and a mode string (as in the C |
| 191 | @code{fopen()} function) as arguments and has to return a file-descriptor if |
| 192 | it is possible to open this file. The other functions are equivalent to the |
| 193 | corresponding POSIX functions. @code{__seek} can be implemented to return |
| 194 | @code{-1} if the functionality is not needed. |
| 195 | |
| 196 | Also, @code{stdin, stdout} and @code{stderr} can be used with the standard |
| 197 | descriptors. |
| 198 | |
| 199 | @subsection CTRL-C Handling |
| 200 | |
| 201 | Some targets implement handlers to terminate the program on ctrl-c or a |
| 202 | similar signal. This usually has the same effect as calling |
| 203 | @code{exit(20)}. |
| 204 | |
| 205 | If you want to change or disable the ctrl-c handling, you can overwrite |
| 206 | the function @code{void _chkabort(void)}. |
| 207 | |
| 208 | @subsection Floating Point |
| 209 | |
| 210 | Whether floating point is supported, depends on the target architecture and |
| 211 | chip. If it is supported, there will usually be a math-library that has to |
| 212 | be linked (using option @option{-lm}) when floating point is used. |
| 213 | |
| 214 | @subsection Useless Functions |
| 215 | |
| 216 | Of course, some of the C library functions can not be implemented reasonably on |
| 217 | embedded systems. These functions are contained in the library but will |
| 218 | always return an error value. Mainly affected are: |
| 219 | |
| 220 | @table @minus |
| 221 | @item locale |
| 222 | @item time |
| 223 | @item signal |
| 224 | @item filesystem functions |
| 225 | @end table |
| 226 | |
| 227 | Depending on the hardware provided by a system it is possible to implement |
| 228 | these functions and add them to the application. In this case, the new |
| 229 | functions will be used rather than the default ones returning only error |
| 230 | values. |
| 231 | |
| 232 | @subsection Linking/Locating |
| 233 | |
| 234 | To produce ROM images (e.g. in the form of absolute ELF executables, Intel |
| 235 | Hex files or Motorola S-Records), the linker is called with a linker script. |
| 236 | This script can be used to join together different sections of the input files |
| 237 | and locate them to suitable absolute memory areas. Also, this linker script |
| 238 | can be used to set symbols that may be used by the application or the startup |
| 239 | code, e.g. addresses of data sections, initialization values or small data |
| 240 | pointers. |
| 241 | |
| 242 | Code or data that has to reside at special locations can be put into a special |
| 243 | section using the @code{__section} attribute. This section can then be |
| 244 | placed at the desired location using the linker script. |
| 245 | |
| 246 | Usually, an example linker script will be provided. While this is often not |
| 247 | suitable for different chips, it may serve as a starting point. |
| 248 | |
| 249 | |
| 250 | @section AmigaOS/68k |
| 251 | |
| 252 | This section describes specifics of the C library for AmigaOS/68k |
| 253 | provided by the target @file{m68k-amigaos}. |
| 254 | The relevant files are @file{startup.o}, @file{minstart.o}, @file{minres.o}, |
| 255 | @file{vc.lib}, @file{vcs.lib}, @file{mieee.lib}, @file{mieees.lib}, |
| 256 | @file{m881.lib}, @file{m881s.lib}, @file{m040.lib}, @file{m040s.lib}, |
| 257 | @file{m060.lib}, @file{m060s.lib}, @file{msoft.lib}, @file{msofts.lib}, |
| 258 | @file{amiga.lib}, @file{amigas.lib}, @file{auto.lib} and @file{autos.lib}, |
| 259 | @file{reaction.lib}, @file{reactions.lib}. |
| 260 | |
| 261 | Note that @file{extra.lib} is no longer part of the vbcc distribution. |
| 262 | It was replaced by 'PosixLib', available on Aminet |
| 263 | @file{dev/c/vbcc_PosixLib.lha}, which has a much more comprehensive |
| 264 | support for POSIX and Unix functions. |
| 265 | |
| 266 | The following config files are available: |
| 267 | @table @code |
| 268 | @item aos68k |
| 269 | Standard startup code (@file{startup.o}) with command line parsing |
| 270 | and optional Workbench startup (@xref{Standard Startup}). |
| 271 | @item aos68km |
| 272 | Minimal startup code (@file{minstart.o}) without command line |
| 273 | parsing. You have to open all libraries yourself (@xref{Minimal Startup}). |
| 274 | @item aos68kr |
| 275 | Minimal startup code (@file{minres.o}) for resident programs. |
| 276 | Always compiles in small data mode and links with @file{vcs.lib} |
| 277 | (@xref{Minimal Resident}). |
| 278 | @end table |
| 279 | |
| 280 | @node Standard Startup |
| 281 | @subsection Startup |
| 282 | |
| 283 | The startup code currently consists of a slightly modified standard |
| 284 | Amiga startup (@file{startup.o}). The startup code sets up some |
| 285 | global variables and initializes stdin, stdout and stderr. |
| 286 | The exit code closes all open files and frees all memory. |
| 287 | If you link with a math library the startup/exit code will be taken |
| 288 | from there if necessary. |
| 289 | |
| 290 | |
| 291 | @node Floating point |
| 292 | @subsection Floating point |
| 293 | |
| 294 | Note that you have to link with a math library if you want to use |
| 295 | floating point. All math functions, special startup code and |
| 296 | printf/scanf functions which support floating point are contained in |
| 297 | the math libraries only. |
| 298 | At the moment there are five math libraries: |
| 299 | |
| 300 | @table @file |
| 301 | @item mieee.lib |
| 302 | This one uses the C= math libraries. The startup code |
| 303 | will always open MathIeeeSingBas.library, |
| 304 | MathIeeeDoubBas.library and MathIeeeDoubTrans.library. |
| 305 | Float return values are passed in d0, double return |
| 306 | values are passed in d0/d1. |
| 307 | A 68000 is sufficient to use this library. |
| 308 | You must not specify @option{-fpu=...} |
| 309 | when you use this library. |
| 310 | By default all floating point routines are provided via stub functions in |
| 311 | @file{mieee.lib}. With the option @option{-amiga-softfloat} you can tell |
| 312 | @command{vbccm68k} to generate inline code for calling the |
| 313 | MathIeee libraries directly. |
| 314 | |
| 315 | @item msoft.lib |
| 316 | This one is based on John Hauser's IEC/IEEE Floating-point Arithmetic |
| 317 | Package (@xref{SoftfloatHauser}) and doesn't need any system libraries for |
| 318 | FP emulation. May be slower than the ROM libraries, though. |
| 319 | Otherwise everything mentioned for @file{mieee.lib} applies here |
| 320 | as well. |
| 321 | Note that you have to call the @command{vc} frontend with the |
| 322 | @option{-rmcfg-amiga-softfloat} option, when your config file contains |
| 323 | @option{-amiga-softfloat} (which is the case for @file{aos68k} |
| 324 | since vbcc V0.9h). |
| 325 | |
| 326 | @item m881.lib |
| 327 | This one uses direct FPU instructions and function |
| 328 | return values are passed in fp0. You must have a |
| 329 | 68020 or higher and an FPU to use this library. You |
| 330 | also have to specify @option{-fpu=68881} or |
| 331 | @option{-fpu=68882}. |
| 332 | Several FPU instructions that have to be emulated on |
| 333 | 040/060 may be used. |
| 334 | |
| 335 | @item m040.lib |
| 336 | This one uses only direct FPU instructions that do not |
| 337 | have to be emulated on a 68040. Other functions use |
| 338 | the Motorola emulation routines modified by |
| 339 | Aki M Laukkanen and Matthew Hey. |
| 340 | It should be used for programs compiled for 68040 |
| 341 | with FPU. |
| 342 | Return values are passed in fp0. |
| 343 | |
| 344 | @item m060.lib |
| 345 | This one uses only direct FPU instructions that do not |
| 346 | have to be emulated on a 68060. Other functions use |
| 347 | the Motorola emulation routines modified by |
| 348 | Aki M Laukkanen and Matthew Hey. |
| 349 | It should be used for programs compiled for 68060 |
| 350 | with FPU. |
| 351 | Return values are passed in fp0. |
| 352 | @end table |
| 353 | |
| 354 | Depending on the CPU/FPU selected, including @file{math.h} will |
| 355 | cause inline-code generated for certain math functions. |
| 356 | |
| 357 | @node amiga-stack |
| 358 | @subsection Stack |
| 359 | |
| 360 | An application can specify the stack-size needed by defining a variable |
| 361 | @code{__stack} (of type @code{size_t}) with external linkage, e.g. |
| 362 | |
| 363 | @example |
| 364 | size_t __stack=65536; /* 64KB stack-size */ |
| 365 | @end example |
| 366 | |
| 367 | The startup code will check whether the stack-size specified is larger |
| 368 | than the default stack-size (as set in the shell) and switch to a new |
| 369 | stack of appropriate size, if necessary. |
| 370 | |
| 371 | If the @option{-stack-check} option is specified when compiling, the |
| 372 | library will check for a stack overflow and abort the program, if the |
| 373 | stack overflows. Note, however, that only code compiled with this |
| 374 | option will be checked. Calls to libraries which have not been compiled |
| 375 | with @option{-stack-check} or calls to OS function may cause a stack |
| 376 | overflow which is not noticed. |
| 377 | |
| 378 | Additionally, if @option{-stack-check} is used, the maximum stack-size |
| 379 | used can be read by querying the external variable @code{__stack_usage}. |
| 380 | |
| 381 | @example |
| 382 | #include <stdio.h> |
| 383 | |
| 384 | extern size_t __stack_usage; |
| 385 | |
| 386 | main() |
| 387 | @{ |
| 388 | do_program(); |
| 389 | printf("stack used: %lu\n",(unsigned long)__stack_usage); |
| 390 | @} |
| 391 | @end example |
| 392 | |
| 393 | Like above, the stack used by functions not compiled using |
| 394 | @option{-stack-check} or OS functions is ignored. |
| 395 | |
| 396 | @node amigasmalldata |
| 397 | @subsection Small data model |
| 398 | |
| 399 | When using the small data model of the 68k series CPUs, you also have |
| 400 | to link with appropriate libraries. Most libraries documented here are |
| 401 | also available as small data versions (with an 's' attached to the |
| 402 | file name). Exceptions are the math libraries. |
| 403 | |
| 404 | To compile and link a program using the small data model a command like |
| 405 | |
| 406 | @example |
| 407 | vc test.c -o test -sd -lvcs -lamigas |
| 408 | @end example |
| 409 | |
| 410 | might be used. |
| 411 | |
| 412 | @subsection Restrictions |
| 413 | |
| 414 | The following list contains some restrictions of this version of the |
| 415 | library: |
| 416 | |
| 417 | @table @code |
| 418 | |
| 419 | @item tmpfile() |
| 420 | The @code{tmpfile()} function always returns an error. |
| 421 | |
| 422 | @item clock() |
| 423 | The @code{clock()} function always returns -1. This is correct, |
| 424 | according to the C standard, because on AmigaOS it is not possible to |
| 425 | obtain the time used by the calling process. |
| 426 | |
| 427 | @end table |
| 428 | |
| 429 | @node Minimal Startup |
| 430 | @subsection Minimal Startup |
| 431 | |
| 432 | If you want to write programs that use only Amiga functions and none from |
| 433 | vc.lib you can use @file{minstart.o} instead of @file{startup.o} and |
| 434 | produce smaller executables. You can also achieve that by simply using |
| 435 | the @file{aos68km} config file instead. |
| 436 | |
| 437 | This startup code does not set up everything needed by vc.lib, so you |
| 438 | must not use most of these functions (string and ctype functions are ok, |
| 439 | but most other functions - especially I/O and memory handling - must not |
| 440 | be used). |
| 441 | @code{exit()} is supplied by minstart and can be used. |
| 442 | |
| 443 | The command line is not parsed, but passed to @code{main()} as a single |
| 444 | string, |
| 445 | so you can declare main as |
| 446 | @code{int main(char *command)} or @code{int main(void)}. |
| 447 | |
| 448 | Also no Amiga libraries are opened (but @code{SysBase} is set up), so you |
| 449 | have to define and open @code{DOSBase} yourself if you need it. |
| 450 | If you want to use floating point with the IEEE libraries |
| 451 | or @option{-amiga-softfloat} you have to |
| 452 | define and open MathIeeeSingBas.library, MathIeeeDoubBas.library and |
| 453 | MathIeeeDoubTrans.library (in this order!) and link with mieee.lib (if |
| 454 | compiled for FPU this is not needed). |
| 455 | |
| 456 | A hello world using minstart could look like this: |
| 457 | |
| 458 | @example |
| 459 | #include <proto/exec.h> |
| 460 | #include <proto/dos.h> |
| 461 | |
| 462 | struct DosLibrary *DOSBase; |
| 463 | |
| 464 | int main() |
| 465 | @{ |
| 466 | if(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",0))@{ |
| 467 | Write(Output(),"Hello, world!\n",14); |
| 468 | CloseLibrary((struct Library *)DOSBase); |
| 469 | @} |
| 470 | return 0; |
| 471 | @} |
| 472 | |
| 473 | @end example |
| 474 | |
| 475 | This can yield an executable of under 256 bytes when compiled with |
| 476 | @option{-sc -sd} and linked with @file{minstart.o} and @code{amigas.lib} |
| 477 | (using @command{vlink} - may not work with other linkers). |
| 478 | |
| 479 | @node Minimal Resident |
| 480 | @subsection Minimal Startup for resident programs |
| 481 | |
| 482 | AmigaOS can keep special "pure" programs resident in RAM, and restart them |
| 483 | from there without having to load them again from disk. To make it easy to |
| 484 | create such reentrant programs, even with static data, you can link with the |
| 485 | special startup code @file{minres.o}, which is a minimal startup code for |
| 486 | resident programs. Or simply use the config file @file{aos68kr} instead. |
| 487 | Everything mentioned for @file{minstart.o} in the previous section is also |
| 488 | valid for @file{minres.o}. |
| 489 | |
| 490 | To create real resident programs you have to follow the following rules: |
| 491 | @itemize @minus |
| 492 | |
| 493 | @item Compile all your code for the small data model (@option{-sd} option). |
| 494 | |
| 495 | @item Avoid absolute references to small data symbols. |
| 496 | Usually these are constant pointers to static data. |
| 497 | The following example creates such an illegal relocation: |
| 498 | @example |
| 499 | int x; |
| 500 | int const *p = &x; |
| 501 | @end example |
| 502 | @command{vlink} warns about all potential problems. |
| 503 | |
| 504 | @item Link with the @file{minres.o} startup code, |
| 505 | and use the small data |
| 506 | versions of linker libraries (@file{vcs.lib}, @file{amigas.lib}, etc.). |
| 507 | |
| 508 | @item Set the Pure flag in the file attributes. |
| 509 | Load the program into RAM |
| 510 | with the AmigaDOS @command{resident} command. |
| 511 | |
| 512 | @end itemize |
| 513 | |
| 514 | |
| 515 | @node amigalib |
| 516 | @subsection amiga.lib |
| 517 | |
| 518 | To write programs using AmigaOS (rather than standard C functions |
| 519 | only), a replacement for the original (copyrighted) @file{amiga.lib} |
| 520 | is provided with @command{vbcc}. This replacement is adapted to vbcc, |
| 521 | does not cause collisions with some functions (e.g. @code{sprintf}) |
| 522 | provided by the original @file{amiga.lib} and is available for the |
| 523 | small data mode as well. It is recommended to always use this library |
| 524 | rather than the original version. |
| 525 | |
| 526 | Additionally, there are header files (in the @file{proto}- and |
| 527 | @file{inline}-subdirectories) which cause inlined calls to Amiga |
| 528 | library functions. |
| 529 | |
| 530 | Besides some support functions @file{amiga.lib} contains stub routines |
| 531 | to call functions from all common AmigaOS libraries with stack arguments. |
| 532 | By including the library's proto header file you make sure that AmigaOS |
| 533 | functions are called directly by inline code, unless @code{_NO_INLINE} |
| 534 | is defined. |
| 535 | |
| 536 | Preprocessor defines to control the behaviour of vbcc's proto headers: |
| 537 | @table @code |
| 538 | @item __NOLIBBASE__ |
| 539 | Do not declare the library base symbol. |
| 540 | @item _NO_INLINE |
| 541 | Do not use optimized inline code for library function calls. |
| 542 | @end table |
| 543 | |
| 544 | Note that the OS-call inlines have been generated using the NDK3.2 clib |
| 545 | header files, while trying to keep compatibility to NDK3.9, so it is |
| 546 | advised to use one of the two NDKs for development. |
| 547 | Otherwise you will get warnings about missing @code{CONST} typedefs and |
| 548 | similar. |
| 549 | |
| 550 | Specify @option{-lamiga} to link with @file{amiga.lib}. |
| 551 | |
| 552 | @node autolib |
| 553 | @subsection auto.lib |
| 554 | |
| 555 | To link with @file{auto.lib} (or the small data version |
| 556 | @file{autos.lib}) specify |
| 557 | the @option{-lauto} or @option{-lautos} option to @command{vc}. |
| 558 | |
| 559 | When you are calling a standard Amiga library function without |
| 560 | having defined the corresponding library base, then the library base |
| 561 | as well as code to open/close it will be taken from @file{auto.lib}. |
| 562 | |
| 563 | By default, @file{auto.lib} will try to open any library version. If you |
| 564 | need at least a certain version you can define and set a variable |
| 565 | _<library-base>Ver with external linkage, e.g. (on file-scope): |
| 566 | |
| 567 | @example |
| 568 | int _IntuitionBaseVer = 39; |
| 569 | @end example |
| 570 | |
| 571 | Note that your program will abort before reaching @code{main()} if one |
| 572 | of the libraries cannot be opened. Also note that @file{auto.lib} |
| 573 | depends on constructor/destructor handling in vclib, which means it |
| 574 | cannot work when linking without vclib, without standard startup code, |
| 575 | or only with a minimal startup code, like @file{minstart.o}. |
| 576 | |
| 577 | @subsection reaction.lib |
| 578 | |
| 579 | The @file{reaction.lib} in @command{vbcc} is a port of Stephan Rupprecht's |
| 580 | rewrite of the copyrighted linker library, extended and fixed by |
| 581 | Olaf Barthel for the NDK 3.2 release. This version should work in |
| 582 | combination with NDK 3.9 as well. |
| 583 | |
| 584 | To link with @file{reaction.lib} (or the small data version |
| 585 | @file{reactions.lib}) specify the @option{-lreaction} or |
| 586 | @option{-lreactions} option to @command{vc}. |
| 587 | |
| 588 | The library contains ReAction GUI class support functions and their |
| 589 | autoinitialization code. Refer to @file{reaction_lib.doc} from your |
| 590 | NDK Autodocs for more information. As documented there, the version |
| 591 | used to automatically open the classes can be defined by the variable |
| 592 | @code{__reactionversion} with external linkage. Otherwise a default |
| 593 | of version 0 is used. |
| 594 | |
| 595 | |
| 596 | @section Kickstart1.x/68k |
| 597 | |
| 598 | This section describes specifics of the C library for Amiga Kickstart 1.2 |
| 599 | and 1.3 provided by the target @file{m68k-kick13}. |
| 600 | The relevant files are @file{startup.o}, @file{minstart.o}, @file{minres.o}, |
| 601 | @file{startup16.o}, @file{minstart16.o}, @file{minres16.o}, |
| 602 | @file{vc.lib}, @file{vcs.lib}, @file{m13.lib}, @file{m13s.lib}, |
| 603 | @file{msoft.lib}, @file{msofts.lib}, @file{m881.lib}, @file{m881s.lib}, |
| 604 | @file{amiga.lib}, @file{amigas.lib}, @file{auto.lib} and @file{autos.lib}, |
| 605 | @file{vc16.lib}, @file{vc16s.lib}, @file{m1316.lib}, @file{m1316s.lib}, |
| 606 | @file{msoft16.lib}, @file{msoft16s.lib}, @file{m88116.lib}, @file{m88116s.lib}, |
| 607 | @file{amiga16.lib}, @file{amiga16s.lib}, @file{auto16.lib} and |
| 608 | @file{auto16s.lib}. |
| 609 | |
| 610 | This target makes it possible to develop programs targeted for these older |
| 611 | versions of the Amiga operating system, using the original Commodore |
| 612 | Kickstart 1.3 header files. Note that there are also libraries and |
| 613 | config files for using a 16-bit int ABI, which was common at that time, |
| 614 | and may have some advantages on 16-bit CPUs, like the 68000 or 68010. |
| 615 | |
| 616 | The following config files are available: |
| 617 | @table @code |
| 618 | @item kick13 |
| 619 | Standard startup code (@file{startup.o}) with command line parsing |
| 620 | and optional Workbench startup (@xref{Startup13}) using 32-bit int. |
| 621 | @item kick13m |
| 622 | Minimal startup code (@file{minstart.o}) without command line |
| 623 | parsing. You have to open all libraries yourself (@xref{Minimal Startup}) |
| 624 | using 32-bit int. |
| 625 | @item kick13r |
| 626 | Minimal startup code (@file{minres.o}) for resident programs. |
| 627 | Always compiles in small data mode and links with @file{vcs.lib} |
| 628 | (@xref{Minimal Resident}) using 32-bit int. |
| 629 | @item kick13s |
| 630 | Standard startup code (@file{startup.o}) with command line parsing |
| 631 | and optional Workbench startup (@xref{Startup13}) using 16-bit int. |
| 632 | @item kick13sm |
| 633 | Minimal startup code (@file{minstart.o}) without command line |
| 634 | parsing. You have to open all libraries yourself (@xref{Minimal Startup}) |
| 635 | using 16-bit int. |
| 636 | @item kick13sr |
| 637 | Minimal startup code (@file{minres.o}) for resident programs. |
| 638 | Always compiles in small data mode and links with @file{vcs.lib} |
| 639 | (@xref{Minimal Resident}) using 16-bit int. |
| 640 | @end table |
| 641 | |
| 642 | @node Startup13 |
| 643 | @subsection Startup |
| 644 | |
| 645 | The startup code currently consists of a slightly modified standard |
| 646 | AmigaOS 1.3 startup (@file{startup.o}). The startup code sets up some |
| 647 | global variables and initializes stdin, stdout and stderr. |
| 648 | The exit code closes all open files and frees all memory. |
| 649 | If you link with a math library the startup/exit code will be taken |
| 650 | from there if necessary. |
| 651 | |
| 652 | |
| 653 | @subsection Floating point |
| 654 | |
| 655 | Note that you have to link with a math library if you want to use |
| 656 | floating point. All math functions, special startup code and |
| 657 | printf/scanf functions which support floating point are contained in |
| 658 | the math libraries only. |
| 659 | At the moment there are two math libraries: |
| 660 | |
| 661 | @table @file |
| 662 | @item m13.lib |
| 663 | This one uses the C= math libraries present under Kickstart 1.2 and 1.3. |
| 664 | The startup code will always open mathffp.library, |
| 665 | MathIeeeDoubBas.library and MathIeeeDoubTrans.library. |
| 666 | Note that all single precision floating point calculations take place |
| 667 | in FFP format and have to be converted between FFP and IEEE by the |
| 668 | library. |
| 669 | Float return values are passed in d0, double return |
| 670 | values are passed in d0/d1. |
| 671 | A 68000 is sufficient to use this library. |
| 672 | You must not specify @option{-fpu=...} |
| 673 | when you use this library. |
| 674 | |
| 675 | @item msoft.lib |
| 676 | This one is based on John Hauser's IEC/IEEE Floating-point Arithmetic |
| 677 | Package (@xref{SoftfloatHauser}) and doesn't need any system libraries for |
| 678 | FP emulation. May be slower than the ROM libraries, though. |
| 679 | Otherwise everything mentioned for @file{m13.lib} applies here |
| 680 | as well. |
| 681 | |
| 682 | @item m881.lib |
| 683 | This one uses direct FPU instructions and function |
| 684 | return values are passed in fp0. You must have a |
| 685 | 68020 or higher and an FPU to use this library. You |
| 686 | also have to specify @option{-fpu=68881}. |
| 687 | Several FPU instructions that have to be emulated on |
| 688 | 040/060 may be used. |
| 689 | @end table |
| 690 | |
| 691 | @subsection Stack |
| 692 | |
| 693 | Stack-checking is available similar to AmigaOS/68k (@xref{amiga-stack}). |
| 694 | But there is no automatic stack-extension under Kickstart 1.3 and a |
| 695 | @code{__stack} variable will be ignored. |
| 696 | |
| 697 | @subsection Small data model |
| 698 | |
| 699 | Small data is supported as described for AmigaOS/68k (@xref{amigasmalldata}). |
| 700 | The startup code takes care of clearing the unititalized part of a |
| 701 | small data section (which Kickstart 1.x fails to do). |
| 702 | |
| 703 | @subsection Restrictions |
| 704 | |
| 705 | The following list contains some restrictions of this version of the |
| 706 | library: |
| 707 | |
| 708 | @table @code |
| 709 | |
| 710 | @item tmpfile() |
| 711 | The @code{tmpfile()} function always returns an error. |
| 712 | |
| 713 | @item clock() |
| 714 | The @code{clock()} function always returns -1. This is correct, |
| 715 | according to the C standard, because on AmigaOS it is not possible to |
| 716 | obtain the time used by the calling process. |
| 717 | |
| 718 | @end table |
| 719 | |
| 720 | @subsection amiga.lib |
| 721 | |
| 722 | @xref{amigalib}. |
| 723 | |
| 724 | This version of @file{amiga.lib} only supports the functionality present |
| 725 | in Kickstart 1.2/1.3. |
| 726 | |
| 727 | @subsection auto.lib |
| 728 | |
| 729 | This library corresponds to the AmigaOS/68k version (@xref{autolib}), but |
| 730 | only supports libraries of Kickstart 1.3. |
| 731 | |
| 732 | @subsection Minimal Startup |
| 733 | |
| 734 | You can use @file{minstart.o} similar to AmigaOS/68k (@xref{Minimal Startup}). |
| 735 | |
| 736 | @subsection Minimal Startup for Resident Programs |
| 737 | |
| 738 | You can use @file{minres.o} similar to AmigaOS/68k (@xref{Minimal Resident}). |
| 739 | |
| 740 | |
| 741 | @section PowerUp/PPC |
| 742 | |
| 743 | This section describes specifics of the C library for PowerUp/PPC |
| 744 | provided by the target @file{ppc-powerup}. |
| 745 | The relevant files are @file{startup.o}, @file{minstart.o}, |
| 746 | @file{libvc.a}, @file{libvcs.a}, @file{libm.a}, @file{libms.a} |
| 747 | @file{libamiga.a}, @file{libamigas.a}, |
| 748 | @file{libauto.a} and @file{libautos.a}. |
| 749 | |
| 750 | Note that @file{libextra.a} is no longer part of the vbcc distribution. |
| 751 | It was replaced by 'PosixLib', available on Aminet |
| 752 | @file{dev/c/vbcc_PosixLib.lha}, which has a much more comprehensive |
| 753 | support for POSIX and Unix functions. |
| 754 | |
| 755 | @subsection Startup |
| 756 | |
| 757 | The startup code @file{startup.o} sets up some |
| 758 | global variables and initializes stdin, stdout and stderr. |
| 759 | The exit code closes all open files and frees all memory. |
| 760 | If you link with a math library the startup/exit code will be taken |
| 761 | from there if necessary. |
| 762 | |
| 763 | @subsection Floating point |
| 764 | |
| 765 | Note that you have to link with a math library if you want to use |
| 766 | floating point. All math functions, special startup code and |
| 767 | printf/scanf functions which support floating point are contained in |
| 768 | the math libraries only. |
| 769 | |
| 770 | The math library (@file{libm.a}) is linked against the floating point |
| 771 | library libmoto by Motorola. |
| 772 | |
| 773 | Depending on the CPU/FPU selected, including @file{math.h} will |
| 774 | cause inline-code generated for certain math functions. |
| 775 | |
| 776 | @subsection Stack |
| 777 | |
| 778 | Stack-handling is similar to AmigaOS/68k (@xref{amiga-stack}). |
| 779 | The only difference is that stack-swapping cannot be done. If the |
| 780 | default stack-size is less than the stack-size specified with |
| 781 | @code{__stack} the program will abort. |
| 782 | |
| 783 | @subsection Small data model |
| 784 | |
| 785 | When using the small data model of the PPC series CPUs, you also have |
| 786 | to link with appropriate libraries. Most libraries documented here are |
| 787 | also available as small data versions (with an 's' attached to the |
| 788 | file name). Exceptions are the math libraries. |
| 789 | |
| 790 | To compile and link a program using the small data model a command like |
| 791 | |
| 792 | @example |
| 793 | vc test.c -o test -sd -lvcs -lamigas |
| 794 | @end example |
| 795 | |
| 796 | might be used. |
| 797 | |
| 798 | @subsection Restrictions |
| 799 | |
| 800 | The following list contains some restrictions of this version of the |
| 801 | library: |
| 802 | |
| 803 | @table @code |
| 804 | |
| 805 | @item tmpfile() |
| 806 | The @code{tmpfile()} function always returns an error. |
| 807 | |
| 808 | @item clock() |
| 809 | The @code{clock()} function always returns -1. This is correct, |
| 810 | according to the C standard, because on AmigaOS it is not possible to |
| 811 | obtain the time used by the calling process. |
| 812 | |
| 813 | @end table |
| 814 | |
| 815 | @subsection Minimal Startup |
| 816 | |
| 817 | The provided minimal startup code (@file{minstart.o}) is used |
| 818 | similarly like the one for 68k (@xref{Minimal Startup}). Only use |
| 819 | it if you know what you are doing. |
| 820 | |
| 821 | @subsection libamiga.a |
| 822 | |
| 823 | To write programs accessing AmigaOS (rather than standard C functions |
| 824 | only), a replacement for the original (copyrighted) @file{amiga.lib} |
| 825 | is provided with @command{vbcc}. This replacement (@file{libamiga.a}) |
| 826 | automatically performs a necessary context switch to the 68k to execute |
| 827 | the system call. Furthermore, it is adapted to vbcc, |
| 828 | does not cause collisions with some functions (e.g. @code{sprintf}) |
| 829 | provided by the original @file{amiga.lib} and is available in |
| 830 | small data. |
| 831 | |
| 832 | Specify @option{-lamiga} to link with @file{libamiga.a}. |
| 833 | |
| 834 | @subsection libauto.a |
| 835 | |
| 836 | This library corresponds to the AmigaOS/68k version (@xref{autolib}). |
| 837 | |
| 838 | @section WarpOS/PPC |
| 839 | |
| 840 | This section describes specifics of the C library for WarpOS/PPC |
| 841 | provided by the target @file{ppc-warpos}. |
| 842 | The relevant files are @file{startup.o}, |
| 843 | @file{vc.lib}, @file{m.lib}, @file{amiga.lib} and @file{auto.lib}. |
| 844 | |
| 845 | Note that @file{extra.lib} is no longer part of the vbcc distribution. |
| 846 | It was replaced by 'PosixLib', available on Aminet |
| 847 | @file{dev/c/vbcc_PosixLib.lha}, which has a much more comprehensive |
| 848 | support for POSIX and Unix functions. |
| 849 | |
| 850 | @subsection Startup |
| 851 | |
| 852 | The startup code @file{startup.o} sets up some |
| 853 | global variables and initializes stdin, stdout and stderr. |
| 854 | The exit code closes all open files and frees all memory. |
| 855 | If you link with a math library the startup/exit code will be taken |
| 856 | from there if necessary. |
| 857 | |
| 858 | @subsection Floating point |
| 859 | |
| 860 | Note that you have to link with a math library if you want to use |
| 861 | floating point. All math functions, special startup code and |
| 862 | printf/scanf functions which support floating point are contained in |
| 863 | the math libraries only. |
| 864 | |
| 865 | The math library (@file{m.lib}) contains functions from Sun's |
| 866 | portable floating point library. Additionally, there is a |
| 867 | @command{vbcc} version of Andreas Heumann's @file{ppcmath.lib}. |
| 868 | These routines are linked against Motorola's floating point |
| 869 | routines optimized for PowerPC and therefore are much faster. |
| 870 | |
| 871 | To make use of this library, link with @file{ppcmath.lib} before |
| 872 | @file{m.lib}, e.g. |
| 873 | |
| 874 | @example |
| 875 | vc test.c -lppcmath -lm |
| 876 | @end example |
| 877 | |
| 878 | |
| 879 | |
| 880 | Depending on the CPU/FPU selected, including @file{math.h} will |
| 881 | cause inline-code generated for certain math functions. |
| 882 | |
| 883 | @subsection Stack |
| 884 | |
| 885 | Stack-handling is similar to AmigaOS/68k (@xref{amiga-stack}). |
| 886 | |
| 887 | @subsection Restrictions |
| 888 | |
| 889 | The following list contains some restrictions of this version of the |
| 890 | library: |
| 891 | |
| 892 | @table @code |
| 893 | |
| 894 | @item tmpfile() |
| 895 | The @code{tmpfile()} function always returns an error. |
| 896 | |
| 897 | @item clock() |
| 898 | The @code{clock()} function always returns -1. This is correct, |
| 899 | according to the C standard, because on AmigaOS it is not possible to |
| 900 | obtain the time used by the calling process. |
| 901 | |
| 902 | @end table |
| 903 | |
| 904 | @subsection amiga.lib |
| 905 | |
| 906 | To write programs accessing AmigaOS (rather than standard C functions |
| 907 | only), a replacement for the original (copyrighted) @file{amiga.lib} |
| 908 | is provided with @command{vbcc}. This replacement |
| 909 | automatically performs a necessary context switch to the 68k to execute |
| 910 | the system call. Furthermore, it is adapted to vbcc, |
| 911 | does not cause collisions with some functions (e.g. @code{sprintf}) |
| 912 | provided by the original @file{amiga.lib} and is available in |
| 913 | small data. |
| 914 | |
| 915 | Specify @option{-lamiga} to link with @file{amiga.lib}. |
| 916 | |
| 917 | |
| 918 | @subsection auto.lib |
| 919 | |
| 920 | This library corresponds to the AmigaOS/68k version (@xref{autolib}). |
| 921 | |
| 922 | |
| 923 | @section MorphOS/PPC |
| 924 | |
| 925 | This section describes specifics of the C library for MorphOS/PPC |
| 926 | provided by the target @file{ppc-morphos}. |
| 927 | The relevant files are @file{startup.o}, @file{minstart.o}, |
| 928 | @file{libvc.a}, @file{libvcs.a}, @file{libm.a}, @file{libms.a} |
| 929 | @file{libamiga.a}, @file{libamigas.a}, |
| 930 | @file{libauto.a} and @file{libautos.a}. |
| 931 | |
| 932 | Note that @file{libextra.a} is no longer part of the vbcc distribution. |
| 933 | It was replaced by 'PosixLib', available on Aminet |
| 934 | @file{dev/c/vbcc_PosixLib.lha}, which has a much more comprehensive |
| 935 | support for POSIX and Unix functions. |
| 936 | |
| 937 | @subsection Startup |
| 938 | |
| 939 | The startup code @file{startup.o} sets up some |
| 940 | global variables and initializes stdin, stdout and stderr. |
| 941 | The exit code closes all open files and frees all memory. |
| 942 | If you link with a math library the startup/exit code will be taken |
| 943 | from there if necessary. |
| 944 | |
| 945 | @subsection Floating point |
| 946 | |
| 947 | Note that you have to link with a math library if you want to use |
| 948 | floating point. All math functions, special startup code and |
| 949 | printf/scanf functions which support floating point are contained in |
| 950 | the math libraries only. |
| 951 | |
| 952 | The math library (@file{libm.a}) is linked against the floating point |
| 953 | library libmoto by Motorola. |
| 954 | |
| 955 | Depending on the CPU/FPU selected, including @file{math.h} will |
| 956 | cause inline-code generated for certain math functions. |
| 957 | |
| 958 | @subsection Stack |
| 959 | |
| 960 | Stack-handling is similar to AmigaOS/68k (@xref{amiga-stack}). |
| 961 | |
| 962 | @subsection Small data model |
| 963 | |
| 964 | When using the small data model of the PPC series CPUs, you also have |
| 965 | to link with appropriate libraries. Most libraries documented here are |
| 966 | also available as small data versions (with an 's' attached to the |
| 967 | file name). Exceptions are the math libraries. |
| 968 | |
| 969 | To compile and link a program using the small data model a command like |
| 970 | |
| 971 | @example |
| 972 | vc test.c -o test -sd -lvcs -lamigas |
| 973 | @end example |
| 974 | |
| 975 | might be used. |
| 976 | |
| 977 | @subsection Restrictions |
| 978 | |
| 979 | The following list contains some restrictions of this version of the |
| 980 | library: |
| 981 | |
| 982 | @table @code |
| 983 | |
| 984 | @item tmpfile() |
| 985 | The @code{tmpfile()} function always returns an error. |
| 986 | |
| 987 | @item clock() |
| 988 | The @code{clock()} function always returns -1. This is correct, |
| 989 | according to the C standard, because on MorphOS it is not possible to |
| 990 | obtain the time used by the calling process. |
| 991 | |
| 992 | @end table |
| 993 | |
| 994 | @subsection libamiga.a |
| 995 | |
| 996 | To write programs using AmigaOS compatible functions, a replacement for |
| 997 | the original (copyrighted) @file{amiga.lib} |
| 998 | is provided with @command{vbcc}. This replacement (@file{libamiga.a}) |
| 999 | will invoke the MorphOS 68k emulator to execute the system function. |
| 1000 | Furthermore, it is adapted to vbcc and |
| 1001 | does not cause collisions with some functions (e.g. @code{sprintf}) |
| 1002 | and is available in small data. |
| 1003 | |
| 1004 | Specify @option{-lamiga} to link with @file{libamiga.a}. |
| 1005 | |
| 1006 | |
| 1007 | @subsection libauto.a |
| 1008 | |
| 1009 | This library corresponds to the AmigaOS/68k version (@xref{autolib}). |
| 1010 | |
| 1011 | |
| 1012 | @section AmigaOS4/PPC |
| 1013 | |
| 1014 | This section describes specifics of the C library for AmigaOS4/PPC |
| 1015 | provided by the target @file{ppc-amigaos}. |
| 1016 | The relevant files are @file{startup.o}, @file{minstart.o}, |
| 1017 | @file{libvc.a}, @file{libvcs.a}, @file{libm.a}, @file{libms.a} |
| 1018 | @file{libamiga.a}, @file{libamigas.a}, |
| 1019 | @file{libauto.a} and @file{libautos.a}. |
| 1020 | |
| 1021 | Note that @file{libextra.a} is no longer part of the vbcc distribution. |
| 1022 | It was replaced by 'PosixLib', available on Aminet |
| 1023 | @file{dev/c/vbcc_PosixLib.lha}, which has a much more comprehensive |
| 1024 | support for POSIX and Unix functions. |
| 1025 | |
| 1026 | @subsection Startup |
| 1027 | |
| 1028 | The startup code @file{startup.o} sets up some |
| 1029 | global variables and initializes stdin, stdout and stderr. |
| 1030 | Then it runs all constructors of dynamically linked libraries, before |
| 1031 | entering the main program. |
| 1032 | The exit code runs all destructors of dynamically linked libraries, |
| 1033 | closes all open files and frees all memory. |
| 1034 | If you link with a math library the startup/exit code will be taken |
| 1035 | from there if necessary. |
| 1036 | |
| 1037 | @subsection Floating point |
| 1038 | |
| 1039 | Note that you have to link with a math library if you want to use |
| 1040 | floating point. All math functions, special startup code and |
| 1041 | printf/scanf functions which support floating point are contained in |
| 1042 | the math libraries only. |
| 1043 | |
| 1044 | The math library (@file{libm.a}) is linked against the floating point |
| 1045 | library libmoto by Motorola. |
| 1046 | |
| 1047 | Depending on the CPU/FPU selected, including @file{math.h} will |
| 1048 | cause inline-code generated for certain math functions. |
| 1049 | |
| 1050 | @subsection Stack |
| 1051 | |
| 1052 | There is no automatic stack extension for AmigaOS 4! This should be |
| 1053 | done automatically by the operating system. |
| 1054 | |
| 1055 | @subsection Small data model |
| 1056 | |
| 1057 | When using the small data model of the PPC series CPUs, you also have |
| 1058 | to link with appropriate libraries. Most libraries documented here are |
| 1059 | also available as small data versions (with an 's' attached to the |
| 1060 | file name). Exceptions are the math libraries. |
| 1061 | |
| 1062 | To compile and link a program using the small data model a command like |
| 1063 | |
| 1064 | @example |
| 1065 | vc test.c -o test -sd -lvcs -lamigas |
| 1066 | @end example |
| 1067 | |
| 1068 | might be used. |
| 1069 | |
| 1070 | @subsection Dynamic linking |
| 1071 | Since @file{elf.library} @code{V52.2} AmigaOS4 supports dynamic linking with |
| 1072 | shared object files (@file{.so} extension), similar to Unix. The default |
| 1073 | behaviour is to prefer linking against a shared object over a static |
| 1074 | library. To force static linking you might want to give the |
| 1075 | @option{-static} option to the @file{vc} frontend. |
| 1076 | |
| 1077 | @subsection Restrictions |
| 1078 | |
| 1079 | The following list contains some restrictions of this version of the |
| 1080 | library: |
| 1081 | |
| 1082 | @table @code |
| 1083 | |
| 1084 | @item tmpfile() |
| 1085 | The @code{tmpfile()} function always returns an error. |
| 1086 | |
| 1087 | @item clock() |
| 1088 | The @code{clock()} function always returns -1. This is correct, |
| 1089 | according to the C standard, because on AmigaOS it is not possible to |
| 1090 | obtain the time used by the calling process. |
| 1091 | |
| 1092 | @item Small data in dynamically linked executables |
| 1093 | There is a bug in @file{elf.library} @code{V52.4} (and earlier), which |
| 1094 | doesn't load @code{.sdata} and @code{.sbss} as a contiguous block into |
| 1095 | memory, when the executable requires dynamic linking. I decided against |
| 1096 | writing a workaround, as the bug should be fixed in OS4. |
| 1097 | |
| 1098 | @end table |
| 1099 | |
| 1100 | @subsection libamiga.a |
| 1101 | |
| 1102 | In contrast to other amigalibs the OS4 @file{libamiga.a} doesn't contain |
| 1103 | any stubs for calling system functions. AmigaOS 4 system calls are done |
| 1104 | through special macros in the SDK's interface header files. |
| 1105 | |
| 1106 | The library only includes some remaining amigalib functions, not already |
| 1107 | integrated into the OS, like @code{CreateIO()}, but its use is discouraged. |
| 1108 | |
| 1109 | Specify @option{-lamiga} to link with @file{libamiga.a}. |
| 1110 | |
| 1111 | |
| 1112 | @subsection libauto.a |
| 1113 | |
| 1114 | Include auto-open and -close functions for the most common OS libraries and |
| 1115 | interfaces. May also be used together with newlib (see below). |
| 1116 | |
| 1117 | |
| 1118 | @subsection newlib |
| 1119 | |
| 1120 | @subsubsection Introduction |
| 1121 | |
| 1122 | newlib.library is a shared AmigaOS4 library, which is covered by |
| 1123 | several BSD like licenses, |
| 1124 | and includes standard ANSI and POSIX functions as well as some |
| 1125 | functions common in Unix, BSD and similar operating systems. It is |
| 1126 | part of the OS4 SDK. |
| 1127 | |
| 1128 | The config file @file{newlib} will be created on installation to |
| 1129 | use the paths for header files and libraries pointing to the |
| 1130 | newlib from the SDK. |
| 1131 | |
| 1132 | What are the main differences between vclib and newlib? |
| 1133 | |
| 1134 | @itemize @minus |
| 1135 | @item vclib contains (almost) only standard ANSI-C and some ISO-C99 |
| 1136 | functions. If you want to port Unix programs you will probably |
| 1137 | miss a lot of functions. |
| 1138 | Also newlib supports things like mapping Unix directory paths to |
| 1139 | Amiga paths or expanding wildcards in command lines automatically. |
| 1140 | |
| 1141 | @item Programs compiled for newlib will be shorter because the code for all |
| 1142 | functions is not contained in the executable itself. |
| 1143 | |
| 1144 | @item Programs compiled for newlib will need the shared object |
| 1145 | @file{libc.so} present when started. |
| 1146 | |
| 1147 | @item Programs compiled for newlib will probably need more memory because |
| 1148 | the entire (rather large) @file{libc.so} will be loaded into memory. |
| 1149 | With vclib only the functions your program uses will be in RAM. |
| 1150 | However if you have several programs using newlib at the same |
| 1151 | time only one copy of @file{libc.so} should be loaded. |
| 1152 | @end itemize |
| 1153 | |
| 1154 | Things you should note: |
| 1155 | |
| 1156 | @itemize @minus |
| 1157 | @item With newlib you do not need extra math-libraries. |
| 1158 | |
| 1159 | @item You must link with a vbcc-specific @file{startup.o} from the newlib |
| 1160 | @file{lib/} directory as startup code. |
| 1161 | The config-file @file{newlib} will usually take care of this. |
| 1162 | |
| 1163 | @item You _must_ use the newlib-includes from the SDK |
| 1164 | rather than the ones which are for vc.lib. |
| 1165 | The config-file @file{newlib} will usually take care of this. |
| 1166 | |
| 1167 | @item There may be vbcc-related bugs in the SDK-newlib. Patches are |
| 1168 | automatically installed when using the Amiga Installer. When |
| 1169 | installing the target manually, you also have to fix the SDK |
| 1170 | manually. For a list of known SDK bugs at this point of time, |
| 1171 | @xref{Known Newlib Bugs}. |
| 1172 | @end itemize |
| 1173 | |
| 1174 | @node Known Newlib Bugs |
| 1175 | @subsubsection Known Newlib Bugs |
| 1176 | |
| 1177 | @itemize @minus |
| 1178 | |
| 1179 | @item The @code{__asm_toupper()} and @code{__asm_tolower()} assembler inlines |
| 1180 | in @file{newlib/include/ctype.h} are wrong, which makes |
| 1181 | @code{toupper()} and @code{tolower()} fail when including |
| 1182 | @file{ctype.h}. Fix: |
| 1183 | @example |
| 1184 | --- ctype.h.orig 2006-04-03 18:00:00.000000000 +0200 |
| 1185 | +++ ctype.h 2017-05-07 19:32:00.000000000 +0200 |
| 1186 | @@@@ -64,8 +64,8 @@@@ |
| 1187 | #elif defined(__VBCC__) |
| 1188 | int __asm_toupper(__reg("r3") int) = |
| 1189 | "\t.extern\t__ctype_ptr\n" |
| 1190 | - "\tlis\t11,(__ctype_ptr)@@ha\n" |
| 1191 | - "\taddi\t11,11,(__ctype_ptr)@@l\n" |
| 1192 | + "\tlis\t11,__ctype_ptr@@ha\n" |
| 1193 | + "\tlwz\t11,11,__ctype_ptr@@l(11)\n" |
| 1194 | "\tlbzx\t12,11,3\n" |
| 1195 | "\tandi.\t12,12,2\n" |
| 1196 | "\tbeq\t$+8\n" |
| 1197 | @@@@ -73,8 +73,8 @@@@ |
| 1198 | "#barrier"; |
| 1199 | int __asm_tolower(__reg("r3") int) = |
| 1200 | "\t.extern\t__ctype_ptr\n" |
| 1201 | - "\tlis\t11,(__ctype_ptr)@@ha\n" |
| 1202 | - "\taddi\t11,11,(__ctype_ptr)@@l\n" |
| 1203 | + "\tlis\t11,__ctype_ptr@@ha\n" |
| 1204 | + "\tlwz\t11,11,__ctype_ptr@@l(11)\n" |
| 1205 | "\tlbzx\t12,11,3\n" |
| 1206 | "\tandi.\t12,12,1\n" |
| 1207 | "\tbeq\t$+8\n" |
| 1208 | @end example |
| 1209 | Note: This should be fixed with the latest OS4 SDK, and the V0.9h |
| 1210 | installer will no longer install a patch! |
| 1211 | |
| 1212 | @item Newlib's @file{libauto.a} contains no working vbcc-style |
| 1213 | constructors or destructors for auto-opening or -closing of libraries. |
| 1214 | You can work-around it, by copying vclib's @file{libauto.a} to |
| 1215 | newlib's lib-directory. Rename it, if you don't want to overwrite |
| 1216 | the gcc-version of it. |
| 1217 | |
| 1218 | @item Some header files, like @file{sys/stat.h}, use the reserved vbcc |
| 1219 | attribute @code{__mask} as an argument name. The config file should |
| 1220 | take care of that, by redefining it as @code{___mask}. |
| 1221 | |
| 1222 | @end itemize |
| 1223 | |
| 1224 | @subsubsection Usage |
| 1225 | |
| 1226 | To compile a program to use newlib for OS4 you must make sure the proper |
| 1227 | config-file (@file{newlib}) is used, e.g. |
| 1228 | |
| 1229 | @example |
| 1230 | vc +newlib hello.c |
| 1231 | @end example |
| 1232 | |
| 1233 | With a new SDK this will usually generate a dynamically linked executable, |
| 1234 | which requires @file{libc.so}. To force a statically linked executable: |
| 1235 | |
| 1236 | @example |
| 1237 | vc +newlib -static hello.c |
| 1238 | @end example |
| 1239 | |
| 1240 | |
| 1241 | @section Atari TOS/MiNT |
| 1242 | |
| 1243 | This section describes specifics of the C library for Atari TOS and MiNT. |
| 1244 | M680x0 processors are supported by the target @file{m68k-atari}, while |
| 1245 | ColdFire processors are supported by the target @file{cf-atari}. Both |
| 1246 | share the same startup-code and are based on common library sources and |
| 1247 | header files. Executables linked with this C library run on plain TOS as |
| 1248 | well as on MiNT, without modifications. |
| 1249 | |
| 1250 | The relevant files are @file{startup.o}, @file{minstart.o}, |
| 1251 | @file{libvc.a}, @file{libm.a}, @file{libgem.a}. For the M68k target |
| 1252 | there are also math libs with FPU support (@file{libm881.a}, |
| 1253 | @file{libm040.a} and @file{libm060.a}) and 16-bit integer versions |
| 1254 | of all libraries (@file{lib*16.a}). |
| 1255 | |
| 1256 | The following config files are available: |
| 1257 | @table @code |
| 1258 | @item tos |
| 1259 | M68k 32-bit @code{int} for classic TOS machines. |
| 1260 | @item tos16 |
| 1261 | M68k 16-bit @code{int} for classic TOS machines. |
| 1262 | @item mint |
| 1263 | M68k 32-bit @code{int} for MiNT. Also works on classic machines, |
| 1264 | but uses an embedded a.out header for MiNT, includes a changeable |
| 1265 | @code{__stksize} and sets the FastLoad, FastRAM and FastAlloc flags |
| 1266 | in the header. |
| 1267 | @item mintcf |
| 1268 | ColdFire 32-bit @code{int}. Otherwise same as @file{mint}. |
| 1269 | @end table |
| 1270 | |
| 1271 | @subsection Startup |
| 1272 | |
| 1273 | The startup code @file{startup.o} sets up some |
| 1274 | global variables and initializes stdin, stdout and stderr and returns |
| 1275 | the unneeded memory to the system. |
| 1276 | The exit code closes all open files and frees all memory. |
| 1277 | |
| 1278 | @subsection Floating point |
| 1279 | |
| 1280 | Note that you have to link with a math library if you want to use |
| 1281 | floating point. All math functions, special startup code and |
| 1282 | printf/scanf functions which support floating point are contained in |
| 1283 | the math libraries only. |
| 1284 | |
| 1285 | On the M68k target you have the option to enable FPU support with |
| 1286 | the @option{-fpu} option and choose the appropriate math library |
| 1287 | (@xref{Floating point}). Otherwise, there is a soft-float library, |
| 1288 | which is compatible with all the Atari models without an FPU. |
| 1289 | |
| 1290 | @subsection Stack |
| 1291 | |
| 1292 | The default stack size is 64k. There is a MiNT tool called @file{stack} |
| 1293 | which can adjust the stack size of an executable to any value, by looking |
| 1294 | for a symbol named @code{__stksize} (defined by vclib's startup code). |
| 1295 | |
| 1296 | Additionally the required stack size can be specified by defining a |
| 1297 | variable @code{__stack} (of type @code{size_t}) with external linkage, as |
| 1298 | in other vbcc targets. |
| 1299 | |
| 1300 | @subsection 16-bit integer model |
| 1301 | |
| 1302 | The default libraries use 32-bit @code{int} types, but you may want to |
| 1303 | use 16-bit @code{int} types for compatibility reasons. In this case you |
| 1304 | have to specify the config file @code{tos16} and link with the appropriate |
| 1305 | 16-bit libraries (which have a '@file{16}' attached to their name). |
| 1306 | |
| 1307 | To compile and link a program using 16-bit integers a command like |
| 1308 | |
| 1309 | @example |
| 1310 | vc +tos16 test.c -o test -lm16 -lvc16 |
| 1311 | @end example |
| 1312 | |
| 1313 | may be used. There are no 16-bit versions for ColdFire targets, |
| 1314 | because this is strictly a 32-bit CPU. |
| 1315 | |
| 1316 | @subsection Restrictions |
| 1317 | |
| 1318 | The following list contains some restrictions of this version of the |
| 1319 | library: |
| 1320 | |
| 1321 | @table @code |
| 1322 | |
| 1323 | @item tmpfile() |
| 1324 | The @code{tmpfile()} function always returns an error. |
| 1325 | |
| 1326 | @item clock() |
| 1327 | The @code{clock()} function always returns -1. This is correct, |
| 1328 | according to the C standard, because neither under TOS nor under MiNT it |
| 1329 | is possible to obtain the time used by the calling process. |
| 1330 | |
| 1331 | @end table |
| 1332 | |
| 1333 | @section VideoCore/Linux |
| 1334 | |
| 1335 | This section describes specifics of the C library for VideoCore under Linux |
| 1336 | provided by the target @file{vidcore-linux}. |
| 1337 | |
| 1338 | The relevant files are @code{vcload}, @file{startup.o}, |
| 1339 | @file{libvc.a}, @file{libm.a}, @file{libms.a}. |
| 1340 | |
| 1341 | The config file @code{vc4-linux} is part of the library. |
| 1342 | |
| 1343 | @subsection Startup |
| 1344 | |
| 1345 | The startup code @file{startup.o} sets up stack and heap and provides |
| 1346 | a function @code{__armcall()} to transfer control to the loader on |
| 1347 | the ARM side. |
| 1348 | The startup process calls constructors to set up some |
| 1349 | global variables and initialize stdin, stdout and stderr if needed. |
| 1350 | |
| 1351 | @subsection Floating point |
| 1352 | |
| 1353 | Note that you have to link with a math library if you want to use |
| 1354 | floating point operations that are not natively implemented. |
| 1355 | All math functions, special startup code and |
| 1356 | printf/scanf functions which support floating point are contained in |
| 1357 | the math libraries only. |
| 1358 | |
| 1359 | @subsection Stack |
| 1360 | |
| 1361 | The library contains a default stack of 32KB. If another size is needed, |
| 1362 | you can add the following to your project: |
| 1363 | |
| 1364 | @example |
| 1365 | .align 4 |
| 1366 | .space <desired-size, suitably aligned> |
| 1367 | ___stackend: |
| 1368 | .global ___stackend |
| 1369 | @end example |
| 1370 | |
| 1371 | @subsection Heap |
| 1372 | |
| 1373 | Currently, a global variable of 16KB is used to get memory for |
| 1374 | malloc() etc. If another size is needed, |
| 1375 | you can add the following to your project: |
| 1376 | |
| 1377 | @example |
| 1378 | #define HEAPSIZE <desired size> |
| 1379 | |
| 1380 | char __heap[HEAPSIZE],*__heapptr=__heap; |
| 1381 | size_t __heapsize=HEAPSIZE; |
| 1382 | @end example |
| 1383 | |
| 1384 | Note that this mechanism will likely be changed in the future! |
| 1385 | |
| 1386 | @subsection System Calls |
| 1387 | |
| 1388 | To access system functions from the VideoCore-side, the function |
| 1389 | @code{__armcall()} can be used. It will save the current context and return |
| 1390 | to the loader. Registers @code{r0-r5} (the function arguments) will be saved |
| 1391 | and are available to the loader. The loader can then execute the system |
| 1392 | call and resume execution, passing the return value of the system |
| 1393 | function. |
| 1394 | |
| 1395 | Resuming is done by calling the image with offset 2. |
| 1396 | |
| 1397 | This functionality can also be used for debugging purposes. |
| 1398 | |
| 1399 | @subsection Loader |
| 1400 | |
| 1401 | A loader is required to execute VideoCore code from the ARM side. For |
| 1402 | standalone VideoCore code, the provided loader can be used. Usually, it |
| 1403 | will be necessary to adapt the loader to communicate between ARM and |
| 1404 | VideoCore side during runtime. |
| 1405 | |
| 1406 | @subsubsection Object Format |
| 1407 | |
| 1408 | Currently, the loader loads an simple binary image that must be pc-relative |
| 1409 | and located to address 0x00000000. Additionally, if present, a file |
| 1410 | with extension @file{.reltext} will be loaded for some limited |
| 1411 | relocation. This file contains a 32bit word containing the number of |
| 1412 | relocations followed by n 32bit words containing an offset. For each |
| 1413 | offset, the address will be relocated to the image load address. |
| 1414 | |
| 1415 | @subsubsection Command line arguments |
| 1416 | |
| 1417 | @code{vcload [-debug] [-cache] [-offset] <image-name>} |
| 1418 | |
| 1419 | The loader currently has the following options: |
| 1420 | |
| 1421 | @table @code |
| 1422 | |
| 1423 | @item -debug |
| 1424 | |
| 1425 | The loader will enter debug mode (see below). |
| 1426 | |
| 1427 | @item -cache |
| 1428 | |
| 1429 | The loader will set the LSB in the start address when executing |
| 1430 | code. This is supposed to inhibit a cache flush. |
| 1431 | |
| 1432 | Just for testing! |
| 1433 | |
| 1434 | @item -offset |
| 1435 | |
| 1436 | The loader will allocate 1 KB more memory than required and leaves |
| 1437 | this space unused at the beginning of the allocated memory. |
| 1438 | |
| 1439 | Just for testing! |
| 1440 | |
| 1441 | @end table |
| 1442 | |
| 1443 | @subsubsection Debug Mode |
| 1444 | |
| 1445 | In debug mode, the loader will wait for user input before starting the |
| 1446 | VideoCore code as well as after every @code{__armcall}. |
| 1447 | |
| 1448 | The following commands are available: |
| 1449 | |
| 1450 | @table @code |
| 1451 | @item w <addr> [<num>] |
| 1452 | Display <num> 32bit words starting at <addr>. |
| 1453 | <addr> must be the offset into the image. If <num> is omitted, |
| 1454 | one unit is displayed. |
| 1455 | |
| 1456 | If one word is displayed, it is additionally displayed translated |
| 1457 | as an offset into the image. |
| 1458 | |
| 1459 | @item h <addr> [<num>] |
| 1460 | Display <num> 16bit halfwords starting at <addr>. |
| 1461 | <addr> must be the offset into the image. If <num> is omitted, |
| 1462 | one unit is displayed. |
| 1463 | |
| 1464 | @item b <addr> [<num>] |
| 1465 | Display <num> 8bit bytes starting at <addr>. |
| 1466 | <addr> must be the offset into the image. If <num> is omitted, |
| 1467 | one unit is displayed. |
| 1468 | |
| 1469 | @item c |
| 1470 | Start/continue execution. |
| 1471 | |
| 1472 | @item q |
| 1473 | Quit. |
| 1474 | |
| 1475 | @item bp <addr> |
| 1476 | Set a breakpoint at <addr>. |
| 1477 | |
| 1478 | This is currently a very crude implementation. It will just write |
| 1479 | a branch to @code{__armcall()} to <addr>. If everything works well, |
| 1480 | you will end in the debugger if <addr> is reached. However, the |
| 1481 | arguments passed are random (and might be dangerous syscalls by |
| 1482 | accident). Also, the old code at this address is currently not |
| 1483 | restored. |
| 1484 | |
| 1485 | As a result, you must not continue execution after hitting a |
| 1486 | breakpoint! |
| 1487 | @end table |
| 1488 | |
| 1489 | |
| 1490 | @subsection Restrictions |
| 1491 | |
| 1492 | The following list contains some restrictions of this version of the |
| 1493 | library: |
| 1494 | |
| 1495 | @itemize @minus |
| 1496 | |
| 1497 | @item no real floating point support yet |
| 1498 | |
| 1499 | @item lots, lots, lots... |
| 1500 | |
| 1501 | |
| 1502 | @end itemize |
| 1503 | |
| 1504 | @section ATARI Jaguar/68k |
| 1505 | |
| 1506 | This section describes specifics of the C library for ATARI Jaguar |
| 1507 | provided by the target @file{m68k-jaguar}. |
| 1508 | |
| 1509 | The relevant files are @file{startup.o}, |
| 1510 | @file{libvc.a}, @file{libm.a}, @file{libjag.a}. |
| 1511 | |
| 1512 | The config files @code{jaguar_unix} and @code{jaguar_windows} are part of the library. |
| 1513 | |
| 1514 | @subsection Startup |
| 1515 | |
| 1516 | The startup code @file{startup.o} sets up stack and heap. |
| 1517 | The startup process calls constructors to set up some |
| 1518 | global variables and initialize stdin, stdout and stderr. |
| 1519 | |
| 1520 | The ATARI Jaguar has no OS, so it is impossible to define how input, output and files |
| 1521 | can be handled. There are a few set of function you have to define if you want to use stdio. |
| 1522 | |
| 1523 | Alternatively you can use the @file{libjag.a}. This library initializes a console window with stdout |
| 1524 | support and uses optionally a SkunkBoard to redirect stderr and file I/O. |
| 1525 | |
| 1526 | @subsection Floating point |
| 1527 | |
| 1528 | Note that you have to link with a math library if you want to use |
| 1529 | floating point operations that are not natively implemented. |
| 1530 | All math functions, special startup code and |
| 1531 | printf/scanf functions which support floating point are contained in |
| 1532 | the math library only. Consider the ATARI Jaguar does not own a FPU so this library is pretty slow. |
| 1533 | |
| 1534 | @subsection Stack |
| 1535 | |
| 1536 | The library contains a default stack of 32KB. If another size is needed, |
| 1537 | you can add a global variable named __stack to your code: |
| 1538 | |
| 1539 | @example |
| 1540 | |
| 1541 | /* Set 64kB stack */ |
| 1542 | unsigned long __stack = 65536; |
| 1543 | |
| 1544 | @end example |
| 1545 | |
| 1546 | @subsection Heap |
| 1547 | |
| 1548 | Currently the free RAM is used as global heapsize for malloc() etc. |
| 1549 | |
| 1550 | It is necessary to place a symbol named _BSS_END at the end of the BSS segment. |
| 1551 | The heap allocates the free RAM between _BSS_END and the bottom of the stack. |
| 1552 | |
| 1553 | If less size is needed feel free to manipulate the value of _BSS_END. |
| 1554 | |
| 1555 | All allocated heap objects can be used as internal JAGUAR objects, because they are qhrase aligned. |
| 1556 | |
| 1557 | @subsection stdio support |
| 1558 | |
| 1559 | The ATARI Jaguar lacks stdio support. So the @file{libvc.a} has just empty stub functions for |
| 1560 | open, close, read and write, which you may overwrite if you need stdio. |
| 1561 | Alternatively you can use @file{libjag.a} which has simple stdio |
| 1562 | and file I/O functionality. |
| 1563 | |
| 1564 | @example |
| 1565 | /** |
| 1566 | * param name: name mentioned in fopen |
| 1567 | * param mode: mode mentioned in fopen |
| 1568 | * returns: > 0 a valid file handle |
| 1569 | * < 0 to indicate an error |
| 1570 | * the values 0,1,2 are used by stdin, stdout and stderr |
| 1571 | * |
| 1572 | * No need to handle stdin, stdout and stderr here |
| 1573 | */ |
| 1574 | int jagopen(const char *name,const char *mode) |
| 1575 | |
| 1576 | /** |
| 1577 | * param handle: handle from jagopen |
| 1578 | * |
| 1579 | * No need to handle stdin, stdout and stderr here |
| 1580 | */ |
| 1581 | void jagclose(int handle) |
| 1582 | |
| 1583 | /** |
| 1584 | * param handle: handle from jagopen |
| 1585 | * param p: points to the char buffer to fill. |
| 1586 | * param l: buffer size of p |
| 1587 | * returns: >=0 number of read bytes |
| 1588 | <0 indicate an error |
| 1589 | * |
| 1590 | * Handle stdin, stdout and stderr here |
| 1591 | */ |
| 1592 | size_t jagread(int handle,char *p,size_t l) |
| 1593 | |
| 1594 | /** |
| 1595 | * param handle: handle from jagopen |
| 1596 | * param p: points to the char buffer to write. |
| 1597 | * param l: number of bytes of p |
| 1598 | * returns: >=0 number of bytes written |
| 1599 | <0 indicate an error |
| 1600 | * |
| 1601 | * Handle stdin, stdout and stderr here |
| 1602 | */ |
| 1603 | size_t jagwrite(int handle,const char *p, size_t l) |
| 1604 | |
| 1605 | /** |
| 1606 | * param handle: handle from jagopen |
| 1607 | * param offset: number of bytes to seek. |
| 1608 | * param direction: see fseek direction |
| 1609 | * returns: =0 successful seek |
| 1610 | <>0 indicate an error |
| 1611 | -1: seek not supported |
| 1612 | * |
| 1613 | * Handle stdin, stdout and stderr here |
| 1614 | */ |
| 1615 | long jagseek(int handle,long offset,int direction) |
| 1616 | @end example |
| 1617 | |
| 1618 | @subsection The jaglib |
| 1619 | |
| 1620 | The jaglib @file{libjag.a} provides simple functions to support your first |
| 1621 | steps in ATARI Jaguar programming. It initializes a simple console output window and comes with |
| 1622 | an old ATARI character set. |
| 1623 | If a SkunkBoard is available I/O functionality can be redirected. |
| 1624 | |
| 1625 | Your first Jaguar program can look like this: |
| 1626 | |
| 1627 | @example |
| 1628 | |
| 1629 | #include <stdio.h> |
| 1630 | |
| 1631 | int main() |
| 1632 | @{ |
| 1633 | printf("Hello, world\n"); |
| 1634 | @} |
| 1635 | |
| 1636 | @end example |
| 1637 | |
| 1638 | Keep in mind: Your JAGUAR will get a red background color to indicate @code{main()} has exited. |
| 1639 | |
| 1640 | The jaglib API documentation is available in a separate document. There is more demo code |
| 1641 | available in the @uref{https://github.com/toarnold/jaglib-demo, jaglib-demo} gibhub repository. |
| 1642 | |
| 1643 | @section 6502/C64 |
| 1644 | |
| 1645 | This is a port of vclib to the C64. |
| 1646 | |
| 1647 | @subsection Startup and Memory |
| 1648 | |
| 1649 | Startup and memory layout is described in the following paragraphs. |
| 1650 | |
| 1651 | @subsubsection Startup |
| 1652 | |
| 1653 | The default linker file creates program files that are loaded to address |
| 1654 | 0x801. A BASIC line is included so that the program can be started using @code{RUN} |
| 1655 | from BASIC. The startup code |
| 1656 | will turn off the BASIC ROM to allow usage of RAM until 0xD000 and most of the |
| 1657 | zero page without need for any special handling. The BSS segment will be cleared |
| 1658 | during startup. |
| 1659 | |
| 1660 | With the default configuration, after exiting the C program, an infinite loop will |
| 1661 | be entered. When using the @code{+c64r} config, the program will return to BASIC |
| 1662 | an can be started again. |
| 1663 | However, this needs additional memory as the init values for the data section have |
| 1664 | to be stored in RAM. Also, some register values and zero page contents have to be |
| 1665 | saved. The overhead depends on the amount of initialized variables. |
| 1666 | |
| 1667 | @subsubsection Command line |
| 1668 | |
| 1669 | Command line parameters are supported by using the convention/code submitted by |
| 1670 | Stefan Haubenthal. |
| 1671 | |
| 1672 | Command-lines look like these lines: |
| 1673 | |
| 1674 | @example |
| 1675 | run |
| 1676 | run : rem |
| 1677 | run:rem arg1 " arg 2 is quoted " arg3 "" arg5 |
| 1678 | @end example |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | @subsubsection Zero Page |
| 1683 | |
| 1684 | @code{vbcc} uses a number of zero page locations for register variables, stack |
| 1685 | pointer etc. in section @code{zpage}. Also, variables can be mapped to zero page using |
| 1686 | the @code{__zpage} attribute. By default the area @code{0x02..0x8d} |
| 1687 | is used, but this can be changed in the linker file. |
| 1688 | |
| 1689 | @subsubsection Stack |
| 1690 | |
| 1691 | By default, the user stack is mapped from @code{0xC800..0xD000}. The size can be |
| 1692 | changed at the top of @code{vlink.cmd}. |
| 1693 | |
| 1694 | @subsubsection Heap |
| 1695 | |
| 1696 | Code and data/BSS are mapped starting after the BASIC init line. |
| 1697 | The heap is placed in the remaining space to stack start. |
| 1698 | |
| 1699 | @subsubsection Banking |
| 1700 | |
| 1701 | The following banking models are supported: |
| 1702 | |
| 1703 | @table @code |
| 1704 | @item -reuflat |
| 1705 | This library supports a REU using a flat 16MB address space. The memory has to |
| 1706 | be addressed through far-pointers. It is not possible to declare variables in |
| 1707 | the REU nor to place code in the REU. The memory is addressed as 0x000000 to |
| 1708 | 0xFFFFFF. All accesses through far-pointers are addressing the REU. It is not |
| 1709 | possible to address the C64 memory through a far-pointer. |
| 1710 | |
| 1711 | Far-pointer arithmetic only works on the lower 16bits. It is not possible to |
| 1712 | cross a bank boundary using far-pointers. Huge-pointers will support this, but |
| 1713 | are not yet fully implemented. In the meantime it is possible to use long integers |
| 1714 | and cast them to far-pointers. |
| 1715 | |
| 1716 | Use @code{-lreuflat} to link with this library. Note that the library does |
| 1717 | not check for the presence of a REU. |
| 1718 | |
| 1719 | @item -reubank |
| 1720 | This configuration reserves a 16KB memory space within the C64 memory as window |
| 1721 | for banking. As the bank number is stored as a single byte (with bank |
| 1722 | 255 denoting the unbanked memory), it is only possible to address up to |
| 1723 | about 4MB of memory in the REU. |
| 1724 | |
| 1725 | Variables and code can be mapped into the REU using the @code{__bank()} attribute |
| 1726 | or @code{#pragma bank}. When calling a banked function, the corresponding bank |
| 1727 | will be copied from the REU into the C64 memory window. |
| 1728 | |
| 1729 | Use the @code{+c64reu} configuration to use this mechanism. Currently the |
| 1730 | linker file provides 8 banks resulting in a 128K REU image. More banks can |
| 1731 | be added for larger expansions. |
| 1732 | |
| 1733 | The configuration will create a usually C64 prg file containing the unbanked |
| 1734 | code and data as well as a REU image with extension @code{.b0}. It must |
| 1735 | be loaded (e.g. with an emulator or the TurboChameleon) before the prg file |
| 1736 | can is executed. |
| 1737 | @end table |
| 1738 | |
| 1739 | |
| 1740 | @subsection Runtime |
| 1741 | |
| 1742 | Apart from standard C library functions, @code{libvc.a} also provides a few |
| 1743 | runtime support functions needed by the compiler. Apart from the math and |
| 1744 | floating point functions mentioned in the documentation of the 6502 backend, |
| 1745 | it includes functions for saving/restoring registers. |
| 1746 | |
| 1747 | @subsection @code{stdio} |
| 1748 | |
| 1749 | stdio supports @code{stdout}, @code{stderr} (both using the |
| 1750 | screen) and @code{stdin} (keyboard). Both are unbuffered by default. |
| 1751 | |
| 1752 | Furthermore, file IO with standard C functions is supported |
| 1753 | for 1541 and compatible disk drives. Other devices have not been tested. |
| 1754 | Only sequential reading and writing of files is supported. No seeking etc. |
| 1755 | There are hardcoded limits for the maximum number of open files and the |
| 1756 | maximum length of filenames. |
| 1757 | |
| 1758 | The @code{remove()} and @code{rename()} functions are supported using 1541 |
| 1759 | |
| 1760 | By default, device ID 8 is used. Another device ID can be specified as prefix |
| 1761 | to the filename: |
| 1762 | |
| 1763 | @example |
| 1764 | /* try to open file "test" on the second drive */ |
| 1765 | FILE *f; |
| 1766 | f=fopen("9:test","r"); |
| 1767 | ... |
| 1768 | @end example |
| 1769 | |
| 1770 | @code{printf/scanf} functions which support floating point are contained in |
| 1771 | the math library only. |
| 1772 | |
| 1773 | |
| 1774 | @subsection Floating Point / wozfp |
| 1775 | |
| 1776 | When using floating point, the math library @code{libm.a} must be linked using |
| 1777 | the @code{-lm} option. It contains the floating routines as well as versions of |
| 1778 | the @code{printf/scanf} family that support floating point. |
| 1779 | |
| 1780 | The floating point routines are based on Steve Wozniaks routines from the 70s, |
| 1781 | somewhat adapted to the ABI of @code{vbcc}. These functions are small and |
| 1782 | reasonably usable, but they do not fully satisfy the requirements of C99. |
| 1783 | |
| 1784 | Only a part of the C library functions for floating point is implemented. The |
| 1785 | list currently includes: |
| 1786 | |
| 1787 | @itemize |
| 1788 | @item @code{exp()} |
| 1789 | @item @code{pow()} |
| 1790 | @item @code{log()} |
| 1791 | @item @code{log10()} |
| 1792 | @end itemize |
| 1793 | |
| 1794 | @subsection Floating Point / IEEE |
| 1795 | |
| 1796 | When using IEEE floating point, @code{-ieee} must be specified and the math library |
| 1797 | @code{libmieee.a} must be linked using |
| 1798 | the @code{-lmieee} option. It contains the floating routines as well as versions of |
| 1799 | the @code{printf/scanf} family that support floating point. |
| 1800 | |
| 1801 | The floating point routines are based on SANE, |
| 1802 | somewhat adapted to the ABI of @code{vbcc} using wrapper functions. |
| 1803 | These functions should be fully C and IEEE compliant and provide precise results for |
| 1804 | 32 and 64bit floating point numbers (the library actually internally calculates |
| 1805 | all operation using 80bits, but vbcc currently only uses up to 64 bits). |
| 1806 | |
| 1807 | Currently, this library probably must be run from RAM. |
| 1808 | |
| 1809 | Most parts of the C library functions for floating point are implemented. The |
| 1810 | list currently includes: |
| 1811 | |
| 1812 | @itemize |
| 1813 | @item @code{exp(), expf(), expl()} |
| 1814 | @item @code{exp2(), exp2f(), exp2l()} |
| 1815 | @item @code{exp1m(), exp1mf(), exp1ml()} |
| 1816 | @item @code{pow(), powf(), powl()} |
| 1817 | @item @code{log(), logf(), logl()} |
| 1818 | @item @code{log1p(), log1pf(), log1pl()} |
| 1819 | @item @code{log2(), log2f(), log2l()} |
| 1820 | @item @code{log10(), log10f(), log10l()} |
| 1821 | @item @code{sqrt(), sqrtf(), sqrtl()} |
| 1822 | @item @code{sin(), sinf(), sinl()} |
| 1823 | @item @code{cos(), cosf(), cosl()} |
| 1824 | @item @code{tan(), tanf(), tanl()} |
| 1825 | @item @code{atan(), atanf(), atanl()} |
| 1826 | |
| 1827 | |
| 1828 | @end itemize |
| 1829 | |
| 1830 | @section 6502/NES |
| 1831 | |
| 1832 | This is a port of vclib to the NES console. |
| 1833 | |
| 1834 | |
| 1835 | @subsection Startup and Memory |
| 1836 | |
| 1837 | Startup and memory layout is dependent on the ROM used. Currently two example configurations |
| 1838 | are provided. They can be selected with @code{+nrom256v} and @code{+unrom512v}. Have a |
| 1839 | look at the corresponding linker scripts in @code{vbcc/targets/6502-nes} for further |
| 1840 | details. |
| 1841 | |
| 1842 | The necessary library routines to support configurations with several ROM banks are |
| 1843 | included. |
| 1844 | |
| 1845 | @subsubsection Zero Page |
| 1846 | |
| 1847 | @code{vbcc} uses a number of zero page locations for register variables, stack |
| 1848 | pointer etc. in section @code{zpage}. Also, variables can be mapped to zero page using |
| 1849 | the @code{__zpage} attribute. The entire zero page can be used, but this can be changed |
| 1850 | in the linker file. |
| 1851 | |
| 1852 | @subsubsection Stack |
| 1853 | |
| 1854 | By default, the user stack starts from @code{0x0800} growing downwards. |
| 1855 | |
| 1856 | @subsubsection Heap |
| 1857 | |
| 1858 | By default, code and data/BSS are mapped starting after the system stack at @code{0x0200}. |
| 1859 | The heap is placed in the remaining space to stack start. |
| 1860 | |
| 1861 | @subsection Runtime |
| 1862 | |
| 1863 | Apart from standard C library functions, @code{libvc.a} also provides a few |
| 1864 | runtime support functions needed by the compiler. Apart from the math and |
| 1865 | floating point functions mentioned in the documentation of the 6502 backend, |
| 1866 | it includes functions for saving/restoring registers. |
| 1867 | |
| 1868 | @subsection @code{stdio} |
| 1869 | |
| 1870 | At the moment, stdio only supports @code{stdout}, @code{stderr} (both using the |
| 1871 | screen) and @code{stdin} (simple input via joypad). |
| 1872 | |
| 1873 | @code{printf/scanf} functions which support floating point are contained in |
| 1874 | the math library only. |
| 1875 | |
| 1876 | For input, up/down changes the current character, left/right moves the cursor, |
| 1877 | the B button deletes from the cursor position, and the A button confirms the input. |
| 1878 | You do not want to use this in real code. |
| 1879 | |
| 1880 | The library contains a default character set. To replace it, link an object that |
| 1881 | contains a character set mapped to section @code{chars} and defines the global symbol |
| 1882 | @code{___stdchr}. |
| 1883 | |
| 1884 | To replace stdio, the function @code{__read()} and @code{__write()} have to be |
| 1885 | implemented. |
| 1886 | |
| 1887 | @subsection Interrupts |
| 1888 | |
| 1889 | The library contains a default NMI implementation that is used for stdio handling |
| 1890 | and the @code{clock()}-function. It can be replaced by linking with an own |
| 1891 | implementation that starts at the global symbol @code{___nmi}. In this case the stdio and |
| 1892 | timing functions from vclib can not be used. |
| 1893 | |
| 1894 | @code{___irq} can be used to overwrite the other IRQ vector. The default implementation |
| 1895 | in the library immediately returns. |
| 1896 | |
| 1897 | @subsection Floating Point / wozfp |
| 1898 | |
| 1899 | When using floating point, the math library @code{libm.a} must be linked using |
| 1900 | the @code{-lm} option. It contains the floating routines as well as versions of |
| 1901 | the @code{printf/scanf} family that support floating point. |
| 1902 | |
| 1903 | The floating point routines are based on Steve Wozniaks routines from the 70s, |
| 1904 | somewhat adapted to the ABI of @code{vbcc}. These functions are small and |
| 1905 | reasonably usable, but they do not fully satisfy the requirements of C99. |
| 1906 | |
| 1907 | Only a part of the C library functions for floating point is implemented. The |
| 1908 | list currently includes: |
| 1909 | |
| 1910 | @itemize |
| 1911 | @item @code{exp()} |
| 1912 | @item @code{pow()} |
| 1913 | @item @code{log()} |
| 1914 | @item @code{log10()} |
| 1915 | @end itemize |
| 1916 | |
| 1917 | @subsection Floating Point / IEEE |
| 1918 | |
| 1919 | IEEE floating point is currently not available for this target. |
| 1920 | |
| 1921 | |
| 1922 | @section 6502/Atari |
| 1923 | |
| 1924 | This is a port of vclib to Atari 8bit computers. |
| 1925 | |
| 1926 | @subsection Startup and Memory |
| 1927 | |
| 1928 | Startup and memory layout is described in the following paragraphs. |
| 1929 | |
| 1930 | @subsubsection Startup |
| 1931 | |
| 1932 | The default linker file creates program files that are loaded to address |
| 1933 | 0x600. The memory area can be adapted by changing @code{MEMSTART} and |
| 1934 | @code{MEMEND} in @code{vlink.cmd}. |
| 1935 | |
| 1936 | With the default configuration, after exiting the C program, it will wait |
| 1937 | for pressing the return key before returning to DOS. |
| 1938 | |
| 1939 | @subsubsection Command line |
| 1940 | |
| 1941 | Command line parameters are not yet supported. |
| 1942 | |
| 1943 | @subsubsection Zero Page |
| 1944 | |
| 1945 | @code{vbcc} uses a number of zero page locations for register variables, stack |
| 1946 | pointer etc. in section @code{zpage}. Also, variables can be mapped to zero page using |
| 1947 | the @code{__zpage} attribute. By default the area @code{0x82..0xFF} |
| 1948 | is used, but this can be changed in the linker file. |
| 1949 | |
| 1950 | @subsubsection Stack |
| 1951 | |
| 1952 | By default, the startup code maps the user stack from |
| 1953 | @code{MEMTOP-STACKLEN..MEMTOP}. |
| 1954 | The size can be changed at the top of @code{vlink.cmd}. |
| 1955 | |
| 1956 | @subsubsection Heap |
| 1957 | |
| 1958 | Code and data/BSS are mapped starting at @code{MEMSTART}. |
| 1959 | The heap is placed in the remaining space to stack start. |
| 1960 | |
| 1961 | @subsubsection Banking |
| 1962 | |
| 1963 | Banking support for this target has not yet been implemented. |
| 1964 | |
| 1965 | @subsection Runtime |
| 1966 | |
| 1967 | Apart from standard C library functions, @code{libvc.a} also provides a few |
| 1968 | runtime support functions needed by the compiler. Apart from the math and |
| 1969 | floating point functions mentioned in the documentation of the 6502 backend, |
| 1970 | it includes functions for saving/restoring registers. |
| 1971 | |
| 1972 | @subsection @code{stdio} |
| 1973 | |
| 1974 | At the moment, stdio only supports @code{stdout}, @code{stderr} (both using the |
| 1975 | screen) and @code{stdin} (keyboard). Both are line-buffered by default. |
| 1976 | |
| 1977 | @code{printf/scanf} functions which support floating point are contained in |
| 1978 | the math library only. |
| 1979 | |
| 1980 | |
| 1981 | @subsection Floating Point / wozfp |
| 1982 | |
| 1983 | When using floating point, the math library @code{libm.a} must be linked using |
| 1984 | the @code{-lm} option. It contains the floating routines as well as versions of |
| 1985 | the @code{printf/scanf} family that support floating point. |
| 1986 | |
| 1987 | The floating point routines are based on Steve Wozniaks routines from the 70s, |
| 1988 | somewhat adapted to the ABI of @code{vbcc}. These functions are small and |
| 1989 | reasonably usable, but they do not fully satisfy the requirements of C99. |
| 1990 | |
| 1991 | Only a part of the C library functions for floating point is implemented. The |
| 1992 | list currently includes: |
| 1993 | |
| 1994 | @itemize |
| 1995 | @item @code{exp()} |
| 1996 | @item @code{pow()} |
| 1997 | @item @code{log()} |
| 1998 | @item @code{log10()} |
| 1999 | @end itemize |
| 2000 | |
| 2001 | @subsection Floating Point / IEEE |
| 2002 | |
| 2003 | When using IEEE floating point, @code{-ieee} must be specified and the math library |
| 2004 | @code{libmieee.a} must be linked using |
| 2005 | the @code{-lmieee} option. It contains the floating routines as well as versions of |
| 2006 | the @code{printf/scanf} family that support floating point. |
| 2007 | |
| 2008 | The floating point routines are based on SANE, |
| 2009 | somewhat adapted to the ABI of @code{vbcc} using wrapper functions. |
| 2010 | These functions should be fully C and IEEE compliant and provide precise results for |
| 2011 | 32 and 64bit floating point numbers (the library actually internally calculates |
| 2012 | all operation using 80bits, but vbcc currently only uses up to 64 bits). |
| 2013 | |
| 2014 | Currently, this library probably must be run from RAM. |
| 2015 | |
| 2016 | Most parts of the C library functions for floating point are implemented. The |
| 2017 | list currently includes: |
| 2018 | |
| 2019 | @itemize |
| 2020 | @item @code{exp(), expf(), expl()} |
| 2021 | @item @code{exp2(), exp2f(), exp2l()} |
| 2022 | @item @code{exp1m(), exp1mf(), exp1ml()} |
| 2023 | @item @code{pow(), powf(), powl()} |
| 2024 | @item @code{log(), logf(), logl()} |
| 2025 | @item @code{log1p(), log1pf(), log1pl()} |
| 2026 | @item @code{log2(), log2f(), log2l()} |
| 2027 | @item @code{log10(), log10f(), log10l()} |
| 2028 | @item @code{sqrt(), sqrtf(), sqrtl()} |
| 2029 | @item @code{sin(), sinf(), sinl()} |
| 2030 | @item @code{cos(), cosf(), cosl()} |
| 2031 | @item @code{tan(), tanf(), tanl()} |
| 2032 | @item @code{atan(), atanf(), atanl()} |
| 2033 | |
| 2034 | |
| 2035 | @end itemize |
| 2036 | |
| 2037 | @section 6502/BBC Micro/Master |
| 2038 | |
| 2039 | This is a port of vclib to BBC 8bit computers. |
| 2040 | |
| 2041 | @subsection Startup and Memory |
| 2042 | |
| 2043 | Startup and memory layout is described in the following paragraphs. |
| 2044 | |
| 2045 | @subsubsection Startup |
| 2046 | |
| 2047 | The default linker file creates program files that are loaded to address |
| 2048 | 0x1900 up to 0x7B00 with 256 bytes of software stack. The memory area can be adapted by |
| 2049 | changing @code{OSHWM}, @code{HIMEM} and @code{STACKSTART} in @code{vlink.cmd}. |
| 2050 | |
| 2051 | With the default configuration (@code{+bbc}), after exiting the C program, the code will |
| 2052 | enter an endless loop. If the reentrant configs are used (@code{+bbcr} or |
| 2053 | @code{+bbcbr}), the program will return to the command prompt. As this |
| 2054 | requires saving the zero page, a bit more memory is used. |
| 2055 | |
| 2056 | |
| 2057 | @subsubsection Command line |
| 2058 | |
| 2059 | If @code{main()} uses arguments, the command line parameters will be passed |
| 2060 | accordingly. There are hardcoded limits to the number of arguments (currently 8) |
| 2061 | and the maximum total command length (currently 80). |
| 2062 | |
| 2063 | Space is used to separate arguments. The quote character (@code{"}) can be used |
| 2064 | to group arguments containing spaces. |
| 2065 | |
| 2066 | |
| 2067 | @subsubsection Zero Page |
| 2068 | |
| 2069 | @code{vbcc} uses a number of zero page locations for register variables, stack |
| 2070 | pointer etc. in section @code{zpage}. Also, variables can be mapped to zero page using |
| 2071 | the @code{__zpage} attribute. By default the area @code{0x00..0x90} |
| 2072 | is used, but this can be changed in the linker file. |
| 2073 | |
| 2074 | @subsubsection Stack |
| 2075 | |
| 2076 | By default, the startup code maps the user stack from |
| 2077 | @code{STACKSTART..HIMEM}. |
| 2078 | The size can be changed at the top of @code{vlink.cmd}. |
| 2079 | |
| 2080 | @subsubsection Heap |
| 2081 | |
| 2082 | Code and data/BSS are mapped starting at @code{OSHWM}. |
| 2083 | The heap is placed in the remaining space to stack start. |
| 2084 | |
| 2085 | @subsubsection Banking |
| 2086 | |
| 2087 | When using the @code{+bbcb} or @code{bbcbr} configurations, vbcc supports |
| 2088 | banked memory, including automated bank-switching. Up to 16 sections of 16K |
| 2089 | size are supported. Each section starts at 0x8000. |
| 2090 | |
| 2091 | The corresponding linker |
| 2092 | files @code{vlinkb.cmd} and @code{vlinkbr.cmd} can be edited to choose the |
| 2093 | banks that are required. Unused banks can be removed by commenting out |
| 2094 | (using old-style C-comments) the corresponding entries in the @code{SECTIONS} |
| 2095 | part of the linker file. When using bank 1-3 the section in the linker file |
| 2096 | could look like this: |
| 2097 | |
| 2098 | @example |
| 2099 | ... |
| 2100 | |
| 2101 | SECTIONS |
| 2102 | @{ |
| 2103 | text : @{*(text)@} >ram |
| 2104 | .dtors : @{ *(.dtors) @} > ram |
| 2105 | .ctors : @{ *(.ctors) @} > ram |
| 2106 | rodata : @{*(rodata)@} >ram |
| 2107 | data: @{*(data)@} >ram |
| 2108 | init : @{*(init)@} >ram |
| 2109 | zpage (NOLOAD) : @{*(zpage) *(zp1) *(zp2)@} >zero |
| 2110 | bss (NOLOAD): @{*(bss)@} >ram |
| 2111 | |
| 2112 | /* |
| 2113 | b0 : @{.=PAGEADDR; *(text0) *(rodata0) *(data0) *(bss0) |
| 2114 | RESERVE(PAGEADDR+PAGESIZE-.); |
| 2115 | @} >b0 AT>dummy0 |
| 2116 | */ |
| 2117 | |
| 2118 | b1 : @{.=PAGEADDR; *(text1) *(rodata1) *(data1) *(bss1) |
| 2119 | RESERVE(PAGEADDR+PAGESIZE-.); |
| 2120 | @} >b1 AT>dummy1 |
| 2121 | |
| 2122 | b2 : @{.=PAGEADDR; *(text2) *(rodata2) *(data2) *(bss2) |
| 2123 | RESERVE(PAGEADDR+PAGESIZE-.); |
| 2124 | @} >b2 AT>dummy2 |
| 2125 | |
| 2126 | b3 : @{.=PAGEADDR; *(text3) *(rodata3) *(data3) *(bss3) |
| 2127 | RESERVE(PAGEADDR+PAGESIZE-.); |
| 2128 | @} >b3 AT>dummy3 |
| 2129 | /* |
| 2130 | b4 : @{.=PAGEADDR; *(text4) *(rodata4) *(data4) *(bss4) |
| 2131 | RESERVE(PAGEADDR+PAGESIZE-.); |
| 2132 | @} >b4 AT>dummy4 |
| 2133 | */ |
| 2134 | |
| 2135 | ... |
| 2136 | |
| 2137 | @end example |
| 2138 | |
| 2139 | During the linking process, apart from the normal output file, a 16K large |
| 2140 | image for each bank and a loader script will be generated. E.g. when using banks |
| 2141 | 1-3 and using the output file name test, the following files will be generated: |
| 2142 | |
| 2143 | @table @code |
| 2144 | @item @code{test} |
| 2145 | The unbanked code/data. |
| 2146 | |
| 2147 | @item @code{test.inf} |
| 2148 | Info file with start address. |
| 2149 | |
| 2150 | @item @code{testb1} |
| 2151 | Image for bank1. |
| 2152 | |
| 2153 | @item @code{testb2} |
| 2154 | Image for bank2. |
| 2155 | |
| 2156 | @item @code{testb2} |
| 2157 | Image for bank2. |
| 2158 | |
| 2159 | @item @code{loadtest} |
| 2160 | Loader |
| 2161 | |
| 2162 | @end table |
| 2163 | |
| 2164 | The contents of the loader @code{loadtest} will look like this: |
| 2165 | |
| 2166 | @example |
| 2167 | *srload testb1 8000 1 |
| 2168 | *srload testb2 8000 2 |
| 2169 | *srload testb3 8000 3 |
| 2170 | *run test |
| 2171 | @end example |
| 2172 | |
| 2173 | The program can be started with @code{*exec loadtest}. |
| 2174 | |
| 2175 | @subsection Runtime |
| 2176 | |
| 2177 | Apart from standard C library functions, @code{libvc.a} also provides a few |
| 2178 | runtime support functions needed by the compiler. Apart from the math and |
| 2179 | floating point functions mentioned in the documentation of the 6502 backend, |
| 2180 | it includes functions for saving/restoring registers. |
| 2181 | |
| 2182 | @subsection @code{stdio} |
| 2183 | |
| 2184 | @code{stdout}, @code{stderr} (both using the screen) and @code{stdin} (keyboard) |
| 2185 | are supported. Furthermore normal file operations are possible using the |
| 2186 | usual C functions. There are hardcoded limits on the maximum number of |
| 2187 | simultaneously open files as well as the length of filenames. |
| 2188 | |
| 2189 | Sequential reading and writing is supported, but no seeking. Furthermore, the |
| 2190 | @code{remove()} call is supported. |
| 2191 | |
| 2192 | When using stdio to emit VDU control sequences, the function |
| 2193 | @code{__vdu_sequence()} is available to ensure verbatim 1:1 transmission |
| 2194 | of all characters: |
| 2195 | |
| 2196 | @example |
| 2197 | /* print diagonal line */ |
| 2198 | __vdu_sequence(1); |
| 2199 | for(int i=0;i<20;i++) |
| 2200 | printf("\x1f%c%cO",i,i); |
| 2201 | __vdu_sequence(0); |
| 2202 | @end example |
| 2203 | |
| 2204 | @code{printf/scanf} functions which support floating point are contained in |
| 2205 | the math library only. |
| 2206 | |
| 2207 | |
| 2208 | @subsection Floating Point / wozfp |
| 2209 | |
| 2210 | When using floating point, the math library @code{libm.a} must be linked using |
| 2211 | the @code{-lm} option. It contains the floating routines as well as versions of |
| 2212 | the @code{printf/scanf} family that support floating point. |
| 2213 | |
| 2214 | The floating point routines are based on Steve Wozniaks routines from the 70s, |
| 2215 | somewhat adapted to the ABI of @code{vbcc}. These functions are small and |
| 2216 | reasonably usable, but they do not fully satisfy the requirements of C99. |
| 2217 | |
| 2218 | Only a part of the C library functions for floating point is implemented. The |
| 2219 | list currently includes: |
| 2220 | |
| 2221 | @itemize |
| 2222 | @item @code{exp()} |
| 2223 | @item @code{pow()} |
| 2224 | @item @code{log()} |
| 2225 | @item @code{log10()} |
| 2226 | @end itemize |
| 2227 | |
| 2228 | @subsection Floating Point / IEEE |
| 2229 | |
| 2230 | When using IEEE floating point, @code{-ieee} must be specified and the math library |
| 2231 | @code{libmieee.a} must be linked using |
| 2232 | the @code{-lmieee} option. It contains the floating routines as well as versions of |
| 2233 | the @code{printf/scanf} family that support floating point. |
| 2234 | |
| 2235 | The floating point routines are based on SANE, |
| 2236 | somewhat adapted to the ABI of @code{vbcc} using wrapper functions. |
| 2237 | These functions should be fully C and IEEE compliant and provide precise results for |
| 2238 | 32 and 64bit floating point numbers (the library actually internally calculates |
| 2239 | all operation using 80bits, but vbcc currently only uses up to 64 bits). |
| 2240 | |
| 2241 | Currently, this library probably must be run from RAM. |
| 2242 | |
| 2243 | Most parts of the C library functions for floating point are implemented. The |
| 2244 | list currently includes: |
| 2245 | |
| 2246 | @itemize |
| 2247 | @item @code{exp(), expf(), expl()} |
| 2248 | @item @code{exp2(), exp2f(), exp2l()} |
| 2249 | @item @code{exp1m(), exp1mf(), exp1ml()} |
| 2250 | @item @code{pow(), powf(), powl()} |
| 2251 | @item @code{log(), logf(), logl()} |
| 2252 | @item @code{log1p(), log1pf(), log1pl()} |
| 2253 | @item @code{log2(), log2f(), log2l()} |
| 2254 | @item @code{log10(), log10f(), log10l()} |
| 2255 | @item @code{sqrt(), sqrtf(), sqrtl()} |
| 2256 | @item @code{sin(), sinf(), sinl()} |
| 2257 | @item @code{cos(), cosf(), cosl()} |
| 2258 | @item @code{tan(), tanf(), tanl()} |
| 2259 | @item @code{atan(), atanf(), atanl()} |
| 2260 | |
| 2261 | |
| 2262 | @end itemize |
| 2263 | |
| 2264 | |
| 2265 | |
| 2266 | @section 6502/MEGA65 |
| 2267 | |
| 2268 | This is a port of vclib to the MEGA65. This port is intended for the C65 mode |
| 2269 | with a C65 or compatible ROM (although the ROM is not used after the |
| 2270 | program is started). The C64 configuration can be used to create programs for |
| 2271 | the C64 mode. |
| 2272 | |
| 2273 | |
| 2274 | @subsection Startup and Memory |
| 2275 | |
| 2276 | Startup and memory layout is described in the following paragraphs. |
| 2277 | |
| 2278 | The following basic configurations are available. See below for more details: |
| 2279 | |
| 2280 | @table @code |
| 2281 | @item +m65s |
| 2282 | Standard unbanked configuration. |
| 2283 | |
| 2284 | @item +m65sr |
| 2285 | Standard unbanked reentrant configuration. |
| 2286 | |
| 2287 | @item +m65sb |
| 2288 | Standard banked configuration. |
| 2289 | |
| 2290 | @item +m65l |
| 2291 | Large unbanked configuration. |
| 2292 | |
| 2293 | @item +m65lr |
| 2294 | Large unbanked reentrant configuration. |
| 2295 | |
| 2296 | @item +m65lb |
| 2297 | Large banked configuration. |
| 2298 | |
| 2299 | @end table |
| 2300 | |
| 2301 | @subsubsection Startup |
| 2302 | |
| 2303 | The default linker file creates program files that are loaded to address |
| 2304 | 0x2001. A BASIC line is included so that the program can be started using @code{RUN} |
| 2305 | from BASIC. The startup code |
| 2306 | will switch to VIC-IV mode, remove write protection of ROM banks, turn on full |
| 2307 | speed and change to a suitable mapping. |
| 2308 | The BSS segment will be cleared during startup. |
| 2309 | |
| 2310 | There are two sets of configurations that affect the configuration of |
| 2311 | upper memory. The standard versions (@code{+m65s, +m65sr, +m65sb}) |
| 2312 | will keep the IO area mapped in at $D000. |
| 2313 | This will limit the contiguous memory block for unbanked configurations to 0xCFFF. |
| 2314 | For banked configurations (see below) it will make a 16K window from |
| 2315 | 0x8000..0xBFFF available for banking. The large configurations |
| 2316 | (@code{+m65l, +m65lr, +m65lb}) will move the upper bound for unbanked programs |
| 2317 | to 0xFFFF. With banking, 32K window will be available from 0x8000..0xFFFF. |
| 2318 | In both cases the total amount of memory available for banking is the same in |
| 2319 | both configurations. |
| 2320 | |
| 2321 | While the large configurations provide larger contiguous memory areas, accesses |
| 2322 | to the IO area have to be made through extended 28bit instructions which are |
| 2323 | much larger and slower. For programs doing many IO accesses, the standard |
| 2324 | configurations are recommended. |
| 2325 | |
| 2326 | With the default configurations, after exiting the C program, an infinite loop will |
| 2327 | be entered. When using the reentrant (@code{+m65sr, +m65lr}) configs, the |
| 2328 | program will return to BASIC an can be started again. |
| 2329 | However, this needs additional memory as the init values for the data section have |
| 2330 | to be stored in RAM. Also, some register values and zero page contents have to be |
| 2331 | saved. The overhead depends on the amount of initialized variables. |
| 2332 | |
| 2333 | Caution: The current configuration assumes that the Z register always contains 0. |
| 2334 | To work correctly, the Z register has to be 0 when C code is |
| 2335 | executed. The startup code will set it correctly and the compiler generated code will |
| 2336 | not touch it. However, when calling other code you may have to take care |
| 2337 | to save/restore the Z register or to set the Z register to 0 again. |
| 2338 | |
| 2339 | @subsubsection Command line |
| 2340 | |
| 2341 | Command line parameters are supported by using the convention/code submitted by |
| 2342 | Stefan Haubenthal. |
| 2343 | |
| 2344 | Command-lines look like these lines: |
| 2345 | |
| 2346 | @example |
| 2347 | run |
| 2348 | run : rem |
| 2349 | run:rem arg1 " arg 2 is quoted " arg3 "" arg5 |
| 2350 | @end example |
| 2351 | |
| 2352 | |
| 2353 | |
| 2354 | @subsubsection Zero Page |
| 2355 | |
| 2356 | @code{vbcc} uses a number of zero page locations for register variables, stack |
| 2357 | pointer etc. in section @code{zpage}. Also, variables can be mapped to zero page using |
| 2358 | the @code{__zpage} attribute. By default the area @code{0x02..0xFF} |
| 2359 | is used, but this can be changed in the linker file. |
| 2360 | |
| 2361 | @subsubsection Stack |
| 2362 | |
| 2363 | By default, the user stack is mapped from @code{0xB800..0xC000}. For the banked version, |
| 2364 | it is mapped from @code{0x7800..0x8000}. The size can be |
| 2365 | changed at the top of @code{vlink.cmd} and @code{vlinkbank.cmd}. |
| 2366 | |
| 2367 | @subsubsection Heap |
| 2368 | |
| 2369 | Code and data/BSS are mapped starting after the BASIC init line. |
| 2370 | The heap is placed in the remaining space depending on the configuration. |
| 2371 | |
| 2372 | @subsubsection Banking |
| 2373 | |
| 2374 | The following banking models are supported: |
| 2375 | |
| 2376 | @table @code |
| 2377 | @item +m65sb |
| 2378 | 16K window at 0x8000 with IO area mapped in at all times. |
| 2379 | |
| 2380 | @item +m65lb |
| 2381 | 32K window at 0x8000. |
| 2382 | @end table |
| 2383 | |
| 2384 | |
| 2385 | Automated bank switching is supported in both modes. The mapping of banks to |
| 2386 | real memory in the standard configuration is like this: |
| 2387 | @example |
| 2388 | Unbanked: 0x000000..0x007FFF |
| 2389 | Bank0: 0x008000..0x00BFFF |
| 2390 | Bank1: 0x00C000..0x00FFFF |
| 2391 | Bank2: 0x010000..0x013FFF |
| 2392 | Bank3: 0x014000..0x017FFF |
| 2393 | ... |
| 2394 | @end example |
| 2395 | |
| 2396 | On the large configuration, it looks like this: |
| 2397 | @example |
| 2398 | Unbanked: 0x000000..0x007FFF |
| 2399 | Bank0: 0x008000..0x00FFFF |
| 2400 | Bank1: 0x010000..0x017FFF |
| 2401 | Bank2: 0x018000..0x01FFFF |
| 2402 | Bank3: 0x020000..0x027FFF |
| 2403 | ... |
| 2404 | @end example |
| 2405 | |
| 2406 | In both cases, the program start is moved to 0x1000. |
| 2407 | When using the banked configurations, the code can not be simply loaded from |
| 2408 | BASIC. The linker will create on large image without any BASIC lines. The |
| 2409 | file can be executed from SD-card by using a special loader that can be loaded |
| 2410 | from BASIC off a disk or disk image. When specifying a name as command line |
| 2411 | argument (see above), the loader will try to load this image from SD-card. If |
| 2412 | no argument is given, the loader will look for a file of the same name. |
| 2413 | Therefore by renaming the loader it can be made to automatically run a |
| 2414 | specific file. |
| 2415 | |
| 2416 | If the loader is on the current disk/image and @code{myimage} on the SD: |
| 2417 | @example |
| 2418 | LOAD "LOADER" |
| 2419 | RUN:REM MYIMAGE |
| 2420 | @end example |
| 2421 | |
| 2422 | After renaming @code{LOADER} to @code{MYIMAGE}, it can be done like this: |
| 2423 | @example |
| 2424 | RUN "MYIMAGE" |
| 2425 | @end example |
| 2426 | |
| 2427 | The colour RAM will be relocated to 0xFF80800 before loading to avoid being |
| 2428 | overwritten through the window at 0x1F800. |
| 2429 | |
| 2430 | @subsection Runtime |
| 2431 | |
| 2432 | Apart from standard C library functions, @code{libvc.a} also provides a few |
| 2433 | runtime support functions needed by the compiler. Apart from the math and |
| 2434 | floating point functions mentioned in the documentation of the 6502 backend, |
| 2435 | it includes functions for saving/restoring registers. |
| 2436 | |
| 2437 | @subsection @code{stdio} |
| 2438 | |
| 2439 | At the moment, stdio only supports @code{stdout}, @code{stderr} (both using the |
| 2440 | screen) and @code{stdin} (keyboard). Both are unbuffered by default. |
| 2441 | Using those streams will directly access the screen buffer and keyboard |
| 2442 | hardware. No ROM functions are needed once the program runs. |
| 2443 | |
| 2444 | Furthermore it is possible to read files on the SD-card using standard |
| 2445 | C functions after opening them using @code{fopen()}. Hyppo services are |
| 2446 | used to read those files. There are several limitations due to the |
| 2447 | restrictions of Hyppo: |
| 2448 | |
| 2449 | @itemize |
| 2450 | @item Files can only be read sequentially, no seeking etc. |
| 2451 | @item Files can not be written to. |
| 2452 | @item Only one file can be open at the same time. |
| 2453 | @end itemize |
| 2454 | |
| 2455 | |
| 2456 | @code{printf/scanf} functions which support floating point are contained in |
| 2457 | the math library only. |
| 2458 | |
| 2459 | @subsection Multiplication/Division |
| 2460 | |
| 2461 | When generating code for the MEGA65, @code{vbcc} will make use of hardware |
| 2462 | multiplier/divider. This can greatly improve performance of such operations. |
| 2463 | Please note the following issues: |
| 2464 | |
| 2465 | @itemize |
| 2466 | @item Some versions of the MEGA65 core contain a bug in the hardware divider |
| 2467 | which will calculate wrong results in certain cases. As workaround you can |
| 2468 | specify option @code{-div-bug} to use (much slower) 6502 software |
| 2469 | routines instead. Multiplication is not affected by the bug and will still |
| 2470 | be using the hardware multiplier. |
| 2471 | |
| 2472 | @item The hardware multiplier registers are mapped in the IO area. When using |
| 2473 | the large configurations (@code{+m65l, +m65lr, +m65lb}), they can only |
| 2474 | be accessed using extended 28bit instructions. The code generator and |
| 2475 | library functions will handle this, but there is some overhead (still |
| 2476 | nowhere near using software multiplication). If your code is speed |
| 2477 | critical and uses many multiplications we strongly recomment to use |
| 2478 | the standard configurations (@code{+m65s, +m65sr, +m65sb}). Those will |
| 2479 | set the option @code{-m65io} that tells @code{vbcc} to use faster |
| 2480 | direct IO accesses. |
| 2481 | @end itemize |
| 2482 | |
| 2483 | @subsection Interrupts |
| 2484 | |
| 2485 | The provided configurations will disable interrupts on the MEGA65. All the |
| 2486 | library functions are written to work with disabled interrupts and do not use |
| 2487 | any ROM routines. The interrupt handlers in existing C65 ROMs do not work well |
| 2488 | with assembly language code and deficiencies in the mapping hardware make it |
| 2489 | very hard to use the ROM in a non-BASIC environment. |
| 2490 | |
| 2491 | If an application wants to use interrupts, interrupt vectors have to be |
| 2492 | installed at 0xFFFA..0xFFFF. Take care that there are always valid vectors |
| 2493 | visible at this address (especially in a banked configuration). Also take |
| 2494 | care that those always point to a valid handler that is visible (i.e. do |
| 2495 | not use an ISR in banked memory). |
| 2496 | |
| 2497 | |
| 2498 | @subsection Floating Point / wozfp |
| 2499 | |
| 2500 | When using floating point, the math library @code{libm.a} must be linked using |
| 2501 | the @code{-lm} option. It contains the floating routines as well as versions of |
| 2502 | the @code{printf/scanf} family that support floating point. |
| 2503 | |
| 2504 | The floating point routines are based on Steve Wozniaks routines from the 70s, |
| 2505 | somewhat adapted to the ABI of @code{vbcc}. These functions are small and |
| 2506 | reasonably usable, but they do not fully satisfy the requirements of C99. |
| 2507 | |
| 2508 | Only a part of the C library functions for floating point is implemented. The |
| 2509 | list currently includes: |
| 2510 | |
| 2511 | @itemize |
| 2512 | @item @code{exp()} |
| 2513 | @item @code{pow()} |
| 2514 | @item @code{log()} |
| 2515 | @item @code{log10()} |
| 2516 | @end itemize |
| 2517 | |
| 2518 | @subsection Floating Point / IEEE |
| 2519 | |
| 2520 | When using IEEE floating point, @code{-ieee} must be specified and the math library |
| 2521 | @code{libmieee.a} must be linked using |
| 2522 | the @code{-lmieee} option. It contains the floating routines as well as versions of |
| 2523 | the @code{printf/scanf} family that support floating point. |
| 2524 | |
| 2525 | The floating point routines are based on SANE, |
| 2526 | somewhat adapted to the ABI of @code{vbcc} using wrapper functions. |
| 2527 | These functions should be fully C and IEEE compliant and provide precise results for |
| 2528 | 32 and 64bit floating point numbers (the library actually internally calculates |
| 2529 | all operation using 80bits, but vbcc currently only uses up to 64 bits). |
| 2530 | |
| 2531 | Currently, this library probably must be run from RAM. |
| 2532 | |
| 2533 | Most parts of the C library functions for floating point are implemented. The |
| 2534 | list currently includes: |
| 2535 | |
| 2536 | @itemize |
| 2537 | @item @code{exp(), expf(), expl()} |
| 2538 | @item @code{exp2(), exp2f(), exp2l()} |
| 2539 | @item @code{exp1m(), exp1mf(), exp1ml()} |
| 2540 | @item @code{pow(), powf(), powl()} |
| 2541 | @item @code{log(), logf(), logl()} |
| 2542 | @item @code{log1p(), log1pf(), log1pl()} |
| 2543 | @item @code{log2(), log2f(), log2l()} |
| 2544 | @item @code{log10(), log10f(), log10l()} |
| 2545 | @item @code{sqrt(), sqrtf(), sqrtl()} |
| 2546 | @item @code{sin(), sinf(), sinl()} |
| 2547 | @item @code{cos(), cosf(), cosl()} |
| 2548 | @item @code{tan(), tanf(), tanl()} |
| 2549 | @item @code{atan(), atanf(), atanl()} |
| 2550 | |
| 2551 | |
| 2552 | @end itemize |
| 2553 | |
| 2554 | @section 6502/X16 |
| 2555 | |
| 2556 | This is a port of vclib to the Commander X16. |
| 2557 | |
| 2558 | |
| 2559 | @subsection Startup and Memory |
| 2560 | |
| 2561 | Startup and memory layout is described in the following paragraphs. |
| 2562 | |
| 2563 | @subsubsection Startup |
| 2564 | |
| 2565 | The default linker file creates program files that are loaded to address |
| 2566 | 0x801. A BASIC line is included so that the program can be started using @code{RUN} |
| 2567 | from BASIC. The startup code |
| 2568 | will turn off the BASIC ROM to allow usage of RAM until 0x9F00 and most of the |
| 2569 | zero page without need for any special handling. The BSS segment will be cleared |
| 2570 | during startup. |
| 2571 | |
| 2572 | With the default configuration, after exiting the C program, an infinite loop will |
| 2573 | be entered. When using the @code{+x16r} config, the program will return to BASIC |
| 2574 | an can be started again. |
| 2575 | However, this needs additional memory as the init values for the data section have |
| 2576 | to be stored in RAM. Also, some register values and zero page contents have to be |
| 2577 | saved. The overhead depends on the amount of initialized variables. |
| 2578 | |
| 2579 | @subsubsection Command line |
| 2580 | |
| 2581 | Command line parameters are supported by using the convention/code submitted by |
| 2582 | Stefan Haubenthal. |
| 2583 | |
| 2584 | Command-lines look like these lines: |
| 2585 | |
| 2586 | @example |
| 2587 | run |
| 2588 | run : rem |
| 2589 | run:rem arg1 " arg 2 is quoted " arg3 "" arg5 |
| 2590 | @end example |
| 2591 | |
| 2592 | |
| 2593 | |
| 2594 | @subsubsection Zero Page |
| 2595 | |
| 2596 | @code{vbcc} uses a number of zero page locations for register variables, stack |
| 2597 | pointer etc. in section @code{zpage}. Also, variables can be mapped to zero page using |
| 2598 | the @code{__zpage} attribute. By default the area @code{0x02..0x7e} |
| 2599 | is used, but this can be changed in the linker file. |
| 2600 | |
| 2601 | @subsubsection Stack |
| 2602 | |
| 2603 | By default, the user stack is mapped from @code{0x9700..0x9F00}. The size can be |
| 2604 | changed at the top of @code{vlink.cmd}. |
| 2605 | |
| 2606 | @subsubsection Heap |
| 2607 | |
| 2608 | Code and data/BSS are mapped starting after the BASIC init line. |
| 2609 | The heap is placed in the remaining space to stack start. |
| 2610 | |
| 2611 | @subsubsection Banking |
| 2612 | |
| 2613 | Banking support for this target is not yet implemented. |
| 2614 | |
| 2615 | |
| 2616 | @subsection Runtime |
| 2617 | |
| 2618 | Apart from standard C library functions, @code{libvc.a} also provides a few |
| 2619 | runtime support functions needed by the compiler. Apart from the math and |
| 2620 | floating point functions mentioned in the documentation of the 6502 backend, |
| 2621 | it includes functions for saving/restoring registers. |
| 2622 | |
| 2623 | @subsection @code{stdio} |
| 2624 | |
| 2625 | At the moment, stdio only supports @code{stdout}, @code{stderr} (both using the |
| 2626 | screen) and @code{stdin} (keyboard). Both are unbuffered by default. |
| 2627 | |
| 2628 | @code{printf/scanf} functions which support floating point are contained in |
| 2629 | the math library only. |
| 2630 | |
| 2631 | |
| 2632 | @subsection Floating Point / wozfp |
| 2633 | |
| 2634 | When using floating point, the math library @code{libm.a} must be linked using |
| 2635 | the @code{-lm} option. It contains the floating routines as well as versions of |
| 2636 | the @code{printf/scanf} family that support floating point. |
| 2637 | |
| 2638 | The floating point routines are based on Steve Wozniaks routines from the 70s, |
| 2639 | somewhat adapted to the ABI of @code{vbcc}. These functions are small and |
| 2640 | reasonably usable, but they do not fully satisfy the requirements of C99. |
| 2641 | |
| 2642 | Only a part of the C library functions for floating point is implemented. The |
| 2643 | list currently includes: |
| 2644 | |
| 2645 | @itemize |
| 2646 | @item @code{exp()} |
| 2647 | @item @code{pow()} |
| 2648 | @item @code{log()} |
| 2649 | @item @code{log10()} |
| 2650 | @end itemize |
| 2651 | |
| 2652 | @subsection Floating Point / IEEE |
| 2653 | |
| 2654 | When using IEEE floating point, @code{-ieee} must be specified and the math library |
| 2655 | @code{libmieee.a} must be linked using |
| 2656 | the @code{-lmieee} option. It contains the floating routines as well as versions of |
| 2657 | the @code{printf/scanf} family that support floating point. |
| 2658 | |
| 2659 | The floating point routines are based on SANE, |
| 2660 | somewhat adapted to the ABI of @code{vbcc} using wrapper functions. |
| 2661 | These functions should be fully C and IEEE compliant and provide precise results for |
| 2662 | 32 and 64bit floating point numbers (the library actually internally calculates |
| 2663 | all operation using 80bits, but vbcc currently only uses up to 64 bits). |
| 2664 | |
| 2665 | Currently, this library probably must be run from RAM. |
| 2666 | |
| 2667 | Most parts of the C library functions for floating point are implemented. The |
| 2668 | list currently includes: |
| 2669 | |
| 2670 | @itemize |
| 2671 | @item @code{exp(), expf(), expl()} |
| 2672 | @item @code{exp2(), exp2f(), exp2l()} |
| 2673 | @item @code{exp1m(), exp1mf(), exp1ml()} |
| 2674 | @item @code{pow(), powf(), powl()} |
| 2675 | @item @code{log(), logf(), logl()} |
| 2676 | @item @code{log1p(), log1pf(), log1pl()} |
| 2677 | @item @code{log2(), log2f(), log2l()} |
| 2678 | @item @code{log10(), log10f(), log10l()} |
| 2679 | @item @code{sqrt(), sqrtf(), sqrtl()} |
| 2680 | @item @code{sin(), sinf(), sinl()} |
| 2681 | @item @code{cos(), cosf(), cosl()} |
| 2682 | @item @code{tan(), tanf(), tanl()} |
| 2683 | @item @code{atan(), atanf(), atanl()} |
| 2684 | |
| 2685 | |
| 2686 | @end itemize |
| 2687 | |
| 2688 | @section 6502/PET |
| 2689 | |
| 2690 | This is a port of vclib to the CBM PET series of computers. |
| 2691 | |
| 2692 | @subsection Startup and Memory |
| 2693 | |
| 2694 | Startup and memory layout is described in the following paragraphs. |
| 2695 | |
| 2696 | @subsubsection Startup |
| 2697 | |
| 2698 | The default linker file creates program files that are loaded to address |
| 2699 | 0x401. A BASIC line is included so that the program can be started using @code{RUN} |
| 2700 | from BASIC. RAM is available until 0x7FFF and most of the |
| 2701 | zero page without need for any special handling. The BSS segment will be cleared |
| 2702 | during startup. |
| 2703 | |
| 2704 | With the default configuration, after exiting the C program, an infinite loop will |
| 2705 | be entered. When using the @code{+petr} config, the program will return to BASIC |
| 2706 | an can be started again. |
| 2707 | However, this needs additional memory as the init values for the data section have |
| 2708 | to be stored in RAM. Also, some register values and zero page contents have to be |
| 2709 | saved. The overhead depends on the amount of initialized variables. |
| 2710 | |
| 2711 | @subsubsection Command line |
| 2712 | |
| 2713 | Command line parameters are supported by using the convention/code submitted by |
| 2714 | Stefan Haubenthal. |
| 2715 | |
| 2716 | Command-lines look like these lines: |
| 2717 | |
| 2718 | @example |
| 2719 | run |
| 2720 | run : rem |
| 2721 | run:rem arg1 " arg 2 is quoted " arg3 "" arg5 |
| 2722 | @end example |
| 2723 | |
| 2724 | |
| 2725 | |
| 2726 | @subsubsection Zero Page |
| 2727 | |
| 2728 | @code{vbcc} uses a number of zero page locations for register variables, stack |
| 2729 | pointer etc. in section @code{zpage}. Also, variables can be mapped to zero page using |
| 2730 | the @code{__zpage} attribute. By default the area @code{0x02..0x8d} |
| 2731 | is used, but this can be changed in the linker file. |
| 2732 | |
| 2733 | @subsubsection Stack |
| 2734 | |
| 2735 | By default, the user stack is mapped from @code{0x7F00..0x7FFF}. The size can be |
| 2736 | changed at the top of @code{vlink.cmd}. |
| 2737 | |
| 2738 | @subsubsection Heap |
| 2739 | |
| 2740 | Code and data/BSS are mapped starting after the BASIC init line. |
| 2741 | The heap is placed in the remaining space to stack start. |
| 2742 | |
| 2743 | @subsubsection Banking |
| 2744 | |
| 2745 | Automated banking is currently not supported. |
| 2746 | |
| 2747 | |
| 2748 | @subsection Runtime |
| 2749 | |
| 2750 | Apart from standard C library functions, @code{libvc.a} also provides a few |
| 2751 | runtime support functions needed by the compiler. Apart from the math and |
| 2752 | floating point functions mentioned in the documentation of the 6502 backend, |
| 2753 | it includes functions for saving/restoring registers. |
| 2754 | |
| 2755 | @subsection @code{stdio} |
| 2756 | |
| 2757 | At the moment, stdio only supports @code{stdout}, @code{stderr} (both using the |
| 2758 | screen) and @code{stdin} (keyboard). Both are unbuffered by default. |
| 2759 | |
| 2760 | @code{printf/scanf} functions which support floating point are contained in |
| 2761 | the math library only. |
| 2762 | |
| 2763 | |
| 2764 | @subsection Floating Point / wozfp |
| 2765 | |
| 2766 | When using floating point, the math library @code{libm.a} must be linked using |
| 2767 | the @code{-lm} option. It contains the floating routines as well as versions of |
| 2768 | the @code{printf/scanf} family that support floating point. |
| 2769 | |
| 2770 | The floating point routines are based on Steve Wozniaks routines from the 70s, |
| 2771 | somewhat adapted to the ABI of @code{vbcc}. These functions are small and |
| 2772 | reasonably usable, but they do not fully satisfy the requirements of C99. |
| 2773 | |
| 2774 | Only a part of the C library functions for floating point is implemented. The |
| 2775 | list currently includes: |
| 2776 | |
| 2777 | @itemize |
| 2778 | @item @code{exp()} |
| 2779 | @item @code{pow()} |
| 2780 | @item @code{log()} |
| 2781 | @item @code{log10()} |
| 2782 | @end itemize |
| 2783 | |
| 2784 | @subsection Floating Point / IEEE |
| 2785 | |
| 2786 | When using IEEE floating point, @code{-ieee} must be specified and the math library |
| 2787 | @code{libmieee.a} must be linked using |
| 2788 | the @code{-lmieee} option. It contains the floating routines as well as versions of |
| 2789 | the @code{printf/scanf} family that support floating point. |
| 2790 | |
| 2791 | The floating point routines are based on SANE, |
| 2792 | somewhat adapted to the ABI of @code{vbcc} using wrapper functions. |
| 2793 | These functions should be fully C and IEEE compliant and provide precise results for |
| 2794 | 32 and 64bit floating point numbers (the library actually internally calculates |
| 2795 | all operation using 80bits, but vbcc currently only uses up to 64 bits). |
| 2796 | |
| 2797 | Currently, this library probably must be run from RAM. |
| 2798 | |
| 2799 | Most parts of the C library functions for floating point are implemented. The |
| 2800 | list currently includes: |
| 2801 | |
| 2802 | @itemize |
| 2803 | @item @code{exp(), expf(), expl()} |
| 2804 | @item @code{exp2(), exp2f(), exp2l()} |
| 2805 | @item @code{exp1m(), exp1mf(), exp1ml()} |
| 2806 | @item @code{pow(), powf(), powl()} |
| 2807 | @item @code{log(), logf(), logl()} |
| 2808 | @item @code{log1p(), log1pf(), log1pl()} |
| 2809 | @item @code{log2(), log2f(), log2l()} |
| 2810 | @item @code{log10(), log10f(), log10l()} |
| 2811 | @item @code{sqrt(), sqrtf(), sqrtl()} |
| 2812 | @item @code{sin(), sinf(), sinl()} |
| 2813 | @item @code{cos(), cosf(), cosl()} |
| 2814 | @item @code{tan(), tanf(), tanl()} |
| 2815 | @item @code{atan(), atanf(), atanl()} |
| 2816 | |
| 2817 | |
| 2818 | @end itemize |