Commit 56d30b19 authored by Alexander Wilhelm's avatar Alexander Wilhelm
Browse files

ADD: mini os kernel

parent 77981481
......@@ -3,10 +3,10 @@ all: main.exe
main.exe: kernel.o user.o
gcc -m32 -nostdlib -Wl,-Tsections.ld kernel.o user.o -o main.exe
kernel.o: kernel.c user.h
kernel.o: kernel.c kernel.h tasks.h
gcc -c -m32 -march=i386 -O0 kernel.c -o kernel.o
user.o: user.c user.h
user.o: user.c kernel.h tasks.h
gcc -c -m32 -march=i386 -O0 user.c -o user.o
.PHONY: clean
......
#include "user.h"
#include "kernel.h"
extern void asm_syscall_handler(void);
void error_infinite_loop(void);
void fatal(char * format,...){ error_infinite_loop(); }
extern void asm_syscall_handler(void) {
static int count = 0;
/******************************************************************************/
tasks[count]();
int _start() {
int x = 0;
int y = 0;
x = one();
y = two();
return x + y;
count = (count + 1) % NTASKS;
}
/******************************************************************************/
/*
asm("\
.global asm_syscall_handler\n\t\
.type asm_syscall_handler, @function\n\
......@@ -25,6 +16,7 @@ asm_syscall_handler:\n\t"
" jmp error_infinite_loop\n\
.size asm_syscall_handler, . - asm_syscall_handler\n\
");
*/
asm("\
.global error_infinite_loop\n\
......@@ -34,3 +26,7 @@ error_infinite_loop:\n\
1: hlt\n\
jmp 1b\n\
");
void fatal(char *format, ...) {
error_infinite_loop();
}
#ifndef KERNEL_H
#define KERNEL_H
#include "tasks.h"
extern void asm_syscall_handler(void);
void error_infinite_loop(void);
void fatal(char *format, ...);
#endif /* KERNEL_H */
#ifndef TASKS_H
#define TASKS_H
#define NTASKS 2
int one();
int two();
extern int (*tasks[NTASKS])();
#endif /* TASKS_H */
#include "user.h"
#include "kernel.h"
#include "tasks.h"
int (*tasks[NTASKS])() = {one, two};
int _start() {
while (1) {
asm_syscall_handler();
}
return 0;
}
int one() {
int x = 5;
......
#ifndef USER_H
#define USER_H
int one();
int two();
#endif /* USER_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment