flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > MenuetOS > Porting Menuet from x86 to ARM... Possible?

Author
Thread Post new topic Reply to topic
S0urcerr0r



Joined: 19 Oct 2010
Posts: 5
Location: SWEDEN
Porting Menuet from x86 to ARM... Possible?
Atm i know almost no assembler - im progressing very slowly.
However, Im considering an attempt to port Menuet to ARMEL, as a step in learning ASM Instructions.

Ive bought a Beagle Board:
http://beagleboard.org/
And it would be a nice project to undertake ...AND it will not be a serious project (at least not in the beginning). It will only be a learning project for making small manipulations to instructions to get it compatible.

Im not gonna attempt a full conversion of the full menuet, but i want to use the Menuet source as a reference on how to efficiently code Asm.
Ill rather learn Asm by looking at other peoples work than by SLOWLY progressing with a trial and error approach.

So the questions is:

1.) Would it be possible to convert "Menuet x86 asm" to "Menuet ARMEL asm"? Would it even be possible to do a full working conversion?
2.) Are there any sneaky traps that could ruin the project? Like CPU cache limitations on the 1GHz ARM Cortex-A8 of the beagle board, or maybe other "Memory addressing issues"...
or maybe other missing features... i remember reading the following on a forum about comparing x86 and ARM:
"These are very different architectures. ARMs can only do integer maths, can't divide, but have good power saving capabilities."
...would that become a serious problem or is it just that it will require more instructions to do Divides and Floating point math?
3.) What do u think of this approach to learn Asm?
...That is - to learn Assembler by converting x86 asm to ARMEL asm?
The pro-side should be that i will get to practice translating by looking up all instructions as i go along in the code, while getting used to "reading" efficiently coded Asm along the way?
And the con-side should be that it may feel overwhelming as i may not understand such complex branches of code in "one go"? ...that is, if ive understood this learning approach correctly...
Post 10 Jan 2011, 19:07
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
It's a little unclear on what you want to learn. Are you interested in learning ARM assembly or x86 assembly? I wouldn't suggest for someone who doesn't know either to attempt to learn both at the same time. Learning one language in a new paradigm is hard enough without trying to learn two, at the same time. As for "porting" an OS written in assembly, it would be as laborious as a complete rewrite, and then some. You'd probably have more fun just writing your own toy OS.
Post 10 Jan 2011, 20:42
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
It would be a rewrite, rather than a port, as Tyler pointed out.
This may give you some pointers
http://dex.7.forumer.com/viewforum.php?f=17
Post 11 Jan 2011, 00:43
View user's profile Send private message Reply with quote
S0urcerr0r



Joined: 19 Oct 2010
Posts: 5
Location: SWEDEN
Thanks very much, you both!
As you both say maybe i should write an os of my own for the Beagle Board.
i will definitly take a look at DexOS Smile
This is were Menuet will be very helpful, as i can use its code as a reference whenever i bump into a deadend.
Porting Menuet is only a step to become more self-sufficient in understanding how Assembler code is composed.
The REAL goal is to become self-sufficent and write a OS for mi N900 cellphone.
Im not gonna attempt making a multi-tasking OS, but rather make a single-tasking realtime OS, as its simpler.
It will have one sole function.
for example "dumping raw data from a camera and writting it to an unpartioned storage drive".
still it will be very difficult even making the simplest OS, and also controlling the camera, AND even accessing the storage drive - and this is where i think menuets source will be able to teach how to access hardware properly.




Tyler wrote:
It's a little unclear on what you want to learn. Are you interested in learning ARM assembly or x86 assembly?


Atm i dont wanna specialize in a certain architecture as im still struggling to understand the basic principles of Asm.
There are so many questions i have about the pure basics of Asm and the easiest way to get answers, is by studying other peoples work... i dont have a mentor to ask, when i reach deadends... these basics are essential to even consider coding in Asm.

The thing is that, in given time, i can learn all x86 or all arm instructions.

What i cant seem to learn though, is how to use these Instructions properly - and this is the big problem.
For example, i cant seem to understand:

* How i can make the CPU communicate with other hardware (PCI, sound, graphics) ...i THINK Interrupts have something to do with it, but i have NO IDEA AT ALL on how its done. Im limited to the knowledge of "INT 21h".

* How to PROPERLY use variables.

* How to properly manage Memory addressing (data/code segments, and periphal addressed shared memory)

* How to write efficient code - short and effective


By reading MenuetOS source while doing the translation process, i will not only learn all the instructions - i will ALSO learn how efficient code looks.
My mind will develop by looking at the code, as i will understand why its written the way it is.

