Page 1 of 1
How to port Bash or Dash
Posted: Fri May 16, 2014 2:31 am
by dragen
hi everyone , i am writing a individual operating system and have implemented some basic functions , such as schedule , memory mapping and memory managerment .
so i want to do some user interface ! i want to use bash or dash or some basic shell in my operating system .
i do not know what conditions are necessary to run the bash or dash ?
need i implement all POSIX system call or what should i do to port the bash into my operating system .
please give me some guide or explain what should i do ?
thanks so much for all your help , i am waiting for your comments .....
Re: how to port a basic bash or dash to my individual OS?
Posted: Fri May 16, 2014 2:53 am
by gerryg400
In the long run the easiest way is to begin by building an OS specific toolchain as described here
http://wiki.osdev.org/OS_Specific_Toolchain. There is a considerable learning curve involved but you can get lots of help here and at #osdev.
After you have done this and have enough system calls many programs (including dash) will configure and make quite easily.
Re: how to port a basic bash or dash to my individual OS?
Posted: Fri May 16, 2014 2:55 am
by bluemoon
This is a far target.
First you would need to extend your scheduler to support process, which is an entity that you may later add resource handle and address space(I'm not familiar with SAS design).
Next, you want an VFS layer and some ram-based device and file access, it can be fairly simple in version 0.1.
Then you write parser for the executable format - note that you may implement and test it on host environment.
Now you code the glue to start a process, and optionally a dynamic linker.
At this point you reached a mile-stone, and you should be able to start a program with:
int main(int argc, char* argv[]) {
return 0;
}
The kernel may panic after main exist, it does not matter.
------------
The second mile-stone is to support libc, there are many solutions: newlib, uclibc, pdclib, glibc, roll your own, etc.
The common thing is you need a system call mechanism, usually INT handler or sysenter/syscall entry.
The minimum effort you need for newlib is about 17 dummy functions.
At this point you reached a mile-stone. You should be able to use printf, usleep, etc on your test program.
You may optionally redirect content of write() system call to debugger or serial port.
You may also implement some form of input device and a unix style file abstraction, so that you can "use" the shell.
------------
The third mile-stone is the painstaking work of porting libraries.
There are many functions in your libc glue remain not implemented, catch them and implement them.
Re: How to port Bash or Dash
Posted: Fri May 16, 2014 6:18 am
by sortie
You are likely not ready for such a port yet. Bash depends on libreadline and other non-trivial things, even I don't have a bash port at the moment. Dash is significantly easier to port, but still non-trivial for people starting out in user-space. I recommend you write or reuse a libc and get comfortable with user-space and your OS-specific toolchain. Then you ought to write your own bad shell, which just strtok_r's on spaces and passes that to fork and execve. If you can't write a simple program like that yourself, you don't stand a chance porting bash or dash.
You should attempt porting easier software before attempting dash or bash.