sync with c; .text is implied
This commit is contained in:
parent
ba6cd8a685
commit
e97519a6d2
3 changed files with 25 additions and 18 deletions
19
bootasm.S
19
bootasm.S
|
@ -5,15 +5,16 @@
|
||||||
# memory at physical address 0x7c00 and starts executing in real mode
|
# memory at physical address 0x7c00 and starts executing in real mode
|
||||||
# with %cs=0 %ip=7c00.
|
# with %cs=0 %ip=7c00.
|
||||||
|
|
||||||
.set CSEG32, 0x8 # kernel code segment selector
|
#define SEG_KCODE 1 // kernel code
|
||||||
.set DSEG32, 0x10 # kernel data segment selector
|
#define SEG_KDATA 2 // kernel data+stack
|
||||||
.set CR0_PE, 0x1 # protected mode enable flag
|
#define SEG_KCPU 3 // kernel per-cpu data
|
||||||
|
|
||||||
|
#define CR0_PE 1 // protected mode enable bit
|
||||||
|
|
||||||
.code16 # Assemble for 16-bit mode
|
.code16 # Assemble for 16-bit mode
|
||||||
.globl start
|
.globl start
|
||||||
start:
|
start:
|
||||||
cli # Disable interrupts
|
cli # Disable interrupts
|
||||||
cld # String operations increment
|
|
||||||
|
|
||||||
# Set up the important data segment registers (DS, ES, SS).
|
# Set up the important data segment registers (DS, ES, SS).
|
||||||
xorw %ax,%ax # Segment number zero
|
xorw %ax,%ax # Segment number zero
|
||||||
|
@ -53,17 +54,18 @@ seta20.2:
|
||||||
|
|
||||||
# Jump to next instruction, but in 32-bit code segment.
|
# Jump to next instruction, but in 32-bit code segment.
|
||||||
# Switches processor into 32-bit mode.
|
# Switches processor into 32-bit mode.
|
||||||
ljmp $CSEG32, $start32
|
ljmp $(SEG_KCODE<<3), $start32
|
||||||
|
|
||||||
.code32 # Assemble for 32-bit mode
|
.code32 # Assemble for 32-bit mode
|
||||||
start32:
|
start32:
|
||||||
# Set up the protected-mode data segment registers
|
# Set up the protected-mode data segment registers
|
||||||
movw $DSEG32, %ax # Our data segment selector
|
movw $(SEG_KDATA<<3), %ax # Our data segment selector
|
||||||
movw %ax, %ds # -> DS: Data Segment
|
movw %ax, %ds # -> DS: Data Segment
|
||||||
movw %ax, %es # -> ES: Extra Segment
|
movw %ax, %es # -> ES: Extra Segment
|
||||||
|
movw %ax, %ss # -> SS: Stack Segment
|
||||||
|
movw $(SEG_KCPU<<3), %ax # Our per-cpu segment selector
|
||||||
movw %ax, %fs # -> FS
|
movw %ax, %fs # -> FS
|
||||||
movw %ax, %gs # -> GS
|
movw %ax, %gs # -> GS
|
||||||
movw %ax, %ss # -> SS: Stack Segment
|
|
||||||
|
|
||||||
# Set up the stack pointer and call into C.
|
# Set up the stack pointer and call into C.
|
||||||
movl $start, %esp
|
movl $start, %esp
|
||||||
|
@ -85,7 +87,8 @@ gdt:
|
||||||
SEG_NULLASM # null seg
|
SEG_NULLASM # null seg
|
||||||
SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff) # code seg
|
SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff) # code seg
|
||||||
SEG_ASM(STA_W, 0x0, 0xffffffff) # data seg
|
SEG_ASM(STA_W, 0x0, 0xffffffff) # data seg
|
||||||
|
SEG_ASM(STA_W, 0x100, 0xffffffff) # per-cpu data seg; 0x100 is okay for now
|
||||||
|
|
||||||
gdtdesc:
|
gdtdesc:
|
||||||
.word 0x17 # sizeof(gdt) - 1
|
.word 0x1f # sizeof(gdt) - 1
|
||||||
.long gdt # address gdt
|
.long gdt # address gdt
|
||||||
|
|
20
trapasm.S
20
trapasm.S
|
@ -1,6 +1,6 @@
|
||||||
.text
|
#define SEG_KCODE 1 // kernel code
|
||||||
|
#define SEG_KDATA 2 // kernel data+stack
|
||||||
.set SEG_KDATA_SEL, 0x10 # selector for SEG_KDATA
|
#define SEG_KCPU 3 // kernel per-cpu data
|
||||||
|
|
||||||
# vectors.S sends all traps here.
|
# vectors.S sends all traps here.
|
||||||
.globl alltraps
|
.globl alltraps
|
||||||
|
@ -12,10 +12,16 @@ alltraps:
|
||||||
pushl %gs
|
pushl %gs
|
||||||
pushal
|
pushal
|
||||||
|
|
||||||
# Set up data segments.
|
# Set up data and per-cpu segments.
|
||||||
movl $SEG_KDATA_SEL, %eax
|
# Can find out KDATA from %ss.
|
||||||
movw %ax,%ds
|
# Assume that KCPU is KDATA+1.
|
||||||
movw %ax,%es
|
movw $(SEG_KDATA<<3), %ax
|
||||||
|
movw %ss, %ax
|
||||||
|
movw %ax, %ds
|
||||||
|
movw %ax, %es
|
||||||
|
movw $(SEG_KCPU<<3), %ax
|
||||||
|
movw %ax, %fs
|
||||||
|
movw %ax, %gs
|
||||||
|
|
||||||
# Call trap(tf), where tf=%esp
|
# Call trap(tf), where tf=%esp
|
||||||
pushl %esp
|
pushl %esp
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
print "# generated by vectors.pl - do not edit\n";
|
print "# generated by vectors.pl - do not edit\n";
|
||||||
print "# handlers\n";
|
print "# handlers\n";
|
||||||
print ".text\n";
|
|
||||||
print ".globl alltraps\n";
|
print ".globl alltraps\n";
|
||||||
for(my $i = 0; $i < 256; $i++){
|
for(my $i = 0; $i < 256; $i++){
|
||||||
print ".globl vector$i\n";
|
print ".globl vector$i\n";
|
||||||
|
@ -29,7 +28,6 @@ for(my $i = 0; $i < 256; $i++){
|
||||||
|
|
||||||
# sample output:
|
# sample output:
|
||||||
# # handlers
|
# # handlers
|
||||||
# .text
|
|
||||||
# .globl alltraps
|
# .globl alltraps
|
||||||
# .globl vector0
|
# .globl vector0
|
||||||
# vector0:
|
# vector0:
|
||||||
|
|
Loading…
Reference in a new issue