 |
 |
Assembly Language
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Location: San Francisco
Status:
Offline
|
|
Hey friends - Here is a sort of vague question for you regarding OS X -
Has anybody tried messing around with PPC Assembly in OS X - I really want to see how far into the guts of my little iMac I can get - I want to take direct control of the hardware and do weird stuff if I can - Anybody tried this kind of thing yet?
thansk///
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Just posting to keep this alive as I am interested in this too.
------------------
Think Different.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status:
Offline
|
|
I've never done this, but I'd guess it's the same as with any BSD - even written in assembly, there are strict limits on what the kernel allows each program to do. You won't find a lot you can do in assembly that you can't do with Objective-C (except being faster, of course).
However, you will find a lot you can do with the various higher-level interfaces available for communication between programs and parts of the system. Spawning Terminal apps, for example, gives you a lot of freedom.
You know, if you *really* want to fiddle, try the Open Firmware. At startup, hold down ( option, command, o, f ). Instructions are at http://developer.apple.com/technotes/tn/tn1061.html
|
|
All words are lies. Including these ones.
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Yeah, as was said you can't go any lower level by using assembly, but optimized assembly is often faster than optimized C.
There are lots of private frameworks for you to fiddle with, especially if you use class-dump to extract the interfaces
You can, of course, go lower level by entering kernel space and writing a kernel extension...
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Location: San Francisco
Status:
Offline
|
|
Yeah - thats what I was thinking - Messing with KEXTs - I really wanna 'talk' to the hardware without hinderance.
I'm wondering how hard it would be to totally take control of the machine - Say - to make a super stable music app or something...
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
Unless you modify the kernel, you can't take total control of the machine. I am not an assembly guru but I have been slowly, trying to learn assembly. In my opinion, PowerPC Assembly looks easier than 68k assembly because there are fewer instructions to memorize but, on the other hand, there are also more steps in doing stuff. The major stumbling block that I have run into is incorporating assembly in with C/C++/Objective C. You can use something like _asm("type assembly here") in order to put an assembly statement directly into C code but I don't know how to access data that I declared in C. You can call C functions from within assembly, I don't remember how but it isn't all that hard.
Here is one way to see the code that the compiler generates. Write a short program in c that only takes up one file. Then, on the command line compile it like this:
cc -S myFile.c
It will generate a myFile.s which is an assembly file. You can then read that and see what the compiler generated. Also, remember that you can specify different optimizations for example, -O3 is highest level of optimization. Example:
cc -S -O3 myFile.c
I know that you can also generate assembly output for compiles of multiple files but I do not know how.
I'm not sure if the compiler is very efficient or not. It always looks like it's branching and using the stack when it doesn't need to but I'm going to have to learn more assembly in order to really see what's going on.
[Edit]
Oh yea, if you want to talk more closely with the hardware, I think that it'd be a better idea to invest time in learning IOKit instead of assembly, or at least before assembly. Why go insane trying to figure out an assembly interface when you already have one in C?
[This message has been edited by Dalgo (edited 05-13-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Location: San Francisco
Status:
Offline
|
|
Because I want ZERO layers of abstraction in my way - I want to hack this like the old 68k amiga hackers used to do - total control - not some 'official apple approved' IOKit...
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: New York, NY USA
Status:
Offline
|
|
admirable, but I'd start with the IOkit, if I were you... at least that way, you'll see what you can and can't do. then go to assembler.
as far as what assembler is available, osx comes with a fairly complete gnu toolchain, which includes the GNU assembler, with some optimizations for altivec from apple.
I'd start with a good PowerPC assembly book, if I were you.
g'luck
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Location: Malaysia
Status:
Offline
|
|
Do you guys recognize your illness? Professional counselling can provide a very helpful hand in your sick sick cases!
---gralem
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by cynistar:
Because I want ZERO layers of abstraction in my way - I want to hack this like the old 68k amiga hackers used to do - total control - not some 'official apple approved' IOKit...
perhaps it's "apple approved" because it makes it:
1) easier
2) harder to screw up
3) less pointless
you don't need to even go as low as IOKit. Use CoreAudio. Would you like to explain just why you plan on going and talking to the hardware directly? Not only will this cause problems because it will only run on computers almost identical to the one you're using, but it will also be a hell of a thing to debug, and you're going so low level that you're not going to be able to do it on OS X (where I'm pretty sure everything goes through Mach, and even going as low as mach from carbon/cocoa apps can make things screw up).
If you really want to talk to hardware directly, go write your own OS.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Location: San Francisco
Status:
Offline
|
|
Actually that is a good observation - Why would I even *want* to get that much low level control of the hardware? Well, I am thinking of writing a sort of 'solid state' electronic music program - one where there is NOTHING other than the software itself doing its thing... Not the finder, not a scheduler nothing -
And I am in fact only thinking about doing this on a specific rev of iMac or maybe iBook - because they can be had cheap nowadays and if I turn one into a depdnable and stable noise maker it will be something I can use in live entertainment ...
It has always been a dream of mine for somebody to write a sort of 'MUSIC ONLY' OS where I put in a CD and the machine boots off of the CD and is 'taken over' by this Music OS with nothing else taking any processor time or causing conflicts - Of course, I'd still want access to storage (hard drive) but the guts of this system would be kept on a CD...
anyway - that's what I'm thinking about...
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
What you're talking about is writing a simple operating system. It can be done, rather easily too. I suggest that you check out books about Minix, for example.
The reason that most folks don't do this (and why few will understand what it is you're proposing to do) is because there's such a great advantage in using the resources programmed by the OS designers.
You could boot Mac OS X in single-user mode, use the command-line interface, and you're pretty close to the "cold iron" of the hardware but with lots of resources and libraries at your disposal.
------------------
Since EBCDIC
Make every post count!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status:
Offline
|
|
Since EBCDIC
You could boot Mac OS X in single-user mode, use the command-line interface, and you're pretty close to the "cold iron" of the hardware but with lots of resources and libraries at your disposal.
Or just use Darwin. Or BSD.
|
|
All words are lies. Including these ones.
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by Since EBCDIC:
You could boot Mac OS X in single-user mode, use the command-line interface, and you're pretty close to the "cold iron" of the hardware but with lots of resources and libraries at your disposal.
You're really no closer than running OS X in normal mode... You're still quite a few layers away from the hardware. There are fewer processes running, but that's about it.
If you really want to write an OS, then good luck to you. To me it sounds incredibly stupid, and a lot more work than it needs to be. But hey, if you want to write device drivers for mundane things like IDE hard drives, it's your choice 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
If you wish to supplement C/C++/Objective C with assembly in OS X, then when you want to put in some assembly statements do it like this: Suppose that you want to, for some reason, copy r3 ro r5, then say copy r3 to r7 also. Then, amidst your C code you could add this:
asm ("mr r5, r3\n"
"mr r7, r3");
viola, that's it... but there's one more thing that you might wish to do. Sometimes the compiler might get wise and decide that it doesn't like the assembly that you have added. In order to prevent the compiler from changing it, all you'd do it like this:
asm volatile ("mr r5, r3\n"
"mr r7, r3");
The volatile keyword keeps it from messing with your assembly. BTW, if you want to map variables in C directly into specific registers you do it in the declaration like this:
register float myFloat asm("f6");
This makes it such that myFloat lives in f6 during it's scope. Give up on writing a new OS and just use assembly to supplement your C/C++/Objective C.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
This isn't what he wants to do. He wants to make sure that his code is the only code running so that there is no chance for bugs in other people's code. This is a common mentality, but he has taken it to the extreme. Anyways, if he really wants to write his own OS, this is completely offtopic for the OS X - Developer forum.
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Moving this over to Developer.
Good luck, yer gonna need it.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|