OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:53 am

All times are UTC - 6 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Creating a OS in BrainFuck
PostPosted: Wed Sep 23, 2009 4:25 pm 
Offline

Joined: Wed Sep 23, 2009 4:19 pm
Posts: 3
I'm going this as a experiment.

The OS will be written partially in C.

I'm aiming for 64-bit support, but I'm starting with 32-bit support for now.

http://code.google.com/p/brainfuckos/


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Wed Sep 23, 2009 10:06 pm 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
So how do you execute I/O? Run assembly language statements? Interface with the C parts?

BF is a little limited, but I'm interested in how one could use it for an OS.

_________________
Image
Image
Solar wrote:
It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.

I wish I could add more tex


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Fri Sep 25, 2009 11:53 pm 
Offline
Member
Member

Joined: Sun Jul 06, 2008 7:50 pm
Posts: 151
Location: New Zealand
On fringe(Tv Program)i saw an episode of a computer program thats melts peoples brains. But anyway that name for your operating system seems inapropiate [-X


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sat Sep 26, 2009 2:13 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
PatrickV wrote:
But anyway that name for your operating system seems inapropiate [-X
Considering the language that he is wanting to use, not really. ;)

I personally think anything with that language is a waste of time. Of course, I have to assume that this is just for fun, so good luck with it :D

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sat Sep 26, 2009 5:40 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
Troy Martin wrote:
So how do you execute I/O? Run assembly language statements? Interface with the C parts?

BF is a little limited, but I'm interested in how one could use it for an OS.


It's turing complete.

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sat Sep 26, 2009 5:58 am 
Offline
Member
Member
User avatar

Joined: Wed Jul 23, 2008 1:37 am
Posts: 140
Location: Canada
JamesM wrote:
Troy Martin wrote:
So how do you execute I/O? Run assembly language statements? Interface with the C parts?

BF is a little limited, but I'm interested in how one could use it for an OS.


It's turing complete.

And a Turing Tarpit

Writing an OS in BF, I wish I had that kind of time on my hands!


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sat Sep 26, 2009 11:29 am 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
Okay, I think I got how this could be done.

The low level part of the kernel itself is best written in something like assembly and/or C, with a built-in custom BF interpreter (written in the same language as the kernel) on top. Writing a BrainFuck interpreter isn't that hard, it's just eight byte-long instructions in a row. Whitespace is ignored, as well as, as far as I know, other non-instructional characters. You could also write a "comment" extension.

As most of you interested in this topic know, the BrainFuck base language has eight instructions:

Code:
Command    Description
----------------------
>          Move the pointer to the right
<          Move the pointer to the left
+          Increment the memory cell under the pointer
-          Decrement the memory cell under the pointer
.          Output the character signified by the cell at the pointer
,          Input a character and store it in the cell at the pointer
[          Jump past the matching ] if the cell under the pointer is 0
]          Jump back to the matching [ if the cell under the pointer is nonzero


There's also a few interesting extensions, including the # and ! instructions and BrainFuck++, which adds file I/O and, apparently, networking support. More "extensions" and related languages can be found here.

I propose the following two additions for OS development:
Code:
Command    Description
----------------------
%          Reads the memory cell under the pointer as an I/O port number for an IN instruction, storing the inputted byte at *(p+1)
@          Reads the memory cell under the pointer as an I/O port number for an OUT instruction, outputting the byte at *(p+1)


A limitation I find with BrainFuck is the inability to nest [ ] sequences. However, this is likely an easy thing to implement (nested stack work is all. This is best done in assembly language.)

Okay, I think I'm going to try writing a BrainFuck OS now.

_________________
Image
Image
Solar wrote:
It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.

I wish I could add more tex


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sat Sep 26, 2009 1:36 pm 
Offline
Member
Member
User avatar

Joined: Sat May 05, 2007 6:20 pm
Posts: 153
I think it'll be good idea next 512-byte OS competition to be a brainfuck 512-byte OS competition. :wink:

_________________
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sat Sep 26, 2009 5:26 pm 
Offline
Member
Member
User avatar

Joined: Tue Mar 24, 2009 8:11 pm
Posts: 1249
Location: Sunnyvale, California
Masterkiller wrote:
I think it'll be good idea next 512-byte OS competition to be a brainfuck 512-byte OS competition. :wink:


Only if you compressed it - 512 bytes means 512 BF instructions, and even very simple functions are hundreds of them. With a simple range encoder, you could pack it at least 3-fold, judging by the number of symbols used.


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sat Sep 26, 2009 10:32 pm 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
NickJohnson wrote:
Masterkiller wrote:
I think it'll be good idea next 512-byte OS competition to be a brainfuck 512-byte OS competition. :wink:


Only if you compressed it - 512 bytes means 512 BF instructions, and even very simple functions are hundreds of them. With a simple range encoder, you could pack it at least 3-fold, judging by the number of symbols used.

I agree. The smallest (functional) program I can think of is the following:
Code:
,[.,]

Five bytes. It takes whatever key you press and prints it to the screen. No more, no less.

Now, that doesn't do anything useful. Let's do a bit of thinking here. Here's a basic puts() routine:
Code:
[.>]

Now, all that does is prints characters starting at the data pointer before the [.>] block and stops when it hits a zero. If you want to print a newline like the libc puts() does, that's just as easy:
Code:
[.>][-]++++++++++.[-]

Now, let's break it down: [.>] prints the string. [-] clears whatever's in the current byte at the data pointer. The ten pluses and the dot increments that byte to 0Ah (newline), followed by printing it. The final [-] clears it again, restoring it to zero. Technically, as the data pointer is on the null after the string, the first [-] isn't really necessary, but it's a good touch. The final [-], however, is necessary to prevent the computer from asploding if the string is printed again and there's no null at the end, printing theoretically endless amounts of garbage.

Now I don't know about you, but I think that looks pretty damn confusing just for a freaking puts() function.

Now think about implementing "if": there's going to be a lot of decrementing and weird nested [] blocks in that.

Your small little OS is going to become a big beehawtch after a while. Debugging will be worse than hell.

_________________
Image
Image
Solar wrote:
It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.

I wish I could add more tex


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sun Sep 27, 2009 1:50 am 
Offline
Member
Member

Joined: Mon Jan 14, 2008 5:53 am
Posts: 188
Location: Helsinki
What about translating brainfuck into assembly? At least the result would be smaller and it would be easier to debug.


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sun Sep 27, 2009 12:31 pm 
Offline
Member
Member
User avatar

Joined: Tue Mar 24, 2009 8:11 pm
Posts: 1249
Location: Sunnyvale, California
@fronty: That would kind of defeat the purpose, wouldn't it?

How about instead of a kernel for BF, a kernel for a universal Turing machine emulator? That's even harder, because it's neither procedural nor functional. It would be dead slow, even compared to BF, but IMO would be much cooler.


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sun Sep 27, 2009 1:00 pm 
Offline
Member
Member

Joined: Mon Jan 14, 2008 5:53 am
Posts: 188
Location: Helsinki
NickJohnson wrote:
@fronty: That would kind of defeat the purpose, wouldn't it?

I thought the goal was operating system partially written in brainfuck, not a kernel which includes a brainfuck interpreter and some parts of kernel running on top of it.


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sun Sep 27, 2009 1:45 pm 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
I'm almost done writing a small Brainfuck interpreter in assembly.. The only problem is it's quite jumpy. I tried the ,[.,] program and it started printing out pieces of the assembly language code :)

_________________
Image
Image
Solar wrote:
It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.

I wish I could add more tex


Top
 Profile  
 
 Post subject: Re: Creating a OS in BrainFuck
PostPosted: Sun Sep 27, 2009 7:22 pm 
Offline
Member
Member
User avatar

Joined: Tue Mar 24, 2009 8:11 pm
Posts: 1249
Location: Sunnyvale, California
fronty wrote:
NickJohnson wrote:
@fronty: That would kind of defeat the purpose, wouldn't it?

I thought the goal was operating system partially written in brainfuck, not a kernel which includes a brainfuck interpreter and some parts of kernel running on top of it.

Sorry, I thought you meant that he should translate the BF to assembly initially, then fix/debug the program by modifying the assembly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 23 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