Go to Post FIRST showed me how to succeed at one of the most difficult, yet important things: Life. - Jim McGeehin [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #16   Spotlight this post!  
Unread 05-04-2011, 22:21
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: I Have A Question About Pointers

Quote:
Originally Posted by demosthenes2k8 View Post
the compiler can probably write better assembly than a human.
Although I agree that it is seldom necessary (or desirable) to write assembly code, an experienced assembly programmer can in many cases implement optimizations that a compiler won't use. The downside is that the code can be a brittle maintenance nightmare.


Reply With Quote
  #17   Spotlight this post!  
Unread 06-04-2011, 01:24
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 674
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: I Have A Question About Pointers

Quote:
Originally Posted by davidthefat View Post
According to Intel there is http://www.intel.com/products/processor/manuals/
And I read that Intanium was the one that was NOT compatible with x86, that is why Intel uses AMD's x86-64 architecture.
Well, I guess I did not follow the Intel terminology as close as I thought. In any case, Intel has three architectures: Itanium 64 (IA64) is not compatible with anything, x64 which is compatible with amd64 and the old 32-bit whatever it is called (x86).
__________________
Reply With Quote
  #18   Spotlight this post!  
Unread 06-04-2011, 01:58
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: I Have A Question About Pointers

Quote:
Originally Posted by mikets View Post
In Intel processor architecture, there is the concept of real mode versus protected mode. But there is no such thing in PPC. In PPC, you probably mean kernel mode versus user mode. But that's entirely different thing. For historic reason, Intel processor boots up into real mode where it uses real mode address space seg : offset to form a 20-bit physical address. That will allow you to access only the low 1 Mbyte of memory. PC BIOS runs in this environment and loads the OS loader into memory (Actually much more complicated than that, but this is the simplified view). The OS loader will then set things up and switch the CPU to go into protected mode. The setup includes setting up the virtual memory address tables GDT, LDT and the interrupt table IDT. So once the OS is booted, the CPU is already in protected mode. Everything including both the OS kernel and applications are run in protected mode. However, in protected mode, there are different privileges. Again, for historic reason, Intel processor supports 4 different privileges (rings). But most of the operating systems support only 2 privileges and they are usuually called kernel mode or superviser mode and user mode. Applications are run in user mode and OS kernel, device drivers are usually run in superviser mode.
I am not very familiar with vxWorks but I believe your program is actually compiled as a downloadable kernel module. So I assume it must be running in kernel mode as well which means your program can misbehave and kill the entire system if you are not careful (e.g. run away pointers). BTW, you can do pointer arithmetics in C/C++. There is no need to do that in assembly. But if you are not careful, you can trash memory. For vxWork, you can probably trash kernel mode memory as well and cause a system crash. For Windows application, for example, a run away pointer can only trash application memory. Kernel mode memory is protected from applications. So your application may crash but the OS will be fine. You can just kill the app and move on. However, for Windows kernel mode drivers, they have privilege to access kernel mode memroy. If they have a run away pointer, they could trash kernel mode memory and bring the system down (Blue-Screen aka BugCheck).
Actually it might be in kernel mode. That explains why vXWorks does not have a system call system. You just go do it for yourself, there is no asking for the OS to do it for you.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #19   Spotlight this post!  
Unread 06-04-2011, 03:11
Techhexium Techhexium is offline
Registered User
FTC #3555
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: California
Posts: 122
Techhexium has a spectacular aura aboutTechhexium has a spectacular aura about
Re: I Have A Question About Pointers

Itanium or IA-64 is in a way pure 64-bit architecture. Because there is little to no compatibility with other architectures, Microsoft is finally abandoning it so there is no more future IA-64 Windows. x64 is actually an extension of x86, I think that's why some call it x86-64.
Reply With Quote
  #20   Spotlight this post!  
Unread 06-04-2011, 08:34
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,753
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: I Have A Question About Pointers

Learning assembly and low-level computer architecture are good things. Putting your experiments on your teams robots -- maybe not.

Assembly programming is a very unforgiving task, and is best done with a net. My CS degree was a few years back, but they still required an assembly course. It was done completely virtual, on a mainframe, because your program would crash about 90% of the time. Since it was virtual, the "processor" was frozen so that you could examine the remains and determine where you went wrong, modify code, and run the experiment again. Even with the help of good tools such as this, it was a painful reminder of just how low-level and complex computers are.

The good thing about that experience is that from time to time, I need to look under the covers and try to understand a bug, an optimization, etc. and being able to grok the assembly and low-level parts of the computer is useful. The rest of the time it would only slow me down by about 100x.

Once you have a good PPC assembly reference and understand the basics of the architecture, I'm pretty sure that you can run your C++ code in vxWorks, hit a breakpoint, show the registers, the stack, and the disassembly. Even better, some environments show you the mixed view of your code -- a line of C and the assembly for that line. This will allow you to see how the compiler produces assembly, learn its tricks, and do it much faster than starting from scratch. It is informative to look at array indexing code, function calls, loops, and other high-level structures that make you productive. It is also informative to intentionally put some common bugs into your code and step through them in assembly to better understand what they cause the computer to do.

Greg McKaskle
Reply With Quote
  #21   Spotlight this post!  
Unread 06-04-2011, 12:38
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 674
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: I Have A Question About Pointers

Are you trying to learn an assembly language or it must be PPC assembly? If learning x86 assembly is good enough, you can use your existing tools. Since your first post seems to be C++/C#, you probaby have visual studio. If so it supports the syntax of _asm {<some assembly code>} mixed in with C code. So you can progressively add more assembly code to your project. Another useful thing to do is to configure your compiler to generate assembly listing so that you can see how each C line is converted into assembly.
__________________
Reply With Quote
  #22   Spotlight this post!  
Unread 06-04-2011, 12:45
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: I Have A Question About Pointers

Quote:
Originally Posted by mikets View Post
Another useful thing to do is to configure your compiler to generate assembly listing so that you can see how each C line is converted into assembly.
Yes. And you may be appalled at what you find.


Reply With Quote
  #23   Spotlight this post!  
Unread 07-04-2011, 22:21
demosthenes2k8's Avatar
demosthenes2k8 demosthenes2k8 is offline
Graduated but not gone
AKA: Matt Soucy
FRC #0166 (Chop Shop 166)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Merrimack, NH
Posts: 589
demosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to behold
Send a message via AIM to demosthenes2k8 Send a message via Yahoo to demosthenes2k8
Re: I Have A Question About Pointers

I'm pretty sure you add a -S to the command line options to do that...I'm gonna try that out now.

After trying that out, HUGE MISTAKE. I used to think my code was elegant...
__________________


GSR Dean's List Finalist 2011
Reply With Quote
  #24   Spotlight this post!  
Unread 07-04-2011, 22:29
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: I Have A Question About Pointers

Yes, I used the disassembly tool in the debugger, I found that a lot of the code was filled with nop (no operation) but why? Is it to compensate for the data transfer from the ram to the cache? That seems unlikely
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #25   Spotlight this post!  
Unread 07-04-2011, 22:34
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 674
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: I Have A Question About Pointers

Most likely for alignment. Usually in between functions.
__________________
Reply With Quote
  #26   Spotlight this post!  
Unread 07-04-2011, 23:24
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: I Have A Question About Pointers

Quote:
Originally Posted by davidthefat View Post
Actually it might be in kernel mode. That explains why vXWorks does not have a system call system. You just go do it for yourself, there is no asking for the OS to do it for you.
The 6.X version of VxWorks does have a system call interface (and normal block, character and network drivers) and processes (which they call RTPs or real-time processes) but the robot code does not use them. But RTP support is not included in the cRio BSP (board support package) provided to FIRST. All the robot code runs in the kernel context or mode.

HTH
Reply With Quote
  #27   Spotlight this post!  
Unread 08-04-2011, 08:53
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: I Have A Question About Pointers

Quote:
Originally Posted by wireties View Post
...the robot code does not use them ... RTP support is not included in the cRio BSP (board support package) provided to FIRST. All the robot code runs in the kernel context or mode.
Keith, I'm not disagreeing with you, but how do you know all this? Is there a document somewhere which discusses this ?


Reply With Quote
  #28   Spotlight this post!  
Unread 11-04-2011, 15:14
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: I Have A Question About Pointers

Quote:
Originally Posted by Ether View Post
Keith, I'm not disagreeing with you, but how do you know all this? Is there a document somewhere which discusses this ?
NP Ether - I taught engineers how to use VxWorks (and embedded Linux) for 15+ years. Check Help->Help Contents->Wind River Documentation from the Workbench IDE. Under Guides->Operating System there is a Application Programmers Guide (which is about programming in a RTP) and a Kernel Programmers Guide (about programming in kernel space/mode) and a BSP Developers Guide (which is about building a board support package - which NI gives us). In our case, NI and/or WPI chose to not use RTPs and stick everything in kernel space/mode (probably because that is how LabView's code generator works). The C/C++ Developer User Guides and Getting Started->Tutorials are also most helpful.

HTH

Last edited by wireties : 11-04-2011 at 15:16.
Reply With Quote
  #29   Spotlight this post!  
Unread 12-04-2011, 06:32
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,753
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: I Have A Question About Pointers

I'm not on the RT team, but the reason I was given was that when they did the board support, the RTP introduced too much overhead for the I/O drivers. Until FRC, the only C programmers for the cRIO were the NI developers, so they kept it in kernel mode. At that time, all other users of the cRIO used LV.

Exposing the C/C++ interfaces and tools, going to RTP was evaluated, but there would be a lot of work and testing involved, and it would mess with the I/O rates of various drivers.

Greg McKaskle
Reply With Quote
  #30   Spotlight this post!  
Unread 12-04-2011, 09:23
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: I Have A Question About Pointers

Quote:
Originally Posted by wireties View Post
Check Help->Help Contents->Wind River Documentation from the Workbench IDE. Under Guides->Operating System there is a Application Programmers Guide (which is about programming in a RTP) and a Kernel Programmers Guide (about programming in kernel space/mode) and a BSP Developers Guide (which is about building a board support package - which NI gives us). In our case, NI and/or WPI chose to not use RTPs and stick everything in kernel space/mode (probably because that is how LabView's code generator works).
Are these three Guides freely available online somewhere, for those who do not have the Workbench installed ?


Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:37.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi