[gdt] Global Descriptor Table driver
This commit is contained in:
parent
a81d275a56
commit
79330973d2
4
Makefile
4
Makefile
|
@ -7,8 +7,8 @@ install: kernel
|
|||
cp kernel /mnt/kernel
|
||||
umount /mnt
|
||||
|
||||
kernel: start.o link.ld main.o vga.o
|
||||
ld -m elf_i386 -T link.ld -o kernel start.o main.o vga.o
|
||||
kernel: start.o link.ld main.o vga.o gdt.o
|
||||
ld -m elf_i386 -T link.ld -o kernel *.o
|
||||
|
||||
%.o: %.c
|
||||
gcc -Wall -m32 -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o $@ $<
|
||||
|
|
BIN
bootdisk.img
BIN
bootdisk.img
Binary file not shown.
|
@ -0,0 +1,74 @@
|
|||
#include <system.h>
|
||||
|
||||
/*
|
||||
* Global Descriptor Tablet Entry
|
||||
*/
|
||||
struct gdt_entry {
|
||||
unsigned short limit_low;
|
||||
unsigned short base_low;
|
||||
unsigned char base_middle;
|
||||
unsigned char access;
|
||||
unsigned char granularity;
|
||||
unsigned char base_high;
|
||||
} __attribute__((packed));
|
||||
|
||||
/*
|
||||
* GDT pointer
|
||||
*/
|
||||
struct gdt_ptr {
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct gdt_entry gdt[3];
|
||||
struct gdt_ptr gp;
|
||||
|
||||
/*
|
||||
* (ASM) gdt_flush
|
||||
* Reloads the segment registers
|
||||
*/
|
||||
extern void gdt_flush();
|
||||
|
||||
/*
|
||||
* gdt_set_gate
|
||||
* Set a GDT descriptor
|
||||
*/
|
||||
void
|
||||
gdt_set_gate(
|
||||
int num,
|
||||
unsigned long base,
|
||||
unsigned long limit,
|
||||
unsigned char access,
|
||||
unsigned char gran
|
||||
) {
|
||||
/* Base Address */
|
||||
gdt[num].base_low = (base & 0xFFFF);
|
||||
gdt[num].base_middle = (base >> 16) & 0xFF;
|
||||
gdt[num].base_high = (base >> 24) & 0xFF;
|
||||
/* Limits */
|
||||
gdt[num].limit_low = (limit & 0xFFFF);
|
||||
gdt[num].granularity = (limit >> 16) & 0X0F;
|
||||
/* Granularity */
|
||||
gdt[num].granularity |= (gran & 0xF0);
|
||||
/* Access flags */
|
||||
gdt[num].access = access;
|
||||
}
|
||||
|
||||
/*
|
||||
* gdt_install
|
||||
* Install the kernel's GDTs
|
||||
*/
|
||||
void
|
||||
gdt_install() {
|
||||
/* GDT pointer and limits */
|
||||
gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
|
||||
gp.base = &gdt;
|
||||
/* NULL */
|
||||
gdt_set_gate(0, 0, 0, 0, 0);
|
||||
/* Code segment */
|
||||
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
|
||||
/* Data segment */
|
||||
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
|
||||
/* Go go go */
|
||||
gdt_flush();
|
||||
}
|
|
@ -16,4 +16,8 @@ extern void puts(unsigned char *str);
|
|||
extern void settextcolor(unsigned char forecolor, unsigned char backcolor);
|
||||
extern void init_video();
|
||||
|
||||
/* GDT */
|
||||
extern void gdt_install();
|
||||
extern void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
|
||||
|
||||
#endif
|
||||
|
|
1
main.c
1
main.c
|
@ -101,6 +101,7 @@ outportb(
|
|||
*/
|
||||
int
|
||||
main() {
|
||||
gdt_install();
|
||||
init_video();
|
||||
puts("Hello world!\n");
|
||||
for (;;);
|
||||
|
|
Loading…
Reference in New Issue