Skip to content

Commit e97519a

Browse files
author
rsc
committed
sync with c; .text is implied
1 parent ba6cd8a commit e97519a

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

bootasm.S

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
# memory at physical address 0x7c00 and starts executing in real mode
66
# with %cs=0 %ip=7c00.
77

8-
.set CSEG32, 0x8 # kernel code segment selector
9-
.set DSEG32, 0x10 # kernel data segment selector
10-
.set CR0_PE, 0x1 # protected mode enable flag
8+
#define SEG_KCODE 1 // kernel code
9+
#define SEG_KDATA 2 // kernel data+stack
10+
#define SEG_KCPU 3 // kernel per-cpu data
11+
12+
#define CR0_PE 1 // protected mode enable bit
1113

1214
.code16 # Assemble for 16-bit mode
1315
.globl start
1416
start:
1517
cli # Disable interrupts
16-
cld # String operations increment
1718

1819
# Set up the important data segment registers (DS, ES, SS).
1920
xorw %ax,%ax # Segment number zero
@@ -53,18 +54,19 @@ seta20.2:
5354

5455
# Jump to next instruction, but in 32-bit code segment.
5556
# Switches processor into 32-bit mode.
56-
ljmp $CSEG32, $start32
57+
ljmp $(SEG_KCODE<<3), $start32
5758

5859
.code32 # Assemble for 32-bit mode
5960
start32:
6061
# Set up the protected-mode data segment registers
61-
movw $DSEG32, %ax # Our data segment selector
62+
movw $(SEG_KDATA<<3), %ax # Our data segment selector
6263
movw %ax, %ds # -> DS: Data Segment
6364
movw %ax, %es # -> ES: Extra Segment
65+
movw %ax, %ss # -> SS: Stack Segment
66+
movw $(SEG_KCPU<<3), %ax # Our per-cpu segment selector
6467
movw %ax, %fs # -> FS
6568
movw %ax, %gs # -> GS
66-
movw %ax, %ss # -> SS: Stack Segment
67-
69+
6870
# Set up the stack pointer and call into C.
6971
movl $start, %esp
7072
call bootmain
@@ -85,7 +87,8 @@ gdt:
8587
SEG_NULLASM # null seg
8688
SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff) # code seg
8789
SEG_ASM(STA_W, 0x0, 0xffffffff) # data seg
90+
SEG_ASM(STA_W, 0x100, 0xffffffff) # per-cpu data seg; 0x100 is okay for now
8891

8992
gdtdesc:
90-
.word 0x17 # sizeof(gdt) - 1
93+
.word 0x1f # sizeof(gdt) - 1
9194
.long gdt # address gdt

trapasm.S

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.text
2-
3-
.set SEG_KDATA_SEL, 0x10 # selector for SEG_KDATA
1+
#define SEG_KCODE 1 // kernel code
2+
#define SEG_KDATA 2 // kernel data+stack
3+
#define SEG_KCPU 3 // kernel per-cpu data
44

55
# vectors.S sends all traps here.
66
.globl alltraps
@@ -12,10 +12,16 @@ alltraps:
1212
pushl %gs
1313
pushal
1414

15-
# Set up data segments.
16-
movl $SEG_KDATA_SEL, %eax
17-
movw %ax,%ds
18-
movw %ax,%es
15+
# Set up data and per-cpu segments.
16+
# Can find out KDATA from %ss.
17+
# Assume that KCPU is KDATA+1.
18+
movw $(SEG_KDATA<<3), %ax
19+
movw %ss, %ax
20+
movw %ax, %ds
21+
movw %ax, %es
22+
movw $(SEG_KCPU<<3), %ax
23+
movw %ax, %fs
24+
movw %ax, %gs
1925

2026
# Call trap(tf), where tf=%esp
2127
pushl %esp

vectors.pl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
print "# generated by vectors.pl - do not edit\n";
99
print "# handlers\n";
10-
print ".text\n";
1110
print ".globl alltraps\n";
1211
for(my $i = 0; $i < 256; $i++){
1312
print ".globl vector$i\n";
@@ -29,7 +28,6 @@
2928

3029
# sample output:
3130
# # handlers
32-
# .text
3331
# .globl alltraps
3432
# .globl vector0
3533
# vector0:

0 commit comments

Comments
 (0)