forked from timtadh/jist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.s
141 lines (113 loc) · 3.15 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
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
# 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
sbrk_imm 4096 @hcb_addr
li $a1 1024
add $a0 @hcb_addr $zero
call initialize_heap
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
addu @loc $0 $0
put @loc @mem_id @hcb_addr $0 @err
lui @temp 0x0001
sbrk @temp @stack_hcb
li $a1 0x4000
add $a0 @stack_hcb $zero
call initialize_heap
khcb_getaddr @hcb_addr
addu @loc $0 0x3
put @loc $0 @hcb_addr @stack_hcb @err
addu @loc $0 0x3
get @loc $0 @hcb_addr @stack_hcb @err
println_hex stack_hcb_msg @stack_hcb
addu $v0 @mem_id $zero
return
.data
stack_hcb_msg: .asciiz " stack_hcb = "
.text
}
.text
.globl __start
__start:
{
# enable_interrupts
# enable_clock_interrupt
# load_user_programs
# la $s0 user_program_locations
# lw $t0 0($s0)
# add $a0 $t0 $0
# call load_process
# load_user_programs
# la $s0 user_program_locations
# lw $s1 4($s0)
@loc = $t0
@sp = $s0
@hcb_addr = $s1
@err = $t1
# addu @sp $sp $0
lui @sp 0x7fff
ori @sp @sp 0xfffc
call init_kernel
khcb_getaddr @hcb_addr
addu @loc $0 0x4
put @loc $0 @hcb_addr @sp @err
addu @loc $0 0x4
get @loc $0 @hcb_addr @sp @err
println_hex stack_pointer_msg @sp
call load_first_process
#sneaky kernel macros:
# load_user_programs
disable_clock_interrupt
#sneaky kernel macros:
load_user_programs
number_user_programs
println_hex numprogs_msg $s1
# la $a0 user_program_locations
# lw $a0 0($a0)
# call println_hex
# la $a0 user_program_locations
# lw $a0 0($a0)
# call make_new_background_process
# la $s0 user_program_locations
# lw $s1 0($s0)
load_first_program
jr $s1
#la $s0 user_program_locations
#lw $s1 12($s0)
#
# enable_clock_interrupt
exit
.data
stack_pointer_msg: .asciiz " sp = "
numprogs_msg: .asciiz " num programs = "
.text
}
# j $s1 # start main program