Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: Forth for M...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 21 of 54 Topic 3987 of 4053
Post > Topic >>

Re: Forth for Mac OS X Leopard (Intel) - what are the options?

by Albert van der Horst <albert@[EMAIL PROTECTED] > Apr 7, 2008 at 10:18 PM

In article
<de98d751-518d-4aa9-b7a3-ab33452883d0@[EMAIL PROTECTED]
>,
 <sToRNG.BaRE.dURiD@[EMAIL PROTECTED]
> wrote:
>Regarding building ciforth/Lina for OS X  ...
>
>Firstly, thanks for making that available - it's a fantastic resource
>I've really quite neglected to look at while exploring forth.
>
>On Apr 5, 6:44 pm, Albert van der Horst <alb...@[EMAIL PROTECTED]
>
>wrote:
>> In article <jytq5r....@[EMAIL PROTECTED]
>,
>> Albert van der Horst  <alb...@[EMAIL PROTECTED]
> wrote:
>> <SNIP>
>>
>> >You *got* to find out how to do a system call, and how to pass
>> >parameters. In Linux this is : parameters in AX BX CX.
>> >System call is
>> >      INT 0x80
>> >      DD  <syscal nr>
>>
>> Sorry of course this is:
>>
>> In Linux this is : parameters in BX CX DX
>> <syscal nr> in AX
>> System call is
>>       INT 0x80
>> So no interspersing of code and data.
>>
>> I found information on the internet, suggesting that
>> this works the same way on a Mac Intel, except for
>> register DX.
>>
>> >This is tricky and documentation may be hard to find, but it is
>> >not really difficult for a hacker.
>
>Been looking and I _think_ I may now know how to call the OS X kernel
>(intel). One may be able to call the OS X kernel with these (hopefully
>correct) assumptions :
>
>1. The kernel function no.s/jump tables are all the same or fairly
>similar across the board. As you say, they appear to be similar
>between BSD and Linux.
>
>2. They can all be accessed by an int 0x80.
>
>3. The pattern appears to be in linux the parameters as you say are
>passed in registers. However in BSD and the OS X kernel XNU, so far it
>seems to me, EAX carries the function call no. and the rest of the
>stuff is _pushed_on_to_the_stack_ (ie ESP).
>
>I do not believe these hold universally, they seem to for simple io
>I've tested (ie output to console, files), but these are VERY
>preliminary.
>
>Now porting Lina:
>
>First, the (hopefully) easy bit. Unfortunately I think the order of
>parameters is reverse from the way your hard coded words in Lina call
>the _syscall mechanism you use to call the linux kernel (ie LINOS and
>LINOS5).
>
>The 2 ways that immediately come to my mind to fix this are
>
>1.  the more predictable one is to fix LINOS and LINOS5 to reorder the
>stack and then do an int 0x80. I think I favour this lazy way out as
>the other way would be to rewrite all the words that call LINOS and
>LINOS5. The advantage of course is user code calling said functions
>won't be broken. The code to do this is ugly however - see right
>below.

This is the way to go. That is where LINOS was factored out for.

>
>
>2. Just rewrite the prebuilt forth words to reorder the parameters. A
>little bit more work but doable but user code out there could be
>broken. However I expect few people would be calling LINOS directly...
>or maybe I am wrong.

LINOS is used in the library, so you would have to patch the
library too. No it is not a good idea.

Calling LINOS is useful:
I recently was experimenting with time outs on reading
from serial ports.
10 _ _ 27 LINOS
(with _ is don't care)
sends an alarm signal in 10 seconds.
Then a small CODE word and another LINOS call (to set traps)
turns the signal into a THROW, such that an infinite loop
is terminated and can be CATCH-ed in 10 seconds.
This is an alternative to a situation where you can only
use facilities that are expressly imported into a Forth via
c-libraries. The advantage is that you are not held back
to experiment with any system call.

>
>All potentially a pleasant evening's work EXCEPT
>
>*** LINKING ***
>
>As you say, one needs to know how to link.
>
>This is very painful given my lack of knowledge of certain
>fundamentals of OS X and linux binaries - how they link etc..
>
>I do not fully understand yet:
>1. The ELF binary format
>2. And of course, mach-o
>3. Lastly I guess I've just had your source for 8 hours :) I'm
>printing a copy...
>
>Have you any suggestions?

If the elf format is used, that is already nice, because it is
well documented.

Use a standard assembler if available.
Use the standard linker.
See what happens.
E.g. with nasm on linux
        nasm -felf lina.asm -o lina.o
        ld lina.o -o lina
It doesn't get much simpler than that.
It worked when I knew nothing more about the elf-format
than that it existed.
Now SAVE-SYSTEM was a little more work.

>
>I have a (somewhat) running executable. Please feel free to comment/
>patch/debug/cast stones/burn etc... :)
>
>MAC OS X INTEL port of lina available for download (source and
>executable)

