Use xv6 macros for gdt init.
This commit is contained in:
parent
fb88c62f67
commit
1e326bddc1
2
Makefile
2
Makefile
@ -46,7 +46,7 @@ kernel.bin: kernel.o console.o drivers/vga.o drivers/keyboard.o \
|
|||||||
$(CC) -m32 -ffreestanding -Wall -Werror -c -g $< -o $@
|
$(CC) -m32 -ffreestanding -Wall -Werror -c -g $< -o $@
|
||||||
|
|
||||||
%.o: %.S
|
%.o: %.S
|
||||||
$(AS) --32 -g $^ -o $@
|
$(CC) -m32 -ffreestanding -c -g $^ -o $@
|
||||||
|
|
||||||
mbr.bin: mbr.o
|
mbr.bin: mbr.o
|
||||||
$(LD) -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@
|
$(LD) -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@
|
||||||
|
|||||||
@ -12,6 +12,11 @@
|
|||||||
#define SEG_UDATA 4
|
#define SEG_UDATA 4
|
||||||
#define SEG_TSS 5
|
#define SEG_TSS 5
|
||||||
|
|
||||||
|
#define SEG_ASM(type,base,lim) \
|
||||||
|
.word (((lim) >> 12) & 0xffff), ((base) & 0xffff); \
|
||||||
|
.byte (((base) >> 16) & 0xff), (0x90 | (type)), \
|
||||||
|
(0xC0 | (((lim) >> 28) & 0xf)), (((base) >> 24) & 0xff)
|
||||||
|
|
||||||
#define USER_BASE 0x400000 // 4 MB
|
#define USER_BASE 0x400000 // 4 MB
|
||||||
|
|
||||||
#ifndef __ASSEMBLER__
|
#ifndef __ASSEMBLER__
|
||||||
|
|||||||
30
mbr.S
30
mbr.S
@ -1,3 +1,5 @@
|
|||||||
|
#include "cpu/gdt.h"
|
||||||
|
|
||||||
.code16
|
.code16
|
||||||
.global _start
|
.global _start
|
||||||
_start:
|
_start:
|
||||||
@ -102,12 +104,12 @@ switch_to_32bit:
|
|||||||
mov %cr0, %eax
|
mov %cr0, %eax
|
||||||
or $1, %eax // 3. enable protected mode
|
or $1, %eax // 3. enable protected mode
|
||||||
mov %eax, %cr0
|
mov %eax, %cr0
|
||||||
ljmp $CODE_SEG, $init_32bit // 4. far jump
|
ljmp $SEG_KCODE << 3, $init_32bit // 4. far jump
|
||||||
|
|
||||||
|
|
||||||
.code32
|
.code32
|
||||||
init_32bit:
|
init_32bit:
|
||||||
mov $DATA_SEG, %ax // 5. update segment registers
|
mov $SEG_KDATA << 3, %ax // 5. update segment registers
|
||||||
mov %ax, %ds
|
mov %ax, %ds
|
||||||
mov %ax, %ss
|
mov %ax, %ss
|
||||||
mov %ax, %es
|
mov %ax, %es
|
||||||
@ -155,25 +157,8 @@ sectors_per_track:
|
|||||||
.balign 4
|
.balign 4
|
||||||
gdt_start:
|
gdt_start:
|
||||||
.quad 0x0 // null descriptor
|
.quad 0x0 // null descriptor
|
||||||
|
SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff) # code seg
|
||||||
// code segment descriptor
|
SEG_ASM(STA_W, 0x0, 0xffffffff) # data seg
|
||||||
gdt_code:
|
|
||||||
.word 0xffff // segment length, bits 0-15
|
|
||||||
.word 0x0 // segment base, bits 0-15
|
|
||||||
.byte 0x0 // segment base, bits 16-23
|
|
||||||
.byte 0b10011010 // flags (8 bits)
|
|
||||||
.byte 0b11001111 // flags (4 bits) + segment length, bits 16-19
|
|
||||||
.byte 0x0 // segment base, bits 24-31
|
|
||||||
|
|
||||||
// data segment descriptor
|
|
||||||
gdt_data:
|
|
||||||
.word 0xffff // segment length, bits 0-15
|
|
||||||
.word 0x0 // segment base, bits 0-15
|
|
||||||
.byte 0x0 // segment base, bits 16-23
|
|
||||||
.byte 0b10010010 // flags (8 bits)
|
|
||||||
.byte 0b11001111 // flags (4 bits) + segment length, bits 16-19
|
|
||||||
.byte 0x0 // segment base, bits 24-31
|
|
||||||
|
|
||||||
gdt_end:
|
gdt_end:
|
||||||
|
|
||||||
// GDT descriptor
|
// GDT descriptor
|
||||||
@ -181,8 +166,5 @@ gdt_descriptor:
|
|||||||
.word gdt_end - gdt_start - 1 // size (16 bit)
|
.word gdt_end - gdt_start - 1 // size (16 bit)
|
||||||
.int gdt_start // address (32 bit)
|
.int gdt_start // address (32 bit)
|
||||||
|
|
||||||
.equ CODE_SEG, gdt_code - gdt_start
|
|
||||||
.equ DATA_SEG, gdt_data - gdt_start
|
|
||||||
|
|
||||||
. = _start + 510 # pad to 510 bytes
|
. = _start + 510 # pad to 510 bytes
|
||||||
.byte 0x55, 0xaa # boot sector magic value
|
.byte 0x55, 0xaa # boot sector magic value
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user