-
Notifications
You must be signed in to change notification settings - Fork 7
/
init.S
96 lines (78 loc) · 3.32 KB
/
init.S
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
/*************************************************************************
* -=-=-= boot.S =-=-=-
*
* THIS FILE WAS CREATED AND IS FOR ELEC4710 - REALTIME SYSTEMS
* PROJECT ASSIGNMENT
*
* This file contains initialisation code which is advisable to do before
* we jump into our C code. These things involve setting up a stack,
* Setting up a minimal GDT and blank IDT.
*
* Assembler: Gas
*
* Author: Colin Goudie
*
*************************************************************************/
.text
.align 4
.global init, idt, gdt, tss_desc
.extern k_main, start_stack
/* In this function we are going to set up the basic functionality */
/* before we move to C code. This includes setting up area to put our */
/* Interrupt Descriptor Table and Global Descriptor tables, as well as */
/* a stack to use. */
init:
call setup_idt # Sets up our IDT
call setup_gdt # Sets up our GDT
movl $0x10, %eax # Reload all segment registers
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
/* Sets up our stack register and stack segment to valid addresses. The */
/* stack is defined in an area that is declared in kernel.c */
lss kernel_stack_desc, %esp
/* Reset EFLAGS */
push $2
popf
pushl %ebx # Push the pointer to our multiboot header info structure
call k_main # Jump to our C code
addl $4, %esp # Clean up the stack
cli
hlt
.long 0
idt_descr:
.word 256*8-1 # IDT has 256 entries
.long idt # Ptr to our idt
.long 0
idt:
.fill 256, 8, 0 # Black IDT Table with
# 256 Entries
/* This section sets up the IDT. This basically will set up 256 entries
that will simply print something out on the screen. The actual entries
will be replaced with valid ones once we go to our C code */
setup_idt:
lidt idt_descr # Loads our IDT
ret
/* This section simply sets the GDT to the one hardcoded below */
setup_gdt:
lgdt gdt_descr # Loads our GDT
ret
.long 0
/* GDT_Table Descriptor. This structure is in the format required by the
lgdt assembly instruction. See the intel dev Manual 2 for more details */
gdt_descr:
.word 256*8-1 # GDT has 256 entries
.long gdt
.long 0
/* Out Glocal Descriptor Table */
gdt:
.quad 0x0000000000000000 /* The first entry is blank as required */
.quad 0x00c09a0000001000 /* This entry is a 16MB Execute/Read
Code Segment. S=1, Privilege = 0,
G=1, D/B=1, AVL = 0 */
.quad 0x00c0920000001000 /* This entry is 16MB Read/Write
Data Segment. S=1, Privilege = 0,
G=1, D/B=1, AVL = 0 */
tss_desc:
.fill 253, 8, 0 /* Fill the rest with zeros */