-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.s
113 lines (91 loc) · 2.63 KB
/
start.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Tim Henderson & Steve Johnson
# start.s is the entry point for the whole system
#include stdlib.s
# KERNEL STATIC HEAP DATA mem_id = 0
# -----------------------------------------
# | loc | data |
# -----------------------------------------
# | 0 | next pid |
# -----------------------------------------
# | 1 | context_mgr linked list |
# -----------------------------------------
# | 2 | current PID |
# -----------------------------------------
# | 3 | stack heap |
# -----------------------------------------
# | 4 | original sp |
# -----------------------------------------
.text
init_kernel:
{
@hcb_addr = $s0
@khcb_addr_loc = $s1
@mem_id = $s2
@loc = $t0
@err = $t1
@temp = $t2
@stack_hcb = $s3
#Allocate memory for the heap and pass it to initialize_heap
sbrk_imm 4096 @hcb_addr
li $a1 1024
add $a0 @hcb_addr $zero
call initialize_heap
#Allocate memory for kernel static space
addu $a0 $0 0x10
addu $a1 @hcb_addr $zero
call alloc
addu @mem_id $v0 $zero
addu @hcb_addr $v1 $zero
khcb_writeback @hcb_addr
#Set next_pid to zero
puti 0 @mem_id @hcb_addr $0 @err
#Initialize the stackheap
lui @temp 0x0001
sbrk @temp @stack_hcb
li $a1 0x4000
add $a0 @stack_hcb $zero
call initialize_heap
khcb_getaddr @hcb_addr
puti 3 $0 @hcb_addr @stack_hcb @err
#geti 3 $0 @hcb_addr @stack_hcb @err
#println_hex stack_hcb_msg @stack_hcb
#return the mem_id of the static data block
addu $v0 @mem_id $zero
return
.data
stack_hcb_msg: .asciiz " stack_hcb = "
.text
}
.text
.globl __start
__start:
{
@loc = $t0
@sp = $s0
@hcb_addr = $s1
@err = $t1
#init stack pointer and kernel data
lui @sp 0x7fff
ori @sp @sp 0xfffc
call init_kernel
#store the stack pointer in static kernel data
khcb_getaddr @hcb_addr
puti 4 $0 @hcb_addr @sp @err
addu @loc $0 0x4
get @loc $0 @hcb_addr @sp @err
println_hex stack_pointer_msg @sp
#initialize space for first process
call init_context_manager
#sneaky kernel macros
load_user_programs
number_user_programs
println_hex numprogs_msg $s1
#start whatever program is in the jistfile
load_first_program
jr $s1
kill_jist
.data
stack_pointer_msg: .asciiz " sp = "
numprogs_msg: .asciiz " num programs = "
.text
}