OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 5:18 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: How do I add a shell to my OS?
PostPosted: Wed Feb 08, 2017 7:57 am 
Offline

Joined: Wed Feb 08, 2017 7:54 am
Posts: 2
Hi, Guys,

I am new here and I wanted to ask this question on how to add a shell? I already created the kernel using the Bare Bones tutorial but now I want to add a shell to the kernel The Wiki doesn't really explain on where to put the code do you add it to the kernel.c or do you have to make a separate file for it?

Hope you guys can help me :)


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Wed Feb 08, 2017 9:51 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
Quote:
do you add it to the kernel.c or do you have to make a separate file for it
That's completely up to you.

I would actually suggest to avoid putting a shell inside your kernel. Instead focus on the important things like virtual memory, VFS and userspace processes. Then you'll be able to make the shell a user program.

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Wed Feb 08, 2017 2:46 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
beachkid wrote:
Hi, Guys,

I am new here and I wanted to ask this question on how to add a shell? I already created the kernel using the Bare Bones tutorial but now I want to add a shell to the kernel The Wiki doesn't really explain on where to put the code do you add it to the kernel.c or do you have to make a separate file for it?

Hope you guys can help me :)


You need to create

- userspace processes
- ways to spawn them
- ways to communicate between them
- ways to use libraries, preferably shared ones so you don't waste memory when mulitple processes are running
- terminal drivers that could work with multiplexed i/o from many processes in some way (both input and output)
- make one process (a shell) do user input and spawn other processes in response to user commands, connect communication channels between child processes and itself and be able to control their execution

easy-peasy

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Wed Feb 08, 2017 3:13 pm 
Offline
Member
Member

Joined: Wed Oct 12, 2016 11:32 am
Posts: 34
Location: At my PC
Do you have a keyboard driver?


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Wed Feb 08, 2017 3:35 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

beachkid wrote:
I am new here and I wanted to ask this question on how to add a shell?


Typically the OS provides various interfaces for user-related devices (keyboard, mouse, video, sound, etc); then you have a layer that talks to all of these (e.g. "X server") that is designed for modern event-driven user input (and not character streams) and modern (graphical) output; then you have some sort of terminal emulator layer (that may or may not run inside a GUI) that acts as a kind of a bridge between "modern, event-driven, graphical" and "antiquated character stream". Finally, after all of that, you have "shell".

beachkid wrote:
I already created the kernel using the Bare Bones tutorial but now I want to add a shell to the kernel The Wiki doesn't really explain on where to put the code do you add it to the kernel.c or do you have to make a separate file for it?


For all of the pieces I mentioned above; the device drivers are the only pieces that really belong in a kernel (and even then micro-kernel advocates would say device drivers don't belong in kernel either). Mostly; if all you have is "example/tutorial code cut&pasted from barebones" then you probably have less than 1% of the things you need for a real shell.

What you probably want is some kind of (temporary?) "kernel debugger thing" that you can use to interact directly with the kernel while you're spending then next several years implementing all the things you need for a shell. For this sort of "lean and mean, not a shell" you probably only need a keyboard driver (and all the stuff it depends on), a "generic frame buffer video driver" (and all the stuff it depends on), and (optionally?) some code to convert characters into pixels.


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.


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Fri Feb 10, 2017 6:44 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 17, 2016 6:58 am
Posts: 101
Location: The Internet
The Bare Bones kernel won't actually get you very far. I recommend you go to http://wiki.osdev.org/Meaty_Skeleton instead. There it gives you a nice code organization example, as well as plenty of reference links to other places that you will need to go (such as OS-Specific Toolchains) (http://wiki.osdev.org/OS_Specific_Toolchain)

_________________
Everyone should know how to program a computer, because it teaches you how to think! -Steve Jobs
Code:
while ( ! ( succeed = try() ) );


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Fri Feb 10, 2017 7:41 am 
Offline

Joined: Fri Feb 10, 2017 7:32 am
Posts: 1
I am new here,too! :o


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Fri Feb 10, 2017 12:13 pm 
Offline

Joined: Wed Feb 08, 2017 7:54 am
Posts: 2
MajickTek wrote:
The Bare Bones kernel won't actually get you very far. I recommend you go to http://wiki.osdev.org/Meaty_Skeleton instead. There it gives you a nice code organization example, as well as plenty of reference links to other places that you will need to go (such as OS-Specific Toolchains) (http://wiki.osdev.org/OS_Specific_Toolchain)


I actually switched to the meaty skeleton it does it better than the bare bones


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Sun Feb 12, 2017 4:54 am 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 852
Unfortunately, neither of those articles cover anything related to actual OS development. They simply show you how to create an image that GRUB can load, and there is example code for presenting text on the screen and an implementation of a few common standard C library functions. This may constitute a basic starting point to quickly start experimenting from, but the rest is up to you.

Obviously, you can't implement a shell or user mode at this point, since there is nothing for user programs to actually use. I recommend starting by implementing threads and synchronization, as well as some form of memory management, since almost everything else will depend on these.


Top
 Profile  
 
 Post subject: Re: How do I add a shell to my OS?
PostPosted: Sun Feb 12, 2017 9:56 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
Perhaps a bit more digging is called for. You say you have covered both Bare Bones and Meaty Skeleton, correct? Now, as Gigasoft states, the first of those only brings you to the point of booting a stub of a kernel from a GRUB, while the second focuses on providing some examples of how to fill in specific details such as kernel-level text output and some of th common standard functions which you might want to use inside your kernel as you develop it.

The first thing to understand is that, even with Meaty Skeleton, this is just a jumping-off point. It give you just enough information to be ready to start writing an OS, but it really isn't showing you anything of how to do that yet.

Second, even in the parts they cover - the parts that vary the least from one OS to another - it is still very much meant as an example rather than a guide, showing you one way to do it.

Third - and this is the part a lot of people get caught on - the example implementations of 'standard' functions described as 'libk' are meant for use inside the kernel, and are only very, very minimal sub-set implementations for the most part. They are not the versions you are going to want to provide to applications, if only because they often rely on kernel-level access to hardware. Again, they are examples, but specifically they are examples of how you would do them if you have direct access to the hardware, as the kernel does. They are meant to give you those functions in the kernel itself, and while they may have the same names and interfaces as the Standard Library functions, they aren't the versions that the kernel will expose for general users - the 'libc' versions, which are selected using preprocessor directives, have mostly been stubbed out, because in order to provide them, you would need to have a method for system calls in place - and those are going to be different for different operating systems.

Finally, there's question of why you want to work on a shell at this early stage in the first place. I am guessing that by 'shell' you are not talking about a user shell in the usual sense, but rather what is known as a kernel monitor - something that would allow you to interact with, tweak, test, and debug the kernel as it is, or at least display what it is doing.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 143 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group