If the executable runs, you can ask
   make testlina
in the generic environment, and find out where it crashes ;-).

>
>http://savefile.com/projects/808626874
>
>Be wary, not all linux calls map 1 <-> 1 OS X.
>
>If any one EVER gets a complete reference of all the direct OS X XNU
>kernel calls, please please please please please send it my way :)

On some unix systems
   man 2 syscall
provides valuable clues.

>
>As for me, I've been awake the whole weekend at work and spent the
>whole morning resetting my clock doing this, so it's time for bed
>before I start looking at it any further.

I'm kind of busy at the moment, but I'll try to have a look at
your source tonight.

>
>Robert Spykerman

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@[EMAIL PROTECTED]
 &=n http://home.hccnet.nl/a.w.m.van.der.horst




 54 Posts in Topic:
Forth for Mac OS X Leopard (Intel) - what are the options?
billclem@[EMAIL PROTECTED  2008-04-03 18:19:47 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-04 03:53:57 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
stephenXXX@[EMAIL PROTECT  2008-04-04 13:42:15 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Ian Osgood <iano@[EMAI  2008-04-04 08:44:54 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
anton@[EMAIL PROTECTED]   2008-04-05 15:26:25 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Bernd Paysan <bernd.pa  2008-04-05 23:14:35 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Roelf Toxopeus <these3  2008-04-04 20:44:10 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
dhoffman@[EMAIL PROTECTED  2008-04-04 18:01:21 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Henry <henry.olders@[E  2008-04-04 12:44:04 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
billclem@[EMAIL PROTECTED  2008-04-04 15:36:47 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-04 23:20:15 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-05 08:44:20 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-04 18:21:56 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
anton@[EMAIL PROTECTED]   2008-04-05 15:33:28 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-04 18:27:24 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
anton@[EMAIL PROTECTED]   2008-04-05 15:22:30 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
pliz <s.m.plis@[EMAIL   2008-04-05 19:27:42 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Bernd Paysan <bernd.pa  2008-04-06 14:05:50 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
sToRNG.BaRE.dURiD@[EMAIL   2008-04-07 03:09:18 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Josh Grams <josh@[EMAI  2008-04-07 12:08:28 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-07 22:18:46 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-10 01:52:10 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-07 03:50:05 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
billclem@[EMAIL PROTECTED  2008-04-07 13:35:54 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-07 17:35:47 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-07 21:53:32 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-08 19:21:05 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-08 16:39:52 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Duke Normandin <dukeof  2008-04-09 00:18:48 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-10 03:10:44 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Josh Grams <josh@[EMAI  2008-04-10 11:30:24 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-10 18:10:11 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Josh Grams <josh@[EMAI  2008-04-11 00:03:18 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-08 18:36:55 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-10 03:25:30 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-09 05:56:53 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-10 04:09:29 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-10 07:45:29 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Josh Grams <josh@[EMAI  2008-04-10 16:33:31 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-10 21:13:01 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Josh Grams <josh@[EMAI  2008-04-11 00:20:38 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-10 17:08:26 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Josh Grams <josh@[EMAI  2008-04-11 13:27:42 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Thomas Pornin <pornin@  2008-04-11 16:32:25 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-11 21:21:11 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Albert van der Horst <  2008-04-11 22:26:52 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Josh Grams <josh@[EMAI  2008-04-12 00:23:55 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-11 10:27:30 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Josh Grams <josh@[EMAI  2008-04-12 00:14:10 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-11 10:43:54 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Slava Pestov <slava@[E  2008-04-11 17:29:31 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
Robert Spykerman <robe  2008-04-12 08:55:47 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
billclem@[EMAIL PROTECTED  2008-04-13 22:43:10 
Re: Forth for Mac OS X Leopard (Intel) - what are the options?
"M. Edward (Ed) Bora  2008-04-22 05:59:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 4:37:32 CDT 2008.