nasm port

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
lama
Member
Member
Posts: 83
Joined: Thu Apr 16, 2009 8:41 am

nasm port

Post by lama »

hello everyone,
i have a one really silly question. i want to port nasm to my os, so i can write programs right inside my system.
but i'm not quite sure whitch way should i do it. the most easiest way could be just download nasm for dos with standalone dos protected mode extender (i tried it on fresh dos with nothing else then nasm and extender, i just launched nasm and it worked), switch back to real mode, implement my own dos-like interrupts to the ivt and write some basic routines that would control execution, basic fat12 filesystem and disk reading/writing. After deciding to quit nasm, i would just restore protected mode and continued normal system exection. i thing i want to choose this option, becase these routines (for executing real mode programs under my pmode os and then transfering control back to my os) already exists in my system (i have programmed it for vesa video mode switching purposes). From the other point of view i could just setup unreal mode (thus discarding extender) and implement dos-like interrupts to my existing idt. but again, i'm not sure how to do it. take for example dos int 0x21 - on that idt entry sits my keyboard isr..so this method will obviously require some sort of pic reprograming (again) - and i really do not want to do that. plus - due to the ip 16bit limitation, unexistent pmode idt, different adressing mode etc..., the system will most likely crash.. And take the entire nasm source code (supposing that it is available to the public) and completly rewrite it to acutaly match my system - that is a mission on it's own ...
So, what are my options? what are your advices?
thanks for any reply.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: nasm port

Post by JamesM »

Firstly, please try to use paragraphs. A wall of text is impossible to read.

Secondly, it would help if you actually had an OS to start with before trying to port nasm to it. From what I read it seems like you're trying to mould your OS around nasm?
lama
Member
Member
Posts: 83
Joined: Thu Apr 16, 2009 8:41 am

Re: nasm port

Post by lama »

mould? how you mean mould?
i'm just trying to find the easiest way how to do what i want.
could you be more specific?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: nasm port

Post by thepowersgang »

How much of your OS is already written? From your original post it seems that you are still in the planning stage of your OS.

Porting an existing application requires quite a large amount of helper code (a usable usermode, a shell and C Library at the very minimum)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: nasm port

Post by DavidCooper »

It sounds to me as if you do have a fair bit of you OS written and you're considering trying to mould (not fungus) it to fit someone else's assembler by contorting your OS rather a lot. I don't know if that means you're going to need DOS running on the machine as well or if it just uses the BIOS (I know next to nothing about NASM and DOS), but I don't see that being a huge problem in relation to your interrupt vectors if your OS runs in protected mode as you can simply switch between tables. More of a problem is how you're going to oranise the use of memory with two competing operating systems sitting in memory at the same time and taking turns to run. I would have thought that the most sane option would be to modify the source code to make NASM run on top of your OS if you're allowed to do that, or alternatively write your own assembler to use the same format. It might take a lot of work, but your OS ought to be worth going to that much trouble for if it's any good. An alternative would be to develop an assembler entirely of your own design and to built it up over time, adding instructions to it as you need them. Ultimately you're the one best placed to make the decision - how much do you want to compromise your OS? What's your OS for? What are your ambitions for your OS? If you have big plans for it, do something bold and daring.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
lama
Member
Member
Posts: 83
Joined: Thu Apr 16, 2009 8:41 am

Re: nasm port

Post by lama »

No, you are wrong.
I have an operation system. It's written entirely using assembler.
It runs in protected mode, has no user mode yet, so everything (even applications) runs in kernel mode.
System has shell, functional multitasking where one process means one shell and maximum of 256 proceses can be run (so that means that maximum 256 shells can run side by side, and i can switch between them by pressing a key).
In a limited way shells can communicate between each other.
Basic batch scripts supported.
I have simple virtual filesystem for devices/mountpoints/executables/commands purposes.
My external drivers are loaded just after system boots and initialise.
Supported devices are 3.5 floppy (also boot device), ata hdd, atapi cdrom, serial port, basic pci, ne2000 (just receiving and transmiting multicasts, no ip/tcp/udp is implemented), PS/2 mouse.
Supported filesystems are so far only fat12, iso9660, and ext2 almost running (can mount root).
Video routing to serial output, single stepping debugger, so if i'm trying my code on real hardware and it tripplefaults, i can see what happend as last thing before reset.
Real to protected mode APM interface enabled, so i can use it inside protected mode.
Numbers of system interrupts, so external programs can call it a use it without the need carying its own drivers.
Default video mode is 80x25 textmode.
I'm playing with vesa mode, and it can be setuped, and ugly window is drawed and there is where my mouse comes to live :D
Real mode programs can be run by noticing system that the next program that i try to run is real mode application. So system loads program as usual, setups real mode, executes that program, returns back.