A metaphore:
So far i feel that learning Asm have been very confusing, and can be compared to trying to learn Chinese by only studying a dictionary.
i know neither chinese (=x86) or japanese (=arm) - but the approach i NOW want to take is to learn the Grammatics and Efficient communication by studying some "excellently written" texts in Chinese and using the dictionary to translate it step-by-step into Japanese.
While doing so i will learn how properly written texts in Chinese should look, while still stimulating the mind, by challenging it with the difficult training of translation. The japanese (=ARM code) i'll write, will not be super efficient but it will still be stimulating since i get the chance to study the Chinese (x86 code) texts and manipulate it as i go along.

Ive found no Asm book that feels like much more than a Dictionary. No books seems to teach me how to code Asm - but only the meaning of the instructions.
Post 11 Jan 2011, 06:54
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
There's no x86 OS that's going to teach you anything about accessing components of an embedded-like device(such as a cellphone).

There aren't any universal basic principles of assembly. That's the thing with assembly, it's unique to every architecture, and even differs between processors of the same architecture.


Quote:

* How i can make the CPU communicate with other hardware (PCI, sound, graphics) ...i THINK Interrupts have something to do with it, but i have NO IDEA AT ALL on how its done. Im limited to the knowledge of "INT 21h".


INT 21 is DOS related. On x86, the CPU communicates with most modern devices through shared memory. Older stuff is accessed through IO ports.


Quote:

* How to properly manage Memory addressing (data/code segments, and periphal addressed shared memory)


Here's where the fun "translating" happens. ARM is a different architecture than x86, and has a different way of providing a virtual address space. I don't know the specifics, but they're different.
Post 11 Jan 2011, 11:40
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314

S0urcerr0r wrote:

Ive found no Asm book that feels like much more than a Dictionary. No books seems to teach me how to code Asm - but only the meaning of the instructions.



Have you tried the Art of Assembly by Randall Hyde?

http://homepage.mac.com/randyhyde/webster.cs.ucr.edu/www.artofasm.com/index.html

regards
Mac2004
Post 14 Jan 2011, 20:29
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7111
Location: Slovakia

Quote:
Have you tried the Art of Assembly by Randall Hyde?


But rather get some (older?) non-HLA version
Post 14 Jan 2011, 20:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314

Quote:

But rather get some (older?) non-HLA version



Agreed, I would recommend the 16bit dos version for S0urcerr0r.


Regards
Mac2004
Post 15 Jan 2011, 07:57
View user's profile Send private message Reply with quote
redrum88



Joined: 30 Mar 2016
Posts: 5
I have a RPi and I would love to run menuetOS on it.

Does any body know about any port/rewritting?
Post 31 Mar 2016, 11:05
View user's profile Send private message Reply with quote
Ville



Joined: 17 Jun 2003
Posts: 197
X86 and ARM command-sets are similar, so most of the commands can be directly translated. There are some small differences, like the lack of divide instruction in some arm-models. Also the interrupt handling routines needs to be rewritten and some mathematical functions don't necessarily have an arm counterpart. Overall, I'd estimate that over 90% of the code is translatable.

Another interesting is the Odroid-C2, which has four 64bit cpus, running at 2.0Ghz.
http://www.phoronix.com/scan.php?page=article&item=raspberry-pi3-odroid2&num=1
Post 01 Apr 2016, 13:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14588
Location: Planet Dirt

Ville wrote:
X86 and ARM command-sets are similar, so most of the commands can be directly translated. There are some small differences, like the lack of divide instruction in some arm-models. Also the interrupt handling routines needs to be rewritten and some mathematical functions don't necessarily have an arm counterpart. Overall, I'd estimate that over 90% of the code is translatable.

I think you forgot a couple of things. ARM doesn't have the ability to do arithmetic directly on memory locations, only load and store, so this has quite a major impact on the code layout. Also, memory offset encoding and immediate constant encoding have some quite severe restraints, and some quite powerful extras, when compared to x86. And if the x86 code uses the parity flag then you are in for a bit of pain to translate that into equivalent ARM form. You will also miss out on a lot of nice optimisations if you just want to translate instead of rewriting the algorithms to suit ARM code.
Post 01 Apr 2016, 13:34
View user's profile Send private message Visit poster's website Reply with quote
Ville



Joined: 17 Jun 2003
Posts: 197

Quote:
From 64bit ARM developer quide:
Unaligned address support
Except for exclusive and ordered accesses, all loads and stores support the
use of unaligned addresses when accessing normal memory. This simplifies
porting code to A64.


So for example, memory addressing and other operations have been simplified with the new 64bit ARMv8.
http://infocenter.arm.com/help/topic/com.arm.doc.den0024a/DEN0024A_v8_architecture_PG.pdf
Post 01 Apr 2016, 14:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
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 vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.