So, i have been asked by Eeems for a nice template for an OS using SDCC - here it is!

http://cemetech.net/scripts/countdown.php?/83plus/COS.tar.bz2&path=archives

COS is a simple OS base that you can put your code into. it is makefile based and needs sdcc 3.0 or higher and gcc to build. Tools to create the 8xu are included. PLEASE ask about the OS and how to use SDCC here, as i don't read minds Wink
This seems like a cool idea to get more people making OSes, since it's apparently set up already Wink I'll actually look at the file itself tomorrow and give feedback on how easy it was to make an actual little OS thing. Curious, how much stuff is already set up in this base? I'm assuming all of the stuff like setting up the linking is done already, along with setting up the pages to load into memory correctly?
it only sets up the LCD to basic settings. Why does it do nothing else? Everyone has their own way of using the hardware. GlassOS and KOS setup the LCD, mem, and other things differently, for ex..

This OS has all of the ports declared ready to use. USB code can use Linky that i modified and it should work out-of-the-box. Unlocking the flash requires you to have SDCC compile extra pages. I can add a demo to unlock the flash if you want...

But, again, it does nothing by itself - it is mainly a framework partially requested by Eeems. If you want to know how to do something, let me know. I deal with SDCC all of the time.
This sounds like a good idea. I was thinking about doing the same for the TI-9x series, but sadly there's not much interest in making new OS's for those. Sad Plus, half of the fun in writing a new OS is having to write everything from scratch. Smile

When I started writing Punix, I actually used (well, looked at) quite a bit of PedroM code, but I had to rewrite much of it to work with the rest of the system. For example, I looked at the link interrupt code in PedroM (written in asm) and rewrote it in C with changes. Mine uses different data structures for storing incoming and outgoing data, and it also wakes up a blocked process, something that PedroM doesn't have to do. The low-level sequences (reading and writing to the ports) are the only similarities between the two implementations.

On the other hand, I would've been lost trying to write my own had I not had the PedroM source code to look at. So I think that including skeleton driver code in this template OS would be a good idea—include comments where an implementation should do something specific to that implementation. Using the link driver as an example, once the code gets a whole byte from the link port, put in a comment like /* do something here with the byte in variable x */. Little things like that can help immensely.
The OS has no code in it, other than an isr that ack.s interrupts and returns. Do you want my to put in some sample drivers, such as lcd and keyboard? I can grab stuff out of GlaßOS as examples.
Did a quick test and I got this to build, then I went all OCD over the makefile to make it follow my specs Razz
I might get around to actually doing stuff with this pretty soon I just have to get the motivation.
Eeems wrote:
Did a quick test and I got this to build, then I went all OCD over the makefile to make it follow my specs Razz
I might get around to actually doing stuff with this pretty soon I just have to get the motivation.
Excellent, glad you pushed AHelper to release this. On a totally off-topic note, you need a red C in that signature bar of yours. Wink AHelper, I wish I had the time to play with this. Sad
KermMartian wrote:
. . . On a totally off-topic note, you need a red C in that signature bar of yours. Wink AHelper, I wish I had the time to play with this. Sad
Why yes I do Razz

AHelper: You might want to also provide a tutorial on how to easily make linking functions between C and asm since I'm struggling with figuring out how to pass variables from C to an asm routine.
if only doorscs became an os...
AHelper wrote:
if only doorscs became an os...


But then it would be DoorsOS, not CS! Razz and it's a shell because then 500x more people will actually use it and benefit from it's use.
Do we have an archive here for OS? If so I am blind and not seeing it.
There isn't a specific folder in the archives for OSs, but COS got uploaded to the 83+ root folder.
http://www.cemetech.net/programs/index.php?mode=folder&path=/83plus/
Ok Thanks.
@Eeems: The way that SDCC stores local variables is not always the same. I haven't done that for local variables, as SDCC will change where they are placed on the stack depending on your code. However, passed parameters to functions is the same, regardless of the sdcc version and allocator method. SDCC uses the IX register to quickly (depends if you have too many variables for pop's) get parameters and other variables. Usually SDCC sets up the ix register. Passed parameters force it, but not always locals alone. Let me demonstrate. Lets say to want to access a variable in multiple instances...

