~cypheon/xos

xos/interrupt.asm -rw-r--r-- 1.5 KiB
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
[bits 32]

extern panic
extern atpic_int_entry
extern syscall_entry
extern current
global handle_interrupt

%include "assym.asm"

handle_interrupt:
  push intext
  call panic
  add esp, 4
  iret

intext:
  db "unhandled interrupt", 0xa, 0x0

%macro int_hand 1

  global atpic_intr_handler%1
  atpic_intr_handler%1:
    push dword %1
    jmp all_intr
    ;pushad

    ;push word %1
    ;call atpic_int_entry
    ;add esp, 2

    ;popad
    ;iret

%endmacro

int_hand 0
int_hand 1
int_hand 2
int_hand 3
int_hand 4
int_hand 5
int_hand 6
int_hand 7
int_hand 8
int_hand 9
int_hand 10
int_hand 11
int_hand 12
int_hand 13
int_hand 14
int_hand 15

all_intr:
    pushad
    push esp
    call atpic_int_entry
    add esp, 4
    popad
    add esp, 4
    iret



global syscall_intr_handler
syscall_intr_handler:
  push ebp

  mov ebp, [current]
  mov ebp, PROC_PCB(ebp)

  mov PCB_EAX(ebp), eax ; store GPRs
  mov PCB_EBX(ebp), ebx
  mov PCB_ECX(ebp), ecx
  mov PCB_EDX(ebp), edx
  mov PCB_EDI(ebp), edi
  mov PCB_ESI(ebp), esi

  mov eax, [esp] ; get stored EBP
  mov PCB_EBP(ebp), eax

  mov eax, [esp + 0x04] ; get old EIP
  mov PCB_EIP(ebp), eax

  mov eax, [esp + 0x08] ; get old EFL
  mov PCB_EFL(ebp), eax

  mov eax, [esp + 0x10] ; get old ESP
  mov PCB_ESP(ebp), eax

  ;pop eax

  ;mov ebp, PROC_PCB(current)
  ;mov eax, [esp + 0x0c]
  ;mov PCB_ESP(ebp), eax

  ;mov eax, [esp + 0x1c]

  mov eax, PCB_EAX(ebp)
  push eax
  call syscall_entry
  ; unreachable code ?

  add esp, 4

  pop ebp
  iret

; expects ebp to equal esp, as it was immediately after INT
save_pcb:
  ret