6502 lib: Small changes to get us to the point we can link init
authorAlan Cox <alan@linux.intel.com>
Fri, 16 Jan 2015 17:36:53 +0000 (17:36 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 16 Jan 2015 17:36:53 +0000 (17:36 +0000)
Mostly we need strtol as the cc65 runtime one tries to use the wrong isfoo()
functions

Library/libs/Makefile.6502
Library/libs/crt0_6502.s

index 89a73a9..0a706a5 100644 (file)
@@ -54,6 +54,7 @@ SRC_C += system.c time.c tmpnam.c ttyname.c
 SRC_C += tzset.c ungetc.c utent.c utimes.c utsname.c
 SRC_C += vfprintf.c vprintf.c wait.c xitoa.c pathconf.c
 SRC_C += gethostname.c sysconf.c confstr.c memccpy.c getpass.c
+SRC_C += strtol.c
 # tty layer
 SRC_C += tcgetattr.c tcsetattr.c tcdrain.c tcflow.c tcflush.c
 SRC_C += cfmakeraw.c cfspeed.c revoke.c
index b710bc9..cfdc54e 100644 (file)
@@ -5,18 +5,21 @@
 ; and Ullrich von Bassewitz <uz@cc65.org> 2014-08-22, Greg King
 ;
 
-        .import         initlib, donelib
        .import         __CODE_SIZE__, __RODATA_SIZE__
        .import         __DATA_SIZE__, __BSS_SIZE__
        .import         _exit
-       .import         _environ
+       .export         _environ
+       .export         initmainargs
        .import         _main
+       .import         popax
+       .import         ___stdio_init_vars
+
+       .export __STARTUP__ : absolute = 1;
 
         .include        "zeropage.inc"
 
-; Place the startup code in a special segment.
+.segment "STARTUP"
 
-.segment        "STARTUP"
        jmp     start
 
        .byte   'F'
@@ -30,6 +33,7 @@
        .word   __BSS_SIZE__
        .word   0
 
+
 ;
 ;      On entry sp/sp+1 have been set up by the kernel (this has to be
 ;      done in kernel as we might take a signal very early on). Above the
 ;      for us and we are ready to roll.
 ;
 start:
-; Call the module constructors.
-        jsr     initlib
-
 ; Push the command-line arguments; and, call main().
 ;
 ; Need to save the environment ptr. The rest of the stack should be
 ; fine.
 ;
+       jsr     ___stdio_init_vars
        lda     sp
        ldx     sp+1
        clc
@@ -56,10 +58,17 @@ start:
        inx
 l1:    sta     _environ
        stx     _environ+1
-       ldy     #4
+       jsr     popax           ; Pull argv off the stack leaving argc
+       ldy     #2              ; 2 bytes of args
         jsr     _main
 
 ; Call the module destructors. This is also the exit() entry.
 
        jmp     _exit           ; exit syscall, AX holds our return code
                                ; for a fastcall return to nowhere.
+
+initmainargs:                  ; Hardcoded compiler dumbness
+       rts
+
+       .bss
+_environ:      .word   0