RetroBSD

2.11BSD operating system for microcontrollers
It is currently Sun Mar 29, 2020 12:30 pm

All times are UTC




Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Sun Dec 06, 2015 1:34 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Alex,

Thanks. I just tried fflush(stdout); Doesn't know value of stdout.

I guess I must be missing a header. Search of retrobsd/sys/include doesn't find a header having STDOUT or NULL.

So I tried fflush(1).

Compiles :). Starts to run....

*** 0x7f0009dd8: bad address 0x00000011

Memory fault - core dumped.

Ugh.

I guess I should look at source of fflush.

Just tried setbuf(1,NULL). Doesn't know value of NULL.

Tried setbuf(1,0);

*** 0x7f00a868: bad address 0x00000011

Hmmm....

Maybe it would cross compile OK? I am compiling with smlrc on my PIC32 system.

The PIC32 system is fun to use :). No HUGE box needed :) MOST IMPRESSIVE. Now if I could just get my program to work :).


I guess I will try to learn about select next! :)

Are we having fun yet :).

Lots of fun!

Wiz


Top
 Profile  
 
PostPosted: Sun Dec 06, 2015 8:27 pm 
Contributor

Joined: Mon Apr 29, 2013 1:56 am
Posts: 196
wiz wrote:
Thanks. I just tried fflush(stdout); Doesn't know value of stdout.

I guess I must be missing a header. Search of retrobsd/sys/include doesn't find a header having STDOUT or NULL.


Code:
#include <stdio.h>


Top
 Profile  
 
PostPosted: Sun Dec 06, 2015 8:44 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Alex and all,

Many thanks.

Adding <stdio.h>

and using setbuf(stdout,NULL); seems to have done the trick :).

fflush(stdout); doesn't seem to do the trick?

Now it 'just works'. Amazing. I am still clueless as to where the flag being set is! Somewhere in machdep I would guess? But now my debugger works as I was hoping.

Time to get to work....

Lots of fun :).

Wiz


Top
 Profile  
 
PostPosted: Sun Dec 06, 2015 8:59 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Alex and all,

I case you happen to know....

When my debugger finishes it restores the termios and calls exit;

I get from the system: EMT trap - core dumped.

Not sure what I do to cause this? I tried asm("ehb"); asm("nop"); but I still get a core dump when I exit?

Not a show stopper, but has made me curious as to what is going on and how to 'fix' it. Not high on my curiousity list :).

Lots of fun.

Wiz


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 7:51 am 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Hi Wiz,

wiz wrote:
Given that ioctl FIONREAD does not give the number of input characters waiting.
I'm pretty sure FIONREAD _does_ give the number of waiting characters. For example, it works in a game "Flappy Bird" I've recently ported to RetroBSD. See file share/examples/gpanel/flappy.c, lines 380-383:
Code:
    int nchars = 0;
    ioctl(0, FIONREAD, &nchars);
    if (nchars <= 0)
        return 0;

wiz wrote:
The number of characters is stored at 0x80005c48. At least for the first uart.
It makes little sense to access the kernel data by fixed addresses, as the layout is highly flexible and in every next version it will be different. It's better to use standard system calls.

wiz wrote:
Adding <stdio.h>
and using setbuf(stdout,NULL); seems to have done the trick :).
It would help if you just look through any tutorial or book chapter about standard Unix i/o. I recommend appendix B "Standard Library" of Kernighan and Ritchie "The C Programming Language" (PDF). On page 242 you can find the description of fflush(), on page 243 - setbuf(). Some intrinsics of stdio implementation, like putchar() macro and others, are described in chapter 8.5.

wiz wrote:
When my debugger finishes it restores the termios and calls exit;
Do you call exit or exit() here? It makes difference.

Best wishes,
--Serge


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 8:02 am 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Another good book is Kernighan and Pike "The UNIX Programming Environment" (PDF). See chapter 6 "Programming with standard I/O" at page 171.


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 2:49 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Serge,

Thanks for your thoughts and suggestions :). I will spend time researching what you suggest.

I did try exit(); this morning. It does not compile. I have not looked into why yet.

I did print out the Linux man page for select and select_tut. I was thinking my debugger needed to be rewritten that way just so I could try that way out as was suggested.. IMHO What a mess!

No wonder select and friends trouble people so much!

I have written lots of real-time stuff in assembler and there are certainly some unusual problems. As long as carefully done, works like a champ. One of the more interesting things I 'discovered' was that interrupts cannot do as much processing as properly written non-interrupt code :). Not really practical here, but true none the less!

I agree with your comment that FIONREAD must work. That said, I couldn't figure out why it didn't for me. It would really help to have a real RAM memory map so I could watch variables in real-time with my debugger. As far as I can tell this just doesn't effectively exist within Unix? There is a large part of RAM used by machdep and friends, but try to tell which bit is in which RAM location! Good luck. Too many levels of structures and unions and header files in the way.

