Issue compiling ld86: Undefined symbol auto_start

573 views Asked by At

Im attempting to compile some assembly and C code using ld86. When doing so, I run into a problem: "Undefined symbol: auto_start"

I have already searched this, and came across this stack overflow question, which is exactly like mine. But, their solution of removing the arguments from the main function did not work for me. I am looking for some more potential options.

ld86 -d bs.o t.o /usr/lib/bcc/libc.a
ld86: warning: _gets redefined in file 
/usr/lib/bcc/libc_s.a(gets.o); using definition in t.o
undefined symbol: auto_start

My code for t.c:

1 #include <string.h>
2 #include <stdio.h>
3 int prints(char *s)
4 {
5   int i;
6   for(i = 0; i<strlen(s); i++)
7   {
8     putchar(s[i]);
9   }
10   return 0;
11 }
12 
13 int gets(char name[])
14 {
15   int i = 0;
16   char c = 0;
17   while(c != '\n')
18   {
19     c = getc(stdin);
20     name[i] = c;
21     i++;
22   }
23   name[i-1] = 0;
24   return 0;
25 }
26 
27 int main()
28 {
29   char name[64];
30   prints("Welcome to my Booter!\n");
31   while(1)
32   {
33     memset(name,0,64);
34     prints("What is your name?\n");
35     gets(name);
36     if(name[0] == 0)
37     {
38       break;
39     }
40     prints("Welcome "); prints(name); prints("\n\r");
41   }
42   prints("Return to assembly and hang\n\r");

And for bs.s:

BOOTSEG =  0x9000        ! Boot block is loaded again to here.
    SSP      =   8192        ! Stack pointer at SS+8KB

    .globl _main,_prints              ! IMPORT symbols
    .globl _getc,_putc                ! EXPORT symbols

.globl _readfd,_setes,_inces,_error  

    !-------------------------------------------------------
    ! Only one SECTOR loaded at (0000,7C00). Get entire BLOCK in
    !-------------------------------------------------------
    mov  ax,#BOOTSEG    ! set ES to 0x9000
    mov  es,ax
    xor  bx,bx          ! clear BX = 0

    !---------------------------------------------------
    !  read boot BLOCK to [0x9000,0]     
    !---------------------------------------------------
    xor  dx,dx          ! drive 0, head 0
    xor  cx,cx          ! cyl 0    sector 0
    incb cl             ! cyl 0, sector 1
    mov  ax, #0x0202    ! READ 1 block
    int  0x13

    jmpi    start,BOOTSEG           ! CS=BOOTSEG, IP=start

start:                    
    mov     ax,cs                   ! Set segment registers for CPU
    mov     ds,ax                   ! we know ES,CS=0x9000. Let DS=CS  
    mov     ss,ax                   ! SS = CS ===> all point at 0x9000
    mov     es,ax
    mov     sp,#SSP                 ! SP = 8KB above SS=0x9000

    mov     ax,#0x0012              ! 640x480 color     
int     0x10 

    call _main                      ! call main() in C

    test ax, ax
je  _error 

    jmpi 0,0x1000


    !---------------------------------------------
    !  char getc()   function: returns a char
    !---------------------------------------------
_getc:
    xorb   ah,ah           ! clear ah
    int    0x16            ! call BIOS to get a char in AX
    ret 

    !----------------------------------------------
    ! void putc(char c)  function: print a char
    !----------------------------------------------
_putc:           
    push   bp
    mov    bp,sp

    movb   al,4[bp]        ! get the char into aL
    movb   ah,#14          ! aH = 14
    movb   bl,#0x0D        ! bL = cyan color 
    int    0x10            ! call BIOS to display the char

    pop    bp
    ret




   !---------------------------------------
   ! readfd(cyl, head, sector, buf)
   !         4     6     8     10
   !---------------------------------------
_readfd:                             
    push  bp
    mov   bp,sp            ! bp = stack frame pointer

    movb  dl, #0x00        ! drive 0=FD0
    movb  dh, 6[bp]        ! head
    movb  cl, 8[bp]        ! sector
    incb  cl               ! BIOS count sector from 1
    movb  ch, 4[bp]        ! cyl
    mov   bx, 10[bp]       ! BX=buf ==> memory addr=(ES,BX)
    mov   ax, #0x0202      ! READ 2 sectors to (EX, BX)

    int  0x13              ! call BIOS to read the block 
    jb   _error            ! to error if CarryBit is on [read failed]

    pop  bp                
    ret


_setes:  push  bp
     mov   bp,sp

     mov   ax,4[bp]        
     mov   es,ax

     pop   bp
     ret

_inces:                         ! inces() inc ES by 0x40, or 1K
     mov   ax,es
     add   ax,#0x40
     mov   es,ax
     ret

    !------------------------------
    !       error & reboot
    !------------------------------
_error:
    mov  bx, #bad
    push bx
    call _prints

    int  0x19                       ! reboot
1

There are 1 answers

0
Oppa On BEST ANSWER

After much trouble shooting: I found that I needed to remove the include statements at the top of the C file, as well as remove the arguments within the main function. so, the linked page was partially correct.