It's not that much, it is sometimes kinda bugy, sometimes it sucks and I know that I'm not exceling in writting OS'es.
But never the less, it is far away from some 'DOS-NASM-whatever mudling or whatever....'.

- I just want to use NASM inside my system, like EVERY other system does. Becase DOS is the most easiest system ever created (it's not much like an OS), therefore any application written for DOS is also simple. There is a DOS distribution of NASM.
So I have bin just supposing, that i would do exactly what i'm doing when executing real mode programs (as said above),
write my OWN DOS-like interrupts (int 0x21 etc...) that would match the original one. Execute NASM and whatever, save the compiled file to disk and then return back.
So try again to read my post, and then please respond.
Thanks.
lama
Member
Member
Posts: 83
Joined: Thu Apr 16, 2009 8:41 am

Re: nasm port

Post by lama »

bercus : that is what i ment :) right :)
OK , so what's you suggestions? is it doable?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: nasm port

Post by thepowersgang »

It's doable, but it's hard.

Implementing another OS's ABI is difficult, especially when you get to the little bugs/issues with the API. And, as berkus said, it will be far more difficult than just re-compiling nasm for your OS.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
lama
Member
Member
Posts: 83
Joined: Thu Apr 16, 2009 8:41 am

Re: nasm port

Post by lama »

ok, so do you think it would be much easier to just swtich back to real mode, write some real mode routines to be able to load and run nasm (for dos) with that extender? and what exatly requires that DPMI to run? has it everything what it needs 'on board'? some documenation would be in order..
i mean - if it is programed for dos, then it should need nothing but only ivt updated with dos-like interrupts, right?
or do i need something else to achiev this?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: nasm port

Post by Brynet-Inc »

NASM has source code available, why go down the binary emulation road?
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: nasm port

Post by Brendan »

Hi,
lama wrote:ok, so do you think it would be much easier to just swtich back to real mode, write some real mode routines to be able to load and run nasm (for dos) with that extender? and what exatly requires that DPMI to run? has it everything what it needs 'on board'? some documenation would be in order..
i mean - if it is programed for dos, then it should need nothing but only ivt updated with dos-like interrupts, right?
or do i need something else to achiev this?
You'd have to add support for the DPMI API to your OS (and use that instead of the DOS extender), as a normal DOS extender assumes it has complete control of the computer (including the assumption that the memory your OS is using is "free"). Note: Wikipedia has links to the DPMI specifications on it's DPMI page.

In the end you'd have a 32-bit program (NASM) using a messy hack (DPMI) to run on DOS; which is using a messy hack (virtual8086 mode or something?) to run on a 32-bit OS. It'd have to be the ugliest way of running 32-bit code on a 32-bit OS ever conceived.... ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
ym
Posts: 8
Joined: Thu Mar 24, 2011 2:05 am

Re: nasm port

Post by ym »

nasm looks like just use file io and memery api, if your system implemented file io api and dynamic loader, may be you generate some libs and recompile the nasm should be ok.

:D or else port the nasm as a function to your os.
lama
Member
Member
Posts: 83
Joined: Thu Apr 16, 2009 8:41 am

Re: nasm port

Post by lama »

ok, i want to make it work under my system as a 'port'. i need source code - on their website is written, that if i download dos distrubution, the source code will be included with it. but that is not true, no source, just executables, extender and doc.
has anyone source codes i may use?

EDIT: sry, found it :D
i'll try what have been suggested to me.
thanks, topic is still open :)
Post Reply