That said maybe there is some neat Unix feature that I just don't know how to use yet?

It is really nice to use my Retro system. That system now has a front panel connector. You just plug into the bus. Pretty neat for breadboarding.

My WiFire can just plug into it.

Now just a little bit of pic32prog for Retro and I will be up and running.

Thank you and MATT and Alex VERY MUCH for your help!

Lots of fun :)

Wiz


Top
 Profile  
 
PostPosted: Thu Dec 10, 2015 8:51 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Serge,

Your links were most informative. Thanks :).

So setbuf was what was needed to turn off output buffering. Or I suppose fflush after each character [ugh!].

I have yet to understand your exit; verses exit(); verses exit(0); comment. Hard to search picture type documents. Do you have a page number reference please?

The only thing that compiles on my RetroBSD system is exit;

Alternatively I can fall off the end [Implied return]. Or put in an explicit return;

All seem to result in the EMT trap problem. So I am still confused as to what happens to cause that type of error.

I am guessing some bit gets set probably by something I do and gets noticed by RetroBSD and results in this error.

Not a show stopper, but interesting enough to try to figure out.

Thanks.

Lots of fun :).

Wiz


Top
 Profile  
 
PostPosted: Thu Dec 10, 2015 9:20 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Serge,

It turns out I have a physical copy of C version 2.

So I am reading about exit on page 164:

"Within main return expr is equivalent to exit(expr);"

And I gather a value can be returned to the calling program, the system in this case.

I wonder if this is my problem?

This does not seem likely since return of various kinds and exit; all 'cause' the same error?

I guess I will try return -1; and a few other values and see what happens....

warm regards,

Wiz


Top
 Profile  
 
PostPosted: Thu Dec 10, 2015 9:31 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Serge again,

Well I just tried: return -1; return 1;

I wonder if one of my debugger 'features' sets something.

I increment 0x8000000c using my version of MemoryRead and MemoryWrite (syscall 157, 158) I also look at the CPU timer asm mfc0 $2, $9.

Hmmm...

More to do on another day :)

Lots of fun.

Wiz


Top
 Profile  
 
PostPosted: Fri Dec 11, 2015 3:26 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Serge and all,

I just figured out that ADB was a debugger for RetroBSD. I thought it was an Android communications tool :).

I was trying to use it and couldn't seem to get any useful information on binaries compiled on the Retro system. I gather that might be much different for cross compiled binaries?

Is it a useful tool? I would guess it is VERY useful given the right input?

And the related question: There MUST also be kernel debugging tools? What are they? How do I get them. And are they useful?

Lots of fun.

Wiz


Top
 Profile  
 
PostPosted: Fri Dec 11, 2015 7:16 pm 

Joined: Mon Nov 24, 2014 1:07 pm
Posts: 58
Hi Wiz,

ADB stands for Android Debug Bridge, it's for debugging android apps not RetroBSD. Sorry but it's not going to help you with BSD debugging.

Dan


Top
 Profile  
 
PostPosted: Fri Dec 11, 2015 7:25 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
ADB also stands for Advanced DeBugger and is a BSD debug tool. At the moment we only have it for debugging LiteBSD, not RetroBSD (AFAIK).

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Fri Dec 11, 2015 9:01 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Actually we have ADB in RetroBSD. Here is a tutorial: http://retrobsd.org/wiki/doku.php/doc/adb/tutorial

The debugger is not fully functional, but it can be used to analyze the dumped core images, and print the memory map and CPU registers at the moment of the crash. For example:
Code:
2.11 BSD UNIX (pic32) (console)

login: root
Password:
Welcome to RetroBSD!
erase ^?, kill ^U, intr ^C
# cd /share/examples/c
# make q8
cc  -o q8  q8.c
# ./q8

Eight Queens brute force
************************

Loop= 0
Solution count= 0
+----------------+
|Q . . . . . . . |
|Q . . . . . . . |
|Q . . . . . . . |
|Q . . . . . . . |
|Q . . . . . . . |
|Q . . . . . . . |
|Q . . . . . . . |
|Q . . . . . . . |
+----------------+
^\Quit - core dumped                   <--- Here I use ^\ to terminate the program and dump core
# adb q8 q8.core                       <--- Invoke the debugger
text=16464 data=700 bss=112 symoff=17196 syms=1868
155 symbols loaded
adb> $c
#7f00c380: ?() from ?+#ffffff          <--- Back trace is not working
c routine not found
adb> $m                                <--- Show memory map
? map       `q8'
b1 = #7f008000   e1 = #7f00c30c   f1 = #20
b2 = #7f008000   e2 = #7f00c30c   f2 = #20
/ map       `q8.core'
b1 = #7f008000   e1 = #7f00c800   f1 = #c00
b2 = #7f01f794   e2 = #7f020000   f2 = #5400
adb> $r                                <--- Show registers
                t0 =        #4  s0 =        #0  t8 =        #1   lo =       #50
