Skip to content
Snippets Groups Projects
Commit 65519c0e authored by Thierno souleymane Bah's avatar Thierno souleymane Bah
Browse files

feat(change from 32 bits to 64 bits done, start_sched function in progress)

parent 8451ca07
No related branches found
No related tags found
No related merge requests found
OPTION=-m32
INC=-I/vagrant/ASE/ordonnancement/x86-64/include
LIB=-L/vagrant/ASE/ordonnancement/x86-64/lib -lhardware
all: display_stack try_mul pingpong pingpongpang
display_stack : display_stack.o
gcc $(OPTION) -o $@ $^
gcc -o $@ $^ $(LIB)
try_mul : try.o try_mul.o
gcc $(OPTION) -o $@ $^
gcc -o $@ $^ $(LIB)
pingpong : try.o pingpong.o
gcc $(OPTION) -o $@ $^
gcc -o $@ $^ $(LIB)
pingpongpang : try.o pingpongpang.o
gcc $(OPTION) -o $@ $^
gcc -o $@ $^ $(LIB)
%.o:%.c
gcc $(OPTION) -c $<
gcc $(INC) -c $<
clean:
rm -f *.o *.s display_stack try_mul pingpong pingpongpang
\ No newline at end of file
......@@ -10,11 +10,13 @@ int main()
{
int a, b;
int la, lb, lc;
asm("movl %%esp, %0"
asm("mov %%rsp, %0"
"\n\t"
"movl %%ebp, %1"
"mov %%rbp, %1"
: "=r"(a), "=r"(b));
printf("esp=%p; ebp=%p\n", &a, &b);
printf("rsp=%p; rbp=%p\n", &a, &b);
printf("la=%p; lb=%p; lc=%p\n", &la, &lb, &lc);
return display(la, lb, lc);
......
......@@ -2,16 +2,17 @@
#include <stdio.h>
#include <assert.h>
#include "try.h"
#include "hardware.h"
ctx_t *current_ctx = NULL;
ctx_t *last_ctx = NULL;
int try(ctx_t *pctx, func_t *f, int arg)
{
asm("movl %%esp, %0"
asm("mov %%rsp, %0"
"\n\t"
"movl %%ebp, %1"
: "=r"(pctx->esp), "=r"(pctx->ebp));
"mov %%rbp, %1"
: "=r"(pctx->rsp), "=r"(pctx->rbp));
return f(arg);
}
......@@ -23,11 +24,11 @@ int throw(ctx_t * pctx, int r)
static int r_tmp;
r_tmp = r;
asm("movl %0 ,%%esp"
asm("mov %0 ,%%rsp"
"\n\t"
"movl %1 ,%%ebp "
"mov %1 ,%%rbp "
:
: "r"(pctx->esp), "r"(pctx->ebp));
: "r"(pctx->rsp), "r"(pctx->rbp));
return r_tmp;
}
......@@ -35,8 +36,8 @@ int throw(ctx_t * pctx, int r)
int init_ctx(ctx_t *pctx, int stack_size, funct_t f, void *args)
{
pctx->stack = malloc(stack_size);
pctx->esp = pctx->stack + stack_size - sizeof(void *);
pctx->ebp = pctx->stack + stack_size - sizeof(void *);
pctx->rsp = pctx->stack + stack_size - sizeof(void *);
pctx->rbp = pctx->stack + stack_size - sizeof(void *);
pctx->f = f;
pctx->args = args;
pctx->status = CTX_INIT;
......@@ -63,18 +64,18 @@ void switch_to_ctx(ctx_t *pctx)
if (current_ctx != NULL)
{
// Sauvegarder où on en est avec le ctx courant
asm("movl %%esp, %0"
asm("mov %%rsp, %0"
"\n\t"
"movl %%ebp, %1"
: "=r"(current_ctx->esp), "=r"(current_ctx->ebp));
"mov %%rbp, %1"
: "=r"(current_ctx->rsp), "=r"(current_ctx->rbp));
}
current_ctx = pctx;
asm("movl %0, %%esp"
asm("mov %0, %%rsp"
"\n\t"
"movl %1, %%ebp"
"mov %1, %%rbp"
:
: "r"(current_ctx->esp), "r"(current_ctx->ebp));
: "r"(current_ctx->rsp), "r"(current_ctx->rbp));
if (current_ctx->status == CTX_INIT)
start_ctx();
......@@ -109,7 +110,6 @@ ctx_t *create_ctx(int stack_size, funct_t f, void *args)
void yield()
{
//printf("%p, %p\n", current_ctx, last_ctx);
if (last_ctx == NULL)
{
printf("\nEnd \n");
......@@ -121,3 +121,40 @@ void yield()
else
switch_to_ctx(current_ctx->next_ctx);
}
empty_it(void)
{
return;
}
void timer_it()
{
_out(TIMER_ALARM, 0xFFFFFFFE);
yield();
}
void start_sched()
{
unsigned int i;
/* init hardware */
if (init_hardware(HARDWARE_INI) == 0)
{
fprintf(stderr, "Error in hardware initialization\n");
exit(EXIT_FAILURE);
}
/* dummy interrupt handlers */
for (i = 0; i < 16; i++)
IRQVECTOR[i] = empty_it;
/* program timer */
IRQVECTOR[TIMER_IRQ] = timer_it;
_out(TIMER_PARAM, 128 + 64 + 32 + 8); /* reset + alarm on + 8 tick / alarm / 11101000 */
_out(TIMER_ALARM, 0xFFFFFFFE); /* alarm at next tick (at 0xFFFFFFFF) */
/* allows all IT */
_mask(1);
yield();
}
\ No newline at end of file
#if !defined(TRY)
#define TRY
#define TIMER_PARAM 0xF4
#define TIMER_ALARM 0xF8
#define TIMER_IRQ 2
#define HARDWARE_INI "hardware.ini"
typedef int(func_t)(int);
typedef void(funct_t)(void *);
......@@ -13,8 +18,8 @@ typedef enum
typedef struct ctx_s
{
void *esp;
void *ebp;
void *rsp;
void *rbp;
char *stack;
funct_t *f;
void *args;
......@@ -36,4 +41,10 @@ ctx_t *create_ctx(int, funct_t, void *);
void yield();
void start_sched();
void irq_disable();
void irq_enable();
#endif // TRY
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment