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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#ifndef I386_ASM_H
#define I386_ASM_H
#include <kernel/gdt.h>
#include <stdint.h>
extern uintptr_t _kernel_start;
extern uintptr_t _kernel_end;
#define KSTART ((uintptr_t)&_kernel_start)
#define KEND ((uintptr_t)&_kernel_end - 0xC0000000)
#define PAGE_SIZE 4096
#define PCI_CONFIG_ADDR 0xCF8
#define PCI_CONFIG_DATA 0xCFC
#define COM_PORT 0x3F8
struct regs {
uint32_t eax;
uint32_t ebx;
uint32_t ecx;
uint32_t edx;
uint32_t esi;
uint32_t edi;
uint32_t ebp;
uint32_t esp;
uint32_t cr0;
uint32_t cr2;
uint32_t cr3;
uint32_t cr4;
};
struct isr_frame {
uint32_t cr4;
uint32_t cr3;
uint32_t cr2;
uint32_t cr0;
uint32_t edi;
uint32_t esi;
uint32_t edx;
uint32_t ecx;
uint32_t ebx;
uint32_t eax;
uint32_t isr_vector;
uint32_t isr_err;
uint32_t eip;
uint32_t cs;
uint32_t eflags;
} __attribute__((packed));
void isr_stub_0(void);
void isr_stub_1(void);
void isr_stub_2(void);
void isr_stub_3(void);
void isr_stub_4(void);
void isr_stub_5(void);
void isr_stub_6(void);
void isr_stub_7(void);
void isr_stub_8(void);
void isr_stub_9(void);
void isr_stub_10(void);
void isr_stub_11(void);
void isr_stub_12(void);
void isr_stub_13(void);
void isr_stub_14(void);
void isr_stub_15(void);
void isr_stub_16(void);
void isr_stub_17(void);
void isr_stub_18(void);
void isr_stub_19(void);
void isr_stub_20(void);
void isr_stub_21(void);
void isr_stub_22(void);
void isr_stub_23(void);
void isr_stub_24(void);
void isr_stub_25(void);
void isr_stub_26(void);
void isr_stub_27(void);
void isr_stub_28(void);
void isr_stub_29(void);
void isr_stub_30(void);
void isr_stub_31(void);
void irq_stub_0(void);
void irq_stub_1(void);
void irq_stub_2(void);
void irq_stub_3(void);
void irq_stub_4(void);
void irq_stub_5(void);
void irq_stub_6(void);
void irq_stub_7(void);
void irq_stub_8(void);
void irq_stub_9(void);
void irq_stub_10(void);
void irq_stub_11(void);
void irq_stub_12(void);
void irq_stub_13(void);
void irq_stub_14(void);
void irq_stub_15(void);
void syscall_stub(void);
void aquire_lock(int *lock);
void release_lock(int *lock);
void enable_paging(uint32_t new_cr3);
static inline void outb(uint16_t port, uint8_t value) {
__asm__ volatile("outb %0, %1" : : "a"(value), "Nd"(port));
}
static inline void outw(uint16_t port, uint16_t value) {
__asm__ volatile("outw %0, %1" : : "a"(value), "Nd"(port));
}
static inline void outl(uint16_t port, uint32_t value) {
__asm__ volatile("outl %0, %1" : : "a"(value), "Nd"(port));
}
static inline uint8_t inb(uint16_t port) {
uint8_t ret;
__asm__ volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
static inline uint16_t inw(uint16_t port) {
uint16_t ret;
__asm__ volatile("inw %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
static inline uint32_t inl(uint16_t port) {
uint32_t ret;
__asm__ volatile("inl %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
static inline void enable_ints(void) {
__asm__ volatile("sti");
}
static inline void disable_ints(void) {
__asm__ volatile("cli");
}
static inline void flush_tss(void) {
__asm__ volatile("movw $0x28, %ax; ltr %ax");
}
static inline void invlpg(void *addr) {
__asm__ volatile("invlpg (%0)" : : "b"(addr) : "memory");
}
#endif
|