To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 2174
2173  |  2175
Subject: 
Re: legOS C++ questions
Newsgroups: 
lugnet.robotics
Date: 
Sun, 3 Jan 1999 00:46:43 GMT
Original-From: 
John A. Tamplin <jat@traveller.com=SayNoToSpam=>
Viewed: 
1381 times
  
On Sat, 2 Jan 1999, Rick Kimball wrote:

I'm having some more success and of course more problems.

I whipped up a C++ version of one of the demo programs.
I successfully compiled and linked it after adding a
a few routines from the libgcc2.c see below.

As long as I create my class objects on the stack and
don't use any task management routines the C++ constructors
and destructors get called automatically.  However, when
I add the execi calls the destructors no longer get invoked.
I'm assuming that is because of the way tm.c manipulates
the return function.  It appears to stuff the address
of the exit routine on the stack.  I would guess it is
replacing the destructor call.  Is there a way around this?

Destructors for stack-based objects get run as soon as the enclosing
scope exits.  If you call exit, the compiler doesn't know it needs to
destroy them first.  If you dynamically allocate objects, you have to
destroy them yourself for the destructor to get called.

If these questions are not appropriate for this group
please let me know and I will stop asking them.

First, I changed the Makefile to use gcc rather than ld directly, which
links crt0.o as the first object and links in libgcc.a and the standard C
library (which for now is a null library - ar rv
/usr/local/h8300-hitachi-hms/lib/libc.a, eventually I will put in standard
string utilities etc).  You get all the appropriate things that are needed
in libgcc.a, which includes FP emulation routines.

I don't have my crt0.s here, but from memory:
.text
jsr @_kernel_init
mov.w #__ctors,r4
mov.w #__ctors_end,r5
cpm.w r5,r4
bhs .Lctors_done
.Lmore_ctors:
mov.w @r4+,r2
jsr @r2
cmp.w r5,r4
blo .Lmore_ctors
.Lctors_done:
jsr @_kmain
mov.w #__dtors,r4
mov.w #__dtors_end,r5
cmp.w r5,r4
bhs .Ldtors_done
.Lmore_dtors:
mov.w @r4+,r2
jsr @r2
cmp.w r5,r4
blo .Lmore_dtors
.Ldtors_done
jsr @_kernel_cleanup
mov.w @0x0000:0,r0
jmp @r0

This takes care of calling global constructors and destructors (well it
would if kmain exited).

You then have to create kernel_init and kernel_cleanup functions that do
some of what is in kinit -- basically everything that sets up anything the
constructors might use (memory management, task management, etc) need to
move to kernel_init and corresponding functions into kernel_cleanup.  I
haven't finished making everything work, but since you are trying to do the
same thing I thought I would share what I have been doing so far.

When I am done making an environment that works properly for C++ I will post
all the changes here.  Once I get familiar enough with the RCX hardware/ROM,
I plan on writing my own C++ kernel that you can download objects to
separately from the OS.

John A. Tamplin Traveller Information Services
jat@Traveller.COM 2104 West Ferry Way
256/705-7007 - FAX 256/705-7100 Huntsville, AL 35801

--
Did you check the web site first?: http://www.crynwr.com/lego-robotics



Message is in Reply To:
  legOS C++ questions
 
I'm having some more success and of course more problems. I whipped up a C++ version of one of the demo programs. I successfully compiled and linked it after adding a a few routines from the libgcc2.c see below. As long as I create my class objects (...) (26 years ago, 2-Jan-99, to lugnet.robotics)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR