Skip to content
Snippets Groups Projects
Commit 4280a89f authored by antnh6@gmail.com's avatar antnh6@gmail.com
Browse files

laid out code structure and what to do in README

parent aaa6edc3
No related branches found
No related tags found
1 merge request!16Withtime
{
"files.associations": {
"task-descriptor.h": "c"
}
}
\ No newline at end of file
## Tom
- [ ] main
- [ ] TDPQ
- [ ] TDPQ
- [ ] Scheduler
--------------------
## An
- [ ] TD
- [ ] Context Switch Assembly
- [ ] Syscall (user side five functions?)
- [ ] main
- [ ] TD
- [ ] Syscall
- [ ] Syscall Handler
- [ ] Kernel
----------------
## TBD
- [ ] kernel side syscall The five functions, such as create)
- [ ] Scheduler
- [ ] Context Switch Assembly
- [ ] Makefile
- [ ] the Doc
----------------
## $100 questions :D
## Ideas
- I think it's `swi n` where n is which of the 5 syscalls, say n = 1 is equal to Create
\ No newline at end of file
- I think it's `swi n` where n is which of the 5 syscalls, say n = 1 is equal to Create
- putting array of PQs where? In kernel structure or as a global var?
- Decision:
- same question, but for the Active task? in main or kernel structure?
- Decision: main
- same question, but for Request, inside kernel structure or the corresponding Task?
- Decision:
\ No newline at end of file
#ifndef ERROR_H
#define ERROR_H
#define FAILURE -1
#define SUCCESS 0
#endif
#ifndef KERNEL_H
#define KERNEL_H
#define MAX_NUM_PRIORITY 8
#define MAX_NUM_TD 10
typedef struct kernel {
TDPQ* ArrayPQ[MAX_NUM_PRIORITY];
TD ArrayTDAvail[MAX_NUM_TD]; //TODO
// a free list of pointers to free TDs. This might take the form of bits set in a couple of words.
// a structure for keeping the request currently being serviced, including its arguments.
int CurRequest;
} KernelStruct;
void kernelInit (KernelStruct* Colonel);
void activate(KernelStruct* Colonel); // TODO Will have to return a request
void handle(KernelStruct* Colonel, Request* syscallRequest);
#endif
#ifndef REQUEST_H
#define REQUEST_H
typedef struct req {
int n;
void* args[2];
} Request;
#endif
\ No newline at end of file
#ifndef SCHEDULER_H
#define SCHEDULER_H
int schedulerInit(); // add the IDLE task with lowest priority and first USER task maybe
int pushToScheduler (KernelStruct* Colonel, TD* Task);
TD* getNextTaskScheduler (KernelStruct* Colonel);
#endif
#ifndef SYSCALL_HANDLER_H
#define SYSCALL_HANDLER_H
typedef enum syscall {
Create,
MyTid,
MyParentTid,
Pass,
Exit
} Syscall;
void handlerCreate (KernelStruct* Colonel, TD* Active);
int syscallHandler (KernelStruct* Colonel, TD* Active);
#endif
#ifndef SYSCALL_H
#define SYSCALL_H
/*
According to the kernel description doc
*/
// Kernel 1
int Create (int priority, void (*code)());
int MyTid();
int MyParentTid();
void Pass();
void Exit();
#endif
\ No newline at end of file
#ifndef TASK_DESCRIPTOR_H
#define TASK_DESCRIPTOR_H
typedef enum taskstate {
Active,
Ready,
Blocked
} State;
typedef struct taskDescriptor {
int TaskID;
int ParentID;
State TaskState;
unsigned int* StackPtr;
TD* Next;
void* RetVal;
int TaskPriority;
char* Stack;
TD* Parent;
Request* Req;
} TD;
int TDinit();
// allocTD
// deallocTD
// get TD
#endif
#include "priority-q.h"
#include "task-descriptor.h"
#include "kernel.h"
void kernelInit(KernelStruct* Colonel) {
}
void activate(KernelStruct* Colonel, TD* Active) {
}
void handle(KernelStruct* Colonel, TD* Active, Request* syscallRequest) {
};
\ No newline at end of file
#include "scheduler.h"
\ No newline at end of file
#include "task-descriptor.h"
#include "kernel.h"
#include "syscall-handler.h"
int handlerCreate(KernelStruct* Colonel, TD* Active) {
if
}
int syscallHandler(KernelStruct* Colonel) {
TD* Active = Colonel->Active;
switch(Colonel->syscallType) {
case SYS_Create:
return handlerCreate(Colonel, Active);
case SYS_myTid:
return Active->TaskID;
case SYS_parentTid:
if (Active->Parent) return Active->ParentID;
else return -1;
case SYS_Pass:
return 0;
case SYS_Exit:
// TODO
}
}
\ No newline at end of file
#include "kernel.h"
#include "syscall.h"
int Create (int priority, void (*code)()) {
}
int MyTid() {
}
int MyParentTid() {
}
void Pass() {
}
void Exit() {
}
\ No newline at end of file
#include "task-descriptor.h"
TD TDinit() {
TD NewTD = {0, 1, Ready, NULL, NULL, 0};
return NewTD;
}
/* copied from the ARM architecture manual */
swi n // n being Create, Pass, Exit, etc.
R14_svc = address of next instruction after the SWI instruction
SPSR_svc = CPSR
CPSR[4:0] = 0b10011 /* Enter Supervisor mode */
CPSR[5] = 0 /* Execute in ARM state */
/* CPSR[6] is unchanged */
CPSR[7] = 1 /* Disable normal interrupts */
/* CPSR[8] is unchanged */
CPSR[9] = CP15_reg1_EEbit /* Endianness on exception entry */
if high vectors configured then
PC = 0xFFFF0008
else
PC = 0x00000008
movs pc, lr // jump outta kernel
#include "kernel.h"
#include "task-descriptor.h"
#include "scheduler.h"
#include "error.h"
#define FOREVER while(1)
int main(int argc, char const *argv[])
{
KernelStruct Colonel;
TD* Active;
Request* syscallReq;
int status;
// TODO turn off interrupts so it won't mess up RedBoot stuff
disableInterrupts();
kernelInit(&Colonel);
status = schedulerInit();
if (status) return FAILURE;
FOREVER {
Active = getNextTaskScheduler(&Colonel);
if (Active == NULL) break; // no tasks to run
syscallReq = activate(&Colonel, Active);
handle(&Colonel, Active, syscallReq);
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment