Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Krishna Vinnakota
CSEP551
Commits
97ac612f
Commit
97ac612f
authored
17 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
nits
parent
ffa58d36
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
bootmain.c
+24
-27
24 additions, 27 deletions
bootmain.c
console.c
+18
-16
18 additions, 16 deletions
console.c
proc.c
+5
-6
5 additions, 6 deletions
proc.c
proc.h
+1
-1
1 addition, 1 deletion
proc.h
syscall.c
+3
-2
3 additions, 2 deletions
syscall.c
with
51 additions
and
52 deletions
bootmain.c
+
24
−
27
View file @
97ac612f
...
@@ -31,31 +31,35 @@
...
@@ -31,31 +31,35 @@
#include
"x86.h"
#include
"x86.h"
#define SECTSIZE 512
#define SECTSIZE 512
#define ELFHDR ((struct elfhdr*) 0x10000) // scratch space
void
readseg
(
uint
,
uint
,
uint
);
void
readseg
(
uint
,
uint
,
uint
);
void
void
cmain
(
void
)
cmain
(
void
)
{
{
struct
elfhdr
*
elf
;
struct
proghdr
*
ph
,
*
eph
;
struct
proghdr
*
ph
,
*
eph
;
void
(
*
entry
)(
void
);
// read 1st page off disk
elf
=
(
struct
elfhdr
*
)
0x10000
;
// scratch space
readseg
((
uint
)
ELFHDR
,
SECTSIZE
*
8
,
0
);
// is this a valid ELF?
// Read 1st page off disk
if
(
ELFHDR
->
magic
!=
ELF_MAGIC
)
readseg
((
uint
)
elf
,
SECTSIZE
*
8
,
0
);
// Is this an ELF executable?
if
(
elf
->
magic
!=
ELF_MAGIC
)
goto
bad
;
goto
bad
;
//
l
oad each program segment (ignores ph flags)
//
L
oad each program segment (ignores ph flags)
.
ph
=
(
struct
proghdr
*
)
((
uchar
*
)
ELFHDR
+
ELFHDR
->
phoff
);
ph
=
(
struct
proghdr
*
)((
uchar
*
)
elf
+
elf
->
phoff
);
eph
=
ph
+
ELFHDR
->
phnum
;
eph
=
ph
+
elf
->
phnum
;
for
(;
ph
<
eph
;
ph
++
)
for
(;
ph
<
eph
;
ph
++
)
readseg
(
ph
->
va
,
ph
->
memsz
,
ph
->
offset
);
readseg
(
ph
->
va
,
ph
->
memsz
,
ph
->
offset
);
// call the entry point from the ELF header
// Call the entry point from the ELF header.
// note: does not return!
// Does not return!
((
void
(
*
)(
void
))
(
ELFHDR
->
entry
&
0xFFFFFF
))();
entry
=
(
void
(
*
)(
void
))(
elf
->
entry
&
0xFFFFFF
);
entry
();
bad:
bad:
outw
(
0x8A00
,
0x8A00
);
outw
(
0x8A00
,
0x8A00
);
...
@@ -67,7 +71,7 @@ bad:
...
@@ -67,7 +71,7 @@ bad:
void
void
waitdisk
(
void
)
waitdisk
(
void
)
{
{
//
w
ait for disk rea
a
dy
//
W
ait for disk ready
.
while
((
inb
(
0x1F7
)
&
0xC0
)
!=
0x40
)
while
((
inb
(
0x1F7
)
&
0xC0
)
!=
0x40
)
;
;
}
}
...
@@ -76,9 +80,8 @@ waitdisk(void)
...
@@ -76,9 +80,8 @@ waitdisk(void)
void
void
readsect
(
void
*
dst
,
uint
offset
)
readsect
(
void
*
dst
,
uint
offset
)
{
{
//
wait for disk to be ready
//
Issue command.
waitdisk
();
waitdisk
();
outb
(
0x1F2
,
1
);
// count = 1
outb
(
0x1F2
,
1
);
// count = 1
outb
(
0x1F3
,
offset
);
outb
(
0x1F3
,
offset
);
outb
(
0x1F4
,
offset
>>
8
);
outb
(
0x1F4
,
offset
>>
8
);
...
@@ -86,10 +89,8 @@ readsect(void *dst, uint offset)
...
@@ -86,10 +89,8 @@ readsect(void *dst, uint offset)
outb
(
0x1F6
,
(
offset
>>
24
)
|
0xE0
);
outb
(
0x1F6
,
(
offset
>>
24
)
|
0xE0
);
outb
(
0x1F7
,
0x20
);
// cmd 0x20 - read sectors
outb
(
0x1F7
,
0x20
);
// cmd 0x20 - read sectors
//
wait for disk to be ready
//
Read data.
waitdisk
();
waitdisk
();
// read a sector
insl
(
0x1F0
,
dst
,
SECTSIZE
/
4
);
insl
(
0x1F0
,
dst
,
SECTSIZE
/
4
);
}
}
...
@@ -98,24 +99,20 @@ readsect(void *dst, uint offset)
...
@@ -98,24 +99,20 @@ readsect(void *dst, uint offset)
void
void
readseg
(
uint
va
,
uint
count
,
uint
offset
)
readseg
(
uint
va
,
uint
count
,
uint
offset
)
{
{
uint
e
nd_
va
;
uint
eva
;
va
&=
0xFFFFFF
;
va
&=
0xFFFFFF
;
e
nd_
va
=
va
+
count
;
eva
=
va
+
count
;
//
r
ound down to sector boundary
//
R
ound down to sector boundary
.
va
&=
~
(
SECTSIZE
-
1
);
va
&=
~
(
SECTSIZE
-
1
);
//
t
ranslate from bytes to sectors
, and
kernel starts at sector 1
//
T
ranslate from bytes to sectors
;
kernel starts at sector 1
.
offset
=
(
offset
/
SECTSIZE
)
+
1
;
offset
=
(
offset
/
SECTSIZE
)
+
1
;
// If this is too slow, we could read lots of sectors at a time.
// If this is too slow, we could read lots of sectors at a time.
// We'd write more to memory than asked, but it doesn't matter --
// We'd write more to memory than asked, but it doesn't matter --
// we load in increasing order.
// we load in increasing order.
while
(
va
<
end_va
)
{
for
(;
va
<
eva
;
va
+=
SECTSIZE
,
offset
++
)
readsect
((
uchar
*
)
va
,
offset
);
readsect
((
uchar
*
)
va
,
offset
);
va
+=
SECTSIZE
;
offset
++
;
}
}
}
This diff is collapsed.
Click to expand it.
console.c
+
18
−
16
View file @
97ac612f
...
@@ -9,7 +9,11 @@
...
@@ -9,7 +9,11 @@
#include
"proc.h"
#include
"proc.h"
#include
"kbd.h"
#include
"kbd.h"
struct
spinlock
console_lock
;
#define CRTPORT 0x3d4
#define LPTPORT 0x378
static
ushort
*
crt
=
(
ushort
*
)
0xb8000
;
// CGA memory
static
struct
spinlock
console_lock
;
int
panicked
=
0
;
int
panicked
=
0
;
int
use_console_lock
=
0
;
int
use_console_lock
=
0
;
...
@@ -21,18 +25,16 @@ lpt_putc(int c)
...
@@ -21,18 +25,16 @@ lpt_putc(int c)
{
{
int
i
;
int
i
;
for
(
i
=
0
;
!
(
inb
(
0x378
+
1
)
&
0x80
)
&&
i
<
12800
;
i
++
)
for
(
i
=
0
;
!
(
inb
(
LPTPORT
+
1
)
&
0x80
)
&&
i
<
12800
;
i
++
)
;
;
outb
(
0x378
+
0
,
c
);
outb
(
LPTPORT
+
0
,
c
);
outb
(
0x378
+
2
,
0x08
|
0x04
|
0x01
);
outb
(
LPTPORT
+
2
,
0x08
|
0x04
|
0x01
);
outb
(
0x378
+
2
,
0x08
);
outb
(
LPTPORT
+
2
,
0x08
);
}
}
static
void
static
void
cons_putc
(
int
c
)
cons_putc
(
int
c
)
{
{
int
crtport
=
0x3d4
;
// io port of CGA
ushort
*
crt
=
(
ushort
*
)
0xB8000
;
// base of CGA memory
int
ind
;
int
ind
;
if
(
panicked
){
if
(
panicked
){
...
@@ -44,10 +46,10 @@ cons_putc(int c)
...
@@ -44,10 +46,10 @@ cons_putc(int c)
lpt_putc
(
c
);
lpt_putc
(
c
);
// cursor position, 16 bits, col + 80*row
// cursor position, 16 bits, col + 80*row
outb
(
crtport
,
14
);
outb
(
CRTPORT
,
14
);
ind
=
inb
(
crtport
+
1
)
<<
8
;
ind
=
inb
(
CRTPORT
+
1
)
<<
8
;
outb
(
crtport
,
15
);
outb
(
CRTPORT
,
15
);
ind
|=
inb
(
crtport
+
1
);
ind
|=
inb
(
CRTPORT
+
1
);
c
&=
0xff
;
c
&=
0xff
;
if
(
c
==
'\n'
){
if
(
c
==
'\n'
){
...
@@ -66,17 +68,17 @@ cons_putc(int c)
...
@@ -66,17 +68,17 @@ cons_putc(int c)
memset
(
crt
+
ind
,
0
,
sizeof
(
crt
[
0
])
*
((
24
*
80
)
-
ind
));
memset
(
crt
+
ind
,
0
,
sizeof
(
crt
[
0
])
*
((
24
*
80
)
-
ind
));
}
}
outb
(
crtport
,
14
);
outb
(
CRTPORT
,
14
);
outb
(
crtport
+
1
,
ind
>>
8
);
outb
(
CRTPORT
+
1
,
ind
>>
8
);
outb
(
crtport
,
15
);
outb
(
CRTPORT
,
15
);
outb
(
crtport
+
1
,
ind
);
outb
(
CRTPORT
+
1
,
ind
);
}
}
void
void
printint
(
int
xx
,
int
base
,
int
sgn
)
printint
(
int
xx
,
int
base
,
int
sgn
)
{
{
static
char
digits
[]
=
"0123456789ABCDEF"
;
char
buf
[
16
];
char
buf
[
16
];
char
digits
[]
=
"0123456789ABCDEF"
;
int
i
=
0
,
neg
=
0
;
int
i
=
0
,
neg
=
0
;
uint
x
;
uint
x
;
...
...
This diff is collapsed.
Click to expand it.
proc.c
+
5
−
6
View file @
97ac612f
...
@@ -65,15 +65,14 @@ growproc(int n)
...
@@ -65,15 +65,14 @@ growproc(int n)
return
cp
->
sz
-
n
;
return
cp
->
sz
-
n
;
}
}
// Set up CPU's segment descriptors and task state for a
// Set up CPU's segment descriptors and task state for a given process.
// given process.
// If p==0, set up for "idle" state for when scheduler() is running.
// If p==0, set up for "idle" state for when scheduler()
// is idling, not running any process.
void
void
setupsegs
(
struct
proc
*
p
)
setupsegs
(
struct
proc
*
p
)
{
{
struct
cpu
*
c
=
&
cpus
[
cpu
()];
struct
cpu
*
c
;
c
=
&
cpus
[
cpu
()];
c
->
ts
.
ss0
=
SEG_KDATA
<<
3
;
c
->
ts
.
ss0
=
SEG_KDATA
<<
3
;
if
(
p
)
if
(
p
)
c
->
ts
.
esp0
=
(
uint
)(
p
->
kstack
+
KSTACKSIZE
);
c
->
ts
.
esp0
=
(
uint
)(
p
->
kstack
+
KSTACKSIZE
);
...
...
This diff is collapsed.
Click to expand it.
proc.h
+
1
−
1
View file @
97ac612f
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// Save all the regular registers so we don't need to care
// Save all the regular registers so we don't need to care
// which are caller save.
// which are caller save.
// Don't save %eax, because that's the return register.
// Don't save %eax, because that's the return register.
// The layout of jmpbuf
is known to
setjmp.S.
// The layout of jmpbuf
must match code in
setjmp.S.
struct
jmpbuf
{
struct
jmpbuf
{
int
ebx
;
int
ebx
;
int
ecx
;
int
ecx
;
...
...
This diff is collapsed.
Click to expand it.
syscall.c
+
3
−
2
View file @
97ac612f
...
@@ -133,8 +133,9 @@ static int (*syscalls[])(void) = {
...
@@ -133,8 +133,9 @@ static int (*syscalls[])(void) = {
void
void
syscall
(
void
)
syscall
(
void
)
{
{
int
num
=
cp
->
tf
->
eax
;
int
num
;
num
=
cp
->
tf
->
eax
;
if
(
num
>=
0
&&
num
<
NELEM
(
syscalls
)
&&
syscalls
[
num
])
if
(
num
>=
0
&&
num
<
NELEM
(
syscalls
)
&&
syscalls
[
num
])
cp
->
tf
->
eax
=
syscalls
[
num
]();
cp
->
tf
->
eax
=
syscalls
[
num
]();
else
{
else
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment