Perfectly valid question.
There are many RTOS-es available with source code in C
The problem is that if you are looking for bare bones one, it is hard to find as most will have TCP/IP implemented in the OS.
Here is a classic RTOS - XINU, the advantage being it has a great book explaining it step by step.
https://sites.google.com/site/avrxinu/the-team[
^]
Here is the reschedule code from it as an example of what you get when you download it from the above link:
#include <conf.h>
#include <kernel.h>
#include <proc.h>
#include <q.h>
#include <inttypes.h>
extern void panic();
extern int insert();
extern int getlast();
extern void ctxsw();
char * getSP(void);
int resched(void)
{
register struct pentry volatile *optr;
register struct pentry volatile *nptr;
int newpid;
preempt = QUANTUM;
if ( ( (optr= &proctab[currpid])->pstate == PRCURR) &&
( lastkey(rdytail) < optr->pprio) ) {
return(OK);
}
if (optr->pstate == PRCURR) {
optr->pstate = PRREADY;
insert(currpid,rdyhead,optr->pprio);
}
if ( (newpid = getlast(rdytail)) == EMPTY )
return(EMPTY);
nptr = &proctab[ ( currpid = newpid ) ];
nptr->pstate = PRCURR;
ctxsw(&optr->pregs[0],&nptr->pregs[0]);
return(OK);
}
char *getSP(void)
{
char * mySP;
asm volatile(
"in %A0, __SP_L__" "\n\t"
"in %B0, __SP_H__" "\n\t"
: "=d" (mySP)
:
);
return (mySP+2);
}</inttypes.h></q.h></proc.h></kernel.h></conf.h>
1) It is an AVR port, but this is irrelevant
2) Any RTOS will have a small amount of assembler as you can see above
Enjoy