summaryrefslogtreecommitdiff
path: root/main.c
blob: 2f3b00e54523bbc82746d20726d1076962e4f2c5 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "types.h"
#include "param.h"
#include "mmu.h"
#include "proc.h"
#include "defs.h"
#include "x86.h"
#include "traps.h"
#include "syscall.h"

extern char edata[], end[];

char buf[512];

int
main()
{
  struct proc *p;
  int i;
  
  // clear BSS
  memset(edata, 0, end - edata);

  cprintf("\nxV6\n\n");

  kinit(); // physical memory allocator
  tinit(); // traps and interrupts
  pic_init();

  // create fake process zero
  p = &proc[0];
  curproc = p;
  p->state = WAITING;
  p->sz = PAGE;
  p->mem = kalloc(p->sz);
  memset(p->mem, 0, p->sz);
  p->kstack = kalloc(KSTACKSIZE);
  p->tf = (struct Trapframe *) (p->kstack + KSTACKSIZE - sizeof(struct Trapframe));
  memset(p->tf, 0, sizeof(struct Trapframe));
  p->tf->tf_es = p->tf->tf_ds = p->tf->tf_ss = (SEG_UDATA << 3) | 3;
  p->tf->tf_cs = (SEG_UCODE << 3) | 3;
  p->tf->tf_eflags = FL_IF;
  p->pid = 0;
  p->ppid = 0;
  setupsegs(p);

  // turn on interrupts
  write_eflags(read_eflags() | FL_IF);
  irq_setmask_8259A(0);

#if 1
  ide_read(0, buf, 1);
  cprintf("sec0.0 %x\n", buf[0] & 0xff);
#endif

#if 0
  p = newproc();

  i = 0;
  p->mem[i++] = 0x90; // nop 
  p->mem[i++] = 0xb8; // mov ..., %eax
  p->mem[i++] = SYS_fork;
  p->mem[i++] = 0;
  p->mem[i++] = 0;
  p->mem[i++] = 0;
  p->mem[i++] = 0xcd; // int
  p->mem[i++] = T_SYSCALL;
  p->mem[i++] = 0xb8; // mov ..., %eax
  p->mem[i++] = SYS_wait;
  p->mem[i++] = 0;
  p->mem[i++] = 0;
  p->mem[i++] = 0;
  p->mem[i++] = 0xcd; // int
  p->mem[i++] = T_SYSCALL;
  p->mem[i++] = 0xb8; // mov ..., %eax
  p->mem[i++] = SYS_exit;
  p->mem[i++] = 0;
  p->mem[i++] = 0;
  p->mem[i++] = 0;
  p->mem[i++] = 0xcd; // int
  p->mem[i++] = T_SYSCALL;
  p->tf->tf_eip = 0;
  p->tf->tf_esp = p->sz;
#endif

  swtch();

  return 0;
}