aboutsummaryrefslogtreecommitdiff
path: root/src/bringelle.c
blob: b0ddec661b5f58c59da93a964c905c6ad6f33682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "libc/stdio.h"
#include "boot/multiboot.h"
#include "core/mem.h"
#include "core/gdt.h"
#include "core/paging.h"

char show_tics=0;

extern GDT_TSS TSS;
extern void interrupt_enable();

void utask(){
  char msg[]="Message from the task :D";
  asm("mov $0x1, %%eax;int $0x30"::"b"(msg));
  while(1);
}

void bringelle(){
  clear();
  printc("Booting Bringelle...\n",GREEN);

  // ----- Kernel boot sequence
  interrupt_enable();
  print("Interrupts enabled\n");

  paging_enable();
  print("Paging enable!\n");
  print("Kernel started !");

  show_tics=1;
  // Utask
  print("Launch user task ");
  memcpy((void*)utask,(void*)0x300000, 100); // 100 bytes seems reasonable to load utask
  asm (
    "cli                      \n\t" // Ensure we do not get interrupted
    "movl %%ss, %%eax         \n\t"
    "movl %%eax, %0           \n\t" // Save kernel ss segment into the TSS
    "movl %%esp, %1           \n\t" // Save kernel esp into the TSS BEFORE setting up the stack
    "pushl $0x33              \n\t" // Push task ss which is 0x30 along with prlv which is 0x3
    "pushl $0x30FFFF          \n\t" // Push task esp
    "pushfl                   \n\t" // Retrieve flags
    "popl %%eax               \n\t"
    "orl $0x200, %%eax        \n\t" // Enable interrupt for the user task
    "and $0xffffbfff, %%eax   \n\t" // Clear the NT flags
    "push %%eax               \n\t" // Push task flags
    "push $0x23               \n\t" // Push task cs which is 0x20 along with prlv which is 0x3
    "push $0x300000           \n\t" // Push task entry point
    "mov $0x2B, %%eax         \n\t" // GDT entry 0x28 along with prlv which is 0x3
    "mov %%eax, %%ds          \n\t" // Setting up user data segment
    "iret                     \n\t" // Launch user task
    : "=m" (TSS.ss0), "=m" (TSS.esp0)
  );

  while(1);
}

void clock(){
  static int tic=0;
  static int sec=0;
  tic++;
  if(tic>=20){
    tic=0;
    sec++;
    if(show_tics)
      putchar('.');
  }
}


void page_fault(){
  print("Page fault!");
}