at = #7f010000  t1 =        #a  s1 =        #0  t9 =        #1   hi =      #127
v0 =        #1  t2 =       #44  s2 =        #0               status = #10000013
v1 = #7f00c0a9  t3 =       #2a  s3 =        #0                   pc = #7f0082d0
a0 =        #0  t4 =       #2d  s4 =        #0  gp = #7f014050
a1 = #7f00c380  t5 =       #2e  s5 =        #0  sp = #7f01fef8
a2 =       #13  t6 =       #2b  s6 =        #0  fp = #7f01ff04
a3 =        #0  t7 =       #23  s7 =        #0  ra = #7f008684
$L35+#10:       lui     v0, #7f01
adb> $q
# _


Top
 Profile  
 
PostPosted: Fri Dec 11, 2015 10:10 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Serge and all,

Thanks :).

My debugger with the EMT dump on exit shows the same status on exit as does my 8hex program [dump program as 8 hex words so I can read the assembly code as hex :).]

So no clue there! At least yet :).

Lots of fun :)

Wiz


Top
 Profile  
 
PostPosted: Sun Dec 13, 2015 8:13 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Serge and all,

Problem resolved [ if you call renaming a resolution? ].

If I define a variable:

int exit;

when I exit, I get the EMT trap from the system?

I was using the variable 'exit = 1;' to tell the main loop to clean up and exit.

If I rename that variable to jexit, the problem does not occur.

So somewhere there is a name collision. I just 'love' compilers....

Probably why I write in assembler when I can.

Lots of fun :).

Wiz


Top
 Profile  
 
PostPosted: Sun Dec 13, 2015 9:22 pm 
Contributor

Joined: Mon Apr 29, 2013 1:56 am
Posts: 196
wiz wrote:
So somewhere there is a name collision. I just 'love' compilers....


The C language standard says that defining/declaring a reserved identifier (exit is reserved because there's a standard function by that name in the language library) in certain contexts causes undefined behavior (meaning, bad things can happen). You may not know it, but it's not a secret, it's documented. There isn't much to 'love' compilers for, when it's defined in the language. Which you don't know well yet. I could just as well say I 'love' English ('cause it's a crazy language!). And some 15 years ago it was a true 'love'. But I don't 'love' it anymore. The quotes are lost. :)


Top
 Profile  
 
PostPosted: Mon Dec 14, 2015 8:46 am 

Joined: Mon Nov 24, 2014 1:07 pm
Posts: 58
I stand corrected, sorry for the misinformation Wiz!

Dan


Top
 Profile  
 
PostPosted: Mon Dec 14, 2015 9:38 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Alex and all,

Reserved words....

So I am looking at "C programming..." page 192. A2.4 Keywords

Great list :).

Exit is NOT there??

It would seem that a warning somewhere in the compilation process for ALL such words should be another 'required' feature?

I wonder what other non-documented surprises lurk around?

What are your favorites?

Lots of fun.

"I love compilers :)"

Wiz


Top
 Profile  
 
PostPosted: Mon Dec 14, 2015 9:54 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
"exit" is not a reserved word in C. It is a function that is a member of the "stdlib":

Code:
EXIT(3)                    Linux Programmer's Manual                    EXIT(3)

NAME
       exit - cause normal process termination

SYNOPSIS
       #include <stdlib.h>

       void exit(int status);

DESCRIPTION
       The  exit()  function causes normal process termination and the value of
       status & 0377 is returned to the parent (see wait(2)).

       All functions registered with atexit(3) and on_exit(3)  are  called,  in
       the  reverse  order  of  their registration.  (It is possible for one of
       these functions to use atexit(3) or on_exit(3) to register an additional
       function  to be executed during exit processing; the new registration is
       added to the front of the list of functions that remain to  be  called.)
       If  one  of these functions does not return (e.g., it calls _exit(2), or
       kills itself with a signal), then none of  the  remaining  functions  is
       called, and further exit processing (in particular, flushing of stdio(3)
       streams) is abandoned.  If a function has been registered multiple times
       using atexit(3) or on_exit(3), then it is called as many times as it was
       registered.

       All open stdio(3) streams are flushed and closed.  Files created by tmp‐
       file(3) are removed.

       The  C  standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE,
       that may be passed to exit() to indicate successful or unsuccessful ter‐
       mination, respectively.

RETURN VALUE
       The exit() function does not return.


In GCC it is a builtin function so you can't create an "exit" variable:

Code:
t.c:7:5: warning: built-in function ‘exit’ declared as non-function
 int exit = 3;

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission