~cypheon/xos

xos/entry.asm -rw-r--r-- 851 bytes
567db604 — Johann Rudloff Implement scanning and allocation of physical memory. 7 years ago
                                                                                
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
[bits 32]
extern kernel_main

%include "assym.asm"

start:
  mov ebx, [esp]
  mov ax, 0x10
  mov ss, ax
  mov esp, 0x200000 ; this gives us 2MiB - kernel_size of stack

  push ebx
  call kernel_main

%define USER_CS 0x1b
%define USER_DS 0x23

global proc_switch
proc_switch:
  mov ebp, [esp + 4] ; struct proc*

  mov ebx, cr3
  mov eax, PROC_PD(ebp)
  cmp eax, ebx
  je .have_cr3 ; CR3 is already set, no need to flush TLB
  mov cr3, eax
.have_cr3:

  mov ebp, PROC_PCB(ebp)

  mov ax, USER_DS
  mov ds, ax
  mov es, ax
  mov fs, ax
  mov gs, ax

  push byte USER_DS ; SS
  mov eax, PCB_ESP(ebp) ; ESP
  push eax

  mov eax, PCB_EFL(ebp) ; EFL
  push eax

  push byte USER_CS ; CS
  mov eax, PCB_EIP(ebp) ; EIP
  push eax

  mov eax, PCB_EAX(ebp)
  mov ebx, PCB_EBX(ebp)
  mov ecx, PCB_ECX(ebp)
  mov edx, PCB_EDX(ebp)
  mov ebp, PCB_EBP(ebp)
  iret