Code:
void callme(int x)
{
  __asm
    ld l,4(ix)
    ld h,5(hl)
  __endasm;
}


Looks like overkill, but not when you call printf with over 9000.... er, 100 parameters... But what is the IX?

SDCC makes that function into

Code:
_callme_start:
_callme:
  push ix
  ld ix,#0
  add ix,sp
  ; start of function below
  ld l,4(ix) ;0-1 is ret, 2-3 is ix, 4-5 is x param
  ld h,5(ix)
  ; end of function
  pop ix
  ret
_callme_end:


What if you don't want ix?
then do this:


Code:
void callme(int x) __naked


That tells sdcc that you plan to use asm to start and end the function. You can still use C if ix is setup first. Now, for variables, you should play around with it. It should be stacked as you expect. Variables in each block are local to it. (as in {} ). I haven't done that, but it should just work... but it's sdcc, full of surprises

So, what about asm to C? Well, sdcc does not promote a byte to fit into a word. What do I mean? If you have void callme(byte a,int b), then sdcc would have a at 4(ix) and b at 5-6(ix). How does it pass it?

Code:
ld a,#0
push af
inc sp
ld hl,#0
push hl
call callme
pop hl
dec sp
pop af


Lastly, what about return values? You should look at the sdcc manual, but iirc, it uses de/hl for the return, dehl for 2 words, hl for a word, and l for a byte. I hope that's right. Anything else about sdcc, let me know

(I may add these functions as examples in the os source)
AHelper wrote:
So, what about asm to C? Well, sdcc does not promote a byte to fit into a word. What do I mean? If you have void callme(byte a,int b), then sdcc would have a at 4(ix) and b at 5-6(ix). How does it pass it?
Code:
ld a,#0
push af
inc sp
ld hl,#0
push hl
call callme
pop hl
dec sp
pop af

I believe the C standard says that values are not promoted when a function prototype is provided, which agrees with SDCC's behavior in this case. Without a function prototype (pre-ANSI function definitions are not prototypes, BTW), integer values smaller than int are promoted up to int, and float values are promoted to double. Do you know if SDCC does these kinds of promotion when a prototype is not provided?

Also, does SDCC really push arguments onto the stack starting at the first argument? Every other C compiler I've used and looked at "under the hood" (eg, z88dk) pushes the last argument onto the stack first, which makes it easier to access the arguments in the correct order inside variable-argument functions like printf(). I vaguely remember asking you or someone else on this matter, but I can't remember the answer.
I am booting from a livecd, but I think that it does have the first param pushed first...
christop wrote:
Also, does SDCC really push arguments onto the stack starting at the first argument? Every other C compiler I've used and looked at "under the hood" (eg, z88dk) pushes the last argument onto the stack first, which makes it easier to access the arguments in the correct order inside variable-argument functions like printf(). I vaguely remember asking you or someone else on this matter, but I can't remember the answer.
Indeed, a common point of confusion, particularly on the x86, where just about every possible permutation of argument order, callee/caller saving, etc. I'm sure someone of your experience has run across this before, but:

http://en.wikipedia.org/wiki/X86_calling_conventions
Anyone want my changes to Linky for COS?

<edit>

I can put it in the glassos svn so that changes to glassos can be pushed along to cos.
So, an OS question: SDCC can compile for multiple Calcs, so couldn't you port a COS-based OS to another z80 calc far more easily than an asm one?
Well, picture it this way: SDCC compiles code for a generic z80 system. The code is cross-platform, but the drivers must be changed. The drivers in asm would be the same way...

The one reason why it may be faster is that it is C. The same issues of calcs with less ROM, different ports, etc. are in both languages.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
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

 

Advertisement