tkchia / newlib-ia16

Fork of IA-16 port of Newlib -- added small and medium model support
GNU General Public License v2.0
13 stars 4 forks source link

TSR - is there anyway to specify which segment the library code ends up in? #23

Open andrewbird opened 1 year ago

andrewbird commented 1 year ago

I'm playing with doslfn with the goal that I'd like to get it to build using nasm and ia16-elf-gcc. My test repo/branch is over at https://gitlab.com/a8d/doslfn/-/tree/t2/src . Currently it is wholly tasm and implements its nls itself rather than using kitten. I'd like to move a significant portion of the non TSR code to C as it doesn't need to be assembly, but I'm finding that although I can play some tricks with objcopy to get the kitten and printf code into .*.startup sections, the library code ends up in .text etc. Can you suggest anything that I can do to get the library code where I'd like it so as to keep the resident code small?

.text           0x0000000000000100      0x664                                   
                0x0000000000000100                __stext_keep = .              
 *(.startupA)                                                                   
 .startupA      0x0000000000000100        0x0 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/dtr-t-c0.o
                0x0000000000000100                _start                        
 *(.head)                                                                       
 *(.head.*)                                                                     
 *(.startupB)                                                                   
 .startupB      0x0000000000000100        0x3 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/dtr-t-c0.o
 *(.text)                                                                       
 *fill*         0x0000000000000103        0xd                                   
 .text          0x0000000000000110        0x0 core.obj                          
 .text          0x0000000000000110        0x0 main.obj                          
 .text          0x0000000000000110        0xc /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libi86.a(dos-keep.o)
                0x0000000000000110                __libi86_bc_keep              
                0x0000000000000110                _dos_keep                     
 .text          0x000000000000011c       0x55 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libi86.a(intdos.o)
                0x000000000000011c                intdos                        
 .text          0x0000000000000171       0x38 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/crtbegin.o
 .text          0x00000000000001a9       0x1b /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/crtend.o
 .text          0x00000000000001c4        0x0 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/dtr-t-c0.o
 .text          0x00000000000001c4        0x0 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-environ.o)
 .text          0x00000000000001c4       0x25 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-exit.o)
                0x00000000000001c4                exit                          
 .text          0x00000000000001e9       0x2a /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-getenv.o)
                0x00000000000001e9                _findenv                      
                0x00000000000001fd                getenv                        
 .text          0x0000000000000213       0xa2 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-getenv_r.o)
                0x0000000000000213                _findenv_r                    
                0x00000000000002a0                _getenv_r                     
 .text          0x00000000000002b5        0x0 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-impure.o)
 .text          0x00000000000002b5       0x20 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-memcpy.o)
                0x00000000000002b5                memcpy                        
 .text          0x00000000000002d5       0x24 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-strcat.o)
                0x00000000000002d5                strcat                        
 .text          0x00000000000002f9       0x1b /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-strchr.o)
                0x00000000000002f9                strchr                        
 .text          0x0000000000000314       0x1d /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-strcpy.o)
                0x0000000000000314                strcpy                        
 .text          0x0000000000000331       0x1c /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-strlen.o)
                0x0000000000000331                strlen                        
 .text          0x000000000000034d       0x27 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-strncmp.o)
                0x000000000000034d                strncmp                       
 .text          0x0000000000000374       0x11 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-sysclose.o)
                0x0000000000000374                close                         
 .text          0x0000000000000385       0x20 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-sysopen.o)
                0x0000000000000385                open                          
 .text          0x00000000000003a5       0x17 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-sysread.o)
                0x00000000000003a5                read                          
 .text          0x00000000000003bc       0x11 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-syssbrk.o)
                0x00000000000003bc                sbrk                          
 .text          0x00000000000003cd       0x17 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-syswrite.o)
                0x00000000000003cd                write                         
 .text          0x00000000000003e4      0x133 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-__call_atexit.o)
                0x00000000000003e4                __call_exitprocs              
 .text          0x0000000000000517        0x2 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-envlock.o)
                0x0000000000000517                __env_lock                    
                0x0000000000000518                __env_unlock                  
 .text          0x0000000000000519       0x15 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/libgcc.a(udivsi3.o)
                0x0000000000000519                __udivsi3                     
 .text          0x000000000000052e       0x1a /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/libgcc.a(umodsi3.o)
                0x000000000000052e                __umodsi3                     
 .text          0x0000000000000548       0x4f /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/libgcc.a(ia16-ldivmodu.o)
                0x0000000000000548                __ia16_ldivmodu               
 .text          0x0000000000000597       0x18 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libdos-t.a(dos-closer.o)
                0x0000000000000597                _close_r                      
 .text          0x00000000000005af       0xea /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libdos-t.a(dos-openr.o)
                0x00000000000005af                _open_r                       
 .text          0x0000000000000699        0x0 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libdos-t.a(dos-psp.o)
 .text          0x0000000000000699       0x1b /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libdos-t.a(dos-readr.o)
                0x0000000000000699                _read_r                       
 .text          0x00000000000006b4       0x51 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libdos-t.a(dos-sbrkr.o)
                0x00000000000006b4                _sbrk_r                       
 .text          0x0000000000000705       0x1f /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libdos-t.a(dos-writer.o)
                0x0000000000000705                _write_r                      
 .text          0x0000000000000724        0x0 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libdos-t.a(dos-heaplen.o)
 .text          0x0000000000000724       0x1e /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libdos-t.a(dos-lseekr.o)
                0x0000000000000724                _lseek_r                      
 .text          0x0000000000000742       0x22 /usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/lib/libc.a(lib_a-memset.o)
                0x0000000000000742                memset                        
 *(.text. .text.[^se]* .text.s[^t]* .text.st[^a]* .text.sta[^r]* .text.star[^t]* .text.start[^u]* .text.startu[^p]* .text.startup[^.]* .text.e[^x]* .text.ex[^i]* .text.exi[^t] .text.exit[^.]*)
                0x0000000000000764                __etext_keep = .              
                0x0000000000000664                __ltext_keep = (__etext_keep - __stext_keep)                                                                        

The way I'm thinking of structuring the code is that all of the C is transient, and the resident part is nasm code converted from tasm.

andrewbird commented 1 year ago

I did try to do an incremental link, in the hope that I could fixup the sections before the final link, but it seems that's not possible?

ia16-elf-gcc -mtsr core.obj kitten.obj tnyprntf.obj main.obj -li86 -Wl,-i -o doslfn.ob1
/usr/lib/x86_64-linux-gnu/gcc/ia16-elf/6.3.0/../../../../../ia16-elf/bin/ld: relocatable linking with relocations from format elf32-i386 (kitten.obj) to format binary (doslfn.ob1) is not supported
collect2: error: ld returned 1 exit status

Thank you!